use solana_program::pubkey::Pubkey;
use spl_associated_token_account::get_associated_token_address;
use steel::*;
use crate::{
consts::{AUCTION, BOARD, MINT_ADDRESS, REFINERY, SOL_MINT, TREASURY_ADDRESS},
instruction::{self, *},
state::*,
};
pub fn log(signer: Pubkey, msg: &[u8]) -> Instruction {
let mut data = Log {}.to_bytes();
data.extend_from_slice(msg);
Instruction {
program_id: crate::ID,
accounts: vec![AccountMeta::new(signer, true)],
data: data,
}
}
pub fn program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramError> {
let (board_address, _) = board_pda();
invoke_signed(&log(board_address, msg), accounts, &crate::ID, &[BOARD])
}
pub fn auction_program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramError> {
let (auction_address, _) = auction_pda();
invoke_signed(&log(auction_address, msg), accounts, &crate::ID, &[AUCTION])
}
pub fn refinery_program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramError> {
let (refinery_address, _) = refinery_pda();
invoke_signed(&log(refinery_address, msg), accounts, &crate::ID, &[REFINERY])
}
pub fn automate(
signer: Pubkey,
authority: Pubkey,
amount: u64,
deposit: u64,
executor: Pubkey,
fee: u64,
mask: u64,
strategy: u8,
reload: bool,
referrer: Option<Pubkey>,
pooled: bool,
is_new_miner: bool,
) -> Instruction {
let automation_address = automation_pda(authority).0;
let miner_address = miner_pda(authority).0;
let config_address = config_pda().0;
let referrer_pk = referrer.unwrap_or(Pubkey::default());
let mut accounts = vec![
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), ];
if is_new_miner && referrer.is_some() && referrer_pk != Pubkey::default() {
let referral_address = referral_pda(referrer_pk).0;
accounts.push(AccountMeta::new(referral_address, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: Automate {
amount: amount.to_le_bytes(),
deposit: deposit.to_le_bytes(),
fee: fee.to_le_bytes(),
mask: mask.to_le_bytes(),
strategy: strategy as u8,
reload: (reload as u64).to_le_bytes(),
referrer: referrer_pk.to_bytes(),
pooled: pooled as u8,
}
.to_bytes(),
}
}
pub fn claim_sol(
signer: Pubkey,
referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, ) -> Instruction {
let miner_address = miner_pda(signer).0;
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(miner_address, false),
AccountMeta::new_readonly(system_program::ID, false),
];
if let (Some(miner_pubkey), Some(referral_pubkey)) = (referrer_miner, referrer_referral) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimSOL {}.to_bytes(),
}
}
pub fn claim_oil(
signer: Pubkey,
referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, referrer_referral_oil_ata: Option<Pubkey>, ) -> Instruction {
let miner_address = miner_pda(signer).0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(miner_address, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_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),
];
if let (Some(miner_pubkey), Some(referral_pubkey), Some(oil_ata_pubkey)) =
(referrer_miner, referrer_referral, referrer_referral_oil_ata) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
accounts.push(AccountMeta::new(oil_ata_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimOIL {}.to_bytes(),
}
}
pub fn close(signer: Pubkey, round_id: u64, rent_payer: Pubkey) -> Instruction {
let board_address = board_pda().0;
let round_address = round_pda(round_id).0;
let treasury_address = TREASURY_ADDRESS;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(rent_payer, false),
AccountMeta::new(round_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: Close {}.to_bytes(),
}
}
pub fn deploy(
signer: Pubkey,
authority: Pubkey,
amount: u64,
round_id: u64,
squares: [bool; 25],
referrer: Option<Pubkey>,
pooled: bool,
) -> Instruction {
let automation_address = automation_pda(authority).0;
let board_address = board_pda().0;
let miner_address = miner_pda(authority).0;
let round_address = round_pda(round_id).0;
let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
let mut mask: u32 = 0;
for (i, &square) in squares.iter().enumerate() {
if square {
mask |= 1 << i;
}
}
let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
let referrer_bytes = referrer_pubkey.to_bytes();
let has_referrer = referrer_pubkey != Pubkey::default() && referrer_pubkey != authority;
let mut accounts = vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(automation_address, false), AccountMeta::new(board_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), ];
if has_referrer {
let referral_address = referral_pda(referrer_pubkey).0;
accounts.push(AccountMeta::new(referral_address, false)); }
accounts.push(AccountMeta::new(entropy_var_address, false)); accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false));
Instruction {
program_id: crate::ID,
accounts,
data: Deploy {
amount: amount.to_le_bytes(),
squares: mask.to_le_bytes(),
referrer: referrer_bytes,
pooled: if pooled { 1 } else { 0 },
}
.to_bytes(),
}
}
pub fn wrap(signer: Pubkey, use_liquidity: bool, amount: u64) -> Instruction {
let config_address = config_pda().0;
let treasury_address = TREASURY_ADDRESS;
let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
let data = Wrap {
use_liquidity: if use_liquidity { 1 } else { 0 },
amount: amount.to_le_bytes(),
}
.to_bytes();
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new_readonly(config_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_sol_address, false),
AccountMeta::new_readonly(solana_program::system_program::ID, false),
],
data,
}
}
pub fn buyback(signer: Pubkey, swap_accounts: &[AccountMeta], swap_data: &[u8]) -> Instruction {
let board_address = board_pda().0;
let mint_address = MINT_ADDRESS;
let treasury_address = TREASURY_ADDRESS;
let treasury_oil_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let treasury_sol_address = get_associated_token_address(&treasury_address, &SOL_MINT);
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_oil_address, false),
AccountMeta::new(treasury_sol_address, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(crate::ID, false),
];
for account in swap_accounts.iter() {
let mut acc_clone = account.clone();
acc_clone.is_signer = false;
accounts.push(acc_clone);
}
let mut data = Buyback {}.to_bytes();
data.extend_from_slice(swap_data);
Instruction {
program_id: crate::ID,
accounts,
data,
}
}
pub fn barrel(signer: Pubkey, amount: u64) -> Instruction {
let board_address = board_pda().0;
let mint_address = MINT_ADDRESS;
let treasury_address = TREASURY_ADDRESS;
let sender_oil_address = get_associated_token_address(&signer, &MINT_ADDRESS);
let treasury_oil_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let data = Barrel {
amount: amount.to_le_bytes(),
}
.to_bytes();
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(sender_oil_address, false),
AccountMeta::new(board_address, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_oil_address, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(crate::ID, false),
],
data,
}
}
pub fn reset(
signer: Pubkey,
fee_collector: Pubkey,
round_id: u64,
top_miner: Pubkey,
var_address: Pubkey,
) -> Instruction {
reset_with_miners(signer, fee_collector, round_id, top_miner, var_address, &[])
}
pub fn reset_with_miners(
signer: Pubkey,
fee_collector: Pubkey,
round_id: u64,
top_miner: Pubkey,
var_address: Pubkey,
miner_accounts: &[Pubkey],
) -> Instruction {
let board_address = board_pda().0;
let config_address = config_pda().0;
let mint_address = MINT_ADDRESS;
let round_address = round_pda(round_id).0;
let round_next_address = round_pda(round_id + 1).0;
let top_miner_address = miner_pda(top_miner).0;
let treasury_address = TREASURY_ADDRESS;
let treasury_tokens_address = treasury_tokens_address();
let pool_address = pool_pda().0;
let mint_authority_address = oil_mint_api::state::authority_pda().0;
let mut reset_instruction = Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(round_address, false),
AccountMeta::new(round_next_address, false),
AccountMeta::new(top_miner_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(pool_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(crate::ID, false),
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
AccountMeta::new_readonly(SOL_MINT, false),
AccountMeta::new(var_address, false),
AccountMeta::new_readonly(entropy_rng_api::ID, false),
AccountMeta::new(mint_authority_address, false),
AccountMeta::new_readonly(oil_mint_api::ID, false),
],
data: Reset {}.to_bytes(),
};
for miner_pubkey in miner_accounts {
reset_instruction.accounts.push(AccountMeta::new(
miner_pda(*miner_pubkey).0,
false,
));
}
reset_instruction
}
pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
let miner_address = miner_pda(authority).0;
let board_address = board_pda().0;
let config_address = config_pda().0;
let round_address = round_pda(round_id).0;
let treasury_address = TREASURY_ADDRESS;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false), AccountMeta::new(miner_address, false),
AccountMeta::new(round_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: Checkpoint {}.to_bytes(),
}
}
pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
let config_address = config_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: SetAdmin {
admin: admin.to_bytes(),
}
.to_bytes(),
}
}
pub fn set_admin_fee(signer: Pubkey, admin_fee: u64) -> Instruction {
let config_address = config_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: SetAdminFee {
admin_fee: admin_fee.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
let config_address = config_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: SetFeeCollector {
fee_collector: fee_collector.to_bytes(),
}
.to_bytes(),
}
}
pub fn set_tge_timestamp(signer: Pubkey, tge_timestamp: i64) -> Instruction {
let config_address = config_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: SetTgeTimestamp {
tge_timestamp: tge_timestamp.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn set_auction(
signer: Pubkey,
halving_period_seconds: u64,
last_halving_time: u64,
base_mining_rates: [u64; 4],
auction_duration_seconds: u64,
starting_prices: [u64; 4],
_well_id: u64, ) -> Instruction {
let config_address = config_pda().0;
let auction_address = auction_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new_readonly(config_address, false),
AccountMeta::new(auction_address, false),
],
data: SetAuction {
halving_period_seconds: halving_period_seconds.to_le_bytes(),
last_halving_time: last_halving_time.to_le_bytes(),
base_mining_rates: [
base_mining_rates[0].to_le_bytes(),
base_mining_rates[1].to_le_bytes(),
base_mining_rates[2].to_le_bytes(),
base_mining_rates[3].to_le_bytes(),
],
auction_duration_seconds: auction_duration_seconds.to_le_bytes(),
starting_prices: [
starting_prices[0].to_le_bytes(),
starting_prices[1].to_le_bytes(),
starting_prices[2].to_le_bytes(),
starting_prices[3].to_le_bytes(),
],
well_id: 4u64.to_le_bytes(), }
.to_bytes(),
}
}
pub fn deposit(signer: Pubkey, authority: Pubkey, amount: u64, lock_duration_days: u64, stake_id: u64) -> Instruction {
let mint_address = MINT_ADDRESS;
let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
let sender_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
let pool_tokens_address = pool_tokens_address();
let miner_address = miner_pda(authority).0; Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new(mint_address, false),
AccountMeta::new(sender_address, false),
AccountMeta::new(stake_address, false),
AccountMeta::new(stake_tokens_address, false),
AccountMeta::new(pool_address, false),
AccountMeta::new(pool_tokens_address, false),
AccountMeta::new(miner_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),
],
data: Deposit {
amount: amount.to_le_bytes(),
lock_duration_days: lock_duration_days.to_le_bytes(),
stake_id: stake_id.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn withdraw(signer: Pubkey, authority: Pubkey, amount: u64, stake_id: u64) -> Instruction {
let stake_address = stake_pda_with_id(authority, stake_id).0; let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
let mint_address = MINT_ADDRESS;
let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS); let pool_address = pool_pda().0;
let pool_tokens_address = pool_tokens_address();
let miner_address = miner_pda(authority).0; let treasury_address = treasury_pda().0;
let treasury_tokens_address = treasury_tokens_address();
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new(mint_address, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new(stake_address, false),
AccountMeta::new(stake_tokens_address, false),
AccountMeta::new(pool_address, false),
AccountMeta::new(pool_tokens_address, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(treasury_address, false), AccountMeta::new(treasury_tokens_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),
],
data: Withdraw {
amount: amount.to_le_bytes(),
stake_id: stake_id.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn reload_sol(
signer: Pubkey,
authority: Pubkey,
referrer_miner: Option<Pubkey>,
referrer_referral: Option<Pubkey>,
) -> Instruction {
let automation_address = automation_pda(authority).0;
let miner_address = miner_pda(authority).0;
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(automation_address, false),
AccountMeta::new(miner_address, false),
AccountMeta::new_readonly(system_program::ID, false),
];
if let (Some(miner_ref), Some(referral_ref)) = (referrer_miner, referrer_referral) {
accounts.push(AccountMeta::new(miner_ref, false));
accounts.push(AccountMeta::new(referral_ref, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ReloadSOL {}.to_bytes(),
}
}
pub fn claim_yield(signer: Pubkey, amount: u64, stake_id: u64) -> Instruction {
let stake_address = stake_pda_with_id(signer, stake_id).0;
let pool_address = pool_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(stake_address, false),
AccountMeta::new(pool_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: ClaimYield {
amount: amount.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn new_var(
signer: Pubkey,
provider: Pubkey,
id: u64,
commit: [u8; 32],
samples: u64,
) -> Instruction {
let board_address = board_pda().0;
let config_address = config_pda().0;
let var_address = entropy_rng_api::state::var_pda(board_address, id).0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false),
AccountMeta::new(provider, false),
AccountMeta::new(var_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(entropy_rng_api::ID, false),
],
data: NewVar {
id: id.to_le_bytes(),
commit: commit,
samples: samples.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn set_swap_program(signer: Pubkey, new_program: Pubkey) -> Instruction {
let config_address = config_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new_readonly(new_program, false),
],
data: SetSwapProgram {}.to_bytes(),
}
}
pub fn set_var_address(signer: Pubkey, new_var_address: Pubkey) -> Instruction {
let board_address = board_pda().0;
let config_address = config_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false),
AccountMeta::new(new_var_address, false),
],
data: SetVarAddress {}.to_bytes(),
}
}
pub fn migrate(signer: Pubkey, miner_authority: Pubkey) -> Instruction {
let config_address = config_pda().0;
let miner_address = miner_pda(miner_authority).0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new(miner_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: Migrate {}.to_bytes(),
}
}
pub fn create_referral(signer: Pubkey) -> Instruction {
let referral_address = referral_pda(signer).0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(referral_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: CreateReferral {}.to_bytes(),
}
}
pub fn create_whitelist(
signer: Pubkey,
code_hash: [u8; 32],
) -> Instruction {
let config_address = config_pda().0;
let (whitelist_address, _) = Whitelist::pda(code_hash);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new_readonly(config_address, false), AccountMeta::new(whitelist_address, false), AccountMeta::new_readonly(system_program::ID, false), ],
data: CreateWhitelist {
code_hash,
}
.to_bytes(),
}
}
pub fn claim_referral(signer: Pubkey, authority: Pubkey) -> Instruction {
let referral_address = referral_pda(authority).0;
let referral_oil_address = get_associated_token_address(&referral_address, &MINT_ADDRESS);
let recipient_oil_address = get_associated_token_address(&authority, &MINT_ADDRESS);
Instruction {
program_id: crate::ID,
accounts: vec![
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), ],
data: ClaimReferral {}.to_bytes(),
}
}
pub fn place_bid(
signer: Pubkey,
authority: Pubkey,
square_id: u64,
fee_collector: Pubkey,
previous_owner_miner: Option<Pubkey>, previous_owner: Option<Pubkey>, referrer: Option<Pubkey>, ) -> Instruction {
let well_address = well_pda(square_id).0;
let auction_address = auction_pda().0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let staking_pool_address = pool_pda().0;
let config_address = config_pda().0;
let mint_authority_address = oil_mint_api::state::authority_pda().0;
let bidder_miner_address = miner_pda(authority).0;
let mut accounts = vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, false), ];
accounts.extend_from_slice(&[
AccountMeta::new(well_address, false), AccountMeta::new(auction_address, false), AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(mint_authority_address, false),
AccountMeta::new_readonly(oil_mint_api::ID, false),
AccountMeta::new(staking_pool_address, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new_readonly(config_address, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(crate::ID, false), AccountMeta::new(bidder_miner_address, false), ]);
if let (Some(miner_pubkey), Some(owner_pubkey)) = (previous_owner_miner, previous_owner) {
accounts.push(AccountMeta::new(miner_pubkey, false)); accounts.push(AccountMeta::new(owner_pubkey, false)); }
if let Some(referrer_pubkey) = referrer {
let referral_address = referral_pda(referrer_pubkey).0;
accounts.push(AccountMeta::new(referral_address, false)); }
Instruction {
program_id: crate::ID,
accounts,
data: instruction::PlaceBid {
square_id: square_id.to_le_bytes(),
referrer: referrer.unwrap_or(Pubkey::default()).to_bytes(),
}
.to_bytes(),
}
}
pub fn claim_auction_oil(
signer: Pubkey,
well_mask: u8, referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, referrer_referral_oil_ata: Option<Pubkey>, ) -> Instruction {
let miner_address = miner_pda(signer).0;
let well_0_address = well_pda(0).0;
let well_1_address = well_pda(1).0;
let well_2_address = well_pda(2).0;
let well_3_address = well_pda(3).0;
let auction_address = auction_pda().0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
let mint_authority_address = oil_mint_api::state::authority_pda().0;
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(miner_address, false),
AccountMeta::new(well_0_address, false),
AccountMeta::new(well_1_address, false),
AccountMeta::new(well_2_address, false),
AccountMeta::new(well_3_address, false),
AccountMeta::new(auction_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(mint_authority_address, false),
AccountMeta::new_readonly(oil_mint_api::ID, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(crate::ID, false),
];
if let (Some(miner_pubkey), Some(referral_pubkey), Some(oil_ata_pubkey)) =
(referrer_miner, referrer_referral, referrer_referral_oil_ata) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
accounts.push(AccountMeta::new(oil_ata_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimAuctionOIL {
well_mask,
}
.to_bytes(),
}
}
pub fn claim_auction_sol(
signer: Pubkey,
referrer_miner: Option<Pubkey>, referrer_referral: Option<Pubkey>, ) -> Instruction {
let miner_address = miner_pda(signer).0;
let (auction_address, _) = auction_pda();
let treasury_address = treasury_pda().0;
let mut accounts = vec![
AccountMeta::new(signer, true), AccountMeta::new(miner_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(auction_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(crate::ID, false),
];
if let (Some(miner_pubkey), Some(referral_pubkey)) = (referrer_miner, referrer_referral) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimAuctionSOL {
_reserved: 0,
}
.to_bytes(),
}
}
pub fn checkpoint_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
round_id: u64,
) -> Instruction {
let miner_address = miner_pda(authority).0;
let board_address = board_pda().0;
let config_address = config_pda().0;
let round_address = round_pda(round_id).0;
let treasury_address = TREASURY_ADDRESS;
let data = vec![52u8];
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new_readonly(program_signer, false), AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false), AccountMeta::new(miner_address, false),
AccountMeta::new(round_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data,
}
}
pub fn deploy_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
amount: u64,
round_id: u64,
squares: [bool; 25],
referrer: Option<Pubkey>,
pooled: bool,
) -> Instruction {
let automation_address = automation_pda(authority).0;
let board_address = board_pda().0;
let miner_address = miner_pda(authority).0;
let round_address = round_pda(round_id).0;
let entropy_var_address = entropy_rng_api::state::var_pda(board_address, 0).0;
let mut mask: u32 = 0;
for (i, &square) in squares.iter().enumerate() {
if square {
mask |= 1 << i;
}
}
let referrer_pubkey = referrer.unwrap_or(Pubkey::default());
let has_referrer = referrer_pubkey != Pubkey::default() && referrer_pubkey != authority;
let user_wrapped_sol_ata = get_associated_token_address(&authority, &SOL_MINT);
let round_wrapped_sol_ata = get_associated_token_address(&round_address, &SOL_MINT);
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, false),
AccountMeta::new(automation_address, false),
AccountMeta::new(board_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),
];
if has_referrer {
let referral_address = referral_pda(referrer_pubkey).0;
accounts.push(AccountMeta::new(referral_address, false));
}
accounts.push(AccountMeta::new(entropy_var_address, false));
accounts.push(AccountMeta::new_readonly(entropy_rng_api::ID, false));
Instruction {
program_id: crate::ID,
accounts,
data: Deploy {
amount: amount.to_le_bytes(),
squares: mask.to_le_bytes(),
referrer: referrer_pubkey.to_bytes(),
pooled: if pooled { 1 } else { 0 },
}
.to_bytes(),
}
}
pub fn automate_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
amount: u64,
deposit: u64,
executor: Pubkey,
fee: u64,
mask: u64,
strategy: u8,
reload: bool,
referrer: Option<Pubkey>,
pooled: bool,
is_new_miner: bool,
) -> Instruction {
let automation_address = automation_pda(authority).0;
let miner_address = miner_pda(authority).0;
let referrer_pk = referrer.unwrap_or(Pubkey::default());
let user_wrapped_sol_ata = get_associated_token_address(&authority, &SOL_MINT);
let automation_wrapped_sol_ata = get_associated_token_address(&automation_address, &SOL_MINT);
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, 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(user_wrapped_sol_ata, false),
AccountMeta::new(automation_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),
];
if is_new_miner && referrer.is_some() && referrer_pk != Pubkey::default() {
let referral_address = referral_pda(referrer_pk).0;
accounts.push(AccountMeta::new(referral_address, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: Automate {
amount: amount.to_le_bytes(),
deposit: deposit.to_le_bytes(),
fee: fee.to_le_bytes(),
mask: mask.to_le_bytes(),
strategy: strategy as u8,
reload: (reload as u64).to_le_bytes(),
referrer: referrer_pk.to_bytes(),
pooled: pooled as u8,
}
.to_bytes(),
}
}
pub fn place_bid_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
square_id: u64,
fee_collector: Pubkey,
previous_owner_miner: Option<Pubkey>,
previous_owner: Option<Pubkey>,
referrer: Option<Pubkey>,
) -> Instruction {
let well_address = well_pda(square_id).0;
let auction_address = auction_pda().0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let staking_pool_address = pool_pda().0;
let config_address = config_pda().0;
let mint_authority_address = oil_mint_api::state::authority_pda().0;
let bidder_miner_address = miner_pda(authority).0;
let user_wrapped_sol_ata = get_associated_token_address(&authority, &SOL_MINT);
let treasury_wrapped_sol_ata = get_associated_token_address(&treasury_address, &SOL_MINT);
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, false),
AccountMeta::new(well_address, false),
AccountMeta::new(auction_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(mint_authority_address, false),
AccountMeta::new_readonly(oil_mint_api::ID, false),
AccountMeta::new(staking_pool_address, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new_readonly(config_address, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(crate::ID, false),
AccountMeta::new(bidder_miner_address, false),
];
if let (Some(miner_pubkey), Some(owner_pubkey)) = (previous_owner_miner, previous_owner) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(owner_pubkey, false));
}
if let Some(referrer_pubkey) = referrer {
let referral_address = referral_pda(referrer_pubkey).0;
accounts.push(AccountMeta::new(referral_address, false));
}
accounts.extend_from_slice(&[
AccountMeta::new(user_wrapped_sol_ata, false),
AccountMeta::new(treasury_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),
]);
Instruction {
program_id: crate::ID,
accounts,
data: instruction::PlaceBid {
square_id: square_id.to_le_bytes(),
referrer: referrer.unwrap_or(Pubkey::default()).to_bytes(),
}
.to_bytes(),
}
}
pub fn claim_auction_oil_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
well_mask: u8,
referrer_miner: Option<Pubkey>,
referrer_referral: Option<Pubkey>,
referrer_referral_oil_ata: Option<Pubkey>,
) -> Instruction {
let miner_address = miner_pda(authority).0;
let well_0_address = well_pda(0).0;
let well_1_address = well_pda(1).0;
let well_2_address = well_pda(2).0;
let well_3_address = well_pda(3).0;
let auction_address = auction_pda().0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS);
let mint_authority_address = oil_mint_api::state::authority_pda().0;
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(well_0_address, false),
AccountMeta::new(well_1_address, false),
AccountMeta::new(well_2_address, false),
AccountMeta::new(well_3_address, false),
AccountMeta::new(auction_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(mint_authority_address, false),
AccountMeta::new_readonly(oil_mint_api::ID, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(crate::ID, false),
];
if let (Some(miner_pubkey), Some(referral_pubkey), Some(oil_ata_pubkey)) =
(referrer_miner, referrer_referral, referrer_referral_oil_ata) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
accounts.push(AccountMeta::new(oil_ata_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimAuctionOIL {
well_mask,
}
.to_bytes(),
}
}
pub fn claim_auction_sol_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
referrer_miner: Option<Pubkey>,
referrer_referral: Option<Pubkey>,
) -> Instruction {
let miner_address = miner_pda(authority).0;
let (auction_address, _) = auction_pda();
let treasury_address = treasury_pda().0;
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(auction_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(crate::ID, false),
];
if let (Some(miner_pubkey), Some(referral_pubkey)) = (referrer_miner, referrer_referral) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimAuctionSOL {
_reserved: 0,
}
.to_bytes(),
}
}
pub fn claim_sol_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
referrer_miner: Option<Pubkey>,
referrer_referral: Option<Pubkey>,
) -> Instruction {
let miner_address = miner_pda(authority).0;
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, false),
AccountMeta::new(miner_address, false),
AccountMeta::new_readonly(system_program::ID, false),
];
if let (Some(miner_pubkey), Some(referral_pubkey)) = (referrer_miner, referrer_referral) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimSOL {}.to_bytes(),
}
}
pub fn claim_oil_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
referrer_miner: Option<Pubkey>,
referrer_referral: Option<Pubkey>,
referrer_referral_oil_ata: Option<Pubkey>,
) -> Instruction {
let miner_address = miner_pda(authority).0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS);
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_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),
];
if let (Some(miner_pubkey), Some(referral_pubkey), Some(oil_ata_pubkey)) =
(referrer_miner, referrer_referral, referrer_referral_oil_ata) {
accounts.push(AccountMeta::new(miner_pubkey, false));
accounts.push(AccountMeta::new(referral_pubkey, false));
accounts.push(AccountMeta::new(oil_ata_pubkey, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: ClaimOIL {}.to_bytes(),
}
}
pub fn withdraw_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
amount: u64,
stake_id: u64,
) -> Instruction {
let stake_address = stake_pda_with_id(authority, stake_id).0;
let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
let mint_address = MINT_ADDRESS;
let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS);
let pool_address = pool_pda().0;
let pool_tokens_address = pool_tokens_address();
let miner_address = miner_pda(authority).0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = treasury_tokens_address();
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new_readonly(program_signer, false),
AccountMeta::new(payer, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new(stake_address, false),
AccountMeta::new(stake_tokens_address, false),
AccountMeta::new(pool_address, false),
AccountMeta::new(pool_tokens_address, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_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),
],
data: Withdraw {
amount: amount.to_le_bytes(),
stake_id: stake_id.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn deposit_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
amount: u64,
lock_duration_days: u64,
stake_id: u64,
) -> Instruction {
let mint_address = MINT_ADDRESS;
let stake_address = stake_pda_with_id(authority, stake_id).0;
let stake_tokens_address = get_associated_token_address(&stake_address, &MINT_ADDRESS);
let sender_address = get_associated_token_address(&authority, &MINT_ADDRESS);
let pool_address = pool_pda().0;
let pool_tokens_address = pool_tokens_address();
let miner_address = miner_pda(authority).0;
let mut data = Deposit {
amount: amount.to_le_bytes(),
lock_duration_days: lock_duration_days.to_le_bytes(),
stake_id: stake_id.to_le_bytes(),
}
.to_bytes();
data[0] = 48u8;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new_readonly(program_signer, false), AccountMeta::new(payer, false), AccountMeta::new(mint_address, false), AccountMeta::new(sender_address, false), AccountMeta::new(stake_address, false), AccountMeta::new(stake_tokens_address, false), AccountMeta::new(pool_address, false), AccountMeta::new(pool_tokens_address, false), AccountMeta::new(miner_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), ],
data,
}
}
pub fn claim_yield_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
amount: u64,
stake_id: u64,
) -> Instruction {
let stake_address = stake_pda_with_id(authority, stake_id).0;
let pool_address = pool_pda().0;
let mut data = ClaimYield {
amount: amount.to_le_bytes(),
}
.to_bytes();
data[0] = 51u8;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, true), AccountMeta::new_readonly(program_signer, false), AccountMeta::new(stake_address, false), AccountMeta::new(pool_address, false), AccountMeta::new_readonly(system_program::ID, false), ],
data,
}
}
pub fn create_referral_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
) -> Instruction {
let referral_address = referral_pda(authority).0;
let data = vec![49u8];
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new_readonly(program_signer, false), AccountMeta::new(payer, false), AccountMeta::new(referral_address, false), AccountMeta::new_readonly(system_program::ID, false), ],
data,
}
}
pub fn claim_referral_with_session(
signer: Pubkey,
authority: Pubkey,
program_signer: Pubkey,
payer: Pubkey,
) -> Instruction {
let referral_address = referral_pda(authority).0;
let referral_oil_address = get_associated_token_address(&referral_address, &MINT_ADDRESS);
let recipient_oil_address = get_associated_token_address(&authority, &MINT_ADDRESS);
let data = vec![50u8];
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true), AccountMeta::new(authority, false), AccountMeta::new_readonly(program_signer, false), AccountMeta::new(payer, 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), ],
data,
}
}