Instruction format
All instructions use Borsh serialization and are defined in theBiddingInstruction enum:
instructions/mod.rs:9-19 for the enum definition.
CreateGame
Creates a new bidding game with an initial bid. This instruction initializes the game state, creates the first player account, and records the first bid.Parameters
Unique identifier for the game. Must be unique across all games. Used as a seed for PDA derivation.
Initial bid amount in lamports. Must be at least 14,000,000 lamports (0.014 SOL).
Accounts
The CreateGame instruction requires the following accounts in order:The game PDA account to be created. Must be derived using seeds:
["game", game_id].- Writable: Yes
- Signer: No
- Size: 96 bytes
The account paying for rent and the initial bid. This becomes the first player.
- Writable: Yes
- Signer: Yes
The Solana system program account.
- Writable: No
- Signer: No
- Address:
11111111111111111111111111111111
The player PDA account to be created for the initial bidder. Must be derived using seeds:
["player", game_id, payer_pubkey, bid_count] where bid_count is 1.- Writable: Yes
- Signer: No
- Size: 32 bytes
The bid PDA account to be created for the initial bid. Must be derived using seeds:
["bid", game_id, bid_number] where bid_number is 1.- Writable: Yes
- Signer: No
- Size: 48 bytes
Validation
The instruction performs the following validation:- Initial bid amount must be ≥ 14,000,000 lamports (0.014 SOL)
- Game account must match expected PDA
- Player account must match expected PDA
- Bid account must match expected PDA
State initialization
The instruction initializes three accounts with the following data: GameState (game_account):- game_id: provided game_id
- initial_bid_amount: provided amount
- highest_bid: initial_bid_amount
- last_bid_time: current timestamp
- total_bids: 1
- last_bidder: payer pubkey
- prize_pool: initial_bid_amount
- platform_fee_percentage: 10 (hardcoded)
- game_ended: false
- total_bid_amount: initial_bid_amount
- safe: false
- royalty_earned: 0
- bid_count: 1
- bidder: payer pubkey
- amount: initial_bid_amount
- timestamp: current timestamp
instructions/create_game.rs:106-133 for initialization logic.
SOL transfers
The instruction transfersinitial_bid_amount lamports from the payer to the game account after initialization.
Example usage
PlaceBid
Places a new bid on an existing game. Creates a new player state and bid record for the bidder.Parameters
Bid amount in lamports. Must be at least double the current highest bid.
Expected bid count after this bid (current total_bids + 1). Used to prevent race conditions.
Accounts
The PlaceBid instruction requires the following accounts in order:The Solana system program account.
- Writable: No
- Signer: No
The platform fee recipient account (used when game ends).
- Writable: Yes
- Signer: No
The existing game PDA account.
- Writable: Yes
- Signer: No
The account placing the bid and paying for it.
- Writable: Yes
- Signer: Yes
The new bid PDA account to be created. Must be derived using seeds:
["bid", game_id, new_bid_count].- Writable: Yes
- Signer: No
The new player PDA account to be created. Must be derived using seeds:
["player", game_id, bidder_pubkey, new_bid_count].- Writable: Yes
- Signer: No
Validation
The instruction performs extensive validation:- Game account must have correct size (96 bytes)
- Game must not have ended (
game_ended == false) - Current time must be within 600 seconds (10 minutes) of last bid
- Bid amount must be ≥ 2x current highest bid
- Bid count must equal current total_bids + 1
- New player account must match expected PDA
- New bid account must match expected PDA
The bid_count parameter prevents race conditions by ensuring the bidder knows the current game state.
State updates
The instruction updates and creates the following state: GameState (updated):- highest_bid: new bid_amount
- last_bid_time: current timestamp
- last_bidder: bidder pubkey
- total_bids: incremented by 1
- prize_pool: increased by bid_amount
- total_bid_amount: bid_amount
- safe: false
- royalty_earned: 0
- bid_count: new_bid_count
- bidder: bidder pubkey
- amount: bid_amount
- timestamp: current timestamp
instructions/place_bid.rs:116-139 for state update logic.
SOL transfers
The instruction transfersbid_amount lamports from the bidder to the game account.
Automatic game ending
If the 10-minute timeout has expired, the instruction automatically callsend_game() which:
- Fetches complete bid history
- Calculates and distributes platform fees (10%)
- Distributes royalties to early bidders (if ≥5 bids)
- Awards remaining balance to last bidder
- Marks game as ended
instructions/place_bid.rs:153-236 for game ending logic.
Example usage
Error handling
Both instructions return detailed error codes on failure. Common errors include:InsufficientInitialBid- Initial bid < 0.014 SOLInvalidGameAccount- Game PDA doesn’t match expected addressInvalidPlayerAccount- Player PDA doesn’t match expected addressInvalidBidAccount- Bid PDA doesn’t match expected addressGameEnded- Cannot bid on ended gameInsufficientBidAmount- Bid < 2x highest bidBidCountMismatch- Provided bid_count doesn’t match expected value
error.rs:4-50 for all error definitions.