SwapPool

Swap pool contract. May or may not be covered by a backstop pool. Conceptionally, there are two ways to temporarily disable a pool: The owner can either pause the pool, disabling deposits, swaps & backstop, or the owner can set the pool cap to zero which only prevents deposits. The former is for security incidents, the latter for phasing out a pool.

SwapFees

struct SwapFees {
  uint32 lpFee;
  uint32 backstopFee;
  uint32 protocolFee;
}

totalLiabilities

uint256 totalLiabilities

The liabilities of the pool Cannot just use totalSupply() as the totalLiabilities will accumulate also the LP fees from swaps. This is fixed point number using the decimals of this pool

reserve

uint256 reserve

The amount of pool tokens usable for swaps This is fixed point number using the decimals of this pool

reserveWithSlippage

uint256 reserveWithSlippage

The amount of pool tokens plus the slippage The relationship with reserve is: reserveWithSlippage = slippageCurve.psi(reserve, totalLiabilities) However this relationship will never hold precisely and will deviate slightly for numerical reasons!! All code needs to work even if this relationship does not hold This is fixed point number using the decimals of this pool

insuranceWithdrawalTimelock

uint256 insuranceWithdrawalTimelock

maxCoverageRatioForSwapIn

uint256 maxCoverageRatioForSwapIn

protocolTreasury

address protocolTreasury

backstop

contract IBackstopPool backstop

router

contract IRouter router

slippageCurve

contract ISlippageCurve slippageCurve

deposit

function deposit(uint256 _depositAmount) external returns (uint256 _sharesToMint, int256 _fee)

Deposits amount of tokens into pool Will change cov ratio of pool, will increase delta to 0

Parameters

NameTypeDescription

_depositAmount

uint256

The amount to be deposited, an amount of pool tokens

Return Values

NameTypeDescription

_sharesToMint

uint256

Total number of pool lp tokens minted

_fee

int256

The slippage reward (a negative fee), fixed point number using the pool decimals

quoteDeposit

function quoteDeposit(uint256 _depositAmount) external view returns (uint256 _sharesToMint)

Get a quote for the effective amount of tokens for a deposit

Parameters

NameTypeDescription

_depositAmount

uint256

The amount to be deposited

Return Values

NameTypeDescription

_sharesToMint

uint256

Total number of pool LP tokens to be minted (incl. slippage)

withdraw

function withdraw(uint256 _sharesToBurn, uint256 _minimumAmount) external returns (uint256 _payoutAmount, int256 _fee)

Withdraws liquidity amount of asset ensuring minimum amount required

Parameters

NameTypeDescription

_sharesToBurn

uint256

The liquidity to be withdrawn, an amount of LP tokens

_minimumAmount

uint256

The minimum amount of returned pool tokens that will be accepted by user

Return Values

NameTypeDescription

_payoutAmount

uint256

Amount of pool tokens withdrawn after applying withdrawal fee

_fee

int256

The penalty due to slippage (a positive fee), fixed point number using the pool decimals

quoteWithdraw

function quoteWithdraw(uint256 _sharesToBurn) external view returns (uint256 _payoutAmount)

Get a quote for the effective amount of tokens for a withdrawal

Parameters

NameTypeDescription

_sharesToBurn

uint256

Total number of pool LP tokens to be burned

Return Values

NameTypeDescription

_payoutAmount

uint256

The amount to be withdrawn (incl. slippage)

quoteBackstopDrain

function quoteBackstopDrain(uint256 _amount) external view returns (uint256 _swapAmount)

Get a quote for the effective amount of tokens for a backstop drain

Parameters

NameTypeDescription

_amount

uint256

The amount of tokens to be withdrawn for backstop liquidity

Return Values

NameTypeDescription

_swapAmount

uint256

The amount to be withdrawn (incl. slippage)

quoteSwapInto

function quoteSwapInto(uint256 _amount) public view returns (uint256 _effectiveAmount)

Get a quote for the effective amount of tokens for a swap into

Parameters

NameTypeDescription

_amount

uint256

The amount of pool tokens to swap into the pool

Return Values

NameTypeDescription

_effectiveAmount

uint256

Effective amount, incl. slippage (penalty or rewards)

quoteSwapOut

function quoteSwapOut(uint256 _amount) public view returns (uint256 _effectiveAmount, uint256 _protocolFeeWithSlippage, uint256 _effectiveLpFee, uint256 _backstopFee)

Get a quote for the effective amount of tokens, incl. slippage and fees

Parameters

NameTypeDescription

_amount

uint256

The amount of pool asset to swap out of the pool

Return Values

NameTypeDescription

_effectiveAmount

uint256

Effective amount, incl. slippage and fees

_protocolFeeWithSlippage

uint256

The protocol fee that is to be sent to the treasury

_effectiveLpFee

uint256

The actual LP fee – totalLiabilities should be incremented by this value

_backstopFee

uint256

The effective backstop fee

coverage

function coverage() external view returns (uint256 _reserves, uint256 _liabilities)

returns pool coverage ratio

Return Values

NameTypeDescription

_reserves

uint256

Current amount of usable asset() tokens (without slippage)

_liabilities

uint256

total amount of asset deposited by liquidity providers

getExcessLiquidity

function getExcessLiquidity() external view returns (int256 _excessLiquidity)

Computes the excess liquidity that forms that valuation of the backstop pool is defined as b + C - B - L where

  • b is reserve

  • C is the amount of asset() tokens in the pool

  • B is reserveWithSlippage

  • L is totalLiabilities The excess liquidity is a fixed point number using the decimals of this pool

Return Values

NameTypeDescription

_excessLiquidity

int256

The total excess liquidity of this pool, can be negative

insuranceWithdrawalUnlock

function insuranceWithdrawalUnlock(address _liquidityProvider) external view returns (uint256 _unlockedOnBlockNo)

Return the earliest block no that insurance withdrawals are possible.

Parameters

NameTypeDescription

_liquidityProvider

address

Address of some account, usually the caller

Return Values

NameTypeDescription

_unlockedOnBlockNo

uint256

Block number of the first block after time lock runs out

sharesTargetWorth

function sharesTargetWorth(uint256 _sharesToBurn) public view returns (uint256 _amount)

Returns the worth of an amount of pool shares (LP tokens) in underlying principle

Parameters

NameTypeDescription

_sharesToBurn

uint256

The number of LP tokens to burn

Return Values

NameTypeDescription

_amount

uint256

The amount of asset() tokens that the shares are worth

swapFees

function swapFees() public view returns (uint256 _lpFee, uint256 _backstopFee, uint256 _protocolFee)

Return the configured swap fees for this pool

Return Values

NameTypeDescription

_lpFee

uint256

Fee that benefits the pool's LPers, in 0.0001% (e.g. 300 -> 0.0300%)

_backstopFee

uint256

Fee that benefits the backstop pool, in 0.0001% (e.g. 150 -> 0.0150%)

_protocolFee

uint256

Fee that benefits the protocol, in 0.0001% (e.g. 50 -> 0.0050%)

Last updated