diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index 43d86124..9ba66e04 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -13,4 +13,3 @@ export * from './initUpdateTswap'; export * from './withdrawMarginAccount'; export * from './withdrawMarginAccountCpiTamm'; export * from './withdrawMarginAccountCpiTcomp'; -export * from './withdrawTswapFees'; diff --git a/clients/js/src/generated/instructions/withdrawTswapFees.ts b/clients/js/src/generated/instructions/withdrawTswapFees.ts deleted file mode 100644 index cdc7b0c2..00000000 --- a/clients/js/src/generated/instructions/withdrawTswapFees.ts +++ /dev/null @@ -1,353 +0,0 @@ -/** - * This code was AUTOGENERATED using the codama library. - * Please DO NOT EDIT THIS FILE, instead use visitors - * to add features, then rerun codama to update it. - * - * @see https://github.com/codama-idl/codama - */ - -import { - combineCodec, - fixDecoderSize, - fixEncoderSize, - getBytesDecoder, - getBytesEncoder, - getStructDecoder, - getStructEncoder, - getU64Decoder, - getU64Encoder, - transformEncoder, - type Address, - type Codec, - type Decoder, - type Encoder, - type IAccountMeta, - type IAccountSignerMeta, - type IInstruction, - type IInstructionWithAccounts, - type IInstructionWithData, - type ReadonlyAccount, - type ReadonlySignerAccount, - type ReadonlyUint8Array, - type TransactionSigner, - type WritableAccount, - type WritableSignerAccount, -} from '@solana/web3.js'; -import { findTSwapPda } from '../pdas'; -import { TENSOR_ESCROW_PROGRAM_ADDRESS } from '../programs'; -import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; - -export const WITHDRAW_TSWAP_FEES_DISCRIMINATOR = new Uint8Array([ - 27, 229, 128, 105, 115, 125, 180, 151, -]); - -export function getWithdrawTswapFeesDiscriminatorBytes() { - return fixEncoderSize(getBytesEncoder(), 8).encode( - WITHDRAW_TSWAP_FEES_DISCRIMINATOR - ); -} - -export type WithdrawTswapFeesInstruction< - TProgram extends string = typeof TENSOR_ESCROW_PROGRAM_ADDRESS, - TAccountTswap extends string | IAccountMeta = string, - TAccountCosigner extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountDestination extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends readonly IAccountMeta[] = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountTswap extends string - ? WritableAccount - : TAccountTswap, - TAccountCosigner extends string - ? ReadonlySignerAccount & - IAccountSignerMeta - : TAccountCosigner, - TAccountOwner extends string - ? WritableSignerAccount & - IAccountSignerMeta - : TAccountOwner, - TAccountDestination extends string - ? WritableAccount - : TAccountDestination, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - ...TRemainingAccounts, - ] - >; - -export type WithdrawTswapFeesInstructionData = { - discriminator: ReadonlyUint8Array; - lamports: bigint; -}; - -export type WithdrawTswapFeesInstructionDataArgs = { - lamports: number | bigint; -}; - -export function getWithdrawTswapFeesInstructionDataEncoder(): Encoder { - return transformEncoder( - getStructEncoder([ - ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], - ['lamports', getU64Encoder()], - ]), - (value) => ({ ...value, discriminator: WITHDRAW_TSWAP_FEES_DISCRIMINATOR }) - ); -} - -export function getWithdrawTswapFeesInstructionDataDecoder(): Decoder { - return getStructDecoder([ - ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], - ['lamports', getU64Decoder()], - ]); -} - -export function getWithdrawTswapFeesInstructionDataCodec(): Codec< - WithdrawTswapFeesInstructionDataArgs, - WithdrawTswapFeesInstructionData -> { - return combineCodec( - getWithdrawTswapFeesInstructionDataEncoder(), - getWithdrawTswapFeesInstructionDataDecoder() - ); -} - -export type WithdrawTswapFeesAsyncInput< - TAccountTswap extends string = string, - TAccountCosigner extends string = string, - TAccountOwner extends string = string, - TAccountDestination extends string = string, - TAccountSystemProgram extends string = string, -> = { - tswap?: Address; - /** We ask also for a signature just to make sure this wallet can actually sign things */ - cosigner: TransactionSigner; - owner: TransactionSigner; - destination: Address; - systemProgram?: Address; - lamports: WithdrawTswapFeesInstructionDataArgs['lamports']; -}; - -export async function getWithdrawTswapFeesInstructionAsync< - TAccountTswap extends string, - TAccountCosigner extends string, - TAccountOwner extends string, - TAccountDestination extends string, - TAccountSystemProgram extends string, - TProgramAddress extends Address = typeof TENSOR_ESCROW_PROGRAM_ADDRESS, ->( - input: WithdrawTswapFeesAsyncInput< - TAccountTswap, - TAccountCosigner, - TAccountOwner, - TAccountDestination, - TAccountSystemProgram - >, - config?: { programAddress?: TProgramAddress } -): Promise< - WithdrawTswapFeesInstruction< - TProgramAddress, - TAccountTswap, - TAccountCosigner, - TAccountOwner, - TAccountDestination, - TAccountSystemProgram - > -> { - // Program address. - const programAddress = - config?.programAddress ?? TENSOR_ESCROW_PROGRAM_ADDRESS; - - // Original accounts. - const originalAccounts = { - tswap: { value: input.tswap ?? null, isWritable: true }, - cosigner: { value: input.cosigner ?? null, isWritable: false }, - owner: { value: input.owner ?? null, isWritable: true }, - destination: { value: input.destination ?? null, isWritable: true }, - systemProgram: { value: input.systemProgram ?? null, isWritable: false }, - }; - const accounts = originalAccounts as Record< - keyof typeof originalAccounts, - ResolvedAccount - >; - - // Original args. - const args = { ...input }; - - // Resolve default values. - if (!accounts.tswap.value) { - accounts.tswap.value = await findTSwapPda(); - } - if (!accounts.systemProgram.value) { - accounts.systemProgram.value = - '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; - } - - const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); - const instruction = { - accounts: [ - getAccountMeta(accounts.tswap), - getAccountMeta(accounts.cosigner), - getAccountMeta(accounts.owner), - getAccountMeta(accounts.destination), - getAccountMeta(accounts.systemProgram), - ], - programAddress, - data: getWithdrawTswapFeesInstructionDataEncoder().encode( - args as WithdrawTswapFeesInstructionDataArgs - ), - } as WithdrawTswapFeesInstruction< - TProgramAddress, - TAccountTswap, - TAccountCosigner, - TAccountOwner, - TAccountDestination, - TAccountSystemProgram - >; - - return instruction; -} - -export type WithdrawTswapFeesInput< - TAccountTswap extends string = string, - TAccountCosigner extends string = string, - TAccountOwner extends string = string, - TAccountDestination extends string = string, - TAccountSystemProgram extends string = string, -> = { - tswap: Address; - /** We ask also for a signature just to make sure this wallet can actually sign things */ - cosigner: TransactionSigner; - owner: TransactionSigner; - destination: Address; - systemProgram?: Address; - lamports: WithdrawTswapFeesInstructionDataArgs['lamports']; -}; - -export function getWithdrawTswapFeesInstruction< - TAccountTswap extends string, - TAccountCosigner extends string, - TAccountOwner extends string, - TAccountDestination extends string, - TAccountSystemProgram extends string, - TProgramAddress extends Address = typeof TENSOR_ESCROW_PROGRAM_ADDRESS, ->( - input: WithdrawTswapFeesInput< - TAccountTswap, - TAccountCosigner, - TAccountOwner, - TAccountDestination, - TAccountSystemProgram - >, - config?: { programAddress?: TProgramAddress } -): WithdrawTswapFeesInstruction< - TProgramAddress, - TAccountTswap, - TAccountCosigner, - TAccountOwner, - TAccountDestination, - TAccountSystemProgram -> { - // Program address. - const programAddress = - config?.programAddress ?? TENSOR_ESCROW_PROGRAM_ADDRESS; - - // Original accounts. - const originalAccounts = { - tswap: { value: input.tswap ?? null, isWritable: true }, - cosigner: { value: input.cosigner ?? null, isWritable: false }, - owner: { value: input.owner ?? null, isWritable: true }, - destination: { value: input.destination ?? null, isWritable: true }, - systemProgram: { value: input.systemProgram ?? null, isWritable: false }, - }; - const accounts = originalAccounts as Record< - keyof typeof originalAccounts, - ResolvedAccount - >; - - // Original args. - const args = { ...input }; - - // Resolve default values. - if (!accounts.systemProgram.value) { - accounts.systemProgram.value = - '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; - } - - const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); - const instruction = { - accounts: [ - getAccountMeta(accounts.tswap), - getAccountMeta(accounts.cosigner), - getAccountMeta(accounts.owner), - getAccountMeta(accounts.destination), - getAccountMeta(accounts.systemProgram), - ], - programAddress, - data: getWithdrawTswapFeesInstructionDataEncoder().encode( - args as WithdrawTswapFeesInstructionDataArgs - ), - } as WithdrawTswapFeesInstruction< - TProgramAddress, - TAccountTswap, - TAccountCosigner, - TAccountOwner, - TAccountDestination, - TAccountSystemProgram - >; - - return instruction; -} - -export type ParsedWithdrawTswapFeesInstruction< - TProgram extends string = typeof TENSOR_ESCROW_PROGRAM_ADDRESS, - TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], -> = { - programAddress: Address; - accounts: { - tswap: TAccountMetas[0]; - /** We ask also for a signature just to make sure this wallet can actually sign things */ - cosigner: TAccountMetas[1]; - owner: TAccountMetas[2]; - destination: TAccountMetas[3]; - systemProgram: TAccountMetas[4]; - }; - data: WithdrawTswapFeesInstructionData; -}; - -export function parseWithdrawTswapFeesInstruction< - TProgram extends string, - TAccountMetas extends readonly IAccountMeta[], ->( - instruction: IInstruction & - IInstructionWithAccounts & - IInstructionWithData -): ParsedWithdrawTswapFeesInstruction { - if (instruction.accounts.length < 5) { - // TODO: Coded error. - throw new Error('Not enough accounts'); - } - let accountIndex = 0; - const getNextAccount = () => { - const accountMeta = instruction.accounts![accountIndex]!; - accountIndex += 1; - return accountMeta; - }; - return { - programAddress: instruction.programAddress, - accounts: { - tswap: getNextAccount(), - cosigner: getNextAccount(), - owner: getNextAccount(), - destination: getNextAccount(), - systemProgram: getNextAccount(), - }, - data: getWithdrawTswapFeesInstructionDataDecoder().decode(instruction.data), - }; -} diff --git a/clients/js/src/generated/programs/tensorEscrow.ts b/clients/js/src/generated/programs/tensorEscrow.ts index 5b830ced..28713a03 100644 --- a/clients/js/src/generated/programs/tensorEscrow.ts +++ b/clients/js/src/generated/programs/tensorEscrow.ts @@ -21,7 +21,6 @@ import { type ParsedWithdrawMarginAccountCpiTammInstruction, type ParsedWithdrawMarginAccountCpiTcompInstruction, type ParsedWithdrawMarginAccountInstruction, - type ParsedWithdrawTswapFeesInstruction, } from '../instructions'; export const TENSOR_ESCROW_PROGRAM_ADDRESS = @@ -71,7 +70,6 @@ export enum TensorEscrowInstruction { WithdrawMarginAccount, WithdrawMarginAccountCpiTamm, WithdrawMarginAccountCpiTcomp, - WithdrawTswapFees, } export function identifyTensorEscrowInstruction( @@ -155,17 +153,6 @@ export function identifyTensorEscrowInstruction( ) { return TensorEscrowInstruction.WithdrawMarginAccountCpiTcomp; } - if ( - containsBytes( - data, - fixEncoderSize(getBytesEncoder(), 8).encode( - new Uint8Array([27, 229, 128, 105, 115, 125, 180, 151]) - ), - 0 - ) - ) { - return TensorEscrowInstruction.WithdrawTswapFees; - } throw new Error( 'The provided instruction could not be identified as a tensorEscrow instruction.' ); @@ -194,7 +181,4 @@ export type ParsedTensorEscrowInstruction< } & ParsedWithdrawMarginAccountCpiTammInstruction) | ({ instructionType: TensorEscrowInstruction.WithdrawMarginAccountCpiTcomp; - } & ParsedWithdrawMarginAccountCpiTcompInstruction) - | ({ - instructionType: TensorEscrowInstruction.WithdrawTswapFees; - } & ParsedWithdrawTswapFeesInstruction); + } & ParsedWithdrawMarginAccountCpiTcompInstruction); diff --git a/clients/rust/src/generated/instructions/mod.rs b/clients/rust/src/generated/instructions/mod.rs index b71a2e1b..c85a8e4e 100644 --- a/clients/rust/src/generated/instructions/mod.rs +++ b/clients/rust/src/generated/instructions/mod.rs @@ -12,7 +12,6 @@ pub(crate) mod r#init_update_tswap; pub(crate) mod r#withdraw_margin_account; pub(crate) mod r#withdraw_margin_account_cpi_tamm; pub(crate) mod r#withdraw_margin_account_cpi_tcomp; -pub(crate) mod r#withdraw_tswap_fees; pub use self::r#close_margin_account::*; pub use self::r#deposit_margin_account::*; @@ -21,4 +20,3 @@ pub use self::r#init_update_tswap::*; pub use self::r#withdraw_margin_account::*; pub use self::r#withdraw_margin_account_cpi_tamm::*; pub use self::r#withdraw_margin_account_cpi_tcomp::*; -pub use self::r#withdraw_tswap_fees::*; diff --git a/clients/rust/src/generated/instructions/withdraw_tswap_fees.rs b/clients/rust/src/generated/instructions/withdraw_tswap_fees.rs deleted file mode 100644 index 785b8ba0..00000000 --- a/clients/rust/src/generated/instructions/withdraw_tswap_fees.rs +++ /dev/null @@ -1,483 +0,0 @@ -//! This code was AUTOGENERATED using the codama library. -//! Please DO NOT EDIT THIS FILE, instead use visitors -//! to add features, then rerun codama to update it. -//! -//! -//! - -use borsh::BorshDeserialize; -use borsh::BorshSerialize; - -/// Accounts. -#[derive(Debug)] -pub struct WithdrawTswapFees { - pub tswap: solana_program::pubkey::Pubkey, - /// We ask also for a signature just to make sure this wallet can actually sign things - pub cosigner: solana_program::pubkey::Pubkey, - - pub owner: solana_program::pubkey::Pubkey, - - pub destination: solana_program::pubkey::Pubkey, - - pub system_program: solana_program::pubkey::Pubkey, -} - -impl WithdrawTswapFees { - pub fn instruction( - &self, - args: WithdrawTswapFeesInstructionArgs, - ) -> solana_program::instruction::Instruction { - self.instruction_with_remaining_accounts(args, &[]) - } - #[allow(clippy::vec_init_then_push)] - pub fn instruction_with_remaining_accounts( - &self, - args: WithdrawTswapFeesInstructionArgs, - remaining_accounts: &[solana_program::instruction::AccountMeta], - ) -> solana_program::instruction::Instruction { - let mut accounts = Vec::with_capacity(5 + remaining_accounts.len()); - accounts.push(solana_program::instruction::AccountMeta::new( - self.tswap, false, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - self.cosigner, - true, - )); - accounts.push(solana_program::instruction::AccountMeta::new( - self.owner, true, - )); - accounts.push(solana_program::instruction::AccountMeta::new( - self.destination, - false, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - self.system_program, - false, - )); - accounts.extend_from_slice(remaining_accounts); - let mut data = borsh::to_vec(&WithdrawTswapFeesInstructionData::new()).unwrap(); - let mut args = borsh::to_vec(&args).unwrap(); - data.append(&mut args); - - solana_program::instruction::Instruction { - program_id: crate::TENSOR_ESCROW_ID, - accounts, - data, - } - } -} - -#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct WithdrawTswapFeesInstructionData { - discriminator: [u8; 8], -} - -impl WithdrawTswapFeesInstructionData { - pub fn new() -> Self { - Self { - discriminator: [27, 229, 128, 105, 115, 125, 180, 151], - } - } -} - -impl Default for WithdrawTswapFeesInstructionData { - fn default() -> Self { - Self::new() - } -} - -#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct WithdrawTswapFeesInstructionArgs { - pub lamports: u64, -} - -/// Instruction builder for `WithdrawTswapFees`. -/// -/// ### Accounts: -/// -/// 0. `[writable]` tswap -/// 1. `[signer]` cosigner -/// 2. `[writable, signer]` owner -/// 3. `[writable]` destination -/// 4. `[optional]` system_program (default to `11111111111111111111111111111111`) -#[derive(Clone, Debug, Default)] -pub struct WithdrawTswapFeesBuilder { - tswap: Option, - cosigner: Option, - owner: Option, - destination: Option, - system_program: Option, - lamports: Option, - __remaining_accounts: Vec, -} - -impl WithdrawTswapFeesBuilder { - pub fn new() -> Self { - Self::default() - } - #[inline(always)] - pub fn tswap(&mut self, tswap: solana_program::pubkey::Pubkey) -> &mut Self { - self.tswap = Some(tswap); - self - } - /// We ask also for a signature just to make sure this wallet can actually sign things - #[inline(always)] - pub fn cosigner(&mut self, cosigner: solana_program::pubkey::Pubkey) -> &mut Self { - self.cosigner = Some(cosigner); - self - } - #[inline(always)] - pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self { - self.owner = Some(owner); - self - } - #[inline(always)] - pub fn destination(&mut self, destination: solana_program::pubkey::Pubkey) -> &mut Self { - self.destination = Some(destination); - self - } - /// `[optional account, default to '11111111111111111111111111111111']` - #[inline(always)] - pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self { - self.system_program = Some(system_program); - self - } - #[inline(always)] - pub fn lamports(&mut self, lamports: u64) -> &mut Self { - self.lamports = Some(lamports); - self - } - /// Add an additional account to the instruction. - #[inline(always)] - pub fn add_remaining_account( - &mut self, - account: solana_program::instruction::AccountMeta, - ) -> &mut Self { - self.__remaining_accounts.push(account); - self - } - /// Add additional accounts to the instruction. - #[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 = WithdrawTswapFees { - tswap: self.tswap.expect("tswap is not set"), - cosigner: self.cosigner.expect("cosigner is not set"), - owner: self.owner.expect("owner is not set"), - destination: self.destination.expect("destination is not set"), - system_program: self - .system_program - .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")), - }; - let args = WithdrawTswapFeesInstructionArgs { - lamports: self.lamports.clone().expect("lamports is not set"), - }; - - accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) - } -} - -/// `withdraw_tswap_fees` CPI accounts. -pub struct WithdrawTswapFeesCpiAccounts<'a, 'b> { - pub tswap: &'b solana_program::account_info::AccountInfo<'a>, - /// We ask also for a signature just to make sure this wallet can actually sign things - pub cosigner: &'b solana_program::account_info::AccountInfo<'a>, - - pub owner: &'b solana_program::account_info::AccountInfo<'a>, - - pub destination: &'b solana_program::account_info::AccountInfo<'a>, - - pub system_program: &'b solana_program::account_info::AccountInfo<'a>, -} - -/// `withdraw_tswap_fees` CPI instruction. -pub struct WithdrawTswapFeesCpi<'a, 'b> { - /// The program to invoke. - pub __program: &'b solana_program::account_info::AccountInfo<'a>, - - pub tswap: &'b solana_program::account_info::AccountInfo<'a>, - /// We ask also for a signature just to make sure this wallet can actually sign things - pub cosigner: &'b solana_program::account_info::AccountInfo<'a>, - - pub owner: &'b solana_program::account_info::AccountInfo<'a>, - - pub destination: &'b solana_program::account_info::AccountInfo<'a>, - - pub system_program: &'b solana_program::account_info::AccountInfo<'a>, - /// The arguments for the instruction. - pub __args: WithdrawTswapFeesInstructionArgs, -} - -impl<'a, 'b> WithdrawTswapFeesCpi<'a, 'b> { - pub fn new( - program: &'b solana_program::account_info::AccountInfo<'a>, - accounts: WithdrawTswapFeesCpiAccounts<'a, 'b>, - args: WithdrawTswapFeesInstructionArgs, - ) -> Self { - Self { - __program: program, - tswap: accounts.tswap, - cosigner: accounts.cosigner, - owner: accounts.owner, - destination: accounts.destination, - system_program: accounts.system_program, - __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::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(5 + remaining_accounts.len()); - accounts.push(solana_program::instruction::AccountMeta::new( - *self.tswap.key, - false, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - *self.cosigner.key, - true, - )); - accounts.push(solana_program::instruction::AccountMeta::new( - *self.owner.key, - true, - )); - accounts.push(solana_program::instruction::AccountMeta::new( - *self.destination.key, - false, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - *self.system_program.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(&WithdrawTswapFeesInstructionData::new()).unwrap(); - let mut args = borsh::to_vec(&self.__args).unwrap(); - data.append(&mut args); - - let instruction = solana_program::instruction::Instruction { - program_id: crate::TENSOR_ESCROW_ID, - accounts, - data, - }; - let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len()); - account_infos.push(self.__program.clone()); - account_infos.push(self.tswap.clone()); - account_infos.push(self.cosigner.clone()); - account_infos.push(self.owner.clone()); - account_infos.push(self.destination.clone()); - account_infos.push(self.system_program.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) - } - } -} - -/// Instruction builder for `WithdrawTswapFees` via CPI. -/// -/// ### Accounts: -/// -/// 0. `[writable]` tswap -/// 1. `[signer]` cosigner -/// 2. `[writable, signer]` owner -/// 3. `[writable]` destination -/// 4. `[]` system_program -#[derive(Clone, Debug)] -pub struct WithdrawTswapFeesCpiBuilder<'a, 'b> { - instruction: Box>, -} - -impl<'a, 'b> WithdrawTswapFeesCpiBuilder<'a, 'b> { - pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { - let instruction = Box::new(WithdrawTswapFeesCpiBuilderInstruction { - __program: program, - tswap: None, - cosigner: None, - owner: None, - destination: None, - system_program: None, - lamports: None, - __remaining_accounts: Vec::new(), - }); - Self { instruction } - } - #[inline(always)] - pub fn tswap(&mut self, tswap: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self { - self.instruction.tswap = Some(tswap); - self - } - /// We ask also for a signature just to make sure this wallet can actually sign things - #[inline(always)] - pub fn cosigner( - &mut self, - cosigner: &'b solana_program::account_info::AccountInfo<'a>, - ) -> &mut Self { - self.instruction.cosigner = Some(cosigner); - self - } - #[inline(always)] - pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self { - self.instruction.owner = Some(owner); - self - } - #[inline(always)] - pub fn destination( - &mut self, - destination: &'b solana_program::account_info::AccountInfo<'a>, - ) -> &mut Self { - self.instruction.destination = Some(destination); - self - } - #[inline(always)] - pub fn system_program( - &mut self, - system_program: &'b solana_program::account_info::AccountInfo<'a>, - ) -> &mut Self { - self.instruction.system_program = Some(system_program); - self - } - #[inline(always)] - pub fn lamports(&mut self, lamports: u64) -> &mut Self { - self.instruction.lamports = Some(lamports); - self - } - /// Add an additional account to the instruction. - #[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 - } - /// Add additional accounts to the instruction. - /// - /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, - /// and a `bool` indicating whether the account is a signer or not. - #[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 = WithdrawTswapFeesInstructionArgs { - lamports: self - .instruction - .lamports - .clone() - .expect("lamports is not set"), - }; - let instruction = WithdrawTswapFeesCpi { - __program: self.instruction.__program, - - tswap: self.instruction.tswap.expect("tswap is not set"), - - cosigner: self.instruction.cosigner.expect("cosigner is not set"), - - owner: self.instruction.owner.expect("owner is not set"), - - destination: self - .instruction - .destination - .expect("destination is not set"), - - system_program: self - .instruction - .system_program - .expect("system_program is not set"), - __args: args, - }; - instruction.invoke_signed_with_remaining_accounts( - signers_seeds, - &self.instruction.__remaining_accounts, - ) - } -} - -#[derive(Clone, Debug)] -struct WithdrawTswapFeesCpiBuilderInstruction<'a, 'b> { - __program: &'b solana_program::account_info::AccountInfo<'a>, - tswap: Option<&'b solana_program::account_info::AccountInfo<'a>>, - cosigner: Option<&'b solana_program::account_info::AccountInfo<'a>>, - owner: Option<&'b solana_program::account_info::AccountInfo<'a>>, - destination: Option<&'b solana_program::account_info::AccountInfo<'a>>, - system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, - lamports: Option, - /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. - __remaining_accounts: Vec<( - &'b solana_program::account_info::AccountInfo<'a>, - bool, - bool, - )>, -} diff --git a/programs/escrow/idl.json b/programs/escrow/idl.json index 818170b5..3b8cc49c 100644 --- a/programs/escrow/idl.json +++ b/programs/escrow/idl.json @@ -289,45 +289,6 @@ "type": "u64" } ] - }, - { - "name": "withdrawTswapFees", - "accounts": [ - { - "name": "tswap", - "isMut": true, - "isSigner": false - }, - { - "name": "cosigner", - "isMut": false, - "isSigner": true, - "docs": [ - "We ask also for a signature just to make sure this wallet can actually sign things" - ] - }, - { - "name": "owner", - "isMut": true, - "isSigner": true - }, - { - "name": "destination", - "isMut": true, - "isSigner": false - }, - { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [ - { - "name": "lamports", - "type": "u64" - } - ] } ], "accounts": [ diff --git a/programs/escrow/src/instructions/mod.rs b/programs/escrow/src/instructions/mod.rs index 2cb8ac77..7439d35a 100644 --- a/programs/escrow/src/instructions/mod.rs +++ b/programs/escrow/src/instructions/mod.rs @@ -5,7 +5,6 @@ pub mod init_update_tswap; pub mod withdraw_margin_account; pub mod withdraw_margin_account_from_tamm; pub mod withdraw_margin_account_from_tcomp; -pub mod withdraw_tswap_fees; pub use close_margin_account::*; pub use deposit_margin_account::*; @@ -14,7 +13,6 @@ pub use init_update_tswap::*; pub use withdraw_margin_account::*; pub use withdraw_margin_account_from_tamm::*; pub use withdraw_margin_account_from_tcomp::*; -pub use withdraw_tswap_fees::*; use tensor_vipers::throw_err; diff --git a/programs/escrow/src/instructions/withdraw_tswap_fees.rs b/programs/escrow/src/instructions/withdraw_tswap_fees.rs deleted file mode 100644 index 5152bf01..00000000 --- a/programs/escrow/src/instructions/withdraw_tswap_fees.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Program owner (Tensor) withdrawing accumulated tswap fees - -use anchor_lang::prelude::*; -use tensor_toolbox::transfer_lamports_from_pda; - -use crate::TSwap; - -#[derive(Accounts)] -pub struct WithdrawTswapFees<'info> { - #[account( - mut, - seeds = [], - bump = tswap.bump[0], - has_one = cosigner, - has_one = owner - )] - pub tswap: Box>, - - /// CHECK: initialized once on init, requires owner sign-off later - /// We ask also for a signature just to make sure this wallet can actually sign things - pub cosigner: Signer<'info>, - - #[account(mut)] - pub owner: Signer<'info>, - - /// CHECK: owner can decide to send anywhere - #[account(mut)] - pub destination: UncheckedAccount<'info>, - - pub system_program: Program<'info, System>, -} - -pub fn process_withdraw_tswap_fees(ctx: Context, lamports: u64) -> Result<()> { - transfer_lamports_from_pda( - &ctx.accounts.tswap.to_account_info(), - &ctx.accounts.destination.to_account_info(), - lamports, - )?; - - Ok(()) -} diff --git a/programs/escrow/src/lib.rs b/programs/escrow/src/lib.rs index 8a33e4b0..22e10169 100644 --- a/programs/escrow/src/lib.rs +++ b/programs/escrow/src/lib.rs @@ -76,8 +76,4 @@ pub mod escrow_program { ctx, lamports, ) } - - pub fn withdraw_tswap_fees(ctx: Context, lamports: u64) -> Result<()> { - instructions::withdraw_tswap_fees::process_withdraw_tswap_fees(ctx, lamports) - } }