- Optimized calculateLinearInterest() on MathUtils.

This commit is contained in:
eboado 2020-10-27 12:44:30 +01:00
parent bb6b322925
commit e88d9dc81b
2 changed files with 6 additions and 7 deletions

View File

@ -25,9 +25,7 @@ library MathUtils {
//solium-disable-next-line
uint256 timeDifference = block.timestamp.sub(uint256(lastUpdateTimestamp));
uint256 timeDelta = timeDifference.wadToRay().rayDiv(SECONDS_PER_YEAR.wadToRay());
return rate.rayMul(timeDelta).add(WadRayMath.ray());
return (rate.mul(timeDifference) / SECONDS_PER_YEAR).add(WadRayMath.ray());
}
/**

View File

@ -1153,11 +1153,12 @@ const calcLinearInterest = (
currentTimestamp: BigNumber,
lastUpdateTimestamp: BigNumber
) => {
const timeDifference = currentTimestamp.minus(lastUpdateTimestamp).wadToRay();
const timeDifference = currentTimestamp.minus(lastUpdateTimestamp);
const timeDelta = timeDifference.rayDiv(new BigNumber(ONE_YEAR).wadToRay());
const cumulatedInterest = rate.rayMul(timeDelta).plus(RAY);
const cumulatedInterest = rate
.multipliedBy(timeDifference)
.dividedBy(new BigNumber(ONE_YEAR))
.plus(RAY);
return cumulatedInterest;
};