SwapFlashLoan
This contract is responsible for custody of closely pegged assets (eg. group of stablecoins) and automatic market making system. Users become an LP (Liquidity Provider) by depositing their tokens in desired ratios for an exchange of the pool token that represents their share of the pool. Users can burn pool tokens and withdraw their share of token(s).
Each time a swap between the pooled tokens happens, a set fee incurs which effectively gets distributed to the LPs.
In case of emergencies, admin can pause additional deposits, swaps, or single-asset withdraws - which stops the ratio of the tokens in the pool from changing. Users can always withdraw their tokens via multi-asset withdraws.
Most of the logic is stored as a library SwapUtils
for the sake of reducing contract's
deployment size.
#
Functions#
initializeInitializes this Swap contract with the given parameters. This will also deploy the LPToken that represents users LP position. The owner of LPToken will be this contract - which means only this contract is allowed to mint new tokens.
#
Parameters:Name | Type | Description |
---|---|---|
_pooledTokens | contract IERC20[] | an array of ERC20s this pool will accept |
decimals | uint8[] | the decimals to use for each pooled token, |
eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS
|lpTokenName
| string | the long-form name of the token to be deployed
|lpTokenSymbol
| string | the short symbol for the token to be deployed
|_a
| uint256 | the amplification coefficient n (n - 1). See the
StableSwap paper for details
|_fee
| uint256 | default swap fee to be initialized with
|_adminFee
| uint256 | default adminFee to be initialized with
|_withdrawFee
| uint256 | default withdrawFee to be initialized with
#
flashLoanBorrow the specified token from this pool for this transaction only. This function will call
IFlashLoanReceiver(receiver).executeOperation
and the receiver
must return the full amount of the token
and the associated fee by the end of the callback transaction. If the conditions are not met, this call
is reverted.
#
Parameters:Name | Type | Description |
---|---|---|
receiver | address | the address of the receiver of the token. This address must implement the IFlashLoanReceiver |
interface and the callback function executeOperation
.
|token
| contract IERC20 | the protocol fee in bps to be applied on the total flash loan fee
|amount
| uint256 | the total amount to borrow in this transaction
|params
| bytes | optional data to pass along to the callback function
#
setFlashLoanFeesUpdates the flash loan fee parameters. This function can only be called by the owner.
#
Parameters:Name | Type | Description |
---|---|---|
newFlashLoanFeeBPS | uint256 | the total fee in bps to be applied on future flash loans |
newProtocolFeeShareBPS | uint256 | the protocol fee in bps to be applied on the total flash loan fee |