BinHelper
Last updated
Last updated
Author: Trader Joe
This library contains functions to help interaction with bins.
Returns the amount of tokens that will be received when burning the given amount of liquidity
Parameters
binReserves
bytes32
The reserves of the bin
amountToBurn
uint256
The amount of liquidity to burn
totalSupply
uint256
The total supply of the liquidity book
Returns
amountsOut
bytes32
The encoded amount of tokens that will be received
Returns the share and the effective amounts in when adding liquidity
Parameters
binReserves
bytes32
The reserves of the bin
amountsIn
bytes32
The amounts of tokens to add
price
uint256
The price of the bin
totalSupply
uint256
The total supply of the liquidity book
Returns
shares
uint256
The share of the liquidity book that the user will receive
effectiveAmountsIn
bytes32
The encoded effective amounts of tokens that the user will add. This is the amount of tokens that the user will actually add to the liquidity book, and will always be less than or equal to the amountsIn.
Returns the amount of liquidity following the constant sum formula L = price * x + y
Parameters
amounts
bytes32
The amounts of tokens
price
uint256
The price of the bin
Returns
liquidity
uint256
The amount of liquidity
Returns the amount of liquidity following the constant sum formula L = price * x + y
Parameters
x
uint256
The amount of the token X
y
uint256
The amount of the token Y
price
uint256
The price of the bin
Returns
liquidity
uint256
The amount of liquidity
Verify that the amounts are correct and that the composition factor is not flawed
Parameters
amounts
bytes32
The amounts of tokens
activeId
uint24
The id of the active bin
id
uint24
The id of the bin
Returns the composition fees when adding liquidity to the active bin with a different composition factor than the bin's one, as it does an implicit swap
Parameters
binReserves
bytes32
The reserves of the bin
parameters
bytes32
The parameters of the liquidity book
binStep
uint16
The step of the bin
amountsIn
bytes32
The amounts of tokens to add
totalSupply
uint256
The total supply of the liquidity book
shares
uint256
The share of the liquidity book that the user will receive
Returns
fees
bytes32
The encoded fees that will be charged
Returns whether the bin is empty (true) or not (false)
Parameters
binReserves
bytes32
The reserves of the bin
isX
bool
Whether the reserve to check is the X reserve (true) or the Y reserve (false)
Returns
<none>
bool
Whether the bin is empty (true) or not (false)
Returns the amounts of tokens that will be added and removed from the bin during a swap along with the fees that will be charged
Parameters
binReserves
bytes32
The reserves of the bin
parameters
bytes32
The parameters of the liquidity book
binStep
uint16
The step of the bin
swapForY
bool
Whether the swap is for Y (true) or for X (false)
activeId
uint24
The id of the active bin
amountsInLeft
bytes32
The amounts of tokens left to swap
Returns
amountsInWithFees
bytes32
The encoded amounts of tokens that will be added to the bin, including fees
amountsOutOfBin
bytes32
The encoded amounts of tokens that will be removed from the bin
totalFees
bytes32
The encoded fees that will be charged
Returns the encoded amounts that were transferred to the contract
Parameters
reserves
bytes32
The reserves
tokenX
IERC20
The token X
tokenY
IERC20
The token Y
Returns
amounts
bytes32
The amounts, encoded as follows: [0 - 128[: amountX [128 - 256[: amountY
Returns the encoded amounts that were transferred to the contract, only for token X
Parameters
reserves
bytes32
The reserves
tokenX
IERC20
The token X
Returns
<none>
bytes32
amounts The amounts, encoded as follows: [0 - 128[: amountX [128 - 256[: empty
Returns the encoded amounts that were transferred to the contract, only for token Y
Parameters
reserves
bytes32
The reserves
tokenY
IERC20
The token Y
Returns
<none>
bytes32
amounts The amounts, encoded as follows: [0 - 128[: empty [128 - 256[: amountY
Transfers the encoded amounts to the recipient
Parameters
amounts
bytes32
The amounts, encoded as follows: [0 - 128[: amountX [128 - 256[: amountY
tokenX
IERC20
The token X
tokenY
IERC20
The token Y
recipient
address
The recipient
Transfers the encoded amounts to the recipient, only for token X
Parameters
amounts
bytes32
The amounts, encoded as follows: [0 - 128[: amountX [128 - 256[: empty
tokenX
IERC20
The token X
recipient
address
The recipient
Transfers the encoded amounts to the recipient, only for token Y
Parameters
amounts
bytes32
The amounts, encoded as follows: [0 - 128[: empty [128 - 256[: amountY
tokenY
IERC20
The token Y
recipient
address
The recipient