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