1use solana_program::pubkey::Pubkey;
2use spl_associated_token_account::get_associated_token_address;
3use steel::*;
4
5use crate::{
6 consts::{AUCTION, BOARD, MINT_ADDRESS, SOL_MINT, TREASURY_ADDRESS},
7 instruction::{self, *},
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 let (board_address, _) = board_pda();
24 invoke_signed(&log(board_address, msg), accounts, &crate::ID, &[BOARD])
25}
26
27pub fn auction_program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramError> {
29 let (auction_address, _) = auction_pda();
31 invoke_signed(&log(auction_address, msg), accounts, &crate::ID, &[AUCTION])
32}
33
34pub fn automate(
78 signer: Pubkey,
79 authority: Pubkey,
80 amount: u64,
81 deposit: u64,
82 executor: Pubkey,
83 fee: u64,
84 mask: u64,
85 strategy: u8,
86 reload: bool,
87 referrer: Option<Pubkey>,
88 pooled: bool,
89 is_new_miner: bool,
90 access_code_hash: Option<[u8; 32]>,
91) -> Instruction {
92 let automation_address = automation_pda(authority).0;
93 let miner_address = miner_pda(authority).0;
94 let config_address = config_pda().0;
95 let referrer_pk = referrer.unwrap_or(Pubkey::default());
96
97 let mut accounts = vec![
98 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(automation_address, false), AccountMeta::new(executor, false), AccountMeta::new(miner_address, false), AccountMeta::new_readonly(system_program::ID, false), AccountMeta::new_readonly(crate::ID, false), AccountMeta::new_readonly(config_address, false), ];
107
108 if is_new_miner && referrer.is_some() && referrer_pk != Pubkey::default() {
113 let referral_address = referral_pda(referrer_pk).0;
114 accounts.push(AccountMeta::new(referral_address, false));
115 }
116
117 let access_code_hash_bytes = access_code_hash.unwrap_or([0; 32]);
119 if access_code_hash_bytes != [0; 32] {
120 let (code_address, _) = Code::pda(access_code_hash_bytes, authority);
121 accounts.push(AccountMeta::new(code_address, false)); }
123
124 Instruction {
125 program_id: crate::ID,
126 accounts,
127 data: Automate {
128 amount: amount.to_le_bytes(),
129 deposit: deposit.to_le_bytes(),
130 fee: fee.to_le_bytes(),
131 mask: mask.to_le_bytes(),
132 strategy: strategy as u8,
133 reload: (reload as u64).to_le_bytes(),
134 referrer: referrer_pk.to_bytes(),
135 pooled: pooled as u8,
136 access_code_hash: access_code_hash_bytes,
137 }
138 .to_bytes(),
139 }
140}
141
142pub fn claim_sol(
150 signer: Pubkey,
151 referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, ) -> Instruction {
154 let miner_address = miner_pda(signer).0;
155
156 let mut accounts = vec![
157 AccountMeta::new(signer, true),
158 AccountMeta::new(miner_address, false),
159 AccountMeta::new_readonly(system_program::ID, false),
160 ];
161
162 if let (Some(miner_pubkey), Some(referral_pubkey)) = (referrer_miner, referrer_referral) {
164 accounts.push(AccountMeta::new(miner_pubkey, false));
165 accounts.push(AccountMeta::new(referral_pubkey, false));
166 }
167
168 Instruction {
169 program_id: crate::ID,
170 accounts,
171 data: ClaimSOL {}.to_bytes(),
172 }
173}
174
175pub fn claim_oil(
185 signer: Pubkey,
186 referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, referrer_referral_oil_ata: Option<Pubkey>, ) -> Instruction {
190 let miner_address = miner_pda(signer).0;
191 let treasury_address = treasury_pda().0;
192 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
193 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
194
195 let mut accounts = vec![
196 AccountMeta::new(signer, true),
197 AccountMeta::new(miner_address, false),
198 AccountMeta::new(MINT_ADDRESS, false),
199 AccountMeta::new(recipient_address, false),
200 AccountMeta::new(treasury_address, false),
201 AccountMeta::new(treasury_tokens_address, false),
202 AccountMeta::new_readonly(system_program::ID, false),
203 AccountMeta::new_readonly(spl_token::ID, false),
204 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
205 ];
206
207 if let (Some(miner_pubkey), Some(referral_pubkey), Some(oil_ata_pubkey)) =
209 (referrer_miner, referrer_referral, referrer_referral_oil_ata) {
210 accounts.push(AccountMeta::new(miner_pubkey, false));
211 accounts.push(AccountMeta::new(referral_pubkey, false));
212 accounts.push(AccountMeta::new(oil_ata_pubkey, false));
213 }
214
215 Instruction {
216 program_id: crate::ID,
217 accounts,
218 data: ClaimOIL {}.to_bytes(),
219 }
220}
221
222
223pub fn close(signer: Pubkey, round_id: u64, rent_payer: Pubkey) -> Instruction {
224 let board_address = board_pda().0;
225 let round_address = round_pda(round_id).0;
226 let treasury_address = TREASURY_ADDRESS;
227 Instruction {
228 program_id: crate::ID,
229 accounts: vec![
230 AccountMeta::new(signer, true),
231 AccountMeta::new(board_address, false),
232 AccountMeta::new(rent_payer, false),
233 AccountMeta::new(round_address, false),
234 AccountMeta::new(treasury_address, false),
235 AccountMeta::new_readonly(system_program::ID, false),
236 ],
237 data: Close {}.to_bytes(),
238 }
239}
240
241pub fn deploy(
244 signer: Pubkey,
245 authority: Pubkey,
246 amount: u64,
247 round_id: u64,
248 squares: [bool; 25],
249 referrer: Option<Pubkey>,
250 pooled: bool,
251 access_code_hash: Option<[u8; 32]>,
252) -> Instruction {
253 let automation_address = automation_pda(authority).0;
254 let board_address = board_pda().0;
255 let config_address = config_pda().0;
256 let miner_address = miner_pda(authority).0;
257 let round_address = round_pda(round_id).0;
258 let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
259
260 let mut mask: u32 = 0;
263 for (i, &square) in squares.iter().enumerate() {
264 if square {
265 mask |= 1 << i;
266 }
267 }
268
269 let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
271 let referrer_bytes = referrer_pubkey.to_bytes();
272
273 let user_wrapped_sol_ata = get_associated_token_address(&authority, &SOL_MINT);
275 let round_wrapped_sol_ata = get_associated_token_address(&round_address, &SOL_MINT);
276
277 let mut accounts = vec![
281 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(automation_address, false), AccountMeta::new(board_address, false), AccountMeta::new_readonly(config_address, false), AccountMeta::new(miner_address, false), AccountMeta::new(round_address, false), AccountMeta::new_readonly(system_program::ID, false), AccountMeta::new_readonly(crate::ID, false), AccountMeta::new(user_wrapped_sol_ata, false), AccountMeta::new(round_wrapped_sol_ata, false), AccountMeta::new_readonly(spl_token::ID, false), AccountMeta::new_readonly(SOL_MINT, false), AccountMeta::new_readonly(spl_associated_token_account::ID, false), ];
298
299 if referrer_pubkey != Pubkey::default() {
301 let referral_address = referral_pda(referrer_pubkey).0;
302 accounts.push(AccountMeta::new(referral_address, false)); }
304
305 let access_code_hash_bytes = access_code_hash.unwrap_or([0; 32]);
307 if access_code_hash_bytes != [0; 32] {
308 let (code_address, _) = Code::pda(access_code_hash_bytes, authority);
309 accounts.push(AccountMeta::new(code_address, false)); }
311
312 accounts.push(AccountMeta::new(entropy_var_address, false)); accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false)); Instruction {
317 program_id: crate::ID,
318 accounts,
319 data: Deploy {
320 amount: amount.to_le_bytes(),
321 squares: mask.to_le_bytes(),
322 referrer: referrer_bytes,
323 pooled: if pooled { 1 } else { 0 },
324 access_code_hash: access_code_hash_bytes,
325 }
326 .to_bytes(),
327 }
328}
329
330pub fn deploy_auto(
333 signer: Pubkey,
334 authority: Pubkey,
335 amount: u64,
336 round_id: u64,
337 squares: [bool; 25],
338 referrer: Option<Pubkey>,
339 pooled: bool,
340 access_code_hash: Option<[u8; 32]>,
341) -> Instruction {
342 let automation_address = automation_pda(authority).0;
343 let board_address = board_pda().0;
344 let config_address = config_pda().0;
345 let miner_address = miner_pda(authority).0;
346 let round_address = round_pda(round_id).0;
347 let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
348
349 let mut mask: u32 = 0;
352 for (i, &square) in squares.iter().enumerate() {
353 if square {
354 mask |= 1 << i;
355 }
356 }
357
358 let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
360 let referrer_bytes = referrer_pubkey.to_bytes();
361
362 let mut accounts = vec![
367 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(automation_address, false), AccountMeta::new(board_address, false), AccountMeta::new_readonly(config_address, false), AccountMeta::new(miner_address, false), AccountMeta::new(round_address, false), AccountMeta::new_readonly(system_program::ID, false), AccountMeta::new_readonly(crate::ID, false), AccountMeta::new_readonly(spl_token::ID, false), AccountMeta::new_readonly(SOL_MINT, false), AccountMeta::new_readonly(spl_associated_token_account::ID, false), ];
382
383 if referrer_pubkey != Pubkey::default() {
385 let referral_address = referral_pda(referrer_pubkey).0;
386 accounts.push(AccountMeta::new(referral_address, false)); }
388
389 let access_code_hash_bytes = access_code_hash.unwrap_or([0; 32]);
391 if access_code_hash_bytes != [0; 32] {
392 let (code_address, _) = Code::pda(access_code_hash_bytes, authority);
393 accounts.push(AccountMeta::new(code_address, false)); }
395
396 accounts.push(AccountMeta::new(entropy_var_address, false)); accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false)); Instruction {
401 program_id: crate::ID,
402 accounts,
403 data: Deploy {
404 amount: amount.to_le_bytes(),
405 squares: mask.to_le_bytes(),
406 referrer: referrer_bytes,
407 pooled: if pooled { 1 } else { 0 },
408 access_code_hash: access_code_hash_bytes,
409 }
410 .to_bytes(),
411 }
412}
413
414pub fn buyback(signer: Pubkey, swap_accounts: &[AccountMeta], swap_data: &[u8]) -> Instruction {
417 let board_address = board_pda().0;
418 let config_address = config_pda().0;
419 let mint_address = MINT_ADDRESS;
420 let treasury_address = TREASURY_ADDRESS;
421 let treasury_oil_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
422 let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
423 let mut accounts = vec![
424 AccountMeta::new(signer, true),
425 AccountMeta::new(board_address, false),
426 AccountMeta::new_readonly(config_address, false),
427 AccountMeta::new(mint_address, false),
428 AccountMeta::new(treasury_address, false),
429 AccountMeta::new(treasury_oil_address, false),
430 AccountMeta::new(treasury_sol_address, false),
431 AccountMeta::new_readonly(spl_token::ID, false),
432 AccountMeta::new_readonly(crate::ID, false),
433 ];
434 for account in swap_accounts.iter() {
435 let mut acc_clone = account.clone();
436 acc_clone.is_signer = false;
437 accounts.push(acc_clone);
438 }
439 let mut data = Buyback {}.to_bytes();
440 data.extend_from_slice(swap_data);
441 Instruction {
442 program_id: crate::ID,
443 accounts,
444 data,
445 }
446}
447
448pub fn reset(
451 signer: Pubkey,
452 fee_collector: Pubkey,
453 round_id: u64,
454 top_miner: Pubkey,
455 var_address: Pubkey,
456) -> Instruction {
457 reset_with_miners(signer, fee_collector, round_id, top_miner, var_address, &[])
458}
459
460pub fn reset_with_miners(
461 signer: Pubkey,
462 fee_collector: Pubkey,
463 round_id: u64,
464 top_miner: Pubkey,
465 var_address: Pubkey,
466 miner_accounts: &[Pubkey],
467) -> Instruction {
468 let board_address = board_pda().0;
469 let config_address = config_pda().0;
470 let mint_address = MINT_ADDRESS;
471 let round_address = round_pda(round_id).0;
472 let round_next_address = round_pda(round_id + 1).0;
473 let top_miner_address = miner_pda(top_miner).0;
474 let treasury_address = TREASURY_ADDRESS;
475 let treasury_tokens_address = treasury_tokens_address();
476 let pool_address = pool_pda().0;
477 let mint_authority_address = oil_mint_api::state::authority_pda().0;
478 let mut reset_instruction = Instruction {
479 program_id: crate::ID,
480 accounts: vec![
481 AccountMeta::new(signer, true),
482 AccountMeta::new(board_address, false),
483 AccountMeta::new(config_address, false),
484 AccountMeta::new(fee_collector, false),
485 AccountMeta::new(mint_address, false),
486 AccountMeta::new(round_address, false),
487 AccountMeta::new(round_next_address, false),
488 AccountMeta::new(top_miner_address, false),
489 AccountMeta::new(treasury_address, false),
490 AccountMeta::new(pool_address, false),
491 AccountMeta::new(treasury_tokens_address, false),
492 AccountMeta::new_readonly(system_program::ID, false),
493 AccountMeta::new_readonly(spl_token::ID, false),
494 AccountMeta::new_readonly(crate::ID, false),
495 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
496 AccountMeta::new_readonly(SOL_MINT, false),
497 AccountMeta::new(var_address, false),
499 AccountMeta::new_readonly(entropy_rng_api::ID, false),
500 AccountMeta::new(mint_authority_address, false),
502 AccountMeta::new_readonly(oil_mint_api::ID, false),
503 ],
504 data: Reset {}.to_bytes(),
505 };
506
507 for miner_pubkey in miner_accounts {
509 reset_instruction.accounts.push(AccountMeta::new(
510 miner_pda(*miner_pubkey).0,
511 false,
512 ));
513 }
514
515 reset_instruction
516}
517
518pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
521 let miner_address = miner_pda(authority).0;
522 let board_address = board_pda().0;
523 let round_address = round_pda(round_id).0;
524 let treasury_address = TREASURY_ADDRESS;
525 Instruction {
526 program_id: crate::ID,
527 accounts: vec![
528 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(board_address, false),
531 AccountMeta::new(miner_address, false),
532 AccountMeta::new(round_address, false),
533 AccountMeta::new(treasury_address, false),
534 AccountMeta::new_readonly(system_program::ID, false),
535 ],
536 data: Checkpoint {}.to_bytes(),
537 }
538}
539
540pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
541 let config_address = config_pda().0;
542 Instruction {
543 program_id: crate::ID,
544 accounts: vec![
545 AccountMeta::new(signer, true),
546 AccountMeta::new(config_address, false),
547 AccountMeta::new_readonly(system_program::ID, false),
548 ],
549 data: SetAdmin {
550 admin: admin.to_bytes(),
551 }
552 .to_bytes(),
553 }
554}
555
556pub fn set_admin_fee(signer: Pubkey, admin_fee: u64) -> Instruction {
557 let config_address = config_pda().0;
558 Instruction {
559 program_id: crate::ID,
560 accounts: vec![
561 AccountMeta::new(signer, true),
562 AccountMeta::new(config_address, false),
563 AccountMeta::new_readonly(system_program::ID, false),
564 ],
565 data: SetAdminFee {
566 admin_fee: admin_fee.to_le_bytes(),
567 }
568 .to_bytes(),
569 }
570}
571
572pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
573 let config_address = config_pda().0;
574 Instruction {
575 program_id: crate::ID,
576 accounts: vec![
577 AccountMeta::new(signer, true),
578 AccountMeta::new(config_address, false),
579 AccountMeta::new_readonly(system_program::ID, false),
580 ],
581 data: SetFeeCollector {
582 fee_collector: fee_collector.to_bytes(),
583 }
584 .to_bytes(),
585 }
586}
587
588pub fn set_tge_timestamp(signer: Pubkey, tge_timestamp: i64) -> Instruction {
593 let config_address = config_pda().0;
594 Instruction {
595 program_id: crate::ID,
596 accounts: vec![
597 AccountMeta::new(signer, true),
598 AccountMeta::new(config_address, false),
599 AccountMeta::new_readonly(system_program::ID, false),
600 ],
601 data: SetTgeTimestamp {
602 tge_timestamp: tge_timestamp.to_le_bytes(),
603 }
604 .to_bytes(),
605 }
606}
607
608pub fn set_auction(
609 signer: Pubkey,
610 halving_period_seconds: u64,
611 last_halving_time: u64,
612 base_mining_rates: [u64; 4],
613 auction_duration_seconds: u64,
614 starting_prices: [u64; 4],
615 _well_id: u64, ) -> Instruction {
617 let config_address = config_pda().0;
618 let auction_address = auction_pda().0;
619
620 Instruction {
621 program_id: crate::ID,
622 accounts: vec![
623 AccountMeta::new(signer, true),
624 AccountMeta::new_readonly(config_address, false),
625 AccountMeta::new(auction_address, false),
626 ],
627 data: SetAuction {
628 halving_period_seconds: halving_period_seconds.to_le_bytes(),
629 last_halving_time: last_halving_time.to_le_bytes(),
630 base_mining_rates: [
631 base_mining_rates[0].to_le_bytes(),
632 base_mining_rates[1].to_le_bytes(),
633 base_mining_rates[2].to_le_bytes(),
634 base_mining_rates[3].to_le_bytes(),
635 ],
636 auction_duration_seconds: auction_duration_seconds.to_le_bytes(),
637 starting_prices: [
638 starting_prices[0].to_le_bytes(),
639 starting_prices[1].to_le_bytes(),
640 starting_prices[2].to_le_bytes(),
641 starting_prices[3].to_le_bytes(),
642 ],
643 well_id: 4u64.to_le_bytes(), }
645 .to_bytes(),
646 }
647}
648
649pub fn deposit(signer: Pubkey, authority: Pubkey, amount: u64, lock_duration_days: u64, stake_id: u64) -> Instruction {
652 let mint_address = MINT_ADDRESS;
653 let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
655 let sender_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
657 let pool_tokens_address = pool_tokens_address();
658 let miner_address = miner_pda(authority).0; Instruction {
660 program_id: crate::ID,
661 accounts: vec![
662 AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new(mint_address, false),
665 AccountMeta::new(sender_address, false),
666 AccountMeta::new(stake_address, false),
667 AccountMeta::new(stake_tokens_address, false),
668 AccountMeta::new(pool_address, false),
669 AccountMeta::new(pool_tokens_address, false),
670 AccountMeta::new(miner_address, false),
671 AccountMeta::new_readonly(system_program::ID, false),
672 AccountMeta::new_readonly(spl_token::ID, false),
673 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
674 ],
675 data: Deposit {
676 amount: amount.to_le_bytes(),
677 lock_duration_days: lock_duration_days.to_le_bytes(),
678 stake_id: stake_id.to_le_bytes(),
679 }
680 .to_bytes(),
681 }
682}
683
684pub fn withdraw(signer: Pubkey, authority: Pubkey, amount: u64, stake_id: u64) -> Instruction {
687 let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
689 let mint_address = MINT_ADDRESS;
690 let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
692 let pool_tokens_address = pool_tokens_address();
693 let miner_address = miner_pda(authority).0; Instruction {
695 program_id: crate::ID,
696 accounts: vec![
697 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(mint_address, false),
700 AccountMeta::new(recipient_address, false),
701 AccountMeta::new(stake_address, false),
702 AccountMeta::new(stake_tokens_address, false),
703 AccountMeta::new(pool_address, false),
704 AccountMeta::new(pool_tokens_address, false),
705 AccountMeta::new(miner_address, false),
706 AccountMeta::new_readonly(system_program::ID, false),
707 AccountMeta::new_readonly(spl_token::ID, false),
708 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
709 ],
710 data: Withdraw {
711 amount: amount.to_le_bytes(),
712 stake_id: stake_id.to_le_bytes(),
713 }
714 .to_bytes(),
715 }
716}
717
718pub fn reload_sol(
728 signer: Pubkey,
729 authority: Pubkey,
730 referrer_miner: Option<Pubkey>,
731 referrer_referral: Option<Pubkey>,
732) -> Instruction {
733 let automation_address = automation_pda(authority).0;
734 let miner_address = miner_pda(authority).0;
735
736 let mut accounts = vec![
737 AccountMeta::new(signer, true),
738 AccountMeta::new(automation_address, false),
739 AccountMeta::new(miner_address, false),
740 AccountMeta::new_readonly(system_program::ID, false),
741 ];
742
743 if let (Some(miner_ref), Some(referral_ref)) = (referrer_miner, referrer_referral) {
745 accounts.push(AccountMeta::new(miner_ref, false));
746 accounts.push(AccountMeta::new(referral_ref, false));
747 }
748
749 Instruction {
750 program_id: crate::ID,
751 accounts,
752 data: ReloadSOL {}.to_bytes(),
753 }
754}
755
756pub fn claim_yield(signer: Pubkey, authority: Pubkey, amount: u64, stake_id: u64) -> Instruction {
760 let stake_address = stake_pda_with_id(authority, stake_id).0; let pool_address = pool_pda().0;
762 Instruction {
763 program_id: crate::ID,
764 accounts: vec![
765 AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new(stake_address, false),
768 AccountMeta::new(pool_address, false),
769 AccountMeta::new_readonly(system_program::ID, false),
770 ],
771 data: ClaimYield {
772 amount: amount.to_le_bytes(),
773 }
774 .to_bytes(),
775 }
776}
777
778pub fn new_var(
779 signer: Pubkey,
780 provider: Pubkey,
781 id: u64,
782 commit: [u8; 32],
783 samples: u64,
784) -> Instruction {
785 let board_address = board_pda().0;
786 let config_address = config_pda().0;
787 let var_address = entropy_rng_api::state::var_pda(board_address, id).0;
788 Instruction {
789 program_id: crate::ID,
790 accounts: vec![
791 AccountMeta::new(signer, true),
792 AccountMeta::new(board_address, false),
793 AccountMeta::new(config_address, false),
794 AccountMeta::new(provider, false),
795 AccountMeta::new(var_address, false),
796 AccountMeta::new_readonly(system_program::ID, false),
797 AccountMeta::new_readonly(entropy_rng_api::ID, false),
798 ],
799 data: NewVar {
800 id: id.to_le_bytes(),
801 commit: commit,
802 samples: samples.to_le_bytes(),
803 }
804 .to_bytes(),
805 }
806}
807
808pub fn set_swap_program(signer: Pubkey, new_program: Pubkey) -> Instruction {
809 let config_address = config_pda().0;
810 Instruction {
811 program_id: crate::ID,
812 accounts: vec![
813 AccountMeta::new(signer, true),
814 AccountMeta::new(config_address, false),
815 AccountMeta::new_readonly(new_program, false),
816 ],
817 data: SetSwapProgram {}.to_bytes(),
818 }
819}
820
821pub fn set_var_address(signer: Pubkey, new_var_address: Pubkey) -> Instruction {
822 let board_address = board_pda().0;
823 let config_address = config_pda().0;
824 Instruction {
825 program_id: crate::ID,
826 accounts: vec![
827 AccountMeta::new(signer, true),
828 AccountMeta::new(board_address, false),
829 AccountMeta::new(config_address, false),
830 AccountMeta::new(new_var_address, false),
831 ],
832 data: SetVarAddress {}.to_bytes(),
833 }
834}
835
836pub fn migrate(signer: Pubkey) -> Instruction {
841 let config_address = config_pda().0;
842 Instruction {
843 program_id: crate::ID,
844 accounts: vec![
845 AccountMeta::new(signer, true),
846 AccountMeta::new(config_address, false),
847 AccountMeta::new_readonly(system_program::ID, false),
848 ],
849 data: Migrate {}.to_bytes(),
850 }
851}
852
853pub fn create_referral(signer: Pubkey) -> Instruction {
855 let referral_address = referral_pda(signer).0;
856 Instruction {
857 program_id: crate::ID,
858 accounts: vec![
859 AccountMeta::new(signer, true),
860 AccountMeta::new(referral_address, false),
861 AccountMeta::new_readonly(system_program::ID, false),
862 ],
863 data: CreateReferral {}.to_bytes(),
864 }
865}
866
867pub fn create_code(
871 signer: Pubkey,
872 code_hash: [u8; 32],
873 authority: Pubkey,
874) -> Instruction {
875 let config_address = config_pda().0;
876 let (code_address, _) = Code::pda(code_hash, authority);
877 Instruction {
878 program_id: crate::ID,
879 accounts: vec![
880 AccountMeta::new(signer, true), AccountMeta::new_readonly(config_address, false), AccountMeta::new(code_address, false), AccountMeta::new_readonly(system_program::ID, false), ],
885 data: CreateCode {
886 code_hash,
887 authority: authority.to_bytes(),
888 }
889 .to_bytes(),
890 }
891}
892
893pub fn claim_referral(signer: Pubkey, authority: Pubkey) -> Instruction {
898 let referral_address = referral_pda(authority).0;
899 let referral_oil_address = get_associated_token_address(&referral_address, &MINT_ADDRESS);
900 let recipient_oil_address = get_associated_token_address(&authority, &MINT_ADDRESS);
901 Instruction {
902 program_id: crate::ID,
903 accounts: vec![
904 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(referral_address, false), AccountMeta::new(referral_oil_address, false), AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(recipient_oil_address, false), AccountMeta::new_readonly(system_program::ID, false), AccountMeta::new_readonly(spl_token::ID, false), AccountMeta::new_readonly(spl_associated_token_account::ID, false), ],
914 data: ClaimReferral {}.to_bytes(),
915 }
916}
917
918pub fn place_bid(
928 signer: Pubkey,
929 authority: Pubkey,
930 square_id: u64,
931 fee_collector: Pubkey,
932 previous_owner_miner: Option<Pubkey>, previous_owner: Option<Pubkey>, referrer: Option<Pubkey>, access_code_hash: Option<[u8; 32]>, ) -> Instruction {
937 let well_address = well_pda(square_id).0;
938 let auction_address = auction_pda().0;
939 let treasury_address = treasury_pda().0;
940 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
941 let staking_pool_address = pool_pda().0;
942 let config_address = config_pda().0;
943 let mint_authority_address = oil_mint_api::state::authority_pda().0;
944 let bidder_miner_address = miner_pda(authority).0;
945
946 let mut accounts = vec![
947 AccountMeta::new(signer, true), AccountMeta::new(authority, false), ];
950
951 accounts.extend_from_slice(&[
955 AccountMeta::new(well_address, false), AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
958 AccountMeta::new(treasury_tokens_address, false),
959 AccountMeta::new(MINT_ADDRESS, false),
960 AccountMeta::new(mint_authority_address, false),
961 AccountMeta::new_readonly(oil_mint_api::ID, false),
962 AccountMeta::new(staking_pool_address, false),
963 AccountMeta::new(fee_collector, false),
964 AccountMeta::new_readonly(config_address, false),
965 AccountMeta::new_readonly(spl_token::ID, false),
966 AccountMeta::new_readonly(system_program::ID, false),
967 AccountMeta::new_readonly(crate::ID, false), AccountMeta::new(bidder_miner_address, false), ]);
970
971 if let (Some(miner_pubkey), Some(owner_pubkey)) = (previous_owner_miner, previous_owner) {
973 accounts.push(AccountMeta::new(miner_pubkey, false)); accounts.push(AccountMeta::new(owner_pubkey, false)); }
976
977 if let Some(referrer_pubkey) = referrer {
979 let referral_address = referral_pda(referrer_pubkey).0;
980 accounts.push(AccountMeta::new(referral_address, false)); }
982
983 let access_code_hash_bytes = access_code_hash.unwrap_or([0; 32]);
985 if access_code_hash_bytes != [0; 32] {
986 let (code_address, _) = Code::pda(access_code_hash_bytes, authority);
987 accounts.push(AccountMeta::new(code_address, false)); }
989
990 Instruction {
997 program_id: crate::ID,
998 accounts,
999 data: instruction::PlaceBid {
1000 square_id: square_id.to_le_bytes(),
1001 referrer: referrer.unwrap_or(Pubkey::default()).to_bytes(),
1002 access_code_hash: access_code_hash_bytes,
1003 }
1004 .to_bytes(),
1005 }
1006}
1007
1008pub fn claim_auction_oil(
1015 signer: Pubkey,
1016 well_mask: u8, well_accounts: [Option<Pubkey>; 4], auction_pool_accounts: Option<[Option<Pubkey>; 4]>, bid_accounts: Option<[Option<Pubkey>; 4]>, ) -> Instruction {
1021 let miner_address = miner_pda(signer).0;
1022 let auction_address = auction_pda().0;
1023 let treasury_address = treasury_pda().0;
1024 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
1025 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
1026 let mint_authority_address = oil_mint_api::state::authority_pda().0;
1027
1028 let mut accounts = vec![
1029 AccountMeta::new(signer, true),
1030 AccountMeta::new(miner_address, false),
1031 ];
1032
1033 for well_opt in well_accounts.iter() {
1035 if let Some(well_pubkey) = well_opt {
1036 accounts.push(AccountMeta::new(*well_pubkey, false));
1037 } else {
1038 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1040 }
1041 }
1042
1043 if let Some(auction_pool_pdas) = auction_pool_accounts {
1045 for auction_pool_pda_opt in auction_pool_pdas.iter() {
1046 if let Some(auction_pool_pubkey) = auction_pool_pda_opt {
1047 accounts.push(AccountMeta::new(*auction_pool_pubkey, false));
1048 } else {
1049 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1051 }
1052 }
1053 } else {
1054 for _ in 0..4 {
1056 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1057 }
1058 }
1059
1060 accounts.extend_from_slice(&[
1061 AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
1063 AccountMeta::new(treasury_tokens_address, false),
1064 AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(mint_authority_address, false), AccountMeta::new_readonly(oil_mint_api::ID, false),
1067 AccountMeta::new(recipient_address, false),
1068 AccountMeta::new_readonly(spl_token::ID, false),
1069 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
1070 AccountMeta::new_readonly(system_program::ID, false),
1071 AccountMeta::new_readonly(crate::ID, false), ]);
1073
1074 if let Some(bid_pdas) = bid_accounts {
1076 for bid_pda_opt in bid_pdas.iter() {
1077 if let Some(bid_pubkey) = bid_pda_opt {
1078 accounts.push(AccountMeta::new(*bid_pubkey, false));
1079 }
1080 }
1081 }
1082
1083 Instruction {
1084 program_id: crate::ID,
1085 accounts,
1086 data: ClaimAuctionOIL {
1087 well_mask,
1088 }
1089 .to_bytes(),
1090 }
1091}
1092
1093pub fn claim_auction_sol(
1100 signer: Pubkey,
1101 well_accounts: [Option<Pubkey>; 4], auction_pool_accounts: Option<[Option<Pubkey>; 4]>, bid_accounts: Option<[Option<Pubkey>; 4]>, ) -> Instruction {
1105 let miner_address = miner_pda(signer).0;
1106 let (auction_address, _) = auction_pda();
1107 let treasury_address = treasury_pda().0;
1108
1109 let mut accounts = vec![
1110 AccountMeta::new(signer, true),
1111 AccountMeta::new(miner_address, false),
1112 ];
1113
1114 for well_opt in well_accounts.iter() {
1116 if let Some(well_pubkey) = well_opt {
1117 accounts.push(AccountMeta::new(*well_pubkey, false));
1118 } else {
1119 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1121 }
1122 }
1123
1124 if let Some(auction_pool_pdas) = auction_pool_accounts {
1126 for auction_pool_pda_opt in auction_pool_pdas.iter() {
1127 if let Some(auction_pool_pubkey) = auction_pool_pda_opt {
1128 accounts.push(AccountMeta::new(*auction_pool_pubkey, false));
1129 } else {
1130 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1132 }
1133 }
1134 } else {
1135 for _ in 0..4 {
1137 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1138 }
1139 }
1140
1141 accounts.extend_from_slice(&[
1142 AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
1144 AccountMeta::new_readonly(system_program::ID, false),
1145 AccountMeta::new_readonly(crate::ID, false), ]);
1147
1148 if let Some(bid_pdas) = bid_accounts {
1150 for bid_pda_opt in bid_pdas.iter() {
1151 if let Some(bid_pubkey) = bid_pda_opt {
1152 accounts.push(AccountMeta::new(*bid_pubkey, false));
1153 }
1154 }
1155 }
1156
1157 Instruction {
1158 program_id: crate::ID,
1159 accounts,
1160 data: ClaimAuctionSOL {
1161 _reserved: 0,
1162 }
1163 .to_bytes(),
1164 }
1165}
1166
1167pub fn claim_seeker(signer: Pubkey, mint: Pubkey) -> Instruction {
1168 let seeker_address = seeker_pda(mint).0;
1169 let token_account_address = get_associated_token_address(&signer, &mint);
1170 Instruction {
1171 program_id: crate::ID,
1172 accounts: vec![
1173 AccountMeta::new(signer, true),
1174 AccountMeta::new_readonly(mint, false),
1175 AccountMeta::new(seeker_address, false),
1176 AccountMeta::new(token_account_address, false),
1177 AccountMeta::new_readonly(system_program::ID, false),
1178 ],
1179 data: ClaimSeeker {}.to_bytes(),
1180 }
1181}