oil-api 0.7.8

API for interacting with the OIL protocol on Solana
Documentation
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
use steel::*;
use bytemuck;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum OilInstruction {
    // Miner
    Automate = 0,
    AutomateWithSession = 40,
    Initialize = 1,
    Checkpoint = 2,
    CheckpointWithSession = 52,
    ClaimSOL = 3,
    ClaimSOLWithSession = 44,
    ClaimOIL = 4,
    ClaimOILWithSession = 45,
    Close = 5,
    Deploy = 6,
    DeployWithSession = 39,
    Log = 8,
    Reset = 9,
    ReloadSOL = 22,
    CreateReferral = 27,
    CreateReferralWithSession = 49,
    ClaimReferral = 28,
    ClaimReferralWithSession = 50,

    // Auction-based mining
    PlaceBid = 29,
    PlaceBidWithSession = 41,
    ClaimAuctionOIL = 31,
    ClaimAuctionOILWithSession = 42,
    ClaimAuctionSOL = 32,
    ClaimAuctionSOLWithSession = 43,
    Contribute = 53,
    ContributeWithSession = 54,
    CheckpointAuction = 55,
    CheckpointAuctionWithSession = 56,

    // Refinery system
    InitializeRefinery = 57,
    PurchasePlot = 58,
    UpgradePlot = 59,
    PurchaseRig = 60,
    PlaceRig = 61,
    RemoveRig = 62,
    ClaimRefineryRewards = 63,
    RefuelPlot = 64,
    SetRigConfig = 65,
    PurchasePlotWithSession = 66,
    UpgradePlotWithSession = 67,
    PurchaseRigWithSession = 68,
    PlaceRigWithSession = 69,
    RemoveRigWithSession = 70,
    RefuelPlotWithSession = 71,
    ClaimRefineryRewardsWithSession = 72,
    InitOilOracle = 73,
    SetOilOraclePrice = 74,
    SetOracleAuthority = 75,
    InitCollection = 76,

    // Staker
    Deposit = 10,
    DepositWithSession = 48,
    Withdraw = 11,
    WithdrawWithSession = 47,
    ClaimYield = 12,
    ClaimYieldWithSession = 51,

    // Admin
    Buyback = 13,
    Wrap = 14,
    SetAdmin = 16,
    SetFeeCollector = 17,
    SetSwapProgram = 18,
    SetVarAddress = 19,
    NewVar = 20,
    SetAdminFee = 21,
    Migrate = 26,
    SetAuction = 33,
    CreateWhitelist = 34,
    SetTgeTimestamp = 35,
    Liq = 37,
    Barrel = 38,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Automate {
    pub amount: [u8; 8],
    pub deposit: [u8; 8],
    pub fee: [u8; 8],
    pub mask: [u8; 8],
    pub strategy: u8,
    pub reload: [u8; 8],
    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
    pub referrer: [u8; 32],
    /// Whether automated deployments should be pooled (1 = pooled, 0 = not pooled).
    pub pooled: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimSOL {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimOIL {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Deploy {
    pub amount: [u8; 8],
    pub squares: [u8; 4],
    /// Optional referrer pubkey. Set to Pubkey::default() for no referrer.
    pub referrer: [u8; 32],
    /// Whether this deploy is pooled. 0 = solo, 1 = pooled.
    pub pooled: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Log {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Reset {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Close {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetAdmin {
    pub admin: [u8; 32],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetFeeCollector {
    pub fee_collector: [u8; 32],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Buyback {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Liq {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Barrel {
    pub amount: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Wrap {
    /// 0 = use balance, 1 = use liquidity
    pub use_liquidity: u8,
    pub amount: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ReloadSOL {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Deposit {
    pub amount: [u8; 8],
    pub lock_duration_days: [u8; 8],  // 0 = no lock, 1-730 days
    pub stake_id: [u8; 8],  // Unique ID for this stake account (allows multiple stakes per user)
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Withdraw {
    pub amount: [u8; 8],
    pub stake_id: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimYield {
    pub amount: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Checkpoint {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct NewVar {
    pub id: [u8; 8],
    pub commit: [u8; 32],
    pub samples: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetAdminFee {
    pub admin_fee: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetSwapProgram {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetVarAddress {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Migrate {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct CreateReferral {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimReferral {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct CreateWhitelist {
    /// The code hash (first 32 bytes of keccak256 hash of the code string)
    pub code_hash: [u8; 32],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetTgeTimestamp {
    /// Unix timestamp for Token Generation Event (TGE).
    /// If current time < tge_timestamp, pre-mine is active.
    /// Set to 0 to disable pre-mine.
    pub tge_timestamp: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Initialize {
    pub barrel_authority: [u8; 32],
    pub fee_collector: [u8; 32],
    pub swap_program: [u8; 32],
    pub var_address: [u8; 32],
    pub admin_fee: [u8; 8],
    // Auction configuration (optional - only used if auction accounts need initialization)
    pub halving_period_seconds: [u8; 8],
    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
    pub auction_duration_seconds: [u8; 8],
    pub starting_prices: [[u8; 8]; 4],  // 4 wells
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct PlaceBid {
    pub square_id: [u8; 8],
    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
    pub referrer: [u8; 32],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimAuctionOIL {
    /// Well IDs to claim OIL from (0-3), can claim multiple at once
    /// Bitmask: bit 0 = well 0, bit 1 = well 1, etc.
    pub well_mask: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimAuctionSOL {
    /// Reserved for future use (currently unused, but kept for consistency)
    pub _reserved: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetAuction {
    pub halving_period_seconds: [u8; 8],
    pub last_halving_time: [u8; 8],
    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
    pub auction_duration_seconds: [u8; 8],
    pub starting_prices: [[u8; 8]; 4],  // 4 wells
    pub well_id: [u8; 8],  // Well ID to update (0-3). If >= 4, only updates auction account.
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Contribute {
    /// Well ID to contribute to (0-3)
    pub well_id: [u8; 8],
    /// Amount to contribute (in lamports) - treated as maximum, may be less if pool becomes eligible
    pub amount: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct CheckpointAuction {
    /// Well mask: bit 0 = well 0, bit 1 = well 1, bit 2 = well 2, bit 3 = well 3
    /// Allows checkpointing multiple wells in a single instruction
    pub well_mask: u8,
    /// Epoch IDs for each well (0-3), in order
    /// If well_mask bit is set, corresponding epoch_id must be provided
    /// If well_mask bit is not set, epoch_id is ignored
    pub epoch_ids: [[u8; 8]; 4],
}

instruction!(OilInstruction, Automate);
instruction!(OilInstruction, Initialize);
instruction!(OilInstruction, Checkpoint);
instruction!(OilInstruction, ClaimSOL);
instruction!(OilInstruction, ClaimOIL);
instruction!(OilInstruction, ReloadSOL);
instruction!(OilInstruction, Deploy);
instruction!(OilInstruction, Log);
instruction!(OilInstruction, Buyback);
instruction!(OilInstruction, Wrap);
instruction!(OilInstruction, Reset);
instruction!(OilInstruction, Close);
instruction!(OilInstruction, SetAdmin);
instruction!(OilInstruction, SetFeeCollector);
instruction!(OilInstruction, Deposit);
instruction!(OilInstruction, Withdraw);
instruction!(OilInstruction, ClaimYield);
instruction!(OilInstruction, NewVar);
instruction!(OilInstruction, SetAdminFee);
instruction!(OilInstruction, SetSwapProgram);
instruction!(OilInstruction, SetVarAddress);
instruction!(OilInstruction, Migrate);
instruction!(OilInstruction, CreateReferral);
instruction!(OilInstruction, ClaimReferral);
instruction!(OilInstruction, PlaceBid);
instruction!(OilInstruction, ClaimAuctionOIL);
instruction!(OilInstruction, ClaimAuctionSOL);
instruction!(OilInstruction, SetAuction);
instruction!(OilInstruction, CreateWhitelist);
instruction!(OilInstruction, SetTgeTimestamp);
instruction!(OilInstruction, Liq);
instruction!(OilInstruction, Barrel);
instruction!(OilInstruction, Contribute);
instruction!(OilInstruction, CheckpointAuction);

// Refinery system instruction structs
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct InitializeRefinery {
    /// Initial emission per block in atomic units (11 decimals)
    pub initial_emission: [u8; 8],
    /// Mining power for each rig type (0-14), 15 values
    pub mining_powers: [[u8; 8]; 15],
    /// Fuel requirement for each rig type (0-14), 15 values
    pub fuel_requirements: [[u8; 8]; 15],
    /// Fuel consumption rate for each rig type (0-14) in atomic units (11 decimals), 15 values
    pub fuel_consumption_rates: [[u8; 8]; 15],
    /// Max supply for each rig type (0-14), u64::MAX = unlimited, 15 values
    pub rig_supplies: [[u8; 8]; 15],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct PurchasePlot {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpgradePlot {
    pub plot_level: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct PurchaseRig {
    pub rig_type: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct PlaceRig {
    pub rig_mint: [u8; 32],
    pub slot: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct RemoveRig {
    pub rig_mint: [u8; 32],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimRefineryRewards {
    /// Claim fee in lamports (35% of claim value in SOL/FOGO). Client computes from OIL price (e.g. Valiant API) and FOGO price.
    pub fee_lamports: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct RefuelPlot {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetRigConfig {
    pub rig_type: [u8; 8],
    pub mining_power: [u8; 8],
    pub fuel_requirement: [u8; 8],
    pub fuel_consumption_rate: [u8; 8],
}

/// Init OIL price oracle (one-time; payer creates account, sets oracle_authority).
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct InitOilOracle {
    /// Authority that may call SetOilOraclePrice (32 bytes).
    pub oracle_authority: [u8; 32],
}

/// Set OIL price (Valiant-backed; only oracle_authority).
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetOilOraclePrice {
    pub price: [u8; 8],
    pub expo: [u8; 4],
    pub conf: [u8; 8],
    pub ema: [u8; 8],
    pub publish_time: [u8; 8],
}

/// Set oracle authority (only current oracle_authority).
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetOracleAuthority {
    /// New authority allowed to call SetOilOraclePrice (32 bytes).
    pub new_oracle_authority: [u8; 32],
}

instruction!(OilInstruction, InitializeRefinery);
instruction!(OilInstruction, PurchasePlot);
instruction!(OilInstruction, UpgradePlot);
instruction!(OilInstruction, PurchaseRig);
instruction!(OilInstruction, PlaceRig);
instruction!(OilInstruction, RemoveRig);
instruction!(OilInstruction, ClaimRefineryRewards);
instruction!(OilInstruction, RefuelPlot);
instruction!(OilInstruction, SetRigConfig);
instruction!(OilInstruction, InitOilOracle);
instruction!(OilInstruction, SetOilOraclePrice);
instruction!(OilInstruction, SetOracleAuthority);

/// Init OIL rig collection NFT (one-time, admin only). Creates collection NFT for verified rig metadata.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct InitCollection {}

instruction!(OilInstruction, InitCollection);