SwapUtils
for the sake of reducing contract's deployment size.initialize(contract IERC20[] _pooledTokens, uint8[] decimals, string lpTokenName, string lpTokenSymbol, uint256 _a, uint256 _fee, uint256 _adminFee, address lpTokenTargetAddress)
_pooledTokens
: an array of ERC20s this pool will acceptdecimals
: the decimals to use for each pooled token, eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALSlpTokenName
: the long-form name of the token to be deployedlpTokenSymbol
: the short symbol for the token to be deployed_a
: the amplification coefficient _ n _ (n - 1). See the StableSwap paper for details_fee
: default swap fee to be initialized with_adminFee
: default adminFee to be initialized withlpTokenTargetAddress
: the address of an existing LPToken contract to use as a targetgetA() → uint256
getAPrecise() → uint256
getToken(uint8 index) → contract IERC20
index
: the index of the tokengetTokenIndex(address tokenAddress) → uint8
tokenAddress
: address of the tokengetTokenBalance(uint8 index) → uint256
index
: the index of the tokengetVirtualPrice() → uint256
calculateSwap(uint8 tokenIndexFrom, uint8 tokenIndexTo, uint256 dx) → uint256
tokenIndexFrom
: the token the user wants to selltokenIndexTo
: the token the user wants to buydx
: 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.calculateTokenAmount(uint256[] amounts, bool deposit) → uint256
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 withdrawalcalculateRemoveLiquidity(uint256 amount) → uint256[]
amount
: the amount of LP tokens that would be burned on withdrawalcalculateRemoveLiquidityOneToken(uint256 tokenAmount, uint8 tokenIndex) → uint256 availableTokenAmount
tokenAmount
: the amount of LP token to burntokenIndex
: index of which token will be withdrawngetAdminBalance(uint256 index) → uint256
index
: Index of the pooled tokenswap(uint8 tokenIndexFrom, uint8 tokenIndexTo, uint256 dx, uint256 minDy, uint256 deadline) → uint256
tokenIndexFrom
: the token the user wants to swap fromtokenIndexTo
: the token the user wants to swap todx
: the amount of tokens the user wants to swap fromminDy
: the min amount the user would like to receive, or revert.deadline
: latest timestamp to accept this transactionaddLiquidity(uint256[] amounts, uint256 minToMint, uint256 deadline) → uint256
amounts
: the amounts of each token to add, in their native precisionminToMint
: the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigationdeadline
: latest timestamp to accept this transactionremoveLiquidity(uint256 amount, uint256[] minAmounts, uint256 deadline) → uint256[]
amount
: the amount of LP tokens to burnminAmounts
: the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigationdeadline
: latest timestamp to accept this transactionremoveLiquidityOneToken(uint256 tokenAmount, uint8 tokenIndex, uint256 minAmount, uint256 deadline) → uint256
tokenAmount
: the amount of the token you want to receivetokenIndex
: the index of the token you want to receiveminAmount
: the minimum amount to withdraw, otherwise revertdeadline
: latest timestamp to accept this transactionremoveLiquidityImbalance(uint256[] amounts, uint256 maxBurnAmount, uint256 deadline) → uint256
amounts
: how much of each token to withdrawmaxBurnAmount
: the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation.deadline
: latest timestamp to accept this transactionwithdrawAdminFees()
setAdminFee(uint256 newAdminFee)
newAdminFee
: new admin fee to be applied on future transactionssetSwapFee(uint256 newSwapFee)
newSwapFee
: new swap fee to be applied on future transactionsrampA(uint256 futureA, uint256 futureTime)
futureA
: the new A to ramp towardsfutureTime
: timestamp when the new A should be reachedstopRampA()
TokenSwap(address buyer, uint256 tokensSold, uint256 tokensBought, uint128 soldId, uint128 boughtId)
AddLiquidity(address provider, uint256[] tokenAmounts, uint256[] fees, uint256 invariant, uint256 lpTokenSupply)
RemoveLiquidity(address provider, uint256[] tokenAmounts, uint256 lpTokenSupply)
RemoveLiquidityOne(address provider, uint256 lpTokenAmount, uint256 lpTokenSupply, uint256 boughtId, uint256 tokensBought)
RemoveLiquidityImbalance(address provider, uint256[] tokenAmounts, uint256[] fees, uint256 invariant, uint256 lpTokenSupply)
NewAdminFee(uint256 newAdminFee)
NewSwapFee(uint256 newSwapFee)
NewWithdrawFee(uint256 newWithdrawFee)
RampA(uint256 oldA, uint256 newA, uint256 initialTime, uint256 futureTime)
StopRampA(uint256 currentA, uint256 time)