From 7da7a472d8518cf148d507b634a25c6fa84fac99 Mon Sep 17 00:00:00 2001 From: 0xddong Date: Wed, 11 Sep 2024 15:08:10 -0700 Subject: [PATCH] fixing calculate pv --- src/RepoTokenUtils.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/RepoTokenUtils.sol b/src/RepoTokenUtils.sol index 47fef65..834fafb 100644 --- a/src/RepoTokenUtils.sol +++ b/src/RepoTokenUtils.sol @@ -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; } /**