Instructions Reference
Complete reference for all program instructions
Platform Management
create_platform_config
Initializes the global platform configuration (admin only).
Accounts:
authority(signer) - Platform admin authorityplatform_config(mut) - Platform configuration PDAsystem_program- System program
Parameters:
fee_basis_points: u16- Platform fee (e.g., 500 = 5%)fee_vault: Pubkey- Address to receive platform fees
Example:
pub fn create_platform_config(
ctx: Context<CreatePlatformConfig>,
fee_basis_points: u16,
fee_vault: Pubkey,
) -> Result<()>Validation:
- Fee basis points must be ≤ 10,000 (100%)
- Only callable once per platform
- Authority must be the program upgrade authority
update_platform_config
Updates platform configuration settings.
Accounts:
authority(signer) - Platform admin authorityplatform_config(mut) - Platform configuration PDA
Parameters:
fee_basis_points: Option<u16>- New platform feefee_vault: Option<Pubkey>- New fee vault address
Example:
pub fn update_platform_config(
ctx: Context<UpdatePlatformConfig>,
fee_basis_points: Option<u16>,
fee_vault: Option<Pubkey>,
) -> Result<()>Integrator Management
initialize_integrator
Sets up a new integrator configuration.
Accounts:
integrator(signer) - Integrator authorityintegrator_config(mut) - Integrator configuration PDAplatform_config- Platform configuration (for validation)system_program- System program
Parameters:
integrator_id: Pubkey- Unique integrator identifierfee_basis_points: u16- Integrator fee percentagefee_vault: Pubkey- Integrator fee collection address
Example:
pub fn initialize_integrator(
ctx: Context<InitializeIntegrator>,
integrator_id: Pubkey,
fee_basis_points: u16,
fee_vault: Pubkey,
) -> Result<()>PDA Derivation:
["integrator_config", integrator_id.as_ref()]Validation:
- Integrator fee + platform fee ≤ 50% (5,000 basis points)
- Integrator ID must be unique
- Fee vault must be a valid address
update_integrator_config
Modifies integrator settings.
Accounts:
integrator(signer) - Integrator authorityintegrator_config(mut) - Integrator configuration PDAplatform_config- Platform configuration (for validation)
Parameters:
fee_basis_points: Option<u16>- New integrator feefee_vault: Option<Pubkey>- New fee vault
Game Lifecycle
create_game
Creates a new chess game.
Accounts:
creator(signer) - Game creator (white player)integrator_config(mut) - Integrator configurationgame_authority- Game authority PDAgame_account(mut) - Game state accounttoken_mint- Entry fee token minttoken_vault(mut) - Game token escrowcreator_token_account(mut) - Creator's token accountmove_history(mut) - Move history accounttoken_program- SPL Token programassociated_token_program- Associated Token programsystem_program- System program
Parameters:
entry_fee: u64- Entry fee amount in token unitstime_control: Option<TimeControl>- Time control settingsrated_game: bool- Whether game affects ratingsallow_draw_offers: bool- Whether draw offers are allowed
Example:
pub fn create_game(
ctx: Context<CreateGame>,
entry_fee: u64,
time_control: Option<TimeControl>,
rated_game: bool,
allow_draw_offers: bool,
) -> Result<()>PDA Derivations:
// Game Account
["game", integrator_id.as_ref(), game_id.to_le_bytes().as_ref()]
// Token Vault
["token_vault", token_mint.as_ref(), game_account.as_ref()]
// Move History
["move_history", game_account.as_ref()]
// Game Authority
["game_authority"]State Changes:
- Game status:
WaitingForPlayer - Board initialized to starting position
- Creator's entry fee transferred to escrow
- Game ID incremented in integrator config
join_game
Joins an existing game as the black player.
Accounts:
joiner(signer) - Joining player (black)integrator_config- Integrator configurationgame_authority- Game authority PDAgame_account(mut) - Game state accounttoken_mint- Entry fee token minttoken_vault(mut) - Game token escrowplayer_token_account(mut) - Joiner's token accountmove_history- Move history accounttoken_program- SPL Token programsystem_program- System program
Example:
pub fn join_game(ctx: Context<JoinGame>) -> Result<()>Validation:
- Game must be in
WaitingForPlayerstatus - Joiner cannot be the same as creator
- Joiner must have sufficient token balance
State Changes:
- Game status:
InProgress - Black player set to joiner
- Joiner's entry fee transferred to escrow
- Game timer started (if time control enabled)
cancel_game
Cancels a game before an opponent joins.
Accounts:
creator(signer) - Game creatorintegrator_config- Integrator configurationgame_authority- Game authority PDAgame_account(mut) - Game state accounttoken_mint- Entry fee token minttoken_vault(mut) - Game token escrowplayer_token_account(mut) - Creator's token accounttoken_program- SPL Token program
Example:
pub fn cancel_game(ctx: Context<CancelGame>) -> Result<()>Validation:
- Only creator can cancel
- Game must be in
WaitingForPlayerstatus - No opponent has joined yet
State Changes:
- Game status:
Cancelled - Creator's entry fee refunded
- Token vault emptied
Gameplay Instructions
make_move
Executes a chess move.
Accounts:
player(signer) - Player making the moveintegrator_config- Integrator configurationgame_account(mut) - Game state accountmove_history(mut) - Move history account
Parameters:
from_square: u8- Source square (0-63)to_square: u8- Destination square (0-63)promotion_piece: Option<PieceType>- Piece to promote to (for pawn promotion)
Example:
pub fn make_move(
ctx: Context<MakeMove>,
from_square: u8,
to_square: u8,
promotion_piece: Option<PieceType>,
) -> Result<()>Validation:
- Must be player's turn
- Game must be in
InProgressstatus - Move must be legal according to chess rules
- Cannot leave own king in check
- Time control validation (if enabled)
State Changes:
- Board state updated
- Move added to history
- Turn switched to opponent
- Game status updated if game ends
- Time control updated
Special Move Handling:
- Castling: King and rook moved simultaneously
- En Passant: Captured pawn removed from board
- Promotion: Pawn replaced with chosen piece
forfeit_game
Forfeits the current game.
Accounts:
player(signer) - Player forfeitingintegrator_config- Integrator configurationgame_account(mut) - Game state account
Example:
pub fn forfeit_game(ctx: Context<ForfeitGame>) -> Result<()>Validation:
- Player must be a participant in the game
- Game must be in
InProgressstatus
State Changes:
- Game status:
Finished - Game result:
Resignation - Winner set to opponent
- Forfeit timestamp recorded
Draw System
offer_draw
Offers a draw to the opponent.
Accounts:
player(signer) - Player offering drawintegrator_config- Integrator configurationgame_account(mut) - Game state account
Example:
pub fn offer_draw(ctx: Context<OfferDraw>) -> Result<()>Validation:
- Must be player's turn
- Game must allow draw offers
- Game must be in
InProgressstatus - No pending draw offer exists
State Changes:
- Draw offer flag set
- Draw offer timestamp recorded
- Offering player recorded
accept_draw
Accepts a pending draw offer.
Accounts:
player(signer) - Player accepting drawintegrator_config- Integrator configurationgame_account(mut) - Game state account
Example:
pub fn accept_draw(ctx: Context<AcceptDraw>) -> Result<()>Validation:
- Pending draw offer must exist
- Player must be the opponent of draw offerer
- Game must be in
InProgressstatus
State Changes:
- Game status:
Finished - Game result:
DrawByAgreement - No winner (draw)
- Draw acceptance timestamp
reject_draw
Rejects a pending draw offer.
Accounts:
player(signer) - Player rejecting drawintegrator_config- Integrator configurationgame_account(mut) - Game state account
Example:
pub fn reject_draw(ctx: Context<RejectDraw>) -> Result<()>State Changes:
- Draw offer flag cleared
- Game continues normally
Prize Management
claim_winnings
Claims the prize pool after game completion.
Accounts:
player(signer) - Player claiming winningsintegrator_config- Integrator configurationplatform_config- Platform configurationgame_authority- Game authority PDAgame_account- Game state accounttoken_mint- Prize token minttoken_vault(mut) - Game token escrowplayer_token_account(mut) - Player's token accountplatform_fee_vault(mut) - Platform fee collectionintegrator_fee_vault(mut) - Integrator fee collectiontoken_program- SPL Token program
Example:
pub fn claim_winnings(ctx: Context<ClaimWinnings>) -> Result<()>Validation:
- Game must be finished
- Player must be eligible for winnings
- Winnings not already claimed
Prize Distribution:
let total_prize = entry_fee * 2;
let platform_fee = total_prize * platform_fee_bps / 10000;
let integrator_fee = total_prize * integrator_fee_bps / 10000;
let player_payout = total_prize - platform_fee - integrator_fee;State Changes:
- Winnings claimed flag set
- Tokens distributed to respective accounts
- Token vault emptied
close_game
Closes a finished game and reclaims rent.
Accounts:
authority(signer) - Game participant or admingame_account(mut) - Game state accountmove_history(mut) - Move history accountrent_receiver(mut) - Account to receive reclaimed rent
Example:
pub fn close_game(ctx: Context<CloseGame>) -> Result<()>Validation:
- Game must be finished or cancelled
- All winnings must be claimed (if applicable)
- Authority must be a game participant
State Changes:
- Game account closed
- Move history account closed
- Rent returned to specified receiver
Error Conditions
Each instruction can fail with specific error codes. See the Error Codes reference for complete details.
Next Steps
- Account Structures - Detailed account schemas
- Error Codes - Complete error reference
- SDK Integration - Using instructions via SDK