baozi protocol v4.6.2: smart contract deep dive
a comprehensive technical analysis of the baozi markets solana program. covers race markets, fee architecture, council resolution, and security mechanisms.
program overview
baozi markets v4.6.2 is a single solana program built with anchor framework. it handles all prediction market logic on-chain: market creation, betting, resolution, fee distribution, and claims.
account architecture
the protocol uses program-derived addresses (pdas) for all accounts. this ensures deterministic derivation and program ownership.
GlobalConfig
["config"]singleton storing protocol settings, fee configs, and kill switches. one per program deployment.
- • admin/treasury/guardian pubkeys
- • layer-specific fee settings
- • affiliate bonus budgets
- • market counter
Market
["market", market_id]binary yes/no market. stores pools, resolution state, creator/council config.
- • yes_pool / no_pool
- • snapshot values at close
- • council members (up to 5)
- • creator_fee_bps
RaceMarket
["race", market_id]multi-outcome pari-mutuel market. supports 2-10 outcomes, winner takes all.
- • outcome_pools[10]
- • outcome_labels[10]
- • fee snapshots at creation
- • council_votes[10]
UserPosition
["position", market_id, user]user bet position in binary market. tracks yes/no amounts and claim status.
- • yes_amount / no_amount
- • referred_by affiliate
- • claimed flag
RacePosition
["race_position", market_id, user]user bets across multiple outcomes. enables hedging strategies.
- • bets[10] per outcome
- • total_bet sum
- • claimed flag
CreatorProfile
["creator_profile", owner]on-chain creator reputation. stores earnings, market stats, verification status.
- • display_name
- • is_verified + type
- • pending_sol earnings
- • default_creator_fee_bps
Affiliate
["affiliate", owner]affiliate account for referral tracking. stores unique code and earnings.
- • unique code
- • total_referred_users
- • pending_sol earnings
fee architecture
gross winnings model
all fees are calculated on gross winnings (stake + profit), not just profit. this creates consistent ux across binary and race markets.
solvency constraint
critical security rule: creator and affiliate fees must not exceed platform fee. this ensures the protocol can always pay winners.
with 3% platform fee and 1% affiliate fee, creators can set up to 2% fee.
per-market fee snapshots (v4.6.2)
race markets snapshot fee settings at creation time. this protects existing markets from admin fee changes that could break solvency.
existing markets use their snapshot values. only new markets use updated global settings.
race markets deep dive
multi-outcome design
race markets support 2-10 outcomes with winner-takes-all resolution. users can bet on multiple outcomes in the same market (hedging).
- fixed-size arrays: outcome_pools[10], outcome_labels[32 bytes each]
- outcome_count determines valid indices (2-10)
- total_pool = sum of all outcome pools
- payout = (user_bet / winning_pool) * total_pool - fees
council resolution
private race markets can use council-based resolution with 3-5 members. each member votes for a winning outcome.
- council_votes[10] tracks votes per outcome
- council_threshold determines majority needed
- race markets require 3-5 council members (binary allows 2-5)
- first outcome to reach threshold wins
snapshot mechanism
at closing_time, pool values are snapshotted. all claims use snapshot values, preventing manipulation after betting closes.
three-layer system
official (layer 0)
2.5% feeadmin-curated markets with BaoziTvs resolution.
- creation: admin only
- resolution: admin or guardian
- creation fee: 0.1 SOL
labs (layer 1)
3% feecommunity sandbox for anyone to create markets.
- creation: anyone with creator profile
- resolution: market creator (HostOracle)
- creation fee: 0.04 SOL
private (layer 2)
2% feeinvite-only tables with council resolution option.
- access: whitelist or invite hash
- resolution: host or council (3-5 members)
- creation fee: 0.04 SOL
security mechanisms
pda ownership
all accounts owned by program, not user wallets. prevents unauthorized modifications.
signer validation
every mutation requires appropriate signer (admin, creator, council member).
overflow protection
BN arithmetic for all amounts. checked_add/checked_mul prevent overflow.
fee solvency
creator + affiliate fees capped at platform fee. protocol always pays winners.
snapshot immutability
pool values frozen at market close. claims use snapshots, not live values.
claim deduplication
claimed flag prevents double-claiming. one claim per position.
key constants
common error codes
resources
disclaimer
this documentation is for educational purposes. smart contracts involve risk. review code before interacting with any protocol.