Skip to content

Commit

Permalink
Merge pull request #59 from term-finance/runtime-fv
Browse files Browse the repository at this point in the history
Runtime fv
  • Loading branch information
aazhou1 authored Oct 3, 2024
2 parents 73d6cf1 + e1ba4a3 commit 11913fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
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

0 comments on commit 11913fb

Please sign in to comment.