Skip to main content

Claim Bid

This guide will provide steps for claiming a bid from a batch auction that has been settled through direct integration with the contracts.

Setup

First, define the BatchAuctionHouse that will be used. This should correspond to the same BatchAuctionHouse in which the auction lot was created.

// Define the deployed BatchAuctionHouse
IBatchAuctionHouse auctionHouse = IBatchAuctionHouse(_batchAuctionHouse);

Inputs

We obtain from the LOT_ID environment variable the lot ID that identifies each auction lot. The lot ID is a uint96 number, so should be checked before being downcast.

// Obtain the lot from the environment variable
uint256 lotIdRaw = vm.envUint("LOT_ID");
if (lotIdRaw > type(uint96).max) {
revert("LOT_ID must be less than uint96 max");
}
uint96 lotId = uint96(lotIdRaw);

The lot ID is returned from the auction creation function. See the Create Auction Guide for more details.

We then obtain from the BID_ID environment variable the bid ID that identifies a single bid in an auction lot. The bid ID is a uint64 number, so should be checked before being downcast.

// Obtain the bid from the environment variable
uint64 bidId;
{
uint256 bidIdRaw = vm.envUint("BID_ID");
if (bidIdRaw > type(uint64).max) {
revert("BID_ID must be less than uint64 max");
}
bidId = uint64(bidIdRaw);
}

The bid ID is returned from the bid submission function. See the Submit Bid Guide for more details.

The last step of preparation is to add the bid ID to an array of bid IDs:

// Prepare the bid ids array
uint64[] memory bidIds = new uint64[](1);
bidIds[0] = bidId;

Contract Call

While in this scenario only a single bid is being claimed, it is possible to claim multiple bids in one call and sponsor the gas. For this reason, claimBids() is not gated to the bidder.

// Perform the claim
// Anyone can claim bids on behalf of the bidder
// The proceeds/payout will go to the bidder
auctionHouse.claimBids(lotId, bidIds);
console2.log("Bid claim completed. Lot ID: %d, Bid ID: %d", lotId, bidId);

It is worthwhile noting that the bid claim may fail for the following reasons:

  • The lot ID or bid ID are invalid
  • The state of the auction lot does not allow for bid claiming

Source Code

The source code for the guide is located in the bid-claim.s.sol file.