use crate::instructions::{
CancelPublicAutomation, ClaimGrubstakeAirdrop, ClaimSats, ClaimSatsInstructionArgs, ClaimToken,
ClaimTokenInstructionArgs, ClaimUsd, ClaimUsdInstructionArgs, CloseRound, CreateBoard, CreateEpochVault,
CreateGrubstakeAirdrop, CreateGrubstakeAirdropInstructionArgs, CreateOneBtcVault, CreatePublicAutomation,
CreatePublicAutomationInstructionArgs, CreateSatrushConfig, CreateSatrushConfigInstructionArgs, CreateSatsVault,
CreateTokenVault, CreateTreasury, DeployPublic, DeployPublicInstructionArgs, DepositGrubstake,
DepositGrubstakeInstructionArgs, ExchangeAffiliatePoints, ExchangeAffiliatePointsInstructionArgs,
ExecutePublicAutomation, ExecutePublicAutomationInstructionArgs, MigrateBoard, MigrateMiner, MigrateSatrushConfig,
MigrateSatrushConfigInstructionArgs, MigrateTreasury, ReclaimGrubstakeAirdrop, ReclaimGrubstakeAutomation,
ReclaimMinerGrubstake, RotateRound, SetAffiliateRate, SetAffiliateRateInstructionArgs, SetMinerTag,
SetMinerTagInstructionArgs, SettleDeployPublic, SwapRoundStake, SwapRoundStakeInstructionArgs,
TopUpPublicAutomation, TopUpPublicAutomationInstructionArgs, UpdateBoardRoundDuration,
UpdateBoardRoundDurationInstructionArgs, UpdateDeployFees, UpdateDeployFeesInstructionArgs,
UpdateDeploymentSettleGraceDuration, UpdateDeploymentSettleGraceDurationInstructionArgs,
UpdateEpochVaultIterationDuration, UpdateEpochVaultIterationDurationInstructionArgs, UpdateMinDeployUsdAmount,
UpdateMinDeployUsdAmountInstructionArgs, UpdateStrikeTriggerModulus, UpdateStrikeTriggerModulusInstructionArgs,
UpdateUnclaimedHashrateBps, UpdateUnclaimedHashrateBpsInstructionArgs, WithdrawGrubstake,
WithdrawGrubstakeInstructionArgs,
};
use crate::types::AutomationStrategy;
use crate::{
get_affiliate_address, get_affiliate_tag_address, get_board_address, get_epoch_vault_address,
get_epoch_vault_iteration_address, get_event_authority_address, get_miner_address, get_one_btc_vault_address,
get_one_btc_vault_iteration_address, get_public_automation_address, get_public_deployment_address,
get_round_address, get_satrush_config_address, get_sats_vault_address, get_token_vault_address,
get_treasury_address,
};
use solana_instruction::{AccountMeta, Instruction};
use solana_pubkey::Pubkey;
pub const TOKEN_PROGRAM_ID: Pubkey = Pubkey::from_str_const("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
pub const ASSOCIATED_TOKEN_PROGRAM_ID: Pubkey = Pubkey::from_str_const("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
pub const SYSTEM_PROGRAM_ID: Pubkey = Pubkey::from_str_const("11111111111111111111111111111111");
pub const SLOT_HASHES_ID: Pubkey = Pubkey::from_str_const("SysvarS1otHashes111111111111111111111111111");
pub fn get_associated_token_address(wallet: &Pubkey, mint: &Pubkey) -> Pubkey {
Pubkey::find_program_address(
&[wallet.as_ref(), TOKEN_PROGRAM_ID.as_ref(), mint.as_ref()],
&ASSOCIATED_TOKEN_PROGRAM_ID,
)
.0
}
pub fn get_create_satrush_config_instruction(
authority: Pubkey,
args: CreateSatrushConfigInstructionArgs,
) -> Instruction {
CreateSatrushConfig {
authority,
satrush_config: get_satrush_config_address().0,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(args)
}
pub fn get_create_board_instruction(authority: Pubkey, usd_mint: Pubkey, btc_mint: Pubkey) -> Instruction {
let board = get_board_address().0;
CreateBoard {
authority,
satrush_config: get_satrush_config_address().0,
board,
initial_round: get_round_address(1).0,
usd_mint,
btc_mint,
board_usd_ata: get_associated_token_address(&board, &usd_mint),
board_btc_ata: get_associated_token_address(&board, &btc_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_update_board_round_duration_instruction(authority: Pubkey, new_round_duration: u32) -> Instruction {
UpdateBoardRoundDuration {
authority,
satrush_config: get_satrush_config_address().0,
board: get_board_address().0,
}
.instruction(UpdateBoardRoundDurationInstructionArgs { new_round_duration })
}
pub fn get_update_min_deploy_usd_amount_instruction(authority: Pubkey, new_min_deploy_usd_amount: u64) -> Instruction {
UpdateMinDeployUsdAmount {
authority,
satrush_config: get_satrush_config_address().0,
}
.instruction(UpdateMinDeployUsdAmountInstructionArgs {
new_min_deploy_usd_amount,
})
}
pub fn get_update_unclaimed_hashrate_bps_instruction(
authority: Pubkey,
new_unclaimed_hashrate_bps: u32,
) -> Instruction {
UpdateUnclaimedHashrateBps {
authority,
satrush_config: get_satrush_config_address().0,
}
.instruction(UpdateUnclaimedHashrateBpsInstructionArgs {
new_unclaimed_hashrate_bps,
})
}
pub fn get_update_deploy_fees_instruction(
authority: Pubkey,
new_strike_fee_bps: u32,
new_epoch_fee_bps: u32,
new_one_btc_fee_bps: u32,
new_protocol_fee_bps: u32,
new_buybacks_fee_bps: u32,
) -> Instruction {
UpdateDeployFees {
authority,
satrush_config: get_satrush_config_address().0,
}
.instruction(UpdateDeployFeesInstructionArgs {
new_strike_fee_bps,
new_epoch_fee_bps,
new_one_btc_fee_bps,
new_protocol_fee_bps,
new_buybacks_fee_bps,
})
}
pub fn get_update_epoch_vault_iteration_duration_instruction(
authority: Pubkey,
new_iteration_duration: u64,
) -> Instruction {
UpdateEpochVaultIterationDuration {
authority,
satrush_config: get_satrush_config_address().0,
}
.instruction(UpdateEpochVaultIterationDurationInstructionArgs { new_iteration_duration })
}
pub fn get_update_strike_trigger_modulus_instruction(authority: Pubkey, new_modulus: u16) -> Instruction {
UpdateStrikeTriggerModulus {
authority,
satrush_config: get_satrush_config_address().0,
}
.instruction(UpdateStrikeTriggerModulusInstructionArgs { new_modulus })
}
pub fn get_update_deployment_settle_grace_duration_instruction(
authority: Pubkey,
new_grace_duration: u64,
) -> Instruction {
UpdateDeploymentSettleGraceDuration {
authority,
satrush_config: get_satrush_config_address().0,
}
.instruction(UpdateDeploymentSettleGraceDurationInstructionArgs { new_grace_duration })
}
pub fn get_create_epoch_vault_instruction(authority: Pubkey, usd_mint: Pubkey, btc_mint: Pubkey) -> Instruction {
let epoch_vault = get_epoch_vault_address().0;
CreateEpochVault {
authority,
satrush_config: get_satrush_config_address().0,
epoch_vault,
epoch_vault_iteration: get_epoch_vault_iteration_address(1).0,
usd_mint,
btc_mint,
epoch_vault_usd_ata: get_associated_token_address(&epoch_vault, &usd_mint),
epoch_vault_btc_ata: get_associated_token_address(&epoch_vault, &btc_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_create_one_btc_vault_instruction(authority: Pubkey, usd_mint: Pubkey, btc_mint: Pubkey) -> Instruction {
let one_btc_vault = get_one_btc_vault_address().0;
CreateOneBtcVault {
authority,
satrush_config: get_satrush_config_address().0,
one_btc_vault,
one_btc_vault_iteration: get_one_btc_vault_iteration_address(1).0,
usd_mint,
btc_mint,
one_btc_vault_usd_ata: get_associated_token_address(&one_btc_vault, &usd_mint),
one_btc_vault_btc_ata: get_associated_token_address(&one_btc_vault, &btc_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_create_treasury_instruction(authority: Pubkey, usd_mint: Pubkey) -> Instruction {
let treasury = get_treasury_address().0;
CreateTreasury {
authority,
satrush_config: get_satrush_config_address().0,
treasury,
usd_mint,
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_deploy_public_instruction(
authority: Pubkey,
usd_mint: Pubkey,
round_id: u32,
selection_mask: u32,
amount: u64,
) -> Instruction {
let funding_usd_ata = get_associated_token_address(&authority, &usd_mint);
build_deploy_public_instruction(authority, usd_mint, round_id, selection_mask, amount, funding_usd_ata, false, None)
}
pub fn get_deploy_public_with_affiliate_instruction(
authority: Pubkey,
usd_mint: Pubkey,
round_id: u32,
selection_mask: u32,
amount: u64,
affiliate_authority: Pubkey,
) -> Instruction {
let funding_usd_ata = get_associated_token_address(&authority, &usd_mint);
build_deploy_public_instruction(
authority,
usd_mint,
round_id,
selection_mask,
amount,
funding_usd_ata,
false,
Some(get_affiliate_address(affiliate_authority).0),
)
}
pub fn get_deploy_public_grubstake_instruction(
authority: Pubkey,
usd_mint: Pubkey,
round_id: u32,
selection_mask: u32,
amount: u64,
) -> Instruction {
let miner = get_miner_address(authority).0;
let funding_usd_ata = get_associated_token_address(&miner, &usd_mint);
build_deploy_public_instruction(authority, usd_mint, round_id, selection_mask, amount, funding_usd_ata, true, None)
}
pub fn get_deploy_public_grubstake_with_affiliate_instruction(
authority: Pubkey,
usd_mint: Pubkey,
round_id: u32,
selection_mask: u32,
amount: u64,
affiliate_authority: Pubkey,
) -> Instruction {
let miner = get_miner_address(authority).0;
let funding_usd_ata = get_associated_token_address(&miner, &usd_mint);
build_deploy_public_instruction(
authority,
usd_mint,
round_id,
selection_mask,
amount,
funding_usd_ata,
true,
Some(get_affiliate_address(affiliate_authority).0),
)
}
#[allow(clippy::too_many_arguments)]
fn build_deploy_public_instruction(
authority: Pubkey,
usd_mint: Pubkey,
round_id: u32,
selection_mask: u32,
amount: u64,
funding_usd_ata: Pubkey,
is_grubstake_funded: bool,
affiliate: Option<Pubkey>,
) -> Instruction {
let board = get_board_address().0;
DeployPublic {
authority,
satrush_config: get_satrush_config_address().0,
board,
usd_mint,
board_usd_ata: get_associated_token_address(&board, &usd_mint),
authority_usd_ata: funding_usd_ata,
round: get_round_address(round_id).0,
public_deployment: get_public_deployment_address(authority, round_id).0,
miner: get_miner_address(authority).0,
affiliate,
token_program: TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction_with_remaining_accounts(
DeployPublicInstructionArgs {
selection_mask,
amount,
is_grubstake_funded,
},
&crate::rng::get_rng_remaining_accounts(),
)
}
pub fn get_rotate_round_instruction(
authority: Pubkey,
usd_mint: Pubkey,
btc_mint: Pubkey,
token_mint: Pubkey,
oracle_pool: Pubkey,
current_round_id: u32,
) -> Instruction {
let board = get_board_address().0;
let epoch_vault = get_epoch_vault_address().0;
let one_btc_vault = get_one_btc_vault_address().0;
let treasury = get_treasury_address().0;
let mut instruction = RotateRound {
authority,
satrush_config: get_satrush_config_address().0,
board,
current_round: get_round_address(current_round_id).0,
next_round: get_round_address(current_round_id + 1).0,
usd_mint,
btc_mint,
board_usd_ata: get_associated_token_address(&board, &usd_mint),
board_btc_ata: get_associated_token_address(&board, &btc_mint),
epoch_vault,
epoch_vault_usd_ata: get_associated_token_address(&epoch_vault, &usd_mint),
epoch_vault_btc_ata: get_associated_token_address(&epoch_vault, &btc_mint),
one_btc_vault,
one_btc_vault_usd_ata: get_associated_token_address(&one_btc_vault, &usd_mint),
treasury,
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
round_rotor: crate::rng::get_rotor_address(crate::rng::ROUND_ROTOR_TAG).0,
token_program: TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction();
instruction
.accounts
.extend(get_rotate_round_remaining_accounts(token_mint, oracle_pool));
instruction
}
pub fn get_rotate_round_remaining_accounts(token_mint: Pubkey, oracle_pool: Pubkey) -> Vec<AccountMeta> {
let board = get_board_address().0;
let epoch_vault = get_epoch_vault_address().0;
vec![
AccountMeta::new(get_associated_token_address(&board, &token_mint), false),
AccountMeta::new(get_associated_token_address(&epoch_vault, &token_mint), false),
AccountMeta::new(token_mint, false),
AccountMeta::new_readonly(crate::mint::SATRUSH_MINT_PROGRAM_ID, false),
AccountMeta::new_readonly(crate::mint::get_satmint_config_address().0, false),
AccountMeta::new(crate::mint::get_satmint_mine_address().0, false),
AccountMeta::new(crate::mint::get_satmint_oracle_address().0, false),
AccountMeta::new_readonly(crate::mint::get_satmint_authority_address().0, false),
AccountMeta::new_readonly(oracle_pool, false),
]
}
#[allow(clippy::too_many_arguments)]
pub fn get_swap_round_stake_instruction(
authority: Pubkey,
usd_mint: Pubkey,
btc_mint: Pubkey,
round_id: u32,
min_btc_out: u64,
swap_program: Pubkey,
swap_data: Vec<u8>,
route_accounts: &[AccountMeta],
) -> Instruction {
let board = get_board_address().0;
SwapRoundStake {
authority,
satrush_config: get_satrush_config_address().0,
board,
round: get_round_address(round_id).0,
usd_mint,
btc_mint,
board_usd_ata: get_associated_token_address(&board, &usd_mint),
board_btc_ata: get_associated_token_address(&board, &btc_mint),
swap_program,
token_program: TOKEN_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction_with_remaining_accounts(SwapRoundStakeInstructionArgs { min_btc_out, swap_data }, route_accounts)
}
pub fn get_settle_deploy_public_instruction(
authority: Pubkey,
deployment_authority: Pubkey,
rent_recipient: Pubkey,
usd_mint: Pubkey,
btc_mint: Pubkey,
token_mint: Pubkey,
round_id: u32,
) -> Instruction {
build_settle_deploy_public_instruction(
authority,
deployment_authority,
rent_recipient,
usd_mint,
btc_mint,
token_mint,
round_id,
None,
)
}
#[allow(clippy::too_many_arguments)]
pub fn get_settle_deploy_public_with_affiliate_instruction(
authority: Pubkey,
deployment_authority: Pubkey,
rent_recipient: Pubkey,
usd_mint: Pubkey,
btc_mint: Pubkey,
token_mint: Pubkey,
round_id: u32,
affiliate: Pubkey,
) -> Instruction {
build_settle_deploy_public_instruction(
authority,
deployment_authority,
rent_recipient,
usd_mint,
btc_mint,
token_mint,
round_id,
Some(affiliate),
)
}
#[allow(clippy::too_many_arguments)]
fn build_settle_deploy_public_instruction(
authority: Pubkey,
deployment_authority: Pubkey,
rent_recipient: Pubkey,
usd_mint: Pubkey,
btc_mint: Pubkey,
token_mint: Pubkey,
round_id: u32,
affiliate: Option<Pubkey>,
) -> Instruction {
let board = get_board_address().0;
let sats_vault = get_sats_vault_address().0;
let token_vault = get_token_vault_address().0;
let public_automation = get_public_automation_address(deployment_authority).0;
let miner = get_miner_address(deployment_authority).0;
let mut instruction = SettleDeployPublic {
authority,
rent_recipient,
satrush_config: get_satrush_config_address().0,
round: get_round_address(round_id).0,
board,
public_deployment: get_public_deployment_address(deployment_authority, round_id).0,
miner,
public_automation,
automation_usd_ata: get_associated_token_address(&public_automation, &usd_mint),
miner_usd_ata: get_associated_token_address(&miner, &usd_mint),
affiliate,
board_usd_ata: get_associated_token_address(&board, &usd_mint),
sats_vault,
btc_mint,
usd_mint,
board_btc_ata: get_associated_token_address(&board, &btc_mint),
sats_vault_btc_ata: get_associated_token_address(&sats_vault, &btc_mint),
token_vault,
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction();
instruction
.accounts
.extend(get_settle_deploy_public_remaining_accounts(token_mint));
instruction
}
pub fn get_settle_deploy_public_remaining_accounts(token_mint: Pubkey) -> Vec<AccountMeta> {
let board = get_board_address().0;
let token_vault = get_token_vault_address().0;
vec![
AccountMeta::new_readonly(token_mint, false),
AccountMeta::new(get_associated_token_address(&board, &token_mint), false),
AccountMeta::new(get_associated_token_address(&token_vault, &token_mint), false),
]
}
#[allow(clippy::too_many_arguments)]
pub fn get_create_public_automation_instruction(
authority: Pubkey,
usd_mint: Pubkey,
strategy: AutomationStrategy,
selection_mask: u32,
per_round_usd_amount: u64,
reload: bool,
deposit_usd_amount: u64,
) -> Instruction {
let funding_usd_ata = get_associated_token_address(&authority, &usd_mint);
build_create_public_automation_instruction(
authority,
usd_mint,
strategy,
selection_mask,
per_round_usd_amount,
reload,
deposit_usd_amount,
funding_usd_ata,
false,
None,
)
}
#[allow(clippy::too_many_arguments)]
pub fn get_create_public_automation_with_affiliate_instruction(
authority: Pubkey,
usd_mint: Pubkey,
strategy: AutomationStrategy,
selection_mask: u32,
per_round_usd_amount: u64,
reload: bool,
deposit_usd_amount: u64,
affiliate_authority: Pubkey,
) -> Instruction {
let funding_usd_ata = get_associated_token_address(&authority, &usd_mint);
build_create_public_automation_instruction(
authority,
usd_mint,
strategy,
selection_mask,
per_round_usd_amount,
reload,
deposit_usd_amount,
funding_usd_ata,
false,
Some(get_affiliate_address(affiliate_authority).0),
)
}
#[allow(clippy::too_many_arguments)]
pub fn get_create_public_automation_grubstake_instruction(
authority: Pubkey,
usd_mint: Pubkey,
strategy: AutomationStrategy,
selection_mask: u32,
per_round_usd_amount: u64,
reload: bool,
deposit_usd_amount: u64,
) -> Instruction {
let miner = get_miner_address(authority).0;
let funding_usd_ata = get_associated_token_address(&miner, &usd_mint);
build_create_public_automation_instruction(
authority,
usd_mint,
strategy,
selection_mask,
per_round_usd_amount,
reload,
deposit_usd_amount,
funding_usd_ata,
true,
None,
)
}
#[allow(clippy::too_many_arguments)]
fn build_create_public_automation_instruction(
authority: Pubkey,
usd_mint: Pubkey,
strategy: AutomationStrategy,
selection_mask: u32,
per_round_usd_amount: u64,
reload: bool,
deposit_usd_amount: u64,
funding_usd_ata: Pubkey,
is_grubstake_funded: bool,
affiliate: Option<Pubkey>,
) -> Instruction {
let public_automation = get_public_automation_address(authority).0;
CreatePublicAutomation {
authority,
satrush_config: get_satrush_config_address().0,
public_automation,
usd_mint,
authority_usd_ata: funding_usd_ata,
automation_usd_ata: get_associated_token_address(&public_automation, &usd_mint),
miner: get_miner_address(authority).0,
affiliate,
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(CreatePublicAutomationInstructionArgs {
strategy,
selection_mask,
per_round_usd_amount,
reload,
deposit_usd_amount,
is_grubstake_funded,
})
}
pub fn get_top_up_public_automation_instruction(authority: Pubkey, usd_mint: Pubkey, amount: u64) -> Instruction {
let funding_usd_ata = get_associated_token_address(&authority, &usd_mint);
build_top_up_public_automation_instruction(authority, usd_mint, amount, funding_usd_ata)
}
pub fn get_top_up_public_automation_grubstake_instruction(
authority: Pubkey,
usd_mint: Pubkey,
amount: u64,
) -> Instruction {
let miner = get_miner_address(authority).0;
let funding_usd_ata = get_associated_token_address(&miner, &usd_mint);
build_top_up_public_automation_instruction(authority, usd_mint, amount, funding_usd_ata)
}
fn build_top_up_public_automation_instruction(
authority: Pubkey,
usd_mint: Pubkey,
amount: u64,
funding_usd_ata: Pubkey,
) -> Instruction {
let public_automation = get_public_automation_address(authority).0;
TopUpPublicAutomation {
authority,
satrush_config: get_satrush_config_address().0,
public_automation,
miner: get_miner_address(authority).0,
usd_mint,
authority_usd_ata: funding_usd_ata,
automation_usd_ata: get_associated_token_address(&public_automation, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
}
.instruction(TopUpPublicAutomationInstructionArgs { amount })
}
pub fn get_cancel_public_automation_instruction(authority: Pubkey, usd_mint: Pubkey) -> Instruction {
let public_automation = get_public_automation_address(authority).0;
let miner = get_miner_address(authority).0;
CancelPublicAutomation {
authority,
satrush_config: get_satrush_config_address().0,
public_automation,
miner,
usd_mint,
automation_usd_ata: get_associated_token_address(&public_automation, &usd_mint),
authority_usd_ata: get_associated_token_address(&authority, &usd_mint),
miner_usd_ata: get_associated_token_address(&miner, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_execute_public_automation_instruction(
crank_authority: Pubkey,
automation_authority: Pubkey,
usd_mint: Pubkey,
round_id: u32,
selection_mask: Option<u32>,
) -> Instruction {
let board = get_board_address().0;
let public_automation = get_public_automation_address(automation_authority).0;
ExecutePublicAutomation {
authority: crank_authority,
satrush_config: get_satrush_config_address().0,
board,
round: get_round_address(round_id).0,
public_automation,
usd_mint,
automation_usd_ata: get_associated_token_address(&public_automation, &usd_mint),
board_usd_ata: get_associated_token_address(&board, &usd_mint),
public_deployment: get_public_deployment_address(automation_authority, round_id).0,
miner: get_miner_address(automation_authority).0,
affiliate: None,
slot_hashes: SLOT_HASHES_ID,
token_program: TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction_with_remaining_accounts(
ExecutePublicAutomationInstructionArgs { selection_mask },
&crate::rng::get_rng_remaining_accounts(),
)
}
pub fn get_execute_public_automation_with_affiliate_instruction(
crank_authority: Pubkey,
automation_authority: Pubkey,
usd_mint: Pubkey,
round_id: u32,
selection_mask: Option<u32>,
affiliate_authority: Pubkey,
) -> Instruction {
let board = get_board_address().0;
let public_automation = get_public_automation_address(automation_authority).0;
ExecutePublicAutomation {
authority: crank_authority,
satrush_config: get_satrush_config_address().0,
board,
round: get_round_address(round_id).0,
public_automation,
usd_mint,
automation_usd_ata: get_associated_token_address(&public_automation, &usd_mint),
board_usd_ata: get_associated_token_address(&board, &usd_mint),
public_deployment: get_public_deployment_address(automation_authority, round_id).0,
miner: get_miner_address(automation_authority).0,
affiliate: Some(get_affiliate_address(affiliate_authority).0),
slot_hashes: SLOT_HASHES_ID,
token_program: TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction_with_remaining_accounts(
ExecutePublicAutomationInstructionArgs { selection_mask },
&crate::rng::get_rng_remaining_accounts(),
)
}
pub fn get_claim_usd_instruction(authority: Pubkey, usd_mint: Pubkey, amount: u64) -> Instruction {
let board = get_board_address().0;
ClaimUsd {
authority,
satrush_config: get_satrush_config_address().0,
board,
miner: get_miner_address(authority).0,
usd_mint,
board_usd_ata: get_associated_token_address(&board, &usd_mint),
authority_usd_ata: get_associated_token_address(&authority, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(ClaimUsdInstructionArgs { amount })
}
pub fn get_claim_sats_instruction(authority: Pubkey, btc_mint: Pubkey, token_mint: Pubkey, shares: u64) -> Instruction {
let sats_vault = get_sats_vault_address().0;
let token_vault = get_token_vault_address().0;
ClaimSats {
authority,
satrush_config: get_satrush_config_address().0,
sats_vault,
token_vault,
miner: get_miner_address(authority).0,
btc_mint,
token_mint,
sats_vault_btc_ata: get_associated_token_address(&sats_vault, &btc_mint),
token_vault_token_ata: get_associated_token_address(&token_vault, &token_mint),
authority_btc_ata: get_associated_token_address(&authority, &btc_mint),
authority_token_ata: get_associated_token_address(&authority, &token_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction(ClaimSatsInstructionArgs { shares })
}
pub fn get_claim_token_instruction(
authority: Pubkey,
token_mint: Pubkey,
btc_mint: Pubkey,
token_shares: u64,
) -> Instruction {
let sats_vault = get_sats_vault_address().0;
let token_vault = get_token_vault_address().0;
ClaimToken {
authority,
satrush_config: get_satrush_config_address().0,
token_vault,
sats_vault,
miner: get_miner_address(authority).0,
token_mint,
btc_mint,
token_vault_token_ata: get_associated_token_address(&token_vault, &token_mint),
sats_vault_btc_ata: get_associated_token_address(&sats_vault, &btc_mint),
authority_token_ata: get_associated_token_address(&authority, &token_mint),
authority_btc_ata: get_associated_token_address(&authority, &btc_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction(ClaimTokenInstructionArgs { token_shares })
}
pub fn get_migrate_miner_instruction(authority: Pubkey, miner: Pubkey) -> Instruction {
MigrateMiner {
authority,
satrush_config: get_satrush_config_address().0,
miner,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_migrate_satrush_config_instruction(authority: Pubkey, token_mint: Pubkey) -> Instruction {
MigrateSatrushConfig {
authority,
satrush_config: get_satrush_config_address().0,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(MigrateSatrushConfigInstructionArgs { token_mint })
}
pub fn get_migrate_board_instruction(authority: Pubkey) -> Instruction {
MigrateBoard {
authority,
satrush_config: get_satrush_config_address().0,
board: get_board_address().0,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_migrate_treasury_instruction(authority: Pubkey) -> Instruction {
MigrateTreasury {
authority,
satrush_config: get_satrush_config_address().0,
treasury: get_treasury_address().0,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_create_sats_vault_instruction(authority: Pubkey, btc_mint: Pubkey) -> Instruction {
let sats_vault = get_sats_vault_address().0;
CreateSatsVault {
authority,
satrush_config: get_satrush_config_address().0,
sats_vault,
btc_mint,
sats_vault_btc_ata: get_associated_token_address(&sats_vault, &btc_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_create_token_vault_instruction(authority: Pubkey, token_mint: Pubkey) -> Instruction {
let token_vault = get_token_vault_address().0;
let board = get_board_address().0;
let epoch_vault = get_epoch_vault_address().0;
CreateTokenVault {
authority,
satrush_config: get_satrush_config_address().0,
token_vault,
board,
epoch_vault,
token_mint,
token_vault_token_ata: get_associated_token_address(&token_vault, &token_mint),
board_token_ata: get_associated_token_address(&board, &token_mint),
epoch_vault_token_ata: get_associated_token_address(&epoch_vault, &token_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_close_round_instruction(
authority: Pubkey,
usd_mint: Pubkey,
btc_mint: Pubkey,
round_id: u32,
) -> Instruction {
let board = get_board_address().0;
let treasury = get_treasury_address().0;
CloseRound {
authority,
satrush_config: get_satrush_config_address().0,
board,
round: get_round_address(round_id).0,
treasury,
usd_mint,
btc_mint,
board_usd_ata: get_associated_token_address(&board, &usd_mint),
board_btc_ata: get_associated_token_address(&board, &btc_mint),
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
treasury_btc_ata: get_associated_token_address(&treasury, &btc_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
event_authority: get_event_authority_address().0,
program: crate::SATRUSH_ID,
}
.instruction()
}
pub fn get_set_miner_tag_instruction(authority: Pubkey, tag: &str) -> Instruction {
SetMinerTag {
authority,
affiliate: get_affiliate_address(authority).0,
affiliate_tag: get_affiliate_tag_address(tag).0,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(SetMinerTagInstructionArgs { tag: tag.to_string() })
}
pub fn get_exchange_affiliate_points_instruction(
authority: Pubkey,
usd_mint: Pubkey,
points_amount: u64,
) -> Instruction {
let miner = get_miner_address(authority).0;
let treasury = get_treasury_address().0;
ExchangeAffiliatePoints {
authority,
satrush_config: get_satrush_config_address().0,
affiliate: get_affiliate_address(authority).0,
miner,
treasury,
usd_mint,
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
miner_usd_ata: get_associated_token_address(&miner, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(ExchangeAffiliatePointsInstructionArgs { points_amount })
}
pub fn get_set_affiliate_rate_instruction(
authority: Pubkey,
affiliate_authority: Pubkey,
rate_bps: u16,
) -> Instruction {
SetAffiliateRate {
authority,
satrush_config: get_satrush_config_address().0,
affiliate: get_affiliate_address(affiliate_authority).0,
}
.instruction(SetAffiliateRateInstructionArgs { rate_bps })
}
pub fn get_deposit_grubstake_instruction(authority: Pubkey, usd_mint: Pubkey, usd_amount: u64) -> Instruction {
let treasury = get_treasury_address().0;
DepositGrubstake {
authority,
satrush_config: get_satrush_config_address().0,
treasury,
usd_mint,
authority_usd_ata: get_associated_token_address(&authority, &usd_mint),
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
}
.instruction(DepositGrubstakeInstructionArgs { usd_amount })
}
pub fn get_withdraw_grubstake_instruction(
authority: Pubkey,
fee_recipient: Pubkey,
usd_mint: Pubkey,
usd_amount: u64,
) -> Instruction {
let treasury = get_treasury_address().0;
WithdrawGrubstake {
authority,
satrush_config: get_satrush_config_address().0,
treasury,
usd_mint,
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
fee_recipient,
fee_recipient_usd_ata: get_associated_token_address(&fee_recipient, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(WithdrawGrubstakeInstructionArgs { usd_amount })
}
pub fn get_create_grubstake_airdrop_instruction(
authority: Pubkey,
airdrop: Pubkey,
airdrop_authority: Pubkey,
usd_amount: u64,
expiration_timestamp: i64,
) -> Instruction {
CreateGrubstakeAirdrop {
authority,
satrush_config: get_satrush_config_address().0,
grubstake_airdrop: airdrop,
treasury: get_treasury_address().0,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction(CreateGrubstakeAirdropInstructionArgs {
airdrop_authority,
usd_amount,
expiration_timestamp,
})
}
pub fn get_claim_grubstake_airdrop_instruction(
authority: Pubkey,
airdrop: Pubkey,
fee_recipient: Pubkey,
usd_mint: Pubkey,
) -> Instruction {
let treasury = get_treasury_address().0;
let miner = get_miner_address(authority).0;
ClaimGrubstakeAirdrop {
authority,
satrush_config: get_satrush_config_address().0,
fee_recipient,
grubstake_airdrop: airdrop,
miner,
treasury,
usd_mint,
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
miner_usd_ata: get_associated_token_address(&miner, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
associated_token_program: ASSOCIATED_TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.instruction()
}
pub fn get_reclaim_grubstake_airdrop_instruction(authority: Pubkey, airdrop: Pubkey) -> Instruction {
ReclaimGrubstakeAirdrop {
authority,
satrush_config: get_satrush_config_address().0,
grubstake_airdrop: airdrop,
treasury: get_treasury_address().0,
}
.instruction()
}
pub fn get_reclaim_miner_grubstake_instruction(
authority: Pubkey,
miner_authority: Pubkey,
usd_mint: Pubkey,
) -> Instruction {
let treasury = get_treasury_address().0;
let miner = get_miner_address(miner_authority).0;
ReclaimMinerGrubstake {
authority,
satrush_config: get_satrush_config_address().0,
miner_authority,
miner,
treasury,
usd_mint,
miner_usd_ata: get_associated_token_address(&miner, &usd_mint),
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
}
.instruction()
}
pub fn get_reclaim_grubstake_automation_instruction(
authority: Pubkey,
automation_owner: Pubkey,
usd_mint: Pubkey,
) -> Instruction {
let treasury = get_treasury_address().0;
let automation = get_public_automation_address(automation_owner).0;
ReclaimGrubstakeAutomation {
authority,
satrush_config: get_satrush_config_address().0,
public_automation: automation,
miner: get_miner_address(automation_owner).0,
automation_owner,
treasury,
usd_mint,
automation_usd_ata: get_associated_token_address(&automation, &usd_mint),
treasury_usd_ata: get_associated_token_address(&treasury, &usd_mint),
token_program: TOKEN_PROGRAM_ID,
}
.instruction()
}