SqrtMath

The SqrtMath library facilitates fixed-point square root calculations using the Babylonian method.

sqrt

Calculate the square root of an unsigned 256-bit integer using fixed-point arithmetic and the Babylonian method.

function sqrt(
    uint256 x) internal pure returns (uint256 z)

Parameters:

NameTypeDescription

x

uint

Unsigned 256-bit integer for which the square root is calculated.

Return Values:

NameTypeDescription

z

uint

Unsigned 256-bit integer representing the square root of x.

Numerous instances of the sqrt function are employed throughout Dyson Finance, necessitating the calculation of the square root of a uint256 number. This includes various functions within the following contracts:

// Gauge.sol
function bonus(address user) external view returns (uint _bonus);
// Pair.sol
function _grantSP(address to, uint input, uint output, uint premium) internal;
function _withdraw(address from, uint index, address to) internal returns (uint token0Amt, uint token1Amt);
// Router.sol
function fairPrice(address pair, uint token0Amt) external view returns (uint token1Amt);

Last updated