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 amount: u64,
80 deposit: u64,
81 executor: Pubkey,
82 fee: u64,
83 mask: u64,
84 strategy: u8,
85 reload: bool,
86 referrer: Option<Pubkey>,
87 pooled: bool,
88 is_new_miner: bool,
89) -> Instruction {
90 let automation_address = automation_pda(signer).0;
91 let miner_address = miner_pda(signer).0;
92 let referrer_pk = referrer.unwrap_or(Pubkey::default());
93
94 let mut accounts = vec![
95 AccountMeta::new(signer, true),
96 AccountMeta::new(automation_address, false),
97 AccountMeta::new(executor, false),
98 AccountMeta::new(miner_address, false),
99 AccountMeta::new_readonly(system_program::ID, false),
100 ];
101
102 if is_new_miner && referrer.is_some() && referrer_pk != Pubkey::default() {
104 let referral_address = referral_pda(referrer_pk).0;
105 accounts.push(AccountMeta::new(referral_address, false));
106 }
107
108 Instruction {
109 program_id: crate::ID,
110 accounts,
111 data: Automate {
112 amount: amount.to_le_bytes(),
113 deposit: deposit.to_le_bytes(),
114 fee: fee.to_le_bytes(),
115 mask: mask.to_le_bytes(),
116 strategy: strategy as u8,
117 reload: (reload as u64).to_le_bytes(),
118 referrer: referrer_pk.to_bytes(),
119 pooled: pooled as u8,
120 }
121 .to_bytes(),
122 }
123}
124
125pub fn claim_sol(
133 signer: Pubkey,
134 referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, ) -> Instruction {
137 let miner_address = miner_pda(signer).0;
138
139 let mut accounts = vec![
140 AccountMeta::new(signer, true),
141 AccountMeta::new(miner_address, false),
142 AccountMeta::new_readonly(system_program::ID, false),
143 ];
144
145 if let (Some(miner_pubkey), Some(referral_pubkey)) = (referrer_miner, referrer_referral) {
147 accounts.push(AccountMeta::new(miner_pubkey, false));
148 accounts.push(AccountMeta::new(referral_pubkey, false));
149 }
150
151 Instruction {
152 program_id: crate::ID,
153 accounts,
154 data: ClaimSOL {}.to_bytes(),
155 }
156}
157
158pub fn claim_oil(
168 signer: Pubkey,
169 referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, referrer_referral_oil_ata: Option<Pubkey>, ) -> Instruction {
173 let miner_address = miner_pda(signer).0;
174 let treasury_address = treasury_pda().0;
175 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
176 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
177
178 let mut accounts = vec![
179 AccountMeta::new(signer, true),
180 AccountMeta::new(miner_address, false),
181 AccountMeta::new(MINT_ADDRESS, false),
182 AccountMeta::new(recipient_address, false),
183 AccountMeta::new(treasury_address, false),
184 AccountMeta::new(treasury_tokens_address, false),
185 AccountMeta::new_readonly(system_program::ID, false),
186 AccountMeta::new_readonly(spl_token::ID, false),
187 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
188 ];
189
190 if let (Some(miner_pubkey), Some(referral_pubkey), Some(oil_ata_pubkey)) =
192 (referrer_miner, referrer_referral, referrer_referral_oil_ata) {
193 accounts.push(AccountMeta::new(miner_pubkey, false));
194 accounts.push(AccountMeta::new(referral_pubkey, false));
195 accounts.push(AccountMeta::new(oil_ata_pubkey, false));
196 }
197
198 Instruction {
199 program_id: crate::ID,
200 accounts,
201 data: ClaimOIL {}.to_bytes(),
202 }
203}
204
205
206pub fn close(signer: Pubkey, round_id: u64, rent_payer: Pubkey) -> Instruction {
207 let board_address = board_pda().0;
208 let round_address = round_pda(round_id).0;
209 let treasury_address = TREASURY_ADDRESS;
210 Instruction {
211 program_id: crate::ID,
212 accounts: vec![
213 AccountMeta::new(signer, true),
214 AccountMeta::new(board_address, false),
215 AccountMeta::new(rent_payer, false),
216 AccountMeta::new(round_address, false),
217 AccountMeta::new(treasury_address, false),
218 AccountMeta::new_readonly(system_program::ID, false),
219 ],
220 data: Close {}.to_bytes(),
221 }
222}
223
224pub fn deploy(
227 signer: Pubkey,
228 authority: Pubkey,
229 amount: u64,
230 round_id: u64,
231 squares: [bool; 25],
232 referrer: Option<Pubkey>,
233 pooled: bool,
234 access_code_hash: Option<[u8; 32]>,
235) -> Instruction {
236 let automation_address = automation_pda(authority).0;
237 let board_address = board_pda().0;
238 let config_address = config_pda().0;
239 let miner_address = miner_pda(authority).0;
240 let round_address = round_pda(round_id).0;
241 let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
242
243 let mut mask: u32 = 0;
246 for (i, &square) in squares.iter().enumerate() {
247 if square {
248 mask |= 1 << i;
249 }
250 }
251
252 let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
254 let referrer_bytes = referrer_pubkey.to_bytes();
255
256 let user_wrapped_sol_ata = get_associated_token_address(&authority, &SOL_MINT);
258 let round_wrapped_sol_ata = get_associated_token_address(&round_address, &SOL_MINT);
259
260 let mut accounts = vec![
264 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), ];
281
282 if referrer_pubkey != Pubkey::default() {
284 let referral_address = referral_pda(referrer_pubkey).0;
285 accounts.push(AccountMeta::new(referral_address, false)); }
287
288 let access_code_hash_bytes = access_code_hash.unwrap_or([0; 32]);
290 if access_code_hash_bytes != [0; 32] {
291 let (code_address, _) = Code::pda(access_code_hash_bytes, authority);
292 accounts.push(AccountMeta::new(code_address, false)); }
294
295 accounts.push(AccountMeta::new(entropy_var_address, false)); accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false)); Instruction {
300 program_id: crate::ID,
301 accounts,
302 data: Deploy {
303 amount: amount.to_le_bytes(),
304 squares: mask.to_le_bytes(),
305 referrer: referrer_bytes,
306 pooled: if pooled { 1 } else { 0 },
307 access_code_hash: access_code_hash_bytes,
308 }
309 .to_bytes(),
310 }
311}
312
313pub fn deploy_auto(
316 signer: Pubkey,
317 authority: Pubkey,
318 amount: u64,
319 round_id: u64,
320 squares: [bool; 25],
321 referrer: Option<Pubkey>,
322 pooled: bool,
323 access_code_hash: Option<[u8; 32]>,
324) -> Instruction {
325 let automation_address = automation_pda(authority).0;
326 let board_address = board_pda().0;
327 let config_address = config_pda().0;
328 let miner_address = miner_pda(authority).0;
329 let round_address = round_pda(round_id).0;
330 let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
331
332 let mut mask: u32 = 0;
335 for (i, &square) in squares.iter().enumerate() {
336 if square {
337 mask |= 1 << i;
338 }
339 }
340
341 let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
343 let referrer_bytes = referrer_pubkey.to_bytes();
344
345 let mut accounts = vec![
350 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), ];
365
366 if referrer_pubkey != Pubkey::default() {
368 let referral_address = referral_pda(referrer_pubkey).0;
369 accounts.push(AccountMeta::new(referral_address, false)); }
371
372 let access_code_hash_bytes = access_code_hash.unwrap_or([0; 32]);
374 if access_code_hash_bytes != [0; 32] {
375 let (code_address, _) = Code::pda(access_code_hash_bytes, authority);
376 accounts.push(AccountMeta::new(code_address, false)); }
378
379 accounts.push(AccountMeta::new(entropy_var_address, false)); accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false)); Instruction {
384 program_id: crate::ID,
385 accounts,
386 data: Deploy {
387 amount: amount.to_le_bytes(),
388 squares: mask.to_le_bytes(),
389 referrer: referrer_bytes,
390 pooled: if pooled { 1 } else { 0 },
391 access_code_hash: access_code_hash_bytes,
392 }
393 .to_bytes(),
394 }
395}
396
397pub fn buyback(signer: Pubkey, swap_accounts: &[AccountMeta], swap_data: &[u8]) -> Instruction {
400 let board_address = board_pda().0;
401 let config_address = config_pda().0;
402 let mint_address = MINT_ADDRESS;
403 let treasury_address = TREASURY_ADDRESS;
404 let treasury_oil_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
405 let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
406 let mut accounts = vec![
407 AccountMeta::new(signer, true),
408 AccountMeta::new(board_address, false),
409 AccountMeta::new_readonly(config_address, false),
410 AccountMeta::new(mint_address, false),
411 AccountMeta::new(treasury_address, false),
412 AccountMeta::new(treasury_oil_address, false),
413 AccountMeta::new(treasury_sol_address, false),
414 AccountMeta::new_readonly(spl_token::ID, false),
415 AccountMeta::new_readonly(crate::ID, false),
416 ];
417 for account in swap_accounts.iter() {
418 let mut acc_clone = account.clone();
419 acc_clone.is_signer = false;
420 accounts.push(acc_clone);
421 }
422 let mut data = Buyback {}.to_bytes();
423 data.extend_from_slice(swap_data);
424 Instruction {
425 program_id: crate::ID,
426 accounts,
427 data,
428 }
429}
430
431pub fn reset(
434 signer: Pubkey,
435 fee_collector: Pubkey,
436 round_id: u64,
437 top_miner: Pubkey,
438 var_address: Pubkey,
439) -> Instruction {
440 reset_with_miners(signer, fee_collector, round_id, top_miner, var_address, &[])
441}
442
443pub fn reset_with_miners(
444 signer: Pubkey,
445 fee_collector: Pubkey,
446 round_id: u64,
447 top_miner: Pubkey,
448 var_address: Pubkey,
449 miner_accounts: &[Pubkey],
450) -> Instruction {
451 let board_address = board_pda().0;
452 let config_address = config_pda().0;
453 let mint_address = MINT_ADDRESS;
454 let round_address = round_pda(round_id).0;
455 let round_next_address = round_pda(round_id + 1).0;
456 let top_miner_address = miner_pda(top_miner).0;
457 let treasury_address = TREASURY_ADDRESS;
458 let treasury_tokens_address = treasury_tokens_address();
459 let pool_address = pool_pda().0;
460 let mint_authority_address = oil_mint_api::state::authority_pda().0;
461 let mut reset_instruction = Instruction {
462 program_id: crate::ID,
463 accounts: vec![
464 AccountMeta::new(signer, true),
465 AccountMeta::new(board_address, false),
466 AccountMeta::new(config_address, false),
467 AccountMeta::new(fee_collector, false),
468 AccountMeta::new(mint_address, false),
469 AccountMeta::new(round_address, false),
470 AccountMeta::new(round_next_address, false),
471 AccountMeta::new(top_miner_address, false),
472 AccountMeta::new(treasury_address, false),
473 AccountMeta::new(pool_address, false),
474 AccountMeta::new(treasury_tokens_address, false),
475 AccountMeta::new_readonly(system_program::ID, false),
476 AccountMeta::new_readonly(spl_token::ID, false),
477 AccountMeta::new_readonly(crate::ID, false),
478 AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
479 AccountMeta::new_readonly(SOL_MINT, false),
480 AccountMeta::new(var_address, false),
482 AccountMeta::new_readonly(entropy_rng_api::ID, false),
483 AccountMeta::new(mint_authority_address, false),
485 AccountMeta::new_readonly(oil_mint_api::ID, false),
486 ],
487 data: Reset {}.to_bytes(),
488 };
489
490 for miner_pubkey in miner_accounts {
492 reset_instruction.accounts.push(AccountMeta::new(
493 miner_pda(*miner_pubkey).0,
494 false,
495 ));
496 }
497
498 reset_instruction
499}
500
501pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
504 let miner_address = miner_pda(authority).0;
505 let board_address = board_pda().0;
506 let round_address = round_pda(round_id).0;
507 let treasury_address = TREASURY_ADDRESS;
508 Instruction {
509 program_id: crate::ID,
510 accounts: vec![
511 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(board_address, false),
514 AccountMeta::new(miner_address, false),
515 AccountMeta::new(round_address, false),
516 AccountMeta::new(treasury_address, false),
517 AccountMeta::new_readonly(system_program::ID, false),
518 ],
519 data: Checkpoint {}.to_bytes(),
520 }
521}
522
523pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
524 let config_address = config_pda().0;
525 Instruction {
526 program_id: crate::ID,
527 accounts: vec![
528 AccountMeta::new(signer, true),
529 AccountMeta::new(config_address, false),
530 AccountMeta::new_readonly(system_program::ID, false),
531 ],
532 data: SetAdmin {
533 admin: admin.to_bytes(),
534 }
535 .to_bytes(),
536 }
537}
538
539pub fn set_admin_fee(signer: Pubkey, admin_fee: u64) -> Instruction {
540 let config_address = config_pda().0;
541 Instruction {
542 program_id: crate::ID,
543 accounts: vec![
544 AccountMeta::new(signer, true),
545 AccountMeta::new(config_address, false),
546 AccountMeta::new_readonly(system_program::ID, false),
547 ],
548 data: SetAdminFee {
549 admin_fee: admin_fee.to_le_bytes(),
550 }
551 .to_bytes(),
552 }
553}
554
555pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
556 let config_address = config_pda().0;
557 Instruction {
558 program_id: crate::ID,
559 accounts: vec![
560 AccountMeta::new(signer, true),
561 AccountMeta::new(config_address, false),
562 AccountMeta::new_readonly(system_program::ID, false),
563 ],
564 data: SetFeeCollector {
565 fee_collector: fee_collector.to_bytes(),
566 }
567 .to_bytes(),
568 }
569}
570
571pub fn set_tge_timestamp(signer: Pubkey, tge_timestamp: i64) -> Instruction {
576 let config_address = config_pda().0;
577 Instruction {
578 program_id: crate::ID,
579 accounts: vec![
580 AccountMeta::new(signer, true),
581 AccountMeta::new(config_address, false),
582 AccountMeta::new_readonly(system_program::ID, false),
583 ],
584 data: SetTgeTimestamp {
585 tge_timestamp: tge_timestamp.to_le_bytes(),
586 }
587 .to_bytes(),
588 }
589}
590
591pub fn set_auction(
592 signer: Pubkey,
593 halving_period_seconds: u64,
594 last_halving_time: u64,
595 base_mining_rates: [u64; 4],
596 auction_duration_seconds: u64,
597 starting_prices: [u64; 4],
598 _well_id: u64, ) -> Instruction {
600 let config_address = config_pda().0;
601 let auction_address = auction_pda().0;
602
603 Instruction {
604 program_id: crate::ID,
605 accounts: vec![
606 AccountMeta::new(signer, true),
607 AccountMeta::new_readonly(config_address, false),
608 AccountMeta::new(auction_address, false),
609 ],
610 data: SetAuction {
611 halving_period_seconds: halving_period_seconds.to_le_bytes(),
612 last_halving_time: last_halving_time.to_le_bytes(),
613 base_mining_rates: [
614 base_mining_rates[0].to_le_bytes(),
615 base_mining_rates[1].to_le_bytes(),
616 base_mining_rates[2].to_le_bytes(),
617 base_mining_rates[3].to_le_bytes(),
618 ],
619 auction_duration_seconds: auction_duration_seconds.to_le_bytes(),
620 starting_prices: [
621 starting_prices[0].to_le_bytes(),
622 starting_prices[1].to_le_bytes(),
623 starting_prices[2].to_le_bytes(),
624 starting_prices[3].to_le_bytes(),
625 ],
626 well_id: 4u64.to_le_bytes(), }
628 .to_bytes(),
629 }
630}
631
632pub fn deposit(signer: Pubkey, authority: Pubkey, amount: u64, lock_duration_days: u64, stake_id: u64) -> Instruction {
635 let mint_address = MINT_ADDRESS;
636 let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
638 let sender_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
640 let pool_tokens_address = pool_tokens_address();
641 let miner_address = miner_pda(authority).0; Instruction {
643 program_id: crate::ID,
644 accounts: vec![
645 AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new(mint_address, false),
648 AccountMeta::new(sender_address, false),
649 AccountMeta::new(stake_address, false),
650 AccountMeta::new(stake_tokens_address, false),
651 AccountMeta::new(pool_address, false),
652 AccountMeta::new(pool_tokens_address, false),
653 AccountMeta::new(miner_address, false),
654 AccountMeta::new_readonly(system_program::ID, false),
655 AccountMeta::new_readonly(spl_token::ID, false),
656 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
657 ],
658 data: Deposit {
659 amount: amount.to_le_bytes(),
660 lock_duration_days: lock_duration_days.to_le_bytes(),
661 stake_id: stake_id.to_le_bytes(),
662 }
663 .to_bytes(),
664 }
665}
666
667pub fn withdraw(signer: Pubkey, authority: Pubkey, amount: u64, stake_id: u64) -> Instruction {
670 let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
672 let mint_address = MINT_ADDRESS;
673 let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
675 let pool_tokens_address = pool_tokens_address();
676 let miner_address = miner_pda(authority).0; Instruction {
678 program_id: crate::ID,
679 accounts: vec![
680 AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(mint_address, false),
683 AccountMeta::new(recipient_address, false),
684 AccountMeta::new(stake_address, false),
685 AccountMeta::new(stake_tokens_address, false),
686 AccountMeta::new(pool_address, false),
687 AccountMeta::new(pool_tokens_address, false),
688 AccountMeta::new(miner_address, false),
689 AccountMeta::new_readonly(system_program::ID, false),
690 AccountMeta::new_readonly(spl_token::ID, false),
691 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
692 ],
693 data: Withdraw {
694 amount: amount.to_le_bytes(),
695 stake_id: stake_id.to_le_bytes(),
696 }
697 .to_bytes(),
698 }
699}
700
701pub fn reload_sol(
711 signer: Pubkey,
712 authority: Pubkey,
713 referrer_miner: Option<Pubkey>,
714 referrer_referral: Option<Pubkey>,
715) -> Instruction {
716 let automation_address = automation_pda(authority).0;
717 let miner_address = miner_pda(authority).0;
718
719 let mut accounts = vec![
720 AccountMeta::new(signer, true),
721 AccountMeta::new(automation_address, false),
722 AccountMeta::new(miner_address, false),
723 AccountMeta::new_readonly(system_program::ID, false),
724 ];
725
726 if let (Some(miner_ref), Some(referral_ref)) = (referrer_miner, referrer_referral) {
728 accounts.push(AccountMeta::new(miner_ref, false));
729 accounts.push(AccountMeta::new(referral_ref, false));
730 }
731
732 Instruction {
733 program_id: crate::ID,
734 accounts,
735 data: ReloadSOL {}.to_bytes(),
736 }
737}
738
739pub fn claim_yield(signer: Pubkey, authority: Pubkey, amount: u64, stake_id: u64) -> Instruction {
743 let stake_address = stake_pda_with_id(authority, stake_id).0; let pool_address = pool_pda().0;
745 Instruction {
746 program_id: crate::ID,
747 accounts: vec![
748 AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new(stake_address, false),
751 AccountMeta::new(pool_address, false),
752 AccountMeta::new_readonly(system_program::ID, false),
753 ],
754 data: ClaimYield {
755 amount: amount.to_le_bytes(),
756 }
757 .to_bytes(),
758 }
759}
760
761pub fn new_var(
762 signer: Pubkey,
763 provider: Pubkey,
764 id: u64,
765 commit: [u8; 32],
766 samples: u64,
767) -> Instruction {
768 let board_address = board_pda().0;
769 let config_address = config_pda().0;
770 let var_address = entropy_rng_api::state::var_pda(board_address, id).0;
771 Instruction {
772 program_id: crate::ID,
773 accounts: vec![
774 AccountMeta::new(signer, true),
775 AccountMeta::new(board_address, false),
776 AccountMeta::new(config_address, false),
777 AccountMeta::new(provider, false),
778 AccountMeta::new(var_address, false),
779 AccountMeta::new_readonly(system_program::ID, false),
780 AccountMeta::new_readonly(entropy_rng_api::ID, false),
781 ],
782 data: NewVar {
783 id: id.to_le_bytes(),
784 commit: commit,
785 samples: samples.to_le_bytes(),
786 }
787 .to_bytes(),
788 }
789}
790
791pub fn set_swap_program(signer: Pubkey, new_program: Pubkey) -> Instruction {
792 let config_address = config_pda().0;
793 Instruction {
794 program_id: crate::ID,
795 accounts: vec![
796 AccountMeta::new(signer, true),
797 AccountMeta::new(config_address, false),
798 AccountMeta::new_readonly(new_program, false),
799 ],
800 data: SetSwapProgram {}.to_bytes(),
801 }
802}
803
804pub fn set_var_address(signer: Pubkey, new_var_address: Pubkey) -> Instruction {
805 let board_address = board_pda().0;
806 let config_address = config_pda().0;
807 Instruction {
808 program_id: crate::ID,
809 accounts: vec![
810 AccountMeta::new(signer, true),
811 AccountMeta::new(board_address, false),
812 AccountMeta::new(config_address, false),
813 AccountMeta::new(new_var_address, false),
814 ],
815 data: SetVarAddress {}.to_bytes(),
816 }
817}
818
819pub fn migrate(signer: Pubkey) -> Instruction {
824 let config_address = config_pda().0;
825 Instruction {
826 program_id: crate::ID,
827 accounts: vec![
828 AccountMeta::new(signer, true),
829 AccountMeta::new(config_address, false),
830 AccountMeta::new_readonly(system_program::ID, false),
831 ],
832 data: Migrate {}.to_bytes(),
833 }
834}
835
836pub fn create_referral(signer: Pubkey) -> Instruction {
838 let referral_address = referral_pda(signer).0;
839 Instruction {
840 program_id: crate::ID,
841 accounts: vec![
842 AccountMeta::new(signer, true),
843 AccountMeta::new(referral_address, false),
844 AccountMeta::new_readonly(system_program::ID, false),
845 ],
846 data: CreateReferral {}.to_bytes(),
847 }
848}
849
850pub fn create_code(
854 signer: Pubkey,
855 code_hash: [u8; 32],
856 authority: Pubkey,
857) -> Instruction {
858 let config_address = config_pda().0;
859 let (code_address, _) = Code::pda(code_hash, authority);
860 Instruction {
861 program_id: crate::ID,
862 accounts: vec![
863 AccountMeta::new(signer, true), AccountMeta::new_readonly(config_address, false), AccountMeta::new(code_address, false), AccountMeta::new_readonly(system_program::ID, false), ],
868 data: CreateCode {
869 code_hash,
870 authority: authority.to_bytes(),
871 }
872 .to_bytes(),
873 }
874}
875
876pub fn claim_referral(signer: Pubkey, authority: Pubkey) -> Instruction {
881 let referral_address = referral_pda(authority).0;
882 let referral_oil_address = get_associated_token_address(&referral_address, &MINT_ADDRESS);
883 let recipient_oil_address = get_associated_token_address(&authority, &MINT_ADDRESS);
884 Instruction {
885 program_id: crate::ID,
886 accounts: vec![
887 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), ],
897 data: ClaimReferral {}.to_bytes(),
898 }
899}
900
901pub fn place_bid(
909 signer: Pubkey,
910 square_id: u64,
911 fee_collector: Pubkey,
912 pool_account: Option<Pubkey>, previous_owner_miner: Option<Pubkey>, previous_owner: Option<Pubkey>, referrer: Option<Pubkey>, ) -> Instruction {
917 let well_address = well_pda(square_id).0;
918 let auction_address = auction_pda().0;
919 let treasury_address = treasury_pda().0;
920 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
921 let staking_pool_address = pool_pda().0;
922 let config_address = config_pda().0;
923 let mint_authority_address = oil_mint_api::state::authority_pda().0;
924
925 let mut accounts = vec![
926 AccountMeta::new(signer, true),
927 AccountMeta::new(well_address, false),
928 ];
929
930 if let Some(pool_pubkey) = pool_account {
932 accounts.push(AccountMeta::new(pool_pubkey, false));
933 } else {
934 accounts.push(AccountMeta::new_readonly(system_program::ID, false)); }
937
938 accounts.extend_from_slice(&[
939 AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
941 AccountMeta::new(treasury_tokens_address, false),
942 AccountMeta::new(MINT_ADDRESS, false),
943 AccountMeta::new(mint_authority_address, false),
944 AccountMeta::new_readonly(oil_mint_api::ID, false),
945 AccountMeta::new(staking_pool_address, false),
946 AccountMeta::new(fee_collector, false),
947 AccountMeta::new(config_address, false),
948 AccountMeta::new_readonly(spl_token::ID, false),
949 AccountMeta::new_readonly(system_program::ID, false),
950 AccountMeta::new_readonly(crate::ID, false), ]);
952
953 if let (Some(miner_pubkey), Some(owner_pubkey)) = (previous_owner_miner, previous_owner) {
955 accounts.push(AccountMeta::new(miner_pubkey, false));
956 accounts.push(AccountMeta::new(owner_pubkey, false));
957 }
958
959 if let Some(referrer_pubkey) = referrer {
961 let referral_address = referral_pda(referrer_pubkey).0;
962 accounts.push(AccountMeta::new(referral_address, false));
963 }
964
965 Instruction {
966 program_id: crate::ID,
967 accounts,
968 data: instruction::PlaceBid {
969 square_id: square_id.to_le_bytes(),
970 referrer: referrer.unwrap_or(Pubkey::default()).to_bytes(),
971 }
972 .to_bytes(),
973 }
974}
975
976pub fn claim_auction_oil(
983 signer: Pubkey,
984 well_mask: u8, well_accounts: [Option<Pubkey>; 4], auction_pool_accounts: Option<[Option<Pubkey>; 4]>, bid_accounts: Option<[Option<Pubkey>; 4]>, ) -> Instruction {
989 let miner_address = miner_pda(signer).0;
990 let auction_address = auction_pda().0;
991 let treasury_address = treasury_pda().0;
992 let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
993 let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
994 let mint_authority_address = oil_mint_api::state::authority_pda().0;
995
996 let mut accounts = vec![
997 AccountMeta::new(signer, true),
998 AccountMeta::new(miner_address, false),
999 ];
1000
1001 for well_opt in well_accounts.iter() {
1003 if let Some(well_pubkey) = well_opt {
1004 accounts.push(AccountMeta::new(*well_pubkey, false));
1005 } else {
1006 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1008 }
1009 }
1010
1011 if let Some(auction_pool_pdas) = auction_pool_accounts {
1013 for auction_pool_pda_opt in auction_pool_pdas.iter() {
1014 if let Some(auction_pool_pubkey) = auction_pool_pda_opt {
1015 accounts.push(AccountMeta::new(*auction_pool_pubkey, false));
1016 } else {
1017 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1019 }
1020 }
1021 } else {
1022 for _ in 0..4 {
1024 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1025 }
1026 }
1027
1028 accounts.extend_from_slice(&[
1029 AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
1031 AccountMeta::new(treasury_tokens_address, false),
1032 AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(mint_authority_address, false), AccountMeta::new_readonly(oil_mint_api::ID, false),
1035 AccountMeta::new(recipient_address, false),
1036 AccountMeta::new_readonly(spl_token::ID, false),
1037 AccountMeta::new_readonly(spl_associated_token_account::ID, false),
1038 AccountMeta::new_readonly(system_program::ID, false),
1039 AccountMeta::new_readonly(crate::ID, false), ]);
1041
1042 if let Some(bid_pdas) = bid_accounts {
1044 for bid_pda_opt in bid_pdas.iter() {
1045 if let Some(bid_pubkey) = bid_pda_opt {
1046 accounts.push(AccountMeta::new(*bid_pubkey, false));
1047 }
1048 }
1049 }
1050
1051 Instruction {
1052 program_id: crate::ID,
1053 accounts,
1054 data: ClaimAuctionOIL {
1055 well_mask,
1056 }
1057 .to_bytes(),
1058 }
1059}
1060
1061pub fn claim_auction_sol(
1068 signer: Pubkey,
1069 well_accounts: [Option<Pubkey>; 4], auction_pool_accounts: Option<[Option<Pubkey>; 4]>, bid_accounts: Option<[Option<Pubkey>; 4]>, ) -> Instruction {
1073 let miner_address = miner_pda(signer).0;
1074 let (auction_address, _) = auction_pda();
1075 let treasury_address = treasury_pda().0;
1076
1077 let mut accounts = vec![
1078 AccountMeta::new(signer, true),
1079 AccountMeta::new(miner_address, false),
1080 ];
1081
1082 for well_opt in well_accounts.iter() {
1084 if let Some(well_pubkey) = well_opt {
1085 accounts.push(AccountMeta::new(*well_pubkey, false));
1086 } else {
1087 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1089 }
1090 }
1091
1092 if let Some(auction_pool_pdas) = auction_pool_accounts {
1094 for auction_pool_pda_opt in auction_pool_pdas.iter() {
1095 if let Some(auction_pool_pubkey) = auction_pool_pda_opt {
1096 accounts.push(AccountMeta::new(*auction_pool_pubkey, false));
1097 } else {
1098 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1100 }
1101 }
1102 } else {
1103 for _ in 0..4 {
1105 accounts.push(AccountMeta::new_readonly(system_program::ID, false));
1106 }
1107 }
1108
1109 accounts.extend_from_slice(&[
1110 AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
1112 AccountMeta::new_readonly(system_program::ID, false),
1113 AccountMeta::new_readonly(crate::ID, false), ]);
1115
1116 if let Some(bid_pdas) = bid_accounts {
1118 for bid_pda_opt in bid_pdas.iter() {
1119 if let Some(bid_pubkey) = bid_pda_opt {
1120 accounts.push(AccountMeta::new(*bid_pubkey, false));
1121 }
1122 }
1123 }
1124
1125 Instruction {
1126 program_id: crate::ID,
1127 accounts,
1128 data: ClaimAuctionSOL {
1129 _reserved: 0,
1130 }
1131 .to_bytes(),
1132 }
1133}
1134
1135pub fn claim_seeker(signer: Pubkey, mint: Pubkey) -> Instruction {
1136 let seeker_address = seeker_pda(mint).0;
1137 let token_account_address = get_associated_token_address(&signer, &mint);
1138 Instruction {
1139 program_id: crate::ID,
1140 accounts: vec![
1141 AccountMeta::new(signer, true),
1142 AccountMeta::new_readonly(mint, false),
1143 AccountMeta::new(seeker_address, false),
1144 AccountMeta::new(token_account_address, false),
1145 AccountMeta::new_readonly(system_program::ID, false),
1146 ],
1147 data: ClaimSeeker {}.to_bytes(),
1148 }
1149}