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) -> Instruction {
91 let automation_address = automation_pda(authority).0;
92 let miner_address = miner_pda(authority).0;
93 let config_address = config_pda().0;
94 let referrer_pk = referrer.unwrap_or(Pubkey::default());
95
96 let mut accounts = vec![
97 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), ];
106
107 if is_new_miner && referrer.is_some() && referrer_pk != Pubkey::default() {
112 let referral_address = referral_pda(referrer_pk).0;
113 accounts.push(AccountMeta::new(referral_address, false));
114 }
115
116 Instruction {
117 program_id: crate::ID,
118 accounts,
119 data: Automate {
120 amount: amount.to_le_bytes(),
121 deposit: deposit.to_le_bytes(),
122 fee: fee.to_le_bytes(),
123 mask: mask.to_le_bytes(),
124 strategy: strategy as u8,
125 reload: (reload as u64).to_le_bytes(),
126 referrer: referrer_pk.to_bytes(),
127 pooled: pooled as u8,
128 }
129 .to_bytes(),
130 }
131}
132
133pub fn claim_sol(
141 signer: Pubkey,
142 referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, ) -> Instruction {
145 let miner_address = miner_pda(signer).0;
146
147 let mut accounts = vec![
148 AccountMeta::new(signer, true),
149 AccountMeta::new(miner_address, false),
150 AccountMeta::new_readonly(system_program::ID, false),
151 ];
152
153 if let (Some(miner_pubkey), Some(referral_pubkey)) = (referrer_miner, referrer_referral) {
155 accounts.push(AccountMeta::new(miner_pubkey, false));
156 accounts.push(AccountMeta::new(referral_pubkey, false));
157 }
158
159 Instruction {
160 program_id: crate::ID,
161 accounts,
162 data: ClaimSOL {}.to_bytes(),
163 }
164}
165
166pub fn claim_oil(
176 signer: Pubkey,
177 referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, referrer_referral_oil_ata: Option<Pubkey>, ) -> Instruction {
181 let miner_address = miner_pda(signer).0;
182 let treasury_address = treasury_pda().0;
183 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
184 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
185
186 let mut accounts = vec![
187 AccountMeta::new(signer, true),
188 AccountMeta::new(miner_address, false),
189 AccountMeta::new(MINT_ADDRESS, false),
190 AccountMeta::new(recipient_address, false),
191 AccountMeta::new(treasury_address, false),
192 AccountMeta::new(treasury_tokens_address, false),
193 AccountMeta::new_readonly(system_program::ID, false),
194 AccountMeta::new_readonly(spl_token::ID, false),
195 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
196 ];
197
198 if let (Some(miner_pubkey), Some(referral_pubkey), Some(oil_ata_pubkey)) =
200 (referrer_miner, referrer_referral, referrer_referral_oil_ata) {
201 accounts.push(AccountMeta::new(miner_pubkey, false));
202 accounts.push(AccountMeta::new(referral_pubkey, false));
203 accounts.push(AccountMeta::new(oil_ata_pubkey, false));
204 }
205
206 Instruction {
207 program_id: crate::ID,
208 accounts,
209 data: ClaimOIL {}.to_bytes(),
210 }
211}
212
213
214pub fn close(signer: Pubkey, round_id: u64, rent_payer: Pubkey) -> Instruction {
215 let board_address = board_pda().0;
216 let round_address = round_pda(round_id).0;
217 let treasury_address = TREASURY_ADDRESS;
218 Instruction {
219 program_id: crate::ID,
220 accounts: vec![
221 AccountMeta::new(signer, true),
222 AccountMeta::new(board_address, false),
223 AccountMeta::new(rent_payer, false),
224 AccountMeta::new(round_address, false),
225 AccountMeta::new(treasury_address, false),
226 AccountMeta::new_readonly(system_program::ID, false),
227 ],
228 data: Close {}.to_bytes(),
229 }
230}
231
232pub 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) -> Instruction {
252 let automation_address = automation_pda(authority).0;
253 let board_address = board_pda().0;
254 let config_address = config_pda().0;
255 let miner_address = miner_pda(authority).0;
256 let round_address = round_pda(round_id).0;
257 let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
258
259 let mut mask: u32 = 0;
262 for (i, &square) in squares.iter().enumerate() {
263 if square {
264 mask |= 1 << i;
265 }
266 }
267
268 let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
270 let referrer_bytes = referrer_pubkey.to_bytes();
271
272 let user_wrapped_sol_ata = get_associated_token_address(&authority, &SOL_MINT);
274 let round_wrapped_sol_ata = get_associated_token_address(&round_address, &SOL_MINT);
275
276 let mut accounts = vec![
280 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), ];
297
298 if referrer_pubkey != Pubkey::default() {
300 let referral_address = referral_pda(referrer_pubkey).0;
301 accounts.push(AccountMeta::new(referral_address, false)); }
303
304 accounts.push(AccountMeta::new(entropy_var_address, false)); accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false)); Instruction {
309 program_id: crate::ID,
310 accounts,
311 data: Deploy {
312 amount: amount.to_le_bytes(),
313 squares: mask.to_le_bytes(),
314 referrer: referrer_bytes,
315 pooled: if pooled { 1 } else { 0 },
316 }
317 .to_bytes(),
318 }
319}
320
321pub fn deploy_auto(
332 signer: Pubkey,
333 authority: Pubkey,
334 amount: u64,
335 round_id: u64,
336 squares: [bool; 25],
337 referrer: Option<Pubkey>,
338 pooled: bool,
339) -> Instruction {
340 let automation_address = automation_pda(authority).0;
341 let board_address = board_pda().0;
342 let config_address = config_pda().0;
343 let miner_address = miner_pda(authority).0;
344 let round_address = round_pda(round_id).0;
345 let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
346
347 let mut mask: u32 = 0;
350 for (i, &square) in squares.iter().enumerate() {
351 if square {
352 mask |= 1 << i;
353 }
354 }
355
356 let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
358 let referrer_bytes = referrer_pubkey.to_bytes();
359
360 let mut accounts = vec![
365 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), ];
380
381 if referrer_pubkey != Pubkey::default() {
383 let referral_address = referral_pda(referrer_pubkey).0;
384 accounts.push(AccountMeta::new(referral_address, false)); }
386
387 accounts.push(AccountMeta::new(entropy_var_address, false)); accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false)); Instruction {
392 program_id: crate::ID,
393 accounts,
394 data: Deploy {
395 amount: amount.to_le_bytes(),
396 squares: mask.to_le_bytes(),
397 referrer: referrer_bytes,
398 pooled: if pooled { 1 } else { 0 },
399 }
400 .to_bytes(),
401 }
402}
403
404pub fn wrap(signer: Pubkey, use_liquidity: bool, amount: u64) -> Instruction {
407 let config_address = config_pda().0;
408 let treasury_address = TREASURY_ADDRESS;
409 let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
410 let data = Wrap {
411 use_liquidity: if use_liquidity { 1 } else { 0 },
412 amount: amount.to_le_bytes(),
413 }
414 .to_bytes();
415 Instruction {
416 program_id: crate::ID,
417 accounts: vec![
418 AccountMeta::new(signer, true),
419 AccountMeta::new_readonly(config_address, false),
420 AccountMeta::new(treasury_address, false),
421 AccountMeta::new(treasury_sol_address, false),
422 AccountMeta::new_readonly(solana_program::system_program::ID, false),
423 ],
424 data,
425 }
426}
427
428pub fn buyback(signer: Pubkey, swap_accounts: &[AccountMeta], swap_data: &[u8]) -> Instruction {
429 let board_address = board_pda().0;
430 let mint_address = MINT_ADDRESS;
431 let treasury_address = TREASURY_ADDRESS;
432 let treasury_oil_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
433 let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
434 let mut accounts = vec![
435 AccountMeta::new(signer, true),
436 AccountMeta::new(board_address, false),
437 AccountMeta::new(mint_address, false),
438 AccountMeta::new(treasury_address, false),
439 AccountMeta::new(treasury_oil_address, false),
440 AccountMeta::new(treasury_sol_address, false),
441 AccountMeta::new_readonly(spl_token::ID, false),
442 AccountMeta::new_readonly(crate::ID, false),
443 ];
444 for account in swap_accounts.iter() {
445 let mut acc_clone = account.clone();
446 acc_clone.is_signer = false;
447 accounts.push(acc_clone);
448 }
449 let mut data = Buyback {}.to_bytes();
450 data.extend_from_slice(swap_data);
451 Instruction {
452 program_id: crate::ID,
453 accounts,
454 data,
455 }
456}
457
458pub fn barrel(signer: Pubkey, amount: u64) -> Instruction {
459 let board_address = board_pda().0;
460 let mint_address = MINT_ADDRESS;
461 let treasury_address = TREASURY_ADDRESS;
462 let sender_oil_address = get_associated_token_address(&signer, &MINT_ADDRESS);
463 let treasury_oil_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
464 let data = Barrel {
465 amount: amount.to_le_bytes(),
466 }
467 .to_bytes();
468 Instruction {
469 program_id: crate::ID,
470 accounts: vec![
471 AccountMeta::new(signer, true),
472 AccountMeta::new(sender_oil_address, false),
473 AccountMeta::new(board_address, false),
474 AccountMeta::new(mint_address, false),
475 AccountMeta::new(treasury_address, false),
476 AccountMeta::new(treasury_oil_address, false),
477 AccountMeta::new_readonly(spl_token::ID, false),
478 AccountMeta::new_readonly(crate::ID, false),
479 ],
480 data,
481 }
482}
483
484
485pub fn reset(
488 signer: Pubkey,
489 fee_collector: Pubkey,
490 round_id: u64,
491 top_miner: Pubkey,
492 var_address: Pubkey,
493) -> Instruction {
494 reset_with_miners(signer, fee_collector, round_id, top_miner, var_address, &[])
495}
496
497pub fn reset_with_miners(
498 signer: Pubkey,
499 fee_collector: Pubkey,
500 round_id: u64,
501 top_miner: Pubkey,
502 var_address: Pubkey,
503 miner_accounts: &[Pubkey],
504) -> Instruction {
505 let board_address = board_pda().0;
506 let config_address = config_pda().0;
507 let mint_address = MINT_ADDRESS;
508 let round_address = round_pda(round_id).0;
509 let round_next_address = round_pda(round_id + 1).0;
510 let top_miner_address = miner_pda(top_miner).0;
511 let treasury_address = TREASURY_ADDRESS;
512 let treasury_tokens_address = treasury_tokens_address();
513 let pool_address = pool_pda().0;
514 let mint_authority_address = oil_mint_api::state::authority_pda().0;
515 let mut reset_instruction = Instruction {
516 program_id: crate::ID,
517 accounts: vec![
518 AccountMeta::new(signer, true),
519 AccountMeta::new(board_address, false),
520 AccountMeta::new(config_address, false),
521 AccountMeta::new(fee_collector, false),
522 AccountMeta::new(mint_address, false),
523 AccountMeta::new(round_address, false),
524 AccountMeta::new(round_next_address, false),
525 AccountMeta::new(top_miner_address, false),
526 AccountMeta::new(treasury_address, false),
527 AccountMeta::new(pool_address, false),
528 AccountMeta::new(treasury_tokens_address, false),
529 AccountMeta::new_readonly(system_program::ID, false),
530 AccountMeta::new_readonly(spl_token::ID, false),
531 AccountMeta::new_readonly(crate::ID, false),
532 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
533 AccountMeta::new_readonly(SOL_MINT, false),
534 AccountMeta::new(var_address, false),
536 AccountMeta::new_readonly(entropy_rng_api::ID, false),
537 AccountMeta::new(mint_authority_address, false),
539 AccountMeta::new_readonly(oil_mint_api::ID, false),
540 ],
541 data: Reset {}.to_bytes(),
542 };
543
544 for miner_pubkey in miner_accounts {
546 reset_instruction.accounts.push(AccountMeta::new(
547 miner_pda(*miner_pubkey).0,
548 false,
549 ));
550 }
551
552 reset_instruction
553}
554
555pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
558 let miner_address = miner_pda(authority).0;
559 let board_address = board_pda().0;
560 let round_address = round_pda(round_id).0;
561 let treasury_address = TREASURY_ADDRESS;
562 Instruction {
563 program_id: crate::ID,
564 accounts: vec![
565 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(board_address, false),
568 AccountMeta::new(miner_address, false),
569 AccountMeta::new(round_address, false),
570 AccountMeta::new(treasury_address, false),
571 AccountMeta::new_readonly(system_program::ID, false),
572 ],
573 data: Checkpoint {}.to_bytes(),
574 }
575}
576
577pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
578 let config_address = config_pda().0;
579 Instruction {
580 program_id: crate::ID,
581 accounts: vec![
582 AccountMeta::new(signer, true),
583 AccountMeta::new(config_address, false),
584 AccountMeta::new_readonly(system_program::ID, false),
585 ],
586 data: SetAdmin {
587 admin: admin.to_bytes(),
588 }
589 .to_bytes(),
590 }
591}
592
593pub fn set_admin_fee(signer: Pubkey, admin_fee: u64) -> Instruction {
594 let config_address = config_pda().0;
595 Instruction {
596 program_id: crate::ID,
597 accounts: vec![
598 AccountMeta::new(signer, true),
599 AccountMeta::new(config_address, false),
600 AccountMeta::new_readonly(system_program::ID, false),
601 ],
602 data: SetAdminFee {
603 admin_fee: admin_fee.to_le_bytes(),
604 }
605 .to_bytes(),
606 }
607}
608
609pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
610 let config_address = config_pda().0;
611 Instruction {
612 program_id: crate::ID,
613 accounts: vec![
614 AccountMeta::new(signer, true),
615 AccountMeta::new(config_address, false),
616 AccountMeta::new_readonly(system_program::ID, false),
617 ],
618 data: SetFeeCollector {
619 fee_collector: fee_collector.to_bytes(),
620 }
621 .to_bytes(),
622 }
623}
624
625pub fn set_tge_timestamp(signer: Pubkey, tge_timestamp: i64) -> Instruction {
630 let config_address = config_pda().0;
631 Instruction {
632 program_id: crate::ID,
633 accounts: vec![
634 AccountMeta::new(signer, true),
635 AccountMeta::new(config_address, false),
636 AccountMeta::new_readonly(system_program::ID, false),
637 ],
638 data: SetTgeTimestamp {
639 tge_timestamp: tge_timestamp.to_le_bytes(),
640 }
641 .to_bytes(),
642 }
643}
644
645pub fn set_auction(
646 signer: Pubkey,
647 halving_period_seconds: u64,
648 last_halving_time: u64,
649 base_mining_rates: [u64; 4],
650 auction_duration_seconds: u64,
651 starting_prices: [u64; 4],
652 _well_id: u64, ) -> Instruction {
654 let config_address = config_pda().0;
655 let auction_address = auction_pda().0;
656
657 Instruction {
658 program_id: crate::ID,
659 accounts: vec![
660 AccountMeta::new(signer, true),
661 AccountMeta::new_readonly(config_address, false),
662 AccountMeta::new(auction_address, false),
663 ],
664 data: SetAuction {
665 halving_period_seconds: halving_period_seconds.to_le_bytes(),
666 last_halving_time: last_halving_time.to_le_bytes(),
667 base_mining_rates: [
668 base_mining_rates[0].to_le_bytes(),
669 base_mining_rates[1].to_le_bytes(),
670 base_mining_rates[2].to_le_bytes(),
671 base_mining_rates[3].to_le_bytes(),
672 ],
673 auction_duration_seconds: auction_duration_seconds.to_le_bytes(),
674 starting_prices: [
675 starting_prices[0].to_le_bytes(),
676 starting_prices[1].to_le_bytes(),
677 starting_prices[2].to_le_bytes(),
678 starting_prices[3].to_le_bytes(),
679 ],
680 well_id: 4u64.to_le_bytes(), }
682 .to_bytes(),
683 }
684}
685
686pub fn deposit(signer: Pubkey, authority: Pubkey, amount: u64, lock_duration_days: u64, stake_id: u64) -> Instruction {
689 let mint_address = MINT_ADDRESS;
690 let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
692 let sender_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
694 let pool_tokens_address = pool_tokens_address();
695 let miner_address = miner_pda(authority).0; Instruction {
697 program_id: crate::ID,
698 accounts: vec![
699 AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new(mint_address, false),
702 AccountMeta::new(sender_address, false),
703 AccountMeta::new(stake_address, false),
704 AccountMeta::new(stake_tokens_address, false),
705 AccountMeta::new(pool_address, false),
706 AccountMeta::new(pool_tokens_address, false),
707 AccountMeta::new(miner_address, false),
708 AccountMeta::new_readonly(system_program::ID, false),
709 AccountMeta::new_readonly(spl_token::ID, false),
710 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
711 ],
712 data: Deposit {
713 amount: amount.to_le_bytes(),
714 lock_duration_days: lock_duration_days.to_le_bytes(),
715 stake_id: stake_id.to_le_bytes(),
716 }
717 .to_bytes(),
718 }
719}
720
721pub fn withdraw(signer: Pubkey, authority: Pubkey, amount: u64, stake_id: u64) -> Instruction {
724 let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
726 let mint_address = MINT_ADDRESS;
727 let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
729 let pool_tokens_address = pool_tokens_address();
730 let miner_address = miner_pda(authority).0; Instruction {
732 program_id: crate::ID,
733 accounts: vec![
734 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(mint_address, false),
737 AccountMeta::new(recipient_address, false),
738 AccountMeta::new(stake_address, false),
739 AccountMeta::new(stake_tokens_address, false),
740 AccountMeta::new(pool_address, false),
741 AccountMeta::new(pool_tokens_address, false),
742 AccountMeta::new(miner_address, false),
743 AccountMeta::new_readonly(system_program::ID, false),
744 AccountMeta::new_readonly(spl_token::ID, false),
745 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
746 ],
747 data: Withdraw {
748 amount: amount.to_le_bytes(),
749 stake_id: stake_id.to_le_bytes(),
750 }
751 .to_bytes(),
752 }
753}
754
755pub fn reload_sol(
765 signer: Pubkey,
766 authority: Pubkey,
767 referrer_miner: Option<Pubkey>,
768 referrer_referral: Option<Pubkey>,
769) -> Instruction {
770 let automation_address = automation_pda(authority).0;
771 let miner_address = miner_pda(authority).0;
772
773 let mut accounts = vec![
774 AccountMeta::new(signer, true),
775 AccountMeta::new(automation_address, false),
776 AccountMeta::new(miner_address, false),
777 AccountMeta::new_readonly(system_program::ID, false),
778 ];
779
780 if let (Some(miner_ref), Some(referral_ref)) = (referrer_miner, referrer_referral) {
782 accounts.push(AccountMeta::new(miner_ref, false));
783 accounts.push(AccountMeta::new(referral_ref, false));
784 }
785
786 Instruction {
787 program_id: crate::ID,
788 accounts,
789 data: ReloadSOL {}.to_bytes(),
790 }
791}
792
793pub fn claim_yield(signer: Pubkey, authority: Pubkey, amount: u64, stake_id: u64) -> Instruction {
797 let stake_address = stake_pda_with_id(authority, stake_id).0; let pool_address = pool_pda().0;
799 Instruction {
800 program_id: crate::ID,
801 accounts: vec![
802 AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new(stake_address, false),
805 AccountMeta::new(pool_address, false),
806 AccountMeta::new_readonly(system_program::ID, false),
807 ],
808 data: ClaimYield {
809 amount: amount.to_le_bytes(),
810 }
811 .to_bytes(),
812 }
813}
814
815pub fn new_var(
816 signer: Pubkey,
817 provider: Pubkey,
818 id: u64,
819 commit: [u8; 32],
820 samples: u64,
821) -> Instruction {
822 let board_address = board_pda().0;
823 let config_address = config_pda().0;
824 let var_address = entropy_rng_api::state::var_pda(board_address, id).0;
825 Instruction {
826 program_id: crate::ID,
827 accounts: vec![
828 AccountMeta::new(signer, true),
829 AccountMeta::new(board_address, false),
830 AccountMeta::new(config_address, false),
831 AccountMeta::new(provider, false),
832 AccountMeta::new(var_address, false),
833 AccountMeta::new_readonly(system_program::ID, false),
834 AccountMeta::new_readonly(entropy_rng_api::ID, false),
835 ],
836 data: NewVar {
837 id: id.to_le_bytes(),
838 commit: commit,
839 samples: samples.to_le_bytes(),
840 }
841 .to_bytes(),
842 }
843}
844
845pub fn set_swap_program(signer: Pubkey, new_program: Pubkey) -> Instruction {
846 let config_address = config_pda().0;
847 Instruction {
848 program_id: crate::ID,
849 accounts: vec![
850 AccountMeta::new(signer, true),
851 AccountMeta::new(config_address, false),
852 AccountMeta::new_readonly(new_program, false),
853 ],
854 data: SetSwapProgram {}.to_bytes(),
855 }
856}
857
858pub fn set_var_address(signer: Pubkey, new_var_address: Pubkey) -> Instruction {
859 let board_address = board_pda().0;
860 let config_address = config_pda().0;
861 Instruction {
862 program_id: crate::ID,
863 accounts: vec![
864 AccountMeta::new(signer, true),
865 AccountMeta::new(board_address, false),
866 AccountMeta::new(config_address, false),
867 AccountMeta::new(new_var_address, false),
868 ],
869 data: SetVarAddress {}.to_bytes(),
870 }
871}
872
873pub fn migrate(signer: Pubkey) -> Instruction {
878 let config_address = config_pda().0;
879 let treasury_address = treasury_pda().0;
880 Instruction {
881 program_id: crate::ID,
882 accounts: vec![
883 AccountMeta::new(signer, true),
884 AccountMeta::new(config_address, false),
885 AccountMeta::new(treasury_address, false),
886 AccountMeta::new_readonly(system_program::ID, false),
887 ],
888 data: Migrate {}.to_bytes(),
889 }
890}
891
892pub fn create_referral(signer: Pubkey) -> Instruction {
894 let referral_address = referral_pda(signer).0;
895 Instruction {
896 program_id: crate::ID,
897 accounts: vec![
898 AccountMeta::new(signer, true),
899 AccountMeta::new(referral_address, false),
900 AccountMeta::new_readonly(system_program::ID, false),
901 ],
902 data: CreateReferral {}.to_bytes(),
903 }
904}
905
906pub fn create_whitelist(
910 signer: Pubkey,
911 code_hash: [u8; 32],
912) -> Instruction {
913 let config_address = config_pda().0;
914 let (whitelist_address, _) = Whitelist::pda(code_hash);
915 Instruction {
916 program_id: crate::ID,
917 accounts: vec![
918 AccountMeta::new(signer, true), AccountMeta::new_readonly(config_address, false), AccountMeta::new(whitelist_address, false), AccountMeta::new_readonly(system_program::ID, false), ],
923 data: CreateWhitelist {
924 code_hash,
925 }
926 .to_bytes(),
927 }
928}
929
930pub fn claim_referral(signer: Pubkey, authority: Pubkey) -> Instruction {
935 let referral_address = referral_pda(authority).0;
936 let referral_oil_address = get_associated_token_address(&referral_address, &MINT_ADDRESS);
937 let recipient_oil_address = get_associated_token_address(&authority, &MINT_ADDRESS);
938 Instruction {
939 program_id: crate::ID,
940 accounts: vec![
941 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), ],
951 data: ClaimReferral {}.to_bytes(),
952 }
953}
954
955pub fn place_bid(
964 signer: Pubkey,
965 authority: Pubkey,
966 square_id: u64,
967 fee_collector: Pubkey,
968 previous_owner_miner: Option<Pubkey>, previous_owner: Option<Pubkey>, referrer: Option<Pubkey>, ) -> Instruction {
972 let well_address = well_pda(square_id).0;
973 let auction_address = auction_pda().0;
974 let treasury_address = treasury_pda().0;
975 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
976 let staking_pool_address = pool_pda().0;
977 let config_address = config_pda().0;
978 let mint_authority_address = oil_mint_api::state::authority_pda().0;
979 let bidder_miner_address = miner_pda(authority).0;
980
981 let mut accounts = vec![
982 AccountMeta::new(signer, true), AccountMeta::new(authority, false), ];
985
986 accounts.extend_from_slice(&[
990 AccountMeta::new(well_address, false), AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
993 AccountMeta::new(treasury_tokens_address, false),
994 AccountMeta::new(MINT_ADDRESS, false),
995 AccountMeta::new(mint_authority_address, false),
996 AccountMeta::new_readonly(oil_mint_api::ID, false),
997 AccountMeta::new(staking_pool_address, false),
998 AccountMeta::new(fee_collector, false),
999 AccountMeta::new_readonly(config_address, false),
1000 AccountMeta::new_readonly(spl_token::ID, false),
1001 AccountMeta::new_readonly(system_program::ID, false),
1002 AccountMeta::new_readonly(crate::ID, false), AccountMeta::new(bidder_miner_address, false), ]);
1005
1006 if let (Some(miner_pubkey), Some(owner_pubkey)) = (previous_owner_miner, previous_owner) {
1008 accounts.push(AccountMeta::new(miner_pubkey, false)); accounts.push(AccountMeta::new(owner_pubkey, false)); }
1011
1012 if let Some(referrer_pubkey) = referrer {
1014 let referral_address = referral_pda(referrer_pubkey).0;
1015 accounts.push(AccountMeta::new(referral_address, false)); }
1017
1018 Instruction {
1025 program_id: crate::ID,
1026 accounts,
1027 data: instruction::PlaceBid {
1028 square_id: square_id.to_le_bytes(),
1029 referrer: referrer.unwrap_or(Pubkey::default()).to_bytes(),
1030 }
1031 .to_bytes(),
1032 }
1033}
1034
1035pub fn claim_auction_oil(
1042 signer: Pubkey,
1043 well_mask: u8, well_accounts: [Option<Pubkey>; 4], auction_pool_accounts: Option<[Option<Pubkey>; 4]>, bid_accounts: Option<[Option<Pubkey>; 4]>, ) -> Instruction {
1048 let miner_address = miner_pda(signer).0;
1049 let auction_address = auction_pda().0;
1050 let treasury_address = treasury_pda().0;
1051 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
1052 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
1053 let mint_authority_address = oil_mint_api::state::authority_pda().0;
1054
1055 let mut accounts = vec![
1056 AccountMeta::new(signer, true),
1057 AccountMeta::new(miner_address, false),
1058 ];
1059
1060 for well_opt in well_accounts.iter() {
1062 if let Some(well_pubkey) = well_opt {
1063 accounts.push(AccountMeta::new(*well_pubkey, false));
1064 } else {
1065 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1067 }
1068 }
1069
1070 if let Some(auction_pool_pdas) = auction_pool_accounts {
1072 for auction_pool_pda_opt in auction_pool_pdas.iter() {
1073 if let Some(auction_pool_pubkey) = auction_pool_pda_opt {
1074 accounts.push(AccountMeta::new(*auction_pool_pubkey, false));
1075 } else {
1076 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1078 }
1079 }
1080 } else {
1081 for _ in 0..4 {
1083 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1084 }
1085 }
1086
1087 accounts.extend_from_slice(&[
1088 AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
1090 AccountMeta::new(treasury_tokens_address, false),
1091 AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(mint_authority_address, false), AccountMeta::new_readonly(oil_mint_api::ID, false),
1094 AccountMeta::new(recipient_address, false),
1095 AccountMeta::new_readonly(spl_token::ID, false),
1096 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
1097 AccountMeta::new_readonly(system_program::ID, false),
1098 AccountMeta::new_readonly(crate::ID, false), ]);
1100
1101 if let Some(bid_pdas) = bid_accounts {
1103 for bid_pda_opt in bid_pdas.iter() {
1104 if let Some(bid_pubkey) = bid_pda_opt {
1105 accounts.push(AccountMeta::new(*bid_pubkey, false));
1106 }
1107 }
1108 }
1109
1110 Instruction {
1111 program_id: crate::ID,
1112 accounts,
1113 data: ClaimAuctionOIL {
1114 well_mask,
1115 }
1116 .to_bytes(),
1117 }
1118}
1119
1120pub fn claim_auction_sol(
1127 signer: Pubkey,
1128 well_accounts: [Option<Pubkey>; 4], auction_pool_accounts: Option<[Option<Pubkey>; 4]>, bid_accounts: Option<[Option<Pubkey>; 4]>, ) -> Instruction {
1132 let miner_address = miner_pda(signer).0;
1133 let (auction_address, _) = auction_pda();
1134 let treasury_address = treasury_pda().0;
1135
1136 let mut accounts = vec![
1137 AccountMeta::new(signer, true),
1138 AccountMeta::new(miner_address, false),
1139 ];
1140
1141 for well_opt in well_accounts.iter() {
1143 if let Some(well_pubkey) = well_opt {
1144 accounts.push(AccountMeta::new(*well_pubkey, false));
1145 } else {
1146 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1148 }
1149 }
1150
1151 if let Some(auction_pool_pdas) = auction_pool_accounts {
1153 for auction_pool_pda_opt in auction_pool_pdas.iter() {
1154 if let Some(auction_pool_pubkey) = auction_pool_pda_opt {
1155 accounts.push(AccountMeta::new(*auction_pool_pubkey, false));
1156 } else {
1157 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1159 }
1160 }
1161 } else {
1162 for _ in 0..4 {
1164 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1165 }
1166 }
1167
1168 accounts.extend_from_slice(&[
1169 AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
1171 AccountMeta::new_readonly(system_program::ID, false),
1172 AccountMeta::new_readonly(crate::ID, false), ]);
1174
1175 if let Some(bid_pdas) = bid_accounts {
1177 for bid_pda_opt in bid_pdas.iter() {
1178 if let Some(bid_pubkey) = bid_pda_opt {
1179 accounts.push(AccountMeta::new(*bid_pubkey, false));
1180 }
1181 }
1182 }
1183
1184 Instruction {
1185 program_id: crate::ID,
1186 accounts,
1187 data: ClaimAuctionSOL {
1188 _reserved: 0,
1189 }
1190 .to_bytes(),
1191 }
1192}
1193
1194pub fn claim_seeker(signer: Pubkey, mint: Pubkey) -> Instruction {
1195 let seeker_address = seeker_pda(mint).0;
1196 let token_account_address = get_associated_token_address(&signer, &mint);
1197 Instruction {
1198 program_id: crate::ID,
1199 accounts: vec![
1200 AccountMeta::new(signer, true),
1201 AccountMeta::new_readonly(mint, false),
1202 AccountMeta::new(seeker_address, false),
1203 AccountMeta::new(token_account_address, false),
1204 AccountMeta::new_readonly(system_program::ID, false),
1205 ],
1206 data: ClaimSeeker {}.to_bytes(),
1207 }
1208}