DragonSwap
  • Getting Started
    • 👋Welcome to DragonSwap
    • 💰How to Create & Connect a Wallet
    • 🪙Approving Tokens
    • 🔴Sei V2 EVM
  • Guides
    • Trading
      • 💱How to Swap
      • 🎁How to Wrap SEI
      • 🎀How to Unwrap SEI
    • Liqudity Providers
      • 🌊How to Add Liquidity
      • ☔How to Remove Liquidity
      • 🏊How to Deploy New Pools
      • 📉Understanding Impermanent Loss
      • 🫗V2: Concentrated Liquidity Pools
      • 🤖Automated Liquidity Managers (ALM)
    • Farms
      • 🥕Depositing to Farm
      • 🧑‍🌾Withdrawing from Farm
      • 🪙Claiming Rewards
      • 🚀Boosted Farms
    • Predictions
      • 🔮How to use Predictions
      • 🧞How Predictions work?
      • ❓Predictions FAQ
    • Analytics
      • 🏊Pools
      • 🥕Farms
      • 🪙Tokens
  • DragonSwap Token
    • Token & Tokenomics
    • How to Stake
    • DragonSwap Points
    • Protocol Rewards
  • Resources
    • 💻Developer Resources
      • 📄Smart Contracts
        • DragonswapV1
          • Factory
          • Pair
          • Pair(ERC-20)
          • Library
          • Router
          • Audit
        • DragonswapV2
          • Core
            • DragonswapV2Factory
            • DragonswapV2Pool
            • DragonswapV2PoolDeployer
            • Interfaces
              • IERC20Minimal
              • IDragonswapV2Factory
              • IDragonswapV2Pool
              • IDragonswapV2PoolDeployer
              • Callbacks
                • IDragonswapV2FlashCallback
                • IDragonswapV2MintCallback
                • IDragonswapV2SwapCallback
              • Pool
                • IDragonswapV2PoolActions
                • IDragonswapV2PoolDerivedState
                • IDragonswapV2PoolEvents
                • IDragonswapV2PoolImmutables
                • IDragonswapV2PoolOwnerActions
                • IDragonswapV2PoolState
            • Libraries
              • BitMath
              • FixedPoint128
              • FixedPoint96
              • FullMath
              • LiquidityMath
              • LowGasSafeMath
              • Oracle
              • Position
              • SafeCast
              • SecondsOutside
              • SqrtPriceMath
              • SwapMath
              • Tick
              • TickBitmap
              • TickMath
              • TransferHelper
              • UnsafeMath
          • Periphery
            • Base
              • BlockTimestamp
              • ERC721Permit
              • LiquidityManagement
              • Multicall
              • PeripheryImmutableState
              • PeripheryPayments
              • PeripheryPaymentsWithFee
              • PoolInitializer
              • SelfPermit
            • Interfaces
              • IERC20Metadata
              • IERC721Permit
              • IMulticall
              • INonfungiblePositionManager
              • INonfungibleTokenPositionDescriptor
              • IPeripheryImmutableState
              • IPeripheryPayments
              • IPeripheryPaymentsWithFee
              • IPoolInitializer
              • IQuoter
              • IQuoterV2
              • ISelfPermit
              • ISwapRouter
              • ITickLens
              • IV2Migrator
              • External
                • IERC1271
                • IERC20PermitAllowed
                • IWSEI
            • Lens
              • Quoter
              • QuoterV2
              • TickLens
            • Libraries
              • Base64
              • BytesLib
              • CallbackValidation
              • ChainId
              • HexStrings
              • LiquidityAmounts
              • NFTDescriptor
              • NFTSVG
              • OracleLibrary
              • Path
              • PoolAddress
              • PoolTicksCounter
              • PositionKey
              • TransferHelper
            • NonfungiblePositionManager
            • NonfungibleTokenPositionDescriptor
            • SwapRouter
            • V2Migrator
            • Error Codes
          • Staker
            • Overview
            • DragonswapV2Staker
            • Interfaces
              • IDragonswapV2Staker
            • Libraries
              • IncentiveId
              • NFTPositionInfo
              • RewardMath
          • Smart Router
            • Base
              • ApproveAndCall
              • ImmutableState
              • MulticallExtended
              • OracleSlippage
              • PeripheryPaymentsExtended
              • PeripheryPaymentsWithFeeExtended
              • PeripheryValidationExtended
            • Interfaces
              • IApproveAndCall
              • IImmutableState
              • IMixedRouteQuoterV1
              • IMulticallExtended
              • IOracleSlippage
              • IPeripheryPaymentsExtended
              • IPeripheryPaymentsWithFeeExtended
              • IQuoter
              • IQuoterV2
              • ISwapRouter02
              • ITokenValidator
              • IV1SwapRouter
              • IV2SwapRouter
            • Lens
              • MixedRouteQuoterV1
              • Quoter
              • QuoterV2
              • TokenValidator
            • Libraries
              • Constants
              • DragonswapLibrary
              • PoolTicksCounter
            • V1SwapRouter
            • V2SwapRouter
            • SwapRouter02
          • Audit
    • ❣️Marketing Resources
      • 🚩Brand Guidelines
      • 😂Meme Library
      • 🤗DragonSwap Ambassador Program
  • FAQ
    • 📲Official Links
    • 📄Contract Addresses
      • DragonswapV1
      • DragonswapV2
      • Predictions
    • ✨Roadmap
    • 📄 Token Listing Policy
    • 🏛️ToS
Powered by GitBook
On this page
  1. Resources
  2. Developer Resources
  3. Smart Contracts
  4. DragonswapV2
  5. Periphery
  6. Libraries

LiquidityAmounts

PreviousHexStringsNextNFTDescriptor

Last updated 9 months ago

Provides functions for computing liquidity amounts from token amounts and prices

Functions

getLiquidityForAmount0

  function getLiquidityForAmount0(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount0
  ) internal returns (uint128 liquidity)

Computes the amount of liquidity received for a given amount of token0 and price range

Calculates amount0 (sqrt(upper) sqrt(lower)) / (sqrt(upper) - sqrt(lower))

Parameters:

Name
Type
Description

sqrtRatioAX96

uint160

A sqrt price representing the first tick boundary

sqrtRatioBX96

uint160

A sqrt price representing the second tick boundary

amount0

uint256

The amount0 being sent in

Return Values:

Name
Type
Description

liquidity

uint128

The amount of returned liquidity

getLiquidityForAmount1

  function getLiquidityForAmount1(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount1
  ) internal returns (uint128 liquidity)

Computes the amount of liquidity received for a given amount of token1 and price range

Calculates amount1 / (sqrt(upper) - sqrt(lower)).

Name
Type
Description

sqrtRatioAX96

uint160

A sqrt price representing the first tick boundary

sqrtRatioBX96

uint160

A sqrt price representing the second tick boundary

amount1

uint256

The amount1 being sent in

Name
Type
Description

liquidity

uint128

The amount of returned liquidity

  function getLiquidityForAmounts(
    uint160 sqrtRatioX96,
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount0,
    uint256 amount1
  ) internal returns (uint128 liquidity)

Computes the maximum amount of liquidity received for a given amount of token0, token1, the current pool prices and the prices at the tick boundaries

Name
Type
Description

sqrtRatioX96

uint160

A sqrt price representing the current pool prices

sqrtRatioAX96

uint160

A sqrt price representing the first tick boundary

sqrtRatioBX96

uint160

A sqrt price representing the second tick boundary

amount0

uint256

The amount of token0 being sent in

amount1

uint256

The amount of token1 being sent in

Name
Type
Description

liquidity

uint128

The maximum amount of liquidity received

  function getAmount0ForLiquidity(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint128 liquidity
  ) internal returns (uint256 amount0)

Computes the amount of token0 for a given amount of liquidity and a price range

Name
Type
Description

sqrtRatioAX96

uint160

A sqrt price representing the first tick boundary

sqrtRatioBX96

uint160

A sqrt price representing the second tick boundary

liquidity

uint128

The liquidity being valued

Name
Type
Description

amount0

uint256

The amount of token0

  function getAmount1ForLiquidity(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint128 liquidity
  ) internal returns (uint256 amount1)

Computes the amount of token1 for a given amount of liquidity and a price range

Name
Type
Description

sqrtRatioAX96

uint160

A sqrt price representing the first tick boundary

sqrtRatioBX96

uint160

A sqrt price representing the second tick boundary

liquidity

uint128

The liquidity being valued

Name
Type
Description

amount1

uint256

The amount of token1

  function getAmountsForLiquidity(
    uint160 sqrtRatioX96,
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint128 liquidity
  ) internal returns (uint256 amount0, uint256 amount1)

Computes the token0 and token1 value for a given amount of liquidity, the current pool prices and the prices at the tick boundaries

Name
Type
Description

sqrtRatioX96

uint160

A sqrt price representing the current pool prices

sqrtRatioAX96

uint160

A sqrt price representing the first tick boundary

sqrtRatioBX96

uint160

A sqrt price representing the second tick boundary

liquidity

uint128

The liquidity being valued

Name
Type
Description

amount0

uint256

The amount of token0

amount1

uint256

The amount of token1

Parameters:

Return Values:

getLiquidityForAmounts

Parameters:

Return Values:

getAmount0ForLiquidity

Parameters:

Return Values:

getAmount1ForLiquidity

Parameters:

Return Values:

getAmountsForLiquidity

Parameters:

Return Values:

💻
📄
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​