Skip to main content

Cancel Auction

This guide will provide steps for cancelling an auction through direct integration with the contracts.

Setup

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

// Define the deployed AuctionHouse
IAuctionHouse auctionHouse = IAuctionHouse(_auctionHouse);

Inputs

We define 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.

The last input to the cancel function is a bytes parameter that will be passed to the onCancel callback. The unencoded structure of the callback data is defined by each callbacks contract. For simplicity, this is an empty bytes value in this example.

// Define callback data (unused)
bytes memory callbackData = abi.encode("");

Contract Call

Lastly, we call the function to cancel the auction. This must be performed as the seller, otherwise it will revert.

// Cancel the auction
vm.prank(_SELLER);
auctionHouse.cancel(lotId, callbackData);
console2.log("Auction cancelled. Lot ID:", lotId);

It is worthwhile noting that auction cancellation may fail for the following reasons:

  • If the caller is not the seller (auction creator)
  • If the state of the auction does not allow for cancellation
    • Auction modules can implement custom functionality to prevent cancellation
    • By default, batch auctions cannot be cancelled once started. This is to prevent a seller from cancelling an auction if they are unhappy with the bids.

Source Code

The source code for the guide is located in the cancel-auction.s.sol file.