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 #59

Merged
merged 6 commits into from
Oct 3, 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: 2 additions & 16 deletions src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -801,15 +801,14 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
// Sweep assets, redeem matured repoTokens and ensure liquid balances up to date
_redeemRepoTokens(0);

bytes32 offerId = _generateOfferId(idHash, address(offerLocker));
uint256 newOfferAmount = purchaseTokenAmount;
uint256 currentOfferAmount = termAuctionListData
.offers[offerId]
.offers[idHash]
.offerAmount;

// Submit the offer and lock it in the auction
ITermAuctionOfferLocker.TermAuctionOfferSubmission memory offer;
offer.id = currentOfferAmount > 0 ? offerId : idHash;
offer.id = idHash;
offer.offeror = address(this);
offer.offerPriceHash = offerPriceHash;
offer.amount = purchaseTokenAmount;
Expand Down Expand Up @@ -966,19 +965,6 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
_redeemRepoTokens(0);
}

/**
* @dev Generate a term offer ID
* @param id The term offer ID hash
* @param offerLocker The address of the term offer locker
* @return The generated term offer ID
*/
function _generateOfferId(
bytes32 id,
address offerLocker
) internal view returns (bytes32) {
return keccak256(abi.encodePacked(id, address(this), offerLocker));
}

/**
* @notice Required for post-processing after auction clos
*/
Expand Down
10 changes: 7 additions & 3 deletions src/TermAuctionList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ library TermAuctionList {
if (offer.termAuction.auctionCompleted()) {
// If auction is completed and closed, mark for removal and prepare to insert repo token
removeNode = true;
insertRepoToken = true;
ITermRepoToken repoToken = ITermRepoToken(offer.repoToken);
(uint256 redemptionTimestamp , , ,) = repoToken.config();
if (redemptionTimestamp > block.timestamp) {
insertRepoToken = true;
}
} else {
if (offerAmount == 0) {
// If offer amount is zero, it indicates the auction was canceled or deleted
Expand Down Expand Up @@ -215,7 +219,7 @@ library TermAuctionList {
// Auction completed but not closed => include offer.offerAmount in totalValue
// 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).
// (only for new auctions, not reopenings).
repoTokenListData.validateAndInsertRepoToken(
ITermRepoToken(offer.repoToken), discountRateAdapter, asset
);
Expand Down Expand Up @@ -377,4 +381,4 @@ library TermAuctionList {
current = _getNext(listData, current);
}
}
}
}
8 changes: 5 additions & 3 deletions src/test/TestUSDCOffers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ contract TestUSDCSubmitOffer is Setup {
vm.prank(management);
bytes32[] memory offerIds = termStrategy.submitAuctionOffer(
repoToken1WeekAuction, address(repoToken1Week), idHash1, bytes32("test price"), offerAmount
);
);

uint256 offerDiff = offerAmount - 1e6;

assertEq(termStrategy.totalLiquidBalance(), initialState.totalLiquidBalance - offerAmount);
assertEq(termStrategy.totalLiquidBalance(), initialState.totalLiquidBalance - offerDiff);
// test: totalAssetValue = total liquid balance + pending offer amount
assertEq(termStrategy.totalAssetValue(), termStrategy.totalLiquidBalance() + offerAmount);
assertEq(termStrategy.totalAssetValue(), termStrategy.totalLiquidBalance() + offerDiff);
}

function testDeleteOffers() public {
Expand Down