Dyson Finance Contract Docs
  • Overview
  • Guides
    • Set Up Your Local Environment
    • Interact with Dyson Finance contracts on Sepolia testnet
    • Integration of Swap
      • Trial Calculation of Swap
      • Perform a Swap
      • Deep Understanding of Swap
    • Integration of Dual Investment
      • Trial Calculation before deposit
      • Perfrom a Dual Investment Deposit
      • Perform a Dual Investment Withdrawal
    • Stake your $DYSN for $sDYSN
    • Boost the Pool by depositing your $sDYSN
    • Sponsorship Reward
  • Technical Reference
    • Overview
    • Core
      • AddressBook
      • DYSON
      • Pair
      • Router
      • PairFactory
      • Membership
        • Agency
        • AgentNFT
      • Fee & Reward distribution
        • FeeDistributor
        • Bribe
      • Staking & Yield Boosting
        • sDYSON
        • Farm
        • Gauge
      • Events
    • Libraries
      • TransferHelper
      • SqrtMath
      • ABDKMath64x64
    • Unit Definition
  • Contract Addresses & Info
    • Blast
    • Polygon zkEVM
    • Linea
    • X Layer
    • Testnet (Sepolia)
    • Testnet (Blast Sepolia)
Powered by GitBook
On this page
  1. Technical Reference
  2. Libraries

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:

Name
Type
Description

x

uint

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

Return Values:

Name
Type
Description

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);
PreviousTransferHelperNextABDKMath64x64

Last updated 1 year ago