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