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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! 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_accrual += 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`.
/// Transfer µUSDC from the treasury vault to a recipient ATA.
///
/// `pool` selects which jackpot counter to debit:
/// - `DISBURSE_POOL_NONE` — bet-round winners (vault only; counters unchanged)
/// - `DISBURSE_POOL_DAILY` — daily jackpot winners
/// - `DISBURSE_POOL_WEEKLY` — weekly jackpot winners (partial release; call
/// `AdminFinalizeWeekly` afterward to sweep leftover accrual → stability)
///
/// Only `EXECUTOR_ADDRESS` may sign. Emits `Paid`.
///
/// **Accounts:** `executor` (signer), `treasury`, `treasury_ata`, `recipient_ata`, `mint`,
/// `token_program`.
/// Executor-only: sweep remaining `weekly_jackpot` into `stability_reserve` at week end.
///
/// No USDC transfer — accounting only. Emits `WeeklyFinalized`.
///
/// **Accounts:** `executor` (signer), `treasury`.
/// Executor-only: sweep remaining `daily_jackpot` into `stability_reserve` at UTC day end.
///
/// No USDC transfer — accounting only. Emits `DailyFinalized`.
///
/// **Accounts:** `executor` (signer), `treasury`.
/// T+1 rotation: move `daily_accrual` → `daily_jackpot` for the next UTC day.
///
/// Requires `daily_jackpot == 0` (call `AdminFinalizeDaily` first). Emits `DailyRotated`.
///
/// **Accounts:** `executor` (signer), `treasury`.
/// Executor-only: overwrite treasury pool counters (one-shot reconcile / migration).
///
/// Enforces `daily + daily_accrual + weekly + buyback + stability <= treasury_ata.amount`.
///
/// **Accounts:** `executor` (signer), `treasury`, `treasury_ata`, `mint`, `token_program`,
/// `system_program`.
use TryFromPrimitive;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;