Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Clarify interest rate function (#218)
Browse files Browse the repository at this point in the history
* clarify interest rate function

* make comments function-level
  • Loading branch information
BrendanChou committed Apr 5, 2019
1 parent 808b19d commit 1276fb0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions contracts/protocol/lib/Interest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ library Interest {

// ============ Library Functions ============

/**
* Returns a new market Index based on the old index and market interest rate.
* Calculates interest for borrowers by using the formula rate * time. This calculation closely
* approximates continuously-compounded interest when called frequently, but is much more
* gas-efficient to calculate. For suppliers, the interest rate is adjusted by the earningsRate,
* then prorated the across all lenders.
*
* @param index The old index for a market
* @param rate The current interest rate of the market
* @param totalPar The total supply and borrow par values of the market
* @param earningsRate The portion of the interest that is forwarded to the lenders
* @return The updated index for a market
*/
function calculateNewIndex(
Index memory index,
Rate memory rate,
Expand All @@ -69,11 +82,11 @@ library Interest {
Types.Wei memory borrowWei
) = totalParToWei(totalPar, index);

// calculate the interest accrued by
// get interest increase for borrowers
uint32 currentTime = Time.currentTime();
uint256 borrowInterest = rate.value.mul(uint256(currentTime).sub(index.lastUpdate));

// adjust the interest by the earningsRate, then prorate the interest across all suppliers
// get interest increase for lenders
uint256 supplyInterest;
if (Types.isZero(supplyWei)) {
supplyInterest = 0;
Expand Down

0 comments on commit 1276fb0

Please sign in to comment.