LFJ Developer Docs
  • Liquidity Book
  • Introduction
  • LB V2.2 Key Changes
  • Guides
    • Swap Tokens
    • Add/Remove Liquidity
    • Tracking Volume
    • Tracking Pool Balances
    • Finding The Best Quote
    • Byte32 Decoding
    • Price From Bin Id
    • Bin Id From Price
    • Finding Liquidity Depth
    • User Balances
  • Concepts
    • Concentrated Liquidity
    • Bin Math
    • Bin Liquidity
    • Swaps
    • Fees
    • Oracle
  • Contracts
    • Interfaces
      • ILBLegacyFactory
      • ILBLegacyToken
      • ILBLegacyPair
      • ILBLegacyRouter
      • ILBFlashLoanCallback
      • IPendingOwnable
      • IJoeFactory
      • IJoePair
      • IJoeRouter01
      • IJoeRouter02
      • IWNATIVE
      • ILBFactory
      • ILBHooks
      • ILBPair
      • ILBRouter
      • ILBToken
    • Libraries
      • Math
        • BitMath
        • Encoded
        • LiquidityConfigurations
        • PackedUint128Math
        • SafeCast
        • SampleMath
        • TreeMath
        • Uint128x128Math
        • Uint256x256Math
      • BinHelper
      • Clone
      • Constants
      • FeeHelper
      • Hooks
      • ImmutableClone
      • JoeLibrary
      • OracleHelper
      • PairParameterHelper
      • PriceHelper
      • ReentrancyGuardUpgradeable
      • TokenHelper
    • LBBaseHooks
    • LBFactory
    • LBPair
    • LBQuoter
    • LBRouter
    • LBToken
  • Deployment Addresses
    • Avalanche C-Chain
    • Fuji Testnet
    • Arbitrum One
    • Binance Smart Chain
    • Binance Smart Chain Testnet
    • Ethereum Mainnet
    • Monad Testnet
  • SDK
    • Introduction
    • Making a Trade
    • Adding Liquidity
    • Removing Liquidity
  • Audits
  • AMM
    • Joe V1 Contracts
    • Joe V1 Audits
  • LFJ DEX API
    • Dex Analytics
    • Pools
    • Rewards
    • User
    • User Lifetime Stats
    • Vaults
    • Models
  • LFJ Aggregator API
    • Default
    • Models
Powered by GitBook
On this page
  • Version
  • LiquidityParameters
  • Path
  • getFactory
  • getLegacyFactory
  • getV1Factory
  • getLegacyRouter
  • getWNATIVE
  • getIdFromPrice
  • getPriceFromId
  • getSwapIn
  • getSwapOut
  • createLBPair
  • addLiquidity
  • addLiquidityNATIVE
  • removeLiquidity
  • removeLiquidityNATIVE
  • swapExactTokensForTokens
  • swapExactTokensForNATIVE
  • swapExactNATIVEForTokens
  • swapTokensForExactTokens
  • swapTokensForExactNATIVE
  • swapNATIVEForExactTokens
  • swapExactTokensForTokensSupportingFeeOnTransferTokens
  • swapExactTokensForNATIVESupportingFeeOnTransferTokens
  • swapExactNATIVEForTokensSupportingFeeOnTransferTokens
  • sweep
  • sweepLBToken
  1. Contracts
  2. Interfaces

ILBRouter

Required interface of LBRouter contract

Version

enum Version{
    V1,
    V2,
    V2_1
}

This enum represents the version of the pair requested:

  • V1: Joe V1 pair

  • V2: LB pair V2. Also called legacyPair

  • V2_1: LB pair V2.1 (current version)

LiquidityParameters

struct LiquidityParameters {
IERC20 tokenX;
    IERC20 tokenY;
    uint256 binStep;
    uint256 amountX;
    uint256 amountY;
    uint256 amountXMin;
    uint256 amountYMin;
    uint256 activeIdDesired;
    uint256 idSlippage;
    int256[] deltaIds;
    uint256[] distributionX;
    uint256[] distributionY;
    address to;
    address refundTo;
    uint256 deadline;
}

The liquidity parameters, such as:

  • tokenX: The address of token X

  • tokenY: The address of token Y

  • binStep: The bin step of the pair

  • amountX: The amount to send of token X

  • amountY: The amount to send of token Y

  • amountXMin: The min amount of token X added to liquidity

  • amountYMin: The min amount of token Y added to liquidity

  • activeIdDesired: The active id that user wants to add liquidity from

  • idSlippage: The number of id that are allowed to slip

  • deltaIds: The list of delta ids to add liquidity (deltaId = activeId - desiredId)

  • distributionX: The distribution of tokenX with sum(distributionX) = 100e18 (100%) or 0 (0%)

  • distributionY: The distribution of tokenY with sum(distributionY) = 100e18 (100%) or 0 (0%)

  • to: The address of the recipient

  • refundTo: The refund address for the X or Y token left

  • deadline: The deadline of the tx

Path

struct Path{
    uint256[] pairBinSteps;
    Version[] versions;
    IERC20[] tokenPath;
}

The path parameters, such as:

  • pairBinSteps: The list of bin steps of the pairs to go through

  • versions: The list of versions of the pairs to go through

  • tokenPath: The list of tokens in the path to go through

getFactory

function getFactory() external view override returns (ILBFactory lbFactory)

getLegacyFactory

function getLegacyFactory() external view override returns (ILBLegacyFactory legacyLBfactory)

getV1Factory

function getV1Factory() external view override returns (IJoeFactory factoryV1)

getLegacyRouter

function getLegacyRouter() external view override returns (ILBLegacyRouter legacyRouter)

getWNATIVE

function getWNATIVE() external view override returns (IWNATIVE wnative)

getIdFromPrice

function getIdFromPrice(ILBPair pair, uint256 price) external view override returns (uint24)

getPriceFromId

function getPriceFromId(ILBPair pair, uint24 id) external view override returns (uint256)

getSwapIn

function getSwapIn(ILBPair pair, uint128 amountOut, bool swapForY) public view override returns (uint128 amountIn, uint128 amountOutLeft, uint128 fee)

getSwapOut

function getSwapOut(ILBPair pair, uint128 amountIn, bool swapForY) external view override returns (uint128 amountInLeft, uint128 amountOut, uint128 fee)

createLBPair

function createLBPair(IERC20 tokenX, IERC20 tokenY, uint24 activeId, uint16 binStep) external override returns (ILBPair pair)

addLiquidity

function addLiquidity(
    LiquidityParameters calldata liquidityParameters
) external returns (
    uint256 amountXAdded,
    uint256 amountYAdded,
    uint256 amountXLeft,
    uint256 amountYLeft,
    uint256[] memory depositIds,
    uint256[] memory liquidityMinted
)

addLiquidityNATIVE

function addLiquidityNATIVE(
    LiquidityParameters calldata liquidityParameters
) external payable returns (
    uint256 amountXAdded,
    uint256 amountYAdded,
    uint256 amountXLeft,
    uint256 amountYLeft,
    uint256[] memory depositIds,
    uint256[] memory liquidityMinted
)

removeLiquidity

function removeLiquidity(
    IERC20 tokenX,
    IERC20 tokenY,
    uint16 binStep,
    uint256 amountXMin,
    uint256 amountYMin,
    uint256[] memory ids,
    uint256[] memory amounts,
    address to,
    uint256 deadline
) external ensure(deadline) returns (uint256 amountX, uint256 amountY)

removeLiquidityNATIVE

function removeLiquidityNATIVE(
    IERC20 token,
    uint16 binStep,
    uint256 amountTokenMin,
    uint256 amountNATIVEMin,
    uint256[] memory ids,
    uint256[] memory amounts,
    address payable to,
    uint256 deadline
) external ensure(deadline) returns (uint256 amountToken, uint256 amountNATIVE)

swapExactTokensForTokens

function swapExactTokensForTokens(
    uint256 amountIn,
    uint256 amountOutMin,
    Path memory path,
    address to,
    uint256 deadline
) external ensure(deadline) verifyPathValidity(path) returns (uint256 amountOut)

swapExactTokensForNATIVE

function swapExactTokensForNATIVE(uint256 amountIn, uint256 amountOutMinNATIVE, Path memory path, address payable to, uint256 deadline) external override ensure(deadline) verifyPathValidity(path) returns (uint256 amountOut)

swapExactNATIVEForTokens

function swapExactNATIVEForTokens(uint256 amountOutMin, Path memory path, address to, uint256 deadline) external payable override ensure(deadline) verifyPathValidity(path) returns (uint256 amountOut)

swapTokensForExactTokens

function swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, Path memory path, address to, uint256 deadline) external override ensure(deadline) verifyPathValidity(path) returns (uint256[] memory amountsIn)

swapTokensForExactNATIVE

function swapTokensForExactNATIVE(uint256 amountNATIVEOut, uint256 amountInMax, Path memory path, address payable to, uint256 deadline) external override ensure(deadline) verifyPathValidity(path) returns (uint256[] memory amountsIn)

Swaps tokens for exact NATIVE while performing safety checks

swapNATIVEForExactTokens

function swapNATIVEForExactTokens(uint256 amountOut, Path memory path, address to, uint256 deadline) external payable override ensure(deadline) verifyPathValidity(path) returns (uint256[] memory amountsIn)

swapExactTokensForTokensSupportingFeeOnTransferTokens

function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, Path memory path, address to, uint256 deadline) external override ensure(deadline) verifyPathValidity(path) returns (uint256 amountOut)

swapExactTokensForNATIVESupportingFeeOnTransferTokens

function swapExactTokensForNATIVESupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMinNATIVE, Path memory path, address payable to, uint256 deadline) external override ensure(deadline) verifyPathValidity(path) returns (uint256 amountOut)

swapExactNATIVEForTokensSupportingFeeOnTransferTokens

function swapExactNATIVEForTokensSupportingFeeOnTransferTokens(uint256 amountOutMin, Path memory path, address to, uint256 deadline) external payable override ensure(deadline) verifyPathValidity(path) returns (uint256 amountOut)

sweep

function sweep(IERC20 token, address to, uint256 amount) external override onlyFactoryOwner

sweepLBToken

function sweepLBToken(ILBToken lbToken, address to, uint256[] calldata ids, uint256[] calldata amounts) external override onlyFactoryOwner
PreviousILBPairNextILBToken

Last updated 8 days ago