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