AMM Data Structures
The LiquidityPoolData
struct used in addLiquidity
, addLiquidityBatch
, removeLiquidity
and removeLiquidityBatch
operations is composed as follows:
The LiquidityPoolData
can be used to add or remove liquidity to/from an AMM, using both the LP (liquidity pool) address or one of the two tokens componing the pair (the pair can be also composed of more than two tokens in case of Balancer for example).
So, if you want to use an LP token the parameters must be passed as follows:
liquidityPoolAddress
-> LP address chosen to execute the operation.amount
-> the LP token amount desired to be added/removed.tokenAddress
-> this parameter must be passed asaddress(0)
because is not used in this case.amountIsLiquidityPool
->true
.involvingETH
-> a boolean value representing if ETH is involved in the LP -> this is crucial for AMMs like Uniswap where Ethereum is represented by WETH. So for example if the LP is ETH/OSinvolvingETH
istrue
, if it is WETH/OSinvolvingETH
isfalse
.receiver
-> the receiver address of theaddLiquidity
orremoveLiquidity
operation. If it's passed asaddress(0)
, the receiver address is themsg.sender
.
If you want to use the pairs tokens the parameters must be passed as follows:
liquidityPoolAddress
-> the LPaddress
of the pool to use.amount
-> the pair token amount desired to be added/removed.tokenAddress
-> represents the address of one of the pair tokens.amountIsLiquidityPool
->false
.involvingETH
-> a boolean value representing if ETH is involved in one of the pair tokens -> this is crucial for AMMs like Uniswap where Ethereum is represented by WETH. So for example if the LP is ETH/OSinvolvingETH
istrue
, if it is WETH/OSinvolvingETH
isfalse
.receiver
-> the receiver address of theaddLiquidity
orremoveLiquidity
operation. If it's passed asaddress(0)
, the receiver address is themsg.sender
.
The SwapData
struct used in swapLiquidity
and swapLiquidityBatch
operations and is composed as follows:
enterInETH
-> a boolean value representing if the input token is ETH (true
) or not (false
). So for example, if the input token is ETHenterInETH
istrue
; if the input token is WETHenterInETH
isfalse
.exitInETH
-> a boolean value representing if the output token is ETH (true
) or not (false
). So for example, if the output token is ETHexitInETH
istrue
, if output token is WETHexitInETH
isfalse
.liquidityPoolAddresses
-> array containing theliquidity pool token addresses
to be used in the swap operation. The first element of the array must necessarily be an LP address containing the input token.path
-> array containing the path (represented by the tokens used) that the swap operation must follow.inputToken
-> theaddress
of the token you want to swap.amount
-> the tokenamount
to swap in the operation.receiver
-> the output token receiveraddress
.If it's passed asaddress(0)
, the receiver address is themsg.sender
.
For example, if an operation swaps USDC for ETH and then for OS, USDC will be the input token and OS will be the output token. The liquidityPoolAddresses
array will contain the USDC/ETH LP address
in the first position, and the ETH/OS LP address
in the second one.
The swapPath
array will contain ETH in the first position, and OS in the second one.
Last updated