LBRouter
Last updated
Last updated
Inherits:
Author: Trader Joe
Main contract to interact with to swap and manage liquidity on Joe V2 exchange.
Constructor
Parameters
factory2_2
ILBFactory
Address of Joe V2.2 factory
factoryV1
IJoeFactory
Address of Joe V1 factory
legacyFactory
ILBLegacyFactory
Address of Joe V2 factory
legacyRouter
ILBLegacyRouter
Address of Joe V2 router
factory2_1
ILBFactory
Address of Joe V2.1 factory
wnative
IWNATIVE
Address of WNATIVE
Receive function that only accept NATIVE from the WNATIVE contract
View function to get the factory V2.1 address
Returns
lbFactory
ILBFactory
The address of the factory V2.1
View function to get the factory V2.1 address
Returns
lbFactory
ILBFactory
The address of the factory V2.1
View function to get the factory V2 address
Returns
legacyLBfactory
ILBLegacyFactory
The address of the factory V2
View function to get the factory V1 address
Returns
factoryV1
IJoeFactory
The address of the factory V1
View function to get the router V2 address
Returns
legacyRouter
ILBLegacyRouter
The address of the router V2
View function to get the WNATIVE address
Returns
wnative
IWNATIVE
The address of WNATIVE
Returns the approximate id corresponding to the inputted price. Warning, the returned id may be inaccurate close to the start price of a bin
Parameters
pair
ILBPair
The address of the LBPair
price
uint256
The price of y per x (multiplied by 1e36)
Returns
<none>
uint24
The id corresponding to this price
Returns the price corresponding to the inputted id
Parameters
pair
ILBPair
The address of the LBPair
id
uint24
The id
Returns
<none>
uint256
The price corresponding to this id
Simulate a swap in
Parameters
pair
ILBPair
The address of the LBPair
amountOut
uint128
The amount of token to receive
swapForY
bool
Whether you swap X for Y (true), or Y for X (false)
Returns
amountIn
uint128
The amount of token to send in order to receive amountOut token
amountOutLeft
uint128
The amount of token Out that can't be returned due to a lack of liquidity
fee
uint128
The amount of fees paid in token sent
Simulate a swap out
Parameters
pair
ILBPair
The address of the LBPair
amountIn
uint128
The amount of token sent
swapForY
bool
Whether you swap X for Y (true), or Y for X (false)
Returns
amountInLeft
uint128
The amount of token In that can't be swapped due to a lack of liquidity
amountOut
uint128
The amount of token received if amountIn tokenX are sent
fee
uint128
The amount of fees paid in token sent
Create a liquidity bin LBPair for tokenX and tokenY using the factory
Parameters
tokenX
IERC20
The address of the first token
tokenY
IERC20
The address of the second token
activeId
uint24
The active id of the pair
binStep
uint16
The bin step in basis point, used to calculate log(1 + binStep)
Returns
pair
ILBPair
The address of the newly created LBPair
Add liquidity while performing safety checks
This function is compliant with fee on transfer tokens
Parameters
liquidityParameters
LiquidityParameters
The liquidity parameters
Returns
amountXAdded
uint256
The amount of token X added
amountYAdded
uint256
The amount of token Y added
amountXLeft
uint256
The amount of token X left (sent back to liquidityParameters.refundTo)
amountYLeft
uint256
The amount of token Y left (sent back to liquidityParameters.refundTo)
depositIds
uint256[]
The ids of the deposits
liquidityMinted
uint256[]
The amount of liquidity minted
Add liquidity with NATIVE while performing safety checks
This function is compliant with fee on transfer tokens
Parameters
liquidityParameters
LiquidityParameters
The liquidity parameters
Returns
amountXAdded
uint256
The amount of token X added
amountYAdded
uint256
The amount of token Y added
amountXLeft
uint256
The amount of token X left (sent back to liquidityParameters.refundTo)
amountYLeft
uint256
The amount of token Y left (sent back to liquidityParameters.refundTo)
depositIds
uint256[]
The ids of the deposits
liquidityMinted
uint256[]
The amount of liquidity minted
Remove liquidity while performing safety checks
This function is compliant with fee on transfer tokens
Parameters
tokenX
IERC20
The address of token X
tokenY
IERC20
The address of token Y
binStep
uint16
The bin step of the LBPair
amountXMin
uint256
The min amount to receive of token X
amountYMin
uint256
The min amount to receive of token Y
ids
uint256[]
The list of ids to burn
amounts
uint256[]
The list of amounts to burn of each id in _ids
to
address
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountX
uint256
Amount of token X returned
amountY
uint256
Amount of token Y returned
Remove NATIVE liquidity while performing safety checks
This function is NOT compliant with fee on transfer tokens.
This is wanted as it would make users pays the fee on transfer twice,
use the removeLiquidity
function to remove liquidity with fee on transfer tokens.
Parameters
token
IERC20
The address of token
binStep
uint16
The bin step of the LBPair
amountTokenMin
uint256
The min amount to receive of token
amountNATIVEMin
uint256
The min amount to receive of NATIVE
ids
uint256[]
The list of ids to burn
amounts
uint256[]
The list of amounts to burn of each id in _ids
to
address payable
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountToken
uint256
Amount of token returned
amountNATIVE
uint256
Amount of NATIVE returned
Swaps exact tokens for tokens while performing safety checks
Parameters
amountIn
uint256
The amount of token to send
amountOutMin
uint256
The min amount of token to receive
path
Path
The path of the swap
to
address
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountOut
uint256
Output amount of the swap
Swaps exact tokens for NATIVE while performing safety checks
Parameters
amountIn
uint256
The amount of token to send
amountOutMinNATIVE
uint256
The min amount of NATIVE to receive
path
Path
The path of the swap
to
address payable
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountOut
uint256
Output amount of the swap
Swaps exact NATIVE for tokens while performing safety checks
Parameters
amountOutMin
uint256
The min amount of token to receive
path
Path
The path of the swap
to
address
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountOut
uint256
Output amount of the swap
Swaps tokens for exact tokens while performing safety checks
Parameters
amountOut
uint256
The amount of token to receive
amountInMax
uint256
The max amount of token to send
path
Path
The path of the swap
to
address
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountsIn
uint256[]
Input amounts of the swap
Swaps tokens for exact NATIVE while performing safety checks
Parameters
amountNATIVEOut
uint256
The amount of NATIVE to receive
amountInMax
uint256
The max amount of token to send
path
Path
The path of the swap
to
address payable
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountsIn
uint256[]
path amounts for every step of the swap
Swaps NATIVE for exact tokens while performing safety checks
Will refund any NATIVE amount sent in excess to msg.sender
Parameters
amountOut
uint256
The amount of tokens to receive
path
Path
The path of the swap
to
address
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountsIn
uint256[]
path amounts for every step of the swap
Swaps exact tokens for tokens while performing safety checks supporting for fee on transfer tokens
Parameters
amountIn
uint256
The amount of token to send
amountOutMin
uint256
The min amount of token to receive
path
Path
The path of the swap
to
address
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountOut
uint256
Output amount of the swap
Swaps exact tokens for NATIVE while performing safety checks supporting for fee on transfer tokens
Parameters
amountIn
uint256
The amount of token to send
amountOutMinNATIVE
uint256
The min amount of NATIVE to receive
path
Path
The path of the swap
to
address payable
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountOut
uint256
Output amount of the swap
Swaps exact NATIVE for tokens while performing safety checks supporting for fee on transfer tokens
Parameters
amountOutMin
uint256
The min amount of token to receive
path
Path
The path of the swap
to
address
The address of the recipient
deadline
uint256
The deadline of the tx
Returns
amountOut
uint256
Output amount of the swap
Unstuck tokens that are sent to this contract by mistake
Only callable by the factory owner
Parameters
token
IERC20
The address of the token
to
address
The address of the user to send back the tokens
amount
uint256
The amount to send
Unstuck LBTokens that are sent to this contract by mistake
Only callable by the factory owner
Parameters
lbToken
ILBToken
The address of the LBToken
to
address
The address of the user to send back the tokens
ids
uint256[]
The list of token ids
amounts
uint256[]
The list of amounts to send
Helper function to add liquidity
Parameters
liq
LiquidityParameters
The liquidity parameter
pair
ILBPair
LBPair where liquidity is deposited
Returns
amountXAdded
uint256
Amount of token X added
amountYAdded
uint256
Amount of token Y added
amountXLeft
uint256
Amount of token X left
amountYLeft
uint256
Amount of token Y left
depositIds
uint256[]
The list of deposit ids
liquidityMinted
uint256[]
The list of liquidity minted
Helper function to return the amounts in
Parameters
versions
Version[]
The list of versions (V1, V2, V2_1 or V2_2)
pairs
address[]
The list of pairs
tokenPath
IERC20[]
The swap path
amountOut
uint256
The amount out
Returns
amountsIn
uint256[]
The list of amounts in
Helper function to remove liquidity
Parameters
pair
ILBPair
The address of the LBPair
amountXMin
uint256
The min amount to receive of token X
amountYMin
uint256
The min amount to receive of token Y
ids
uint256[]
The list of ids to burn
amounts
uint256[]
The list of amounts to burn of each id in _ids
to
address
The address of the recipient
Returns
amountX
uint256
The amount of token X sent by the pair
amountY
uint256
The amount of token Y sent by the pair
Helper function to swap exact tokens for tokens
Parameters
amountIn
uint256
The amount of token sent
pairs
address[]
The list of pairs
versions
Version[]
The list of versions (V1, V2, V2_1 or V2_2)
tokenPath
IERC20[]
The swap path using the binSteps following pairBinSteps
to
address
The address of the recipient
Returns
amountOut
uint256
The amount of token sent to to
Helper function to swap tokens for exact tokens
Parameters
pairs
address[]
The array of pairs
versions
Version[]
The list of versions (V1, V2, V2_1 or V2_2)
tokenPath
IERC20[]
The swap path using the binSteps following pairBinSteps
amountsIn
uint256[]
The list of amounts in
to
address
The address of the recipient
Returns
amountOut
uint256
The amount of token sent to to
Helper function to swap exact tokens supporting for fee on transfer tokens
Parameters
pairs
address[]
The list of pairs
versions
Version[]
The list of versions (V1, V2, V2_1 or V2_2)
tokenPath
IERC20[]
The swap path using the binSteps following pairBinSteps
to
address
The address of the recipient
Helper function to return the address of the LBPair
Revert if the pair is not created yet
Parameters
tokenX
IERC20
The address of the tokenX
tokenY
IERC20
The address of the tokenY
binStep
uint256
The bin step of the LBPair
version
Version
The version of the LBPair
Returns
lbPair
address
The address of the LBPair
Helper function to return the address of the pair (v1 or v2, according to binStep
)
Revert if the pair is not created yet
Parameters
tokenX
IERC20
The address of the tokenX
tokenY
IERC20
The address of the tokenY
binStep
uint256
The bin step of the LBPair
version
Version
The version of the LBPair
Returns
pair
address
The address of the pair of binStep binStep
Helper function to return a list of pairs
Parameters
pairBinSteps
uint256[]
The list of bin steps
versions
Version[]
The list of versions (V1, V2, V2_1 or V2_2)
tokenPath
IERC20[]
The swap path using the binSteps following pairBinSteps
Returns
pairs
address[]
The list of pairs
Helper function to transfer tokens to to
Parameters
token
IERC20
The address of the token
to
address
The address of the recipient
amount
uint256
The amount to send
Helper function to transfer tokens from from
to to
Parameters
token
IERC20
The address of the token
from
address
The address of the sender
to
address
The address of the recipient
amount
uint256
The amount to send
Helper function to transfer NATIVE to to
Parameters
to
address
The address of the recipient
amount
uint256
The amount to send
Helper function to deposit and transfer WNative to to
Parameters
to
address
The address of the recipient
amount
uint256
The amount to deposit and transfer
Helper function to withdraw and transfer WNative to to
Parameters
to
address
The address of the recipient
amount
uint256
The amount to withdraw and transfer