Skip to main content

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