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