diff --git a/src/RepoTokenList.sol b/src/RepoTokenList.sol index 1767a323..28fcfa6e 100644 --- a/src/RepoTokenList.sol +++ b/src/RepoTokenList.sol @@ -15,7 +15,6 @@ struct RepoTokenListNode { struct RepoTokenListData { address head; mapping(address => RepoTokenListNode) nodes; - mapping(address => uint256) discountRates; /// @notice keyed by collateral token mapping(address => uint256) collateralTokenParams; } @@ -174,6 +173,7 @@ library RepoTokenList { * @notice Get the present value of repoTokens * @param listData The list data * @param purchaseTokenPrecision The precision of the purchase token + * @param discountRateAdapter The discount rate adapter * @param repoTokenToMatch The address of the repoToken to match (optional) * @return totalPresentValue The total present value of the repoTokens * @dev If the `repoTokenToMatch` parameter is provided (non-zero address), the function will filter @@ -187,6 +187,7 @@ library RepoTokenList { function getPresentValue( RepoTokenListData storage listData, uint256 purchaseTokenPrecision, + ITermDiscountRateAdapter discountRateAdapter, address repoTokenToMatch ) internal view returns (uint256 totalPresentValue) { // If the list is empty, return 0 @@ -205,7 +206,7 @@ library RepoTokenList { uint256 currentMaturity = getRepoTokenMaturity(current); uint256 repoTokenBalance = ITermRepoToken(current).balanceOf(address(this)); uint256 repoTokenPrecision = 10**ERC20(current).decimals(); - uint256 discountRate = listData.discountRates[current]; + uint256 discountRate = discountRateAdapter.getDiscountRate(current); // Convert repo token balance to base asset precision // (ratePrecision * repoPrecision * purchasePrecision) / (repoPrecision * ratePrecision) = purchasePrecision @@ -291,7 +292,6 @@ library RepoTokenList { listData.nodes[prev].next = next; delete listData.nodes[current]; - delete listData.discountRates[current]; } } else { /// @dev early exit because list is sorted @@ -364,29 +364,13 @@ library RepoTokenList { ITermDiscountRateAdapter discountRateAdapter, address asset ) internal returns (uint256 discountRate, uint256 redemptionTimestamp) { - discountRate = listData.discountRates[address(repoToken)]; - if (discountRate != INVALID_AUCTION_RATE) { - (redemptionTimestamp, , ,) = repoToken.config(); - - // skip matured repoTokens - if (redemptionTimestamp < block.timestamp) { - revert InvalidRepoToken(address(repoToken)); - } - - uint256 oracleRate = discountRateAdapter.getDiscountRate(address(repoToken)); - if (oracleRate != INVALID_AUCTION_RATE) { - if (discountRate != oracleRate) { - listData.discountRates[address(repoToken)] = oracleRate; - } - } - } else { - discountRate = discountRateAdapter.getDiscountRate(address(repoToken)); + + discountRate = discountRateAdapter.getDiscountRate(address(repoToken)); - redemptionTimestamp = validateRepoToken(listData, repoToken, asset); + redemptionTimestamp = validateRepoToken(listData, repoToken, asset); - insertSorted(listData, address(repoToken)); - listData.discountRates[address(repoToken)] = discountRate; - } + insertSorted(listData, address(repoToken)); + } /** diff --git a/src/Strategy.sol b/src/Strategy.sol index cb3a4860..5d353f6b 100644 --- a/src/Strategy.sol +++ b/src/Strategy.sol @@ -431,6 +431,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { return repoTokenListData.getPresentValue( PURCHASE_TOKEN_PRECISION, + discountRateAdapter, repoToken ) + termAuctionListData.getPresentValue( @@ -490,6 +491,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { liquidBalance + repoTokenListData.getPresentValue( PURCHASE_TOKEN_PRECISION, + discountRateAdapter, address(0) ) + termAuctionListData.getPresentValue( @@ -611,6 +613,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { bool foundInOfferList ) = termAuctionListData.getCumulativeOfferData( repoTokenListData, + discountRateAdapter, repoToken, repoTokenAmount, PURCHASE_TOKEN_PRECISION diff --git a/src/TermAuctionList.sol b/src/TermAuctionList.sol index 672b3b75..25b821fc 100644 --- a/src/TermAuctionList.sol +++ b/src/TermAuctionList.sol @@ -286,7 +286,7 @@ library TermAuctionList { // Handle new or unseen repo tokens /// @dev offer processed, but auctionClosed not yet called and auction is new so repoToken not on List and wont be picked up /// checking repoTokendiscountRates to make sure we are not double counting on re-openings - if (offer.termAuction.auctionCompleted() && repoTokenListData.discountRates[offer.repoToken] == 0) { + if (offer.termAuction.auctionCompleted() && discountRateAdapter.getDiscountRate(offer.repoToken) == 0) { if (!offer.isRepoTokenSeen) { uint256 repoTokenAmountInBaseAssetPrecision = RepoTokenUtils.getNormalizedRepoTokenAmount( offer.repoToken, @@ -316,6 +316,7 @@ library TermAuctionList { * @notice Get cumulative offer data for a specified repoToken * @param listData The list data * @param repoTokenListData The repoToken list data + * @param discountRateAdapter The discount rate adapter * @param repoToken The address of the repoToken (optional) * @param newOfferAmount The new offer amount for the specified repoToken * @param purchaseTokenPrecision The precision of the purchase token @@ -331,6 +332,7 @@ library TermAuctionList { function getCumulativeOfferData( TermAuctionListData storage listData, RepoTokenListData storage repoTokenListData, + ITermDiscountRateAdapter discountRateAdapter, address repoToken, uint256 newOfferAmount, uint256 purchaseTokenPrecision @@ -355,7 +357,7 @@ library TermAuctionList { // Handle new repo tokens or reopening auctions /// @dev offer processed, but auctionClosed not yet called and auction is new so repoToken not on List and wont be picked up /// checking repoTokendiscountRates to make sure we are not double counting on re-openings - if (offer.termAuction.auctionCompleted() && repoTokenListData.discountRates[offer.repoToken] == 0) { + if (offer.termAuction.auctionCompleted() && discountRateAdapter.getDiscountRate(offer.repoToken) == 0) { // use normalized repoToken amount if repoToken is not in the list if (!offer.isRepoTokenSeen) { offerAmount = RepoTokenUtils.getNormalizedRepoTokenAmount(