baozi
Solana
...
back to insights
Technical15 min read

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.

program idCPZZD3kHrw8MQvj4H4KLVcmXPzzX3XkKsAT8FZ7UJ7ZH
networkSolana Devnet (production-ready)
frameworkAnchor 0.30+
source lines~5,000 lines of Rust

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.

gross_winnings = user_share * total_pool
platform_fee = gross_winnings * platform_bps / 10000
creator_fee = gross_winnings * creator_bps / 10000
affiliate_fee = gross_winnings * affiliate_bps / 10000
net_payout = gross_winnings - all_fees

solvency constraint

critical security rule: creator and affiliate fees must not exceed platform fee. this ensures the protocol can always pay winners.

require!(creator_fee_bps + affiliate_fee_bps <= platform_fee_bps)

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.

platform_fee_bps_at_creation: u16
affiliate_fee_bps_at_creation: u16

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.

// at market close
snapshot_pools = outcome_pools.clone()
snapshot_total = total_pool
// payout uses snapshots
payout = (position.bets[winner] / snapshot_pools[winner]) * snapshot_total

three-layer system

official (layer 0)

2.5% fee

admin-curated markets with BaoziTvs resolution.

  • creation: admin only
  • resolution: admin or guardian
  • creation fee: 0.1 SOL

labs (layer 1)

3% fee

community sandbox for anyone to create markets.

  • creation: anyone with creator profile
  • resolution: market creator (HostOracle)
  • creation fee: 0.04 SOL

private (layer 2)

2% fee

invite-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

MIN_BET_SOL0.01 SOL (10,000,000 lamports)
MAX_BET_SOL100 SOL
MAX_RACE_OUTCOMES10
MAX_COUNCIL_SIZE5
MIN_COUNCIL_SIZE (race)3
BETTING_FREEZE_PERIOD5 minutes before close
EMERGENCY_RESOLUTION48 hours after close
MAX_RESOLUTION_BUFFER30 days

common error codes

6000Unauthorized
6010ProtocolPaused
6020MarketNotActive
6026BettingClosed
6040BetTooLow
6044AlreadyClaimed
6049InvalidCouncilSize

disclaimer

this documentation is for educational purposes. smart contracts involve risk. review code before interacting with any protocol.