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
  • Codeโ€‹
  • Internal Functions
  • sortTokensโ€‹
  • pairForโ€‹
  • getReservesโ€‹
  • quoteโ€‹
  • getAmountOutโ€‹
  • getAmountInโ€‹
  • getAmountsOutโ€‹
  • getAmountsInโ€‹
  1. Resources
  2. Developer Resources
  3. Smart Contracts
  4. DragonswapV1

Library

PreviousPair(ERC-20)NextRouter

Last updated 9 months ago

Code

Internal Functions

sortTokens

function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1);

Sorts token addresses.

pairFor

function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair);

Calculates the address for a pair without making any external calls via the dragonswap SDK.

getReserves

function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB);

Calls on the pair for the passed tokens, and returns the results sorted in the order that the parameters were passed in.

quote

function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB);

Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.

function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut);

Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.

function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn);

Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.

function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts);
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts);

Useful for calculating optimal token amounts before calling .

getAmountOut

Used in .

getAmountIn

Used in .

getAmountsOut

Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling for each pair of token addresses in the path in turn, and using these to call .

Useful for calculating optimal token amounts before calling .

getAmountsIn

Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling for each pair of token addresses in the path in turn, and using these to call .

Useful for calculating optimal token amounts before calling .

๐Ÿ’ป
๐Ÿ“„
โ€‹
โ€‹
โ€‹
โ€‹
getAmountsOut
getAmountsIn
getReserves
getAmountOut
getReserves
getAmountIn
โ€‹
DragonswapLibrary.sol
โ€‹
โ€‹
โ€‹
โ€‹
getReserves
mint
swap
swap