1use solana_program::pubkey::Pubkey;
2use spl_associated_token_account::get_associated_token_address;
3use steel::*;
4
5use crate::{
6 consts::{BOARD, MINT_ADDRESS, SOL_MINT, TREASURY_ADDRESS},
7 instruction::*,
8 state::*,
9};
10
11pub fn log(signer: Pubkey, msg: &[u8]) -> Instruction {
12 let mut data = Log {}.to_bytes();
13 data.extend_from_slice(msg);
14 Instruction {
15 program_id: crate::ID,
16 accounts: vec![AccountMeta::new(signer, true)],
17 data: data,
18 }
19}
20
21pub fn program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramError> {
22 invoke_signed(&log(*accounts[0].key, msg), accounts, &crate::ID, &[BOARD])
23}
24
25pub fn automate(
28 signer: Pubkey,
29 amount: u64,
30 deposit: u64,
31 executor: Pubkey,
32 fee: u64,
33 mask: u64,
34 strategy: u8,
35) -> Instruction {
36 let automation_address = automation_pda(signer).0;
37 let miner_address = miner_pda(signer).0;
38 Instruction {
39 program_id: crate::ID,
40 accounts: vec![
41 AccountMeta::new(signer, true),
42 AccountMeta::new(automation_address, false),
43 AccountMeta::new(executor, false),
44 AccountMeta::new(miner_address, false),
45 AccountMeta::new_readonly(system_program::ID, false),
46 ],
47 data: Automate {
48 amount: amount.to_le_bytes(),
49 deposit: deposit.to_le_bytes(),
50 fee: fee.to_le_bytes(),
51 mask: mask.to_le_bytes(),
52 strategy: strategy as u8,
53 }
54 .to_bytes(),
55 }
56}
57
58pub fn claim_sol(signer: Pubkey) -> Instruction {
59 let miner_address = miner_pda(signer).0;
60 Instruction {
61 program_id: crate::ID,
62 accounts: vec![
63 AccountMeta::new(signer, true),
64 AccountMeta::new(miner_address, false),
65 AccountMeta::new_readonly(system_program::ID, false),
66 ],
67 data: ClaimSOL {}.to_bytes(),
68 }
69}
70
71pub fn claim_ore(signer: Pubkey) -> Instruction {
74 let miner_address = miner_pda(signer).0;
75 let treasury_address = treasury_pda().0;
76 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
77 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
78 Instruction {
79 program_id: crate::ID,
80 accounts: vec![
81 AccountMeta::new(signer, true),
82 AccountMeta::new(miner_address, false),
83 AccountMeta::new(MINT_ADDRESS, false),
84 AccountMeta::new(recipient_address, false),
85 AccountMeta::new(treasury_address, false),
86 AccountMeta::new(treasury_tokens_address, false),
87 AccountMeta::new_readonly(system_program::ID, false),
88 AccountMeta::new_readonly(spl_token::ID, false),
89 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
90 ],
91 data: ClaimORE {}.to_bytes(),
92 }
93}
94
95pub fn deploy(
98 signer: Pubkey,
99 authority: Pubkey,
100 amount: u64,
101 round_id: u64,
102 squares: [bool; 25],
103) -> Instruction {
104 let automation_address = automation_pda(authority).0;
105 let board_address = board_pda().0;
106 let miner_address = miner_pda(authority).0;
107 let round_address = round_pda(round_id).0;
108 let entropy_var_address = entropy_api::state::var_pda(board_address, 0).0;
109
110 let mut mask: u32 = 0;
113 for (i, &square) in squares.iter().enumerate() {
114 if square {
115 mask |= 1 << i;
116 }
117 }
118
119 Instruction {
120 program_id: crate::ID,
121 accounts: vec![
122 AccountMeta::new(signer, true),
123 AccountMeta::new(authority, false),
124 AccountMeta::new(automation_address, false),
125 AccountMeta::new(board_address, false),
126 AccountMeta::new(miner_address, false),
127 AccountMeta::new(round_address, false),
128 AccountMeta::new_readonly(system_program::ID, false),
129 AccountMeta::new(entropy_var_address, false),
131 AccountMeta::new_readonly(entropy_api::ID, false),
132 ],
133 data: Deploy {
134 amount: amount.to_le_bytes(),
135 squares: mask.to_le_bytes(),
136 }
137 .to_bytes(),
138 }
139}
140
141pub fn bury(signer: Pubkey, swap_accounts: &[AccountMeta], swap_data: &[u8]) -> Instruction {
144 let board_address = board_pda().0;
145 let config_address = config_pda().0;
146 let mint_address = MINT_ADDRESS;
147 let treasury_address = TREASURY_ADDRESS;
148 let treasury_ore_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
149 let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
150 let mut accounts = vec![
151 AccountMeta::new(signer, true),
152 AccountMeta::new(board_address, false),
153 AccountMeta::new_readonly(config_address, false),
154 AccountMeta::new(mint_address, false),
155 AccountMeta::new(treasury_address, false),
156 AccountMeta::new(treasury_ore_address, false),
157 AccountMeta::new(treasury_sol_address, false),
158 AccountMeta::new_readonly(spl_token::ID, false),
159 AccountMeta::new_readonly(crate::ID, false),
160 ];
161 for account in swap_accounts.iter() {
162 let mut acc_clone = account.clone();
163 acc_clone.is_signer = false;
164 accounts.push(acc_clone);
165 }
166 let mut data = Bury {}.to_bytes();
167 data.extend_from_slice(swap_data);
168 Instruction {
169 program_id: crate::ID,
170 accounts,
171 data,
172 }
173}
174
175pub fn wrap(signer: Pubkey) -> Instruction {
176 let config_address = config_pda().0;
177 let treasury_address = TREASURY_ADDRESS;
178 let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
179 Instruction {
180 accounts: vec![
181 AccountMeta::new(signer, true),
182 AccountMeta::new_readonly(config_address, false),
183 AccountMeta::new(treasury_address, false),
184 AccountMeta::new(treasury_sol_address, false),
185 AccountMeta::new_readonly(system_program::ID, false),
186 ],
187 program_id: crate::ID,
188 data: Wrap {}.to_bytes(),
189 }
190}
191
192pub fn reset(
195 signer: Pubkey,
196 fee_collector: Pubkey,
197 round_id: u64,
198 top_miner: Pubkey,
199) -> Instruction {
200 let board_address = board_pda().0;
201 let config_address = config_pda().0;
202 let mint_address = MINT_ADDRESS;
203 let round_address = round_pda(round_id).0;
204 let round_next_address = round_pda(round_id + 1).0;
205 let top_miner_address = miner_pda(top_miner).0;
206 let treasury_address = TREASURY_ADDRESS;
207 let treasury_tokens_address = treasury_tokens_address();
208 let entropy_var_address = entropy_api::state::var_pda(board_address, 0).0;
209 Instruction {
210 program_id: crate::ID,
211 accounts: vec![
212 AccountMeta::new(signer, true),
213 AccountMeta::new(board_address, false),
214 AccountMeta::new(config_address, false),
215 AccountMeta::new(fee_collector, false),
216 AccountMeta::new(mint_address, false),
217 AccountMeta::new(round_address, false),
218 AccountMeta::new(round_next_address, false),
219 AccountMeta::new(top_miner_address, false),
220 AccountMeta::new(treasury_address, false),
221 AccountMeta::new(treasury_tokens_address, false),
222 AccountMeta::new_readonly(system_program::ID, false),
223 AccountMeta::new_readonly(spl_token::ID, false),
224 AccountMeta::new_readonly(crate::ID, false),
225 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
226 AccountMeta::new(entropy_var_address, false),
228 AccountMeta::new_readonly(entropy_api::ID, false),
229 ],
230 data: Reset {}.to_bytes(),
231 }
232}
233
234pub fn close(signer: Pubkey, round_id: u64, rent_payer: Pubkey) -> Instruction {
237 let board_address = board_pda().0;
238 let treasury_address = TREASURY_ADDRESS;
239 let round_address = round_pda(round_id).0;
240 Instruction {
241 program_id: crate::ID,
242 accounts: vec![
243 AccountMeta::new(signer, true),
244 AccountMeta::new(board_address, false),
245 AccountMeta::new(rent_payer, false),
246 AccountMeta::new(round_address, false),
247 AccountMeta::new(treasury_address, false),
248 AccountMeta::new_readonly(system_program::ID, false),
249 ],
250 data: Close {}.to_bytes(),
251 }
252}
253
254pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
257 let miner_address = miner_pda(authority).0;
258 let board_address = board_pda().0;
259 let round_address = round_pda(round_id).0;
260 let treasury_address = TREASURY_ADDRESS;
261 Instruction {
262 program_id: crate::ID,
263 accounts: vec![
264 AccountMeta::new(signer, true),
265 AccountMeta::new(board_address, false),
266 AccountMeta::new(miner_address, false),
267 AccountMeta::new(round_address, false),
268 AccountMeta::new(treasury_address, false),
269 AccountMeta::new_readonly(system_program::ID, false),
270 ],
271 data: Checkpoint {}.to_bytes(),
272 }
273}
274
275pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
276 let config_address = config_pda().0;
277 Instruction {
278 program_id: crate::ID,
279 accounts: vec![
280 AccountMeta::new(signer, true),
281 AccountMeta::new(config_address, false),
282 AccountMeta::new_readonly(system_program::ID, false),
283 ],
284 data: SetAdmin {
285 admin: admin.to_bytes(),
286 }
287 .to_bytes(),
288 }
289}
290
291pub fn set_admin_fee(signer: Pubkey, admin_fee: u64) -> Instruction {
292 let config_address = config_pda().0;
293 Instruction {
294 program_id: crate::ID,
295 accounts: vec![
296 AccountMeta::new(signer, true),
297 AccountMeta::new(config_address, false),
298 AccountMeta::new_readonly(system_program::ID, false),
299 ],
300 data: SetAdminFee {
301 admin_fee: admin_fee.to_le_bytes(),
302 }
303 .to_bytes(),
304 }
305}
306
307pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
308 let config_address = config_pda().0;
309 Instruction {
310 program_id: crate::ID,
311 accounts: vec![
312 AccountMeta::new(signer, true),
313 AccountMeta::new(config_address, false),
314 AccountMeta::new_readonly(system_program::ID, false),
315 ],
316 data: SetFeeCollector {
317 fee_collector: fee_collector.to_bytes(),
318 }
319 .to_bytes(),
320 }
321}
322
323pub fn deposit(signer: Pubkey, payer: Pubkey, amount: u64) -> Instruction {
326 let mint_address = MINT_ADDRESS;
327 let stake_address = stake_pda(signer).0;
328 let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
329 let sender_address = get_associated_token_address(&signer, &MINT_ADDRESS);
330 let treasury_address = TREASURY_ADDRESS;
331 Instruction {
332 program_id: crate::ID,
333 accounts: vec![
334 AccountMeta::new(signer, true),
335 AccountMeta::new(payer, true),
336 AccountMeta::new(mint_address, false),
337 AccountMeta::new(sender_address, false),
338 AccountMeta::new(stake_address, false),
339 AccountMeta::new(stake_tokens_address, false),
340 AccountMeta::new(treasury_address, false),
341 AccountMeta::new_readonly(system_program::ID, false),
342 AccountMeta::new_readonly(spl_token::ID, false),
343 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
344 ],
345 data: Deposit {
346 amount: amount.to_le_bytes(),
347 }
348 .to_bytes(),
349 }
350}
351
352pub fn withdraw(signer: Pubkey, amount: u64) -> Instruction {
355 let stake_address = stake_pda(signer).0;
356 let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
357 let mint_address = MINT_ADDRESS;
358 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
359 let treasury_address = TREASURY_ADDRESS;
360 Instruction {
361 program_id: crate::ID,
362 accounts: vec![
363 AccountMeta::new(signer, true),
364 AccountMeta::new(mint_address, false),
365 AccountMeta::new(recipient_address, false),
366 AccountMeta::new(stake_address, false),
367 AccountMeta::new(stake_tokens_address, false),
368 AccountMeta::new(treasury_address, false),
369 AccountMeta::new_readonly(system_program::ID, false),
370 AccountMeta::new_readonly(spl_token::ID, false),
371 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
372 ],
373 data: Withdraw {
374 amount: amount.to_le_bytes(),
375 }
376 .to_bytes(),
377 }
378}
379
380pub fn migrate_automation(signer: Pubkey, authority: Pubkey) -> Instruction {
381 let config_address = config_pda().0;
382 let automation_address = automation_pda(authority).0;
383 Instruction {
384 program_id: crate::ID,
385 accounts: vec![
386 AccountMeta::new(signer, true),
387 AccountMeta::new(config_address, false),
388 AccountMeta::new(automation_address, false),
389 AccountMeta::new_readonly(system_program::ID, false),
390 ],
391 data: MigrateAutomation {}.to_bytes(),
392 }
393}
394
395pub fn recycle_sol(signer: Pubkey, authority: Pubkey) -> Instruction {
398 let automation_address = automation_pda(authority).0;
399 let miner_address = miner_pda(authority).0;
400 Instruction {
401 program_id: crate::ID,
402 accounts: vec![
403 AccountMeta::new(signer, true),
404 AccountMeta::new(automation_address, false),
405 AccountMeta::new(miner_address, false),
406 AccountMeta::new_readonly(system_program::ID, false),
407 ],
408 data: RecycleSOL {}.to_bytes(),
409 }
410}
411
412pub fn claim_yield(signer: Pubkey, amount: u64) -> Instruction {
415 let stake_address = stake_pda(signer).0;
416 let mint_address = MINT_ADDRESS;
417 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
418 let treasury_address = TREASURY_ADDRESS;
419 let treasury_tokens_address = treasury_tokens_address();
420 Instruction {
421 program_id: crate::ID,
422 accounts: vec![
423 AccountMeta::new(signer, true),
424 AccountMeta::new(mint_address, false),
425 AccountMeta::new(recipient_address, false),
426 AccountMeta::new(stake_address, false),
427 AccountMeta::new(treasury_address, false),
428 AccountMeta::new(treasury_tokens_address, false),
429 AccountMeta::new_readonly(system_program::ID, false),
430 AccountMeta::new_readonly(spl_token::ID, false),
431 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
432 ],
433 data: ClaimYield {
434 amount: amount.to_le_bytes(),
435 }
436 .to_bytes(),
437 }
438}
439
440pub fn new_var(
441 signer: Pubkey,
442 provider: Pubkey,
443 id: u64,
444 commit: [u8; 32],
445 samples: u64,
446) -> Instruction {
447 let board_address = board_pda().0;
448 let config_address = config_pda().0;
449 let var_address = entropy_api::state::var_pda(board_address, id).0;
450 Instruction {
451 program_id: crate::ID,
452 accounts: vec![
453 AccountMeta::new(signer, true),
454 AccountMeta::new(board_address, false),
455 AccountMeta::new(config_address, false),
456 AccountMeta::new(provider, false),
457 AccountMeta::new(var_address, false),
458 AccountMeta::new_readonly(system_program::ID, false),
459 AccountMeta::new_readonly(entropy_api::ID, false),
460 ],
461 data: NewVar {
462 id: id.to_le_bytes(),
463 commit: commit,
464 samples: samples.to_le_bytes(),
465 }
466 .to_bytes(),
467 }
468}
469
470pub fn set_swap_program(signer: Pubkey, new_program: Pubkey) -> Instruction {
471 let config_address = config_pda().0;
472 Instruction {
473 program_id: crate::ID,
474 accounts: vec![
475 AccountMeta::new(signer, true),
476 AccountMeta::new(config_address, false),
477 AccountMeta::new_readonly(new_program, false),
478 ],
479 data: SetSwapProgram {}.to_bytes(),
480 }
481}
482
483pub fn set_var_address(signer: Pubkey, new_var_address: Pubkey) -> Instruction {
484 let board_address = board_pda().0;
485 let config_address = config_pda().0;
486 Instruction {
487 program_id: crate::ID,
488 accounts: vec![
489 AccountMeta::new(signer, true),
490 AccountMeta::new(board_address, false),
491 AccountMeta::new(config_address, false),
492 AccountMeta::new(new_var_address, false),
493 ],
494 data: SetVarAddress {}.to_bytes(),
495 }
496}