use crate::types::Fees;
use crate::types::Limit;
use borsh::{BorshDeserialize, BorshSerialize};
pub const OPERATOR_SET_POOL_CONFIG_DISCRIMINATOR: [u8; 8] = [76, 201, 80, 18, 199, 92, 246, 105];
#[derive(Debug)]
pub struct OperatorSetPoolConfig {
pub operator: solana_program::pubkey::Pubkey,
pub pool: solana_program::pubkey::Pubkey,
}
impl OperatorSetPoolConfig {
pub fn instruction(
&self,
args: OperatorSetPoolConfigInstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::arithmetic_side_effects)]
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: OperatorSetPoolConfigInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.operator,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.pool, false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&OperatorSetPoolConfigInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_program::instruction::Instruction {
program_id: crate::PERPETUALS_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OperatorSetPoolConfigInstructionData {
discriminator: [u8; 8],
}
impl OperatorSetPoolConfigInstructionData {
pub fn new() -> Self {
Self {
discriminator: [76, 201, 80, 18, 199, 92, 246, 105],
}
}
}
impl Default for OperatorSetPoolConfigInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OperatorSetPoolConfigInstructionArgs {
pub fees: Fees,
pub limit: Limit,
pub max_request_execution_sec: i64,
pub max_trigger_price_diff_bps: u64,
pub disable_close_position_request: bool,
pub max_lp_token_price_change_bps: u64,
}
#[derive(Clone, Debug, Default)]
pub struct OperatorSetPoolConfigBuilder {
operator: Option<solana_program::pubkey::Pubkey>,
pool: Option<solana_program::pubkey::Pubkey>,
fees: Option<Fees>,
limit: Option<Limit>,
max_request_execution_sec: Option<i64>,
max_trigger_price_diff_bps: Option<u64>,
disable_close_position_request: Option<bool>,
max_lp_token_price_change_bps: Option<u64>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl OperatorSetPoolConfigBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn operator(&mut self, operator: solana_program::pubkey::Pubkey) -> &mut Self {
self.operator = Some(operator);
self
}
#[inline(always)]
pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
self.pool = Some(pool);
self
}
#[inline(always)]
pub fn fees(&mut self, fees: Fees) -> &mut Self {
self.fees = Some(fees);
self
}
#[inline(always)]
pub fn limit(&mut self, limit: Limit) -> &mut Self {
self.limit = Some(limit);
self
}
#[inline(always)]
pub fn max_request_execution_sec(&mut self, max_request_execution_sec: i64) -> &mut Self {
self.max_request_execution_sec = Some(max_request_execution_sec);
self
}
#[inline(always)]
pub fn max_trigger_price_diff_bps(&mut self, max_trigger_price_diff_bps: u64) -> &mut Self {
self.max_trigger_price_diff_bps = Some(max_trigger_price_diff_bps);
self
}
#[inline(always)]
pub fn disable_close_position_request(
&mut self,
disable_close_position_request: bool,
) -> &mut Self {
self.disable_close_position_request = Some(disable_close_position_request);
self
}
#[inline(always)]
pub fn max_lp_token_price_change_bps(
&mut self,
max_lp_token_price_change_bps: u64,
) -> &mut Self {
self.max_lp_token_price_change_bps = Some(max_lp_token_price_change_bps);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: solana_program::instruction::AccountMeta,
) -> &mut Self {
self.__remaining_accounts.push(account);
self
}
#[inline(always)]
pub fn add_remaining_accounts(
&mut self,
accounts: &[solana_program::instruction::AccountMeta],
) -> &mut Self {
self.__remaining_accounts.extend_from_slice(accounts);
self
}
#[allow(clippy::clone_on_copy)]
pub fn instruction(&self) -> solana_program::instruction::Instruction {
let accounts = OperatorSetPoolConfig {
operator: self.operator.expect("operator is not set"),
pool: self.pool.expect("pool is not set"),
};
let args = OperatorSetPoolConfigInstructionArgs {
fees: self.fees.clone().expect("fees is not set"),
limit: self.limit.clone().expect("limit is not set"),
max_request_execution_sec: self
.max_request_execution_sec
.clone()
.expect("max_request_execution_sec is not set"),
max_trigger_price_diff_bps: self
.max_trigger_price_diff_bps
.clone()
.expect("max_trigger_price_diff_bps is not set"),
disable_close_position_request: self
.disable_close_position_request
.clone()
.expect("disable_close_position_request is not set"),
max_lp_token_price_change_bps: self
.max_lp_token_price_change_bps
.clone()
.expect("max_lp_token_price_change_bps is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct OperatorSetPoolConfigCpiAccounts<'a, 'b> {
pub operator: &'b solana_program::account_info::AccountInfo<'a>,
pub pool: &'b solana_program::account_info::AccountInfo<'a>,
}
pub struct OperatorSetPoolConfigCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub operator: &'b solana_program::account_info::AccountInfo<'a>,
pub pool: &'b solana_program::account_info::AccountInfo<'a>,
pub __args: OperatorSetPoolConfigInstructionArgs,
}
impl<'a, 'b> OperatorSetPoolConfigCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: OperatorSetPoolConfigCpiAccounts<'a, 'b>,
args: OperatorSetPoolConfigInstructionArgs,
) -> Self {
Self {
__program: program,
operator: accounts.operator,
pool: accounts.pool,
__args: args,
}
}
#[inline(always)]
pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(&[], &[])
}
#[inline(always)]
pub fn invoke_with_remaining_accounts(
&self,
remaining_accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
}
#[inline(always)]
pub fn invoke_signed(
&self,
signers_seeds: &[&[&[u8]]],
) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
}
#[allow(clippy::arithmetic_side_effects)]
#[allow(clippy::clone_on_copy)]
#[allow(clippy::vec_init_then_push)]
pub fn invoke_signed_with_remaining_accounts(
&self,
signers_seeds: &[&[&[u8]]],
remaining_accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.operator.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.pool.key,
false,
));
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_signer: remaining_account.1,
is_writable: remaining_account.2,
})
});
let mut data = borsh::to_vec(&OperatorSetPoolConfigInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);
let instruction = solana_program::instruction::Instruction {
program_id: crate::PERPETUALS_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.operator.clone());
account_infos.push(self.pool.clone());
remaining_accounts
.iter()
.for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
if signers_seeds.is_empty() {
solana_program::program::invoke(&instruction, &account_infos)
} else {
solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
}
}
}
#[derive(Clone, Debug)]
pub struct OperatorSetPoolConfigCpiBuilder<'a, 'b> {
instruction: Box<OperatorSetPoolConfigCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> OperatorSetPoolConfigCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(OperatorSetPoolConfigCpiBuilderInstruction {
__program: program,
operator: None,
pool: None,
fees: None,
limit: None,
max_request_execution_sec: None,
max_trigger_price_diff_bps: None,
disable_close_position_request: None,
max_lp_token_price_change_bps: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn operator(
&mut self,
operator: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.operator = Some(operator);
self
}
#[inline(always)]
pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.pool = Some(pool);
self
}
#[inline(always)]
pub fn fees(&mut self, fees: Fees) -> &mut Self {
self.instruction.fees = Some(fees);
self
}
#[inline(always)]
pub fn limit(&mut self, limit: Limit) -> &mut Self {
self.instruction.limit = Some(limit);
self
}
#[inline(always)]
pub fn max_request_execution_sec(&mut self, max_request_execution_sec: i64) -> &mut Self {
self.instruction.max_request_execution_sec = Some(max_request_execution_sec);
self
}
#[inline(always)]
pub fn max_trigger_price_diff_bps(&mut self, max_trigger_price_diff_bps: u64) -> &mut Self {
self.instruction.max_trigger_price_diff_bps = Some(max_trigger_price_diff_bps);
self
}
#[inline(always)]
pub fn disable_close_position_request(
&mut self,
disable_close_position_request: bool,
) -> &mut Self {
self.instruction.disable_close_position_request = Some(disable_close_position_request);
self
}
#[inline(always)]
pub fn max_lp_token_price_change_bps(
&mut self,
max_lp_token_price_change_bps: u64,
) -> &mut Self {
self.instruction.max_lp_token_price_change_bps = Some(max_lp_token_price_change_bps);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: &'b solana_program::account_info::AccountInfo<'a>,
is_writable: bool,
is_signer: bool,
) -> &mut Self {
self.instruction
.__remaining_accounts
.push((account, is_writable, is_signer));
self
}
#[inline(always)]
pub fn add_remaining_accounts(
&mut self,
accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> &mut Self {
self.instruction
.__remaining_accounts
.extend_from_slice(accounts);
self
}
#[inline(always)]
pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed(&[])
}
#[allow(clippy::clone_on_copy)]
#[allow(clippy::vec_init_then_push)]
pub fn invoke_signed(
&self,
signers_seeds: &[&[&[u8]]],
) -> solana_program::entrypoint::ProgramResult {
let args = OperatorSetPoolConfigInstructionArgs {
fees: self.instruction.fees.clone().expect("fees is not set"),
limit: self.instruction.limit.clone().expect("limit is not set"),
max_request_execution_sec: self
.instruction
.max_request_execution_sec
.clone()
.expect("max_request_execution_sec is not set"),
max_trigger_price_diff_bps: self
.instruction
.max_trigger_price_diff_bps
.clone()
.expect("max_trigger_price_diff_bps is not set"),
disable_close_position_request: self
.instruction
.disable_close_position_request
.clone()
.expect("disable_close_position_request is not set"),
max_lp_token_price_change_bps: self
.instruction
.max_lp_token_price_change_bps
.clone()
.expect("max_lp_token_price_change_bps is not set"),
};
let instruction = OperatorSetPoolConfigCpi {
__program: self.instruction.__program,
operator: self.instruction.operator.expect("operator is not set"),
pool: self.instruction.pool.expect("pool is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct OperatorSetPoolConfigCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
operator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
fees: Option<Fees>,
limit: Option<Limit>,
max_request_execution_sec: Option<i64>,
max_trigger_price_diff_bps: Option<u64>,
disable_close_position_request: Option<bool>,
max_lp_token_price_change_bps: Option<u64>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}