SaplingPoolContext

SaplingPoolContext

Provides common pool functionality with lender deposits, first loss capital staking, and reward distribution.

tokenConfig

struct IPoolContext.TokenConfig tokenConfig

Tokens configuration

config

struct IPoolContext.PoolConfig config

Pool configuration

balances

struct IPoolContext.PoolBalance balances

Pool balances

withdrawalAllowances

mapping(address => struct IPoolContext.WithdrawalAllowance) withdrawalAllowances

Per user withdrawal allowances with time windows

noWithdrawalRequests

modifier noWithdrawalRequests()

Limits access only when no active withdrawal requests are present

updatedState

modifier updatedState()

Modifier to update pool accounting state before function execution

__SaplingPoolContext_init

function __SaplingPoolContext_init(address _poolToken, address _liquidityToken, address _accessControl, address _stakerAddress) internal

Creates a SaplingPoolContext.

Addresses must not be 0.

NameTypeDescription

_poolToken

address

ERC20 token contract address to be used as the pool issued token.

_liquidityToken

address

ERC20 token contract address to be used as pool liquidity currency.

_accessControl

address

Access control contract

_stakerAddress

address

Staker address

setTargetStakePercent

function setTargetStakePercent(uint32 _targetStakePercent) external

Set the target stake percent for the pool.

_targetStakePercent must be greater than 0 and less than or equal to SaplingMath.HUNDRED_PERCENT. Caller must be the governance.

NameTypeDescription

_targetStakePercent

uint32

New target stake percent.

setTargetLiquidityPercent

function setTargetLiquidityPercent(uint32 _targetLiquidityPercent) external

Set the target liquidity percent for the pool.

_targetLiquidityPercent must be inclusively between 0 and SaplingMath.HUNDRED_PERCENT. Caller must be the staker.

NameTypeDescription

_targetLiquidityPercent

uint32

new target liquidity percent.

setProtocolEarningPercent

function setProtocolEarningPercent(uint32 _protocolEarningPercent) external

Set the protocol earning percent for the pool.

_protocolEarningPercent must be inclusively between 0 and MAX_PROTOCOL_FEE_PERCENT. Caller must be the governance.

NameTypeDescription

_protocolEarningPercent

uint32

new protocol earning percent.

setStakerEarnFactorMax

function setStakerEarnFactorMax(uint32 _stakerEarnFactorMax) external

Set an upper bound for the staker earn factor.

_stakerEarnFactorMax must be greater than or equal to SaplingMath.HUNDRED_PERCENT. If the current earn factor is greater than the new maximum, then the current earn factor is set to the new maximum. Caller must be the governance.

NameTypeDescription

_stakerEarnFactorMax

uint32

new maximum for staker earn factor.

setStakerEarnFactor

function setStakerEarnFactor(uint32 _stakerEarnFactor) external

Set the staker earn factor.

_stakerEarnFactor must be inclusively between SaplingMath.HUNDRED_PERCENT and stakerEarnFactorMax. Caller must be the staker.

NameTypeDescription

_stakerEarnFactor

uint32

new staker earn factor.

deposit

function deposit(uint256 amount) external

Deposit funds to the pool. Depositing funds will mint an equivalent amount of pool tokens and transfer it to the caller. Exact exchange rate depends on the current pool state.

Deposit amount must be non zero and not exceed amountDepositable(). An appropriate spend limit must be present at the token contract. Caller must be a user. Caller must not have any outstanding withdrawal requests.

NameTypeDescription

amount

uint256

Liquidity token amount to deposit.

requestWithdrawalAllowance

function requestWithdrawalAllowance(uint256 _amount) external

Request withdrawal allowance.

Allowance amount must not exceed current balance. Withdrawal allowance is active after 1 minute of request, and is valid for a single use within 10 minutes after becoming active.

NameTypeDescription

_amount

uint256

Liquidity token amount of allowance.

withdraw

function withdraw(uint256 amount) public

Withdraw funds from the pool. Withdrawals redeem equivalent amount of the caller's pool tokens by burning the tokens in question. Exact exchange rate depends on the current pool state.

Withdrawal amount must be non zero and not exceed amountWithdrawable(). Must have a valid withdrawal allowance.

NameTypeDescription

amount

uint256

Liquidity token amount to withdraw.

stake

function stake(uint256 amount) external

Stake funds into the pool. Staking funds will mint an equivalent amount of pool tokens and lock them in the pool. Exact exchange rate depends on the current pool state.

Caller must be the staker. Stake amount must be non zero. An appropriate spend limit must be present at the token contract.

NameTypeDescription

amount

uint256

Liquidity token amount to stake.

unstake

function unstake(uint256 amount) external

Unstake funds from the pool. Unstaking redeems equivalent amount of the caller's pool tokens locked in the pool by burning the tokens in question.

Caller must be the staker. Unstake amount must be non zero and not exceed amountUnstakable().

NameTypeDescription

amount

uint256

Liquidity token amount to unstake.

initialMint

function initialMint() external

Mint initial minimum amount of pool tokens and lock them into the access control contract, which is non upgradable - locking them forever.

Caller must be the staker. An appropriate spend limit must be present at the asset token contract. This function can only be called when the total pool token supply is zero.

amountDepositable

function amountDepositable() public view returns (uint256)

Check liquidity token amount depositable by lenders at this time.

Return value depends on the pool state rather than caller's balance.

NameTypeDescription

[0]

uint256

Max amount of tokens depositable to the pool.

amountWithdrawable

function amountWithdrawable(address wallet) public view returns (uint256)

Check liquidity token amount withdrawable by the caller at this time.

Return value depends on the callers balance, and is limited by pool liquidity.

NameTypeDescription

wallet

address

Address of the wallet to check the withdrawable balance of.

NameTypeDescription

[0]

uint256

Max amount of liquidity tokens withdrawable by the caller.

balanceStaked

function balanceStaked() external view returns (uint256)

Check the staker's balance in the pool.

NameTypeDescription

[0]

uint256

Liquidity token balance of the stake.

balanceOf

function balanceOf(address wallet) public view returns (uint256)

Check wallet's funds balance in the pool. This balance includes deposited balance and acquired yield. This balance does not included staked balance, balance locked in withdrawal requests, leveraged earnings or protocol revenue.

NameTypeDescription

wallet

address

Address of the wallet to check the balance of.

NameTypeDescription

[0]

uint256

Liquidity token balance of the wallet in this pool.

amountUnstakable

function amountUnstakable() public view returns (uint256)

Check funds amount unstakable by the staker at this time.

Return value depends on the staked balance and targetStakePercent, and is limited by pool liquidity.

NameTypeDescription

[0]

uint256

Max amount of liquidity tokens unstakable by the staker.

strategyLiquidity

function strategyLiquidity() public view returns (uint256)

Current liquidity available for pool strategies such as lending or investing.

NameTypeDescription

[0]

uint256

Strategy liquidity amount.

poolFundsLimit

function poolFundsLimit() public view returns (uint256)

View pool funds limit based on the staked funds.

NameTypeDescription

[0]

uint256

MAX amount of liquidity tokens allowed in the pool based on staked assets

enter

function enter(uint256 amount) private returns (uint256)

Internal method to enter the pool with a liquidity token amount. If the caller is the staker, entered funds are considered staked. New pool tokens are minted in a way that will not influence the current share price. Shares are equivalent to pool tokens and are represented by them.

NameTypeDescription

amount

uint256

Liquidity token amount to add to the pool on behalf of the caller.

NameTypeDescription

[0]

uint256

Amount of pool tokens minted and allocated to the caller.

exit

function exit(uint256 amount) private returns (uint256)

Internal method to exit the pool with funds amount. Amount must not exceed amountWithdrawable() for non-stakers, and amountUnstakable() for the staker. If the caller is the staker, exited funds are considered unstaked. Pool tokens are burned in a way that will not influence the current share price. Shares are equivalent to pool tokens and are represented by them.

NameTypeDescription

amount

uint256

Liquidity token amount to withdraw from the pool on behalf of the caller.

NameTypeDescription

[0]

uint256

Amount of pool tokens burned and taken from the caller.

sharesToFunds

function sharesToFunds(uint256 shares) public view returns (uint256)

Get funds value of shares.

NameTypeDescription

shares

uint256

Pool token amount

NameTypeDescription

[0]

uint256

Converted liquidity token value

fundsToShares

function fundsToShares(uint256 funds) public view returns (uint256)

Get share value of funds.

For use in all cases except for defaults. Use fundsToSharesBase for default calculations instead.

NameTypeDescription

funds

uint256

Amount of liquidity tokens

NameTypeDescription

[0]

uint256

Converted pool token value

maintainsStakeRatio

function maintainsStakeRatio() public view returns (bool)

Check if the pool has sufficient stake

NameTypeDescription

[0]

bool

True if the staked funds provide at least a minimum ratio to the pool funds, False otherwise.

totalPoolTokenSupply

function totalPoolTokenSupply() internal view returns (uint256)

poolFunds

function poolFunds() public view returns (uint256)

Current amount of liquidity tokens in the pool, including liquid, in strategies, and settled yield

liquidity

function liquidity() public view returns (uint256)

Lending pool raw liquidity, same as the liquidity token balance.

Encapsulated in to a function to reduce compiled contract size.

strategizedFunds

function strategizedFunds() internal view virtual returns (uint256)

Current amount of liquidity tokens in strategies, including both allocated and committed but excluding pending yield.

Implement in the extending contract that handles the strategy, i.e. Lending pool.

settleYield

function settleYield() public virtual

Settle pending yield.

Calculates interest due since last update and increases preSettledYield, taking into account the protocol fee and the staker earnings. Implement in the Lending Pool.

projectedAPYBreakdown

function projectedAPYBreakdown(uint256 _totalPoolTokens, uint256 _stakedTokens, uint256 _poolFunds, uint256 _strategizedFunds, uint256 _avgStrategyAPR, uint32 _protocolFeePercent, uint32 _stakerEarnFactor) public pure returns (struct IPoolContext.APYBreakdown)

APY breakdown given a specified scenario.

Represent percentage parameter values in contract specific format.

NameTypeDescription

_totalPoolTokens

uint256

total pull token supply. For current conditions use: totalPoolTokenSupply()

_stakedTokens

uint256

the amount of staked pool tokens. Must be less than or equal to _totalPoolTokens. For current conditions use: balances.stakedShares

_poolFunds

uint256

liquidity token funds that make up the pool. For current conditions use: poolFunds()

_strategizedFunds

uint256

part of the pool funds that will remain in strategies. Must be less than or equal to _poolFunds. For current conditions use: strategizedFunds()

_avgStrategyAPR

uint256

Weighted average APR of the funds in strategies. For current conditions use: ILoanDesk(loanDesk).weightedAvgAPR()

_protocolFeePercent

uint32

Protocol fee parameter. Must be less than 100%. For current conditions use: config.protocolFeePercent

_stakerEarnFactor

uint32

Staker's earn factor. Must be greater than or equal to 1x (100%). For current conditions use: config.stakerEarnFactor

NameTypeDescription

[0]

struct IPoolContext.APYBreakdown

Pool apy with protocol, staker, and lender components broken down.

isPpsHealthy

function isPpsHealthy(uint256 shares, uint256 funds) private pure returns (bool)

_Checks if given values of total shares and funds maintain acceptable conversion rate for pool entries.

 Set PPS_RATE_CHECK_DIVISOR as a divisor derived from a percentage.
 i.e. When the PPS_RATE_CHECK_DIVISOR is 20, method returns false if PPS has fallen over 95% from initial rate._
NameTypeDescription

shares

uint256

Total pool shares

funds

uint256

Total pool funds

NameTypeDescription

[0]

bool

Returns true if price per share is greater than or equal to the required minimum, false otherwise

percentDecimals

function percentDecimals() external pure returns (uint8)

External accessor for library level percent decimals.

__gap

uint256[43] __gap

Slots reserved for future state variables

Last updated