Liquidity Pools

Liquidity pools on Backd either support ERC20 tokens or ETH. The abstract base contract is the LiquidityPool contract. Depending on the underlying asset, the child contract is either an Erc20Pool contract or an EthPool contract. Below is the common interface for all liquidity pools.

Pool Information

LiquidityPool.controller() public view returns (address)

Get the address of the controller.

LiquidityPool.addressProvider() public view returns (address)

Get the address of the addressProvider.

LiquidityPool.getUnderlying() external returns (address)

Get the address of a pool’s underlying asset. This returns address(0) if the underlying asset is ETH.

LiquidityPool.computeAPY() external view returns (uint256)

Computes the current APY for this pool which can be expressed as (underlying / supply) ^ (1 / number of years) where number of years can be expressed in seconds using secondsEllapsed / secondsPerYear

LiquidityPool.staker() external view returns (address)

Get the staker vault of the pool.

LiquidityPool.getDeployedAt() external view returns (uint256)

Get the timestamp at which the pool was deployed.

LiquidityPool.depositCap() external view returns (uint256)

Get the deposit cap of the pool during the capped phase of protocol launch.

LiquidityPool.lpToken() external view returns (address)

Get the address of the LP token of the pool.

LiquidityPool.exchangeRate() public view returns (uint256)

Compute the latest exchange rate of the pool. Returns the current exchange rate for the pool’s underlying and LP token. Here, exchange rate means: underlying = LP token * exchangeRate

LiquidityPool.getWithdrawalFee(address account, uint256 amount) public view returns (uint256)

Computes the withdrawal fee for an amount of LP tokens for a specific account.

  • account: Address of the account for which the withdrawal fee should be computed.

  • amount: Amount of LP tokens for which the withdrawal fee should be computed.

LiquidityPool.getNewCurrentFees(uint256 timeToWait, uint256 lastActionTimestamp, uint256 totalFeeAmount, uint256 currentBalance) public view returns (uint256)

Calculates the withdrawal fee a user would currently need to pay on currentBalance.

  • timeToWait: The total time to wait until the withdrawal fee reached the minimum fee.

  • lastActionTimestamp: Timestamp of the last fee update.

  • totalFeeAmount: Fees that would currently be paid on the user’s entire balance.

  • currentBalance: The balance to calculate the fees on.

Returns the updated fee amount on the current balance.

LiquidityPool.calcRedeem() public view returns (uint256)

Calculates the amount of LP tokens that need to be redeemed to get a certain amount of underlying (includes fees and exchange rate).

LiquidityPool.getVault() public view returns (IVault)

Returns the vault of the pool.

LiquidityPool.isAuthorizedToPause(address account) internal view returns (bool)

Checks if an address is authorized to pause the liquidity pool.

  • account: Address to check if it is allowed to pause the pool.

LiquidityPool.totalUnderlying() external returns (uint256)

Compute total amount of underlying tokens for this pool

LiquidityPool.isCapped() public view returns (uint256)

Returns True if pool is still capped. Once the pool is uncapped, it can not be set to capped again.

Deposits and Withdrawals

LiquidityPool.deposit(uint256 depositAmount) external returns (uint256)

Deposit underlying token into a liquidity pool and receive LP tokens in exchange.

  • depositAmount: Amount of underlying token to deposit.

LiquidityPool.deposit(uint256 depositAmount, uint256 minTokenAmount) external returns (uint256)

Deposit underlying token into a liquidity pool and receive LP tokens in exchange.

  • depositAmount: Amount of underlying token to deposit.

  • minTokenAmount: Minimum amount of LP tokens that should be received in exchange. If less than minTokenAmount LP tokens are minted, the transaction reverts.

LiquidityPool.depositFor(address account, uint256 depositAmount) external returns (uint256)

Deposit underlying token into a liquidity pool on behalf of some other address, which receives LP tokens in exchange.

  • account: Address which should receive LP tokens.

  • depositAmount: Amount of underlying token to deposit.

LiquidityPool.depositFor(address account, uint256 depositAmount, uint256 minTokenAmount) external returns (uint256)

Deposit underlying token into a liquidity pool on behalf of some other address, which receives LP tokens in exchange.

  • account: Address which should receive LP tokens.

  • depositAmount: Amount of underlying token to deposit.

  • minTokenAmount: Minimum amount of LP tokens that should be received in exchange. If less than minTokenAmount LP tokens are minted, the transaction reverts.

LiquidityPool.redeem(uint256 redeemLpTokens) external returns (uint256)

Redeem the underlying token by burning LP tokens of the pool. Returns the amount of underlying tokens redeemed.

  • redeemLpTokens: Number of LP tokens to burn for underlying.

LiquidityPool.redeem(uint256 redeemLpTokens, minRedeemAmount) public returns (uint256)

Redeem the underlying token by burning LP tokens of the pool. Returns the amount of underlying tokens redeemed.

  • redeemLpTokens: Number of LP tokens to burn for underlying.

  • minRedeemAmount: Minimum amount of underlying that needs to be redeemed or else the transaction will revert.

LiquidityPool.redeem(uint256 redeemTokens, uint256 minRedeemAmount) external returns (uint256)

Redeem the underlying token by burning LP tokens of the pool. Returns the amount of underlying tokens redeemed.

  • redeemTokens: Number of LP tokens to burn for underlying.

  • minRedeemAmount: Minimum amount of underlying that needs to be redeemed in exchange for tokens

LiquidityPool.unstakeAndRedeem(uint256 redeemLpTokens, uint256 minRedeemAmount) external returns (uint256)

Redeems the underlying asset by burning LP tokens, unstaking any LP tokens needed.

  • redeemLpTokens: Number of tokens to unstake and/or burn for redeeming the underlying.

  • minRedeemAmount: Minimum amount of underlying that should be received.

Withdrawal Fee

On withdrawals, a linearly decreasing withdrawal fee is enforced, which starts at a MAX_WITHDRAWAL_FEE and decreases linearly over 2 weeks to a MIN_WITHDRAWAL_FEE. The LiquidityPool contract maintains current withdrawal fees for each user, which are updated upon deposit and redeem. Upon deposit, the new fee percentage is calculated as the weighted average of the current balance at the current (linearly decreased) withdrawal fee and the added amount at the MAX_WITHDRAWAL_FEE. Note that actions are exempt from the withdrawal fee, i.e., when an action redeems funds for execution, it is not charged a withdrawal fee. Additionally, the StakerVault maintains a paidInStakedBalance parameter for each user. This allows a user to unstake (and thereby deposit into the Pool) funds from the StakerVault without incurring increased fees on these. Consequently, a user can stake his funds or register them for actions without incurring an increased fee upon unstaking them. However, transfers to a user’s address within the StakerVault or funds obtained from a different address via unstakeFor do not accrue to his paidInBalance and are therefore subject to increased fees upon unstaking.

Admin Methods

The primary role of the admin is to potentially update pool parameters.

LiquidityPool.rebalance() external

Rebalance vault according to required reserves ratio.

Setters

Setters across Backd contracts employ a prepare/execute/reset pattern, whereby a parameter that should be set needs to first be prepared. After a time delay specified by the constant ADMIN_DELAY (set to 3 days) the prepared parameter update can be executed by calling the execute method. If a parameter update has not been executed yet, it may be reset via the reset method.

Note

The setter methods prepare and reset can only be called by a contract’s admin. The setter method execute may be called by anyone.

LiquidityPool.prepareNewStaker(uint256 newStaker) external returns (uint256)

Prepare new staker vault to be set.

  • newStaker: New staker vault tp be used by the pool to determine required reserve ratios.

LiquidityPool.prepareNewWithdrawalFee(uint256 newFee) external returns (uint256)

Prepare new withdrawal fee that is charged on funds withdrawn from the pool.

  • newFee: New withdrawal fee to be charged.

LiquidityPool.prepareNewVault(address newVault) external returns (uint256)

Prepare a new vault for the pool.

  • newVault: New vault to be used by the pool.

LiquidityPool.prepareNewRequiredReserves(uint256 newRatio) external returns (uint256)

Prepare new required reserves ratio of locked underlying.

  • newRatio: Percentage of the total funds which are locked as back up collateral that may not be used to generate yield and must be idle in the pool.

LiquidityPool.setMaxBackingReserveDeviationRatio(uint256 newRatio) external

Set the maximum percentage by which the required reserve ratio may deviate. This is helpful for when rebalancing happens and can save on gas costs.

  • newRatio: Maximum deviation )(percentage) by which the required reserve ratio may deviate.

LiquidityPool.withdrawAll() external

Withdraw all funds from pool’s vault to the liquidity pool.

LiquidityPool.setStaker() external returns (bool)

Gets the address of the staker vault for the pool’s LP token from the controller.

Note

This can only be set once. If no staker vault exists yet for the LP token of the pool, the transaction will revert.

LiquidityPool.setLpToken(address _lpToken) external

Set the LP token of a pool. This can only be set once by the admin.

Parameter Updates

Parameter updates prepared by the admin may be executed by any caller once the admin delay has passed.

LiquidityPool.executeNewMinWithdrawalFee() external returns (uint256)

Execute a prepared update of the minimum withdrawal fee.

LiquidityPool.executeNewMaxWithdrawalFee() external returns (uint256)

Execute a prepared update of the maximum withdrawal fee.

LiquidityPool.executeNewWithdrawalFeeDecreasePeriod() external returns (uint256)

Execute a prepared update of the withdrawal fee decrease period.

LiquidityPool.executeNewVault() external returns (address)

Execute a prepared update of the vault.

LiquidityPool.executeNewReserveDeviation() external returns (address)

Execute a prepared update of the reserve deviation.

LiquidityPool.executeNewRequiredReserves() external returns (address)

Execute a prepared update of the required reserves.