From 34425342764f6feb1afcada477d6b1795f330926 Mon Sep 17 00:00:00 2001 From: Andrew Zhou Date: Thu, 3 Oct 2024 11:02:15 -0700 Subject: [PATCH 1/3] fix submit offer debit --- src/Strategy.sol | 18 ++---------------- src/test/TestUSDCOffers.t.sol | 8 +++++--- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/Strategy.sol b/src/Strategy.sol index ae2a2877..c9dac147 100644 --- a/src/Strategy.sol +++ b/src/Strategy.sol @@ -801,15 +801,14 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { // Sweep assets, redeem matured repoTokens and ensure liquid balances up to date _redeemRepoTokens(0); - bytes32 offerId = _generateOfferId(idHash, address(offerLocker)); uint256 newOfferAmount = purchaseTokenAmount; uint256 currentOfferAmount = termAuctionListData - .offers[offerId] + .offers[idHash] .offerAmount; // Submit the offer and lock it in the auction ITermAuctionOfferLocker.TermAuctionOfferSubmission memory offer; - offer.id = currentOfferAmount > 0 ? offerId : idHash; + offer.id = idHash; offer.offeror = address(this); offer.offerPriceHash = offerPriceHash; offer.amount = purchaseTokenAmount; @@ -966,19 +965,6 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { _redeemRepoTokens(0); } - /** - * @dev Generate a term offer ID - * @param id The term offer ID hash - * @param offerLocker The address of the term offer locker - * @return The generated term offer ID - */ - function _generateOfferId( - bytes32 id, - address offerLocker - ) internal view returns (bytes32) { - return keccak256(abi.encodePacked(id, address(this), offerLocker)); - } - /** * @notice Required for post-processing after auction clos */ diff --git a/src/test/TestUSDCOffers.t.sol b/src/test/TestUSDCOffers.t.sol index 88818b64..282a0355 100644 --- a/src/test/TestUSDCOffers.t.sol +++ b/src/test/TestUSDCOffers.t.sol @@ -83,11 +83,13 @@ contract TestUSDCSubmitOffer is Setup { vm.prank(management); bytes32[] memory offerIds = termStrategy.submitAuctionOffer( repoToken1WeekAuction, address(repoToken1Week), idHash1, bytes32("test price"), offerAmount - ); + ); + + uint256 offerDiff = offerAmount - 1e6; - assertEq(termStrategy.totalLiquidBalance(), initialState.totalLiquidBalance - offerAmount); + assertEq(termStrategy.totalLiquidBalance(), initialState.totalLiquidBalance - offerDiff); // test: totalAssetValue = total liquid balance + pending offer amount - assertEq(termStrategy.totalAssetValue(), termStrategy.totalLiquidBalance() + offerAmount); + assertEq(termStrategy.totalAssetValue(), termStrategy.totalLiquidBalance() + offerDiff); } function testDeleteOffers() public { From 6f8ba637966153d021b833d939289423a5d9c7ff Mon Sep 17 00:00:00 2001 From: Andrew Zhou Date: Thu, 3 Oct 2024 12:54:48 -0700 Subject: [PATCH 2/3] no insert if redemption past --- src/TermAuctionList.sol | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/TermAuctionList.sol b/src/TermAuctionList.sol index 333af754..91a2ed4e 100644 --- a/src/TermAuctionList.sol +++ b/src/TermAuctionList.sol @@ -179,7 +179,11 @@ library TermAuctionList { if (offer.termAuction.auctionCompleted()) { // If auction is completed and closed, mark for removal and prepare to insert repo token removeNode = true; - insertRepoToken = true; + ITermRepoToken repoToken = ITermRepoToken(offer.repoToken); + (uint256 redemptionTimestamp , , ,) = repoToken.config(); + if (redemptionTimestamp > block.timestamp) { + insertRepoToken = true; + } } else { if (offerAmount == 0) { // If offer amount is zero, it indicates the auction was canceled or deleted @@ -215,10 +219,10 @@ library TermAuctionList { // Auction completed but not closed => include offer.offerAmount in totalValue // because the offerLocker will have already removed the offer. // This applies if the repoToken hasn't been added to the repoTokenList - // (only for new auctions, not reopenings). - repoTokenListData.validateAndInsertRepoToken( - ITermRepoToken(offer.repoToken), discountRateAdapter, asset - ); + // (only for new auctions, not reopenings). + repoTokenListData.validateAndInsertRepoToken( + ITermRepoToken(offer.repoToken), discountRateAdapter, asset + ); } // Move to the next node @@ -377,4 +381,4 @@ library TermAuctionList { current = _getNext(listData, current); } } -} +} From ac99fa2141e0f4b3de5c2231780ab64f0672de0b Mon Sep 17 00:00:00 2001 From: Andrew Zhou Date: Thu, 3 Oct 2024 12:58:31 -0700 Subject: [PATCH 3/3] get rid of extra indent --- src/TermAuctionList.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TermAuctionList.sol b/src/TermAuctionList.sol index 91a2ed4e..97801c90 100644 --- a/src/TermAuctionList.sol +++ b/src/TermAuctionList.sol @@ -220,9 +220,9 @@ library TermAuctionList { // because the offerLocker will have already removed the offer. // This applies if the repoToken hasn't been added to the repoTokenList // (only for new auctions, not reopenings). - repoTokenListData.validateAndInsertRepoToken( - ITermRepoToken(offer.repoToken), discountRateAdapter, asset - ); + repoTokenListData.validateAndInsertRepoToken( + ITermRepoToken(offer.repoToken), discountRateAdapter, asset + ); } // Move to the next node