Skip to content

Conversation

@indirection42
Copy link
Contributor

@indirection42 indirection42 commented Oct 1, 2025

Description

This PR is part of #9765. This PR introduces pallet-auction, a new FRAME pallet that provides a generic framework for on-chain auctions. The pallet allows for the creation and management of auctions for any type of asset, with customizable logic through the AuctionHandler trait.

The auction pallet implements a flexible auction mechanism that can be used to implement various auction types, such as English auctions, Dutch auctions, or other custom formats. It provides a standard interface through the Auction trait so other pallets can query and update auctions via a shared API.

Integration

This PR introduces a new pallet (pallet-auction) that downstream projects can integrate into their runtime. The integration requires:

  1. Runtime Configuration: Add the auction pallet to your runtime's construct_runtime! macro
  2. Handler Implementation: Implement the AuctionHandler trait to define custom auction logic
  3. Type Configuration: Configure the required types (Balance, AuctionId) in your runtime's config

Example integration:

impl pallet_auction::Config for Runtime {
    type Balance = Balance;
    type AuctionId = u32;
    type Handler = YourAuctionHandler;
    type WeightInfo = pallet_auction::weights::SubstrateWeight<Runtime>;
}

The pallet is designed to be generic and can work with any asset type through the handler implementation.

Review Notes

Implementation Details

The auction pallet uses a simple but effective storage design:

  • Auctions<T>: Maps auction IDs to auction information including current bid and timing
  • AuctionEndTime<T>: Double map from end block to auction ID for efficient batch processing of ending auctions
  • AuctionsIndex<T>: Tracks the next available auction ID for new auction creation

Key Features

  • Generic Auction Mechanism: Can be used for auctioning any asset
  • Customizable Logic: The AuctionHandler trait allows for custom implementation of auction logic
  • Scheduled Auctions: Auctions can be scheduled to start at a future block number
  • Automatic Auction Closing: Auctions are automatically closed at their end block number in the on_finalize hook
  • Standard Interface: Implements the Auction trait for interoperability

Auction Lifecycle

  1. Creation: Auctions are created with a start block and optional end block via new_auction()
  2. Active Phase: Bids can be placed during the active period via bid()
  3. Bid Processing: Each bid is validated by the handler and may extend the auction
  4. Conclusion: Auctions are automatically concluded at their end block

Storage Efficiency

The pallet uses efficient storage patterns:

  • Double map for AuctionEndTime allows batch processing of ending auctions
  • Automatic cleanup of ended auctions prevents storage bloat
  • Incremental auction ID generation prevents ID conflicts

Error Handling

The pallet includes comprehensive error handling:

  • AuctionNotExist: For invalid auction IDs
  • AuctionNotStarted: For bids placed before auction start
  • BidNotAccepted: For bids rejected by the handler
  • InvalidBidPrice: For invalid bid amounts
  • NoAvailableAuctionId: For auction ID overflow

Security Considerations

  • All bid operations require signed origins
  • Bid validation is enforced both at the pallet level and through the handler
  • Auction timing is enforced through block number checks
  • Storage operations are atomic to prevent inconsistent states

Checklist

  • My PR includes a detailed description as outlined in the "Description" and its two subsections above.
  • My PR follows the labeling requirements of this project (at minimum one label for T required)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@indirection42 indirection42 marked this pull request as ready for review October 1, 2025 04:07
@indirection42 indirection42 requested a review from a team as a code owner October 1, 2025 04:07
@indirection42
Copy link
Contributor Author

/cmd fmt

@indirection42
Copy link
Contributor Author

/cmd --help

@indirection42
Copy link
Contributor Author

/cmd label T1-FRAME

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant