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