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