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    /// Optional access code hash for pre-mine. Set to [0; 32] for no access code.
60    pub access_code_hash: [u8; 32],
61}
62
63#[repr(C)]
64#[derive(Clone, Copy, Debug, Pod, Zeroable)]
65pub struct InitRound {}
66
67#[repr(C)]
68#[derive(Clone, Copy, Debug, Pod, Zeroable)]
69pub struct ClaimSOL {}
70
71#[repr(C)]
72#[derive(Clone, Copy, Debug, Pod, Zeroable)]
73pub struct ClaimOIL {}
74
75#[repr(C)]
76#[derive(Clone, Copy, Debug, Pod, Zeroable)]
77pub struct ClaimSeeker {}
78
79#[repr(C)]
80#[derive(Clone, Copy, Debug, Pod, Zeroable)]
81pub struct Deploy {
82    pub amount: [u8; 8],
83    pub squares: [u8; 4],
84    /// Optional referrer pubkey. Set to Pubkey::default() for no referrer.
85    pub referrer: [u8; 32],
86    /// Whether this deploy is pooled. 0 = solo, 1 = pooled.
87    pub pooled: u8,
88    /// Optional access code hash for pre-mine. Set to [0; 32] for no access code.
89    pub access_code_hash: [u8; 32],
90}
91
92#[repr(C)]
93#[derive(Clone, Copy, Debug, Pod, Zeroable)]
94pub struct Log {}
95
96#[repr(C)]
97#[derive(Clone, Copy, Debug, Pod, Zeroable)]
98pub struct Reset {}
99
100#[repr(C)]
101#[derive(Clone, Copy, Debug, Pod, Zeroable)]
102pub struct Close {}
103
104#[repr(C)]
105#[derive(Clone, Copy, Debug, Pod, Zeroable)]
106pub struct Mine {
107    pub nonce: [u8; 8],
108}
109
110#[repr(C)]
111#[derive(Clone, Copy, Debug, Pod, Zeroable)]
112pub struct Swap {
113    pub amount: [u8; 8],
114    pub direction: u8,
115    pub precision: u8,
116    pub seed: [u8; 32],
117}
118
119#[repr(C)]
120#[derive(Clone, Copy, Debug, Pod, Zeroable)]
121pub struct Uncommit {
122    pub amount: [u8; 8],
123}
124
125#[repr(C)]
126#[derive(Clone, Copy, Debug, Pod, Zeroable)]
127pub struct SetAdmin {
128    pub admin: [u8; 32],
129}
130
131#[repr(C)]
132#[derive(Clone, Copy, Debug, Pod, Zeroable)]
133pub struct SetFeeCollector {
134    pub fee_collector: [u8; 32],
135}
136
137#[repr(C)]
138#[derive(Clone, Copy, Debug, Pod, Zeroable)]
139pub struct SetFeeRate {
140    pub fee_rate: [u8; 8],
141}
142
143#[repr(C)]
144#[derive(Clone, Copy, Debug, Pod, Zeroable)]
145pub struct Buyback {}
146
147#[repr(C)]
148#[derive(Clone, Copy, Debug, Pod, Zeroable)]
149pub struct ReloadSOL {}
150
151#[repr(C)]
152#[derive(Clone, Copy, Debug, Pod, Zeroable)]
153pub struct Deposit {
154    pub amount: [u8; 8],
155    pub lock_duration_days: [u8; 8],  // 0 = no lock, 1-730 days
156    pub stake_id: [u8; 8],  // Unique ID for this stake account (allows multiple stakes per user)
157}
158
159#[repr(C)]
160#[derive(Clone, Copy, Debug, Pod, Zeroable)]
161pub struct Withdraw {
162    pub amount: [u8; 8],
163    pub stake_id: [u8; 8],
164}
165
166#[repr(C)]
167#[derive(Clone, Copy, Debug, Pod, Zeroable)]
168pub struct ClaimYield {
169    pub amount: [u8; 8],
170}
171
172#[repr(C)]
173#[derive(Clone, Copy, Debug, Pod, Zeroable)]
174pub struct Checkpoint {}
175
176#[repr(C)]
177#[derive(Clone, Copy, Debug, Pod, Zeroable)]
178pub struct NewVar {
179    pub id: [u8; 8],
180    pub commit: [u8; 32],
181    pub samples: [u8; 8],
182}
183
184#[repr(C)]
185#[derive(Clone, Copy, Debug, Pod, Zeroable)]
186pub struct SetAdminFee {
187    pub admin_fee: [u8; 8],
188}
189
190#[repr(C)]
191#[derive(Clone, Copy, Debug, Pod, Zeroable)]
192pub struct SetSwapProgram {}
193
194#[repr(C)]
195#[derive(Clone, Copy, Debug, Pod, Zeroable)]
196pub struct SetVarAddress {}
197
198#[repr(C)]
199#[derive(Clone, Copy, Debug, Pod, Zeroable)]
200pub struct Migrate {}
201
202#[repr(C)]
203#[derive(Clone, Copy, Debug, Pod, Zeroable)]
204pub struct CreateReferral {}
205
206#[repr(C)]
207#[derive(Clone, Copy, Debug, Pod, Zeroable)]
208pub struct ClaimReferral {}
209
210#[repr(C)]
211#[derive(Clone, Copy, Debug, Pod, Zeroable)]
212pub struct CreateWhitelist {
213    /// The code hash (first 32 bytes of keccak256 hash of the code string)
214    pub code_hash: [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    /// Optional access code hash for pre-mine. Set to [0; 32] for no access code.
248    pub access_code_hash: [u8; 32],
249}
250
251#[repr(C)]
252#[derive(Clone, Copy, Debug, Pod, Zeroable)]
253pub struct ClaimAuctionOIL {
254    /// Well IDs to claim OIL from (0-3), can claim multiple at once
255    /// Bitmask: bit 0 = well 0, bit 1 = well 1, etc.
256    pub well_mask: u8,
257}
258
259#[repr(C)]
260#[derive(Clone, Copy, Debug, Pod, Zeroable)]
261pub struct ClaimAuctionSOL {
262    /// Reserved for future use (currently unused, but kept for consistency)
263    pub _reserved: u8,
264}
265
266#[repr(C)]
267#[derive(Clone, Copy, Debug, Pod, Zeroable)]
268pub struct SetAuction {
269    pub halving_period_seconds: [u8; 8],
270    pub last_halving_time: [u8; 8],
271    pub base_mining_rates: [[u8; 8]; 4],  // 4 wells
272    pub auction_duration_seconds: [u8; 8],
273    pub starting_prices: [[u8; 8]; 4],  // 4 wells
274    pub well_id: [u8; 8],  // Well ID to update (0-3). If >= 4, only updates auction account.
275}
276
277#[repr(C)]
278#[derive(Clone, Copy, Debug, Pod, Zeroable)]
279pub struct JoinAuctionPool {
280    /// Square ID (well ID) for this pool contribution (0-3)
281    pub square_id: [u8; 8],
282    /// SOL amount to contribute (in lamports)
283    pub amount: [u8; 8],
284}
285
286impl JoinAuctionPool {
287    pub fn to_bytes(&self) -> Vec<u8> {
288        bytemuck::bytes_of(self).to_vec()
289    }
290}
291
292instruction!(OilInstruction, Automate);
293instruction!(OilInstruction, Initialize);
294instruction!(OilInstruction, Checkpoint);
295instruction!(OilInstruction, ClaimSOL);
296instruction!(OilInstruction, ClaimOIL);
297instruction!(OilInstruction, ClaimSeeker);
298instruction!(OilInstruction, ReloadSOL);
299instruction!(OilInstruction, Deploy);
300instruction!(OilInstruction, Log);
301instruction!(OilInstruction, Buyback);
302instruction!(OilInstruction, Reset);
303instruction!(OilInstruction, Close);
304instruction!(OilInstruction, SetAdmin);
305instruction!(OilInstruction, SetFeeCollector);
306instruction!(OilInstruction, Deposit);
307instruction!(OilInstruction, Withdraw);
308instruction!(OilInstruction, ClaimYield);
309instruction!(OilInstruction, NewVar);
310instruction!(OilInstruction, SetAdminFee);
311instruction!(OilInstruction, SetSwapProgram);
312instruction!(OilInstruction, SetVarAddress);
313instruction!(OilInstruction, Migrate);
314instruction!(OilInstruction, CreateReferral);
315instruction!(OilInstruction, ClaimReferral);
316instruction!(OilInstruction, PlaceBid);
317instruction!(OilInstruction, ClaimAuctionOIL);
318instruction!(OilInstruction, ClaimAuctionSOL);
319instruction!(OilInstruction, SetAuction);
320instruction!(OilInstruction, CreateWhitelist);
321instruction!(OilInstruction, SetTgeTimestamp);