InterestRate
An external contract that provides the APY for each collateral type. A modular design here allows for updating of the parameters at a later date without upgrading the core protocol.
Each collateral has its own interest rate model, and every operation on the IonPool
(lend, withdraw, borrow, repay) will alter the interest rate for all collaterals. Therefore, before every operation, the previous interest rate must be accrued. Ion determines the interest rate for each collateral based on various collateral-specific parameters which must be stored on-chain. However, to iterate through all these parameters as contract storage on every operation introduces an immense gas overhead, especially as more collaterals are listed on Ion. Therefore, this contract is heavily optimized to reduce storage reads at the unfortunate cost of code-complexity.
State Variables
MAX_ILKS
ILKCONFIG_0A
Packed collateral configs
ILKCONFIG_0B
ILKCONFIG_0C
ILKCONFIG_1A
ILKCONFIG_1B
ILKCONFIG_1C
ILKCONFIG_2A
ILKCONFIG_2B
ILKCONFIG_2C
ILKCONFIG_3A
ILKCONFIG_3B
ILKCONFIG_3C
ILKCONFIG_4A
ILKCONFIG_4B
ILKCONFIG_4C
ILKCONFIG_5A
ILKCONFIG_5B
ILKCONFIG_5C
ILKCONFIG_6A
ILKCONFIG_6B
ILKCONFIG_6C
ILKCONFIG_7A
ILKCONFIG_7B
ILKCONFIG_7C
COLLATERAL_COUNT
YIELD_ORACLE
Functions
constructor
Creates a new InterestRate
instance.
Parameters
Name | Type | Description |
---|---|---|
|
| List of ilk configs. |
|
| Address of the Yield oracle. |
_packCollateralConfig
Helper function to pack the collateral configs into 3 words. This function is only called during construction.
Parameters
Name | Type | Description |
---|---|---|
|
| The list of ilk configs. |
|
| The ilkIndex to pack. |
Returns
Name | Type | Description |
---|---|---|
|
| packedConfig_a |
|
| packedConfig_b |
|
| packedConfig_c |
_unpackCollateralConfig
Helper function to unpack the collateral configs from the 3 words.
Parameters
Name | Type | Description |
---|---|---|
|
| The ilkIndex to unpack. |
Returns
Name | Type | Description |
---|---|---|
|
| The unpacked collateral config. |
calculateInterestRate
Calculates the interest rate for a given collateral.
Parameters
Name | Type | Description |
---|---|---|
|
| Index of the collateral. |
|
| Total debt of the collateral. [RAD] |
|
| Total eth supply of the system. [WAD] |