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


maxCoverageRatioForSwapIn

uint256 maxCoverageRatioForSwapIn

safeRedeemPercentage

uint256 safeRedeemPercentage

safeRedeemInterval

uint256 safeRedeemInterval

lastBackstopBurnTimestamp

uint256 lastBackstopBurnTimestamp

lastAvailableAmountForSafeRedeem

uint256 lastAvailableAmountForSafeRedeem

protocolTreasury

address protocolTreasury

lastDepositAt

mapping(address => uint256) lastDepositAt

lastDepositAmount

mapping(address => uint256) lastDepositAmount

backstop

contract IBackstopPool backstop

router

contract IRouter router

router instance for this swap pool


slippageCurve

contract ISlippageCurve slippageCurve

deposit

function deposit(uint256 _depositAmount, uint256 _minLPAmountOut, uint256 _deadline) external returns (uint256 sharesToMint_, int256 fee_)

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

Parameters

Return Values


quoteDeposit

function quoteDeposit(uint256 _depositAmount) external view returns (uint256 sharesToMint_, uint256 slippageReward_)

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

Parameters

Return Values


withdraw

function withdraw(uint256 _sharesToBurn, uint256 _minimumAmount, uint256 _deadline) external returns (uint256 payoutAmount_, int256 fee_)

Withdraws liquidity amount of asset ensuring minimum amount required

Parameters

Return Values


quoteWithdraw

function quoteWithdraw(uint256 _sharesToBurn) external view returns (uint256 payoutAmount_, uint256 slippagePenalty_)

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

Parameters

Return Values


backstopBurn

function backstopBurn(address _owner, uint256 _sharesToBurn) external returns (uint256 amount_)

Burns swap pool LP tokens of owner, will get compensated using backstop liquidity (reedem swap pool shares) Can only be invoked by backstop pool, disabled when pool is paused

Parameters

Return Values


getMaxRedeemSwapPoolShares

function getMaxRedeemSwapPoolShares() external view returns (uint256 maxShares_)

Get the maximum amount of swap pool LP tokens that can be burned (CR <= 100%)

Return Values


backstopDrain

function backstopDrain(uint256 _amount, address _recipient) external returns (uint256 swapAmount_)

For backstop pool to withdraw liquidity if swap pool's coverage ratio > 100% Can only be invoked by backstop pool

Parameters

Return Values


quoteBackstopDrain

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

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

Parameters

Return Values


quoteSwapInto

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

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

Parameters

Return Values


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

Return Values


coverage

function coverage() external view returns (uint256 reserves_, uint256 liabilities_)

returns pool coverage ratio

Return Values


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


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

Return Values


swapFees

function swapFees() public view returns (uint256 lpFee_, uint256 backstopFee_, uint256 protocolFee_)

Return the configured swap fees for this pool

Return Values


depositingUnfreezesAt

function depositingUnfreezesAt() public view returns (uint256 depositingUnfreezesAt_)

Last updated