Skip to main content

oil_api/
instruction.rs

1use steel::*;
2use bytemuck;
3
4#[repr(u8)]
5#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
6pub enum OilInstruction {
7    // Miner
8    Automate = 0,
9    AutomateWithSession = 40,
10    Initialize = 1,
11    Checkpoint = 2,
12    CheckpointWithSession = 52,
13    ClaimSOL = 3,
14    ClaimSOLWithSession = 44,
15    ClaimOIL = 4,
16    ClaimOILWithSession = 45,
17    Close = 5,
18    Deploy = 6,
19    DeployWithSession = 39,
20    Log = 8,
21    Reset = 9,
22    ReloadSOL = 22,
23    CreateReferral = 27,
24    CreateReferralWithSession = 49,
25    ClaimReferral = 28,
26    ClaimReferralWithSession = 50,
27
28    // Auction-based mining
29    PlaceBid = 29,
30    PlaceBidWithSession = 41,
31    ClaimAuctionOIL = 31,
32    ClaimAuctionOILWithSession = 42,
33    ClaimAuctionSOL = 32,
34    ClaimAuctionSOLWithSession = 43,
35    Contribute = 53,
36    ContributeWithSession = 54,
37    CheckpointAuction = 55,
38    CheckpointAuctionWithSession = 56,
39
40    // Refinery system
41    InitializeRefinery = 57,
42    PurchasePlot = 58,
43    UpgradePlot = 59,
44    PurchaseRig = 60,
45    PlaceRig = 61,
46    RemoveRig = 62,
47    ClaimRefineryRewards = 63,
48    RefuelPlot = 64,
49    SetRigConfig = 65,
50    PurchasePlotWithSession = 66,
51    UpgradePlotWithSession = 67,
52    PurchaseRigWithSession = 68,
53    PlaceRigWithSession = 69,
54    RemoveRigWithSession = 70,
55    RefuelPlotWithSession = 71,
56    ClaimRefineryRewardsWithSession = 72,
57    InitOilOracle = 73,
58    SetOilOraclePrice = 74,
59    SetOracleAuthority = 75,
60    InitCollection = 76,
61
62    // Staker
63    Deposit = 10,
64    DepositWithSession = 48,
65    Withdraw = 11,
66    WithdrawWithSession = 47,
67    ClaimYield = 12,
68    ClaimYieldWithSession = 51,
69
70    // Admin
71    Buyback = 13,
72    Wrap = 14,
73    SetAdmin = 16,
74    SetFeeCollector = 17,
75    SetSwapProgram = 18,
76    SetVarAddress = 19,
77    NewVar = 20,
78    SetAdminFee = 21,
79    Migrate = 26,
80    SetAuction = 33,
81    CreateWhitelist = 34,
82    SetTgeTimestamp = 35,
83    Liq = 37,
84    Barrel = 38,
85}
86
87#[repr(C)]
88#[derive(Clone, Copy, Debug, Pod, Zeroable)]
89pub struct Automate {
90    pub amount: [u8; 8],
91    pub deposit: [u8; 8],
92    pub fee: [u8; 8],
93    pub mask: [u8; 8],
94    pub strategy: u8,
95    pub reload: [u8; 8],
96    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
97    pub referrer: [u8; 32],
98    /// Whether automated deployments should be pooled (1 = pooled, 0 = not pooled).
99    pub pooled: u8,
100}
101
102#[repr(C)]
103#[derive(Clone, Copy, Debug, Pod, Zeroable)]
104pub struct ClaimSOL {}
105
106#[repr(C)]
107#[derive(Clone, Copy, Debug, Pod, Zeroable)]
108pub struct ClaimOIL {}
109
110#[repr(C)]
111#[derive(Clone, Copy, Debug, Pod, Zeroable)]
112pub struct Deploy {
113    pub amount: [u8; 8],
114    pub squares: [u8; 4],
115    /// Optional referrer pubkey. Set to Pubkey::default() for no referrer.
116    pub referrer: [u8; 32],
117    /// Whether this deploy is pooled. 0 = solo, 1 = pooled.
118    pub pooled: u8,
119}
120
121#[repr(C)]
122#[derive(Clone, Copy, Debug, Pod, Zeroable)]
123pub struct Log {}
124
125#[repr(C)]
126#[derive(Clone, Copy, Debug, Pod, Zeroable)]
127pub struct Reset {}
128
129#[repr(C)]
130#[derive(Clone, Copy, Debug, Pod, Zeroable)]
131pub struct Close {}
132
133#[repr(C)]
134#[derive(Clone, Copy, Debug, Pod, Zeroable)]
135pub struct SetAdmin {
136    pub admin: [u8; 32],
137}
138
139#[repr(C)]
140#[derive(Clone, Copy, Debug, Pod, Zeroable)]
141pub struct SetFeeCollector {
142    pub fee_collector: [u8; 32],
143}
144
145#[repr(C)]
146#[derive(Clone, Copy, Debug, Pod, Zeroable)]
147pub struct Buyback {}
148
149#[repr(C)]
150#[derive(Clone, Copy, Debug, Pod, Zeroable)]
151pub struct Liq {}
152
153#[repr(C)]
154#[derive(Clone, Copy, Debug, Pod, Zeroable)]
155pub struct Barrel {
156    pub amount: [u8; 8],
157}
158
159#[repr(C)]
160#[derive(Clone, Copy, Debug, Pod, Zeroable)]
161pub struct Wrap {
162    /// 0 = use balance, 1 = use liquidity
163    pub use_liquidity: u8,
164    pub amount: [u8; 8],
165}
166
167#[repr(C)]
168#[derive(Clone, Copy, Debug, Pod, Zeroable)]
169pub struct ReloadSOL {}
170
171#[repr(C)]
172#[derive(Clone, Copy, Debug, Pod, Zeroable)]
173pub struct Deposit {
174    pub amount: [u8; 8],
175    pub lock_duration_days: [u8; 8],  // 0 = no lock, 1-730 days
176    pub stake_id: [u8; 8],  // Unique ID for this stake account (allows multiple stakes per user)
177}
178
179#[repr(C)]
180#[derive(Clone, Copy, Debug, Pod, Zeroable)]
181pub struct Withdraw {
182    pub amount: [u8; 8],
183    pub stake_id: [u8; 8],
184}
185
186#[repr(C)]
187#[derive(Clone, Copy, Debug, Pod, Zeroable)]
188pub struct ClaimYield {
189    pub amount: [u8; 8],
190}
191
192#[repr(C)]
193#[derive(Clone, Copy, Debug, Pod, Zeroable)]
194pub struct Checkpoint {}
195
196#[repr(C)]
197#[derive(Clone, Copy, Debug, Pod, Zeroable)]
198pub struct NewVar {
199    pub id: [u8; 8],
200    pub commit: [u8; 32],
201    pub samples: [u8; 8],
202}
203
204#[repr(C)]
205#[derive(Clone, Copy, Debug, Pod, Zeroable)]
206pub struct SetAdminFee {
207    pub admin_fee: [u8; 8],
208}
209
210#[repr(C)]
211#[derive(Clone, Copy, Debug, Pod, Zeroable)]
212pub struct SetSwapProgram {}
213
214#[repr(C)]
215#[derive(Clone, Copy, Debug, Pod, Zeroable)]
216pub struct SetVarAddress {}
217
218#[repr(C)]
219#[derive(Clone, Copy, Debug, Pod, Zeroable)]
220pub struct Migrate {}
221
222#[repr(C)]
223#[derive(Clone, Copy, Debug, Pod, Zeroable)]
224pub struct CreateReferral {}
225
226#[repr(C)]
227#[derive(Clone, Copy, Debug, Pod, Zeroable)]
228pub struct ClaimReferral {}
229
230#[repr(C)]
231#[derive(Clone, Copy, Debug, Pod, Zeroable)]
232pub struct CreateWhitelist {
233    /// The code hash (first 32 bytes of keccak256 hash of the code string)
234    pub code_hash: [u8; 32],
235}
236
237#[repr(C)]
238#[derive(Clone, Copy, Debug, Pod, Zeroable)]
239pub struct SetTgeTimestamp {
240    /// Unix timestamp for Token Generation Event (TGE).
241    /// If current time < tge_timestamp, pre-mine is active.
242    /// Set to 0 to disable pre-mine.
243    pub tge_timestamp: [u8; 8],
244}
245
246#[repr(C)]
247#[derive(Clone, Copy, Debug, Pod, Zeroable)]
248pub struct Initialize {
249    pub barrel_authority: [u8; 32],
250    pub fee_collector: [u8; 32],
251    pub swap_program: [u8; 32],
252    pub var_address: [u8; 32],
253    pub admin_fee: [u8; 8],
254    // Auction configuration (optional - only used if auction accounts need initialization)
255    pub halving_period_seconds: [u8; 8],
256    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
257    pub auction_duration_seconds: [u8; 8],
258    pub starting_prices: [[u8; 8]; 4],  // 4 wells
259}
260
261#[repr(C)]
262#[derive(Clone, Copy, Debug, Pod, Zeroable)]
263pub struct PlaceBid {
264    pub square_id: [u8; 8],
265    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
266    pub referrer: [u8; 32],
267}
268
269#[repr(C)]
270#[derive(Clone, Copy, Debug, Pod, Zeroable)]
271pub struct ClaimAuctionOIL {
272    /// Well IDs to claim OIL from (0-3), can claim multiple at once
273    /// Bitmask: bit 0 = well 0, bit 1 = well 1, etc.
274    pub well_mask: u8,
275}
276
277#[repr(C)]
278#[derive(Clone, Copy, Debug, Pod, Zeroable)]
279pub struct ClaimAuctionSOL {
280    /// Reserved for future use (currently unused, but kept for consistency)
281    pub _reserved: u8,
282}
283
284#[repr(C)]
285#[derive(Clone, Copy, Debug, Pod, Zeroable)]
286pub struct SetAuction {
287    pub halving_period_seconds: [u8; 8],
288    pub last_halving_time: [u8; 8],
289    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
290    pub auction_duration_seconds: [u8; 8],
291    pub starting_prices: [[u8; 8]; 4],  // 4 wells
292    pub well_id: [u8; 8],  // Well ID to update (0-3). If >= 4, only updates auction account.
293}
294
295#[repr(C)]
296#[derive(Clone, Copy, Debug, Pod, Zeroable)]
297pub struct Contribute {
298    /// Well ID to contribute to (0-3)
299    pub well_id: [u8; 8],
300    /// Amount to contribute (in lamports) - treated as maximum, may be less if pool becomes eligible
301    pub amount: [u8; 8],
302}
303
304#[repr(C)]
305#[derive(Clone, Copy, Debug, Pod, Zeroable)]
306pub struct CheckpointAuction {
307    /// Well mask: bit 0 = well 0, bit 1 = well 1, bit 2 = well 2, bit 3 = well 3
308    /// Allows checkpointing multiple wells in a single instruction
309    pub well_mask: u8,
310    /// Epoch IDs for each well (0-3), in order
311    /// If well_mask bit is set, corresponding epoch_id must be provided
312    /// If well_mask bit is not set, epoch_id is ignored
313    pub epoch_ids: [[u8; 8]; 4],
314}
315
316instruction!(OilInstruction, Automate);
317instruction!(OilInstruction, Initialize);
318instruction!(OilInstruction, Checkpoint);
319instruction!(OilInstruction, ClaimSOL);
320instruction!(OilInstruction, ClaimOIL);
321instruction!(OilInstruction, ReloadSOL);
322instruction!(OilInstruction, Deploy);
323instruction!(OilInstruction, Log);
324instruction!(OilInstruction, Buyback);
325instruction!(OilInstruction, Wrap);
326instruction!(OilInstruction, Reset);
327instruction!(OilInstruction, Close);
328instruction!(OilInstruction, SetAdmin);
329instruction!(OilInstruction, SetFeeCollector);
330instruction!(OilInstruction, Deposit);
331instruction!(OilInstruction, Withdraw);
332instruction!(OilInstruction, ClaimYield);
333instruction!(OilInstruction, NewVar);
334instruction!(OilInstruction, SetAdminFee);
335instruction!(OilInstruction, SetSwapProgram);
336instruction!(OilInstruction, SetVarAddress);
337instruction!(OilInstruction, Migrate);
338instruction!(OilInstruction, CreateReferral);
339instruction!(OilInstruction, ClaimReferral);
340instruction!(OilInstruction, PlaceBid);
341instruction!(OilInstruction, ClaimAuctionOIL);
342instruction!(OilInstruction, ClaimAuctionSOL);
343instruction!(OilInstruction, SetAuction);
344instruction!(OilInstruction, CreateWhitelist);
345instruction!(OilInstruction, SetTgeTimestamp);
346instruction!(OilInstruction, Liq);
347instruction!(OilInstruction, Barrel);
348instruction!(OilInstruction, Contribute);
349instruction!(OilInstruction, CheckpointAuction);
350
351// Refinery system instruction structs
352#[repr(C)]
353#[derive(Clone, Copy, Debug, Pod, Zeroable)]
354pub struct InitializeRefinery {
355    /// Initial emission per block in atomic units (11 decimals)
356    pub initial_emission: [u8; 8],
357    /// Mining power for each rig type (0-14), 15 values
358    pub mining_powers: [[u8; 8]; 15],
359    /// Fuel requirement for each rig type (0-14), 15 values
360    pub fuel_requirements: [[u8; 8]; 15],
361    /// Fuel consumption rate for each rig type (0-14) in atomic units (11 decimals), 15 values
362    pub fuel_consumption_rates: [[u8; 8]; 15],
363    /// Max supply for each rig type (0-14), u64::MAX = unlimited, 15 values
364    pub rig_supplies: [[u8; 8]; 15],
365}
366
367#[repr(C)]
368#[derive(Clone, Copy, Debug, Pod, Zeroable)]
369pub struct PurchasePlot {}
370
371#[repr(C)]
372#[derive(Clone, Copy, Debug, Pod, Zeroable)]
373pub struct UpgradePlot {
374    pub plot_level: [u8; 8],
375}
376
377#[repr(C)]
378#[derive(Clone, Copy, Debug, Pod, Zeroable)]
379pub struct PurchaseRig {
380    pub rig_type: [u8; 8],
381}
382
383#[repr(C)]
384#[derive(Clone, Copy, Debug, Pod, Zeroable)]
385pub struct PlaceRig {
386    pub rig_mint: [u8; 32],
387    pub slot: [u8; 8],
388}
389
390#[repr(C)]
391#[derive(Clone, Copy, Debug, Pod, Zeroable)]
392pub struct RemoveRig {
393    pub rig_mint: [u8; 32],
394}
395
396#[repr(C)]
397#[derive(Clone, Copy, Debug, Pod, Zeroable)]
398pub struct ClaimRefineryRewards {
399    /// Claim fee in lamports (35% of claim value in SOL/FOGO). Client computes from OIL price (e.g. Valiant API) and FOGO price.
400    pub fee_lamports: [u8; 8],
401}
402
403#[repr(C)]
404#[derive(Clone, Copy, Debug, Pod, Zeroable)]
405pub struct RefuelPlot {}
406
407#[repr(C)]
408#[derive(Clone, Copy, Debug, Pod, Zeroable)]
409pub struct SetRigConfig {
410    pub rig_type: [u8; 8],
411    pub mining_power: [u8; 8],
412    pub fuel_requirement: [u8; 8],
413    pub fuel_consumption_rate: [u8; 8],
414}
415
416/// Init OIL price oracle (one-time; payer creates account, sets oracle_authority).
417#[repr(C)]
418#[derive(Clone, Copy, Debug, Pod, Zeroable)]
419pub struct InitOilOracle {
420    /// Authority that may call SetOilOraclePrice (32 bytes).
421    pub oracle_authority: [u8; 32],
422}
423
424/// Set OIL price (Valiant-backed; only oracle_authority).
425#[repr(C)]
426#[derive(Clone, Copy, Debug, Pod, Zeroable)]
427pub struct SetOilOraclePrice {
428    pub price: [u8; 8],
429    pub expo: [u8; 4],
430    pub conf: [u8; 8],
431    pub ema: [u8; 8],
432    pub publish_time: [u8; 8],
433}
434
435/// Set oracle authority (only current oracle_authority).
436#[repr(C)]
437#[derive(Clone, Copy, Debug, Pod, Zeroable)]
438pub struct SetOracleAuthority {
439    /// New authority allowed to call SetOilOraclePrice (32 bytes).
440    pub new_oracle_authority: [u8; 32],
441}
442
443instruction!(OilInstruction, InitializeRefinery);
444instruction!(OilInstruction, PurchasePlot);
445instruction!(OilInstruction, UpgradePlot);
446instruction!(OilInstruction, PurchaseRig);
447instruction!(OilInstruction, PlaceRig);
448instruction!(OilInstruction, RemoveRig);
449instruction!(OilInstruction, ClaimRefineryRewards);
450instruction!(OilInstruction, RefuelPlot);
451instruction!(OilInstruction, SetRigConfig);
452instruction!(OilInstruction, InitOilOracle);
453instruction!(OilInstruction, SetOilOraclePrice);
454instruction!(OilInstruction, SetOracleAuthority);
455
456/// Init OIL rig collection NFT (one-time, admin only). Creates collection NFT for verified rig metadata.
457#[repr(C)]
458#[derive(Clone, Copy, Debug, Pod, Zeroable)]
459pub struct InitCollection {}
460
461instruction!(OilInstruction, InitCollection);