SaplingPoolContext
SaplingPoolContext
Provides common pool functionality with lender deposits, first loss capital staking, and reward distribution.
tokenConfig
Tokens configuration
config
Pool configuration
balances
Pool balances
withdrawalAllowances
Per user withdrawal allowances with time windows
noWithdrawalRequests
Limits access only when no active withdrawal requests are present
updatedState
Modifier to update pool accounting state before function execution
__SaplingPoolContext_init
Creates a SaplingPoolContext.
Addresses must not be 0.
Name | Type | Description |
---|---|---|
_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
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.
Name | Type | Description |
---|---|---|
_targetStakePercent | uint32 | New target stake percent. |
setTargetLiquidityPercent
Set the target liquidity percent for the pool.
_targetLiquidityPercent must be inclusively between 0 and SaplingMath.HUNDRED_PERCENT. Caller must be the staker.
Name | Type | Description |
---|---|---|
_targetLiquidityPercent | uint32 | new target liquidity percent. |
setProtocolEarningPercent
Set the protocol earning percent for the pool.
_protocolEarningPercent must be inclusively between 0 and MAX_PROTOCOL_FEE_PERCENT. Caller must be the governance.
Name | Type | Description |
---|---|---|
_protocolEarningPercent | uint32 | new protocol earning percent. |
setStakerEarnFactorMax
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.
Name | Type | Description |
---|---|---|
_stakerEarnFactorMax | uint32 | new maximum for staker earn factor. |
setStakerEarnFactor
Set the staker earn factor.
_stakerEarnFactor must be inclusively between SaplingMath.HUNDRED_PERCENT and stakerEarnFactorMax. Caller must be the staker.
Name | Type | Description |
---|---|---|
_stakerEarnFactor | uint32 | new staker earn factor. |
deposit
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.
Name | Type | Description |
---|---|---|
amount | uint256 | Liquidity token amount to deposit. |
requestWithdrawalAllowance
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.
Name | Type | Description |
---|---|---|
_amount | uint256 | Liquidity token amount of allowance. |
withdraw
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.
Name | Type | Description |
---|---|---|
amount | uint256 | Liquidity token amount to withdraw. |
stake
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.
Name | Type | Description |
---|---|---|
amount | uint256 | Liquidity token amount to stake. |
unstake
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().
Name | Type | Description |
---|---|---|
amount | uint256 | Liquidity token amount to unstake. |
initialMint
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
Check liquidity token amount depositable by lenders at this time.
Return value depends on the pool state rather than caller's balance.
Name | Type | Description |
---|---|---|
[0] | uint256 | Max amount of tokens depositable to the pool. |
amountWithdrawable
Check liquidity token amount withdrawable by the caller at this time.
Return value depends on the callers balance, and is limited by pool liquidity.
Name | Type | Description |
---|---|---|
wallet | address | Address of the wallet to check the withdrawable balance of. |
Name | Type | Description |
---|---|---|
[0] | uint256 | Max amount of liquidity tokens withdrawable by the caller. |
balanceStaked
Check the staker's balance in the pool.
Name | Type | Description |
---|---|---|
[0] | uint256 | Liquidity token balance of the stake. |
balanceOf
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.
Name | Type | Description |
---|---|---|
wallet | address | Address of the wallet to check the balance of. |
Name | Type | Description |
---|---|---|
[0] | uint256 | Liquidity token balance of the wallet in this pool. |
amountUnstakable
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.
Name | Type | Description |
---|---|---|
[0] | uint256 | Max amount of liquidity tokens unstakable by the staker. |
strategyLiquidity
Current liquidity available for pool strategies such as lending or investing.
Name | Type | Description |
---|---|---|
[0] | uint256 | Strategy liquidity amount. |
poolFundsLimit
View pool funds limit based on the staked funds.
Name | Type | Description |
---|---|---|
[0] | uint256 | MAX amount of liquidity tokens allowed in the pool based on staked assets |
enter
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.
Name | Type | Description |
---|---|---|
amount | uint256 | Liquidity token amount to add to the pool on behalf of the caller. |
Name | Type | Description |
---|---|---|
[0] | uint256 | Amount of pool tokens minted and allocated to the caller. |
exit
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.
Name | Type | Description |
---|---|---|
amount | uint256 | Liquidity token amount to withdraw from the pool on behalf of the caller. |
Name | Type | Description |
---|---|---|
[0] | uint256 | Amount of pool tokens burned and taken from the caller. |
sharesToFunds
Get funds value of shares.
Name | Type | Description |
---|---|---|
shares | uint256 | Pool token amount |
Name | Type | Description |
---|---|---|
[0] | uint256 | Converted liquidity token value |
fundsToShares
Get share value of funds.
For use in all cases except for defaults. Use fundsToSharesBase for default calculations instead.
Name | Type | Description |
---|---|---|
funds | uint256 | Amount of liquidity tokens |
Name | Type | Description |
---|---|---|
[0] | uint256 | Converted pool token value |
maintainsStakeRatio
Check if the pool has sufficient stake
Name | Type | Description |
---|---|---|
[0] | bool | True if the staked funds provide at least a minimum ratio to the pool funds, False otherwise. |
totalPoolTokenSupply
poolFunds
Current amount of liquidity tokens in the pool, including liquid, in strategies, and settled yield
liquidity
Lending pool raw liquidity, same as the liquidity token balance.
Encapsulated in to a function to reduce compiled contract size.
strategizedFunds
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
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
APY breakdown given a specified scenario.
Represent percentage parameter values in contract specific format.
Name | Type | Description |
---|---|---|
_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 |
Name | Type | Description |
---|---|---|
[0] | struct IPoolContext.APYBreakdown | Pool apy with protocol, staker, and lender components broken down. |
isPpsHealthy
_Checks if given values of total shares and funds maintain acceptable conversion rate for pool entries.
Name | Type | Description |
---|---|---|
shares | uint256 | Total pool shares |
funds | uint256 | Total pool funds |
Name | Type | Description |
---|---|---|
[0] | bool | Returns true if price per share is greater than or equal to the required minimum, false otherwise |
percentDecimals
External accessor for library level percent decimals.
__gap
Slots reserved for future state variables
Last updated