Implements supply and borrow functionality.
Implements ERC4626 interface.
event CollateralAdded(address token, address account, enum TokenType ofType, uint256 amount)Emitted when collateral is added
| Name | Type | Description |
|---|---|---|
| token | address | The token added |
| account | address | The account that added the collateral. |
| ofType | enum TokenType | The type of collateral |
| amount | uint256 | The amount of token added as collateral |
event CollateralRemoved(address token, address account, enum TokenType ofType, uint256 amount)Emitted when collateral is removed
| Name | Type | Description |
|---|---|---|
| token | address | The token removed. |
| account | address | The account that removed the collateral. |
| ofType | enum TokenType | The type of collateral |
| amount | uint256 | The amount of token removed as collateral |
event AssetBorrowed(address account, uint256 amount, uint256 debtMinted)Emitted when assets are borrowed.
| Name | Type | Description |
|---|---|---|
| account | address | The account that borrowed assets. |
| amount | uint256 | The amount of assets borrowed. |
| debtMinted | uint256 | The amount of debt token created. |
event AssetRepaid(address account, address repaidBy, uint256 amount, uint256 debtBurned)Emitted when borrowed assets are repaid.
| Name | Type | Description |
|---|---|---|
| account | address | The account that repaid assets. |
| repaidBy | address | The account doing the repayment. This is the same as account in normal repayment with putAmount or putShares. In case of liquidation, this is the address of the liquidator. |
| amount | uint256 | The amount of assets repaid. |
| debtBurned | uint256 | The amount of debt token burned. |
event InterestAccrued(address caller, uint256 interest, uint256 totalDebt, uint256 totalAssets)Emitted when interest is accrued
called on all state changing functions.
| Name | Type | Description |
|---|---|---|
| caller | address | indexed param of the caller of the action that triggered interest accrual. |
| interest | uint256 | The amount of interest accrued. |
| totalDebt | uint256 | The total amount debt pending. |
| totalAssets | uint256 | The total amount of assets including interest. |
event MintToReserve(address caller, uint256 shares, uint256 amount)Emitted when pool share tokens are minted to reserve to cover fees.
| Name | Type | Description |
|---|---|---|
| caller | address | Caller of function that triggered event. |
| shares | uint256 | The amount of shares to mint. |
| amount | uint256 | The corresponding amount of asset for shares minted. |
event GaugeSet(address gauge, address caller)Emitted when the rewards gauge is set
| Name | Type | Description |
|---|---|---|
| gauge | address | The gauge address. |
| caller | address | The account that set the gauge. |
event StakingPoolSet(address pool, address caller)Emitted when the staking pool for this lending pool is set
| Name | Type | Description |
|---|---|---|
| pool | address | The pool address. |
| caller | address | The account that set the gauge. |
event SupplyCapSet(uint256 cap, address caller)Emitted when the supply cap is set.
| Name | Type | Description |
|---|---|---|
| cap | uint256 | The new supply cap. |
| caller | address | The account that set the gauge. |
event CollateralParamsSet(address token, uint256 ltv, uint256 lltv, uint256 liqPenalty, uint256 liqBonus)Explain to an end user what this does
Explain to a developer any extra details
| Name | Type | Description |
|---|---|---|
| token | address | |
| ltv | uint256 | Max loan to value. |
| lltv | uint256 | Max liquidation loan to value. |
| liqPenalty | uint256 | Liquidation penalty (goes to reserve). |
| liqBonus | uint256 | Liquidation bonus (goes to liquidator). |
event PositionLiquidated(address account, address liquidator, address collateral, uint256 repayAmount)Emitted when a position is successfully liquidated.
| Name | Type | Description |
|---|---|---|
| account | address | The account being liquidated. |
| liquidator | address | The caller of the function. |
| collateral | address | The collateral token to liquidate. |
| repayAmount | uint256 | The amount of debt being repaid by the liquidator. |
event PoolState(address pool, address caller, uint256 timestamp, uint256 supplied, uint256 borrowed, uint256 supplyRate, uint256 borrowRate)Emitted any time the pool state changes
Pool state changes on supply, withdraw, take or put.
Also called from the updatePoolState() function.
| Name | Type | Description |
|---|---|---|
| pool | address | The pool address emitting this event. This is indexed. |
| caller | address | |
| timestamp | uint256 | The timestamp of the event. This is indexed. |
| supplied | uint256 | The total amount supplied to the pool. |
| borrowed | uint256 | The total amount borrowed from the pool. |
| supplyRate | uint256 | The base supply APY. |
| borrowRate | uint256 | The base borrow APR. |
event CollaterallizeAsset(address account, bool useAsCollateral)event CallbackApproved(address callback, bool isApproved)Emitted when flashLiquidateWhitelist is updated
| Name | Type | Description |
|---|---|---|
| callback | address | The address to whitelist or not |
| isApproved | bool | true of false |
error CheddaPool_CollateralNotAllowed(address token)Thrown when a caller tries to deposit a token for collateral that is not allowed
error CheddaPool_CollateralAlreadyAdded(address token)Thrown when adding collateral that has already been added during initialization.
error CheddaPool_ZeroAmount()Thrown when a caller tries to supply/deposit 0 amount of asset/collateral.
error CheddaPool_SupplyCapExceeded(uint256 cap, uint256 supplied)Thrown when the supply cap is exceeded.
error CheddaPool_InsufficientCollateral(address account, address token, uint256 amountRequested, uint256 amountDeposited)Thrown when a caller tries to withdraw more collateral than they have deposited.
error CheddaPool_AccountNotCollateralized(address account)Thrown when the account does not have sufficient collateral.
error CheddaPool_AccountSolvent(address account, uint256 health)Thrown when attempting to liquidate a solvent account.
error CheddaPool_InsufficientAssetBalance(uint256 available, uint256 requested)Thrown when a caller tries withdraw more asset than supplied.
error CheddaPool_Overpayment()Thrown when a caller tries to repay more debt than they owe.
error CheddaPool_AssetMustBeSupplied()Thrown when a caller tries to deposit the asset token as collateral.
error CheddaPool_AsssetMustBeWithdrawn()Thrown when a caller tries to remove asset token from collateral. withdraw must be used instead.
error CheddaPool_ZeroShares()Thrown when withdrawing or depositing zero shares
error CheddaPool_BadPrice(address asset, uint256 price)Thrown if the asset price is invalid.
error CheddaPool_StalePrice(address asset, uint256 lastUpdated)Thrown if the asset price is stale.
error CheddaPool_InvalidLiquidation()Thrown in an invalid liquidation call.
error CheddaPool_UnsupportedCollateral(address collateralToken)Thrown when trying to calculate the value of unsupported collateral token
error CheddaPool_InvalidCollateralParams()Thrown when setting invalid collateral params
error CheddaPool_CallbackNotApproved(address callback)Thrown when a non approved callback is used in flashLiquidate()
uint256 suppliedstate vars
uint256 totalReserveShareslifetime shares minted to reserve
string characterizationdisplay name of thi spool
contract DebtToken debtTokenDebt and interest
contract IAddressRegistry registrycontract IPriceFeed priceFeedcontract IInterestRateModel interestRatesModelstruct InterestRates interestRatescontract ILockingGauge gaugecontract IStakingPool stakingPooladdress[] collateralTokenListCollateral
mapping(address => bool) collateralAllowedmapping(address => bool) assetCollateralizedmapping(address => struct CollateralParams) collateralParamsmapping(address => mapping(address => struct CollateralDeposit)) accountCollateralDepositedmapping(address => uint256) tokenCollateralDepositedmapping(address => bool) approvedCallbacksaddresses approved to be used as callbacks
uint256 maxAccountHealthThe max value for account health. This is returned if user has no debt.
uint256 supplyCapPool asset supply cap
uint256 reserveFactorPercentage of interest that goes to reserve. 1e18 = 100%
uint256 stalePriceThresholdaddress reserveaddress to receive reserve funds
mapping(address => address) icmAccountCollateralinitialization
struct InitParams {
string name;
address asset;
address priceFeed;
address interestRatesModel;
address owner;
address registry;
address reserve;
uint256 reserveFactor;
uint256 initialSupplyCap;
uint256 stalePriceThreshold;
struct CollateralInfoInit[] collaterals;
}constructor(struct LendingPool.InitParams initParams) publicfunction setGauge(address _gauge) externalSet the rewards gauge for this pool.
Can only be called by contract owner Emits GaugeSet(gauge, caller).
function setStakingPool(address sPool) externalSet the staking pool for this pool.
Can only be called by contract owner Emits StakingPoolSet(sPool, caller).
function setSupplyCap(uint256 _supplyCap) externalSets the supply cap in this pool.
This is the maximum amount that can be supplied in this pool.
| Name | Type | Description |
|---|---|---|
| _supplyCap | uint256 | The new supply cap |
function setCallbackApproved(address callback, bool isApproved) externalapproves or disapproves a callback address
function setCollateralParams(address token, struct CollateralParams params) externalfunction supply(uint256 amount, address receiver, bool useAsCollateral) external returns (uint256 shares)Supplies assets to pool
if useAsCollateral is true, and receiver != msg.sender, collateral is added to
receiver's collateral balance.
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount to supply |
| receiver | address | The account to mint share tokens to |
| useAsCollateral | bool | Whethe this deposit should be marked as collateral |
| Name | Type | Description |
|---|---|---|
| shares | uint256 | The amount of shares minted. |
function withdraw(uint256 assetAmount, address receiver, address owner) public returns (uint256 shares)Withdraws a specified amount of assets from pool
If user has added this asset as collateral a collateral amount will be removed.
if owner != msg.sender there must be an existing approval >= assetAmount
| Name | Type | Description |
|---|---|---|
| assetAmount | uint256 | The amount to withdraw |
| receiver | address | The account to receive withdrawn assets |
| owner | address | The account to withdraw assets from. |
| Name | Type | Description |
|---|---|---|
| shares | uint256 | The amount of shares burned by withdrawal. |
function redeem(uint256 shares, address receiver, address owner) public returns (uint256 assetAmount)Withdraws and burns a specified amount of shares.
If user has added this asset as collateral a collateral amount will be removed. if owner != msg.sender there must be an existing approval >= assetAmount
| Name | Type | Description |
|---|---|---|
| shares | uint256 | The share amount to redeem. |
| receiver | address | The account to receive withdrawn assets |
| owner | address | The account to withdraw assets from. |
| Name | Type | Description |
|---|---|---|
| assetAmount | uint256 | The amount of assets repaid. |
function take(uint256 amount) external returns (uint256 debtCreated)Borrows asset from the pool.
The max amount a user can borrow must be less than the value of their collateral weighted against the loan to value ratio of that colalteral. Emits AssetBorrowed(account, amount, debt) event.
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount to borrow |
| Name | Type | Description |
|---|---|---|
| debtCreated | uint256 | The amount of debt token minted. |
function putAmount(uint256 amount) external returns (uint256 debtBurned)Repays a part or all of a loan.
Emits AssetRepaid(account, amount, debtBurned).
| Name | Type | Description |
|---|---|---|
| amount | uint256 | amount to repay. Must be > 0 and <= amount borrowed by sender |
| Name | Type | Description |
|---|---|---|
| debtBurned | uint256 | The amount of debt shares burned by this repayment. |
function putShares(uint256 shares) external returns (uint256 amountRepaid)Repays a part or all of a loan by specifying the amount of debt token to repay.
Emits AssetRepaid(account, amountRepaid, shares).
| Name | Type | Description |
|---|---|---|
| shares | uint256 | The share of debt token to repay. |
| Name | Type | Description |
|---|---|---|
| amountRepaid | uint256 | the amount repaid. |
function collateralize(bool useAsCollateral) externalManaging collateral logic
function addCollateral(address token, uint256 amount) externalAdd ERC-20 token collateral to pool.
Emits CollateralAdded(address token, address account, uint tokenType, uint amount).
| Name | Type | Description |
|---|---|---|
| token | address | The token to deposit as collateral. |
| amount | uint256 | The amount of token to deposit. |
function removeCollateral(address token, uint256 amount) externalRemoves ERC20 collateral from pool.
Emits CollateralRemoved(token, account, type, amount).
| Name | Type | Description |
|---|---|---|
| token | address | The collateral token to remove. |
| amount | uint256 | The amount to remove. |
Struct passed in to liquidation functions.
Contains parameters forliquidation.
| Name | Type | Description |
|---|
struct LiquidateParams {
address borrower;
address receiver;
address collateral;
uint256 repayAmount;
}function batchLiquidate(struct LendingPool.LiquidateParams[] params) external returns (uint256[])Allows an account to liquidate a borrower's position if their health factor falls below 1.0e18.
Throws the CheddaPool_InvalidLiquidation error if there is a mismatch in length of any of
borrowers, collateralTokens, repayAmounts.
Throws CheddaPool_InvalidLiquidation error if health of a borrower after liquidation is not
greater than the health before liquidation.
| Name | Type | Description |
|---|---|---|
| params | struct LendingPool.LiquidateParams[] | Array of LiquidateParams objects specifying parameters for liquidations. |
| Name | Type | Description |
|---|---|---|
| [0] | uint256[] | collateralAmounts The amounts of collateral removed. |
function flashLiquidate(struct LendingPool.LiquidateParams params, address callback, bytes data) external returns (uint256)Explain to an end user what this does
Explain to a developer any extra details
| Name | Type | Description |
|---|---|---|
| params | struct LendingPool.LiquidateParams | Array of LiquidateParams objects specifying parameters for liquidations. |
| callback | address | |
| data | bytes |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | totalCollateralAmount The amount of collateral the liquidator received. |
function getPrice(address asset, bool checkAge) public view returns (uint256)View functions Reads the price of an asset from the oracle
Explain to a developer any extra details
| Name | Type | Description |
|---|---|---|
| asset | address | The asset to return price for |
| checkAge | bool | Check if the price has been updated recently. Revert if checkAge is true and price is stale. |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The price of the asset. |
function totalAccountCollateralValue(address account, enum AccountValue valueType) public view returns (uint256 accountValue)Returns the total value of an account including asset and collateral.
| Name | Type | Description |
|---|---|---|
| account | address | The account to get collateral value for. |
| valueType | enum AccountValue | Determines how the value is calculated. This is of enum AccountValue. |
| Name | Type | Description |
|---|---|---|
| accountValue | uint256 | The value of collateral deposited by account. |
function accountCollateralAmount(address account, address collateral) public view returns (uint256 collateralAmount)Returns the amount of a given token an account has deposited as collateral
| Name | Type | Description |
|---|---|---|
| account | address | The account to check collateral for |
| collateral | address | The collateral to check |
| Name | Type | Description |
|---|---|---|
| collateralAmount | uint256 | The amount of collateral token account has deposited. |
function assetsBorrowed(address account) public view returns (uint256)Returns the amount of asset an account has borrowed, including any accrued interest.
| Name | Type | Description |
|---|---|---|
| account | address | The account to check for. |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | amount The amount of account borrowed by account. |
function accountHealth(address account) public view returns (uint256 health)Returns the health ratio of the account health > 1.0 means the account is solvent. health <1.0 but != 0 means account is insolvent health == 0 means account has no debt and is also solvent.
| Name | Type | Description |
|---|---|---|
| account | address | The account to check. |
| Name | Type | Description |
|---|---|---|
| health | uint256 | The health ration of the account, to 1e18. i.e 1e18 = 1.0 health. |
function collaterals() external view returns (address[])function calculateCollateralAmount(uint256 assetAmount, address collateralToken, bool useLTV) public view returns (uint256 collateralAmount)function tokenMarketValue(address token, uint256 amount) public view returns (uint256)Returns the market value of a given number of token.
| Name | Type | Description |
|---|---|---|
| token | address | The token to return value for. |
| amount | uint256 | The amount of token to calculate the value of. |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | value The market value of amount of token. |
function tokenLoanValue(address token, uint256 amount) public view returns (uint256)Returns the value as collateral for a given amount of token
This takes into account the loan to value (LTV) ratio.
| Name | Type | Description |
|---|---|---|
| token | address | The token to return value for. |
| amount | uint256 | The amount of token to calculate the value of. |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | value The collateral value of amount of token. |
function tokenLiquidationValue(address token, uint256 amount) public view returns (uint256)Returns the value as collateral for a given amount of token
This takes into account the lltv.
| Name | Type | Description |
|---|---|---|
| token | address | The token to return value for. |
| amount | uint256 | The amount of token to calculate the value of. |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | value The collateral value of amount of token. |
function collateralInfo(address token) external view returns (struct CollateralParams)Returns the collateral configuration for a given token;
| Name | Type | Description |
|---|---|---|
| token | address | The token to return collateral info for. |
| Name | Type | Description |
|---|---|---|
| [0] | struct CollateralParams | The CollateralParams for requested token. |
function updatePoolState() externaltake a snapshot of the current pool state.
function isSolvent(address account) external view returns (bool)Checks if account is solvent. In simple terms, an account is solvent if collateralMarketValue * liquidation threshold > debt.
| Name | Type | Description |
|---|---|---|
| account | address | account to check for. |
| Name | Type | Description |
|---|---|---|
| [0] | bool | If the account is solvent. |
function isCollateralized(address account) public view returns (bool)Checks if account has enough collateral after currnet operation completes.
In simple terms, an account is collateralized if collateralMarketValue * ltv > debt.
| Name | Type | Description |
|---|---|---|
| account | address | account to check for. |
| Name | Type | Description |
|---|---|---|
| [0] | bool | If the account is collateralized. |
function accrueInterest() publicfunction poolAsset() external view returns (contract ERC20)Returns the asset that can be borrowed from this pool
| Name | Type | Description |
|---|---|---|
| [0] | contract ERC20 | asset The pool asset |
function assetBalance(address account) public view returns (uint256)The amount of asset an account can access.
This is based on the number of pool shares an account holds.
| Name | Type | Description |
|---|---|---|
| account | address | The account to check the balance of. |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | amount The amount of asset an account holds in the pool. |
function totalAssets() public view returns (uint256)The total amount of asset deposited into the pool.
This includes assets that have been borrowed.
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | amount The total assets supplied to pool. |
function transfer(address to, uint256 amount) public returns (bool success)Transfer tokens from caller to another address.
Overrides ERC-20 transfer to add health checks after transfers
| Name | Type | Description |
|---|---|---|
| to | address | address to send to |
| amount | uint256 | amount to send |
| Name | Type | Description |
|---|---|---|
| success | bool | True if transfer is successful, false otherwise. |
function transferFrom(address from, address to, uint256 amount) public returns (bool success)Transfer tokens from a given address to another.
Overrides ERC-20 transferFrom to add health checks after transfers.
Caller must have an allowance to transfer from from address.
| Name | Type | Description |
|---|---|---|
| from | address | address to send from |
| to | address | address to send to |
| amount | uint256 | amount to send |
| Name | Type | Description |
|---|---|---|
| success | bool | True if transfer is successful, false otherwise. |
function available() public view returns (uint256 assetAmount)The assets available to be borrowed from pool.
| Name | Type | Description |
|---|---|---|
| assetAmount | uint256 | The amount of asset available in pool. |
function borrowed() public view returns (uint256 assetAmount)The assets borrowed from pool.
| Name | Type | Description |
|---|---|---|
| assetAmount | uint256 | The amount of asset borrowed from pool, including accrued interest. |
function tvl(bool countBorrows) external view returns (uint256 totalValue)The total value locked in this pool.
TVL is calculated as assets supplied + collateral deposited.
| Name | Type | Description |
|---|---|---|
| countBorrows | bool | Flag indicating if the borrows should be included in TVL calculation. |
| Name | Type | Description |
|---|---|---|
| totalValue | uint256 | The total value locked in pool. |
function baseSupplyAPY() external view returns (uint256 apy)Returns the base supply APY.
This is the interest earned on supplied assets.
| Name | Type | Description |
|---|---|---|
| apy | uint256 | The interest earned on supplied assets. |
function baseBorrowAPY() external view returns (uint256 apy)Returns the base borrow APY.
This is the interest paid on borrowed assets.
| Name | Type | Description |
|---|---|---|
| apy | uint256 | The interest paid on borrowed assets. |
function utilization() public view returns (uint256 u)The pool asset utilization
This is the amount of asset borrowed divided by assets supplied.
| Name | Type | Description |
|---|---|---|
| u | uint256 | The pool asset utilization. |
function beforeWithdraw(uint256 assets, uint256) internaldeposit/withdraw hooks
function afterDeposit(uint256 assets, uint256) internalfunction version() external pure returns (uint16)Returns the version of the pool
| Name | Type | Description |
|---|---|---|
| [0] | uint16 | The version |