From 7da7a472d8518cf148d507b634a25c6fa84fac99 Mon Sep 17 00:00:00 2001 From: 0xddong Date: Wed, 11 Sep 2024 15:08:10 -0700 Subject: [PATCH 1/3] 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 47fef655..834fafb5 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; } /** From 2e8f3ff8bf4f749fe1bb69297f5cde5e4c8e09bd Mon Sep 17 00:00:00 2001 From: Andrew Zhou Date: Mon, 23 Sep 2024 14:54:35 -0700 Subject: [PATCH 2/3] fix infinite looping with iteration in calculate present value auction list --- src/TermAuctionList.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/TermAuctionList.sol b/src/TermAuctionList.sol index c3d0f9ca..18ed8408 100644 --- a/src/TermAuctionList.sol +++ b/src/TermAuctionList.sol @@ -257,6 +257,8 @@ library TermAuctionList { // Filter by specific repo token if provided, address(0) bypasses this filter if (repoTokenToMatch != address(0) && offer.repoToken != repoTokenToMatch) { // Not a match, skip + // Move to the next token in the list + current = _getNext(listData, current); continue; } From 5300ce1cb540cd3fec3c70a533d39b439f7c7c19 Mon Sep 17 00:00:00 2001 From: Andrew Zhou Date: Mon, 23 Sep 2024 15:55:41 -0700 Subject: [PATCH 3/3] refactor setdiscountRateMarkup to setDiscountRateMarkup --- src/Strategy.sol | 3 +-- src/test/TestUSDCOffers.t.sol | 2 +- src/test/TestUSDCSellRepoToken.t.sol | 6 +++--- src/test/TestUSDCSubmitOffer.t.sol | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Strategy.sol b/src/Strategy.sol index 6dcc3788..720217b4 100644 --- a/src/Strategy.sol +++ b/src/Strategy.sol @@ -193,7 +193,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { * @notice Set the markup that the vault will receive in excess of the oracle rate * @param newDiscountRateMarkup The new auction rate markup */ - function setdiscountRateMarkup( + function setDiscountRateMarkup( uint256 newDiscountRateMarkup ) external onlyManagement { TERM_VAULT_EVENT_EMITTER.emitDiscountRateMarkupUpdated( @@ -202,7 +202,6 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { ); discountRateMarkup = newDiscountRateMarkup; } - /** * @notice Set the collateral token parameters * @param tokenAddr The address of the collateral token to be accepted diff --git a/src/test/TestUSDCOffers.t.sol b/src/test/TestUSDCOffers.t.sol index ea30441a..88818b64 100644 --- a/src/test/TestUSDCOffers.t.sol +++ b/src/test/TestUSDCOffers.t.sol @@ -38,7 +38,7 @@ contract TestUSDCSubmitOffer is Setup { termStrategy.setTimeToMaturityThreshold(3 weeks); termStrategy.setRepoTokenConcentrationLimit(1e18); termStrategy.setRequiredReserveRatio(0); - termStrategy.setdiscountRateMarkup(0); + termStrategy.setDiscountRateMarkup(0); vm.stopPrank(); // start with some initial funds diff --git a/src/test/TestUSDCSellRepoToken.t.sol b/src/test/TestUSDCSellRepoToken.t.sol index c6c6ee23..a7616e5f 100644 --- a/src/test/TestUSDCSellRepoToken.t.sol +++ b/src/test/TestUSDCSellRepoToken.t.sol @@ -50,7 +50,7 @@ contract TestUSDCSellRepoToken is Setup { termStrategy.setTimeToMaturityThreshold(10 weeks); termStrategy.setRepoTokenConcentrationLimit(1e18); termStrategy.setRequiredReserveRatio(0); - termStrategy.setdiscountRateMarkup(0); + termStrategy.setDiscountRateMarkup(0); vm.stopPrank(); } @@ -350,10 +350,10 @@ contract TestUSDCSellRepoToken is Setup { assertEq(termStrategy.requiredReserveRatio(), 12345); vm.expectRevert("!management"); - termStrategy.setdiscountRateMarkup(12345); + termStrategy.setDiscountRateMarkup(12345); vm.prank(management); - termStrategy.setdiscountRateMarkup(12345); + termStrategy.setDiscountRateMarkup(12345); assertEq(termStrategy.discountRateMarkup(), 12345); vm.expectRevert("!management"); diff --git a/src/test/TestUSDCSubmitOffer.t.sol b/src/test/TestUSDCSubmitOffer.t.sol index 07bffcca..876fd2e9 100644 --- a/src/test/TestUSDCSubmitOffer.t.sol +++ b/src/test/TestUSDCSubmitOffer.t.sol @@ -38,7 +38,7 @@ contract TestUSDCSubmitOffer is Setup { termStrategy.setTimeToMaturityThreshold(3 weeks); termStrategy.setRepoTokenConcentrationLimit(1e18); termStrategy.setRequiredReserveRatio(0); - termStrategy.setdiscountRateMarkup(0); + termStrategy.setDiscountRateMarkup(0); vm.stopPrank(); // start with some initial funds