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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! Instruction discriminators + payload types (**Ore**: single `instruction.rs`).
use *;
/// One-time **`Initialize`**: creates **`Treasury`** PDA + treasury USDC ATA. Economics and routing pubkeys are [`crate::consts`] (**`FEE_COLLECTOR`** for team-fee SPL legs). **`payer`** must be [`ADMIN_ADDRESS`](crate::consts::ADMIN_ADDRESS).
///
/// **Accounts:** **`payer`**, **`treasury`**, **`mint`**, **`treasury_ata`**, **`system_program`**, **`token_program`**, **`ata_program`**.
/// Purchase tickets: user pays **`amount`** USDC (**micro base units**); team cut to fee collector; remainder splits into **`Treasury`** pools; **`Ledger`** credits **`unstaked_micros`** and **`tickets`**.
///
/// **`previous_*`** resolves **`series_id`** + **`period - 1`** (same **`series_id`**).
///
/// **Accounts:** **`user`**, **`treasury`**, **`ledger`**, **`mint`**, **`user_ata`**, **`treasury_ata`**, **`team_ata`**, **`system_program`**, **`token_program`**, **`ata_program`**, **`previous_market`**, **`previous_position`**.
/// Spend **`ticket_units`** from **`Ledger`** into **`Position`** / **`Market`** while **`STATUS_OPEN`** and **`now < close_ts`**:
///
/// - **Pre-open commit** (no open oracle yet **or** **`now < open_ts`**): debits tickets; records **[`Position::STATE_COMMITTED_PREOPEN`]**; bumps **`market.committed_{side}`** only (**`total_*`** unchanged).
/// - **Live window** (**open oracle** + **`open_ts ≤ now < close_ts`**): merges any **[`Position::STATE_COMMITTED_PREOPEN`]** into **`total_*`** first; then debits tickets and adds to **`total_*`** as **[`Position::STATE_PENDING`]** (same as legacy stake).
/// - **Activate-only:** **`ticket_units == 0`** allowed only in the live window on an existing **COMMITTED** position (merges into **`total_*`** / **PENDING** without debiting).
///
/// **`period`** in the ix must match **`market.period`** (**PDA derivation**).
///
/// **Accounts:** **`user`**, **`ledger`**, **`treasury`** (**readonly**), **`market`**, **`position`**, **`previous_market`**, **`previous_position`**, **`system_program`**.
/// Creates **`Market`** (**executor signer**) **or** records open Pyth snapshot (crank).
///
/// **`Create`**: allowed whenever the **`Market`** PDA is **still empty** (executor may calendar **`open_ts`** / **`close_ts`** ahead of **`now`**; live **`PlaceBet`** that writes **`total_*`** remains **`BettingClosed`** until the open oracle anchor exists and **`open_ts ≤ now`**).
///
/// **Accounts:** **`authority`**, **`market`**, **`treasury`** (**readonly**), **`system_program`**, **`pyth_price_feed`** (**readonly**).
/// **`EXECUTOR_KIND_DISTRIBUTE_MARKET_REWARD`**: **`pool`** and **`amount`** must be **0** (**`series_id`** must match **`market.series_id`**).
///
/// **`EXECUTOR_KIND_JACKPOT_PAY`**: SPL **`transfer_checked`**; **`series_id`** should be **`0`**.
///
/// **`EXECUTOR_KIND_MARKET_LINE_RELEASE`**: **`amount`** = **`period`** LE; **`series_id`** in payload.
///
/// **`EXECUTOR_KIND_MERGE_COMMITTED_POSITION`**: **`pool`** and **`amount`** must be **0**; **`series_id`** must match **`position.series_id`**; merges one **[`Position::STATE_COMMITTED_PREOPEN`]** into **`Market::total_*`**. Accounts: **`executor`**, **`treasury`** (**readonly**), **`market`**, **`position`**.
/// Void an open market when BTC moves < 0.01% (or for oracle failure).
///
/// **Authority**: `ADMIN_ADDRESS` or `EXECUTOR_ADDRESS` (both accepted).
///
/// **Accounts:** `authority` (signer), `treasury` (readonly), `market`.
///
/// Preconditions: `market.status == STATUS_OPEN`, `committed_up == 0`, `committed_down == 0`
/// (all pre-open committed positions must have been merged before voiding).
/// The instruction may be called before or after `close_ts`.
///
/// After voiding, positions are refunded one-by-one via `AdminRefundVoidPosition`.
/// Refund a single `STATE_PENDING` position from a voided market back to the player's `Ledger`.
///
/// **Authority**: `EXECUTOR_ADDRESS`.
///
/// **Accounts:** `authority` (signer), `market` (readonly), `position`, `ledger`.
///
/// Preconditions: `market.status == STATUS_VOIDED`, `position.state == STATE_PENDING`.
/// Sets `position.state = STATE_COMMIT_REFUNDED`; restores `stake / TICKET_MICROS` tickets and
/// `stake` `unstaked_micros` to the player's `Ledger`.
/// Advance the global week counter (`Treasury::current_week += 1`).
///
/// **Authority**: `EXECUTOR_ADDRESS`.
///
/// **Accounts:** `authority` (signer), `treasury`.
///
/// Call once at the start of each scoring week. All `Ledger` accounts will lazily zero their
/// `week_*` counters the next time any instruction touches them (no sweep required).
/// The new week number is returned in the `current_week` field of `Treasury` after the ix.
pub const EXECUTOR_KIND_DISTRIBUTE_MARKET_REWARD: u8 = 0;
pub const EXECUTOR_KIND_JACKPOT_PAY: u8 = 1;
pub const EXECUTOR_KIND_MARKET_LINE_RELEASE: u8 = 2;
pub const EXECUTOR_KIND_MERGE_COMMITTED_POSITION: u8 = 3;
use TryFromPrimitive;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;
instruction!;