Skip to content

metaggdev/Solana-Auction-Smart-Contract

Repository files navigation

Auction Smart Contract on Solana

A Solana auction smart contract for NFT auctions. Sellers list NFTs with a start price and duration; bidders place bids in HTO token. The highest bidder wins when the auction ends, with automatic royalty and fee distribution.


Table of Contents


Features

  • Create auction — List an NFT with start price and duration (1–14 days). NFT is escrowed by the program.
  • Place bid — Bid in HTO token; first bid must meet start price; outbids require ≥5% or 10 HTO increase. Previous bidder is refunded automatically.
  • Auction extension — Last 10 minutes: any new bid extends the end time by 10 minutes.
  • Cancel auction — Seller can cancel only if there are no bids; NFT is returned.
  • Claim auction — After end time, seller or winner can claim: NFT goes to winner, HTO to seller (minus 2% platform fee and creator royalties).

Project Architecture

Overview

The project is an Anchor program (Solana smart contract) that implements an NFT auction with SPL token bids (HTO). It uses Metaplex Token Metadata for NFT verification and creator royalty distribution.

Solana-Auction-Smart-Contract/
├── programs/
│   └── auction/
│       ├── src/
│       │   ├── lib.rs      # Program entry, instructions, account contexts
│       │   ├── account.rs  # GlobalPool, AuctionPool state
│       │   ├── error.rs    # AuctionError enum
│       │   └── utils.rs    # Constants, ATA creation, SPL transfers
│       └── Cargo.toml
├── tests/
│   └── auction.ts          # Anchor/TypeScript integration tests
├── cli/                     # Optional CLI (wallet-specific scripts)
├── Anchor.toml              # Anchor config (program ID, cluster, scripts)
├── Cargo.toml               # Workspace (programs/*)
└── package.json             # Node deps and test script

Program layout

Component Description
Program ID 6VwSgSesAeqqSw3uXsU8BGMxMAqSzFVQxPPUDUVX8Qw4 (devnet in Anchor.toml)
Instructions initialize, create_auction, cancel_auction, place_bid, claim_auction
State accounts GlobalPool (super admin), AuctionPool (per-auction: seller, NFT mint, bidder, current bid, start price, end time)

Data flow

  1. Initialize — Deployer creates the single GlobalPool PDA (seed: global-authority), sets super_admin.
  2. Create auction — Seller passes NFT mint + metadata; program checks Metaplex metadata and collection/creators, creates auction PDA and auction ATA, escrows 1 NFT from seller to program-owned ATA.
  3. Place bid — Bidder sends HTO to program-owned auction_vault; if there was a previous bidder, their HTO is refunded from vault. Bid rules: first bid ≥ start price; later bids ≥ current + 5% or +10 HTO; last 10 minutes extend end time by 10 minutes.
  4. Cancel auction — Only seller, only when current_bid == 0; NFT is transferred back to seller; auction PDA is closed.
  5. Claim auction — Callable by seller or winning bidder after end_time. Program: pays creator royalties (from metadata), 2% to VAULT_WALLET, remainder to seller; transfers NFT to winner; closes auction vault and auction PDA.

Dependencies (program)

  • anchor-lang / anchor-spl — Framework and token CPI
  • mpl-token-metadata — NFT metadata and creators (royalties)
  • spl-token, spl-associated-token-account — Token and ATA handling

Constants (in utils.rs)

  • GLOBAL_AUTHORITY_SEED: PDA seed for global config and escrow authority
  • DAY, MIN_DURATION_AFTER_BID_SECS: Duration bounds and extension window
  • FEE_PERCENT: 2% platform fee
  • MIN_INCREMENT_PERCENT / MIN_INCREMENT: 5% or 10 HTO minimum bid increase
  • VAULT_WALLET, HTO_TOKEN_MINT: Fee recipient and bid token mint

Requirements

  • Rust (for building the Solana program)
  • Solana CLI (for cluster and deployment)
  • Anchor (v0.27; see Anchor book)
  • Node.js and Yarn (for tests and optional CLI)

How to Run

1. Install tools

2. Clone and install

git clone https://github.com/husreodev/auction_contract.git
cd auction_contract
yarn install

3. Build the auction program

anchor build

This compiles the programs/auction crate and produces the program binary and IDL under target/.

4. Configure cluster and wallet

Anchor.toml is set to devnet and a wallet path (e.g. ../keys/user-Shit.json). Point provider.wallet to your keypair or set ANCHOR_WALLET when running commands.

For localnet:

# Terminal 1: run validator
solana-test-validator

Then in Anchor.toml set cluster = "localnet" (or override with anchor run / env).

5. Run tests

anchor test

This runs yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts (as in Anchor.toml), which executes the TypeScript tests in tests/auction.ts against the built program.

6. Deploy (e.g. devnet)

anchor deploy --provider.cluster devnet

Ensure the configured wallet has enough SOL and that the program ID in Anchor.toml matches your keypair-derived program ID (or update declare_id! in lib.rs and Anchor.toml after anchor keys list).

7. Optional: CLI scripts

The repo includes wallet-specific scripts in package.json (e.g. ts-node, ts-node-deployer) that use cli/command.ts. These depend on keypair paths (e.g. ../keys/...). Run only if you have set up those keys and adjusted paths:

yarn ts-node-user   # example; uses ANCHOR_WALLET from script

Program Instructions

Instruction Who Description
initialize Admin Creates GlobalPool PDA and sets super admin.
create_auction Seller Escrows NFT, sets start price and end time (1–14 days).
cancel_auction Seller Cancels if no bids; returns NFT and closes auction.
place_bid Bidder Locks HTO in vault; refunds previous bidder; enforces min increment and optional time extension.
claim_auction Seller or winner Settles: royalties + fee + seller payout in HTO; NFT to winner; closes auction.

Author

Telegram


Auction smart contract • Solana • Anchor • NFT auction • Blockchain auction

About

Solana auction smart contract for NFT auctions. Create auctions, place bids in HTO, claim with automatic royalties and fees. Built with Anchor.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages