Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime fv #63

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/RepoTokenList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -297,20 +298,20 @@ 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;
(redemptionTimestamp, purchaseToken, , collateralManager) = repoToken.config();

// 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
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions src/TermAuctionList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down