Skip to main content

Auctioneer Contract

The Auctioneer Contract is a Solidity smart contract that implements an auction mechanism for selling block space. This contract allows bidders to participate in auctions, submit manual bids, and settle the auctions. It supports multiple bidders, each with a unique ID.

Key Features

  • Bidders: Add and remove bidders dynamically.
  • Auctions: Open and run auctions for selling block space.
  • Manual Bids: Bidders can submit manual bids with specific quantities and prices.
  • Settlement: After the auction, settle with successful bidders, transferring owed amounts.

Contract Structure

  • The contract is based on the ERC6909 standard.
  • It uses the SafeTransferLib for safe WETH (Wrapped Ether) transfers.
  • Bidders can participate through the getBid function.
  • Manual bids are supported via the bid function.

Events

  • BidderAdded and BidderRemoved for dynamic management of bidders.
  • AuctionOpened signals the start of a new auction.
  • ManualBidSubmitted is emitted when a bidder submits a manual bid.
  • AuctionSettled indicates the successful settlement of an auction.

Errors

  • Various error messages to handle exceptional cases, such as invalid bids or insufficient funds.

Functions

  • newBidder: Add a new bidder to the auction.
  • removeBidder: Remove a bidder from the auction.
  • openAuction: Open a new auction for a specific slot.
  • bid: Submit a bid for a specific auction slot.
  • run: Execute the auction for a specific slot, considering manual and contract bids.
  • settle: Settle the auction by transferring owed amounts to successful bidders.
  • getBidderInfo: Retrieve information about a bidder after auction settlement.
  • packBid: Pack bid details into a uint256 for submission.
  • decodeBid: Decode packed bid information for analysis.
  • checkBid: Check the validity of a bid before execution.

State Variables

maxBidder

uint8 public maxBidder;

WETH9

WETH public WETH9;

IdMap

mapping(address => uint8) public IdMap;

bidderMap

mapping(uint8 => address) public bidderMap;

auctions

mapping(uint256 => Auction) public auctions;

bidCount

mapping(uint256 => uint256) internal bidCount;

bids

mapping(uint256 => mapping(uint256 => uint256)) internal bids;

Functions

constructor

constructor(WETH _weth) Owned(msg.sender);

onlyAuctionOpen

modifier onlyAuctionOpen(uint256 slot);

newBidder

Add a new bidder to the auction.

function newBidder(address additionalBidder) external onlyOwner returns (uint8 newId);

Parameters

NameTypeDescription
additionalBidderaddressThe address of the additional bidder.

removeBidder

Remove a bidder from the auction.

function removeBidder(uint8 bidderId) external onlyOwner;

Parameters

NameTypeDescription
bidderIduint8The index of the bidder to be removed.

openAuction

Open a new auction for a specific slot.

function openAuction(uint256 slot, uint120 itemsForSale) external onlyOwner;

Parameters

NameTypeDescription
slotuint256The auction slot.
itemsForSaleuint120The number of items available for sale in the auction.

bid

Bid function for bidders to submit manual bids.

function bid(uint256 slot, uint256[] memory packedBids) external;

Parameters

NameTypeDescription
slotuint256The auction slot.
packedBidsuint256[]Array of packed bids

run

Execute the auction for a specific slot.

function run(uint256 slot) external onlyAuctionOpen(slot) onlyOwner;

Parameters

NameTypeDescription
slotuint256The auction slot.

settle

Settle the auction for a specific slot.

function settle(uint256 slot) external onlyOwner;

Parameters

NameTypeDescription
slotuint256The auction slot.

getBidderInfo

Retrieve information about a bidder after auction settlement.

function getBidderInfo(uint256 slot, address bidder) external view returns (uint120 itemsBought, uint128 amountOwed);

Parameters

NameTypeDescription
slotuint256The slot identifier of the auction.
bidderaddressThe address of the bidder for whom information is requested.

Returns

NameTypeDescription
itemsBoughtuint120The number of items bought by the bidder in the specified auction.
amountOweduint128The amount owed by the bidder for the items bought in the specified auction. Requirements: - The auction must have been settled. - The provided bidder address must be valid and have participated in the auction.

packBid

Packed Bid details into a uint256 for submission.

function packBid(uint256 bidPrice, uint256 itemsToBuy, uint256 bidderId) external pure returns (uint256 packedBid);

Parameters

NameTypeDescription
bidPriceuint256Price per item.
itemsToBuyuint256Items to buy in the auction.
bidderIduint256Id for bidder

Returns

NameTypeDescription
packedBiduint256for auction submission

decodeBid

Decode the packed bid information.

function decodeBid(uint256 packedBid) internal pure returns (uint8 bidderId, uint120 itemsToBuy, uint128 bidPrice);

Parameters

NameTypeDescription
packedBiduint256The packed bid information.

Returns

NameTypeDescription
bidderIduint8The bidder's ID.
itemsToBuyuint120The number of items the bidder wants to buy.
bidPriceuint128The price per item in the bid.

checkAndStoreBid

Check the validity of a bid.

function checkAndStoreBid(address bidder, uint256 slot, uint256 itemsForSale, uint256[] memory packedBids) internal;

Parameters

NameTypeDescription
bidderaddressAddress of bidder.
slotuint256The auction slot.
itemsForSaleuint256Total items for sale for the slot.
packedBidsuint256[]Array of packed bids Requirements: - The number of items in the bid must not exceed the available items for sale in the auction. - The bidder must have enough funds to cover the bid amount.

isContract

checks codesize for contract existence

function isContract(address _addr) internal view returns (bool _isContract);

Parameters

NameTypeDescription
_addraddressaddress of contract to check

Events

AuctionSettled

event AuctionSettled(uint256 indexed slot);

BidderAdded

event BidderAdded(address indexed bidder, uint8 bidderId);

BidderRemoved

event BidderRemoved(address indexed bidder, uint8 bidderId);

AuctionOpened

event AuctionOpened(uint256 indexed slot, uint120 itemsForSale);

Errors

InvalidId

error InvalidId();

InvalidBidItems

error InvalidBidItems();

InsufficientFunds

error InsufficientFunds();

AuctionNotOpen

error AuctionNotOpen(uint256 slot);

AuctionNotClosed

error AuctionNotClosed(uint256 slot);

AuctionAlreadyOpen

error AuctionAlreadyOpen(uint256 slot);

AuctionAlreadySettled

error AuctionAlreadySettled(uint256 slot);

BidderNotRegistered

error BidderNotRegistered(address bidder);

BidderAlreadyExists

error BidderAlreadyExists(address bidder);

Structs

Auction

struct Auction {
uint120 itemsForSale;
bool isOpen;
bool isSettled;
mapping(address => BidderInfo) biddersInfo;
}

BidderInfo

struct BidderInfo {
uint120 itemsBought;
uint128 amountOwed;
}