Skip to content

Commit 68e72ac

Browse files
authored
feat: don't revert on sweepCurrency for non graduated auctions (#343)
1 parent 18488e8 commit 68e72ac

8 files changed

Lines changed: 42 additions & 15 deletions

File tree

snapshots/AuctionTest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Auction bytecode size": "20415",
2+
"Auction bytecode size": "20382",
33
"checkpoint_advanceToCurrentStep": "180672",
44
"checkpoint_noBids": "166644",
55
"checkpoint_zeroSupply": "117018",

src/ContinuousClearingAuction.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,11 @@ contract ContinuousClearingAuction is
656656
if (msg.sender != FUNDS_RECIPIENT) revert NotAuthorized(FUNDS_RECIPIENT, msg.sender);
657657
// Cannot sweep if already swept
658658
if (sweepCurrencyBlock != 0) revert CannotSweepCurrency();
659-
// Cannot sweep currency if the auction has not graduated, as all of the Currency must be refunded
660-
if (!_isGraduated()) revert NotGraduated();
659+
// If the auction did not graduate there is no currency to sweep as it all must be refunded to bidders
660+
if (!_isGraduated()) {
661+
_sweepCurrency(_getBlockNumberish(), 0);
662+
return;
663+
}
661664
// Sweep the currency and the protocol fee
662665
uint256 currencyRaised = currencyRaised();
663666
uint256 protocolFeeAmount =

test/Auction.graduation.t.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ contract AuctionGraduationTest is AuctionBaseTest {
305305
auction.claimTokensBatch(alice, bids);
306306
}
307307

308-
function test_sweepCurrency_notGraduated_reverts(
308+
function test_sweepCurrency_notGraduated_sweepsZeroCurrency(
309309
FuzzDeploymentParams memory _deploymentParams,
310310
uint128 _bidAmount,
311311
uint128 _maxPrice
@@ -327,9 +327,13 @@ contract AuctionGraduationTest is AuctionBaseTest {
327327
uint256 expectedCurrencyRaisedFromCheckpoint =
328328
(ValueX7.unwrap(auction.currencyRaisedQ96X7()) / ConstantsLib.MPS) >> FixedPoint96.RESOLUTION;
329329

330+
uint256 fundsRecipientBalanceBefore = fundsRecipient.balance;
331+
vm.expectEmit(true, true, true, true);
332+
emit IAuctionStorage.CurrencySwept(fundsRecipient, 0);
330333
vm.prank(fundsRecipient);
331-
vm.expectRevert(IAuctionStorage.NotGraduated.selector);
332334
auction.sweepCurrency();
335+
assertEq(auction.sweepCurrencyBlock(), block.number);
336+
assertEq(fundsRecipient.balance, fundsRecipientBalanceBefore);
333337

334338
emit log_string('===== Auction is NOT graduated =====');
335339
emit log_named_uint('currencyRaised in final checkpoint', expectedCurrencyRaisedFromCheckpoint);

test/Auction.invariant.t.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,11 @@ abstract contract AuctionInvariantBase is AuctionUnitTest {
812812
);
813813
} else {
814814
emit log_string('==================== NOT GRADUATED AUCTION ====================');
815+
vm.expectEmit(true, true, true, true);
816+
emit IAuctionStorage.CurrencySwept(mockAuction.fundsRecipient(), 0);
815817
vm.prank(mockAuction.fundsRecipient());
816-
vm.expectRevert(IAuctionStorage.NotGraduated.selector);
817818
mockAuction.sweepCurrency();
819+
assertEq(mockAuction.sweepCurrencyBlock(), block.number);
818820
// At this point we know all bids have been exited so auction balance should be zero
819821
assertEq(address(mockAuction).balance, 0, 'Auction balance is not zero at end of auction');
820822
}
@@ -900,9 +902,11 @@ abstract contract AuctionInvariantBase is AuctionUnitTest {
900902
);
901903
assertEq(token.balanceOf(address(mockAuction)), 0);
902904

905+
vm.expectEmit(true, true, true, true);
906+
emit IAuctionStorage.CurrencySwept(mockAuction.fundsRecipient(), 0);
903907
vm.prank(mockAuction.fundsRecipient());
904-
vm.expectRevert(IAuctionStorage.NotGraduated.selector);
905908
mockAuction.sweepCurrency();
909+
assertEq(mockAuction.sweepCurrencyBlock(), block.number);
906910
}
907911

908912
function helper__assertClaimsRevertWhenNotGraduated() internal {

test/Auction.t.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,9 +1058,11 @@ contract AuctionTest is AuctionBaseTest {
10581058
assertEq(token.balanceOf(newAuction.tokensRecipient()), TOTAL_SUPPLY);
10591059

10601060
// Expect no currency was swept
1061+
vm.expectEmit(true, true, true, true);
1062+
emit IAuctionStorage.CurrencySwept(newAuction.fundsRecipient(), 0);
10611063
vm.prank(newAuction.fundsRecipient());
1062-
vm.expectRevert(IAuctionStorage.NotGraduated.selector);
10631064
newAuction.sweepCurrency();
1065+
assertEq(newAuction.sweepCurrencyBlock(), block.number);
10641066
assertEq(address(newAuction).balance, 0);
10651067
}
10661068

test/btt/auction/sweepCurrency.t.sol

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ contract SweepCurrencyTest is BttBase {
7373
public
7474
givenEndBlockIsCheckpointed
7575
{
76-
// it reverts with {NotGraduated}
76+
// it writes sweepCurrencyBlock
77+
// it does not transfer currency to funds recipient
78+
// it emits {CurrencySwept} with zero amount
7779

7880
vm.deal(address(this), type(uint256).max);
7981
vm.assume(_bidAmount > 0);
@@ -99,14 +101,22 @@ contract SweepCurrencyTest is BttBase {
99101
// max price must be > 1 (given min tick spacing)
100102

101103
uint256 maxPrice = mParams.parameters.floorPrice + mParams.parameters.tickSpacing;
102-
uint256 bidId = auction.submitBid{value: _bidAmount}(maxPrice, _bidAmount, owner, bytes(''));
104+
auction.submitBid{value: _bidAmount}(maxPrice, _bidAmount, owner, bytes(''));
103105

104106
vm.roll(mParams.parameters.endBlock);
105-
auction.exitPartiallyFilledBid(bidId, mParams.parameters.startBlock, 0);
107+
auction.checkpoint();
108+
109+
uint256 fundsRecipientBalanceBefore = mParams.parameters.fundsRecipient.balance;
110+
uint256 auctionBalanceBefore = address(auction).balance;
106111

112+
vm.expectEmit(true, true, true, true);
113+
emit IAuctionStorage.CurrencySwept(mParams.parameters.fundsRecipient, 0);
107114
vm.prank(mParams.parameters.fundsRecipient);
108-
vm.expectRevert(IAuctionStorage.NotGraduated.selector);
109115
auction.sweepCurrency();
116+
117+
assertEq(auction.sweepCurrencyBlock(), block.number);
118+
assertEq(mParams.parameters.fundsRecipient.balance, fundsRecipientBalanceBefore);
119+
assertEq(address(auction).balance, auctionBalanceBefore);
110120
}
111121

112122
modifier givenAuctionIsGraduated() {

test/btt/auction/sweepCurrency.tree

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ SweepCurrencyTest
66
│ └── it reverts with {CannotSweepCurrency}
77
└── given not previously swept
88
├── when auction is not graduated
9-
│ └── it reverts with {NotGraduated}
9+
│ ├── it writes sweepCurrencyBlock
10+
│ ├── it does not transfer currency to funds recipient
11+
│ └── it emits {CurrencySwept} with zero amount
1012
└── given auction is graduated
1113
├── when amount GT zero
1214
│ ├── it writes sweepCurrencyBlock

test/utils/AuctionBaseTest.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,12 @@ abstract contract AuctionBaseTest is TokenHandler, Assertions, Test {
510510
auction.sweepUnsoldTokens();
511511
// Assert that all tokens were swept
512512
assertEq(token.balanceOf(auction.tokensRecipient()), auction.totalSupply());
513-
// Expect to revert when sweeping currency
513+
// Non-graduated auctions still mark currency as swept but transfer no funds.
514+
vm.expectEmit(true, true, true, true);
515+
emit IAuctionStorage.CurrencySwept(auction.fundsRecipient(), 0);
514516
vm.prank(auction.fundsRecipient());
515-
vm.expectRevert(IAuctionStorage.NotGraduated.selector);
516517
auction.sweepCurrency();
518+
assertEq(auction.sweepCurrencyBlock(), block.number);
517519
}
518520
}
519521

0 commit comments

Comments
 (0)