Smart Contract Architecture
Overview
The Flip.is smart contract is built on the Solana blockchain using the Anchor framework. It implements a secure, scalable, and verifiably fair coin flip gaming system with support for multiple tokens and automated treasury management.
Contract Address
Program ID: 472RXUv8zUX7zm4LprxNsFQvAZYEpSGaY9EUE4akCvG6
Core Components
Account Structures
Global Account
This account maintains platform-wide settings:
Key fields:
admin_authority
: Administrator wallet with special permissionsfee_reciever
: Wallet designated for fee collectioninitialized
: Prevents multiple initializations
CoinFlipGame Account
Each game instance is represented by a CoinFlipGame account:
Key fields:
creator
: Game creator's wallet addresscreator_selection
: Creator's choice (heads/tails)oposite
: Opponent's wallet addressavailable_opposite
: Indicates if game is joinablebetting_amount
: Stake amount in lamports/tokensis_sol
: Differentiates between SOL and SPL token gamestoken_mint
: SPL token mint address (if applicable)start_time
: Game creation timestampis_finished
: Game completion statusindex
: Unique game identifier
Core Instructions
1. Initialize
Platform initialization process:
Verifies no existing initialization
Creates global configuration account
Sets up administrative controls
Establishes fee structure
Required accounts:
authority
: Admin signerglobal
: Platform configuration PDAsystem_program
: Solana system program
2. Create Game
Game creation workflow:
Validates parameters and accounts
Creates game PDA
Handles token/SOL deposits
Initializes VRF request
Emits creation event
Required accounts:
global
: Platform configurationfee_reciever
: Fee collection walletcreator
: Game creatornew_game
: Game account PDAtreasury
: Platform treasuryrandom
: VRF accountToken program (for SPL games)
3. Join Game
Game joining process:
Validates game availability
Processes opponent's deposit
Updates game state
Emits join event
Required accounts:
global
: Platform configurationfee_reciever
: Fee collectioncreator
: Original game creatorplayer
: Joining playercoin_flip_game
: Target game account
Security Features
Access Control
Program-derived addresses (PDAs)
Signer verification
Authority checks
State validation
Fund Safety
Escrow-based holding
Atomic transactions
Automatic refunds
Balance verification
Token Support
Supported Tokens
Native SOL Handling
SPL Token Support
Random Number Generation
The contract uses Orao VRF for secure random number generation:
Security measures:
On-chain verification
Tamper-proof results
Transparent process
Error Handling
Events
InitEvent
JoinEvent
HandleEvent
Contract Optimization
Space Optimization
Minimal account sizes
Efficient data structures
Optimal PDA seeds
Performance Considerations
Minimized CPI calls
Efficient token handling
Optimized account lookups
Testing and Deployment
Test Scripts
Located in scripts/ directory:
Integration tests
Unit tests
Simulation tests
Deployment Process
Program deployment
Global initialization
Authority setup
Token configuration
Last updated