MetaSwapDeposit
Last updated
Was this helpful?
Last updated
Was this helpful?
This contract flattens the LP token in a MetaSwap pool for easier user access. MetaSwap must be deployed before this contract can be initialized successfully.
For example, suppose there exists a base Swap pool consisting of [DAI, USDC, USDT]. Then a MetaSwap pool can be created with [sUSD, BaseSwapLPToken] to allow trades between either the LP token or the underlying tokens and sUSD.
MetaSwapDeposit flattens the LP token and remaps them to a single array, allowing users to ignore the dependency on BaseSwapLPToken. Using the above example, MetaSwapDeposit can act as a Swap containing [sUSD, DAI, USDC, USDT] tokens.
initialize(contract ISwap _baseSwap, contract IMetaSwap _metaSwap, contract IERC20 _metaLPToken)
Sets the address for the base Swap contract, MetaSwap contract, and the MetaSwap LP token contract.
_baseSwap
: the address of the base Swap contract
_metaSwap
: the address of the MetaSwap contract
_metaLPToken
: the address of the MetaSwap LP token contract
swap(uint8 tokenIndexFrom, uint8 tokenIndexTo, uint256 dx, uint256 minDy, uint256 deadline) → uint256
Swap two underlying tokens using the meta pool and the base pool
tokenIndexFrom
: the token the user wants to swap from
tokenIndexTo
: the token the user wants to swap to
dx
: the amount of tokens the user wants to swap from
minDy
: the min amount the user would like to receive, or revert.
deadline
: latest timestamp to accept this transaction
addLiquidity(uint256[] amounts, uint256 minToMint, uint256 deadline) → uint256
Add liquidity to the pool with the given amounts of tokens
amounts
: the amounts of each token to add, in their native precision
minToMint
: the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation
deadline
: latest timestamp to accept this transaction
amount of LP token user minted and received
removeLiquidity(uint256 amount, uint256[] minAmounts, uint256 deadline) → uint256[]
Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply.
Liquidity can always be removed, even when the pool is paused.
amount
: the amount of LP tokens to burn
minAmounts
: the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation
deadline
: latest timestamp to accept this transaction
amounts of tokens user received
removeLiquidityOneToken(uint256 tokenAmount, uint8 tokenIndex, uint256 minAmount, uint256 deadline) → uint256
Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply.
tokenAmount
: the amount of the token you want to receive
tokenIndex
: the index of the token you want to receive
minAmount
: the minimum amount to withdraw, otherwise revert
deadline
: latest timestamp to accept this transaction
amount of chosen token user received
removeLiquidityImbalance(uint256[] amounts, uint256 maxBurnAmount, uint256 deadline) → uint256
Remove liquidity from the pool, weighted differently than the pool's current balances. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply.
amounts
: how much of each token to withdraw
maxBurnAmount
: the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation.
deadline
: latest timestamp to accept this transaction
amount of LP tokens burned
calculateTokenAmount(uint256[] amounts, bool deposit) → uint256
A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running. When withdrawing from the base pool in imbalanced fashion, the recommended slippage setting is 0.2% or higher.
This shouldn't be used outside frontends for user estimates.
amounts
: an array of token amounts to deposit or withdrawal, corresponding to pooledTokens. The amount should be in each pooled token's native precision. If a token charges a fee on transfers, use the amount that gets transferred after the fee.
deposit
: whether this is a deposit or a withdrawal
token amount the user will receive
calculateRemoveLiquidity(uint256 amount) → uint256[]
A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens
amount
: the amount of LP tokens that would be burned on withdrawal
array of token balances that the user will receive
calculateRemoveLiquidityOneToken(uint256 tokenAmount, uint8 tokenIndex) → uint256
Calculate the amount of underlying token available to withdraw when withdrawing via only single token
tokenAmount
: the amount of LP token to burn
tokenIndex
: index of which token will be withdrawn
availableTokenAmount calculated amount of underlying token available to withdraw
getToken(uint8 index) → contract IERC20
Returns the address of the pooled token at given index. Reverts if tokenIndex is out of range. This is a flattened representation of the pooled tokens.
index
: the index of the token
address of the token at given index
calculateSwap(uint8 tokenIndexFrom, uint8 tokenIndexTo, uint256 dx) → uint256
Calculate amount of tokens you receive on swap
tokenIndexFrom
: the token the user wants to sell
tokenIndexTo
: the token the user wants to buy
dx
: the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee.
amount of tokens the user will receive