use crate::{
idl::{
arcium::{
accounts::MXEAccount,
client::{
accounts::{
ActivateArx as ActivateArxAccs,
ActivateCluster as ActivateClusterAccs,
BindRecoveryPeerMigration as BindRecoveryPeerMigrationAccs,
BumpEpochCluster as BumpEpochClusterAccs,
CallbackComputation as CallbackComputationAccs,
ClaimComputationRent as ClaimComputationRentAccs,
ClaimFailureAppend as ClaimFailureAppendAccs,
ClaimFailureFinalize as ClaimFailureFinalizeAccs,
ClaimFailureInit as ClaimFailureInitAccs,
ClaimNodeFees as ClaimNodeFeesAccs,
CloseComputationDefinition as CloseComputationDefinitionAccs,
CloseComputationDefinitionBuffers as CloseComputationDefinitionBuffersAccs,
CloseKeyRecovery as CloseKeyRecoveryAccs,
CloseMxe as CloseMxeAccs,
DeactivateArx as DeactivateArxAccs,
DeactivateCluster as DeactivateClusterAccs,
DeactivateComputationDefinition as DeactivateComputationDefinitionAccs,
EmbiggenRawCircuitAcc as EmbiggenRawCircuitAccAccs,
ExtendRecoveryKeyshares as ExtendRecoveryKeysharesAccs,
FinalizeComputationDefinition as FinalizeComputationDefinitionAccs,
FinalizeKeyRecoveryCallback as FinalizeKeyRecoveryCallbackAccs,
FinalizeKeyRecoveryExecution as FinalizeKeyRecoveryExecutionAccs,
FinalizeKeyRecoverySharesUpload as FinalizeKeyRecoverySharesUploadAccs,
FinalizeMxeKeys as FinalizeMxeKeysAccs,
IncreaseMempoolSize as IncreaseMempoolSizeAccs,
Init as InitNetworkProgramAccs,
InitArxNode as InitArxNodeAccs,
InitCluster as InitClusterAccs,
InitComputationDefinition as InitComputationDefinitionAccs,
InitKeyRecoveryExecutionPart1 as InitKeyRecoveryExecutionPart1Accs,
InitKeyRecoveryExecutionPart2 as InitKeyRecoveryExecutionPart2Accs,
InitMxePart1 as InitMxePart1Accs,
InitMxePart2 as InitMxePart2Accs,
InitOperator as InitOperatorAccs,
InitRawCircuitAcc as InitRawCircuitAccs,
InitRecoveryPeerAccount as InitRecoveryPeerAccountAccs,
JoinCluster as JoinClusterAccs,
MigrateArxNode as MigrateArxNodeAccs,
MigrateCluster as MigrateClusterAccs,
MigrateMxeAccount as MigrateMxeAccountAccs,
MigrateRecoveryPeer as MigrateRecoveryPeerAccs,
ProposeFee as ProposeFeeAccs,
ProposeJoinCluster as ProposeJoinClusterAccs,
QueueComputation as QueueComputationAccs,
QueueKeyRecoveryInit as QueueKeyRecoveryInitAccs,
ReclaimExpiredComputationFee as ReclaimExpiredComputationFeeAccs,
ReclaimFailureRentIdempotent as ReclaimFailureRentIdempotentAccs,
RecoverMxe as RecoverMxeAccs,
RegisterAccountInLut as RegisterAccountInLutAccs,
RequeueMxeKeygen as RequeueMxeKeygenAccs,
SetActive as SetActiveAccs,
SetArxNodeConfig as SetArxNodeConfigAccs,
SetArxNodeMetadata as SetArxNodeMetadataAccs,
SetClusterAuthority as SetClusterAuthorityAccs,
SetClusterTdInfo as SetClusterTdInfoAccs,
SetLeaderChoice as SetLeaderChoiceAccs,
SetMxeKeys as SetMxeKeysAccs,
SetMxeRecoveryKeysInit as SetMxeRecoveryKeysInitAccs,
SubmitAggregatedBlsPubkey as SubmitAggregatedBlsPubkeyAccs,
SubmitKeyRecoveryShare as SubmitKeyRecoveryShareAccs,
UpdateCurrentEpochIdempotent as UpdateCurrentEpochIdempotentAccs,
UploadCircuit as UploadCircuitAccs,
VoteFee as VoteFeeAccs,
ZCloseAbortedKeyRecovery as CloseAbortedKeyRecoveryAccs,
},
args::{
ActivateArx as ActivateArxArgs,
ActivateCluster as ActivateClusterArgs,
BindRecoveryPeerMigration as BindRecoveryPeerMigrationArgs,
BumpEpochCluster as BumpEpochClusterArgs,
CallbackComputation as CallbackComputationArgs,
ClaimComputationRent as ClaimComputationRentArgs,
ClaimFailureAppend as ClaimFailureAppendArgs,
ClaimFailureFinalize as ClaimFailureFinalizeArgs,
ClaimFailureInit as ClaimFailureInitArgs,
ClaimNodeFees as ClaimNodeFeesArgs,
CloseComputationDefinition as CloseComputationDefinitionArgs,
CloseComputationDefinitionBuffers as CloseComputationDefinitionBuffersArgs,
CloseKeyRecovery as CloseKeyRecoveryArgs,
CloseMxe as CloseMxeArgs,
DeactivateArx as DeactivateArxArgs,
DeactivateCluster as DeactivateClusterArgs,
DeactivateComputationDefinition as DeactivateComputationDefinitionArgs,
EmbiggenRawCircuitAcc as EmbiggenRawCircuitAccArgs,
ExtendRecoveryKeyshares as ExtendRecoveryKeysharesArgs,
FinalizeComputationDefinition as FinalizeComputationDefinitionArgs,
FinalizeKeyRecoveryCallback as FinalizeKeyRecoveryCallbackArgs,
FinalizeKeyRecoveryExecution as FinalizeKeyRecoveryExecutionArgs,
FinalizeKeyRecoverySharesUpload as FinalizeKeyRecoverySharesUploadArgs,
FinalizeMxeKeys as FinalizeMxeKeysArgs,
IncreaseMempoolSize as IncreaseMempoolSizeArgs,
Init as InitNetworkProgramArgs,
InitArxNode as InitArxNodeArgs,
InitCluster as InitClusterArgs,
InitComputationDefinition as InitComputationDefinitionArgs,
InitKeyRecoveryExecutionPart1 as InitKeyRecoveryExecutionPart1Args,
InitKeyRecoveryExecutionPart2 as InitKeyRecoveryExecutionPart2Args,
InitMxePart1 as InitMxePart1Args,
InitMxePart2 as InitMxePart2Args,
InitOperator as InitOperatorArgs,
InitRawCircuitAcc as InitRawCircuitArgs,
InitRecoveryPeerAccount as InitRecoveryPeerAccountArgs,
JoinCluster as JoinClusterArgs,
MigrateArxNode as MigrateArxNodeArgs,
MigrateCluster as MigrateClusterArgs,
MigrateMxeAccount as MigrateMxeAccountArgs,
MigrateRecoveryPeer as MigrateRecoveryPeerArgs,
ProposeFee as ProposeFeeArgs,
ProposeJoinCluster as ProposeJoinClusterArgs,
QueueComputation as QueueComputationArgs,
QueueKeyRecoveryInit as QueueKeyRecoveryInitArgs,
ReclaimExpiredComputationFee as ReclaimExpiredComputationFeeArgs,
ReclaimFailureRentIdempotent as ReclaimFailureRentIdempotentArgs,
RecoverMxe as RecoverMxeArgs,
RegisterAccountInLut as RegisterAccountInLutArgs,
RequeueMxeKeygen as RequeueMxeKeygenArgs,
SetActive as SetActiveArgs,
SetArxNodeConfig as SetArxNodeConfigArgs,
SetArxNodeMetadata as SetArxNodeMetadataArgs,
SetClusterAuthority as SetClusterAuthorityArgs,
SetClusterTdInfo as SetClusterTdInfoArgs,
SetLeaderChoice as SetLeaderChoiceArgs,
SetMxeKeys as SetMxeKeysArgs,
SetMxeRecoveryKeysInit as SetMxeRecoveryKeysInitArgs,
SubmitAggregatedBlsPubkey as SubmitAggregatedBlsPubkeyArgs,
SubmitKeyRecoveryShare as SubmitKeyRecoveryShareArgs,
UpdateCurrentEpochIdempotent as UpdateCurrentEpochIdempotentArgs,
UploadCircuit as UploadCircuitArgs,
VoteFee as VoteFeeArgs,
ZCloseAbortedKeyRecovery as CloseAbortedKeyRecoveryArgs,
},
},
types::{
ArgumentList,
ArxNodeConfig,
BN254G2BLSPublicKey,
CallbackAccount,
CallbackInstruction,
CircuitSource,
ComputationDefinitionMeta,
ComputationSignature,
Epoch,
ExecutionStatus,
LeaderChoice,
MempoolSize,
NodeMetadata,
OperatorMeta,
Output,
Parameter,
Timestamp,
},
ID as ARCIUM_PROG_ID,
},
arcium_staking::ID as ARCIUM_STAKING_PROG_ID,
},
pda::{
arx_acc,
clock_acc,
cluster_acc,
computation_acc,
computation_definition_acc,
execpool_acc,
failure_claim_acc,
fee_pool_acc,
mempool_acc,
mxe_acc,
mxe_lut_acc,
mxe_recovery_acc,
operator_acc,
permissioned_recovery_peers_acc,
raw_circuit_acc,
recovery_cluster_acc,
recovery_peer_acc,
signer_acc,
staking::primary_stake_acc,
},
utils::MAX_RECOVERY_PEERS,
MXE_KEYGEN_COMPUTATION_DEFINITION_OFFSET,
MXE_KEY_RECOVERY_FINALIZE_COMPUTATION_DEFINITION_OFFSET,
MXE_KEY_RECOVERY_INIT_COMPUTATION_DEFINITION_OFFSET,
};
use anchor_lang::{prelude::*, solana_program::instruction::Instruction, InstructionData};
use arcis_compiler::MXE_KEYS_ENC_COUNT;
use solana_address_lookup_table_interface::program::ID as ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
use solana_sdk_ids::{
system_program::ID as SYSTEM_PROGRAM_ID,
sysvar::instructions::ID as INSTRUCTIONS_SYSVAR_ID,
};
use std::vec;
pub const ARCIUM_TOKEN_DECIMALS: u8 = 9;
const RESERVED_MXE_KEYGEN_COMP_DEF_OFFSET: u32 = 1;
pub const RESERVED_MXE_KEY_RECOVERY_INIT_COMP_DEF_OFFSET: u32 = 2;
pub fn migrate_cluster_ix(payer: &Pubkey, cluster_offset: u32) -> Instruction {
let accounts = MigrateClusterAccs {
payer: payer.to_owned(),
cluster: cluster_acc(cluster_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = MigrateClusterArgs {}.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn migrate_mxe_account_ix(payer: &Pubkey, mxe_program: &Pubkey) -> Instruction {
let accounts = MigrateMxeAccountAccs {
payer: payer.to_owned(),
mxe: mxe_acc(mxe_program),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = MigrateMxeAccountArgs {}.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn migrate_recovery_peer_ix(payer: &Pubkey, peer_offset: u32) -> Instruction {
let accounts = MigrateRecoveryPeerAccs {
payer: payer.to_owned(),
recovery_peer: recovery_peer_acc(peer_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = MigrateRecoveryPeerArgs {}.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn migrate_arx_node_ix(authority: &Pubkey, node_offset: u32) -> Instruction {
let accounts = MigrateArxNodeAccs {
authority: authority.to_owned(),
arx_node_acc: arx_acc(node_offset),
primary_stake_account: primary_stake_acc(authority),
arcium_staking_program: ARCIUM_STAKING_PROG_ID,
}
.to_account_metas(None);
let data = MigrateArxNodeArgs { node_offset }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn bind_recovery_peer_migration_ix(authority: &Pubkey, peer_offset: u32) -> Instruction {
let accounts = BindRecoveryPeerMigrationAccs {
authority: authority.to_owned(),
recovery_peer_account: recovery_peer_acc(peer_offset),
primary_stake_account: primary_stake_acc(authority),
arcium_staking_program: ARCIUM_STAKING_PROG_ID,
}
.to_account_metas(None);
let data = BindRecoveryPeerMigrationArgs { peer_offset }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_network_program_ix(current_timestamp: u64, signer: &Pubkey) -> Instruction {
let pool_acc = fee_pool_acc();
let accounts = InitNetworkProgramAccs {
signer: signer.to_owned(),
fee_pool: pool_acc,
system_program: SYSTEM_PROGRAM_ID,
clock: clock_acc(),
}
.to_account_metas(None);
let data = InitNetworkProgramArgs {
start_epoch_timestamp: Timestamp {
timestamp: current_timestamp,
},
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_node_operator_acc_ix(signer: &Pubkey, url: String, location: u8) -> Instruction {
let accounts = InitOperatorAccs {
signer: signer.to_owned(),
operator_acc: operator_acc(signer),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitOperatorArgs {
meta: OperatorMeta { url, location },
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn init_arx_node_acc_ix(
operator_signer: &Pubkey,
node_signer: &Pubkey,
node_offset: u32,
callback_authority: &Pubkey,
cu_claim: u64,
bls_pubkey: BN254G2BLSPublicKey,
bls_pop_sig: [u8; 64],
metadata: NodeMetadata,
x25519_pubkey: [u8; 32],
primary_stake_account: &Pubkey,
staker: &Pubkey,
) -> Instruction {
let accounts = InitArxNodeAccs {
operator_signer: operator_signer.to_owned(),
operator_acc: operator_acc(operator_signer),
arx_node_acc: arx_acc(node_offset),
primary_stake_account: primary_stake_account.to_owned(),
staker: staker.to_owned(),
arcium_staking_program: ARCIUM_STAKING_PROG_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let config = ArxNodeConfig {
authority: node_signer.to_owned(),
callback_authority: callback_authority.to_owned(),
};
let data = InitArxNodeArgs {
node_offset,
cu_capacity_claim: cu_claim,
config,
bls_pubkey,
bls_pop_sig,
metadata,
x25519_pubkey,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_cluster_ix(
signer: &Pubkey,
cluster_authority: Pubkey,
cluster_offset: u32,
cluster_size: u16,
cu_price: u64,
mempool_size: MempoolSize,
td_info: Option<NodeMetadata>,
) -> Instruction {
let accounts = InitClusterAccs {
signer: signer.to_owned(),
cluster_acc: cluster_acc(cluster_offset),
authority: cluster_authority,
pool_account: fee_pool_acc(),
system_program: SYSTEM_PROGRAM_ID,
mempool: mempool_acc(cluster_offset),
execpool: execpool_acc(cluster_offset),
clock: clock_acc(),
}
.to_account_metas(None);
let data = InitClusterArgs {
cluster_size,
cluster_id: cluster_offset,
cu_price,
mempool_size,
td_info,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_recovery_peer_acc_ix(
signer: &Pubkey,
peer_offset: u32,
x25519_pubkey: [u8; 32],
primary_stake_account: &Pubkey,
staker: &Pubkey,
) -> Instruction {
let accounts = InitRecoveryPeerAccountAccs {
signer: signer.to_owned(),
recovery_peer_account: recovery_peer_acc(peer_offset),
permissioned_recovery_peers_acc: permissioned_recovery_peers_acc(),
primary_stake_account: primary_stake_account.to_owned(),
staker: staker.to_owned(),
arcium_staking_program: ARCIUM_STAKING_PROG_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitRecoveryPeerAccountArgs {
peer_offset,
signer: *signer,
x25519_pubkey,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn set_cluster_authority_ix(
signer: &Pubkey,
cluster_offset: u32,
new_authority: Option<Pubkey>,
) -> Instruction {
let accounts = SetClusterAuthorityAccs {
current_authority: signer.to_owned(),
cluster_acc: cluster_acc(cluster_offset),
}
.to_account_metas(None);
let data = SetClusterAuthorityArgs {
cluster_id: cluster_offset,
new_authority,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn set_cluster_td_info_ix(
signer: &Pubkey,
cluster_offset: u32,
td_info: Option<NodeMetadata>,
) -> Instruction {
let accounts = SetClusterTdInfoAccs {
authority: signer.to_owned(),
cluster_acc: cluster_acc(cluster_offset),
}
.to_account_metas(None);
let data = SetClusterTdInfoArgs {
cluster_id: cluster_offset,
td_info,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_mxe_part1_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
recovery_peers: [u32; MAX_RECOVERY_PEERS],
) -> Instruction {
let (program_data, _) =
Pubkey::find_program_address(&[mxe_program.as_ref()], &bpf_loader_upgradeable::id());
let accounts = InitMxePart1Accs {
signer: signer.to_owned(),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
mxe_program: *mxe_program,
program_data,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitMxePart1Args { recovery_peers }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn init_mxe_part2_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
cluster_offset: u32,
keygen_offset: u64,
key_recovery_init_offset: u64,
mxe_authority: Option<Pubkey>,
recent_slot: u64,
) -> Instruction {
let (program_data, _) =
Pubkey::find_program_address(&[mxe_program.as_ref()], &bpf_loader_upgradeable::id());
let accounts = InitMxePart2Accs {
signer: signer.to_owned(),
address_lookup_table: mxe_lut_acc(mxe_program, recent_slot),
cluster: cluster_acc(cluster_offset),
mxe: mxe_acc(mxe_program),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
executing_pool: execpool_acc(cluster_offset),
mempool: mempool_acc(cluster_offset),
mxe_keygen_computation_definition: computation_definition_acc(
mxe_program,
MXE_KEYGEN_COMPUTATION_DEFINITION_OFFSET,
),
mxe_keygen_computation: computation_acc(cluster_offset, keygen_offset),
key_recovery_init_computation: computation_acc(cluster_offset, key_recovery_init_offset),
mxe_authority,
mxe_program: *mxe_program,
program_data,
clock: clock_acc(),
pool_account: fee_pool_acc(),
instructions_sysvar: INSTRUCTIONS_SYSVAR_ID,
system_program: SYSTEM_PROGRAM_ID,
lut_program: ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitMxePart2Args {
cluster_offset,
keygen_offset,
key_recovery_init_offset,
recent_slot,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn register_account_in_lut_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
lut_slot: u64,
account: Pubkey,
) -> Instruction {
let accounts = RegisterAccountInLutAccs {
signer: signer.to_owned(),
mxe: mxe_acc(mxe_program),
mxe_program: *mxe_program,
address_lookup_table: mxe_lut_acc(mxe_program, lut_slot),
lut_program: ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = RegisterAccountInLutArgs { account }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn init_computation_definition_ix(
signer: &Pubkey,
comp_def_offset: u32,
mxe_program: &Pubkey,
circuit_len: u32,
parameters: Vec<Parameter>,
outputs: Vec<Output>,
cu_amount: u64,
circuit_source_override: Option<CircuitSource>,
lut_slot: u64,
) -> Instruction {
let comp_def_acc = computation_definition_acc(mxe_program, comp_def_offset);
let accounts = InitComputationDefinitionAccs {
signer: signer.to_owned(),
mxe: mxe_acc(mxe_program),
address_lookup_table: mxe_lut_acc(mxe_program, lut_slot),
comp_def_acc,
system_program: SYSTEM_PROGRAM_ID,
lut_program: ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitComputationDefinitionArgs {
mxe_program: *mxe_program,
comp_offset: comp_def_offset,
computation_definition: ComputationDefinitionMeta {
signature: ComputationSignature {
parameters,
outputs,
},
circuit_len,
},
circuit_source_override,
cu_amount,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_raw_circuit_acc_ix(
signer: &Pubkey,
comp_def_offset: u32,
mxe_program_id: &Pubkey,
circuit_chunk_index: u8,
) -> Instruction {
let comp_def_acc = computation_definition_acc(mxe_program_id, comp_def_offset);
let accounts = InitRawCircuitAccs {
signer: signer.to_owned(),
comp_def_acc,
comp_def_raw: raw_circuit_acc(&comp_def_acc, circuit_chunk_index),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitRawCircuitArgs {
comp_offset: comp_def_offset,
mxe_program: mxe_program_id.to_owned(),
raw_circuit_index: circuit_chunk_index,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn upload_circuit_ix(
signer: &Pubkey,
mxe_program_id: &Pubkey,
comp_def_offset: u32,
circuit_chunk_index: u8,
upload_data: [u8; 814],
offset: u32,
) -> Instruction {
let comp_def_acc = computation_definition_acc(mxe_program_id, comp_def_offset);
let accounts = UploadCircuitAccs {
signer: signer.to_owned(),
comp_def_raw: raw_circuit_acc(&comp_def_acc, circuit_chunk_index),
comp_def_acc,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = UploadCircuitArgs {
comp_offset: comp_def_offset,
mxe_program: mxe_program_id.to_owned(),
raw_circuit_index: circuit_chunk_index,
upload_data,
offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn embiggen_raw_circuit_acc_ix(
signer: &Pubkey,
comp_def_offset: u32,
mxe_program_id: &Pubkey,
circuit_chunk_index: u8,
) -> Instruction {
let comp_def_acc = computation_definition_acc(mxe_program_id, comp_def_offset);
let accounts = EmbiggenRawCircuitAccAccs {
signer: signer.to_owned(),
comp_def_raw: raw_circuit_acc(&comp_def_acc, circuit_chunk_index),
comp_def_acc,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = EmbiggenRawCircuitAccArgs {
comp_offset: comp_def_offset,
mxe_program: mxe_program_id.to_owned(),
raw_circuit_index: circuit_chunk_index,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn finalize_computation_definition_ix(
signer: &Pubkey,
comp_def_offset: u32,
mxe_program: &Pubkey,
) -> Instruction {
let comp_def_acc = computation_definition_acc(mxe_program, comp_def_offset);
let accounts = FinalizeComputationDefinitionAccs {
signer: signer.to_owned(),
comp_def_acc,
comp_def_raw: raw_circuit_acc(&comp_def_acc, 0),
}
.to_account_metas(None);
let data = FinalizeComputationDefinitionArgs {
comp_offset: comp_def_offset,
mxe_program: mxe_program.to_owned(),
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn increase_mempool_size_ix(signer: &Pubkey, cluster_offset: u32) -> Instruction {
let accounts = IncreaseMempoolSizeAccs {
signer: signer.to_owned(),
mempool: mempool_acc(cluster_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = IncreaseMempoolSizeArgs { cluster_offset }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn requeue_mxe_keygen_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
cluster_offset: u32,
computation_offset: u64,
) -> Instruction {
let accounts = RequeueMxeKeygenAccs {
signer: signer.to_owned(),
mxe: mxe_acc(mxe_program),
mempool: mempool_acc(cluster_offset),
executing_pool: execpool_acc(cluster_offset),
cluster: cluster_acc(cluster_offset),
mxe_keygen_computation: computation_acc(cluster_offset, computation_offset),
mxe_program: *mxe_program,
}
.to_account_metas(None);
let data = RequeueMxeKeygenArgs { cluster_offset }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn queue_key_recovery_init_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
cluster_offset: u32,
key_recovery_init_offset: u64,
) -> Instruction {
let accounts = QueueKeyRecoveryInitAccs {
signer: signer.to_owned(),
mxe: mxe_acc(mxe_program),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
executing_pool: execpool_acc(cluster_offset),
mempool: mempool_acc(cluster_offset),
key_recovery_init_computation_definition: computation_definition_acc(
mxe_program,
MXE_KEY_RECOVERY_INIT_COMPUTATION_DEFINITION_OFFSET,
),
key_recovery_init_computation: computation_acc(cluster_offset, key_recovery_init_offset),
mxe_program: *mxe_program,
pool_account: fee_pool_acc(),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = QueueKeyRecoveryInitArgs {
cluster_offset,
mxe_program: *mxe_program,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn propose_join_cluster_ix(
cluster_auth_signer: &Pubkey,
cluster_offset: u32,
node_offset: u32,
primary_stake_account: &Pubkey,
) -> Instruction {
let accounts = ProposeJoinClusterAccs {
cluster_authority: cluster_auth_signer.to_owned(),
cluster_acc: cluster_acc(cluster_offset),
arx_node_acc: arx_acc(node_offset),
mempool: mempool_acc(cluster_offset),
primary_stake_account: primary_stake_account.to_owned(),
clock: clock_acc(),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = ProposeJoinClusterArgs {
cluster_id: cluster_offset,
node_bump: node_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn join_cluster_ix(
node_auth_signer: &Pubkey,
cluster_offset: u32,
node_offset: u32,
join: bool,
) -> Instruction {
let accounts = JoinClusterAccs {
node_authority: node_auth_signer.to_owned(),
cluster_acc: cluster_acc(cluster_offset),
arx_node_acc: arx_acc(node_offset),
clock: clock_acc(),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = JoinClusterArgs {
cluster_id: cluster_offset,
node_bump: node_offset,
join,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn queue_computation_ix(
payer: &Pubkey,
mxe_program: &Pubkey,
computation_offset: u64,
comp_def_offset: u32,
args: ArgumentList,
cu_price_micro: u64,
callback_cu_limit: u32,
mxe_account: MXEAccount,
callback_instructions: Vec<CallbackInstruction>,
callback_transaction_count_required: u8,
) -> Result<Instruction> {
let accounts = QueueComputationAccs {
signer: payer.to_owned(),
sign_seed: signer_acc(mxe_program),
cluster: cluster_acc(mxe_account.cluster),
mxe: mxe_acc(mxe_program),
mempool: mempool_acc(mxe_account.cluster),
executing_pool: execpool_acc(mxe_account.cluster),
comp_def_acc: computation_definition_acc(mxe_program, comp_def_offset),
pool_account: fee_pool_acc(),
system_program: SYSTEM_PROGRAM_ID,
clock: clock_acc(),
comp: computation_acc(mxe_account.cluster, computation_offset),
}
.to_account_metas(None);
let data = QueueComputationArgs {
mxe_program: *mxe_program,
comp_offset: computation_offset,
computation_definition_offset: comp_def_offset,
callback_cu_limit,
padding: 0,
cu_price_micro,
args,
custom_callback_instructions: callback_instructions,
callback_transactions_required: callback_transaction_count_required,
}
.data();
Ok(Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
})
}
pub fn propose_fee_ix(
node_auth_signer: Pubkey,
cluster_offset: u32,
node_offset: u32,
proposed_fee: u64,
) -> Instruction {
let accounts = ProposeFeeAccs {
node_authority: node_auth_signer,
cluster_acc: cluster_acc(cluster_offset),
arx_node_acc: arx_acc(node_offset),
clock: clock_acc(),
}
.to_account_metas(None);
let data = ProposeFeeArgs {
cluster_offset,
node_offset,
proposed_fee,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn vote_fee_ix(
node_auth_signer: Pubkey,
cluster_offset: u32,
node_offset: u32,
fee_vote: u64,
) -> Instruction {
let accounts = VoteFeeAccs {
node_authority: node_auth_signer,
cluster_acc: cluster_acc(cluster_offset),
arx_node_acc: arx_acc(node_offset),
clock: clock_acc(),
}
.to_account_metas(None);
let data = VoteFeeArgs {
cluster_offset,
node_offset,
fee_vote,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn set_leader_choice_ix(
node_auth_signer: Pubkey,
cluster_offset: u32,
node_offset: u32,
choice: LeaderChoice,
) -> Instruction {
let accounts = SetLeaderChoiceAccs {
node_authority: node_auth_signer,
cluster_acc: cluster_acc(cluster_offset),
arx_node_acc: arx_acc(node_offset),
mempool: mempool_acc(cluster_offset),
}
.to_account_metas(None);
let data = SetLeaderChoiceArgs {
cluster_offset,
node_offset,
choice,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn claim_node_fees_ix(
staking_pool_signer: &Pubkey,
primary_stake_account: &Pubkey,
cluster_offset: u32,
node_offset: u32,
) -> Instruction {
let accounts = ClaimNodeFeesAccs {
staking_pool_signer: *staking_pool_signer,
primary_stake_account: *primary_stake_account,
cluster: cluster_acc(cluster_offset),
node: arx_acc(node_offset),
pool: fee_pool_acc(),
}
.to_account_metas(None);
let data = ClaimNodeFeesArgs {
cluster_offset,
node_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn bump_epoch_cluster_ix(cluster_offset: u32) -> Instruction {
let accounts = BumpEpochClusterAccs {
cluster_acc: cluster_acc(cluster_offset),
clock: clock_acc(),
}
.to_account_metas(None);
let data = BumpEpochClusterArgs { cluster_offset }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn activate_arx_ix(signer: &Pubkey, node_offset: u32) -> Instruction {
let arx_node_acc = arx_acc(node_offset);
let accounts = ActivateArxAccs {
signer: signer.key(),
arx_node_acc,
}
.to_account_metas(None);
let data = ActivateArxArgs { node_offset }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn deactivate_arx_ix(
signer: &Pubkey,
node_offset: u32,
cluster_offset: Option<u32>,
) -> Instruction {
let cluster_acc = cluster_offset.map(cluster_acc);
let arx_node_acc = arx_acc(node_offset);
let accounts = DeactivateArxAccs {
signer: signer.key(),
arx_node_acc,
clock: clock_acc(),
cluster_acc,
}
.to_account_metas(None);
let data = DeactivateArxArgs { node_offset }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn activate_cluster_ix(signer: &Pubkey, cluster_offset: u32) -> Instruction {
let accounts = ActivateClusterAccs {
authority: signer.key(),
cluster_acc: cluster_acc(cluster_offset),
clock: clock_acc(),
}
.to_account_metas(None);
let data = ActivateClusterArgs {
cluster_id: cluster_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn deactivate_cluster_ix(
signer: &Pubkey,
cluster_offset: u32,
deactivation_epoch: Epoch,
) -> Instruction {
let accounts = DeactivateClusterAccs {
authority: signer.key(),
cluster_acc: cluster_acc(cluster_offset),
clock: clock_acc(),
}
.to_account_metas(None);
let data = DeactivateClusterArgs {
cluster_id: cluster_offset,
deactivation_epoch,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn set_mxe_keys_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
node_offset: u32,
cluster_offset: u32,
mxe_x25519_pubkey: [u8; 32],
mxe_ed25519_verifying_key: [u8; 32],
mxe_elgamal_pubkey: [u8; 32],
mxe_pubkey_validity_proof: [u8; 64],
) -> Instruction {
let accounts = SetMxeKeysAccs {
signer: signer.key(),
node: arx_acc(node_offset),
mxe: mxe_acc(mxe_program),
cluster_acc: cluster_acc(cluster_offset),
}
.to_account_metas(None);
let data = SetMxeKeysArgs {
node_offset,
_mxe_program: *mxe_program,
mxe_x25519_pubkey,
mxe_ed25519_verifying_key,
mxe_elgamal_pubkey,
mxe_pubkey_validity_proof,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn finalize_mxe_keys_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
cluster_offset: u32,
) -> Instruction {
let accounts = FinalizeMxeKeysAccs {
signer: signer.key(),
mxe: mxe_acc(mxe_program),
cluster: cluster_acc(cluster_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = FinalizeMxeKeysArgs {
_mxe_program: *mxe_program,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn set_mxe_recovery_keys_init_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
node_offset: u32,
cluster_offset: u32,
nonce: u128,
encrypted_mxe_keys: [[u8; 32]; MXE_KEYS_ENC_COUNT],
key_material_hash: [u8; 32],
bls_sig: [u8; 64],
) -> Instruction {
let accounts = SetMxeRecoveryKeysInitAccs {
signer: signer.key(),
node: arx_acc(node_offset),
mxe: mxe_acc(mxe_program),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
cluster_acc: cluster_acc(cluster_offset),
}
.to_account_metas(None);
let data = SetMxeRecoveryKeysInitArgs {
node_offset,
_mxe_program: *mxe_program,
nonce: nonce.to_le_bytes(),
encrypted_mxe_keys,
key_material_hash,
bls_sig,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn extend_recovery_keyshares_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
node_offset: u32,
cluster_offset: u32,
keyshares_offset: u32,
keyshares: Vec<[[u8; 32]; 5]>,
) -> Instruction {
let accounts = ExtendRecoveryKeysharesAccs {
signer: signer.key(),
node: arx_acc(node_offset),
mxe: mxe_acc(mxe_program),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
cluster_acc: cluster_acc(cluster_offset),
}
.to_account_metas(None);
let data = ExtendRecoveryKeysharesArgs {
node_offset,
_mxe_program: *mxe_program,
keyshares_offset,
keyshares,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn finalize_key_recovery_shares_upload_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
node_offset: u32,
cluster_offset: u32,
computation_offset: u64,
) -> Instruction {
let accounts = FinalizeKeyRecoverySharesUploadAccs {
signer: signer.key(),
node: arx_acc(node_offset),
mxe: mxe_acc(mxe_program),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
cluster_acc: cluster_acc(cluster_offset),
comp: computation_acc(cluster_offset, computation_offset),
}
.to_account_metas(None);
let data = FinalizeKeyRecoverySharesUploadArgs {
node_offset,
_mxe_program: *mxe_program,
computation_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn set_migration_ix(authority: &Pubkey, mxe_program: &Pubkey) -> Instruction {
let accounts = RecoverMxeAccs {
authority: authority.key(),
mxe: mxe_acc(mxe_program),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
mxe_program: *mxe_program,
}
.to_account_metas(None);
let data = RecoverMxeArgs {
mxe_program: *mxe_program,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn set_active_ix(signer: &Pubkey, mxe_program: &Pubkey) -> Instruction {
let accounts = SetActiveAccs {
signer: signer.key(),
mxe: mxe_acc(mxe_program),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
mxe_recovery_account: mxe_recovery_acc(mxe_program),
mxe_program: *mxe_program,
}
.to_account_metas(None);
let data = SetActiveArgs {
mxe_program: *mxe_program,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_key_recovery_execution_part1_ix(
authority: &Pubkey,
payer: &Pubkey,
original_mxe_program: &Pubkey,
backup_mxe_program: &Pubkey,
) -> Instruction {
let accounts = InitKeyRecoveryExecutionPart1Accs {
authority: authority.key(),
payer: payer.key(),
original_mxe: mxe_acc(original_mxe_program),
mxe_recovery_account: mxe_recovery_acc(original_mxe_program),
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitKeyRecoveryExecutionPart1Args {
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn init_key_recovery_execution_part2_ix(
payer: &Pubkey,
original_mxe_program: &Pubkey,
backup_mxe_program: &Pubkey,
cluster_offset: u32,
key_recovery_finalize_offset: u64,
) -> Instruction {
let accounts = InitKeyRecoveryExecutionPart2Accs {
authority: payer.key(),
payer: payer.key(),
original_mxe: mxe_acc(original_mxe_program),
backup_mxe: mxe_acc(backup_mxe_program),
recovery_cluster_acc: recovery_cluster_acc(original_mxe_program),
mxe_recovery_account: mxe_recovery_acc(original_mxe_program),
key_recovery_finalize_comp_def: computation_definition_acc(
backup_mxe_program,
MXE_KEY_RECOVERY_FINALIZE_COMPUTATION_DEFINITION_OFFSET,
),
key_recovery_finalize_computation: computation_acc(
cluster_offset,
key_recovery_finalize_offset,
),
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitKeyRecoveryExecutionPart2Args {
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
cluster_offset,
key_recovery_finalize_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::type_complexity)]
pub fn submit_key_recovery_share_ix(
signer: &Pubkey,
original_mxe_program: &Pubkey,
backup_mxe_program: &Pubkey,
peer_offset: u32,
peer_index: u32,
share: [[u8; 32]; 5],
) -> Instruction {
let accounts = SubmitKeyRecoveryShareAccs {
signer: signer.key(),
recovery_peer_account: recovery_peer_acc(peer_offset),
original_mxe: mxe_acc(original_mxe_program),
recovery_cluster_acc: recovery_cluster_acc(original_mxe_program),
mxe_recovery_account: mxe_recovery_acc(original_mxe_program),
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
}
.to_account_metas(None);
let data = SubmitKeyRecoveryShareArgs {
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
peer_offset,
peer_index,
share,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn queue_key_recovery_finalize_ix(
authority: &Pubkey,
payer: &Pubkey,
original_mxe_program: &Pubkey,
backup_mxe_program: &Pubkey,
cluster_offset: u32,
key_recovery_finalize_offset: u64,
lut_slot: u64,
) -> Instruction {
let accounts = FinalizeKeyRecoveryExecutionAccs {
authority: authority.key(),
payer: payer.key(),
original_mxe: mxe_acc(original_mxe_program),
backup_mxe: mxe_acc(backup_mxe_program),
recovery_cluster_acc: recovery_cluster_acc(original_mxe_program),
mxe_recovery_account: mxe_recovery_acc(original_mxe_program),
key_recovery_finalize_comp_def: computation_definition_acc(
backup_mxe_program,
MXE_KEY_RECOVERY_FINALIZE_COMPUTATION_DEFINITION_OFFSET,
),
key_recovery_finalize_computation: computation_acc(
cluster_offset,
key_recovery_finalize_offset,
),
executing_pool: execpool_acc(cluster_offset),
mempool: mempool_acc(cluster_offset),
pool_account: fee_pool_acc(),
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
system_program: SYSTEM_PROGRAM_ID,
address_lookup_table: mxe_lut_acc(original_mxe_program, lut_slot),
cluster_acc: cluster_acc(cluster_offset),
lut_program: ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
}
.to_account_metas(None);
let data = FinalizeKeyRecoveryExecutionArgs {
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
cluster_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn close_successful_key_recovery_ix(
authority: &Pubkey,
original_mxe_program: &Pubkey,
backup_mxe_program: &Pubkey,
backup_cluster_offset: u32,
key_recovery_finalize_offset: u64,
) -> Instruction {
let accounts = CloseKeyRecoveryAccs {
authority: authority.key(),
original_mxe: mxe_acc(original_mxe_program),
backup_mxe: mxe_acc(backup_mxe_program),
mxe_recovery_account: mxe_recovery_acc(original_mxe_program),
key_recovery_finalize_comp_def: computation_definition_acc(
backup_mxe_program,
MXE_KEY_RECOVERY_FINALIZE_COMPUTATION_DEFINITION_OFFSET,
),
key_recovery_finalize_computation: computation_acc(
backup_cluster_offset,
key_recovery_finalize_offset,
),
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
}
.to_account_metas(None);
let data = CloseKeyRecoveryArgs {
original_mxe_program: *original_mxe_program,
backup_cluster_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn close_aborted_key_recovery_ix(
authority: &Pubkey,
original_mxe_program: &Pubkey,
backup_mxe_program: &Pubkey,
backup_cluster_offset: u32,
key_recovery_finalize_offset: u64,
) -> Instruction {
let accounts = CloseAbortedKeyRecoveryAccs {
authority: authority.key(),
original_mxe: mxe_acc(original_mxe_program),
backup_mxe: mxe_acc(backup_mxe_program),
mxe_recovery_account: mxe_recovery_acc(original_mxe_program),
key_recovery_finalize_comp_def: computation_definition_acc(
backup_mxe_program,
MXE_KEY_RECOVERY_FINALIZE_COMPUTATION_DEFINITION_OFFSET,
),
key_recovery_finalize_computation: computation_acc(
backup_cluster_offset,
key_recovery_finalize_offset,
),
executing_pool: execpool_acc(backup_cluster_offset),
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
}
.to_account_metas(None);
let data = CloseAbortedKeyRecoveryArgs {
original_mxe_program: *original_mxe_program,
backup_cluster_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn finalize_key_recovery_callback_ix(
signer: &Pubkey,
original_mxe_program: &Pubkey,
backup_mxe_program: &Pubkey,
cluster_offset: u32,
comp_offset: u64,
node_offset: u32,
execution_status: ExecutionStatus,
callback_transaction_index: u8,
output_bytes: Vec<u8>,
bls_sig: [u8; 64],
) -> Instruction {
let accounts = FinalizeKeyRecoveryCallbackAccs {
signer: signer.key(),
original_mxe: mxe_acc(original_mxe_program),
backup_mxe: mxe_acc(backup_mxe_program),
mxe_recovery_account: mxe_recovery_acc(original_mxe_program),
computation: computation_acc(cluster_offset, comp_offset),
comp_def: computation_definition_acc(
backup_mxe_program,
MXE_KEY_RECOVERY_FINALIZE_COMPUTATION_DEFINITION_OFFSET,
),
node: arx_acc(node_offset),
cluster_acc: cluster_acc(cluster_offset),
executing_pool: execpool_acc(cluster_offset),
mempool: mempool_acc(cluster_offset),
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
}
.to_account_metas(None);
let data = FinalizeKeyRecoveryCallbackArgs {
original_mxe_program: *original_mxe_program,
backup_mxe_program: *backup_mxe_program,
cluster_offset,
comp_offset,
node_offset,
execution_status,
callback_transaction_index,
output_bytes,
bls_sig,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn claim_computation_rent_ix(
signer: &Pubkey,
computation_offset: u64,
cluster_offset: u32,
) -> Instruction {
let accounts = ClaimComputationRentAccs {
signer: signer.key(),
comp: computation_acc(cluster_offset, computation_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = ClaimComputationRentArgs {
comp_offset: computation_offset,
cluster_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn callback_computation_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
computation_offset: u64,
comp_def_offset: u32,
node_offset: u32,
cluster_offset: u32,
execution_status: ExecutionStatus,
callback_transaction_index: u8,
) -> Instruction {
let accounts = CallbackComputationAccs {
signer: signer.key(),
node: arx_acc(node_offset),
comp: computation_acc(cluster_offset, computation_offset),
mxe: mxe_acc(mxe_program),
cluster_acc: cluster_acc(cluster_offset),
mempool: mempool_acc(cluster_offset),
executing_pool: execpool_acc(cluster_offset),
comp_def_acc: computation_definition_acc(mxe_program, comp_def_offset),
instructions_sysvar: INSTRUCTIONS_SYSVAR_ID,
}
.to_account_metas(None);
let data = CallbackComputationArgs {
node_offset,
comp_def_offset,
comp_offset: computation_offset,
mxe_program: *mxe_program,
execution_status,
callback_transaction_index,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn callback_computation_ix_user(
mxe_prog_id: &Pubkey,
callback_accs: Vec<CallbackAccount>,
comp_def_offset: u32,
callback_discriminator: &[u8],
output_bytes: Vec<u8>,
) -> Instruction {
let mut bytes = Vec::with_capacity(callback_discriminator.len() + output_bytes.len());
bytes.extend_from_slice(callback_discriminator);
bytes.extend_from_slice(&output_bytes);
let accounts = vec![
AccountMeta {
pubkey: ARCIUM_PROG_ID,
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: computation_definition_acc(mxe_prog_id, comp_def_offset),
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: INSTRUCTIONS_SYSVAR_ID,
is_signer: false,
is_writable: false,
},
]
.into_iter()
.chain(callback_accs.iter().map(|c| AccountMeta {
pubkey: c.pubkey,
is_writable: c.is_writable,
is_signer: false,
}))
.collect::<Vec<AccountMeta>>()
.to_account_metas(None);
Instruction {
program_id: mxe_prog_id.to_owned(),
accounts,
data: bytes,
}
}
pub fn claim_failure_init_ix(
signer: &Pubkey,
mxe_program_id: &Pubkey,
cluster_offset: u32,
comp_def_offset: u32,
computation_offset: u64,
node_offset: u32,
output_len_bytes: u32,
) -> Instruction {
let accounts = ClaimFailureInitAccs {
signer: signer.key(),
node_acc: arx_acc(node_offset),
mxe: mxe_acc(mxe_program_id),
cluster_acc: cluster_acc(cluster_offset),
comp_acc: computation_acc(cluster_offset, computation_offset),
comp_def_acc: computation_definition_acc(mxe_program_id, comp_def_offset),
failure_acc: failure_claim_acc(mxe_program_id, computation_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = ClaimFailureInitArgs {
comp_offset: computation_offset,
node_offset,
mxe_program: mxe_program_id.to_owned(),
output_len_bytes,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn claim_failure_append_ix(
signer: &Pubkey,
mxe_program_id: &Pubkey,
computation_offset: u64,
chunk: Vec<u8>,
failure_claim_offset: u32,
) -> Instruction {
let accounts = ClaimFailureAppendAccs {
signer: signer.key(),
failure_acc: failure_claim_acc(mxe_program_id, computation_offset),
}
.to_account_metas(None);
let data = ClaimFailureAppendArgs {
comp_offset: computation_offset,
mxe_program: mxe_program_id.to_owned(),
chunk,
failure_claim_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn claim_failure_finalize_ix(
signer: &Pubkey,
mxe_program_id: &Pubkey,
cluster_offset: u32,
computation_offset: u64,
node_offset: u32,
) -> Instruction {
let accounts = ClaimFailureFinalizeAccs {
signer: signer.key(),
failure_acc: failure_claim_acc(mxe_program_id, computation_offset),
executing_pool: execpool_acc(cluster_offset),
mempool: mempool_acc(cluster_offset),
comp: computation_acc(cluster_offset, computation_offset),
cluster_acc: cluster_acc(cluster_offset),
mxe: mxe_acc(mxe_program_id),
}
.to_account_metas(None);
let data = ClaimFailureFinalizeArgs {
comp_offset: computation_offset,
node_offset,
mxe_program: mxe_program_id.to_owned(),
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn reclaim_expired_computation_fee_ix(
signer: &Pubkey,
mxe_program_id: &Pubkey,
cluster_offset: u32,
computation_offset: u64,
) -> Instruction {
let accounts = ReclaimExpiredComputationFeeAccs {
signer: signer.key(),
mxe: mxe_acc(mxe_program_id),
cluster_acc: cluster_acc(cluster_offset),
comp: computation_acc(cluster_offset, computation_offset),
executing_pool: execpool_acc(cluster_offset),
pool_account: fee_pool_acc(),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = ReclaimExpiredComputationFeeArgs {
comp_offset: computation_offset,
mxe_program: mxe_program_id.to_owned(),
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn reclaim_failure_rent_idempotent_ix(
signer: &Pubkey,
recipient: &Pubkey,
mxe_program_id: &Pubkey,
computation_offset: u64,
) -> Instruction {
let accounts = ReclaimFailureRentIdempotentAccs {
signer: signer.key(),
recipient: recipient.key(),
failure_acc: failure_claim_acc(mxe_program_id, computation_offset),
}
.to_account_metas(None);
let data = ReclaimFailureRentIdempotentArgs {
comp_offset: computation_offset,
mxe_program: mxe_program_id.to_owned(),
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn update_current_epoch_idempotent_ix() -> Instruction {
let accounts = UpdateCurrentEpochIdempotentAccs { clock: clock_acc() }.to_account_metas(None);
let data = UpdateCurrentEpochIdempotentArgs {}.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn set_arx_node_config_ix(
signer: &Pubkey,
node_offset: u32,
config: ArxNodeConfig,
) -> Instruction {
let accounts = SetArxNodeConfigAccs {
signer: signer.key(),
arx_node_acc: arx_acc(node_offset),
}
.to_account_metas(None);
let data = SetArxNodeConfigArgs {
node_offset,
config,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn set_arx_node_metadata_ix(
signer: &Pubkey,
node_offset: u32,
metadata: NodeMetadata,
) -> Instruction {
let accounts = SetArxNodeMetadataAccs {
signer: signer.key(),
arx_node_acc: arx_acc(node_offset),
}
.to_account_metas(None);
let data = SetArxNodeMetadataArgs {
node_offset,
meta: metadata,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn submit_aggregated_bls_pubkey_ix(
node_authority: &Pubkey,
cluster_offset: u32,
node_offset: u32,
aggregated_bls_pubkey: BN254G2BLSPublicKey,
) -> Instruction {
let accounts = SubmitAggregatedBlsPubkeyAccs {
cluster_acc: cluster_acc(cluster_offset),
arx_node_acc: arx_acc(node_offset),
node_authority: node_authority.key(),
}
.to_account_metas(None);
let data = SubmitAggregatedBlsPubkeyArgs {
cluster_id: cluster_offset,
aggregated_bls_pubkey,
node_bump: node_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn deactivate_computation_definition_ix(
signer: &Pubkey,
comp_offset: u32,
mxe_program: &Pubkey,
) -> Instruction {
let accounts = DeactivateComputationDefinitionAccs {
signer: signer.to_owned(),
mxe: mxe_acc(mxe_program),
comp_def_acc: computation_definition_acc(mxe_program, comp_offset),
}
.to_account_metas(None);
let data = DeactivateComputationDefinitionArgs {
comp_offset,
mxe_program: *mxe_program,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn close_computation_definition_ix(
signer: &Pubkey,
comp_offset: u32,
mxe_program: &Pubkey,
cluster_offset: u32,
) -> Instruction {
let accounts = CloseComputationDefinitionAccs {
signer: signer.to_owned(),
mxe: mxe_acc(mxe_program),
comp_def_acc: computation_definition_acc(mxe_program, comp_offset),
executing_pool: execpool_acc(cluster_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = CloseComputationDefinitionArgs {
comp_offset,
mxe_program: *mxe_program,
cluster_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn close_computation_definition_buffers_ix(
signer: &Pubkey,
comp_offset: u32,
mxe_program: &Pubkey,
raw_circuit_index: u8,
) -> Instruction {
let comp_def_acc = computation_definition_acc(mxe_program, comp_offset);
let accounts = CloseComputationDefinitionBuffersAccs {
signer: signer.to_owned(),
mxe: mxe_acc(mxe_program),
comp_def_acc,
comp_def_raw: raw_circuit_acc(&comp_def_acc, raw_circuit_index),
}
.to_account_metas(None);
let data = CloseComputationDefinitionBuffersArgs {
comp_offset,
mxe_program: *mxe_program,
raw_circuit_index,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
#[allow(clippy::too_many_arguments)]
pub fn close_mxe_ix(
signer: &Pubkey,
mxe_program: &Pubkey,
cluster_offset: u32,
keygen_offset: u64,
key_recovery_init_offset: u64,
kr_init_comp_def_exists: bool,
) -> Instruction {
let accounts = CloseMxeAccs {
signer: signer.to_owned(),
mxe_program: *mxe_program,
mxe: mxe_acc(mxe_program),
mxe_keygen_computation: computation_acc(cluster_offset, keygen_offset),
mxe_keygen_comp_def: computation_definition_acc(
mxe_program,
RESERVED_MXE_KEYGEN_COMP_DEF_OFFSET,
),
mxe_key_recovery_init_comp_def: if kr_init_comp_def_exists {
Some(computation_definition_acc(
mxe_program,
RESERVED_MXE_KEY_RECOVERY_INIT_COMP_DEF_OFFSET,
))
} else {
None
},
key_recovery_init_computation: Some(computation_acc(
cluster_offset,
key_recovery_init_offset,
)),
recovery_cluster_acc: recovery_cluster_acc(mxe_program),
}
.to_account_metas(None);
let data = CloseMxeArgs {
cluster_offset,
keygen_offset,
}
.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub mod staking {
use super::*;
use crate::{
idl::{
arcium::ID as ARCIUM_PROG_ID,
arcium_staking::{
client::{
accounts::{
ActivatePrimaryStake as ActivatePrimaryStakeAccs,
AddPrimaryStakeToLegacyAcc as AddPrimaryStakeToLegacyAccAccs,
ClaimPrimaryStakeRewards as ClaimPrimaryStakeRewardsAccs,
CloseDelegatedStake as CloseDelegatedStakeAccs,
DeactivatePrimaryStake as DeactivatePrimaryStakeAccs,
DelegateStake as DelegateStakeAccs,
FinalizeEpochRewards as FinalizeEpochRewardsAccs,
InitClusterStakeState as InitClusterStakeStateAccs,
InitDelegatedStakeAcc as InitDelegatedStakeAccs,
InitMxeRecoveryStakeState as InitMxeRecoveryStakeStateAccs,
InitPrimaryStake as InitPrimaryStakeAccs,
InitStakeMasterAcc as InitDelegatedStakeMasterAccs,
MergeDelegatedStakeAccount as MergeDelegatedStakeAccountAccs,
ModifyPrimaryStake as ModifyPrimaryStakeAccs,
SplitDelegatedStakeAccount as SplitDelegatedStakeAccountAccs,
UndelegateStake as UndelegateStakeAccs,
},
args::{
ActivatePrimaryStake as ActivatePrimaryStakeArgs,
AddPrimaryStakeToLegacyAcc as AddPrimaryStakeToLegacyAccArgs,
ClaimPrimaryStakeRewards as ClaimPrimaryStakeRewardsArgs,
CloseDelegatedStake as CloseDelegatedStakeArgs,
DeactivatePrimaryStake as DeactivatePrimaryStakeArgs,
DelegateStake as DelegateStakeArgs,
FinalizeEpochRewards as FinalizeEpochRewardsArgs,
InitClusterStakeState as InitClusterStakeStateArgs,
InitDelegatedStakeAcc as InitDelegatedStakeArgs,
InitMxeRecoveryStakeState as InitMxeRecoveryStakeStateArgs,
InitPrimaryStake as InitPrimaryStakeArgs,
InitStakeMasterAcc as InitDelegatedStakeMasterArgs,
MergeDelegatedStakeAccount as MergeDelegatedStakeAccountArgs,
ModifyPrimaryStake as ModifyPrimaryStakeArgs,
SplitDelegatedStakeAccount as SplitDelegatedStakeAccountArgs,
UndelegateStake as UndelegateStakeArgs,
},
},
types::{Epoch, Hash, MTProof, RewardBatch, RewardClaim},
ID as ARCIUM_STAKING_PROG_ID,
},
},
pda::{
arx_acc,
clock_acc,
cluster_acc,
fee_pool_acc,
staking::{
cluster_stake_state_acc,
delegated_stake_acc,
mxe_recovery_stake_state_acc,
primary_stake_acc,
stake_master_acc,
staking_pool_acc,
},
ARCIUM_TOKEN_MINT,
},
};
use anchor_spl::{
associated_token::get_associated_token_address,
token::ID as TOKEN_PROGRAM_ID,
};
pub fn init_primary_stake_acc_ix(
signer: &Pubkey,
amount: u64,
fee_basis_points: u16,
) -> Instruction {
let primary_stake_acc = primary_stake_acc(signer);
let pool_acc = staking_pool_acc();
let accounts = InitPrimaryStakeAccs {
from: signer.to_owned(),
from_ta: get_associated_token_address(signer, &ARCIUM_TOKEN_MINT),
primary_stake_account: primary_stake_acc.key(),
mint: ARCIUM_TOKEN_MINT,
pool_account: pool_acc,
pool_ata: get_associated_token_address(&pool_acc, &ARCIUM_TOKEN_MINT),
clock: clock_acc(),
system_program: SYSTEM_PROGRAM_ID,
token_program: TOKEN_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitPrimaryStakeArgs {
amount,
fee_basis_points,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn add_primary_stake_to_legacy_acc_ix(
signer: &Pubkey,
amount: u64,
fee_basis_points: u16,
) -> Instruction {
let pool_acc = staking_pool_acc();
let accounts = AddPrimaryStakeToLegacyAccAccs {
from: signer.to_owned(),
from_ta: get_associated_token_address(signer, &ARCIUM_TOKEN_MINT),
primary_stake_account: primary_stake_acc(signer),
mint: ARCIUM_TOKEN_MINT,
pool_account: pool_acc,
pool_ata: get_associated_token_address(&pool_acc, &ARCIUM_TOKEN_MINT),
clock: clock_acc(),
system_program: SYSTEM_PROGRAM_ID,
token_program: TOKEN_PROGRAM_ID,
}
.to_account_metas(None);
let data = AddPrimaryStakeToLegacyAccArgs {
amount,
fee_basis_points,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn activate_primary_stake_acc_ix(signer: &Pubkey, lockup_epochs: u64) -> Instruction {
let accounts = ActivatePrimaryStakeAccs {
signer: signer.to_owned(),
primary_stake_account: primary_stake_acc(signer),
clock: clock_acc(),
}
.to_account_metas(None);
let data = ActivatePrimaryStakeArgs {
lockup_epochs: Epoch(lockup_epochs),
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn deactivate_primary_stake_acc_ix(
signer: &Pubkey,
arx_node_offset: Option<u32>,
) -> Instruction {
let accounts = DeactivatePrimaryStakeAccs {
signer: signer.to_owned(),
primary_stake_account: primary_stake_acc(signer),
clock: clock_acc(),
}
.to_account_metas(None);
let data = DeactivatePrimaryStakeArgs {
node_offset: arx_node_offset,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn modify_primary_stake_ix(
signer: &Pubkey,
diff: i64,
arx_node: Option<Pubkey>,
mempool: Option<Pubkey>,
) -> Instruction {
let pool_acc = staking_pool_acc();
let accounts = ModifyPrimaryStakeAccs {
signer: signer.to_owned(),
signer_ta: get_associated_token_address(signer, &ARCIUM_TOKEN_MINT),
primary_stake_account: primary_stake_acc(signer),
mint: ARCIUM_TOKEN_MINT,
pool_account: pool_acc,
pool_ata: get_associated_token_address(&pool_acc, &ARCIUM_TOKEN_MINT),
clock: clock_acc(),
arx_node,
mempool,
system_program: SYSTEM_PROGRAM_ID,
token_program: TOKEN_PROGRAM_ID,
}
.to_account_metas(None);
let data = ModifyPrimaryStakeArgs { diff }.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn finalize_epoch_rewards_ix(
signer: &Pubkey,
primary_stake_owner: &Pubkey,
cluster_offset: u32,
node_offset: u32,
) -> Instruction {
let pool_account = staking_pool_acc();
let mint = ARCIUM_TOKEN_MINT;
let primary_stake_acc = primary_stake_acc(primary_stake_owner);
let accounts = FinalizeEpochRewardsAccs {
signer: signer.key(),
primary_stake_owner: primary_stake_owner.key(),
primary_stake_owner_ata: get_associated_token_address(primary_stake_owner, &mint),
primary_stake_account: primary_stake_acc,
arx_node_acc: arx_acc(node_offset),
cluster_acc: cluster_acc(cluster_offset),
fee_pool: fee_pool_acc(),
pool_account,
pool_ata: get_associated_token_address(&pool_account, &mint),
clock: clock_acc(),
cluster_stake_state: cluster_stake_state_acc(cluster_offset),
arcium_program: ARCIUM_PROG_ID,
token_program: TOKEN_PROGRAM_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = FinalizeEpochRewardsArgs {
cluster_offset,
node_offset,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub const REWARDS_MT_HEIGHT: usize = 15;
pub fn claim_primary_stake_rewards_ix(
signer: &Pubkey,
destination: &Pubkey,
leaf_index: u16,
opening: [[u8; 32]; REWARDS_MT_HEIGHT],
claim: RewardClaim,
) -> Instruction {
let accounts = ClaimPrimaryStakeRewardsAccs {
signer: signer.to_owned(),
destination: destination.to_owned(),
primary_stake_account: primary_stake_acc(signer),
pool_account: staking_pool_acc(),
}
.to_account_metas(None);
let data = ClaimPrimaryStakeRewardsArgs {
proof: MTProof {
leaf_index,
opening: opening.map(Hash),
},
claims: RewardBatch { claims: [claim] },
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn init_cluster_stake_state_ix(payer: &Pubkey, cluster_offset: u32) -> Instruction {
let accounts = InitClusterStakeStateAccs {
payer: payer.to_owned(),
cluster_stake_state: cluster_stake_state_acc(cluster_offset),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitClusterStakeStateArgs { cluster_offset }.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn init_mxe_recovery_stake_state_ix(payer: &Pubkey, mxe_program: &Pubkey) -> Instruction {
let accounts = InitMxeRecoveryStakeStateAccs {
payer: payer.to_owned(),
mxe_recovery_stake_state: mxe_recovery_stake_state_acc(mxe_program),
instructions_sysvar: INSTRUCTIONS_SYSVAR_ID,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitMxeRecoveryStakeStateArgs {
mxe_program: *mxe_program,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn init_delegated_stake_master_acc_ix(signer: &Pubkey, owner: &Pubkey) -> Instruction {
let accounts = InitDelegatedStakeMasterAccs {
signer: signer.to_owned(),
master_stake_account: stake_master_acc(owner),
owner: owner.to_owned(),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitDelegatedStakeMasterArgs {}.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn init_delegated_stake_acc_ix(
signer: &Pubkey,
stake_offset: u128,
amount: u64,
) -> Instruction {
let accounts = InitDelegatedStakeAccs {
from: signer.to_owned(),
from_ata: get_associated_token_address(signer, &ARCIUM_TOKEN_MINT),
master_stake_account: stake_master_acc(signer),
user_stake_account: delegated_stake_acc(stake_offset),
mint: ARCIUM_TOKEN_MINT,
pool_account: staking_pool_acc(),
pool_ata: get_associated_token_address(&staking_pool_acc(), &ARCIUM_TOKEN_MINT),
system_program: SYSTEM_PROGRAM_ID,
token_program: TOKEN_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitDelegatedStakeArgs {
stake_offset,
amount,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn delegate_stake_ix(
signer: &Pubkey,
stake_offset: u128,
primary_stake_owner: &Pubkey,
lockup_epochs: u64,
) -> Instruction {
let accounts = DelegateStakeAccs {
signer: signer.to_owned(),
primary_acc_owner: primary_stake_owner.to_owned(),
user_stake_account: delegated_stake_acc(stake_offset),
primary: primary_stake_acc(primary_stake_owner),
clock: clock_acc(),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = DelegateStakeArgs {
stake_offset,
lockup_epochs: Epoch(lockup_epochs),
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn undelegate_stake_ix(
signer: &Pubkey,
stake_offset: u128,
primary_stake_owner: &Pubkey,
) -> Instruction {
let accounts = UndelegateStakeAccs {
signer: signer.to_owned(),
user_stake_account: delegated_stake_acc(stake_offset),
primary: primary_stake_acc(primary_stake_owner),
clock: clock_acc(),
}
.to_account_metas(None);
let data = UndelegateStakeArgs { stake_offset }.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn split_delegated_stake_account_ix(
_primary_stake_owner_target: &Pubkey,
delegation_authority: &Pubkey,
withdrawal_authority: &Pubkey,
stake_offset: u128,
stake_offset_new: u128,
new_acc_balance: u64,
) -> Instruction {
let accounts = SplitDelegatedStakeAccountAccs {
delegation_authority: delegation_authority.to_owned(),
withdrawal_authority: withdrawal_authority.to_owned(),
delegation_master: stake_master_acc(delegation_authority),
withdrawal_master: stake_master_acc(withdrawal_authority),
old_stake_account: delegated_stake_acc(stake_offset),
new_stake_account: delegated_stake_acc(stake_offset_new),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = SplitDelegatedStakeAccountArgs {
new_acc_balance,
_stake_offset: stake_offset,
_stake_offset_new: stake_offset_new,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn merge_delegated_stake_account_ix(
_primary_stake_owner_target: &Pubkey,
delegation_authority: &Pubkey,
withdrawal_authority: &Pubkey,
stake_offset_keep: u128,
stake_offset_close: u128,
) -> Instruction {
let accounts = MergeDelegatedStakeAccountAccs {
delegation_authority: delegation_authority.to_owned(),
withdrawal_authority: withdrawal_authority.to_owned(),
delegation_master: stake_master_acc(delegation_authority),
withdrawal_master: stake_master_acc(withdrawal_authority),
stake_acc_to_keep: delegated_stake_acc(stake_offset_keep),
stake_acc_to_close: delegated_stake_acc(stake_offset_close),
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = MergeDelegatedStakeAccountArgs {
_stake_offset_keep: stake_offset_keep,
_stake_offset_close: stake_offset_close,
}
.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
pub fn close_delegated_stake_ix(
signer: &Pubkey,
delegation_owner: &Pubkey,
stake_offset: u128,
primary_stake_owner: Option<&Pubkey>,
) -> Instruction {
let accounts = CloseDelegatedStakeAccs {
signer: signer.to_owned(),
signer_ata: get_associated_token_address(signer, &ARCIUM_TOKEN_MINT),
withdrawal_master: stake_master_acc(signer),
delegation_master: stake_master_acc(delegation_owner),
delegation_owner: delegation_owner.to_owned(),
user_stake_account: delegated_stake_acc(stake_offset),
mint: ARCIUM_TOKEN_MINT,
pool_account: staking_pool_acc(),
pool_ata: get_associated_token_address(&staking_pool_acc(), &ARCIUM_TOKEN_MINT),
clock: clock_acc(),
system_program: SYSTEM_PROGRAM_ID,
token_program: TOKEN_PROGRAM_ID,
primary: primary_stake_owner.map(primary_stake_acc),
}
.to_account_metas(None);
let data = CloseDelegatedStakeArgs { stake_offset }.data();
Instruction {
program_id: ARCIUM_STAKING_PROG_ID,
accounts,
data,
}
}
}
#[cfg(feature = "permissioned-mainnet")]
pub mod permissioned_mainnet {
use crate::{
idl::arcium::{
client::{
accounts::{
AddPermissionedRecoveryPeers as AddPermissionedRecoveryPeersAccs,
ClosePermissionedRecoveryPeersAccount as ClosePermissionedRecoveryPeersAccountAccs,
InitPermissionedRecoveryPeersAccount as InitPermissionedRecoveryPeersAccountAccs,
RemovePermissionedRecoveryPeers as RemovePermissionedRecoveryPeersAccs,
},
args::{
AddPermissionedRecoveryPeers as AddPermissionedRecoveryPeersArgs,
ClosePermissionedRecoveryPeersAccount as ClosePermissionedRecoveryPeersAccountArgs,
InitPermissionedRecoveryPeersAccount as InitPermissionedRecoveryPeersAccountArgs,
RemovePermissionedRecoveryPeers as RemovePermissionedRecoveryPeersArgs,
},
},
ID as ARCIUM_PROG_ID,
},
instruction::SYSTEM_PROGRAM_ID,
pda::permissioned_recovery_peers_acc,
};
use anchor_lang::{
prelude::{bpf_loader_upgradeable, Pubkey},
InstructionData,
ToAccountMetas,
};
use solana_program::instruction::Instruction;
pub fn init_permissioned_recovery_peers_acc_ix(signer: &Pubkey) -> Instruction {
let (program_data, _) =
Pubkey::find_program_address(&[ARCIUM_PROG_ID.as_ref()], &bpf_loader_upgradeable::id());
let accounts = InitPermissionedRecoveryPeersAccountAccs {
signer: signer.to_owned(),
permissioned_recovery_peers_acc: permissioned_recovery_peers_acc(),
program_data,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = InitPermissionedRecoveryPeersAccountArgs.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn close_permissioned_recovery_peers_acc_ix(signer: &Pubkey) -> Instruction {
let (program_data, _) =
Pubkey::find_program_address(&[ARCIUM_PROG_ID.as_ref()], &bpf_loader_upgradeable::id());
let accounts = ClosePermissionedRecoveryPeersAccountAccs {
signer: signer.to_owned(),
permissioned_recovery_peers_acc: permissioned_recovery_peers_acc(),
program_data,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = ClosePermissionedRecoveryPeersAccountArgs.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn add_permissioned_recovery_peers_ix(signer: &Pubkey, peers: Vec<Pubkey>) -> Instruction {
let (program_data, _) =
Pubkey::find_program_address(&[ARCIUM_PROG_ID.as_ref()], &bpf_loader_upgradeable::id());
let accounts = AddPermissionedRecoveryPeersAccs {
signer: signer.to_owned(),
permissioned_recovery_peers_acc: permissioned_recovery_peers_acc(),
program_data,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = AddPermissionedRecoveryPeersArgs { peers }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
pub fn remove_permissioned_recovery_peers_ix(
signer: &Pubkey,
peers: Vec<Pubkey>,
) -> Instruction {
let (program_data, _) =
Pubkey::find_program_address(&[ARCIUM_PROG_ID.as_ref()], &bpf_loader_upgradeable::id());
let accounts = RemovePermissionedRecoveryPeersAccs {
signer: signer.to_owned(),
permissioned_recovery_peers_acc: permissioned_recovery_peers_acc(),
program_data,
system_program: SYSTEM_PROGRAM_ID,
}
.to_account_metas(None);
let data = RemovePermissionedRecoveryPeersArgs { peers }.data();
Instruction {
program_id: ARCIUM_PROG_ID,
accounts,
data,
}
}
}