diff --git a/packages/nouns-contracts/.gas-snapshot b/packages/nouns-contracts/.gas-snapshot index 6269717483..d88bc3ade6 100644 --- a/packages/nouns-contracts/.gas-snapshot +++ b/packages/nouns-contracts/.gas-snapshot @@ -1,9 +1,11 @@ -NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createOneBid() (gas: 35090) -NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createTwoBids() (gas: 93677) +NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createOneBid() (gas: 34941) +NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createTwoBids() (gas: 93379) NounsAuctionHouseV2WarmedUp_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 232680) -NounsAuctionHouseV2_GasSnapshot:test_createOneBid() (gas: 35090) -NounsAuctionHouseV2_GasSnapshot:test_createTwoBids() (gas: 93677) +NounsAuctionHouseV2_GasSnapshot:test_createOneBid() (gas: 34941) +NounsAuctionHouseV2_GasSnapshot:test_createTwoBids() (gas: 93379) NounsAuctionHouseV2_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 249780) +NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_prices_90() (gas: 385106) +NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_prices_range_90() (gas: 377540) NounsAuctionHouse_GasSnapshot:test_createOneBid() (gas: 81474) NounsAuctionHouse_GasSnapshot:test_createTwoBids() (gas: 142736) NounsAuctionHouse_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 243008) diff --git a/packages/nouns-contracts/contracts/NounsAuctionHouseV2.sol b/packages/nouns-contracts/contracts/NounsAuctionHouseV2.sol index 9ab8abd270..fe3d7c666a 100644 --- a/packages/nouns-contracts/contracts/NounsAuctionHouseV2.sol +++ b/packages/nouns-contracts/contracts/NounsAuctionHouseV2.sol @@ -368,17 +368,18 @@ contract NounsAuctionHouseV2 is settlements = new Settlement[](auctionCount); uint256 actualCount = 0; while (actualCount < auctionCount && latestNounId > 0) { + SettlementState memory settlementState = settlementHistory[latestNounId]; // Skip Nouner reward Nouns, they have no price // Also skips IDs with no price data - if (settlementHistory[latestNounId].winner == address(0)) { + if (settlementState.winner == address(0)) { --latestNounId; continue; } settlements[actualCount] = Settlement({ - blockTimestamp: settlementHistory[latestNounId].blockTimestamp, - amount: uint64PriceToUint256(settlementHistory[latestNounId].amount), - winner: settlementHistory[latestNounId].winner, + blockTimestamp: settlementState.blockTimestamp, + amount: uint64PriceToUint256(settlementState.amount), + winner: settlementState.winner, nounId: latestNounId }); ++actualCount; @@ -404,17 +405,18 @@ contract NounsAuctionHouseV2 is uint256 actualCount = 0; uint256 currentId = startId; while (currentId < endId) { + SettlementState memory settlementState = settlementHistory[currentId]; // Skip Nouner reward Nouns, they have no price // Also skips IDs with no price data - if (settlementHistory[currentId].winner == address(0)) { + if (settlementState.winner == address(0)) { ++currentId; continue; } settlements[actualCount] = Settlement({ - blockTimestamp: settlementHistory[currentId].blockTimestamp, - amount: uint64PriceToUint256(settlementHistory[currentId].amount), - winner: settlementHistory[currentId].winner, + blockTimestamp: settlementState.blockTimestamp, + amount: uint64PriceToUint256(settlementState.amount), + winner: settlementState.winner, nounId: currentId }); ++actualCount; diff --git a/packages/nouns-contracts/contracts/interfaces/INounsAuctionHouseV2.sol b/packages/nouns-contracts/contracts/interfaces/INounsAuctionHouseV2.sol index bf64fa12b9..f47401ed36 100644 --- a/packages/nouns-contracts/contracts/interfaces/INounsAuctionHouseV2.sol +++ b/packages/nouns-contracts/contracts/interfaces/INounsAuctionHouseV2.sol @@ -89,5 +89,7 @@ interface INounsAuctionHouseV2 { function prices(uint256 auctionCount) external view returns (Settlement[] memory settlements); + function prices(uint256 startId, uint256 endId) external view returns (Settlement[] memory settlements); + function warmUpSettlementState(uint256[] calldata nounIds) external; } diff --git a/packages/nouns-contracts/test/foundry/NounsAuctionHouseGasSnapshot.t.sol b/packages/nouns-contracts/test/foundry/NounsAuctionHouseGasSnapshot.t.sol index b6b635961f..0b8f69fc4a 100644 --- a/packages/nouns-contracts/test/foundry/NounsAuctionHouseGasSnapshot.t.sol +++ b/packages/nouns-contracts/test/foundry/NounsAuctionHouseGasSnapshot.t.sol @@ -9,7 +9,7 @@ import { AuctionHouseUpgrader } from './helpers/AuctionHouseUpgrader.sol'; import { NounsAuctionHouseProxy } from '../../contracts/proxies/NounsAuctionHouseProxy.sol'; import { NounsAuctionHouseProxyAdmin } from '../../contracts/proxies/NounsAuctionHouseProxyAdmin.sol'; -contract NounsAuctionHouse_GasSnapshot is DeployUtils { +abstract contract NounsAuctionHouseBaseTest is DeployUtils { INounsAuctionHouse auctionHouse; INounsToken nouns; address noundersDAO = makeAddr('noundersDAO'); @@ -31,7 +31,9 @@ contract NounsAuctionHouse_GasSnapshot is DeployUtils { vm.prank(owner); auctionHouse.unpause(); } +} +contract NounsAuctionHouse_GasSnapshot is NounsAuctionHouseBaseTest { function test_createOneBid() public { auctionHouse.createBid{ value: 1 ether }(1); } @@ -62,3 +64,39 @@ contract NounsAuctionHouseV2WarmedUp_GasSnapshot is NounsAuctionHouseV2_GasSnaps INounsAuctionHouseV2(address(auctionHouse)).warmUpSettlementState(nounIds); } } + +contract NounsAuctionHouseV2_HistoricPrices_GasSnapshot is NounsAuctionHouseBaseTest { + INounsAuctionHouseV2 auctionHouseV2; + + function setUp() public virtual override { + super.setUp(); + AuctionHouseUpgrader.upgradeAuctionHouse(owner, proxyAdmin, auctionHouseProxy); + auctionHouseV2 = INounsAuctionHouseV2(address(auctionHouse)); + + for (uint256 i = 1; i <= 200; ++i) { + address bidder = makeAddr(vm.toString(i)); + bidAndWinCurrentAuction(bidder, i * 1e18); + } + } + + function bidAndWinCurrentAuction(address bidder, uint256 bid) internal returns (uint256) { + uint128 nounId = auctionHouseV2.auction().nounId; + uint40 endTime = auctionHouseV2.auction().endTime; + vm.deal(bidder, bid); + vm.prank(bidder); + auctionHouseV2.createBid{ value: bid }(nounId); + vm.warp(endTime); + auctionHouseV2.settleCurrentAndCreateNewAuction(); + return block.timestamp; + } + + function test_prices_90() public { + INounsAuctionHouseV2.Settlement[] memory prices = auctionHouseV2.prices(90); + assertEq(prices.length, 90); + } + + function test_prices_range_90() public { + INounsAuctionHouseV2.Settlement[] memory prices = auctionHouseV2.prices(1, 100); + assertEq(prices.length, 90); + } +}