Interest Bearing Logic

Interest Bearing Logic

Yield

yield is represented as cumulative per-second rate in 27 decimal format. The rate is calculated as follows:

cumulativeYield represents the aggregate interest accrued over time. It is calculated with a 1-second precision based on the block timestamp. cumulativeYield is updated whenever the _refreshCumulativeYield() internal function is called, to update the cumulativeYield to the current time

cumulativeYield is calculated as follows: Cumulative Rate is calculated as:

Setting yield to RAY (1e27) - which is also its initial value at deployment - sets yield to zero. A positive yield will increase the cumulativeYield over time.

Here timeElapsed refers to the time elapsed between the last _cumulativeYield refresh and the current timestamp.

previousEpochCumulativeYield also represents the aggregate interest accrued over time with a 1-second precision but is based on the cumulativeYield calculated at the previousEpochTimestamp. previousEpochCumulativeYield is also updated whenever the _refreshCumulativeYield() internal function is called.

previousEpochCumulativeYield is calculated as follows:

Here timeElapsedToEpoch refers to the time elapsed between the last cumulativeYield refresh and the previousEpochTimestamp.

Setting yield to RAY (1e27) - which is also its initial value at deployment - sets yield to zero. A positive yield will increase the cumulativeYield over time.

Epoch

Although interest accrues each second, balances only increase each epoch. This is done to :

  • Provide keepers with enough time to expire a bond (see Keepers)

  • Avoid leftover residual dust amounts when transferring all of a user's balance, since most frontend wallets do not refresh a user's balance on a per second basis.

  • Enable adapting epochs to bond term lengths if the DAO votes to do so. For example a 1 year T-Bill might have a 4 hour rebase while a 30 year bond could have a daily or weekly rebase.

Thus balanceOf and totalSupply both rely on the internal function _calculatePreviousEpochCumulativeYield(). The _calculatePreviousEpochCumulativeYield() is called in _refreshCumulativeYield to update the _previousEpochCumulativeYield state.

Even though only _previousEpochCumulativeYield is used to return external KIBT balances , the more accurate cumulativeYield state is required to track the yield earned between epochs.

Epochs add a layer of flexibility that enables KIBTokens to adapt to investment strategies with different time horizons.

Last updated