AuctionHouse
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
Name | Type | Description |
---|---|---|
routing_ | IAuctionHouse.RoutingParams | Routing information for the auction lot |
params_ | IAuction.AuctionParams | Auction parameters for the auction lot |
infoHash_ | string | IPFS hash of the auction information |
Returns
Name | Type | Description |
---|---|---|
lotId | uint96 | ID 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | The auction lot ID |
routing_ | IAuctionHouse.RoutingParams | RoutingParams |
params_ | IAuction.AuctionParams | AuctionParams |
Returns
Name | Type | Description |
---|---|---|
performedCallback | bool | true 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | ID 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | The auction lot ID |
callbackData_ | bytes | Calldata for the callback |
Returns
Name | Type | Description |
---|---|---|
performedCallback | bool | true 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | ID of the auction lot |
Returns
Name | Type | Description |
---|---|---|
<none> | IAuction | module 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | ID of the auction lot |
Returns
Name | Type | Description |
---|---|---|
<none> | IDerivative | module 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | ID of the auction lot |
Returns
Name | Type | Description |
---|---|---|
<none> | AuctionModule | AuctionModule |
_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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | ID of the auction lot |
Returns
Name | Type | Description |
---|---|---|
<none> | DerivativeModule | DerivativeModule |
_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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | ID 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | Lot 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
Name | Type | Description |
---|---|---|
lotId_ | uint96 | The auction lot ID |
curatorFeePayout_ | uint256 | The amount to pay the curator |
callbackData_ | bytes | Calldata for the callback |
Returns
Name | Type | Description |
---|---|---|
performedCallback | bool | true 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
Name | Type | Description |
---|---|---|
auctionType_ | Keycode | Auction type to set fees for |
type_ | FeeType | Type of fee to set |
fee_ | uint48 | Fee 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
Name | Type | Description |
---|---|---|
protocol_ | address | Address 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_
orderivativeRef_
are emptyauctionRef_
does not belong to an auction modulederivativeRef_
does not belong to a derivative modulecondenserRef_
does not belong to a condenser module
function setCondenser(
Veecode auctionRef_,
Veecode derivativeRef_,
Veecode condenserRef_
) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
auctionRef_ | Veecode | The auction type |
derivativeRef_ | Veecode | The derivative type |
condenserRef_ | Veecode | The 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
Name | Type | Description |
---|---|---|
amount_ | uint256 | Amount of quoteToken to collect (in native decimals) |
quoteToken_ | ERC20 | Quote token to collect |
permit2Approval_ | Transfer.Permit2Approval | Permit2 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
Name | Type | Description |
---|---|---|
lotOwner_ | address | Owner of the lot |
amount_ | uint256 | Amount of quoteToken to send (in native decimals) |
quoteToken_ | ERC20 | Quote token to send |
callbacks_ | ICallback | Callbacks 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
Name | Type | Description |
---|---|---|
recipient_ | address | Address to receive payout |
payoutAmount_ | uint256 | Amount of payoutToken to send (in native decimals) |
routingParams_ | Routing | Routing parameters for the lot |
auctionOutput_ | bytes | Output 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
Name | Type | Description |
---|---|---|
protocolFee_ | uint48 | The fee charged by the protocol |
referrerFee_ | uint48 | The fee charged by the referrer |
referrer_ | address | The address of the referrer |
quoteToken_ | ERC20 | The quote token |
amount_ | uint256 | The amount of quote tokens |