1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Instruction discriminators + payload types.
use *;
/// One-time setup: creates `Treasury` PDA + treasury USDC ATA. `payer` must be `ADMIN_ADDRESS`.
///
/// **Accounts:** `payer`, `treasury`, `mint`, `treasury_ata`, `system_program`, `token_program`,
/// `ata_program`.
/// Purchase tickets (gaming credits) with USDC.
///
/// Buying tickets is separate from placing a bet. The user first buys credits here
/// (on-chain, USDC split immediately), then places bets off-chain via the server
/// using those credits.
///
/// 1. Transfers `amount` µUSDC from the user's ATA into the treasury ATA.
/// 2. Updates `Treasury` PDA counters: `daily_jackpot += 70%`, `weekly_jackpot += 15%`,
/// `buyback += 10%`.
/// 3. Forwards the team share (5%) from the treasury ATA to `FEE_COLLECTOR` (CPI).
/// 4. Creates or increments the user's `UserCredits` PDA (`total_purchased += amount`).
/// 5. Emits `TicketPurchased { user, amount }`.
///
/// The indexer reads `TicketPurchased` events to credit the user's off-chain spendable
/// balance. Bets are placed and debited server-side against that balance.
///
/// **Accounts:** `user` (signer/payer), `user_ata`, `treasury`, `treasury_ata`, `credits`,
/// `fee_collector_ata`, `mint`, `token_program`, `system_program`.
/// Route claimed DBC / DAMM v2 trading fees into the treasury and split them on-chain.
///
/// The executor bot claims pool creator/LP fees off-chain via the Meteora SDK, receiving USDC
/// into its own ATA. This instruction then:
/// 1. Transfers `amount` µUSDC from the executor's ATA into the treasury ATA (CPI).
/// 2. Splits the amount according to `TICKET_*_BPS` and updates `Treasury` counters.
/// 3. Forwards the team share (5%) from the treasury ATA to `FEE_COLLECTOR` (CPI).
/// 4. Emits `FeesRouted`.
///
/// **Accounts:** `executor` (signer), `executor_ata`, `treasury`, `treasury_ata`,
/// `fee_collector_ata`, `mint`, `token_program`.
/// Pay `amount` µUSDC from the treasury ATA to `recipient_ata`. Used for winner payouts and
/// jackpot distributions. Only `EXECUTOR_ADDRESS` may sign.
///
/// **Accounts:** `executor` (signer), `treasury`, `treasury_ata`, `recipient_ata`, `mint`,
/// `token_program`.
/// Place one bet for the current round.
///
/// Rules enforced on-chain:
/// 1. `User.balance >= TICKET_PRICE_MICROS` (must have at least 1 ticket).
/// 2. `User.last_bet_period != period` (one bet per round, no double-betting).
/// 3. Debits exactly `TICKET_PRICE_MICROS` from `User.balance`.
/// 4. Sets `User.last_bet_period = period`.
/// 5. Emits `BetPlaced { user, period, side }`.
///
/// The indexer reads `BetPlaced` to insert the bet into the DB and update market pools.
/// The server builds and returns an unsigned `PlaceBet` tx; the user signs in their wallet.
///
/// **Accounts:** `user` (signer), `user_pda`.
use TryFromPrimitive;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;