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    CreateCode = 34,
43    SetTgeTimestamp = 35,
44}
45
46#[repr(C)]
47#[derive(Clone, Copy, Debug, Pod, Zeroable)]
48pub struct Automate {
49    pub amount: [u8; 8],
50    pub deposit: [u8; 8],
51    pub fee: [u8; 8],
52    pub mask: [u8; 8],
53    pub strategy: u8,
54    pub reload: [u8; 8],
55    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
56    pub referrer: [u8; 32],
57    /// Whether automated deployments should be pooled (1 = pooled, 0 = not pooled).
58    pub pooled: u8,
59}
60
61#[repr(C)]
62#[derive(Clone, Copy, Debug, Pod, Zeroable)]
63pub struct InitRound {}
64
65#[repr(C)]
66#[derive(Clone, Copy, Debug, Pod, Zeroable)]
67pub struct ClaimSOL {}
68
69#[repr(C)]
70#[derive(Clone, Copy, Debug, Pod, Zeroable)]
71pub struct ClaimOIL {}
72
73#[repr(C)]
74#[derive(Clone, Copy, Debug, Pod, Zeroable)]
75pub struct ClaimSeeker {}
76
77#[repr(C)]
78#[derive(Clone, Copy, Debug, Pod, Zeroable)]
79pub struct Deploy {
80    pub amount: [u8; 8],
81    pub squares: [u8; 4],
82    /// Optional referrer pubkey. Set to Pubkey::default() for no referrer.
83    pub referrer: [u8; 32],
84    /// Whether this deploy is pooled. 0 = solo, 1 = pooled.
85    pub pooled: u8,
86    /// Optional access code hash for pre-mine. Set to [0; 32] for no access code.
87    pub access_code_hash: [u8; 32],
88}
89
90#[repr(C)]
91#[derive(Clone, Copy, Debug, Pod, Zeroable)]
92pub struct Log {}
93
94#[repr(C)]
95#[derive(Clone, Copy, Debug, Pod, Zeroable)]
96pub struct Reset {}
97
98#[repr(C)]
99#[derive(Clone, Copy, Debug, Pod, Zeroable)]
100pub struct Close {}
101
102#[repr(C)]
103#[derive(Clone, Copy, Debug, Pod, Zeroable)]
104pub struct Mine {
105    pub nonce: [u8; 8],
106}
107
108#[repr(C)]
109#[derive(Clone, Copy, Debug, Pod, Zeroable)]
110pub struct Swap {
111    pub amount: [u8; 8],
112    pub direction: u8,
113    pub precision: u8,
114    pub seed: [u8; 32],
115}
116
117#[repr(C)]
118#[derive(Clone, Copy, Debug, Pod, Zeroable)]
119pub struct Uncommit {
120    pub amount: [u8; 8],
121}
122
123#[repr(C)]
124#[derive(Clone, Copy, Debug, Pod, Zeroable)]
125pub struct SetAdmin {
126    pub admin: [u8; 32],
127}
128
129#[repr(C)]
130#[derive(Clone, Copy, Debug, Pod, Zeroable)]
131pub struct SetFeeCollector {
132    pub fee_collector: [u8; 32],
133}
134
135#[repr(C)]
136#[derive(Clone, Copy, Debug, Pod, Zeroable)]
137pub struct SetFeeRate {
138    pub fee_rate: [u8; 8],
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 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 CreateCode {
211    /// The code hash (first 32 bytes of keccak256 hash of the code string)
212    pub code_hash: [u8; 32],
213    /// The wallet (authority) this code is linked to
214    pub authority: [u8; 32],
215}
216
217#[repr(C)]
218#[derive(Clone, Copy, Debug, Pod, Zeroable)]
219pub struct SetTgeTimestamp {
220    /// Unix timestamp for Token Generation Event (TGE).
221    /// If current time < tge_timestamp, pre-mine is active.
222    /// Set to 0 to disable pre-mine.
223    pub tge_timestamp: [u8; 8],
224}
225
226#[repr(C)]
227#[derive(Clone, Copy, Debug, Pod, Zeroable)]
228pub struct Initialize {
229    pub barrel_authority: [u8; 32],
230    pub fee_collector: [u8; 32],
231    pub swap_program: [u8; 32],
232    pub var_address: [u8; 32],
233    pub admin_fee: [u8; 8],
234    // Auction configuration (optional - only used if auction accounts need initialization)
235    pub halving_period_seconds: [u8; 8],
236    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
237    pub auction_duration_seconds: [u8; 8],
238    pub starting_prices: [[u8; 8]; 4],  // 4 wells
239}
240
241#[repr(C)]
242#[derive(Clone, Copy, Debug, Pod, Zeroable)]
243pub struct PlaceBid {
244    pub square_id: [u8; 8],
245    /// Optional referrer pubkey for new miners. Set to Pubkey::default() for no referrer.
246    pub referrer: [u8; 32],
247}
248
249#[repr(C)]
250#[derive(Clone, Copy, Debug, Pod, Zeroable)]
251pub struct ClaimAuctionOIL {
252    /// Well IDs to claim OIL from (0-3), can claim multiple at once
253    /// Bitmask: bit 0 = well 0, bit 1 = well 1, etc.
254    pub well_mask: u8,
255}
256
257#[repr(C)]
258#[derive(Clone, Copy, Debug, Pod, Zeroable)]
259pub struct ClaimAuctionSOL {
260    /// Reserved for future use (currently unused, but kept for consistency)
261    pub _reserved: u8,
262}
263
264#[repr(C)]
265#[derive(Clone, Copy, Debug, Pod, Zeroable)]
266pub struct SetAuction {
267    pub halving_period_seconds: [u8; 8],
268    pub last_halving_time: [u8; 8],
269    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
270    pub auction_duration_seconds: [u8; 8],
271    pub starting_prices: [[u8; 8]; 4],  // 4 wells
272    pub well_id: [u8; 8],  // Well ID to update (0-3). If >= 4, only updates auction account.
273}
274
275#[repr(C)]
276#[derive(Clone, Copy, Debug, Pod, Zeroable)]
277pub struct JoinAuctionPool {
278    /// Square ID (well ID) for this pool contribution (0-3)
279    pub square_id: [u8; 8],
280    /// SOL amount to contribute (in lamports)
281    pub amount: [u8; 8],
282}
283
284impl JoinAuctionPool {
285    pub fn to_bytes(&self) -> Vec<u8> {
286        bytemuck::bytes_of(self).to_vec()
287    }
288}
289
290instruction!(OilInstruction, Automate);
291instruction!(OilInstruction, Initialize);
292instruction!(OilInstruction, Checkpoint);
293instruction!(OilInstruction, ClaimSOL);
294instruction!(OilInstruction, ClaimOIL);
295instruction!(OilInstruction, ClaimSeeker);
296instruction!(OilInstruction, ReloadSOL);
297instruction!(OilInstruction, Deploy);
298instruction!(OilInstruction, Log);
299instruction!(OilInstruction, Buyback);
300instruction!(OilInstruction, Reset);
301instruction!(OilInstruction, Close);
302instruction!(OilInstruction, SetAdmin);
303instruction!(OilInstruction, SetFeeCollector);
304instruction!(OilInstruction, Deposit);
305instruction!(OilInstruction, Withdraw);
306instruction!(OilInstruction, ClaimYield);
307instruction!(OilInstruction, NewVar);
308instruction!(OilInstruction, SetAdminFee);
309instruction!(OilInstruction, SetSwapProgram);
310instruction!(OilInstruction, SetVarAddress);
311instruction!(OilInstruction, Migrate);
312instruction!(OilInstruction, CreateReferral);
313instruction!(OilInstruction, ClaimReferral);
314instruction!(OilInstruction, PlaceBid);
315instruction!(OilInstruction, ClaimAuctionOIL);
316instruction!(OilInstruction, ClaimAuctionSOL);
317instruction!(OilInstruction, SetAuction);
318instruction!(OilInstruction, CreateCode);
319instruction!(OilInstruction, SetTgeTimestamp);