Skip to main content

AuctionHouse

Git Source

Inherits: IAuctionHouse, WithModules, ReentrancyGuard, FeeManager

The base AuctionHouse contract defines common structures and functions across auction types (atomic and batch). It defines the following:

  • Creating new auction lots
  • Cancelling auction lots
  • Storing information about how to handle inputs and outputs for auctions ("routing")

State Variables

_PERMIT2

Address of the Permit2 contract

address internal immutable _PERMIT2;

lotCounter

The counter tracks the total number of auction lots

uint96 public lotCounter;

lotRouting

Mapping of lot IDs to their routing information

See the Routing struct for more information

mapping(uint96 lotId => Routing) public lotRouting;

lotFees

Mapping of lot IDs to their fee information

See the FeeData struct for more information

mapping(uint96 lotId => FeeData) public lotFees;

condensers

Mapping auction and derivative references to the condenser that is used to pass data between them

mapping(Veecode auctionRef => mapping(Veecode derivativeRef => Veecode condenserRef)) public
condensers;

Functions

constructor

constructor(
address owner_,
address protocol_,
address permit2_
) FeeManager(protocol_) WithModules(owner_);

auction

Creates a new auction lot

This function performs the following:

  • Validates the auction parameters
  • Validates the auction module
  • Validates the derivative module (if provided)
  • Validates the callbacks contract (if provided)
  • Stores the auction routing information
  • Calls the auction module to store implementation-specific data
  • Caches the fees for the lot
  • Calls the implementation-specific auction function
  • Calls the onCreate callback (if needed)

This function reverts if:

  • The module for the auction type is not installed
  • The auction type is sunset
  • The base token or quote token decimals are not within the required range
  • Validation for the auction parameters fails
  • The module for the optional specified derivative type is not installed
  • Validation for the optional specified derivative type fails
  • Validation for the optional specified callbacks contract fails
  • Re-entrancy is detected
function auction(
IAuctionHouse.RoutingParams calldata routing_,
IAuction.AuctionParams calldata params_,
string calldata infoHash_
) external nonReentrant returns (uint96 lotId);

Parameters

NameTypeDescription
routing_IAuctionHouse.RoutingParamsRouting information for the auction lot
params_IAuction.AuctionParamsAuction parameters for the auction lot
infoHash_stringIPFS hash of the auction information

Returns

NameTypeDescription
lotIduint96ID of the auction lot

_auction

Implementation-specific logic for auction creation

Inheriting contracts can implement additional logic, such as:

  • Validation
  • Prefunding
function _auction(
uint96 lotId_,
IAuctionHouse.RoutingParams calldata routing_,
IAuction.AuctionParams calldata params_
) internal virtual returns (bool performedCallback);

Parameters

NameTypeDescription
lotId_uint96The auction lot ID
routing_IAuctionHouse.RoutingParamsRoutingParams
params_IAuction.AuctionParamsAuctionParams

Returns

NameTypeDescription
performedCallbackbooltrue if the implementing function calls the onCreate callback

cancel

Cancels an auction lot

This function performs the following:

  • Checks that the lot ID is valid
  • Checks that caller is the seller
  • Calls the auction module to validate state, update records and determine the amount to be refunded
  • Calls the implementation-specific logic for auction cancellation
  • Calls the onCancel callback (if needed)

The function reverts if:

  • The lot ID is invalid
  • The caller is not the seller
  • The respective auction module reverts
  • Re-entrancy is detected
function cancel(uint96 lotId_, bytes calldata callbackData_) external nonReentrant;

Parameters

NameTypeDescription
lotId_uint96ID of the auction lot
callbackData_bytes

_cancel

Implementation-specific logic for auction cancellation

Inheriting contracts can implement additional logic, such as:

  • Validation
  • Refunding
function _cancel(
uint96 lotId_,
bytes calldata callbackData_
) internal virtual returns (bool performedCallback);

Parameters

NameTypeDescription
lotId_uint96The auction lot ID
callbackData_bytesCalldata for the callback

Returns

NameTypeDescription
performedCallbackbooltrue if the implementing function calls the onCancel callback

getAuctionModuleForId

Gets the auction module for a given lot ID

The function reverts if:

  • The lot ID is invalid
  • The module for the auction type is not installed
function getAuctionModuleForId(uint96 lotId_) external view override returns (IAuction);

Parameters

NameTypeDescription
lotId_uint96ID of the auction lot

Returns

NameTypeDescription
<none>IAuctionmodule The auction module

getDerivativeModuleForId

Gets the derivative module for a given lot ID

The function reverts if:

  • The lot ID is invalid
  • The module for the derivative type is not installed
function getDerivativeModuleForId(uint96 lotId_) external view override returns (IDerivative);

Parameters

NameTypeDescription
lotId_uint96ID of the auction lot

Returns

NameTypeDescription
<none>IDerivativemodule The derivative module

_getAuctionModuleForId

Gets the module for a given lot ID

The function assumes:

  • The lot ID is valid
function _getAuctionModuleForId(uint96 lotId_) internal view returns (AuctionModule);

Parameters

NameTypeDescription
lotId_uint96ID of the auction lot

Returns

NameTypeDescription
<none>AuctionModuleAuctionModule

_getDerivativeModuleForId

Gets the module for a given lot ID

The function assumes:

  • The lot ID is valid
function _getDerivativeModuleForId(uint96 lotId_) internal view returns (DerivativeModule);

Parameters

NameTypeDescription
lotId_uint96ID of the auction lot

Returns

NameTypeDescription
<none>DerivativeModuleDerivativeModule

_onCreateCallback

function _onCreateCallback(
IAuctionHouse.RoutingParams calldata routing_,
uint96 lotId_,
uint256 capacity_,
bool preFund_
) internal;

_getAddressGivenCallbackBaseTokenFlag

function _getAddressGivenCallbackBaseTokenFlag(
ICallback callbacks_,
address seller_
) internal pure returns (address);

_isLotValid

Checks that the lot ID is valid

Reverts if the lot ID is invalid

function _isLotValid(uint96 lotId_) internal view;

Parameters

NameTypeDescription
lotId_uint96ID of the auction lot

curate

Accept curation request for a lot.

This function performs the following:

  • Checks that the lot ID is valid
  • Checks that the caller is the proposed curator
  • Validates state
  • Sets the curated state to true
  • Calls the implementation-specific logic for curation
  • Calls the onCurate callback (if needed)

This function reverts if:

  • The lot ID is invalid
  • The caller is not the proposed curator
  • The auction has ended or is already curated
  • Re-entrancy is detected
function curate(uint96 lotId_, bytes calldata callbackData_) external override nonReentrant;

Parameters

NameTypeDescription
lotId_uint96Lot ID
callbackData_bytes(optional) abi-encoded data to be sent to the onCurate callback function

_curate

Implementation-specific logic for curation

Inheriting contracts can implement additional logic, such as:

  • Validation
  • Prefunding
function _curate(
uint96 lotId_,
uint256 curatorFeePayout_,
bytes calldata callbackData_
) internal virtual returns (bool performedCallback);

Parameters

NameTypeDescription
lotId_uint96The auction lot ID
curatorFeePayout_uint256The amount to pay the curator
callbackData_bytesCalldata for the callback

Returns

NameTypeDescription
performedCallbackbooltrue if the implementing function calls the onCurate callback

setFee

Sets the protocol fee, referrer fee, or max curator fee for a specific auction type

Implemented in this contract as it required access to the onlyOwner modifier

function setFee(Keycode auctionType_, FeeType type_, uint48 fee_) external override onlyOwner;

Parameters

NameTypeDescription
auctionType_KeycodeAuction type to set fees for
type_FeeTypeType of fee to set
fee_uint48Fee to charge

setProtocol

Sets the protocol address

Implemented in this contract as it required access to the onlyOwner modifier

function setProtocol(address protocol_) external override onlyOwner;

Parameters

NameTypeDescription
protocol_addressAddress of the protocol

setCondenser

Sets the value of the Condenser for a given auction and derivative combination

To remove a condenser, set the value of condenserRef_ to a blank Veecode

This function will revert if:

  • The caller is not the owner
  • auctionRef_ or derivativeRef_ are empty
  • auctionRef_ does not belong to an auction module
  • derivativeRef_ does not belong to a derivative module
  • condenserRef_ does not belong to a condenser module
function setCondenser(
Veecode auctionRef_,
Veecode derivativeRef_,
Veecode condenserRef_
) external onlyOwner;

Parameters

NameTypeDescription
auctionRef_VeecodeThe auction type
derivativeRef_VeecodeThe derivative type
condenserRef_VeecodeThe condenser type

_collectPayment

Convenience function to collect payment of the quote token from the user

This function calls the Transfer library to handle the transfer of the quote token

function _collectPayment(
uint256 amount_,
ERC20 quoteToken_,
Transfer.Permit2Approval memory permit2Approval_
) internal;

Parameters

NameTypeDescription
amount_uint256Amount of quoteToken to collect (in native decimals)
quoteToken_ERC20Quote token to collect
permit2Approval_Transfer.Permit2ApprovalPermit2 approval data (optional)

_sendPayment

Convenience function to send payment of the quote token to the seller

This function calls the Transfer library to handle the transfer of the quote token

function _sendPayment(
address lotOwner_,
uint256 amount_,
ERC20 quoteToken_,
ICallback callbacks_
) internal;

Parameters

NameTypeDescription
lotOwner_addressOwner of the lot
amount_uint256Amount of quoteToken to send (in native decimals)
quoteToken_ERC20Quote token to send
callbacks_ICallbackCallbacks contract that may receive the tokens

_sendPayout

Sends the payout token to the recipient

This function handles the following:

  • If the lot has a derivative defined, mints the derivative token ot the recipient
  • Otherwise, sends the payout token to the recipient

This function assumes that:

  • The payout token has already been transferred to this contract
  • The payout token is supported (e.g. not fee-on-transfer)

This function reverts if:

  • The payout token transfer fails
  • The payout token transfer would result in a lesser amount being received
function _sendPayout(
address recipient_,
uint256 payoutAmount_,
Routing memory routingParams_,
bytes memory auctionOutput_
) internal;

Parameters

NameTypeDescription
recipient_addressAddress to receive payout
payoutAmount_uint256Amount of payoutToken to send (in native decimals)
routingParams_RoutingRouting parameters for the lot
auctionOutput_bytesOutput data from the auction module

_allocateQuoteFees

Allocates fees on quote tokens to the protocol and referrer

This function calculates the fees for the quote token and updates the balances.

function _allocateQuoteFees(
uint48 protocolFee_,
uint48 referrerFee_,
address referrer_,
ERC20 quoteToken_,
uint256 amount_
) internal returns (uint256 totalFees);

Parameters

NameTypeDescription
protocolFee_uint48The fee charged by the protocol
referrerFee_uint48The fee charged by the referrer
referrer_addressThe address of the referrer
quoteToken_ERC20The quote token
amount_uint256The amount of quote tokens