A fair token auction platform built on the NEAR Protocol, inspired by Gnosis EasyAuction. This platform enables batch auctions for initial token offerings with a fair price discovery mechanism.
NEAR Token Auction is a smart contract that facilitates batch auctions, where a predefined amount of tokens is offered for sale. The auction mechanism ensures fair price discovery through a uniform clearing price model.
- Batch Auction Mechanism: All orders are collected during the bidding period and settled at a uniform clearing price
- Fair Price Discovery: Final price is determined by matching buy orders from highest to lowest until the supply is exhausted
- Token Standards: Built using NEAR's fungible token standards (NEP-141)
- Storage Management: Efficient storage handling with proper deposit/withdrawal mechanisms
- Order Management: Supports order placement, cancellation, and settlement
-
Initialization:
- Auctioneer creates auction specifying:
- Token to be sold (auctioning token)
- Minimum price
- Auction duration
- Total supply for sale
- Auctioneer creates auction specifying:
-
Bidding Phase:
- Bidders register and place orders with their desired:
- Amount of tokens to buy
- Maximum price willing to pay
- Orders can be placed until auction end time
- Bidders register and place orders with their desired:
-
Settlement:
- After auction ends, the final price is calculated
- Winning orders are determined
- Tokens are distributed to winning bidders
- Excess payments are refunded
The final clearing price is determined by:
- Sorting all buy orders from highest to lowest price
- Accumulating order volumes until reaching total supply
- Setting uniform clearing price at the last included order
- All winning bids pay the same clearing price
pub struct Contract {
token: FungibleToken,
metadata: LazyOption<FungibleTokenMetadata>,
auction: Auction,
orders: Vector<Order>
}
new
: Initialize new auctionregister_bidder
: Register account for participationplace_order
: Submit bid for tokenssettle_auction
: Calculate final price and winnersclaim_tokens
: Withdraw won tokensrefund_deposit
: Return funds for non-winning bids
Deploy contract
near deploy --wasmFile res/fungible_token.wasm --accountId auction.near
Initialize auction
near call auction.near new '{"owner_id": "owner.near","total_supply": "1000000000000000","metadata": {...},"auction_duration": "100000000000","min_buy_amount": "1000000000000000000000000"}' --accountId owner.near
Register as bidder
near call auction.near register_bidder --accountId bidder.near --deposit 0.1
Place order
near call auction.near place_order '{"buy_amount": "1000000000000000000"}' --accountId bidder.near --deposit 1
- NEAR CLI
- Rust
- Near Workspaces for testing
cargo near build
RUST_TEST_THREADS=1 cargo test -- --nocapture
- Implements proper storage management
- Handles decimal precision carefully
- Includes checks for overflow/underflow
- Validates auction parameters
- Ensures proper access control
This implementation was inspired by Gnosis EasyAuction, adapted for the NEAR Protocol ecosystem.