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    // Staker
41    Deposit = 10,
42    DepositWithSession = 48,
43    Withdraw = 11,
44    WithdrawWithSession = 47,
45    ClaimYield = 12,
46    ClaimYieldWithSession = 51,
47
48    // Admin
49    Buyback = 13,
50    Wrap = 14,
51    SetAdmin = 16,
52    SetFeeCollector = 17,
53    SetSwapProgram = 18,
54    SetVarAddress = 19,
55    NewVar = 20,
56    SetAdminFee = 21,
57    Migrate = 26,
58    SetAuction = 33,
59    CreateWhitelist = 34,
60    SetTgeTimestamp = 35,
61    Liq = 37,
62    Barrel = 38,
63}
64
65#[repr(C)]
66#[derive(Clone, Copy, Debug, Pod, Zeroable)]
67pub struct Automate {
68    pub amount: [u8; 8],
69    pub deposit: [u8; 8],
70    pub fee: [u8; 8],
71    pub mask: [u8; 8],
72    pub strategy: u8,
73    pub reload: [u8; 8],
74    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
75    pub referrer: [u8; 32],
76    /// Whether automated deployments should be pooled (1 = pooled, 0 = not pooled).
77    pub pooled: u8,
78}
79
80#[repr(C)]
81#[derive(Clone, Copy, Debug, Pod, Zeroable)]
82pub struct ClaimSOL {}
83
84#[repr(C)]
85#[derive(Clone, Copy, Debug, Pod, Zeroable)]
86pub struct ClaimOIL {}
87
88#[repr(C)]
89#[derive(Clone, Copy, Debug, Pod, Zeroable)]
90pub struct Deploy {
91    pub amount: [u8; 8],
92    pub squares: [u8; 4],
93    /// Optional referrer pubkey. Set to Pubkey::default() for no referrer.
94    pub referrer: [u8; 32],
95    /// Whether this deploy is pooled. 0 = solo, 1 = pooled.
96    pub pooled: u8,
97}
98
99#[repr(C)]
100#[derive(Clone, Copy, Debug, Pod, Zeroable)]
101pub struct Log {}
102
103#[repr(C)]
104#[derive(Clone, Copy, Debug, Pod, Zeroable)]
105pub struct Reset {}
106
107#[repr(C)]
108#[derive(Clone, Copy, Debug, Pod, Zeroable)]
109pub struct Close {}
110
111#[repr(C)]
112#[derive(Clone, Copy, Debug, Pod, Zeroable)]
113pub struct SetAdmin {
114    pub admin: [u8; 32],
115}
116
117#[repr(C)]
118#[derive(Clone, Copy, Debug, Pod, Zeroable)]
119pub struct SetFeeCollector {
120    pub fee_collector: [u8; 32],
121}
122
123#[repr(C)]
124#[derive(Clone, Copy, Debug, Pod, Zeroable)]
125pub struct Buyback {}
126
127#[repr(C)]
128#[derive(Clone, Copy, Debug, Pod, Zeroable)]
129pub struct Liq {}
130
131#[repr(C)]
132#[derive(Clone, Copy, Debug, Pod, Zeroable)]
133pub struct Barrel {
134    pub amount: [u8; 8],
135}
136
137#[repr(C)]
138#[derive(Clone, Copy, Debug, Pod, Zeroable)]
139pub struct Wrap {
140    /// 0 = use balance, 1 = use liquidity
141    pub use_liquidity: u8,
142    pub amount: [u8; 8],
143}
144
145#[repr(C)]
146#[derive(Clone, Copy, Debug, Pod, Zeroable)]
147pub struct ReloadSOL {}
148
149#[repr(C)]
150#[derive(Clone, Copy, Debug, Pod, Zeroable)]
151pub struct Deposit {
152    pub amount: [u8; 8],
153    pub lock_duration_days: [u8; 8],  // 0 = no lock, 1-730 days
154    pub stake_id: [u8; 8],  // Unique ID for this stake account (allows multiple stakes per user)
155}
156
157#[repr(C)]
158#[derive(Clone, Copy, Debug, Pod, Zeroable)]
159pub struct Withdraw {
160    pub amount: [u8; 8],
161    pub stake_id: [u8; 8],
162}
163
164#[repr(C)]
165#[derive(Clone, Copy, Debug, Pod, Zeroable)]
166pub struct ClaimYield {
167    pub amount: [u8; 8],
168}
169
170#[repr(C)]
171#[derive(Clone, Copy, Debug, Pod, Zeroable)]
172pub struct Checkpoint {}
173
174#[repr(C)]
175#[derive(Clone, Copy, Debug, Pod, Zeroable)]
176pub struct NewVar {
177    pub id: [u8; 8],
178    pub commit: [u8; 32],
179    pub samples: [u8; 8],
180}
181
182#[repr(C)]
183#[derive(Clone, Copy, Debug, Pod, Zeroable)]
184pub struct SetAdminFee {
185    pub admin_fee: [u8; 8],
186}
187
188#[repr(C)]
189#[derive(Clone, Copy, Debug, Pod, Zeroable)]
190pub struct SetSwapProgram {}
191
192#[repr(C)]
193#[derive(Clone, Copy, Debug, Pod, Zeroable)]
194pub struct SetVarAddress {}
195
196#[repr(C)]
197#[derive(Clone, Copy, Debug, Pod, Zeroable)]
198pub struct Migrate {}
199
200#[repr(C)]
201#[derive(Clone, Copy, Debug, Pod, Zeroable)]
202pub struct CreateReferral {}
203
204#[repr(C)]
205#[derive(Clone, Copy, Debug, Pod, Zeroable)]
206pub struct ClaimReferral {}
207
208#[repr(C)]
209#[derive(Clone, Copy, Debug, Pod, Zeroable)]
210pub struct CreateWhitelist {
211    /// The code hash (first 32 bytes of keccak256 hash of the code string)
212    pub code_hash: [u8; 32],
213}
214
215#[repr(C)]
216#[derive(Clone, Copy, Debug, Pod, Zeroable)]
217pub struct SetTgeTimestamp {
218    /// Unix timestamp for Token Generation Event (TGE).
219    /// If current time < tge_timestamp, pre-mine is active.
220    /// Set to 0 to disable pre-mine.
221    pub tge_timestamp: [u8; 8],
222}
223
224#[repr(C)]
225#[derive(Clone, Copy, Debug, Pod, Zeroable)]
226pub struct Initialize {
227    pub barrel_authority: [u8; 32],
228    pub fee_collector: [u8; 32],
229    pub swap_program: [u8; 32],
230    pub var_address: [u8; 32],
231    pub admin_fee: [u8; 8],
232    // Auction configuration (optional - only used if auction accounts need initialization)
233    pub halving_period_seconds: [u8; 8],
234    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
235    pub auction_duration_seconds: [u8; 8],
236    pub starting_prices: [[u8; 8]; 4],  // 4 wells
237}
238
239#[repr(C)]
240#[derive(Clone, Copy, Debug, Pod, Zeroable)]
241pub struct PlaceBid {
242    pub square_id: [u8; 8],
243    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
244    pub referrer: [u8; 32],
245}
246
247#[repr(C)]
248#[derive(Clone, Copy, Debug, Pod, Zeroable)]
249pub struct ClaimAuctionOIL {
250    /// Well IDs to claim OIL from (0-3), can claim multiple at once
251    /// Bitmask: bit 0 = well 0, bit 1 = well 1, etc.
252    pub well_mask: u8,
253}
254
255#[repr(C)]
256#[derive(Clone, Copy, Debug, Pod, Zeroable)]
257pub struct ClaimAuctionSOL {
258    /// Reserved for future use (currently unused, but kept for consistency)
259    pub _reserved: u8,
260}
261
262#[repr(C)]
263#[derive(Clone, Copy, Debug, Pod, Zeroable)]
264pub struct SetAuction {
265    pub halving_period_seconds: [u8; 8],
266    pub last_halving_time: [u8; 8],
267    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
268    pub auction_duration_seconds: [u8; 8],
269    pub starting_prices: [[u8; 8]; 4],  // 4 wells
270    pub well_id: [u8; 8],  // Well ID to update (0-3). If >= 4, only updates auction account.
271}
272
273#[repr(C)]
274#[derive(Clone, Copy, Debug, Pod, Zeroable)]
275pub struct Contribute {
276    /// Well ID to contribute to (0-3)
277    pub well_id: [u8; 8],
278    /// Amount to contribute (in lamports) - treated as maximum, may be less if pool becomes eligible
279    pub amount: [u8; 8],
280}
281
282#[repr(C)]
283#[derive(Clone, Copy, Debug, Pod, Zeroable)]
284pub struct CheckpointAuction {
285    /// Well ID to checkpoint (0-3)
286    pub well_id: [u8; 8],
287    /// Epoch ID to checkpoint
288    pub epoch_id: [u8; 8],
289}
290
291instruction!(OilInstruction, Automate);
292instruction!(OilInstruction, Initialize);
293instruction!(OilInstruction, Checkpoint);
294instruction!(OilInstruction, ClaimSOL);
295instruction!(OilInstruction, ClaimOIL);
296instruction!(OilInstruction, ReloadSOL);
297instruction!(OilInstruction, Deploy);
298instruction!(OilInstruction, Log);
299instruction!(OilInstruction, Buyback);
300instruction!(OilInstruction, Wrap);
301instruction!(OilInstruction, Reset);
302instruction!(OilInstruction, Close);
303instruction!(OilInstruction, SetAdmin);
304instruction!(OilInstruction, SetFeeCollector);
305instruction!(OilInstruction, Deposit);
306instruction!(OilInstruction, Withdraw);
307instruction!(OilInstruction, ClaimYield);
308instruction!(OilInstruction, NewVar);
309instruction!(OilInstruction, SetAdminFee);
310instruction!(OilInstruction, SetSwapProgram);
311instruction!(OilInstruction, SetVarAddress);
312instruction!(OilInstruction, Migrate);
313instruction!(OilInstruction, CreateReferral);
314instruction!(OilInstruction, ClaimReferral);
315instruction!(OilInstruction, PlaceBid);
316instruction!(OilInstruction, ClaimAuctionOIL);
317instruction!(OilInstruction, ClaimAuctionSOL);
318instruction!(OilInstruction, SetAuction);
319instruction!(OilInstruction, CreateWhitelist);
320instruction!(OilInstruction, SetTgeTimestamp);
321instruction!(OilInstruction, Liq);
322instruction!(OilInstruction, Barrel);
323instruction!(OilInstruction, Contribute);
324instruction!(OilInstruction, CheckpointAuction);