Skip to content

Commit

Permalink
Merge pull request #27 from term-finance/fix-normalized
Browse files Browse the repository at this point in the history
Capping PV
  • Loading branch information
aazhou1 authored Sep 13, 2024
2 parents 701cd79 + 02362cd commit 357daba
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/RepoTokenUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ library RepoTokenUtils {
uint256 redemptionTimestamp,
uint256 discountRate
) internal view returns (uint256 presentValue) {
uint256 timeLeftToMaturityDayFraction =
uint256 timeLeftToMaturityDayFraction = block.timestamp > redemptionTimestamp ? 0 :
((redemptionTimestamp - block.timestamp) * purchaseTokenPrecision) / THREESIXTY_DAYCOUNT_SECONDS;

// repoTokenAmountInBaseAssetPrecision / (1 + r * days / 360)
presentValue =
(repoTokenAmountInBaseAssetPrecision * purchaseTokenPrecision) /
(purchaseTokenPrecision + (discountRate * timeLeftToMaturityDayFraction / RATE_PRECISION));

return presentValue > repoTokenAmountInBaseAssetPrecision ? repoTokenAmountInBaseAssetPrecision : presentValue;
}

/**
Expand Down

0 comments on commit 357daba

Please sign in to comment.