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

Various strategy fixes #9

Merged
merged 3 commits into from
Aug 15, 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
24 changes: 11 additions & 13 deletions src/RepoTokenList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ library RepoTokenList {

address current = listData.head;
while (current != NULL_NODE) {
// Filter by a specific repoToken, address(0) bypasses this filter
if (repoTokenToMatch != address(0) && current != repoTokenToMatch) {
// Not a match, do not add to totalPresentValue
// Move to the next token in the list
current = _getNext(listData, current);
continue;
}

uint256 currentMaturity = getRepoTokenMaturity(current);
uint256 repoTokenBalance = ITermRepoToken(current).balanceOf(address(this));
uint256 repoTokenPrecision = 10**ERC20(current).decimals();
Expand All @@ -217,10 +225,9 @@ library RepoTokenList {
totalPresentValue += repoTokenBalanceInBaseAssetPrecision;
}

// If filtering by a specific repo token, stop early if matched
// Filter by a specific repo token, address(0) bypasses this condition
if (repoTokenToMatch != address(0) && current == repoTokenToMatch) {
// matching a specific repoToken and terminate early because the list is sorted
// with no duplicates
// Found a match, terminate early
break;
}

Expand Down Expand Up @@ -304,7 +311,6 @@ library RepoTokenList {
* @notice Validates a repoToken against specific criteria
* @param listData The list data
* @param repoToken The repoToken to validate
* @param termController The term controller
* @param asset The address of the base asset
* @return redemptionTimestamp The redemption timestamp of the validated repoToken
*
Expand All @@ -314,14 +320,8 @@ library RepoTokenList {
function validateRepoToken(
RepoTokenListData storage listData,
ITermRepoToken repoToken,
ITermController termController,
address asset
) internal view returns (uint256 redemptionTimestamp) {
// Ensure the repo token is deployed by term
if (!termController.isTermDeployed(address(repoToken))) {
revert InvalidRepoToken(address(repoToken));
}

// Retrieve repo token configuration
address purchaseToken;
address collateralManager;
Expand Down Expand Up @@ -357,7 +357,6 @@ library RepoTokenList {
* @notice Validate and insert a repoToken into the list data
* @param listData The list data
* @param repoToken The repoToken to validate and insert
* @param termController The term controller
* @param discountRateAdapter The discount rate adapter
* @param asset The address of the base asset
* @return discountRate The discount rate to be applied to the validated repoToken
Expand All @@ -366,7 +365,6 @@ library RepoTokenList {
function validateAndInsertRepoToken(
RepoTokenListData storage listData,
ITermRepoToken repoToken,
ITermController termController,
ITermDiscountRateAdapter discountRateAdapter,
address asset
) internal returns (uint256 discountRate, uint256 redemptionTimestamp) {
Expand All @@ -388,7 +386,7 @@ library RepoTokenList {
} else {
discountRate = discountRateAdapter.getDiscountRate(address(repoToken));

redemptionTimestamp = validateRepoToken(listData, repoToken, termController, asset);
redemptionTimestamp = validateRepoToken(listData, repoToken, asset);

insertSorted(listData, address(repoToken));
listData.discountRates[address(repoToken)] = discountRate;
Expand Down
Loading
Loading