IonPool
Inherits: PausableUpgradeable, RewardModule
IonPool
is the central contract of the Ion Protocol system. All other contracts in the system revolve around it. Directly interacting with IonPool
may be unintuitive and it is recommended to interface with the protocol through Handler contracts for a more UX-friendly experience.
State Variables
GEM_JOIN_ROLE
LIQUIDATOR_ROLE
ADDRESS_THIS
IonPoolStorageLocation
Functions
onlyWhitelistedBorrowers
onlyWhitelistedLenders
_getIonPoolStorage
constructor
initialize
initializeIlk
Initializes a market with a new collateral type.
This function and the entire protocol as a whole operates under the assumption that there will never be more than 256 collaterals.
Parameters
Name | Type | Description |
---|---|---|
|
| address of the ERC-20 collateral. |
updateIlkSpot
Updates the spot oracle for a given collateral.
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| address of the new spot oracle. |
updateIlkDebtCeiling
A market can be sunset by setting the debt ceiling to 0. It would still be possible to repay debt but creating new debt would not be possible.
Updates the debt ceiling for a given collateral.
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| new debt ceiling. |
updateIlkDust
When increasing the dust
, it is possible that some vaults will be dusty after the update. However, changes to the vault position from there will require that the vault be non-dusty (either by repaying all debt or increasing debt beyond the dust
).
Updates the dust amount for a given collateral.
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| new dust |
updateSupplyCap
Reducing the supply cap will not affect existing deposits. However, if it is below the totalSupply
, then no new deposits will be allowed until the totalSupply
is below the new supplyCap
.
Updates the supply cap.
Parameters
Name | Type | Description |
---|---|---|
|
| new supply cap. |
updateInterestRateModule
Updates the interest rate module. There is a check to ensure that collateralCount()
on the new interest rate module match the current number of collaterals in the pool.
Parameters
Name | Type | Description |
---|---|---|
|
| new interest rate module. |
updateWhitelist
Updates the whitelist.
Parameters
Name | Type | Description |
---|---|---|
|
| new whitelist address. |
pause
Pause actions but accrue interest as well.
unpause
Unpause actions but this will also update the lastRateUpdate
to the unpause transaction timestamp. This essentially allows for a pausing and unpausing of the accrual of interest.
accrueInterest
Updates accumulators for all ilk
s based on current interest rates.
Returns
Name | Type | Description |
---|---|---|
|
| the new total debt after interest accrual |
_accrueInterest
calculateRewardAndDebtDistribution
calculateRewardAndDebtDistributionForIlk
This is primarily for simulation purposes to see how an individual ilk's state will change after an accrual.
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
Returns
Name | Type | Description |
---|---|---|
|
| the rate increase for the ilk. |
|
| the timestamp increase for the ilk. |
_calculateRewardAndDebtDistributionForIlk
withdraw
Allows lenders to redeem their interest-bearing position for the underlying asset. It is possible that dust amounts more of the position are burned than the underlying received due to rounding.
Parameters
Name | Type | Description |
---|---|---|
|
| the address to which the redeemed underlying asset should be sent to. |
|
| of underlying to reedeem for. |
supply
Allows lenders to deposit their underlying asset into the pool and earn interest on it.
Parameters
Name | Type | Description |
---|---|---|
|
| the address to receive credit for the position. |
|
| of underlying asset to use to create the position. |
|
| merkle proof that the user is whitelisted. |
borrow
Allows a borrower to create debt in a position.
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| to create the position for. |
|
| to receive the borrowed funds |
|
| to create. |
|
| merkle proof that the user is whitelist. |
repay
Allows a borrower to repay debt in a position.
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| to repay the debt for. |
|
| to source the funds from. |
|
| to repay. |
withdrawCollateral
Moves collateral from internal vault.collateral
balances to gem
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| to withdraw the collateral for. |
|
| to receive the collateral. |
|
| to withdraw. |
depositCollateral
Moves collateral from gem
balances to internal vault.collateral
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| to deposit the collateral for. |
|
| to deposit the collateral from. |
|
| to deposit. |
|
| merkle proof that the user is whitelisted. |
_modifyPosition
repayBadDebt
To be used by protocol to settle bad debt using reserves NOTE: Can pay another user's bad debt with the sender's asset
Parameters
Name | Type | Description |
---|---|---|
|
| the address that owns the bad debt being paid off |
|
| amount of debt to be repaid (45 decimals) |
_transferWeth
Helper function to deal with borrowing and repaying debt. A positive amount is a borrow while negative amount is a repayment
Parameters
Name | Type | Description |
---|---|---|
|
| receiver if transfer to, or sender if transfer from |
|
| amount to transfer [RAD] |
confiscateVault
This function foregoes pausability for pausability at the liquidation module layer
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral. |
|
| user to confiscate the vault from. |
|
| address to either credit |
|
| |
|
| collateral to add or remove from the vault |
|
| debt to add or remove from the vault |
mintAndBurnGem
To be called by GemJoin contracts. After a user deposits collateral, credit the user with collateral internally
Parameters
Name | Type | Description |
---|---|---|
|
| collateral |
|
| user |
|
| amount to add or remove |
transferGem
Transfer gem across the internal accounting of the pool
Parameters
Name | Type | Description |
---|---|---|
|
| index of the collateral |
|
| source of the gem |
|
| destination of the gem |
|
| amount of gem |
ilkCount
Returns
Name | Type | Description |
---|---|---|
|
| The total amount of collateral in the pool. |
getIlkIndex
Returns
Name | Type | Description |
---|---|---|
|
| The index of the collateral with |
getIlkAddress
Returns
Name | Type | Description |
---|---|---|
|
| The address of the collateral at index |
addressContains
Returns
Name | Type | Description |
---|---|---|
|
| Whether or not an address is a supported collateral. |
totalNormalizedDebt
Returns
Name | Type | Description |
---|---|---|
|
| The total amount of normalized debt for collateral with index |
rateUnaccrued
rate
Returns
Name | Type | Description |
---|---|---|
|
| The rate (debt accumulator) for collateral with index |
lastRateUpdate
Returns
Name | Type | Description |
---|---|---|
|
| The timestamp of the last rate update for collateral with index |
spot
Returns
Name | Type | Description |
---|---|---|
|
| The spot oracle for collateral with index |
debtCeiling
Returns
Name | Type | Description |
---|---|---|
|
| debt ceiling for collateral with index |
dust
Returns
Name | Type | Description |
---|---|---|
|
| dust amount for collateral with index |
collateral
Returns
Name | Type | Description |
---|---|---|
|
| The amount of collateral |
normalizedDebt
Returns
Name | Type | Description |
---|---|---|
|
| The amount of normalized debt |
vault
Returns
Name | Type | Description |
---|---|---|
|
| All data within vault for |
|
|
gem
Returns
Name | Type | Description |
---|---|---|
|
| Amount of |
unbackedDebt
Returns
Name | Type | Description |
---|---|---|
|
| The amount of unbacked debt |
isOperator
Returns
Name | Type | Description |
---|---|---|
|
| Whether or not |
isAllowed
Returns
Name | Type | Description |
---|---|---|
|
| Whether or not |
debtUnaccrued
debt
This includes unbacked debt.
Returns
Name | Type | Description |
---|---|---|
|
| The total amount of debt. |
totalUnbackedDebt
Returns
Name | Type | Description |
---|---|---|
|
| The total amount of unbacked debt. |
interestRateModule
Returns
Name | Type | Description |
---|---|---|
|
| The address of interest rate module. |
whitelist
Returns
Name | Type | Description |
---|---|---|
|
| The address of the whitelist. |
weth
Returns
Name | Type | Description |
---|---|---|
|
| The total amount of ETH liquidity in the pool. |
getCurrentBorrowRate
Gets the current borrow rate for borrowing against a given collateral.
implementation
Address of the implementation. This is stored immutably on the implementation so that it can be read by the proxy.
addOperator
Allows an operator
to make unsafe changes to _msgSender()
s positions.
removeOperator
Disallows an operator
to make unsafe changes to _msgSender()
s positions.
_add
_sub
_rpow
x and the returned value are to be interpreted as fixed-point integers with scaling factor b. For example, if b == 100, this specifies two decimal digits of precision and the normal decimal value 2.1 would be represented as 210; rpow(210, 2, 100) returns 441 (the two-decimal digit fixed-point representation of 2.1^2 = 4.41) (From MCD docs)
Parameters
Name | Type | Description |
---|---|---|
|
| base |
|
| exponent |
|
| scaling factor |