oil_api/
instruction.rs

1use steel::*;
2
3#[repr(u8)]
4#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5pub enum OilInstruction {
6    // Driller
7    Automate = 0,
8    Initialize = 1,
9    Checkpoint = 2,
10    ClaimSOL = 3,
11    ClaimOIL = 4,
12    Close = 5,
13    Deploy = 6,
14    Log = 8,
15    Reset = 9,
16    ReloadSOL = 21,
17    CreateReferral = 27,
18    ClaimReferral = 28,
19
20    // Auction-based mining
21    SetBid = 29,
22    JoinAuctionPool = 30,
23    ClaimAuctionOIL = 31,
24    ClaimAuctionSOL = 32,
25    SyncAuctionState = 34,
26
27    // Staker
28    Deposit = 10,
29    Withdraw = 11,
30    ClaimYield = 12,
31
32    // Admin
33    Buyback = 13,
34    SetAdmin = 15,
35    SetFeeCollector = 16,
36    SetSwapProgram = 17,
37    SetVarAddress = 18,
38    NewVar = 19,
39    SetAdminFee = 20,
40    Migrate = 26,
41    SetAuction = 33,
42}
43
44#[repr(C)]
45#[derive(Clone, Copy, Debug, Pod, Zeroable)]
46pub struct Automate {
47    pub amount: [u8; 8],
48    pub deposit: [u8; 8],
49    pub fee: [u8; 8],
50    pub mask: [u8; 8],
51    pub strategy: u8,
52    pub reload: [u8; 8],
53    /// Optional referrer pubkey for new drillers. Set to Pubkey::default() for no referrer.
54    pub referrer: [u8; 32],
55    /// Whether automated deployments should be pooled (1 = pooled, 0 = not pooled).
56    pub pooled: u8,
57}
58
59#[repr(C)]
60#[derive(Clone, Copy, Debug, Pod, Zeroable)]
61pub struct InitRound {}
62
63#[repr(C)]
64#[derive(Clone, Copy, Debug, Pod, Zeroable)]
65pub struct ClaimSOL {}
66
67#[repr(C)]
68#[derive(Clone, Copy, Debug, Pod, Zeroable)]
69pub struct ClaimOIL {}
70
71#[repr(C)]
72#[derive(Clone, Copy, Debug, Pod, Zeroable)]
73pub struct Deploy {
74    pub amount: [u8; 8],
75    pub squares: [u8; 4],
76    /// Optional referrer pubkey. Set to Pubkey::default() for no referrer.
77    pub referrer: [u8; 32],
78    /// Whether this deploy is pooled. 0 = solo, 1 = pooled.
79    pub pooled: u8,
80}
81
82#[repr(C)]
83#[derive(Clone, Copy, Debug, Pod, Zeroable)]
84pub struct Log {}
85
86#[repr(C)]
87#[derive(Clone, Copy, Debug, Pod, Zeroable)]
88pub struct Reset {}
89
90#[repr(C)]
91#[derive(Clone, Copy, Debug, Pod, Zeroable)]
92pub struct Close {}
93
94#[repr(C)]
95#[derive(Clone, Copy, Debug, Pod, Zeroable)]
96pub struct Mine {
97    pub nonce: [u8; 8],
98}
99
100#[repr(C)]
101#[derive(Clone, Copy, Debug, Pod, Zeroable)]
102pub struct Swap {
103    pub amount: [u8; 8],
104    pub direction: u8,
105    pub precision: u8,
106    pub seed: [u8; 32],
107}
108
109#[repr(C)]
110#[derive(Clone, Copy, Debug, Pod, Zeroable)]
111pub struct Uncommit {
112    pub amount: [u8; 8],
113}
114
115#[repr(C)]
116#[derive(Clone, Copy, Debug, Pod, Zeroable)]
117pub struct SetAdmin {
118    pub admin: [u8; 32],
119}
120
121#[repr(C)]
122#[derive(Clone, Copy, Debug, Pod, Zeroable)]
123pub struct SetFeeCollector {
124    pub fee_collector: [u8; 32],
125}
126
127#[repr(C)]
128#[derive(Clone, Copy, Debug, Pod, Zeroable)]
129pub struct SetFeeRate {
130    pub fee_rate: [u8; 8],
131}
132
133#[repr(C)]
134#[derive(Clone, Copy, Debug, Pod, Zeroable)]
135pub struct Buyback {}
136
137#[repr(C)]
138#[derive(Clone, Copy, Debug, Pod, Zeroable)]
139pub struct ReloadSOL {}
140
141#[repr(C)]
142#[derive(Clone, Copy, Debug, Pod, Zeroable)]
143pub struct Deposit {
144    pub amount: [u8; 8],
145    pub lock_duration_days: [u8; 8],  // 0 = no lock, 1-730 days
146    pub stake_id: [u8; 8],  // Unique ID for this stake account (allows multiple stakes per user)
147}
148
149#[repr(C)]
150#[derive(Clone, Copy, Debug, Pod, Zeroable)]
151pub struct Withdraw {
152    pub amount: [u8; 8],
153    pub stake_id: [u8; 8],
154}
155
156#[repr(C)]
157#[derive(Clone, Copy, Debug, Pod, Zeroable)]
158pub struct ClaimYield {
159    pub amount: [u8; 8],
160}
161
162#[repr(C)]
163#[derive(Clone, Copy, Debug, Pod, Zeroable)]
164pub struct Checkpoint {}
165
166#[repr(C)]
167#[derive(Clone, Copy, Debug, Pod, Zeroable)]
168pub struct NewVar {
169    pub id: [u8; 8],
170    pub commit: [u8; 32],
171    pub samples: [u8; 8],
172}
173
174#[repr(C)]
175#[derive(Clone, Copy, Debug, Pod, Zeroable)]
176pub struct SetAdminFee {
177    pub admin_fee: [u8; 8],
178}
179
180#[repr(C)]
181#[derive(Clone, Copy, Debug, Pod, Zeroable)]
182pub struct SetSwapProgram {}
183
184#[repr(C)]
185#[derive(Clone, Copy, Debug, Pod, Zeroable)]
186pub struct SetVarAddress {}
187
188#[repr(C)]
189#[derive(Clone, Copy, Debug, Pod, Zeroable)]
190pub struct Migrate {}
191
192#[repr(C)]
193#[derive(Clone, Copy, Debug, Pod, Zeroable)]
194pub struct CreateReferral {}
195
196#[repr(C)]
197#[derive(Clone, Copy, Debug, Pod, Zeroable)]
198pub struct ClaimReferral {}
199
200#[repr(C)]
201#[derive(Clone, Copy, Debug, Pod, Zeroable)]
202pub struct Initialize {
203    pub barrel_authority: [u8; 32],
204    pub fee_collector: [u8; 32],
205    pub swap_program: [u8; 32],
206    pub var_address: [u8; 32],
207    pub admin_fee: [u8; 8],
208    // Auction configuration (optional - only used if auction accounts need initialization)
209    pub halving_period_seconds: [u8; 8],
210    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
211    pub auction_duration_seconds: [u8; 8],
212    pub starting_prices: [[u8; 8]; 4],  // 4 wells
213    pub min_pool_contribution: [u8; 8],
214}
215
216#[repr(C)]
217#[derive(Clone, Copy, Debug, Pod, Zeroable)]
218pub struct SetBid {
219    pub square_id: [u8; 8],
220}
221
222#[repr(C)]
223#[derive(Clone, Copy, Debug, Pod, Zeroable)]
224pub struct JoinAuctionPool {
225    pub square_id: [u8; 8],
226    pub amount: [u8; 8], // SOL amount in lamports
227}
228
229#[repr(C)]
230#[derive(Clone, Copy, Debug, Pod, Zeroable)]
231pub struct ClaimAuctionOIL {
232    /// Well IDs to claim OIL from (0-3), can claim multiple at once
233    /// Bitmask: bit 0 = well 0, bit 1 = well 1, etc.
234    pub well_mask: u8,
235}
236
237#[repr(C)]
238#[derive(Clone, Copy, Debug, Pod, Zeroable)]
239pub struct ClaimAuctionSOL {
240    /// Reserved for future use (currently unused, but kept for consistency)
241    pub _reserved: u8,
242}
243
244#[repr(C)]
245#[derive(Clone, Copy, Debug, Pod, Zeroable)]
246pub struct SetAuction {
247    pub halving_period_seconds: [u8; 8],
248    pub last_halving_time: [u8; 8],
249    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
250    pub auction_duration_seconds: [u8; 8],
251    pub starting_prices: [[u8; 8]; 4],  // 4 wells
252    pub min_pool_contribution: [u8; 8],
253    pub well_id: [u8; 8],  // Well ID to update (0-3). If >= 4, only updates auction account.
254}
255
256#[repr(C)]
257#[derive(Clone, Copy, Debug, Pod, Zeroable)]
258pub struct SyncAuctionState {
259    /// Well ID to sync (0-3). If well_id >= 4, syncs all wells.
260    pub well_id: [u8; 8],
261}
262
263instruction!(OilInstruction, Automate);
264instruction!(OilInstruction, Initialize);
265instruction!(OilInstruction, Checkpoint);
266instruction!(OilInstruction, ClaimSOL);
267instruction!(OilInstruction, ClaimOIL);
268instruction!(OilInstruction, ReloadSOL);
269instruction!(OilInstruction, Deploy);
270instruction!(OilInstruction, Log);
271instruction!(OilInstruction, Buyback);
272instruction!(OilInstruction, Reset);
273instruction!(OilInstruction, Close);
274instruction!(OilInstruction, SetAdmin);
275instruction!(OilInstruction, SetFeeCollector);
276instruction!(OilInstruction, Deposit);
277instruction!(OilInstruction, Withdraw);
278instruction!(OilInstruction, ClaimYield);
279instruction!(OilInstruction, NewVar);
280instruction!(OilInstruction, SetAdminFee);
281instruction!(OilInstruction, SetSwapProgram);
282instruction!(OilInstruction, SetVarAddress);
283instruction!(OilInstruction, Migrate);
284instruction!(OilInstruction, CreateReferral);
285instruction!(OilInstruction, ClaimReferral);
286instruction!(OilInstruction, SetBid);
287instruction!(OilInstruction, JoinAuctionPool);
288instruction!(OilInstruction, ClaimAuctionOIL);
289instruction!(OilInstruction, ClaimAuctionSOL);
290instruction!(OilInstruction, SetAuction);
291instruction!(OilInstruction, SyncAuctionState);