InterestRate

Git Source

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

uint256 private constant MAX_ILKS = 8;

ILKCONFIG_0A

Packed collateral configs

uint256 private immutable ILKCONFIG_0A;

ILKCONFIG_0B

uint256 private immutable ILKCONFIG_0B;

ILKCONFIG_0C

uint256 private immutable ILKCONFIG_0C;

ILKCONFIG_1A

uint256 private immutable ILKCONFIG_1A;

ILKCONFIG_1B

uint256 private immutable ILKCONFIG_1B;

ILKCONFIG_1C

uint256 private immutable ILKCONFIG_1C;

ILKCONFIG_2A

uint256 private immutable ILKCONFIG_2A;

ILKCONFIG_2B

uint256 private immutable ILKCONFIG_2B;

ILKCONFIG_2C

uint256 private immutable ILKCONFIG_2C;

ILKCONFIG_3A

uint256 private immutable ILKCONFIG_3A;

ILKCONFIG_3B

uint256 private immutable ILKCONFIG_3B;

ILKCONFIG_3C

uint256 private immutable ILKCONFIG_3C;

ILKCONFIG_4A

uint256 private immutable ILKCONFIG_4A;

ILKCONFIG_4B

uint256 private immutable ILKCONFIG_4B;

ILKCONFIG_4C

uint256 private immutable ILKCONFIG_4C;

ILKCONFIG_5A

uint256 private immutable ILKCONFIG_5A;

ILKCONFIG_5B

uint256 private immutable ILKCONFIG_5B;

ILKCONFIG_5C

uint256 private immutable ILKCONFIG_5C;

ILKCONFIG_6A

uint256 private immutable ILKCONFIG_6A;

ILKCONFIG_6B

uint256 private immutable ILKCONFIG_6B;

ILKCONFIG_6C

uint256 private immutable ILKCONFIG_6C;

ILKCONFIG_7A

uint256 private immutable ILKCONFIG_7A;

ILKCONFIG_7B

uint256 private immutable ILKCONFIG_7B;

ILKCONFIG_7C

uint256 private immutable ILKCONFIG_7C;

COLLATERAL_COUNT

uint256 public immutable COLLATERAL_COUNT;

YIELD_ORACLE

IYieldOracle public immutable YIELD_ORACLE;

Functions

constructor

Creates a new InterestRate instance.

constructor(IlkData[] memory ilkDataList, IYieldOracle _yieldOracle);

Parameters

NameTypeDescription

ilkDataList

IlkData[]

List of ilk configs.

_yieldOracle

IYieldOracle

Address of the Yield oracle.

_packCollateralConfig

Helper function to pack the collateral configs into 3 words. This function is only called during construction.

function _packCollateralConfig(
    IlkData[] memory ilkDataList,
    uint256 index
)
    private
    view
    returns (uint256 packedConfig_a, uint256 packedConfig_b, uint256 packedConfig_c);

Parameters

NameTypeDescription

ilkDataList

IlkData[]

The list of ilk configs.

index

uint256

The ilkIndex to pack.

Returns

NameTypeDescription

packedConfig_a

uint256

packedConfig_a

packedConfig_b

uint256

packedConfig_b

packedConfig_c

uint256

packedConfig_c

_unpackCollateralConfig

Helper function to unpack the collateral configs from the 3 words.

function _unpackCollateralConfig(uint256 index) internal view returns (IlkData memory ilkData);

Parameters

NameTypeDescription

index

uint256

The ilkIndex to unpack.

Returns

NameTypeDescription

ilkData

IlkData

The unpacked collateral config.

calculateInterestRate

Calculates the interest rate for a given collateral.

function calculateInterestRate(
    uint256 ilkIndex,
    uint256 totalIlkDebt,
    uint256 totalEthSupply
)
    external
    view
    returns (uint256, uint256);

Parameters

NameTypeDescription

ilkIndex

uint256

Index of the collateral.

totalIlkDebt

uint256

Total debt of the collateral. [RAD]

totalEthSupply

uint256

Total eth supply of the system. [WAD]

Errors

CollateralIndexOutOfBounds

error CollateralIndexOutOfBounds();

DistributionFactorsDoNotSumToOne

error DistributionFactorsDoNotSumToOne(uint256 sum);

TotalDebtsLength

error TotalDebtsLength(uint256 COLLATERAL_COUNT, uint256 totalIlkDebtsLength);

InvalidMinimumKinkRate

error InvalidMinimumKinkRate(uint256 minimumKinkRate, uint256 minimumBaseRate);

InvalidIlkDataListLength

error InvalidIlkDataListLength(uint256 length);

InvalidOptimalUtilizationRate

error InvalidOptimalUtilizationRate(uint256 optimalUtilizationRate);

InvalidReserveFactor

error InvalidReserveFactor(uint256 reserveFactor);

InvalidYieldOracleAddress

error InvalidYieldOracleAddress();