diff --git a/src/RepoTokenList.sol b/src/RepoTokenList.sol index b22e4a87..4e0a5670 100644 --- a/src/RepoTokenList.sol +++ b/src/RepoTokenList.sol @@ -288,6 +288,7 @@ library RepoTokenList { * @param listData The list data * @param repoToken The repoToken to validate * @param asset The address of the base asset + * @return isRepoTokenValid Whether the repoToken is valid * @return redemptionTimestamp The redemption timestamp of the validated repoToken * * @dev Ensures the repoToken is deployed, matches the purchase token, is not matured, and meets collateral requirements. @@ -297,7 +298,7 @@ library RepoTokenList { RepoTokenListData storage listData, ITermRepoToken repoToken, address asset - ) internal view returns (uint256 redemptionTimestamp) { + ) internal view returns (bool isRepoTokenValid, uint256 redemptionTimestamp) { // Retrieve repo token configuration address purchaseToken; address collateralManager; @@ -305,12 +306,12 @@ library RepoTokenList { // Validate purchase token if (purchaseToken != asset) { - revert InvalidRepoToken(address(repoToken)); + return (false, redemptionTimestamp); } // Check if repo token has matured if (redemptionTimestamp < block.timestamp) { - revert InvalidRepoToken(address(repoToken)); + return (false, redemptionTimestamp); } // Validate collateral token ratios @@ -320,13 +321,14 @@ library RepoTokenList { uint256 minCollateralRatio = listData.collateralTokenParams[currentToken]; if (minCollateralRatio == 0) { - revert InvalidRepoToken(address(repoToken)); + return (false, redemptionTimestamp); } else if ( ITermRepoCollateralManager(collateralManager).maintenanceCollateralRatios(currentToken) < minCollateralRatio ) { - revert InvalidRepoToken(address(repoToken)); + return (false, redemptionTimestamp); } } + return (true, redemptionTimestamp); } /** @@ -362,8 +364,12 @@ library RepoTokenList { } else { discountRate = discountRateAdapter.getDiscountRate(address(repoToken)); - redemptionTimestamp = validateRepoToken(listData, repoToken, asset); + bool isRepoTokenValid; + (isRepoTokenValid, redemptionTimestamp) = validateRepoToken(listData, repoToken, asset); + if (!isRepoTokenValid) { + revert InvalidRepoToken(address(repoToken)); + } insertSorted(listData, address(repoToken)); listData.discountRates[address(repoToken)] = discountRate; } diff --git a/src/Strategy.sol b/src/Strategy.sol index c9dac147..41003347 100644 --- a/src/Strategy.sol +++ b/src/Strategy.sol @@ -349,17 +349,22 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { revert RepoTokenList.InvalidRepoToken(repoToken); } - uint256 redemptionTimestamp = repoTokenListData.validateRepoToken( + (bool isRepoTokenValid, uint256 redemptionTimestamp) = repoTokenListData.validateRepoToken( ITermRepoToken(repoToken), address(asset) ); + + if (!isRepoTokenValid) { + revert RepoTokenList.InvalidRepoToken(repoToken); + } uint256 discountRate = discountRateAdapter.getDiscountRate(repoToken); + uint256 repoRedemptionHaircut = discountRateAdapter.repoRedemptionHaircut(repoToken); repoTokenAmountInBaseAssetPrecision = RepoTokenUtils.getNormalizedRepoTokenAmount( repoToken, amount, PURCHASE_TOKEN_PRECISION, - discountRateAdapter.repoRedemptionHaircut(repoToken) + repoRedemptionHaircut ); proceeds = RepoTokenUtils.calculatePresentValue( repoTokenAmountInBaseAssetPrecision, diff --git a/src/TermAuctionList.sol b/src/TermAuctionList.sol index 97801c90..1412d0f9 100644 --- a/src/TermAuctionList.sol +++ b/src/TermAuctionList.sol @@ -179,11 +179,7 @@ library TermAuctionList { if (offer.termAuction.auctionCompleted()) { // If auction is completed and closed, mark for removal and prepare to insert repo token removeNode = true; - ITermRepoToken repoToken = ITermRepoToken(offer.repoToken); - (uint256 redemptionTimestamp , , ,) = repoToken.config(); - if (redemptionTimestamp > block.timestamp) { - insertRepoToken = true; - } + (insertRepoToken, ) = repoTokenListData.validateRepoToken(ITermRepoToken(offer.repoToken), asset); } else { if (offerAmount == 0) { // If offer amount is zero, it indicates the auction was canceled or deleted