Skip to content

Commit

Permalink
Merge pull request #119 from term-finance/yearn-audit-variable-optimi…
Browse files Browse the repository at this point in the history
…zations

Yearn audit variable optimizations
  • Loading branch information
aazhou1 authored Dec 23, 2024
2 parents bfe30b8 + 79941d6 commit 78b5e15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/RepoTokenList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,22 +340,21 @@ library RepoTokenList {
* @param discountRateAdapter The discount rate adapter
* @param asset The address of the base asset
* @return validRepoToken Whether the repoToken is valid
* @return discountRate The discount rate to be applied to the validated repoToken
* @return redemptionTimestamp The redemption timestamp of the validated repoToken
*/
function validateAndInsertRepoToken(
RepoTokenListData storage listData,
ITermRepoToken repoToken,
ITermDiscountRateAdapter discountRateAdapter,
address asset
) internal returns (bool validRepoToken, uint256 discountRate, uint256 redemptionTimestamp) {
discountRate = listData.discountRates[address(repoToken)];
) internal returns (bool validRepoToken, uint256 redemptionTimestamp) {
uint256 discountRate = listData.discountRates[address(repoToken)];
if (discountRate != INVALID_AUCTION_RATE) {
(redemptionTimestamp, , ,) = repoToken.config();

// skip matured repoTokens
if (redemptionTimestamp < block.timestamp) {
return (false, discountRate, redemptionTimestamp); //revert InvalidRepoToken(address(repoToken));
return (false, redemptionTimestamp); //revert InvalidRepoToken(address(repoToken));
}

uint256 oracleRate;
Expand All @@ -374,20 +373,20 @@ library RepoTokenList {
discountRate = rate == 0 ? ZERO_AUCTION_RATE : rate;
} catch {
discountRate = INVALID_AUCTION_RATE;
return (false, discountRate, redemptionTimestamp);
return (false, redemptionTimestamp);
}

bool isRepoTokenValid;

(isRepoTokenValid, redemptionTimestamp) = validateRepoToken(listData, repoToken, asset);
if (!isRepoTokenValid) {
return (false, discountRate, redemptionTimestamp);
return (false, redemptionTimestamp);
}
insertSorted(listData, address(repoToken));
listData.discountRates[address(repoToken)] = discountRate;
}

return (true, discountRate, redemptionTimestamp);
return (true, redemptionTimestamp);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ contract Strategy is BaseStrategy, Pausable, AccessControl {
) external onlyRole(GOVERNOR_ROLE) {
require(newTermControllerAddr != address(0));
require(ITermController(newTermControllerAddr).getProtocolReserveAddress() != address(0));
ITermController newTermController = ITermController(newTermControllerAddr);
address currentIteration = repoTokenListData.head;
while (currentIteration != address(0)) {
if (!_isTermDeployed(currentIteration)) {
Expand All @@ -191,7 +190,7 @@ contract Strategy is BaseStrategy, Pausable, AccessControl {
newTermControllerAddr
);
strategyState.prevTermController = ITermController(current);
strategyState.currTermController = newTermController;
strategyState.currTermController = ITermController(newTermControllerAddr);
}

/**
Expand Down Expand Up @@ -578,8 +577,6 @@ contract Strategy is BaseStrategy, Pausable, AccessControl {
* and the present value of all pending offers to calculate the total asset value.
*/
function _totalAssetValue(uint256 liquidBalance) internal view returns (uint256 totalValue) {
ITermController prevTermController = strategyState.prevTermController;
ITermController currTermController = strategyState.currTermController;

return
liquidBalance +
Expand Down Expand Up @@ -1087,7 +1084,7 @@ contract Strategy is BaseStrategy, Pausable, AccessControl {
}

// Validate and insert the repoToken into the list, retrieve auction rate and redemption timestamp
(bool isRepoTokenValid , , uint256 redemptionTimestamp) = repoTokenListData
(bool isRepoTokenValid , uint256 redemptionTimestamp) = repoTokenListData
.validateAndInsertRepoToken(
ITermRepoToken(repoToken),
strategyState.discountRateAdapter,
Expand Down
2 changes: 1 addition & 1 deletion src/TermAuctionList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ 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).
(bool isValidRepoToken, , uint256 redemptionTimestamp ) = repoTokenListData.validateAndInsertRepoToken(
(bool isValidRepoToken, uint256 redemptionTimestamp ) = repoTokenListData.validateAndInsertRepoToken(
ITermRepoToken(offer.repoToken), discountRateAdapter, asset
);
if (!isValidRepoToken && block.timestamp > redemptionTimestamp) {
Expand Down

0 comments on commit 78b5e15

Please sign in to comment.