diff --git a/program/.gitignore b/program/.gitignore index d517aa8..4cf9cd0 100644 --- a/program/.gitignore +++ b/program/.gitignore @@ -8,8 +8,9 @@ dist/ /tests/integration-tests/deps # Codama generated clients -/clients/rust/src/generated/* -/clients/typescript/src/generated/* +# We'll check in the generated clients to make publishing to crates.io easier +#/clients/rust/src/generated/* +#/clients/typescript/src/generated/* # Local test validator *test-ledger* diff --git a/program/clients/rust/src/generated/accounts/merchant.rs b/program/clients/rust/src/generated/accounts/merchant.rs new file mode 100644 index 0000000..51f230a --- /dev/null +++ b/program/clients/rust/src/generated/accounts/merchant.rs @@ -0,0 +1,141 @@ +//! 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; +use solana_pubkey::Pubkey; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Merchant { + pub discriminator: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub owner: Pubkey, + pub bump: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub settlement_wallet: Pubkey, +} + +impl Merchant { + pub const LEN: usize = 66; + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Merchant { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_merchant( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_merchant(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_merchant( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref().ok_or(std::io::Error::new( + std::io::ErrorKind::Other, + format!("Account not found: {}", address), + ))?; + let data = Merchant::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_merchant( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_merchant(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_merchant( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Merchant::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists( + crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }, + )); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountDeserialize for Merchant { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountSerialize for Merchant {} + +#[cfg(feature = "anchor")] +impl anchor_lang::Owner for Merchant { + fn owner() -> Pubkey { + crate::COMMERCE_PROGRAM_ID + } +} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::IdlBuild for Merchant {} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::Discriminator for Merchant { + const DISCRIMINATOR: &[u8] = &[0; 8]; +} diff --git a/program/clients/rust/src/generated/accounts/merchant_operator_config.rs b/program/clients/rust/src/generated/accounts/merchant_operator_config.rs new file mode 100644 index 0000000..1de754e --- /dev/null +++ b/program/clients/rust/src/generated/accounts/merchant_operator_config.rs @@ -0,0 +1,150 @@ +//! 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 crate::generated::types::FeeType; +use borsh::BorshDeserialize; +use borsh::BorshSerialize; +use solana_pubkey::Pubkey; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct MerchantOperatorConfig { + pub discriminator: u8, + pub version: u32, + pub bump: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub merchant: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub operator: Pubkey, + pub operator_fee: u64, + pub fee_type: FeeType, + pub current_order_id: u32, + pub days_to_close: u16, + pub num_policies: u32, + pub num_accepted_currencies: u32, +} + +impl MerchantOperatorConfig { + pub const LEN: usize = 93; + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for MerchantOperatorConfig { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_merchant_operator_config( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_merchant_operator_config(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_merchant_operator_config( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = + Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref().ok_or(std::io::Error::new( + std::io::ErrorKind::Other, + format!("Account not found: {}", address), + ))?; + let data = MerchantOperatorConfig::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_merchant_operator_config( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_merchant_operator_config(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_merchant_operator_config( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = MerchantOperatorConfig::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists( + crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }, + )); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountDeserialize for MerchantOperatorConfig { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountSerialize for MerchantOperatorConfig {} + +#[cfg(feature = "anchor")] +impl anchor_lang::Owner for MerchantOperatorConfig { + fn owner() -> Pubkey { + crate::COMMERCE_PROGRAM_ID + } +} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::IdlBuild for MerchantOperatorConfig {} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::Discriminator for MerchantOperatorConfig { + const DISCRIMINATOR: &[u8] = &[0; 8]; +} diff --git a/program/clients/rust/src/generated/accounts/mod.rs b/program/clients/rust/src/generated/accounts/mod.rs new file mode 100644 index 0000000..5975e35 --- /dev/null +++ b/program/clients/rust/src/generated/accounts/mod.rs @@ -0,0 +1,16 @@ +//! 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. +//! +//! +//! + +pub(crate) mod r#merchant; +pub(crate) mod r#merchant_operator_config; +pub(crate) mod r#operator; +pub(crate) mod r#payment; + +pub use self::r#merchant::*; +pub use self::r#merchant_operator_config::*; +pub use self::r#operator::*; +pub use self::r#payment::*; diff --git a/program/clients/rust/src/generated/accounts/operator.rs b/program/clients/rust/src/generated/accounts/operator.rs new file mode 100644 index 0000000..9c8efc3 --- /dev/null +++ b/program/clients/rust/src/generated/accounts/operator.rs @@ -0,0 +1,136 @@ +//! 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; +use solana_pubkey::Pubkey; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Operator { + pub discriminator: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub owner: Pubkey, + pub bump: u8, +} + +impl Operator { + pub const LEN: usize = 34; + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Operator { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_operator( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_operator(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_operator( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref().ok_or(std::io::Error::new( + std::io::ErrorKind::Other, + format!("Account not found: {}", address), + ))?; + let data = Operator::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_operator( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_operator(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_operator( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Operator::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists( + crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }, + )); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountDeserialize for Operator { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountSerialize for Operator {} + +#[cfg(feature = "anchor")] +impl anchor_lang::Owner for Operator { + fn owner() -> Pubkey { + crate::COMMERCE_PROGRAM_ID + } +} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::IdlBuild for Operator {} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::Discriminator for Operator { + const DISCRIMINATOR: &[u8] = &[0; 8]; +} diff --git a/program/clients/rust/src/generated/accounts/payment.rs b/program/clients/rust/src/generated/accounts/payment.rs new file mode 100644 index 0000000..d487f7e --- /dev/null +++ b/program/clients/rust/src/generated/accounts/payment.rs @@ -0,0 +1,135 @@ +//! 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 crate::generated::types::Status; +use borsh::BorshDeserialize; +use borsh::BorshSerialize; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Payment { + pub discriminator: u8, + pub order_id: u32, + pub amount: u64, + pub created_at: i64, + pub status: Status, + pub bump: u8, +} + +impl Payment { + pub const LEN: usize = 23; + + #[inline(always)] + pub fn from_bytes(data: &[u8]) -> Result { + let mut data = data; + Self::deserialize(&mut data) + } +} + +impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Payment { + type Error = std::io::Error; + + fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result { + let mut data: &[u8] = &(*account_info.data).borrow(); + Self::deserialize(&mut data) + } +} + +#[cfg(feature = "fetch")] +pub fn fetch_payment( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_payment(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_payment( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + let account = accounts[i].as_ref().ok_or(std::io::Error::new( + std::io::ErrorKind::Other, + format!("Account not found: {}", address), + ))?; + let data = Payment::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }); + } + Ok(decoded_accounts) +} + +#[cfg(feature = "fetch")] +pub fn fetch_maybe_payment( + rpc: &solana_client::rpc_client::RpcClient, + address: &solana_pubkey::Pubkey, +) -> Result, std::io::Error> { + let accounts = fetch_all_maybe_payment(rpc, &[*address])?; + Ok(accounts[0].clone()) +} + +#[cfg(feature = "fetch")] +pub fn fetch_all_maybe_payment( + rpc: &solana_client::rpc_client::RpcClient, + addresses: &[solana_pubkey::Pubkey], +) -> Result>, std::io::Error> { + let accounts = rpc + .get_multiple_accounts(addresses) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let mut decoded_accounts: Vec> = Vec::new(); + for i in 0..addresses.len() { + let address = addresses[i]; + if let Some(account) = accounts[i].as_ref() { + let data = Payment::from_bytes(&account.data)?; + decoded_accounts.push(crate::shared::MaybeAccount::Exists( + crate::shared::DecodedAccount { + address, + account: account.clone(), + data, + }, + )); + } else { + decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address)); + } + } + Ok(decoded_accounts) +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountDeserialize for Payment { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + Ok(Self::deserialize(buf)?) + } +} + +#[cfg(feature = "anchor")] +impl anchor_lang::AccountSerialize for Payment {} + +#[cfg(feature = "anchor")] +impl anchor_lang::Owner for Payment { + fn owner() -> Pubkey { + crate::COMMERCE_PROGRAM_ID + } +} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::IdlBuild for Payment {} + +#[cfg(feature = "anchor-idl-build")] +impl anchor_lang::Discriminator for Payment { + const DISCRIMINATOR: &[u8] = &[0; 8]; +} diff --git a/program/clients/rust/src/generated/errors/commerce_program.rs b/program/clients/rust/src/generated/errors/commerce_program.rs new file mode 100644 index 0000000..6e3233d --- /dev/null +++ b/program/clients/rust/src/generated/errors/commerce_program.rs @@ -0,0 +1,76 @@ +//! 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 num_derive::FromPrimitive; +use thiserror::Error; + +#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] +pub enum CommerceProgramError { + /// 0 - Incorrect mint provided + #[error("Incorrect mint provided")] + InvalidMint = 0x0, + /// 1 - Invalid payment status for the operation + #[error("Invalid payment status for the operation")] + InvalidPaymentStatus = 0x1, + /// 2 - Insufficient settlement amount + #[error("Insufficient settlement amount")] + InsufficientSettlementAmount = 0x2, + /// 3 - Settlement attempted too early + #[error("Settlement attempted too early")] + SettlementTooEarly = 0x3, + /// 4 - Refund amount exceeds policy limit + #[error("Refund amount exceeds policy limit")] + RefundAmountExceedsPolicyLimit = 0x4, + /// 5 - Refund window expired + #[error("Refund window expired")] + RefundWindowExpired = 0x5, + /// 6 - Invalid event authority + #[error("Invalid event authority")] + InvalidEventAuthority = 0x6, + /// 7 - Invalid ATA + #[error("Invalid ATA")] + InvalidAta = 0x7, + /// 8 - Payment close window not reached + #[error("Payment close window not reached")] + PaymentCloseWindowNotReached = 0x8, + /// 9 - Merchant owner does not match expected owner + #[error("Merchant owner does not match expected owner")] + MerchantOwnerMismatch = 0x9, + /// 10 - Merchant PDA is invalid + #[error("Merchant PDA is invalid")] + MerchantInvalidPda = 0xA, + /// 11 - Operator owner does not match expected owner + #[error("Operator owner does not match expected owner")] + OperatorOwnerMismatch = 0xB, + /// 12 - Operator PDA is invalid + #[error("Operator PDA is invalid")] + OperatorInvalidPda = 0xC, + /// 13 - Operator does not match config operator + #[error("Operator does not match config operator")] + OperatorMismatch = 0xD, + /// 14 - Merchant does not match config merchant + #[error("Merchant does not match config merchant")] + MerchantMismatch = 0xE, + /// 15 - Order ID is invalid or already used + #[error("Order ID is invalid or already used")] + OrderIdInvalid = 0xF, + /// 16 - MerchantOperatorConfig PDA is invalid + #[error("MerchantOperatorConfig PDA is invalid")] + MerchantOperatorConfigInvalidPda = 0x10, + /// 17 - Accepted currencies is empty + #[error("Accepted currencies is empty")] + AcceptedCurrenciesEmpty = 0x11, + /// 18 - Duplicate mint in accepted currencies + #[error("Duplicate mint in accepted currencies")] + DuplicateMint = 0x12, +} + +impl From for solana_program_error::ProgramError { + fn from(e: CommerceProgramError) -> Self { + solana_program_error::ProgramError::Custom(e as u32) + } +} diff --git a/program/clients/rust/src/generated/errors/mod.rs b/program/clients/rust/src/generated/errors/mod.rs new file mode 100644 index 0000000..20d23d3 --- /dev/null +++ b/program/clients/rust/src/generated/errors/mod.rs @@ -0,0 +1,10 @@ +//! 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. +//! +//! +//! + +pub(crate) mod commerce_program; + +pub use self::commerce_program::CommerceProgramError; diff --git a/program/clients/rust/src/generated/instructions/chargeback_payment.rs b/program/clients/rust/src/generated/instructions/chargeback_payment.rs new file mode 100644 index 0000000..9d23977 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/chargeback_payment.rs @@ -0,0 +1,777 @@ +//! 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; + +pub const CHARGEBACK_PAYMENT_DISCRIMINATOR: u8 = 6; + +/// Accounts. +#[derive(Debug)] +pub struct ChargebackPayment { + pub payer: solana_pubkey::Pubkey, + /// Payment PDA being updated + pub payment: solana_pubkey::Pubkey, + + pub operator_authority: solana_pubkey::Pubkey, + /// Chargeback destination owner + pub buyer: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + /// Operator PDA + pub operator: solana_pubkey::Pubkey, + /// Merchant Operator Config PDA + pub merchant_operator_config: solana_pubkey::Pubkey, + + pub mint: solana_pubkey::Pubkey, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: solana_pubkey::Pubkey, + + pub buyer_ata: solana_pubkey::Pubkey, + + pub token_program: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, + /// Event authority PDA + pub event_authority: solana_pubkey::Pubkey, + /// Commerce Program ID + pub commerce_program: solana_pubkey::Pubkey, +} + +impl ChargebackPayment { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(14 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.payment, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator_authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.buyer, false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant_operator_config, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, false, + )); + accounts.push(solana_instruction::AccountMeta::new( + self.merchant_escrow_ata, + false, + )); + accounts.push(solana_instruction::AccountMeta::new(self.buyer_ata, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.event_authority, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.commerce_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&ChargebackPaymentInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ChargebackPaymentInstructionData { + discriminator: u8, +} + +impl ChargebackPaymentInstructionData { + pub fn new() -> Self { + Self { discriminator: 6 } + } +} + +impl Default for ChargebackPaymentInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `ChargebackPayment`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` buyer +/// 4. `[]` merchant +/// 5. `[]` operator +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` merchant_escrow_ata +/// 9. `[writable]` buyer_ata +/// 10. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) +/// 11. `[optional]` system_program (default to `11111111111111111111111111111111`) +/// 12. `[optional]` event_authority (default to `3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1`) +/// 13. `[optional]` commerce_program (default to `commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT`) +#[derive(Clone, Debug, Default)] +pub struct ChargebackPaymentBuilder { + payer: Option, + payment: Option, + operator_authority: Option, + buyer: Option, + merchant: Option, + operator: Option, + merchant_operator_config: Option, + mint: Option, + merchant_escrow_ata: Option, + buyer_ata: Option, + token_program: Option, + system_program: Option, + event_authority: Option, + commerce_program: Option, + __remaining_accounts: Vec, +} + +impl ChargebackPaymentBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + /// Payment PDA being updated + #[inline(always)] + pub fn payment(&mut self, payment: solana_pubkey::Pubkey) -> &mut Self { + self.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority(&mut self, operator_authority: solana_pubkey::Pubkey) -> &mut Self { + self.operator_authority = Some(operator_authority); + self + } + /// Chargeback destination owner + #[inline(always)] + pub fn buyer(&mut self, buyer: solana_pubkey::Pubkey) -> &mut Self { + self.buyer = Some(buyer); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + /// Merchant Operator Config PDA + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: solana_pubkey::Pubkey, + ) -> &mut Self { + self.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + /// Merchant Escrow ATA (Merchant PDA is owner) + #[inline(always)] + pub fn merchant_escrow_ata(&mut self, merchant_escrow_ata: solana_pubkey::Pubkey) -> &mut Self { + self.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + #[inline(always)] + pub fn buyer_ata(&mut self, buyer_ata: solana_pubkey::Pubkey) -> &mut Self { + self.buyer_ata = Some(buyer_ata); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` + #[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1']` + /// Event authority PDA + #[inline(always)] + pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self { + self.event_authority = Some(event_authority); + self + } + /// `[optional account, default to 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT']` + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program(&mut self, commerce_program: solana_pubkey::Pubkey) -> &mut Self { + self.commerce_program = Some(commerce_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = ChargebackPayment { + payer: self.payer.expect("payer is not set"), + payment: self.payment.expect("payment is not set"), + operator_authority: self + .operator_authority + .expect("operator_authority is not set"), + buyer: self.buyer.expect("buyer is not set"), + merchant: self.merchant.expect("merchant is not set"), + operator: self.operator.expect("operator is not set"), + merchant_operator_config: self + .merchant_operator_config + .expect("merchant_operator_config is not set"), + mint: self.mint.expect("mint is not set"), + merchant_escrow_ata: self + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + buyer_ata: self.buyer_ata.expect("buyer_ata is not set"), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!( + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + )), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + event_authority: self.event_authority.unwrap_or(solana_pubkey::pubkey!( + "3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1" + )), + commerce_program: self.commerce_program.unwrap_or(solana_pubkey::pubkey!( + "commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT" + )), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `chargeback_payment` CPI accounts. +pub struct ChargebackPaymentCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA being updated + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + /// Chargeback destination owner + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + + pub buyer_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `chargeback_payment` CPI instruction. +pub struct ChargebackPaymentCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA being updated + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + /// Chargeback destination owner + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + + pub buyer_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> ChargebackPaymentCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ChargebackPaymentCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + payment: accounts.payment, + operator_authority: accounts.operator_authority, + buyer: accounts.buyer, + merchant: accounts.merchant, + operator: accounts.operator, + merchant_operator_config: accounts.merchant_operator_config, + mint: accounts.mint, + merchant_escrow_ata: accounts.merchant_escrow_ata, + buyer_ata: accounts.buyer_ata, + token_program: accounts.token_program, + system_program: accounts.system_program, + event_authority: accounts.event_authority, + commerce_program: accounts.commerce_program, + } + } + #[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_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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_entrypoint::ProgramResult { + let mut accounts = Vec::with_capacity(14 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.payment.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator_authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.buyer.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant_operator_config.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant_escrow_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.buyer_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.event_authority.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.commerce_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&ChargebackPaymentInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(15 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.payment.clone()); + account_infos.push(self.operator_authority.clone()); + account_infos.push(self.buyer.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.merchant_operator_config.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.merchant_escrow_ata.clone()); + account_infos.push(self.buyer_ata.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.event_authority.clone()); + account_infos.push(self.commerce_program.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `ChargebackPayment` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` buyer +/// 4. `[]` merchant +/// 5. `[]` operator +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` merchant_escrow_ata +/// 9. `[writable]` buyer_ata +/// 10. `[]` token_program +/// 11. `[]` system_program +/// 12. `[]` event_authority +/// 13. `[]` commerce_program +#[derive(Clone, Debug)] +pub struct ChargebackPaymentCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ChargebackPaymentCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ChargebackPaymentCpiBuilderInstruction { + __program: program, + payer: None, + payment: None, + operator_authority: None, + buyer: None, + merchant: None, + operator: None, + merchant_operator_config: None, + mint: None, + merchant_escrow_ata: None, + buyer_ata: None, + token_program: None, + system_program: None, + event_authority: None, + commerce_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + /// Payment PDA being updated + #[inline(always)] + pub fn payment(&mut self, payment: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority( + &mut self, + operator_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.operator_authority = Some(operator_authority); + self + } + /// Chargeback destination owner + #[inline(always)] + pub fn buyer(&mut self, buyer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer = Some(buyer); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + /// Merchant Operator Config PDA + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + /// Merchant Escrow ATA (Merchant PDA is owner) + #[inline(always)] + pub fn merchant_escrow_ata( + &mut self, + merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + #[inline(always)] + pub fn buyer_ata(&mut self, buyer_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer_ata = Some(buyer_ata); + self + } + #[inline(always)] + pub fn token_program( + &mut self, + token_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Event authority PDA + #[inline(always)] + pub fn event_authority( + &mut self, + event_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.event_authority = Some(event_authority); + self + } + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program( + &mut self, + commerce_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.commerce_program = Some(commerce_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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 instruction = ChargebackPaymentCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + payment: self.instruction.payment.expect("payment is not set"), + + operator_authority: self + .instruction + .operator_authority + .expect("operator_authority is not set"), + + buyer: self.instruction.buyer.expect("buyer is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + merchant_operator_config: self + .instruction + .merchant_operator_config + .expect("merchant_operator_config is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + merchant_escrow_ata: self + .instruction + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + + buyer_ata: self.instruction.buyer_ata.expect("buyer_ata is not set"), + + token_program: self + .instruction + .token_program + .expect("token_program is not set"), + + system_program: self + .instruction + .system_program + .expect("system_program is not set"), + + event_authority: self + .instruction + .event_authority + .expect("event_authority is not set"), + + commerce_program: self + .instruction + .commerce_program + .expect("commerce_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct ChargebackPaymentCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + payment: Option<&'b solana_account_info::AccountInfo<'a>>, + operator_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_operator_config: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_escrow_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + event_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + commerce_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/clear_payment.rs b/program/clients/rust/src/generated/instructions/clear_payment.rs new file mode 100644 index 0000000..15f183c --- /dev/null +++ b/program/clients/rust/src/generated/instructions/clear_payment.rs @@ -0,0 +1,876 @@ +//! 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; + +pub const CLEAR_PAYMENT_DISCRIMINATOR: u8 = 4; + +/// Accounts. +#[derive(Debug)] +pub struct ClearPayment { + pub payer: solana_pubkey::Pubkey, + /// New Payment PDA being created + pub payment: solana_pubkey::Pubkey, + + pub operator_authority: solana_pubkey::Pubkey, + + pub buyer: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + /// Operator PDA + pub operator: solana_pubkey::Pubkey, + + pub merchant_operator_config: solana_pubkey::Pubkey, + + pub mint: solana_pubkey::Pubkey, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: solana_pubkey::Pubkey, + /// Merchant Settlement ATA (Merchant settlement wallet is owner) + pub merchant_settlement_ata: solana_pubkey::Pubkey, + /// Operator Settlement ATA (Operator owner is owner) + pub operator_settlement_ata: solana_pubkey::Pubkey, + + pub token_program: solana_pubkey::Pubkey, + + pub associated_token_program: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, + /// Event authority PDA + pub event_authority: solana_pubkey::Pubkey, + /// Commerce Program ID + pub commerce_program: solana_pubkey::Pubkey, +} + +impl ClearPayment { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(16 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.payment, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator_authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.buyer, false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant_operator_config, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, false, + )); + accounts.push(solana_instruction::AccountMeta::new( + self.merchant_escrow_ata, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + self.merchant_settlement_ata, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + self.operator_settlement_ata, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.associated_token_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.event_authority, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.commerce_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&ClearPaymentInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ClearPaymentInstructionData { + discriminator: u8, +} + +impl ClearPaymentInstructionData { + pub fn new() -> Self { + Self { discriminator: 4 } + } +} + +impl Default for ClearPaymentInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `ClearPayment`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` buyer +/// 4. `[]` merchant +/// 5. `[]` operator +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` merchant_escrow_ata +/// 9. `[writable]` merchant_settlement_ata +/// 10. `[writable]` operator_settlement_ata +/// 11. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) +/// 12. `[optional]` associated_token_program (default to `ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL`) +/// 13. `[optional]` system_program (default to `11111111111111111111111111111111`) +/// 14. `[optional]` event_authority (default to `3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1`) +/// 15. `[optional]` commerce_program (default to `commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT`) +#[derive(Clone, Debug, Default)] +pub struct ClearPaymentBuilder { + payer: Option, + payment: Option, + operator_authority: Option, + buyer: Option, + merchant: Option, + operator: Option, + merchant_operator_config: Option, + mint: Option, + merchant_escrow_ata: Option, + merchant_settlement_ata: Option, + operator_settlement_ata: Option, + token_program: Option, + associated_token_program: Option, + system_program: Option, + event_authority: Option, + commerce_program: Option, + __remaining_accounts: Vec, +} + +impl ClearPaymentBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + /// New Payment PDA being created + #[inline(always)] + pub fn payment(&mut self, payment: solana_pubkey::Pubkey) -> &mut Self { + self.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority(&mut self, operator_authority: solana_pubkey::Pubkey) -> &mut Self { + self.operator_authority = Some(operator_authority); + self + } + #[inline(always)] + pub fn buyer(&mut self, buyer: solana_pubkey::Pubkey) -> &mut Self { + self.buyer = Some(buyer); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: solana_pubkey::Pubkey, + ) -> &mut Self { + self.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + /// Merchant Escrow ATA (Merchant PDA is owner) + #[inline(always)] + pub fn merchant_escrow_ata(&mut self, merchant_escrow_ata: solana_pubkey::Pubkey) -> &mut Self { + self.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + /// Merchant Settlement ATA (Merchant settlement wallet is owner) + #[inline(always)] + pub fn merchant_settlement_ata( + &mut self, + merchant_settlement_ata: solana_pubkey::Pubkey, + ) -> &mut Self { + self.merchant_settlement_ata = Some(merchant_settlement_ata); + self + } + /// Operator Settlement ATA (Operator owner is owner) + #[inline(always)] + pub fn operator_settlement_ata( + &mut self, + operator_settlement_ata: solana_pubkey::Pubkey, + ) -> &mut Self { + self.operator_settlement_ata = Some(operator_settlement_ata); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` + #[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + /// `[optional account, default to 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL']` + #[inline(always)] + pub fn associated_token_program( + &mut self, + associated_token_program: solana_pubkey::Pubkey, + ) -> &mut Self { + self.associated_token_program = Some(associated_token_program); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1']` + /// Event authority PDA + #[inline(always)] + pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self { + self.event_authority = Some(event_authority); + self + } + /// `[optional account, default to 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT']` + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program(&mut self, commerce_program: solana_pubkey::Pubkey) -> &mut Self { + self.commerce_program = Some(commerce_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = ClearPayment { + payer: self.payer.expect("payer is not set"), + payment: self.payment.expect("payment is not set"), + operator_authority: self + .operator_authority + .expect("operator_authority is not set"), + buyer: self.buyer.expect("buyer is not set"), + merchant: self.merchant.expect("merchant is not set"), + operator: self.operator.expect("operator is not set"), + merchant_operator_config: self + .merchant_operator_config + .expect("merchant_operator_config is not set"), + mint: self.mint.expect("mint is not set"), + merchant_escrow_ata: self + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + merchant_settlement_ata: self + .merchant_settlement_ata + .expect("merchant_settlement_ata is not set"), + operator_settlement_ata: self + .operator_settlement_ata + .expect("operator_settlement_ata is not set"), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!( + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + )), + associated_token_program: self.associated_token_program.unwrap_or( + solana_pubkey::pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"), + ), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + event_authority: self.event_authority.unwrap_or(solana_pubkey::pubkey!( + "3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1" + )), + commerce_program: self.commerce_program.unwrap_or(solana_pubkey::pubkey!( + "commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT" + )), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `clear_payment` CPI accounts. +pub struct ClearPaymentCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// New Payment PDA being created + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Settlement ATA (Merchant settlement wallet is owner) + pub merchant_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + /// Operator Settlement ATA (Operator owner is owner) + pub operator_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `clear_payment` CPI instruction. +pub struct ClearPaymentCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// New Payment PDA being created + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Settlement ATA (Merchant settlement wallet is owner) + pub merchant_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + /// Operator Settlement ATA (Operator owner is owner) + pub operator_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub associated_token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> ClearPaymentCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ClearPaymentCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + payment: accounts.payment, + operator_authority: accounts.operator_authority, + buyer: accounts.buyer, + merchant: accounts.merchant, + operator: accounts.operator, + merchant_operator_config: accounts.merchant_operator_config, + mint: accounts.mint, + merchant_escrow_ata: accounts.merchant_escrow_ata, + merchant_settlement_ata: accounts.merchant_settlement_ata, + operator_settlement_ata: accounts.operator_settlement_ata, + token_program: accounts.token_program, + associated_token_program: accounts.associated_token_program, + system_program: accounts.system_program, + event_authority: accounts.event_authority, + commerce_program: accounts.commerce_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(16 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.payment.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator_authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.buyer.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant_operator_config.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant_escrow_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant_settlement_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.operator_settlement_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.associated_token_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.event_authority.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.commerce_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&ClearPaymentInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(17 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.payment.clone()); + account_infos.push(self.operator_authority.clone()); + account_infos.push(self.buyer.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.merchant_operator_config.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.merchant_escrow_ata.clone()); + account_infos.push(self.merchant_settlement_ata.clone()); + account_infos.push(self.operator_settlement_ata.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.associated_token_program.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.event_authority.clone()); + account_infos.push(self.commerce_program.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `ClearPayment` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` buyer +/// 4. `[]` merchant +/// 5. `[]` operator +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` merchant_escrow_ata +/// 9. `[writable]` merchant_settlement_ata +/// 10. `[writable]` operator_settlement_ata +/// 11. `[]` token_program +/// 12. `[]` associated_token_program +/// 13. `[]` system_program +/// 14. `[]` event_authority +/// 15. `[]` commerce_program +#[derive(Clone, Debug)] +pub struct ClearPaymentCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ClearPaymentCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ClearPaymentCpiBuilderInstruction { + __program: program, + payer: None, + payment: None, + operator_authority: None, + buyer: None, + merchant: None, + operator: None, + merchant_operator_config: None, + mint: None, + merchant_escrow_ata: None, + merchant_settlement_ata: None, + operator_settlement_ata: None, + token_program: None, + associated_token_program: None, + system_program: None, + event_authority: None, + commerce_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + /// New Payment PDA being created + #[inline(always)] + pub fn payment(&mut self, payment: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority( + &mut self, + operator_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.operator_authority = Some(operator_authority); + self + } + #[inline(always)] + pub fn buyer(&mut self, buyer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer = Some(buyer); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + /// Merchant Escrow ATA (Merchant PDA is owner) + #[inline(always)] + pub fn merchant_escrow_ata( + &mut self, + merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + /// Merchant Settlement ATA (Merchant settlement wallet is owner) + #[inline(always)] + pub fn merchant_settlement_ata( + &mut self, + merchant_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_settlement_ata = Some(merchant_settlement_ata); + self + } + /// Operator Settlement ATA (Operator owner is owner) + #[inline(always)] + pub fn operator_settlement_ata( + &mut self, + operator_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.operator_settlement_ata = Some(operator_settlement_ata); + self + } + #[inline(always)] + pub fn token_program( + &mut self, + token_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn associated_token_program( + &mut self, + associated_token_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.associated_token_program = Some(associated_token_program); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Event authority PDA + #[inline(always)] + pub fn event_authority( + &mut self, + event_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.event_authority = Some(event_authority); + self + } + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program( + &mut self, + commerce_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.commerce_program = Some(commerce_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = ClearPaymentCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + payment: self.instruction.payment.expect("payment is not set"), + + operator_authority: self + .instruction + .operator_authority + .expect("operator_authority is not set"), + + buyer: self.instruction.buyer.expect("buyer is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + merchant_operator_config: self + .instruction + .merchant_operator_config + .expect("merchant_operator_config is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + merchant_escrow_ata: self + .instruction + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + + merchant_settlement_ata: self + .instruction + .merchant_settlement_ata + .expect("merchant_settlement_ata is not set"), + + operator_settlement_ata: self + .instruction + .operator_settlement_ata + .expect("operator_settlement_ata is not set"), + + token_program: self + .instruction + .token_program + .expect("token_program is not set"), + + associated_token_program: self + .instruction + .associated_token_program + .expect("associated_token_program is not set"), + + system_program: self + .instruction + .system_program + .expect("system_program is not set"), + + event_authority: self + .instruction + .event_authority + .expect("event_authority is not set"), + + commerce_program: self + .instruction + .commerce_program + .expect("commerce_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct ClearPaymentCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + payment: Option<&'b solana_account_info::AccountInfo<'a>>, + operator_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_operator_config: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_escrow_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_settlement_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + operator_settlement_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + event_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + commerce_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/close_payment.rs b/program/clients/rust/src/generated/instructions/close_payment.rs new file mode 100644 index 0000000..416e1ee --- /dev/null +++ b/program/clients/rust/src/generated/instructions/close_payment.rs @@ -0,0 +1,565 @@ +//! 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; + +pub const CLOSE_PAYMENT_DISCRIMINATOR: u8 = 9; + +/// Accounts. +#[derive(Debug)] +pub struct ClosePayment { + pub payer: solana_pubkey::Pubkey, + /// Payment PDA to close + pub payment: solana_pubkey::Pubkey, + + pub operator_authority: solana_pubkey::Pubkey, + /// Operator PDA + pub operator: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + /// Buyer account + pub buyer: solana_pubkey::Pubkey, + /// Merchant Operator Config PDA + pub merchant_operator_config: solana_pubkey::Pubkey, + /// Token mint + pub mint: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, +} + +impl ClosePayment { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(9 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.payment, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator_authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.buyer, false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant_operator_config, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&ClosePaymentInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ClosePaymentInstructionData { + discriminator: u8, +} + +impl ClosePaymentInstructionData { + pub fn new() -> Self { + Self { discriminator: 9 } + } +} + +impl Default for ClosePaymentInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `ClosePayment`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` operator +/// 4. `[]` merchant +/// 5. `[]` buyer +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct ClosePaymentBuilder { + payer: Option, + payment: Option, + operator_authority: Option, + operator: Option, + merchant: Option, + buyer: Option, + merchant_operator_config: Option, + mint: Option, + system_program: Option, + __remaining_accounts: Vec, +} + +impl ClosePaymentBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + /// Payment PDA to close + #[inline(always)] + pub fn payment(&mut self, payment: solana_pubkey::Pubkey) -> &mut Self { + self.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority(&mut self, operator_authority: solana_pubkey::Pubkey) -> &mut Self { + self.operator_authority = Some(operator_authority); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + /// Buyer account + #[inline(always)] + pub fn buyer(&mut self, buyer: solana_pubkey::Pubkey) -> &mut Self { + self.buyer = Some(buyer); + self + } + /// Merchant Operator Config PDA + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: solana_pubkey::Pubkey, + ) -> &mut Self { + self.merchant_operator_config = Some(merchant_operator_config); + self + } + /// Token mint + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = ClosePayment { + payer: self.payer.expect("payer is not set"), + payment: self.payment.expect("payment is not set"), + operator_authority: self + .operator_authority + .expect("operator_authority is not set"), + operator: self.operator.expect("operator is not set"), + merchant: self.merchant.expect("merchant is not set"), + buyer: self.buyer.expect("buyer is not set"), + merchant_operator_config: self + .merchant_operator_config + .expect("merchant_operator_config is not set"), + mint: self.mint.expect("mint is not set"), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `close_payment` CPI accounts. +pub struct ClosePaymentCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA to close + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Buyer account + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + /// Token mint + pub mint: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `close_payment` CPI instruction. +pub struct ClosePaymentCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA to close + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Buyer account + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + /// Token mint + pub mint: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> ClosePaymentCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ClosePaymentCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + payment: accounts.payment, + operator_authority: accounts.operator_authority, + operator: accounts.operator, + merchant: accounts.merchant, + buyer: accounts.buyer, + merchant_operator_config: accounts.merchant_operator_config, + mint: accounts.mint, + system_program: accounts.system_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(9 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.payment.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator_authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.buyer.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant_operator_config.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&ClosePaymentInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.payment.clone()); + account_infos.push(self.operator_authority.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.buyer.clone()); + account_infos.push(self.merchant_operator_config.clone()); + account_infos.push(self.mint.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_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `ClosePayment` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` operator +/// 4. `[]` merchant +/// 5. `[]` buyer +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[]` system_program +#[derive(Clone, Debug)] +pub struct ClosePaymentCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ClosePaymentCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ClosePaymentCpiBuilderInstruction { + __program: program, + payer: None, + payment: None, + operator_authority: None, + operator: None, + merchant: None, + buyer: None, + merchant_operator_config: None, + mint: None, + system_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + /// Payment PDA to close + #[inline(always)] + pub fn payment(&mut self, payment: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority( + &mut self, + operator_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.operator_authority = Some(operator_authority); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + /// Buyer account + #[inline(always)] + pub fn buyer(&mut self, buyer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer = Some(buyer); + self + } + /// Merchant Operator Config PDA + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_operator_config = Some(merchant_operator_config); + self + } + /// Token mint + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = ClosePaymentCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + payment: self.instruction.payment.expect("payment is not set"), + + operator_authority: self + .instruction + .operator_authority + .expect("operator_authority is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + buyer: self.instruction.buyer.expect("buyer is not set"), + + merchant_operator_config: self + .instruction + .merchant_operator_config + .expect("merchant_operator_config is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + system_program: self + .instruction + .system_program + .expect("system_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct ClosePaymentCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + payment: Option<&'b solana_account_info::AccountInfo<'a>>, + operator_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_operator_config: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/close_payment_permissionless.rs b/program/clients/rust/src/generated/instructions/close_payment_permissionless.rs new file mode 100644 index 0000000..72bd17d --- /dev/null +++ b/program/clients/rust/src/generated/instructions/close_payment_permissionless.rs @@ -0,0 +1,556 @@ +//! 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::BorshSerialize; +use borsh::BorshDeserialize; + +pub const CLOSE_PAYMENT_PERMISSIONLESS_DISCRIMINATOR: u8 = 10; + +/// Accounts. +#[derive(Debug)] +pub struct ClosePaymentPermissionless { + + + pub payer: solana_pubkey::Pubkey, + /// Payment PDA to close + + + + pub payment: solana_pubkey::Pubkey, + /// Operator PDA + + + + pub operator: solana_pubkey::Pubkey, + /// Merchant PDA + + + + pub merchant: solana_pubkey::Pubkey, + /// Buyer account + + + + pub buyer: solana_pubkey::Pubkey, + /// Merchant Operator Config PDA + + + + pub merchant_operator_config: solana_pubkey::Pubkey, + /// Token mint + + + + pub mint: solana_pubkey::Pubkey, + + + pub system_program: solana_pubkey::Pubkey, + } + +impl ClosePaymentPermissionless { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(8+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + self.payer, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + self.payment, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.buyer, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant_operator_config, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&ClosePaymentPermissionlessInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ClosePaymentPermissionlessInstructionData { + discriminator: u8, + } + +impl ClosePaymentPermissionlessInstructionData { + pub fn new() -> Self { + Self { + discriminator: 10, + } + } +} + +impl Default for ClosePaymentPermissionlessInstructionData { + fn default() -> Self { + Self::new() + } +} + + + +/// Instruction builder for `ClosePaymentPermissionless`. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` payer + /// 1. `[writable]` payment + /// 2. `[]` operator + /// 3. `[]` merchant + /// 4. `[]` buyer + /// 5. `[]` merchant_operator_config + /// 6. `[]` mint + /// 7. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct ClosePaymentPermissionlessBuilder { + payer: Option, + payment: Option, + operator: Option, + merchant: Option, + buyer: Option, + merchant_operator_config: Option, + mint: Option, + system_program: Option, + __remaining_accounts: Vec, +} + +impl ClosePaymentPermissionlessBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + /// Payment PDA to close +#[inline(always)] + pub fn payment(&mut self, payment: solana_pubkey::Pubkey) -> &mut Self { + self.payment = Some(payment); + self + } + /// Operator PDA +#[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + /// Merchant PDA +#[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + /// Buyer account +#[inline(always)] + pub fn buyer(&mut self, buyer: solana_pubkey::Pubkey) -> &mut Self { + self.buyer = Some(buyer); + self + } + /// Merchant Operator Config PDA +#[inline(always)] + pub fn merchant_operator_config(&mut self, merchant_operator_config: solana_pubkey::Pubkey) -> &mut Self { + self.merchant_operator_config = Some(merchant_operator_config); + self + } + /// Token mint +#[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` +#[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta]) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = ClosePaymentPermissionless { + payer: self.payer.expect("payer is not set"), + payment: self.payment.expect("payment is not set"), + operator: self.operator.expect("operator is not set"), + merchant: self.merchant.expect("merchant is not set"), + buyer: self.buyer.expect("buyer is not set"), + merchant_operator_config: self.merchant_operator_config.expect("merchant_operator_config is not set"), + mint: self.mint.expect("mint is not set"), + system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + + /// `close_payment_permissionless` CPI accounts. + pub struct ClosePaymentPermissionlessCpiAccounts<'a, 'b> { + + + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA to close + + + + pub payment: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + + + + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + + + + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Buyer account + + + + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + + + + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + /// Token mint + + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +/// `close_payment_permissionless` CPI instruction. +pub struct ClosePaymentPermissionlessCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA to close + + + + pub payment: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + + + + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + + + + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Buyer account + + + + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + + + + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + /// Token mint + + + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + } + +impl<'a, 'b> ClosePaymentPermissionlessCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: ClosePaymentPermissionlessCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + payment: accounts.payment, + operator: accounts.operator, + merchant: accounts.merchant, + buyer: accounts.buyer, + merchant_operator_config: accounts.merchant_operator_config, + mint: accounts.mint, + system_program: accounts.system_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)] + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(8+ remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.payer.key, + true + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.payment.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.buyer.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant_operator_config.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&ClosePaymentPermissionlessInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.payment.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.buyer.clone()); + account_infos.push(self.merchant_operator_config.clone()); + account_infos.push(self.mint.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_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `ClosePaymentPermissionless` via CPI. +/// +/// ### Accounts: +/// + /// 0. `[writable, signer]` payer + /// 1. `[writable]` payment + /// 2. `[]` operator + /// 3. `[]` merchant + /// 4. `[]` buyer + /// 5. `[]` merchant_operator_config + /// 6. `[]` mint + /// 7. `[]` system_program +#[derive(Clone, Debug)] +pub struct ClosePaymentPermissionlessCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> ClosePaymentPermissionlessCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(ClosePaymentPermissionlessCpiBuilderInstruction { + __program: program, + payer: None, + payment: None, + operator: None, + merchant: None, + buyer: None, + merchant_operator_config: None, + mint: None, + system_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + /// Payment PDA to close +#[inline(always)] + pub fn payment(&mut self, payment: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payment = Some(payment); + self + } + /// Operator PDA +#[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + /// Merchant PDA +#[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + /// Buyer account +#[inline(always)] + pub fn buyer(&mut self, buyer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer = Some(buyer); + self + } + /// Merchant Operator Config PDA +#[inline(always)] + pub fn merchant_operator_config(&mut self, merchant_operator_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant_operator_config = Some(merchant_operator_config); + self + } + /// Token mint +#[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = ClosePaymentPermissionlessCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + payment: self.instruction.payment.expect("payment is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + buyer: self.instruction.buyer.expect("buyer is not set"), + + merchant_operator_config: self.instruction.merchant_operator_config.expect("merchant_operator_config is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + system_program: self.instruction.system_program.expect("system_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts) + } +} + +#[derive(Clone, Debug)] +struct ClosePaymentPermissionlessCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + payment: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_operator_config: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} + diff --git a/program/clients/rust/src/generated/instructions/create_operator.rs b/program/clients/rust/src/generated/instructions/create_operator.rs new file mode 100644 index 0000000..ac4ca03 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/create_operator.rs @@ -0,0 +1,404 @@ +//! 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; + +pub const CREATE_OPERATOR_DISCRIMINATOR: u8 = 1; + +/// Accounts. +#[derive(Debug)] +pub struct CreateOperator { + pub payer: solana_pubkey::Pubkey, + + pub operator: solana_pubkey::Pubkey, + + pub authority: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, +} + +impl CreateOperator { + pub fn instruction( + &self, + args: CreateOperatorInstructionArgs, + ) -> solana_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: CreateOperatorInstructionArgs, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.operator, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = borsh::to_vec(&CreateOperatorInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&args).unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct CreateOperatorInstructionData { + discriminator: u8, +} + +impl CreateOperatorInstructionData { + pub fn new() -> Self { + Self { discriminator: 1 } + } +} + +impl Default for CreateOperatorInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct CreateOperatorInstructionArgs { + pub bump: u8, +} + +/// Instruction builder for `CreateOperator`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` operator +/// 2. `[signer]` authority +/// 3. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct CreateOperatorBuilder { + payer: Option, + operator: Option, + authority: Option, + system_program: Option, + bump: Option, + __remaining_accounts: Vec, +} + +impl CreateOperatorBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.bump = Some(bump); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = CreateOperator { + payer: self.payer.expect("payer is not set"), + operator: self.operator.expect("operator is not set"), + authority: self.authority.expect("authority is not set"), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + let args = CreateOperatorInstructionArgs { + bump: self.bump.clone().expect("bump is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + +/// `create_operator` CPI accounts. +pub struct CreateOperatorCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub operator: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `create_operator` CPI instruction. +pub struct CreateOperatorCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub operator: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: CreateOperatorInstructionArgs, +} + +impl<'a, 'b> CreateOperatorCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: CreateOperatorCpiAccounts<'a, 'b>, + args: CreateOperatorInstructionArgs, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + operator: accounts.operator, + authority: accounts.authority, + system_program: accounts.system_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = borsh::to_vec(&CreateOperatorInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&self.__args).unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.authority.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_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `CreateOperator` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` operator +/// 2. `[signer]` authority +/// 3. `[]` system_program +#[derive(Clone, Debug)] +pub struct CreateOperatorCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> CreateOperatorCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(CreateOperatorCpiBuilderInstruction { + __program: program, + payer: None, + operator: None, + authority: None, + system_program: None, + bump: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.authority = Some(authority); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.instruction.bump = Some(bump); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let args = CreateOperatorInstructionArgs { + bump: self.instruction.bump.clone().expect("bump is not set"), + }; + let instruction = CreateOperatorCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + authority: self.instruction.authority.expect("authority 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 CreateOperatorCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + authority: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + bump: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/emit_event.rs b/program/clients/rust/src/generated/instructions/emit_event.rs new file mode 100644 index 0000000..63beb9f --- /dev/null +++ b/program/clients/rust/src/generated/instructions/emit_event.rs @@ -0,0 +1,273 @@ +//! 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; + +pub const EMIT_EVENT_DISCRIMINATOR: u8 = 228; + +/// Accounts. +#[derive(Debug)] +pub struct EmitEvent { + pub event_authority: solana_pubkey::Pubkey, +} + +impl EmitEvent { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(1 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.event_authority, + true, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&EmitEventInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct EmitEventInstructionData { + discriminator: u8, +} + +impl EmitEventInstructionData { + pub fn new() -> Self { + Self { discriminator: 228 } + } +} + +impl Default for EmitEventInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `EmitEvent`. +/// +/// ### Accounts: +/// +/// 0. `[signer, optional]` event_authority (default to `3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1`) +#[derive(Clone, Debug, Default)] +pub struct EmitEventBuilder { + event_authority: Option, + __remaining_accounts: Vec, +} + +impl EmitEventBuilder { + pub fn new() -> Self { + Self::default() + } + /// `[optional account, default to '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1']` + #[inline(always)] + pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self { + self.event_authority = Some(event_authority); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = EmitEvent { + event_authority: self.event_authority.unwrap_or(solana_pubkey::pubkey!( + "3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1" + )), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `emit_event` CPI accounts. +pub struct EmitEventCpiAccounts<'a, 'b> { + pub event_authority: &'b solana_account_info::AccountInfo<'a>, +} + +/// `emit_event` CPI instruction. +pub struct EmitEventCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub event_authority: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> EmitEventCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: EmitEventCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + event_authority: accounts.event_authority, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(1 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.event_authority.key, + true, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&EmitEventInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.event_authority.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `EmitEvent` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[signer]` event_authority +#[derive(Clone, Debug)] +pub struct EmitEventCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> EmitEventCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(EmitEventCpiBuilderInstruction { + __program: program, + event_authority: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn event_authority( + &mut self, + event_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.event_authority = Some(event_authority); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = EmitEventCpi { + __program: self.instruction.__program, + + event_authority: self + .instruction + .event_authority + .expect("event_authority is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct EmitEventCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + event_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/initialize_merchant.rs b/program/clients/rust/src/generated/instructions/initialize_merchant.rs new file mode 100644 index 0000000..8207b1e --- /dev/null +++ b/program/clients/rust/src/generated/instructions/initialize_merchant.rs @@ -0,0 +1,446 @@ +//! 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; + +pub const INITIALIZE_MERCHANT_DISCRIMINATOR: u8 = 0; + +/// Accounts. +#[derive(Debug)] +pub struct InitializeMerchant { + pub payer: solana_pubkey::Pubkey, + + pub authority: solana_pubkey::Pubkey, + + pub merchant: solana_pubkey::Pubkey, + + pub settlement_wallet: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, +} + +impl InitializeMerchant { + pub fn instruction( + &self, + args: InitializeMerchantInstructionArgs, + ) -> solana_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: InitializeMerchantInstructionArgs, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(5 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new(self.merchant, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.settlement_wallet, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = borsh::to_vec(&InitializeMerchantInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&args).unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct InitializeMerchantInstructionData { + discriminator: u8, +} + +impl InitializeMerchantInstructionData { + pub fn new() -> Self { + Self { discriminator: 0 } + } +} + +impl Default for InitializeMerchantInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct InitializeMerchantInstructionArgs { + pub bump: u8, +} + +/// Instruction builder for `InitializeMerchant`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[signer]` authority +/// 2. `[writable]` merchant +/// 3. `[]` settlement_wallet +/// 4. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct InitializeMerchantBuilder { + payer: Option, + authority: Option, + merchant: Option, + settlement_wallet: Option, + system_program: Option, + bump: Option, + __remaining_accounts: Vec, +} + +impl InitializeMerchantBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); + self + } + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn settlement_wallet(&mut self, settlement_wallet: solana_pubkey::Pubkey) -> &mut Self { + self.settlement_wallet = Some(settlement_wallet); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.bump = Some(bump); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = InitializeMerchant { + payer: self.payer.expect("payer is not set"), + authority: self.authority.expect("authority is not set"), + merchant: self.merchant.expect("merchant is not set"), + settlement_wallet: self + .settlement_wallet + .expect("settlement_wallet is not set"), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + let args = InitializeMerchantInstructionArgs { + bump: self.bump.clone().expect("bump is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + +/// `initialize_merchant` CPI accounts. +pub struct InitializeMerchantCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub settlement_wallet: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `initialize_merchant` CPI instruction. +pub struct InitializeMerchantCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub settlement_wallet: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: InitializeMerchantInstructionArgs, +} + +impl<'a, 'b> InitializeMerchantCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: InitializeMerchantCpiAccounts<'a, 'b>, + args: InitializeMerchantInstructionArgs, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + authority: accounts.authority, + merchant: accounts.merchant, + settlement_wallet: accounts.settlement_wallet, + system_program: accounts.system_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(5 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.settlement_wallet.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = borsh::to_vec(&InitializeMerchantInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&self.__args).unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.authority.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.settlement_wallet.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_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `InitializeMerchant` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[signer]` authority +/// 2. `[writable]` merchant +/// 3. `[]` settlement_wallet +/// 4. `[]` system_program +#[derive(Clone, Debug)] +pub struct InitializeMerchantCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> InitializeMerchantCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(InitializeMerchantCpiBuilderInstruction { + __program: program, + payer: None, + authority: None, + merchant: None, + settlement_wallet: None, + system_program: None, + bump: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.authority = Some(authority); + self + } + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn settlement_wallet( + &mut self, + settlement_wallet: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.settlement_wallet = Some(settlement_wallet); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.instruction.bump = Some(bump); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let args = InitializeMerchantInstructionArgs { + bump: self.instruction.bump.clone().expect("bump is not set"), + }; + let instruction = InitializeMerchantCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + authority: self.instruction.authority.expect("authority is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + settlement_wallet: self + .instruction + .settlement_wallet + .expect("settlement_wallet 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 InitializeMerchantCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + authority: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + settlement_wallet: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + bump: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/initialize_merchant_operator_config.rs b/program/clients/rust/src/generated/instructions/initialize_merchant_operator_config.rs new file mode 100644 index 0000000..c3b8481 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/initialize_merchant_operator_config.rs @@ -0,0 +1,611 @@ +//! 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 crate::generated::types::FeeType; +use crate::generated::types::PolicyData; +use borsh::BorshDeserialize; +use borsh::BorshSerialize; +use solana_pubkey::Pubkey; + +pub const INITIALIZE_MERCHANT_OPERATOR_CONFIG_DISCRIMINATOR: u8 = 2; + +/// Accounts. +#[derive(Debug)] +pub struct InitializeMerchantOperatorConfig { + pub payer: solana_pubkey::Pubkey, + /// Authority of the merchant + pub authority: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + /// Operator PDA + pub operator: solana_pubkey::Pubkey, + /// The MerchantOperatorConfig PDA being initialized + pub config: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, +} + +impl InitializeMerchantOperatorConfig { + pub fn instruction( + &self, + args: InitializeMerchantOperatorConfigInstructionArgs, + ) -> solana_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: InitializeMerchantOperatorConfigInstructionArgs, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(6 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator, + false, + )); + accounts.push(solana_instruction::AccountMeta::new(self.config, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = + borsh::to_vec(&InitializeMerchantOperatorConfigInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&args).unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct InitializeMerchantOperatorConfigInstructionData { + discriminator: u8, +} + +impl InitializeMerchantOperatorConfigInstructionData { + pub fn new() -> Self { + Self { discriminator: 2 } + } +} + +impl Default for InitializeMerchantOperatorConfigInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct InitializeMerchantOperatorConfigInstructionArgs { + pub version: u32, + pub bump: u8, + pub operator_fee: u64, + pub fee_type: FeeType, + pub days_to_close: u16, + pub policies: Vec, + pub accepted_currencies: Vec, +} + +/// Instruction builder for `InitializeMerchantOperatorConfig`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[signer]` authority +/// 2. `[]` merchant +/// 3. `[]` operator +/// 4. `[writable]` config +/// 5. `[optional]` system_program (default to `11111111111111111111111111111111`) +#[derive(Clone, Debug, Default)] +pub struct InitializeMerchantOperatorConfigBuilder { + payer: Option, + authority: Option, + merchant: Option, + operator: Option, + config: Option, + system_program: Option, + version: Option, + bump: Option, + operator_fee: Option, + fee_type: Option, + days_to_close: Option, + policies: Option>, + accepted_currencies: Option>, + __remaining_accounts: Vec, +} + +impl InitializeMerchantOperatorConfigBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + /// Authority of the merchant + #[inline(always)] + pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + /// The MerchantOperatorConfig PDA being initialized + #[inline(always)] + pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self { + self.config = Some(config); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn version(&mut self, version: u32) -> &mut Self { + self.version = Some(version); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.bump = Some(bump); + self + } + #[inline(always)] + pub fn operator_fee(&mut self, operator_fee: u64) -> &mut Self { + self.operator_fee = Some(operator_fee); + self + } + #[inline(always)] + pub fn fee_type(&mut self, fee_type: FeeType) -> &mut Self { + self.fee_type = Some(fee_type); + self + } + #[inline(always)] + pub fn days_to_close(&mut self, days_to_close: u16) -> &mut Self { + self.days_to_close = Some(days_to_close); + self + } + #[inline(always)] + pub fn policies(&mut self, policies: Vec) -> &mut Self { + self.policies = Some(policies); + self + } + #[inline(always)] + pub fn accepted_currencies(&mut self, accepted_currencies: Vec) -> &mut Self { + self.accepted_currencies = Some(accepted_currencies); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = InitializeMerchantOperatorConfig { + payer: self.payer.expect("payer is not set"), + authority: self.authority.expect("authority is not set"), + merchant: self.merchant.expect("merchant is not set"), + operator: self.operator.expect("operator is not set"), + config: self.config.expect("config is not set"), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + }; + let args = InitializeMerchantOperatorConfigInstructionArgs { + version: self.version.clone().expect("version is not set"), + bump: self.bump.clone().expect("bump is not set"), + operator_fee: self.operator_fee.clone().expect("operator_fee is not set"), + fee_type: self.fee_type.clone().expect("fee_type is not set"), + days_to_close: self + .days_to_close + .clone() + .expect("days_to_close is not set"), + policies: self.policies.clone().expect("policies is not set"), + accepted_currencies: self + .accepted_currencies + .clone() + .expect("accepted_currencies is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + +/// `initialize_merchant_operator_config` CPI accounts. +pub struct InitializeMerchantOperatorConfigCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Authority of the merchant + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// The MerchantOperatorConfig PDA being initialized + pub config: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `initialize_merchant_operator_config` CPI instruction. +pub struct InitializeMerchantOperatorConfigCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Authority of the merchant + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// The MerchantOperatorConfig PDA being initialized + pub config: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: InitializeMerchantOperatorConfigInstructionArgs, +} + +impl<'a, 'b> InitializeMerchantOperatorConfigCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: InitializeMerchantOperatorConfigCpiAccounts<'a, 'b>, + args: InitializeMerchantOperatorConfigInstructionArgs, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + authority: accounts.authority, + merchant: accounts.merchant, + operator: accounts.operator, + config: accounts.config, + system_program: accounts.system_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(6 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.config.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = + borsh::to_vec(&InitializeMerchantOperatorConfigInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&self.__args).unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.authority.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.config.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_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `InitializeMerchantOperatorConfig` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[signer]` authority +/// 2. `[]` merchant +/// 3. `[]` operator +/// 4. `[writable]` config +/// 5. `[]` system_program +#[derive(Clone, Debug)] +pub struct InitializeMerchantOperatorConfigCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> InitializeMerchantOperatorConfigCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(InitializeMerchantOperatorConfigCpiBuilderInstruction { + __program: program, + payer: None, + authority: None, + merchant: None, + operator: None, + config: None, + system_program: None, + version: None, + bump: None, + operator_fee: None, + fee_type: None, + days_to_close: None, + policies: None, + accepted_currencies: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + /// Authority of the merchant + #[inline(always)] + pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.authority = Some(authority); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + /// The MerchantOperatorConfig PDA being initialized + #[inline(always)] + pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.config = Some(config); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + #[inline(always)] + pub fn version(&mut self, version: u32) -> &mut Self { + self.instruction.version = Some(version); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.instruction.bump = Some(bump); + self + } + #[inline(always)] + pub fn operator_fee(&mut self, operator_fee: u64) -> &mut Self { + self.instruction.operator_fee = Some(operator_fee); + self + } + #[inline(always)] + pub fn fee_type(&mut self, fee_type: FeeType) -> &mut Self { + self.instruction.fee_type = Some(fee_type); + self + } + #[inline(always)] + pub fn days_to_close(&mut self, days_to_close: u16) -> &mut Self { + self.instruction.days_to_close = Some(days_to_close); + self + } + #[inline(always)] + pub fn policies(&mut self, policies: Vec) -> &mut Self { + self.instruction.policies = Some(policies); + self + } + #[inline(always)] + pub fn accepted_currencies(&mut self, accepted_currencies: Vec) -> &mut Self { + self.instruction.accepted_currencies = Some(accepted_currencies); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let args = InitializeMerchantOperatorConfigInstructionArgs { + version: self + .instruction + .version + .clone() + .expect("version is not set"), + bump: self.instruction.bump.clone().expect("bump is not set"), + operator_fee: self + .instruction + .operator_fee + .clone() + .expect("operator_fee is not set"), + fee_type: self + .instruction + .fee_type + .clone() + .expect("fee_type is not set"), + days_to_close: self + .instruction + .days_to_close + .clone() + .expect("days_to_close is not set"), + policies: self + .instruction + .policies + .clone() + .expect("policies is not set"), + accepted_currencies: self + .instruction + .accepted_currencies + .clone() + .expect("accepted_currencies is not set"), + }; + let instruction = InitializeMerchantOperatorConfigCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + authority: self.instruction.authority.expect("authority is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + config: self.instruction.config.expect("config 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 InitializeMerchantOperatorConfigCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + authority: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + config: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + version: Option, + bump: Option, + operator_fee: Option, + fee_type: Option, + days_to_close: Option, + policies: Option>, + accepted_currencies: Option>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/make_payment.rs b/program/clients/rust/src/generated/instructions/make_payment.rs new file mode 100644 index 0000000..273e24d --- /dev/null +++ b/program/clients/rust/src/generated/instructions/make_payment.rs @@ -0,0 +1,877 @@ +//! 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; + +pub const MAKE_PAYMENT_DISCRIMINATOR: u8 = 3; + +/// Accounts. +#[derive(Debug)] +pub struct MakePayment { + pub payer: solana_pubkey::Pubkey, + + pub payment: solana_pubkey::Pubkey, + + pub operator_authority: solana_pubkey::Pubkey, + + pub buyer: solana_pubkey::Pubkey, + + pub operator: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + + pub merchant_operator_config: solana_pubkey::Pubkey, + + pub mint: solana_pubkey::Pubkey, + + pub buyer_ata: solana_pubkey::Pubkey, + + pub merchant_escrow_ata: solana_pubkey::Pubkey, + + pub merchant_settlement_ata: solana_pubkey::Pubkey, + + pub token_program: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, + /// Event authority PDA + pub event_authority: solana_pubkey::Pubkey, + /// Commerce Program ID + pub commerce_program: solana_pubkey::Pubkey, +} + +impl MakePayment { + pub fn instruction(&self, args: MakePaymentInstructionArgs) -> solana_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: MakePaymentInstructionArgs, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(15 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.payment, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator_authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.buyer, true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + self.merchant_operator_config, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, false, + )); + accounts.push(solana_instruction::AccountMeta::new(self.buyer_ata, false)); + accounts.push(solana_instruction::AccountMeta::new( + self.merchant_escrow_ata, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + self.merchant_settlement_ata, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.event_authority, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.commerce_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let mut data = borsh::to_vec(&MakePaymentInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&args).unwrap(); + data.append(&mut args); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct MakePaymentInstructionData { + discriminator: u8, +} + +impl MakePaymentInstructionData { + pub fn new() -> Self { + Self { discriminator: 3 } + } +} + +impl Default for MakePaymentInstructionData { + fn default() -> Self { + Self::new() + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct MakePaymentInstructionArgs { + pub order_id: u32, + pub amount: u64, + pub bump: u8, +} + +/// Instruction builder for `MakePayment`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[signer]` buyer +/// 4. `[]` operator +/// 5. `[]` merchant +/// 6. `[writable]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` buyer_ata +/// 9. `[writable]` merchant_escrow_ata +/// 10. `[writable]` merchant_settlement_ata +/// 11. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) +/// 12. `[optional]` system_program (default to `11111111111111111111111111111111`) +/// 13. `[optional]` event_authority (default to `3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1`) +/// 14. `[optional]` commerce_program (default to `commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT`) +#[derive(Clone, Debug, Default)] +pub struct MakePaymentBuilder { + payer: Option, + payment: Option, + operator_authority: Option, + buyer: Option, + operator: Option, + merchant: Option, + merchant_operator_config: Option, + mint: Option, + buyer_ata: Option, + merchant_escrow_ata: Option, + merchant_settlement_ata: Option, + token_program: Option, + system_program: Option, + event_authority: Option, + commerce_program: Option, + order_id: Option, + amount: Option, + bump: Option, + __remaining_accounts: Vec, +} + +impl MakePaymentBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn payment(&mut self, payment: solana_pubkey::Pubkey) -> &mut Self { + self.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority(&mut self, operator_authority: solana_pubkey::Pubkey) -> &mut Self { + self.operator_authority = Some(operator_authority); + self + } + #[inline(always)] + pub fn buyer(&mut self, buyer: solana_pubkey::Pubkey) -> &mut Self { + self.buyer = Some(buyer); + self + } + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: solana_pubkey::Pubkey, + ) -> &mut Self { + self.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] + pub fn buyer_ata(&mut self, buyer_ata: solana_pubkey::Pubkey) -> &mut Self { + self.buyer_ata = Some(buyer_ata); + self + } + #[inline(always)] + pub fn merchant_escrow_ata(&mut self, merchant_escrow_ata: solana_pubkey::Pubkey) -> &mut Self { + self.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + #[inline(always)] + pub fn merchant_settlement_ata( + &mut self, + merchant_settlement_ata: solana_pubkey::Pubkey, + ) -> &mut Self { + self.merchant_settlement_ata = Some(merchant_settlement_ata); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` + #[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1']` + /// Event authority PDA + #[inline(always)] + pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self { + self.event_authority = Some(event_authority); + self + } + /// `[optional account, default to 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT']` + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program(&mut self, commerce_program: solana_pubkey::Pubkey) -> &mut Self { + self.commerce_program = Some(commerce_program); + self + } + #[inline(always)] + pub fn order_id(&mut self, order_id: u32) -> &mut Self { + self.order_id = Some(order_id); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.amount = Some(amount); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.bump = Some(bump); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = MakePayment { + payer: self.payer.expect("payer is not set"), + payment: self.payment.expect("payment is not set"), + operator_authority: self + .operator_authority + .expect("operator_authority is not set"), + buyer: self.buyer.expect("buyer is not set"), + operator: self.operator.expect("operator is not set"), + merchant: self.merchant.expect("merchant is not set"), + merchant_operator_config: self + .merchant_operator_config + .expect("merchant_operator_config is not set"), + mint: self.mint.expect("mint is not set"), + buyer_ata: self.buyer_ata.expect("buyer_ata is not set"), + merchant_escrow_ata: self + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + merchant_settlement_ata: self + .merchant_settlement_ata + .expect("merchant_settlement_ata is not set"), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!( + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + )), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + event_authority: self.event_authority.unwrap_or(solana_pubkey::pubkey!( + "3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1" + )), + commerce_program: self.commerce_program.unwrap_or(solana_pubkey::pubkey!( + "commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT" + )), + }; + let args = MakePaymentInstructionArgs { + order_id: self.order_id.clone().expect("order_id is not set"), + amount: self.amount.clone().expect("amount is not set"), + bump: self.bump.clone().expect("bump is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + +/// `make_payment` CPI accounts. +pub struct MakePaymentCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + + pub buyer: &'b solana_account_info::AccountInfo<'a>, + + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + pub buyer_ata: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `make_payment` CPI instruction. +pub struct MakePaymentCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + + pub buyer: &'b solana_account_info::AccountInfo<'a>, + + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + + pub buyer_ata: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + + pub merchant_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, + /// The arguments for the instruction. + pub __args: MakePaymentInstructionArgs, +} + +impl<'a, 'b> MakePaymentCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: MakePaymentCpiAccounts<'a, 'b>, + args: MakePaymentInstructionArgs, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + payment: accounts.payment, + operator_authority: accounts.operator_authority, + buyer: accounts.buyer, + operator: accounts.operator, + merchant: accounts.merchant, + merchant_operator_config: accounts.merchant_operator_config, + mint: accounts.mint, + buyer_ata: accounts.buyer_ata, + merchant_escrow_ata: accounts.merchant_escrow_ata, + merchant_settlement_ata: accounts.merchant_settlement_ata, + token_program: accounts.token_program, + system_program: accounts.system_program, + event_authority: accounts.event_authority, + commerce_program: accounts.commerce_program, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(15 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.payment.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator_authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.buyer.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant_operator_config.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.buyer_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant_escrow_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant_settlement_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.event_authority.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.commerce_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = borsh::to_vec(&MakePaymentInstructionData::new()).unwrap(); + let mut args = borsh::to_vec(&self.__args).unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(16 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.payment.clone()); + account_infos.push(self.operator_authority.clone()); + account_infos.push(self.buyer.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.merchant_operator_config.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.buyer_ata.clone()); + account_infos.push(self.merchant_escrow_ata.clone()); + account_infos.push(self.merchant_settlement_ata.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.event_authority.clone()); + account_infos.push(self.commerce_program.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `MakePayment` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[signer]` buyer +/// 4. `[]` operator +/// 5. `[]` merchant +/// 6. `[writable]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` buyer_ata +/// 9. `[writable]` merchant_escrow_ata +/// 10. `[writable]` merchant_settlement_ata +/// 11. `[]` token_program +/// 12. `[]` system_program +/// 13. `[]` event_authority +/// 14. `[]` commerce_program +#[derive(Clone, Debug)] +pub struct MakePaymentCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> MakePaymentCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(MakePaymentCpiBuilderInstruction { + __program: program, + payer: None, + payment: None, + operator_authority: None, + buyer: None, + operator: None, + merchant: None, + merchant_operator_config: None, + mint: None, + buyer_ata: None, + merchant_escrow_ata: None, + merchant_settlement_ata: None, + token_program: None, + system_program: None, + event_authority: None, + commerce_program: None, + order_id: None, + amount: None, + bump: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn payment(&mut self, payment: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority( + &mut self, + operator_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.operator_authority = Some(operator_authority); + self + } + #[inline(always)] + pub fn buyer(&mut self, buyer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer = Some(buyer); + self + } + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] + pub fn buyer_ata(&mut self, buyer_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer_ata = Some(buyer_ata); + self + } + #[inline(always)] + pub fn merchant_escrow_ata( + &mut self, + merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + #[inline(always)] + pub fn merchant_settlement_ata( + &mut self, + merchant_settlement_ata: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_settlement_ata = Some(merchant_settlement_ata); + self + } + #[inline(always)] + pub fn token_program( + &mut self, + token_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Event authority PDA + #[inline(always)] + pub fn event_authority( + &mut self, + event_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.event_authority = Some(event_authority); + self + } + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program( + &mut self, + commerce_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.commerce_program = Some(commerce_program); + self + } + #[inline(always)] + pub fn order_id(&mut self, order_id: u32) -> &mut Self { + self.instruction.order_id = Some(order_id); + self + } + #[inline(always)] + pub fn amount(&mut self, amount: u64) -> &mut Self { + self.instruction.amount = Some(amount); + self + } + #[inline(always)] + pub fn bump(&mut self, bump: u8) -> &mut Self { + self.instruction.bump = Some(bump); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let args = MakePaymentInstructionArgs { + order_id: self + .instruction + .order_id + .clone() + .expect("order_id is not set"), + amount: self.instruction.amount.clone().expect("amount is not set"), + bump: self.instruction.bump.clone().expect("bump is not set"), + }; + let instruction = MakePaymentCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + payment: self.instruction.payment.expect("payment is not set"), + + operator_authority: self + .instruction + .operator_authority + .expect("operator_authority is not set"), + + buyer: self.instruction.buyer.expect("buyer is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + merchant_operator_config: self + .instruction + .merchant_operator_config + .expect("merchant_operator_config is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + buyer_ata: self.instruction.buyer_ata.expect("buyer_ata is not set"), + + merchant_escrow_ata: self + .instruction + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + + merchant_settlement_ata: self + .instruction + .merchant_settlement_ata + .expect("merchant_settlement_ata is not set"), + + token_program: self + .instruction + .token_program + .expect("token_program is not set"), + + system_program: self + .instruction + .system_program + .expect("system_program is not set"), + + event_authority: self + .instruction + .event_authority + .expect("event_authority is not set"), + + commerce_program: self + .instruction + .commerce_program + .expect("commerce_program is not set"), + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct MakePaymentCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + payment: Option<&'b solana_account_info::AccountInfo<'a>>, + operator_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_operator_config: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_escrow_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_settlement_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + event_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + commerce_program: Option<&'b solana_account_info::AccountInfo<'a>>, + order_id: Option, + amount: Option, + bump: Option, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/mod.rs b/program/clients/rust/src/generated/instructions/mod.rs new file mode 100644 index 0000000..6b1c7e5 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/mod.rs @@ -0,0 +1,30 @@ +//! 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. +//! +//! +//! + +pub(crate) mod r#clear_payment; +pub(crate) mod r#close_payment; +pub(crate) mod r#create_operator; +pub(crate) mod r#emit_event; +pub(crate) mod r#initialize_merchant; +pub(crate) mod r#initialize_merchant_operator_config; +pub(crate) mod r#make_payment; +pub(crate) mod r#refund_payment; +pub(crate) mod r#update_merchant_authority; +pub(crate) mod r#update_merchant_settlement_wallet; +pub(crate) mod r#update_operator_authority; + +pub use self::r#clear_payment::*; +pub use self::r#close_payment::*; +pub use self::r#create_operator::*; +pub use self::r#emit_event::*; +pub use self::r#initialize_merchant::*; +pub use self::r#initialize_merchant_operator_config::*; +pub use self::r#make_payment::*; +pub use self::r#refund_payment::*; +pub use self::r#update_merchant_authority::*; +pub use self::r#update_merchant_settlement_wallet::*; +pub use self::r#update_operator_authority::*; diff --git a/program/clients/rust/src/generated/instructions/refund_payment.rs b/program/clients/rust/src/generated/instructions/refund_payment.rs new file mode 100644 index 0000000..7210e93 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/refund_payment.rs @@ -0,0 +1,771 @@ +//! 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; + +pub const REFUND_PAYMENT_DISCRIMINATOR: u8 = 5; + +/// Accounts. +#[derive(Debug)] +pub struct RefundPayment { + pub payer: solana_pubkey::Pubkey, + /// Payment PDA being updated + pub payment: solana_pubkey::Pubkey, + + pub operator_authority: solana_pubkey::Pubkey, + /// Refund destination owner + pub buyer: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + /// Operator PDA + pub operator: solana_pubkey::Pubkey, + /// Merchant Operator Config PDA + pub merchant_operator_config: solana_pubkey::Pubkey, + + pub mint: solana_pubkey::Pubkey, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: solana_pubkey::Pubkey, + + pub buyer_ata: solana_pubkey::Pubkey, + + pub token_program: solana_pubkey::Pubkey, + + pub system_program: solana_pubkey::Pubkey, + /// Event authority PDA + pub event_authority: solana_pubkey::Pubkey, + /// Commerce Program ID + pub commerce_program: solana_pubkey::Pubkey, +} + +impl RefundPayment { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(14 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.payment, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator_authority, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.buyer, false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.operator, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.merchant_operator_config, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.mint, false, + )); + accounts.push(solana_instruction::AccountMeta::new( + self.merchant_escrow_ata, + false, + )); + accounts.push(solana_instruction::AccountMeta::new(self.buyer_ata, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.token_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.system_program, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.event_authority, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.commerce_program, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&RefundPaymentInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct RefundPaymentInstructionData { + discriminator: u8, +} + +impl RefundPaymentInstructionData { + pub fn new() -> Self { + Self { discriminator: 5 } + } +} + +impl Default for RefundPaymentInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `RefundPayment`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` buyer +/// 4. `[]` merchant +/// 5. `[]` operator +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` merchant_escrow_ata +/// 9. `[writable]` buyer_ata +/// 10. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`) +/// 11. `[optional]` system_program (default to `11111111111111111111111111111111`) +/// 12. `[optional]` event_authority (default to `3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1`) +/// 13. `[optional]` commerce_program (default to `commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT`) +#[derive(Clone, Debug, Default)] +pub struct RefundPaymentBuilder { + payer: Option, + payment: Option, + operator_authority: Option, + buyer: Option, + merchant: Option, + operator: Option, + merchant_operator_config: Option, + mint: Option, + merchant_escrow_ata: Option, + buyer_ata: Option, + token_program: Option, + system_program: Option, + event_authority: Option, + commerce_program: Option, + __remaining_accounts: Vec, +} + +impl RefundPaymentBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + /// Payment PDA being updated + #[inline(always)] + pub fn payment(&mut self, payment: solana_pubkey::Pubkey) -> &mut Self { + self.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority(&mut self, operator_authority: solana_pubkey::Pubkey) -> &mut Self { + self.operator_authority = Some(operator_authority); + self + } + /// Refund destination owner + #[inline(always)] + pub fn buyer(&mut self, buyer: solana_pubkey::Pubkey) -> &mut Self { + self.buyer = Some(buyer); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + /// Merchant Operator Config PDA + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: solana_pubkey::Pubkey, + ) -> &mut Self { + self.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + /// Merchant Escrow ATA (Merchant PDA is owner) + #[inline(always)] + pub fn merchant_escrow_ata(&mut self, merchant_escrow_ata: solana_pubkey::Pubkey) -> &mut Self { + self.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + #[inline(always)] + pub fn buyer_ata(&mut self, buyer_ata: solana_pubkey::Pubkey) -> &mut Self { + self.buyer_ata = Some(buyer_ata); + self + } + /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']` + #[inline(always)] + pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self { + self.token_program = Some(token_program); + self + } + /// `[optional account, default to '11111111111111111111111111111111']` + #[inline(always)] + pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self { + self.system_program = Some(system_program); + self + } + /// `[optional account, default to '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1']` + /// Event authority PDA + #[inline(always)] + pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self { + self.event_authority = Some(event_authority); + self + } + /// `[optional account, default to 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT']` + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program(&mut self, commerce_program: solana_pubkey::Pubkey) -> &mut Self { + self.commerce_program = Some(commerce_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = RefundPayment { + payer: self.payer.expect("payer is not set"), + payment: self.payment.expect("payment is not set"), + operator_authority: self + .operator_authority + .expect("operator_authority is not set"), + buyer: self.buyer.expect("buyer is not set"), + merchant: self.merchant.expect("merchant is not set"), + operator: self.operator.expect("operator is not set"), + merchant_operator_config: self + .merchant_operator_config + .expect("merchant_operator_config is not set"), + mint: self.mint.expect("mint is not set"), + merchant_escrow_ata: self + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + buyer_ata: self.buyer_ata.expect("buyer_ata is not set"), + token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!( + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + )), + system_program: self + .system_program + .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")), + event_authority: self.event_authority.unwrap_or(solana_pubkey::pubkey!( + "3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1" + )), + commerce_program: self.commerce_program.unwrap_or(solana_pubkey::pubkey!( + "commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT" + )), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `refund_payment` CPI accounts. +pub struct RefundPaymentCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA being updated + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + /// Refund destination owner + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + + pub buyer_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, +} + +/// `refund_payment` CPI instruction. +pub struct RefundPaymentCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + /// Payment PDA being updated + pub payment: &'b solana_account_info::AccountInfo<'a>, + + pub operator_authority: &'b solana_account_info::AccountInfo<'a>, + /// Refund destination owner + pub buyer: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Operator Config PDA + pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + + pub mint: &'b solana_account_info::AccountInfo<'a>, + /// Merchant Escrow ATA (Merchant PDA is owner) + pub merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + + pub buyer_ata: &'b solana_account_info::AccountInfo<'a>, + + pub token_program: &'b solana_account_info::AccountInfo<'a>, + + pub system_program: &'b solana_account_info::AccountInfo<'a>, + /// Event authority PDA + pub event_authority: &'b solana_account_info::AccountInfo<'a>, + /// Commerce Program ID + pub commerce_program: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> RefundPaymentCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: RefundPaymentCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + payment: accounts.payment, + operator_authority: accounts.operator_authority, + buyer: accounts.buyer, + merchant: accounts.merchant, + operator: accounts.operator, + merchant_operator_config: accounts.merchant_operator_config, + mint: accounts.mint, + merchant_escrow_ata: accounts.merchant_escrow_ata, + buyer_ata: accounts.buyer_ata, + token_program: accounts.token_program, + system_program: accounts.system_program, + event_authority: accounts.event_authority, + commerce_program: accounts.commerce_program, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(14 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.payment.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator_authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.buyer.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.merchant_operator_config.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.mint.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant_escrow_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.buyer_ata.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.token_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.system_program.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.event_authority.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.commerce_program.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&RefundPaymentInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(15 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.payment.clone()); + account_infos.push(self.operator_authority.clone()); + account_infos.push(self.buyer.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.merchant_operator_config.clone()); + account_infos.push(self.mint.clone()); + account_infos.push(self.merchant_escrow_ata.clone()); + account_infos.push(self.buyer_ata.clone()); + account_infos.push(self.token_program.clone()); + account_infos.push(self.system_program.clone()); + account_infos.push(self.event_authority.clone()); + account_infos.push(self.commerce_program.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `RefundPayment` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable]` payment +/// 2. `[signer]` operator_authority +/// 3. `[]` buyer +/// 4. `[]` merchant +/// 5. `[]` operator +/// 6. `[]` merchant_operator_config +/// 7. `[]` mint +/// 8. `[writable]` merchant_escrow_ata +/// 9. `[writable]` buyer_ata +/// 10. `[]` token_program +/// 11. `[]` system_program +/// 12. `[]` event_authority +/// 13. `[]` commerce_program +#[derive(Clone, Debug)] +pub struct RefundPaymentCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> RefundPaymentCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(RefundPaymentCpiBuilderInstruction { + __program: program, + payer: None, + payment: None, + operator_authority: None, + buyer: None, + merchant: None, + operator: None, + merchant_operator_config: None, + mint: None, + merchant_escrow_ata: None, + buyer_ata: None, + token_program: None, + system_program: None, + event_authority: None, + commerce_program: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + /// Payment PDA being updated + #[inline(always)] + pub fn payment(&mut self, payment: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payment = Some(payment); + self + } + #[inline(always)] + pub fn operator_authority( + &mut self, + operator_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.operator_authority = Some(operator_authority); + self + } + /// Refund destination owner + #[inline(always)] + pub fn buyer(&mut self, buyer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer = Some(buyer); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + /// Merchant Operator Config PDA + #[inline(always)] + pub fn merchant_operator_config( + &mut self, + merchant_operator_config: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_operator_config = Some(merchant_operator_config); + self + } + #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + /// Merchant Escrow ATA (Merchant PDA is owner) + #[inline(always)] + pub fn merchant_escrow_ata( + &mut self, + merchant_escrow_ata: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.merchant_escrow_ata = Some(merchant_escrow_ata); + self + } + #[inline(always)] + pub fn buyer_ata(&mut self, buyer_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.buyer_ata = Some(buyer_ata); + self + } + #[inline(always)] + pub fn token_program( + &mut self, + token_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.token_program = Some(token_program); + self + } + #[inline(always)] + pub fn system_program( + &mut self, + system_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.system_program = Some(system_program); + self + } + /// Event authority PDA + #[inline(always)] + pub fn event_authority( + &mut self, + event_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.event_authority = Some(event_authority); + self + } + /// Commerce Program ID + #[inline(always)] + pub fn commerce_program( + &mut self, + commerce_program: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.commerce_program = Some(commerce_program); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = RefundPaymentCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + payment: self.instruction.payment.expect("payment is not set"), + + operator_authority: self + .instruction + .operator_authority + .expect("operator_authority is not set"), + + buyer: self.instruction.buyer.expect("buyer is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + merchant_operator_config: self + .instruction + .merchant_operator_config + .expect("merchant_operator_config is not set"), + + mint: self.instruction.mint.expect("mint is not set"), + + merchant_escrow_ata: self + .instruction + .merchant_escrow_ata + .expect("merchant_escrow_ata is not set"), + + buyer_ata: self.instruction.buyer_ata.expect("buyer_ata is not set"), + + token_program: self + .instruction + .token_program + .expect("token_program is not set"), + + system_program: self + .instruction + .system_program + .expect("system_program is not set"), + + event_authority: self + .instruction + .event_authority + .expect("event_authority is not set"), + + commerce_program: self + .instruction + .commerce_program + .expect("commerce_program is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct RefundPaymentCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + payment: Option<&'b solana_account_info::AccountInfo<'a>>, + operator_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_operator_config: Option<&'b solana_account_info::AccountInfo<'a>>, + mint: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant_escrow_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + buyer_ata: Option<&'b solana_account_info::AccountInfo<'a>>, + token_program: Option<&'b solana_account_info::AccountInfo<'a>>, + system_program: Option<&'b solana_account_info::AccountInfo<'a>>, + event_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + commerce_program: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/update_merchant_authority.rs b/program/clients/rust/src/generated/instructions/update_merchant_authority.rs new file mode 100644 index 0000000..2c811e0 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/update_merchant_authority.rs @@ -0,0 +1,362 @@ +//! 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; + +pub const UPDATE_MERCHANT_AUTHORITY_DISCRIMINATOR: u8 = 7; + +/// Accounts. +#[derive(Debug)] +pub struct UpdateMerchantAuthority { + pub payer: solana_pubkey::Pubkey, + + pub authority: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + + pub new_authority: solana_pubkey::Pubkey, +} + +impl UpdateMerchantAuthority { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.authority, true)); + accounts.push(solana_instruction::AccountMeta::new(self.merchant, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.new_authority, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&UpdateMerchantAuthorityInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct UpdateMerchantAuthorityInstructionData { + discriminator: u8, +} + +impl UpdateMerchantAuthorityInstructionData { + pub fn new() -> Self { + Self { discriminator: 7 } + } +} + +impl Default for UpdateMerchantAuthorityInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `UpdateMerchantAuthority`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable, signer]` authority +/// 2. `[writable]` merchant +/// 3. `[]` new_authority +#[derive(Clone, Debug, Default)] +pub struct UpdateMerchantAuthorityBuilder { + payer: Option, + authority: Option, + merchant: Option, + new_authority: Option, + __remaining_accounts: Vec, +} + +impl UpdateMerchantAuthorityBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn new_authority(&mut self, new_authority: solana_pubkey::Pubkey) -> &mut Self { + self.new_authority = Some(new_authority); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = UpdateMerchantAuthority { + payer: self.payer.expect("payer is not set"), + authority: self.authority.expect("authority is not set"), + merchant: self.merchant.expect("merchant is not set"), + new_authority: self.new_authority.expect("new_authority is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `update_merchant_authority` CPI accounts. +pub struct UpdateMerchantAuthorityCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub new_authority: &'b solana_account_info::AccountInfo<'a>, +} + +/// `update_merchant_authority` CPI instruction. +pub struct UpdateMerchantAuthorityCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub new_authority: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> UpdateMerchantAuthorityCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: UpdateMerchantAuthorityCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + authority: accounts.authority, + merchant: accounts.merchant, + new_authority: accounts.new_authority, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.new_authority.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&UpdateMerchantAuthorityInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.authority.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.new_authority.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `UpdateMerchantAuthority` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable, signer]` authority +/// 2. `[writable]` merchant +/// 3. `[]` new_authority +#[derive(Clone, Debug)] +pub struct UpdateMerchantAuthorityCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> UpdateMerchantAuthorityCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(UpdateMerchantAuthorityCpiBuilderInstruction { + __program: program, + payer: None, + authority: None, + merchant: None, + new_authority: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.authority = Some(authority); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn new_authority( + &mut self, + new_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.new_authority = Some(new_authority); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = UpdateMerchantAuthorityCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + authority: self.instruction.authority.expect("authority is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + new_authority: self + .instruction + .new_authority + .expect("new_authority is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct UpdateMerchantAuthorityCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + authority: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + new_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/update_merchant_settlement_wallet.rs b/program/clients/rust/src/generated/instructions/update_merchant_settlement_wallet.rs new file mode 100644 index 0000000..57f9061 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/update_merchant_settlement_wallet.rs @@ -0,0 +1,367 @@ +//! 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; + +pub const UPDATE_MERCHANT_SETTLEMENT_WALLET_DISCRIMINATOR: u8 = 6; + +/// Accounts. +#[derive(Debug)] +pub struct UpdateMerchantSettlementWallet { + pub payer: solana_pubkey::Pubkey, + + pub authority: solana_pubkey::Pubkey, + /// Merchant PDA + pub merchant: solana_pubkey::Pubkey, + + pub new_settlement_wallet: solana_pubkey::Pubkey, +} + +impl UpdateMerchantSettlementWallet { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.authority, true)); + accounts.push(solana_instruction::AccountMeta::new(self.merchant, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.new_settlement_wallet, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&UpdateMerchantSettlementWalletInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct UpdateMerchantSettlementWalletInstructionData { + discriminator: u8, +} + +impl UpdateMerchantSettlementWalletInstructionData { + pub fn new() -> Self { + Self { discriminator: 6 } + } +} + +impl Default for UpdateMerchantSettlementWalletInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `UpdateMerchantSettlementWallet`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable, signer]` authority +/// 2. `[writable]` merchant +/// 3. `[]` new_settlement_wallet +#[derive(Clone, Debug, Default)] +pub struct UpdateMerchantSettlementWalletBuilder { + payer: Option, + authority: Option, + merchant: Option, + new_settlement_wallet: Option, + __remaining_accounts: Vec, +} + +impl UpdateMerchantSettlementWalletBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self { + self.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn new_settlement_wallet( + &mut self, + new_settlement_wallet: solana_pubkey::Pubkey, + ) -> &mut Self { + self.new_settlement_wallet = Some(new_settlement_wallet); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = UpdateMerchantSettlementWallet { + payer: self.payer.expect("payer is not set"), + authority: self.authority.expect("authority is not set"), + merchant: self.merchant.expect("merchant is not set"), + new_settlement_wallet: self + .new_settlement_wallet + .expect("new_settlement_wallet is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `update_merchant_settlement_wallet` CPI accounts. +pub struct UpdateMerchantSettlementWalletCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub new_settlement_wallet: &'b solana_account_info::AccountInfo<'a>, +} + +/// `update_merchant_settlement_wallet` CPI instruction. +pub struct UpdateMerchantSettlementWalletCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Merchant PDA + pub merchant: &'b solana_account_info::AccountInfo<'a>, + + pub new_settlement_wallet: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> UpdateMerchantSettlementWalletCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: UpdateMerchantSettlementWalletCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + authority: accounts.authority, + merchant: accounts.merchant, + new_settlement_wallet: accounts.new_settlement_wallet, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.merchant.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.new_settlement_wallet.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&UpdateMerchantSettlementWalletInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.authority.clone()); + account_infos.push(self.merchant.clone()); + account_infos.push(self.new_settlement_wallet.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `UpdateMerchantSettlementWallet` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable, signer]` authority +/// 2. `[writable]` merchant +/// 3. `[]` new_settlement_wallet +#[derive(Clone, Debug)] +pub struct UpdateMerchantSettlementWalletCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> UpdateMerchantSettlementWalletCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(UpdateMerchantSettlementWalletCpiBuilderInstruction { + __program: program, + payer: None, + authority: None, + merchant: None, + new_settlement_wallet: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.authority = Some(authority); + self + } + /// Merchant PDA + #[inline(always)] + pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.merchant = Some(merchant); + self + } + #[inline(always)] + pub fn new_settlement_wallet( + &mut self, + new_settlement_wallet: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.new_settlement_wallet = Some(new_settlement_wallet); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = UpdateMerchantSettlementWalletCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + authority: self.instruction.authority.expect("authority is not set"), + + merchant: self.instruction.merchant.expect("merchant is not set"), + + new_settlement_wallet: self + .instruction + .new_settlement_wallet + .expect("new_settlement_wallet is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct UpdateMerchantSettlementWalletCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + authority: Option<&'b solana_account_info::AccountInfo<'a>>, + merchant: Option<&'b solana_account_info::AccountInfo<'a>>, + new_settlement_wallet: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/instructions/update_operator_authority.rs b/program/clients/rust/src/generated/instructions/update_operator_authority.rs new file mode 100644 index 0000000..f8210c6 --- /dev/null +++ b/program/clients/rust/src/generated/instructions/update_operator_authority.rs @@ -0,0 +1,367 @@ +//! 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; + +pub const UPDATE_OPERATOR_AUTHORITY_DISCRIMINATOR: u8 = 8; + +/// Accounts. +#[derive(Debug)] +pub struct UpdateOperatorAuthority { + pub payer: solana_pubkey::Pubkey, + + pub authority: solana_pubkey::Pubkey, + /// Operator PDA + pub operator: solana_pubkey::Pubkey, + + pub new_operator_authority: solana_pubkey::Pubkey, +} + +impl UpdateOperatorAuthority { + pub fn instruction(&self) -> solana_instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::vec_init_then_push)] + pub fn instruction_with_remaining_accounts( + &self, + remaining_accounts: &[solana_instruction::AccountMeta], + ) -> solana_instruction::Instruction { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(self.payer, true)); + accounts.push(solana_instruction::AccountMeta::new(self.authority, true)); + accounts.push(solana_instruction::AccountMeta::new(self.operator, false)); + accounts.push(solana_instruction::AccountMeta::new_readonly( + self.new_operator_authority, + false, + )); + accounts.extend_from_slice(remaining_accounts); + let data = borsh::to_vec(&UpdateOperatorAuthorityInstructionData::new()).unwrap(); + + solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + } + } +} + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct UpdateOperatorAuthorityInstructionData { + discriminator: u8, +} + +impl UpdateOperatorAuthorityInstructionData { + pub fn new() -> Self { + Self { discriminator: 8 } + } +} + +impl Default for UpdateOperatorAuthorityInstructionData { + fn default() -> Self { + Self::new() + } +} + +/// Instruction builder for `UpdateOperatorAuthority`. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable, signer]` authority +/// 2. `[writable]` operator +/// 3. `[]` new_operator_authority +#[derive(Clone, Debug, Default)] +pub struct UpdateOperatorAuthorityBuilder { + payer: Option, + authority: Option, + operator: Option, + new_operator_authority: Option, + __remaining_accounts: Vec, +} + +impl UpdateOperatorAuthorityBuilder { + pub fn new() -> Self { + Self::default() + } + #[inline(always)] + pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self { + self.operator = Some(operator); + self + } + #[inline(always)] + pub fn new_operator_authority( + &mut self, + new_operator_authority: solana_pubkey::Pubkey, + ) -> &mut Self { + self.new_operator_authority = Some(new_operator_authority); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_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_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = UpdateOperatorAuthority { + payer: self.payer.expect("payer is not set"), + authority: self.authority.expect("authority is not set"), + operator: self.operator.expect("operator is not set"), + new_operator_authority: self + .new_operator_authority + .expect("new_operator_authority is not set"), + }; + + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) + } +} + +/// `update_operator_authority` CPI accounts. +pub struct UpdateOperatorAuthorityCpiAccounts<'a, 'b> { + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + + pub new_operator_authority: &'b solana_account_info::AccountInfo<'a>, +} + +/// `update_operator_authority` CPI instruction. +pub struct UpdateOperatorAuthorityCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub payer: &'b solana_account_info::AccountInfo<'a>, + + pub authority: &'b solana_account_info::AccountInfo<'a>, + /// Operator PDA + pub operator: &'b solana_account_info::AccountInfo<'a>, + + pub new_operator_authority: &'b solana_account_info::AccountInfo<'a>, +} + +impl<'a, 'b> UpdateOperatorAuthorityCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: UpdateOperatorAuthorityCpiAccounts<'a, 'b>, + ) -> Self { + Self { + __program: program, + payer: accounts.payer, + authority: accounts.authority, + operator: accounts.operator, + new_operator_authority: accounts.new_operator_authority, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true)); + accounts.push(solana_instruction::AccountMeta::new( + *self.authority.key, + true, + )); + accounts.push(solana_instruction::AccountMeta::new( + *self.operator.key, + false, + )); + accounts.push(solana_instruction::AccountMeta::new_readonly( + *self.new_operator_authority.key, + false, + )); + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let data = borsh::to_vec(&UpdateOperatorAuthorityInstructionData::new()).unwrap(); + + let instruction = solana_instruction::Instruction { + program_id: crate::COMMERCE_PROGRAM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.payer.clone()); + account_infos.push(self.authority.clone()); + account_infos.push(self.operator.clone()); + account_infos.push(self.new_operator_authority.clone()); + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `UpdateOperatorAuthority` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` payer +/// 1. `[writable, signer]` authority +/// 2. `[writable]` operator +/// 3. `[]` new_operator_authority +#[derive(Clone, Debug)] +pub struct UpdateOperatorAuthorityCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> UpdateOperatorAuthorityCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(UpdateOperatorAuthorityCpiBuilderInstruction { + __program: program, + payer: None, + authority: None, + operator: None, + new_operator_authority: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); + self + } + #[inline(always)] + pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.authority = Some(authority); + self + } + /// Operator PDA + #[inline(always)] + pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.operator = Some(operator); + self + } + #[inline(always)] + pub fn new_operator_authority( + &mut self, + new_operator_authority: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.new_operator_authority = Some(new_operator_authority); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_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_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_error::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_error::ProgramResult { + let instruction = UpdateOperatorAuthorityCpi { + __program: self.instruction.__program, + + payer: self.instruction.payer.expect("payer is not set"), + + authority: self.instruction.authority.expect("authority is not set"), + + operator: self.instruction.operator.expect("operator is not set"), + + new_operator_authority: self + .instruction + .new_operator_authority + .expect("new_operator_authority is not set"), + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct UpdateOperatorAuthorityCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + authority: Option<&'b solana_account_info::AccountInfo<'a>>, + operator: Option<&'b solana_account_info::AccountInfo<'a>>, + new_operator_authority: Option<&'b solana_account_info::AccountInfo<'a>>, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/program/clients/rust/src/generated/mod.rs b/program/clients/rust/src/generated/mod.rs new file mode 100644 index 0000000..e0d740a --- /dev/null +++ b/program/clients/rust/src/generated/mod.rs @@ -0,0 +1,15 @@ +//! 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. +//! +//! +//! + +pub mod accounts; +pub mod errors; +pub mod instructions; +pub mod programs; +pub mod shared; +pub mod types; + +pub(crate) use programs::*; diff --git a/program/clients/rust/src/generated/programs.rs b/program/clients/rust/src/generated/programs.rs new file mode 100644 index 0000000..8ce7a9c --- /dev/null +++ b/program/clients/rust/src/generated/programs.rs @@ -0,0 +1,11 @@ +//! 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 solana_pubkey::{pubkey, Pubkey}; + +/// `commerce_program` program ID. +pub const COMMERCE_PROGRAM_ID: Pubkey = pubkey!("commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT"); diff --git a/program/clients/rust/src/generated/shared.rs b/program/clients/rust/src/generated/shared.rs new file mode 100644 index 0000000..71b906d --- /dev/null +++ b/program/clients/rust/src/generated/shared.rs @@ -0,0 +1,21 @@ +//! 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. +//! +//! +//! + +#[cfg(feature = "fetch")] +#[derive(Debug, Clone)] +pub struct DecodedAccount { + pub address: solana_pubkey::Pubkey, + pub account: solana_account::Account, + pub data: T, +} + +#[cfg(feature = "fetch")] +#[derive(Debug, Clone)] +pub enum MaybeAccount { + Exists(DecodedAccount), + NotFound(solana_pubkey::Pubkey), +} diff --git a/program/clients/rust/src/generated/types/chargeback_policy.rs b/program/clients/rust/src/generated/types/chargeback_policy.rs new file mode 100644 index 0000000..e94c569 --- /dev/null +++ b/program/clients/rust/src/generated/types/chargeback_policy.rs @@ -0,0 +1,16 @@ +//! 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; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ChargebackPolicy { + pub max_amount: u64, + pub max_time_after_purchase: u64, +} diff --git a/program/clients/rust/src/generated/types/fee_type.rs b/program/clients/rust/src/generated/types/fee_type.rs new file mode 100644 index 0000000..b63741e --- /dev/null +++ b/program/clients/rust/src/generated/types/fee_type.rs @@ -0,0 +1,28 @@ +//! 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; +use num_derive::FromPrimitive; + +#[derive( + BorshSerialize, + BorshDeserialize, + Clone, + Debug, + Eq, + PartialEq, + Copy, + PartialOrd, + Hash, + FromPrimitive, +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum FeeType { + Bps, + Fixed, +} diff --git a/program/clients/rust/src/generated/types/mod.rs b/program/clients/rust/src/generated/types/mod.rs new file mode 100644 index 0000000..0fb4a5f --- /dev/null +++ b/program/clients/rust/src/generated/types/mod.rs @@ -0,0 +1,26 @@ +//! 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. +//! +//! +//! + +pub(crate) mod r#fee_type; +pub(crate) mod r#payment_cleared_event; +pub(crate) mod r#payment_created_event; +pub(crate) mod r#payment_refunded_event; +pub(crate) mod r#policy_data; +pub(crate) mod r#policy_type; +pub(crate) mod r#refund_policy; +pub(crate) mod r#settlement_policy; +pub(crate) mod r#status; + +pub use self::r#fee_type::*; +pub use self::r#payment_cleared_event::*; +pub use self::r#payment_created_event::*; +pub use self::r#payment_refunded_event::*; +pub use self::r#policy_data::*; +pub use self::r#policy_type::*; +pub use self::r#refund_policy::*; +pub use self::r#settlement_policy::*; +pub use self::r#status::*; diff --git a/program/clients/rust/src/generated/types/payment_chargebacked_event.rs b/program/clients/rust/src/generated/types/payment_chargebacked_event.rs new file mode 100644 index 0000000..43142f1 --- /dev/null +++ b/program/clients/rust/src/generated/types/payment_chargebacked_event.rs @@ -0,0 +1,33 @@ +//! 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; +use solana_pubkey::Pubkey; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct PaymentChargebackedEvent { + pub discriminator: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub buyer: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub merchant: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub operator: Pubkey, + pub amount: u64, + pub order_id: u32, +} diff --git a/program/clients/rust/src/generated/types/payment_cleared_event.rs b/program/clients/rust/src/generated/types/payment_cleared_event.rs new file mode 100644 index 0000000..36e9c21 --- /dev/null +++ b/program/clients/rust/src/generated/types/payment_cleared_event.rs @@ -0,0 +1,34 @@ +//! 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; +use solana_pubkey::Pubkey; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct PaymentClearedEvent { + pub discriminator: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub buyer: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub merchant: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub operator: Pubkey, + pub amount: u64, + pub operator_fee: u64, + pub order_id: u32, +} diff --git a/program/clients/rust/src/generated/types/payment_created_event.rs b/program/clients/rust/src/generated/types/payment_created_event.rs new file mode 100644 index 0000000..a01c5ae --- /dev/null +++ b/program/clients/rust/src/generated/types/payment_created_event.rs @@ -0,0 +1,33 @@ +//! 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; +use solana_pubkey::Pubkey; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct PaymentCreatedEvent { + pub discriminator: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub buyer: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub merchant: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub operator: Pubkey, + pub amount: u64, + pub order_id: u32, +} diff --git a/program/clients/rust/src/generated/types/payment_refunded_event.rs b/program/clients/rust/src/generated/types/payment_refunded_event.rs new file mode 100644 index 0000000..0bc2d83 --- /dev/null +++ b/program/clients/rust/src/generated/types/payment_refunded_event.rs @@ -0,0 +1,33 @@ +//! 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; +use solana_pubkey::Pubkey; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct PaymentRefundedEvent { + pub discriminator: u8, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub buyer: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub merchant: Pubkey, + #[cfg_attr( + feature = "serde", + serde(with = "serde_with::As::") + )] + pub operator: Pubkey, + pub amount: u64, + pub order_id: u32, +} diff --git a/program/clients/rust/src/generated/types/policy_data.rs b/program/clients/rust/src/generated/types/policy_data.rs new file mode 100644 index 0000000..0c4e4d4 --- /dev/null +++ b/program/clients/rust/src/generated/types/policy_data.rs @@ -0,0 +1,18 @@ +//! 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 crate::generated::types::RefundPolicy; +use crate::generated::types::SettlementPolicy; +use borsh::BorshDeserialize; +use borsh::BorshSerialize; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum PolicyData { + Refund(RefundPolicy), + Settlement(SettlementPolicy), +} diff --git a/program/clients/rust/src/generated/types/policy_type.rs b/program/clients/rust/src/generated/types/policy_type.rs new file mode 100644 index 0000000..d7e2659 --- /dev/null +++ b/program/clients/rust/src/generated/types/policy_type.rs @@ -0,0 +1,28 @@ +//! 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; +use num_derive::FromPrimitive; + +#[derive( + BorshSerialize, + BorshDeserialize, + Clone, + Debug, + Eq, + PartialEq, + Copy, + PartialOrd, + Hash, + FromPrimitive, +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum PolicyType { + Refund, + Settlement, +} diff --git a/program/clients/rust/src/generated/types/refund_policy.rs b/program/clients/rust/src/generated/types/refund_policy.rs new file mode 100644 index 0000000..ba57695 --- /dev/null +++ b/program/clients/rust/src/generated/types/refund_policy.rs @@ -0,0 +1,16 @@ +//! 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; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct RefundPolicy { + pub max_amount: u64, + pub max_time_after_purchase: u64, +} diff --git a/program/clients/rust/src/generated/types/settlement_policy.rs b/program/clients/rust/src/generated/types/settlement_policy.rs new file mode 100644 index 0000000..98c2ca9 --- /dev/null +++ b/program/clients/rust/src/generated/types/settlement_policy.rs @@ -0,0 +1,17 @@ +//! 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; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SettlementPolicy { + pub min_settlement_amount: u64, + pub settlement_frequency_hours: u32, + pub auto_settle: bool, +} diff --git a/program/clients/rust/src/generated/types/status.rs b/program/clients/rust/src/generated/types/status.rs new file mode 100644 index 0000000..bfd75d0 --- /dev/null +++ b/program/clients/rust/src/generated/types/status.rs @@ -0,0 +1,29 @@ +//! 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; +use num_derive::FromPrimitive; + +#[derive( + BorshSerialize, + BorshDeserialize, + Clone, + Debug, + Eq, + PartialEq, + Copy, + PartialOrd, + Hash, + FromPrimitive, +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum Status { + Paid, + Cleared, + Refunded, +} diff --git a/program/clients/typescript/src/generated/accounts/index.ts b/program/clients/typescript/src/generated/accounts/index.ts new file mode 100644 index 0000000..1054e1f --- /dev/null +++ b/program/clients/typescript/src/generated/accounts/index.ts @@ -0,0 +1,12 @@ +/** + * 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 + */ + +export * from './merchant'; +export * from './merchantOperatorConfig'; +export * from './operator'; +export * from './payment'; diff --git a/program/clients/typescript/src/generated/accounts/merchant.ts b/program/clients/typescript/src/generated/accounts/merchant.ts new file mode 100644 index 0000000..cbf7a3c --- /dev/null +++ b/program/clients/typescript/src/generated/accounts/merchant.ts @@ -0,0 +1,120 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from '@solana/kit'; + +export type Merchant = { + discriminator: number; + owner: Address; + bump: number; + settlementWallet: Address; +}; + +export type MerchantArgs = Merchant; + +export function getMerchantEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['owner', getAddressEncoder()], + ['bump', getU8Encoder()], + ['settlementWallet', getAddressEncoder()], + ]); +} + +export function getMerchantDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['owner', getAddressDecoder()], + ['bump', getU8Decoder()], + ['settlementWallet', getAddressDecoder()], + ]); +} + +export function getMerchantCodec(): FixedSizeCodec { + return combineCodec(getMerchantEncoder(), getMerchantDecoder()); +} + +export function decodeMerchant( + encodedAccount: EncodedAccount +): Account; +export function decodeMerchant( + encodedAccount: MaybeEncodedAccount +): MaybeAccount; +export function decodeMerchant( + encodedAccount: EncodedAccount | MaybeEncodedAccount +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getMerchantDecoder() + ); +} + +export async function fetchMerchant( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchMaybeMerchant(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeMerchant( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeMerchant(maybeAccount); +} + +export async function fetchAllMerchant( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchAllMaybeMerchant(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeMerchant( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeMerchant(maybeAccount)); +} + +export function getMerchantSize(): number { + return 66; +} diff --git a/program/clients/typescript/src/generated/accounts/merchantOperatorConfig.ts b/program/clients/typescript/src/generated/accounts/merchantOperatorConfig.ts new file mode 100644 index 0000000..dd13d8b --- /dev/null +++ b/program/clients/typescript/src/generated/accounts/merchantOperatorConfig.ts @@ -0,0 +1,187 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from '@solana/kit'; +import { + getFeeTypeDecoder, + getFeeTypeEncoder, + type FeeType, + type FeeTypeArgs, +} from '../types'; + +export type MerchantOperatorConfig = { + discriminator: number; + version: number; + bump: number; + merchant: Address; + operator: Address; + operatorFee: bigint; + feeType: FeeType; + currentOrderId: number; + daysToClose: number; + numPolicies: number; + numAcceptedCurrencies: number; +}; + +export type MerchantOperatorConfigArgs = { + discriminator: number; + version: number; + bump: number; + merchant: Address; + operator: Address; + operatorFee: number | bigint; + feeType: FeeTypeArgs; + currentOrderId: number; + daysToClose: number; + numPolicies: number; + numAcceptedCurrencies: number; +}; + +export function getMerchantOperatorConfigEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['version', getU32Encoder()], + ['bump', getU8Encoder()], + ['merchant', getAddressEncoder()], + ['operator', getAddressEncoder()], + ['operatorFee', getU64Encoder()], + ['feeType', getFeeTypeEncoder()], + ['currentOrderId', getU32Encoder()], + ['daysToClose', getU16Encoder()], + ['numPolicies', getU32Encoder()], + ['numAcceptedCurrencies', getU32Encoder()], + ]); +} + +export function getMerchantOperatorConfigDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['version', getU32Decoder()], + ['bump', getU8Decoder()], + ['merchant', getAddressDecoder()], + ['operator', getAddressDecoder()], + ['operatorFee', getU64Decoder()], + ['feeType', getFeeTypeDecoder()], + ['currentOrderId', getU32Decoder()], + ['daysToClose', getU16Decoder()], + ['numPolicies', getU32Decoder()], + ['numAcceptedCurrencies', getU32Decoder()], + ]); +} + +export function getMerchantOperatorConfigCodec(): FixedSizeCodec< + MerchantOperatorConfigArgs, + MerchantOperatorConfig +> { + return combineCodec( + getMerchantOperatorConfigEncoder(), + getMerchantOperatorConfigDecoder() + ); +} + +export function decodeMerchantOperatorConfig( + encodedAccount: EncodedAccount +): Account; +export function decodeMerchantOperatorConfig( + encodedAccount: MaybeEncodedAccount +): MaybeAccount; +export function decodeMerchantOperatorConfig( + encodedAccount: EncodedAccount | MaybeEncodedAccount +): + | Account + | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getMerchantOperatorConfigDecoder() + ); +} + +export async function fetchMerchantOperatorConfig< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchMaybeMerchantOperatorConfig( + rpc, + address, + config + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeMerchantOperatorConfig< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeMerchantOperatorConfig(maybeAccount); +} + +export async function fetchAllMerchantOperatorConfig( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchAllMaybeMerchantOperatorConfig( + rpc, + addresses, + config + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeMerchantOperatorConfig( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodeMerchantOperatorConfig(maybeAccount) + ); +} + +export function getMerchantOperatorConfigSize(): number { + return 93; +} diff --git a/program/clients/typescript/src/generated/accounts/operator.ts b/program/clients/typescript/src/generated/accounts/operator.ts new file mode 100644 index 0000000..d428996 --- /dev/null +++ b/program/clients/typescript/src/generated/accounts/operator.ts @@ -0,0 +1,113 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from '@solana/kit'; + +export type Operator = { discriminator: number; owner: Address; bump: number }; + +export type OperatorArgs = Operator; + +export function getOperatorEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['owner', getAddressEncoder()], + ['bump', getU8Encoder()], + ]); +} + +export function getOperatorDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['owner', getAddressDecoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getOperatorCodec(): FixedSizeCodec { + return combineCodec(getOperatorEncoder(), getOperatorDecoder()); +} + +export function decodeOperator( + encodedAccount: EncodedAccount +): Account; +export function decodeOperator( + encodedAccount: MaybeEncodedAccount +): MaybeAccount; +export function decodeOperator( + encodedAccount: EncodedAccount | MaybeEncodedAccount +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getOperatorDecoder() + ); +} + +export async function fetchOperator( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchMaybeOperator(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeOperator( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeOperator(maybeAccount); +} + +export async function fetchAllOperator( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchAllMaybeOperator(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeOperator( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeOperator(maybeAccount)); +} + +export function getOperatorSize(): number { + return 34; +} diff --git a/program/clients/typescript/src/generated/accounts/payment.ts b/program/clients/typescript/src/generated/accounts/payment.ts new file mode 100644 index 0000000..2f001dc --- /dev/null +++ b/program/clients/typescript/src/generated/accounts/payment.ts @@ -0,0 +1,143 @@ +/** + * 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 { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from '@solana/kit'; +import { + getStatusDecoder, + getStatusEncoder, + type Status, + type StatusArgs, +} from '../types'; + +export type Payment = { + discriminator: number; + orderId: number; + amount: bigint; + createdAt: bigint; + status: Status; + bump: number; +}; + +export type PaymentArgs = { + discriminator: number; + orderId: number; + amount: number | bigint; + createdAt: number | bigint; + status: StatusArgs; + bump: number; +}; + +export function getPaymentEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['orderId', getU32Encoder()], + ['amount', getU64Encoder()], + ['createdAt', getI64Encoder()], + ['status', getStatusEncoder()], + ['bump', getU8Encoder()], + ]); +} + +export function getPaymentDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['orderId', getU32Decoder()], + ['amount', getU64Decoder()], + ['createdAt', getI64Decoder()], + ['status', getStatusDecoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getPaymentCodec(): FixedSizeCodec { + return combineCodec(getPaymentEncoder(), getPaymentDecoder()); +} + +export function decodePayment( + encodedAccount: EncodedAccount +): Account; +export function decodePayment( + encodedAccount: MaybeEncodedAccount +): MaybeAccount; +export function decodePayment( + encodedAccount: EncodedAccount | MaybeEncodedAccount +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getPaymentDecoder() + ); +} + +export async function fetchPayment( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchMaybePayment(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybePayment( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodePayment(maybeAccount); +} + +export async function fetchAllPayment( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchAllMaybePayment(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybePayment( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodePayment(maybeAccount)); +} + +export function getPaymentSize(): number { + return 23; +} diff --git a/program/clients/typescript/src/generated/errors/commerceProgram.ts b/program/clients/typescript/src/generated/errors/commerceProgram.ts new file mode 100644 index 0000000..723ffa8 --- /dev/null +++ b/program/clients/typescript/src/generated/errors/commerceProgram.ts @@ -0,0 +1,132 @@ +/** + * 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 { + isProgramError, + type Address, + type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + type SolanaError, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; + +/** InvalidMint: Incorrect mint provided */ +export const COMMERCE_PROGRAM_ERROR__INVALID_MINT = 0x0; // 0 +/** InvalidPaymentStatus: Invalid payment status for the operation */ +export const COMMERCE_PROGRAM_ERROR__INVALID_PAYMENT_STATUS = 0x1; // 1 +/** InsufficientSettlementAmount: Insufficient settlement amount */ +export const COMMERCE_PROGRAM_ERROR__INSUFFICIENT_SETTLEMENT_AMOUNT = 0x2; // 2 +/** SettlementTooEarly: Settlement attempted too early */ +export const COMMERCE_PROGRAM_ERROR__SETTLEMENT_TOO_EARLY = 0x3; // 3 +/** RefundAmountExceedsPolicyLimit: Refund amount exceeds policy limit */ +export const COMMERCE_PROGRAM_ERROR__REFUND_AMOUNT_EXCEEDS_POLICY_LIMIT = 0x4; // 4 +/** RefundWindowExpired: Refund window expired */ +export const COMMERCE_PROGRAM_ERROR__REFUND_WINDOW_EXPIRED = 0x5; // 5 +/** InvalidEventAuthority: Invalid event authority */ +export const COMMERCE_PROGRAM_ERROR__INVALID_EVENT_AUTHORITY = 0x6; // 6 +/** InvalidAta: Invalid ATA */ +export const COMMERCE_PROGRAM_ERROR__INVALID_ATA = 0x7; // 7 +/** PaymentCloseWindowNotReached: Payment close window not reached */ +export const COMMERCE_PROGRAM_ERROR__PAYMENT_CLOSE_WINDOW_NOT_REACHED = 0x8; // 8 +/** MerchantOwnerMismatch: Merchant owner does not match expected owner */ +export const COMMERCE_PROGRAM_ERROR__MERCHANT_OWNER_MISMATCH = 0x9; // 9 +/** MerchantInvalidPda: Merchant PDA is invalid */ +export const COMMERCE_PROGRAM_ERROR__MERCHANT_INVALID_PDA = 0xa; // 10 +/** OperatorOwnerMismatch: Operator owner does not match expected owner */ +export const COMMERCE_PROGRAM_ERROR__OPERATOR_OWNER_MISMATCH = 0xb; // 11 +/** OperatorInvalidPda: Operator PDA is invalid */ +export const COMMERCE_PROGRAM_ERROR__OPERATOR_INVALID_PDA = 0xc; // 12 +/** OperatorMismatch: Operator does not match config operator */ +export const COMMERCE_PROGRAM_ERROR__OPERATOR_MISMATCH = 0xd; // 13 +/** MerchantMismatch: Merchant does not match config merchant */ +export const COMMERCE_PROGRAM_ERROR__MERCHANT_MISMATCH = 0xe; // 14 +/** OrderIdInvalid: Order ID is invalid or already used */ +export const COMMERCE_PROGRAM_ERROR__ORDER_ID_INVALID = 0xf; // 15 +/** MerchantOperatorConfigInvalidPda: MerchantOperatorConfig PDA is invalid */ +export const COMMERCE_PROGRAM_ERROR__MERCHANT_OPERATOR_CONFIG_INVALID_PDA = 0x10; // 16 +/** AcceptedCurrenciesEmpty: Accepted currencies is empty */ +export const COMMERCE_PROGRAM_ERROR__ACCEPTED_CURRENCIES_EMPTY = 0x11; // 17 +/** DuplicateMint: Duplicate mint in accepted currencies */ +export const COMMERCE_PROGRAM_ERROR__DUPLICATE_MINT = 0x12; // 18 + +export type CommerceProgramError = + | typeof COMMERCE_PROGRAM_ERROR__ACCEPTED_CURRENCIES_EMPTY + | typeof COMMERCE_PROGRAM_ERROR__DUPLICATE_MINT + | typeof COMMERCE_PROGRAM_ERROR__INSUFFICIENT_SETTLEMENT_AMOUNT + | typeof COMMERCE_PROGRAM_ERROR__INVALID_ATA + | typeof COMMERCE_PROGRAM_ERROR__INVALID_EVENT_AUTHORITY + | typeof COMMERCE_PROGRAM_ERROR__INVALID_MINT + | typeof COMMERCE_PROGRAM_ERROR__INVALID_PAYMENT_STATUS + | typeof COMMERCE_PROGRAM_ERROR__MERCHANT_INVALID_PDA + | typeof COMMERCE_PROGRAM_ERROR__MERCHANT_MISMATCH + | typeof COMMERCE_PROGRAM_ERROR__MERCHANT_OPERATOR_CONFIG_INVALID_PDA + | typeof COMMERCE_PROGRAM_ERROR__MERCHANT_OWNER_MISMATCH + | typeof COMMERCE_PROGRAM_ERROR__OPERATOR_INVALID_PDA + | typeof COMMERCE_PROGRAM_ERROR__OPERATOR_MISMATCH + | typeof COMMERCE_PROGRAM_ERROR__OPERATOR_OWNER_MISMATCH + | typeof COMMERCE_PROGRAM_ERROR__ORDER_ID_INVALID + | typeof COMMERCE_PROGRAM_ERROR__PAYMENT_CLOSE_WINDOW_NOT_REACHED + | typeof COMMERCE_PROGRAM_ERROR__REFUND_AMOUNT_EXCEEDS_POLICY_LIMIT + | typeof COMMERCE_PROGRAM_ERROR__REFUND_WINDOW_EXPIRED + | typeof COMMERCE_PROGRAM_ERROR__SETTLEMENT_TOO_EARLY; + +let commerceProgramErrorMessages: + | Record + | undefined; +if (process.env.NODE_ENV !== 'production') { + commerceProgramErrorMessages = { + [COMMERCE_PROGRAM_ERROR__ACCEPTED_CURRENCIES_EMPTY]: `Accepted currencies is empty`, + [COMMERCE_PROGRAM_ERROR__DUPLICATE_MINT]: `Duplicate mint in accepted currencies`, + [COMMERCE_PROGRAM_ERROR__INSUFFICIENT_SETTLEMENT_AMOUNT]: `Insufficient settlement amount`, + [COMMERCE_PROGRAM_ERROR__INVALID_ATA]: `Invalid ATA`, + [COMMERCE_PROGRAM_ERROR__INVALID_EVENT_AUTHORITY]: `Invalid event authority`, + [COMMERCE_PROGRAM_ERROR__INVALID_MINT]: `Incorrect mint provided`, + [COMMERCE_PROGRAM_ERROR__INVALID_PAYMENT_STATUS]: `Invalid payment status for the operation`, + [COMMERCE_PROGRAM_ERROR__MERCHANT_INVALID_PDA]: `Merchant PDA is invalid`, + [COMMERCE_PROGRAM_ERROR__MERCHANT_MISMATCH]: `Merchant does not match config merchant`, + [COMMERCE_PROGRAM_ERROR__MERCHANT_OPERATOR_CONFIG_INVALID_PDA]: `MerchantOperatorConfig PDA is invalid`, + [COMMERCE_PROGRAM_ERROR__MERCHANT_OWNER_MISMATCH]: `Merchant owner does not match expected owner`, + [COMMERCE_PROGRAM_ERROR__OPERATOR_INVALID_PDA]: `Operator PDA is invalid`, + [COMMERCE_PROGRAM_ERROR__OPERATOR_MISMATCH]: `Operator does not match config operator`, + [COMMERCE_PROGRAM_ERROR__OPERATOR_OWNER_MISMATCH]: `Operator owner does not match expected owner`, + [COMMERCE_PROGRAM_ERROR__ORDER_ID_INVALID]: `Order ID is invalid or already used`, + [COMMERCE_PROGRAM_ERROR__PAYMENT_CLOSE_WINDOW_NOT_REACHED]: `Payment close window not reached`, + [COMMERCE_PROGRAM_ERROR__REFUND_AMOUNT_EXCEEDS_POLICY_LIMIT]: `Refund amount exceeds policy limit`, + [COMMERCE_PROGRAM_ERROR__REFUND_WINDOW_EXPIRED]: `Refund window expired`, + [COMMERCE_PROGRAM_ERROR__SETTLEMENT_TOO_EARLY]: `Settlement attempted too early`, + }; +} + +export function getCommerceProgramErrorMessage( + code: CommerceProgramError +): string { + if (process.env.NODE_ENV !== 'production') { + return ( + commerceProgramErrorMessages as Record + )[code]; + } + + return 'Error message not available in production bundles.'; +} + +export function isCommerceProgramError< + TProgramErrorCode extends CommerceProgramError, +>( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + COMMERCE_PROGRAM_PROGRAM_ADDRESS, + code + ); +} diff --git a/program/clients/typescript/src/generated/errors/index.ts b/program/clients/typescript/src/generated/errors/index.ts new file mode 100644 index 0000000..96e5fd5 --- /dev/null +++ b/program/clients/typescript/src/generated/errors/index.ts @@ -0,0 +1,9 @@ +/** + * 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 + */ + +export * from './commerceProgram'; diff --git a/program/clients/typescript/src/generated/index.ts b/program/clients/typescript/src/generated/index.ts new file mode 100644 index 0000000..1f8edf1 --- /dev/null +++ b/program/clients/typescript/src/generated/index.ts @@ -0,0 +1,14 @@ +/** + * 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 + */ + +export * from './accounts'; +export * from './errors'; +export * from './instructions'; +export * from './pdas'; +export * from './programs'; +export * from './types'; diff --git a/program/clients/typescript/src/generated/instructions/chargebackPayment.ts b/program/clients/typescript/src/generated/instructions/chargebackPayment.ts new file mode 100644 index 0000000..52fc10e --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/chargebackPayment.ts @@ -0,0 +1,350 @@ +/** + * 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 { address, combineCodec, getAddressEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, getUtf8Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { expectAddress, getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const CHARGEBACK_PAYMENT_DISCRIMINATOR = 6; + +export function getChargebackPaymentDiscriminatorBytes() { return getU8Encoder().encode(CHARGEBACK_PAYMENT_DISCRIMINATOR); } + +export type ChargebackPaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, TAccountPayment extends string | AccountMeta = string, TAccountOperatorAuthority extends string | AccountMeta = string, TAccountBuyer extends string | AccountMeta = string, TAccountMerchant extends string | AccountMeta = string, TAccountOperator extends string | AccountMeta = string, TAccountMerchantOperatorConfig extends string | AccountMeta = string, TAccountMint extends string | AccountMeta = string, TAccountMerchantEscrowAta extends string | AccountMeta = string, TAccountBuyerAta extends string | AccountMeta = string, TAccountTokenProgram extends string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TAccountEventAuthority extends string | AccountMeta = "3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1", TAccountCommerceProgram extends string | AccountMeta = "commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction + & InstructionWithData + & InstructionWithAccounts<[TAccountPayer extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayer, TAccountPayment extends string ? WritableAccount : TAccountPayment, TAccountOperatorAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountOperatorAuthority, TAccountBuyer extends string ? ReadonlyAccount : TAccountBuyer, TAccountMerchant extends string ? ReadonlyAccount : TAccountMerchant, TAccountOperator extends string ? ReadonlyAccount : TAccountOperator, TAccountMerchantOperatorConfig extends string ? ReadonlyAccount : TAccountMerchantOperatorConfig, TAccountMint extends string ? ReadonlyAccount : TAccountMint, TAccountMerchantEscrowAta extends string ? WritableAccount : TAccountMerchantEscrowAta, TAccountBuyerAta extends string ? WritableAccount : TAccountBuyerAta, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountEventAuthority extends string ? ReadonlyAccount : TAccountEventAuthority, TAccountCommerceProgram extends string ? ReadonlyAccount : TAccountCommerceProgram, ...TRemainingAccounts]> + ; + + + +export type ChargebackPaymentInstructionData = { discriminator: number; }; + +export type ChargebackPaymentInstructionDataArgs = { }; + + + + +export function getChargebackPaymentInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), (value) => ({ ...value, discriminator: CHARGEBACK_PAYMENT_DISCRIMINATOR })); +} + + + +export function getChargebackPaymentInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + + + + +export function getChargebackPaymentInstructionDataCodec(): FixedSizeCodec { + return combineCodec(getChargebackPaymentInstructionDataEncoder(), getChargebackPaymentInstructionDataDecoder()); +} + + + +export type ChargebackPaymentAsyncInput += { + payer: TransactionSigner; +/** Payment PDA being updated */ +payment: Address; +operatorAuthority: TransactionSigner; +/** Chargeback destination owner */ +buyer: Address; +/** Merchant PDA */ +merchant: Address; +/** Operator PDA */ +operator?: Address; +/** Merchant Operator Config PDA */ +merchantOperatorConfig: Address; +mint: Address; +/** Merchant Escrow ATA (Merchant PDA is owner) */ +merchantEscrowAta?: Address; +buyerAta?: Address; +tokenProgram?: Address; +systemProgram?: Address; +/** Event authority PDA */ +eventAuthority?: Address; +/** Commerce Program ID */ +commerceProgram?: Address; +} + + +export async function getChargebackPaymentInstructionAsync(input: ChargebackPaymentAsyncInput, config?: { programAddress?: TProgramAddress } ): Promise> { + // Program address. + const programAddress = config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { value: input.operatorAuthority ?? null, isWritable: false }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchantOperatorConfig: { value: input.merchantOperatorConfig ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + merchantEscrowAta: { value: input.merchantEscrowAta ?? null, isWritable: true }, + buyerAta: { value: input.buyerAta ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { value: input.commerceProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record; + + + + // Resolve default values. +if (!accounts.operator.value) { +accounts.operator.value = await getProgramDerivedAddress({ programAddress: 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, seeds: [getUtf8Encoder().encode("operator"), getAddressEncoder().encode(expectAddress(accounts.operatorAuthority.value))] }); +} +if (!accounts.merchantEscrowAta.value) { +accounts.merchantEscrowAta.value = await getProgramDerivedAddress({ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, seeds: [getAddressEncoder().encode(expectAddress(accounts.merchant.value)), getAddressEncoder().encode(address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), getAddressEncoder().encode(expectAddress(accounts.mint.value))] }); +} +if (!accounts.buyerAta.value) { +accounts.buyerAta.value = await getProgramDerivedAddress({ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, seeds: [getAddressEncoder().encode(expectAddress(accounts.buyer.value)), getAddressEncoder().encode(address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")), getAddressEncoder().encode(expectAddress(accounts.mint.value))] }); +} +if (!accounts.tokenProgram.value) { +accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; +} +if (!accounts.systemProgram.value) { +accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; +} +if (!accounts.eventAuthority.value) { +accounts.eventAuthority.value = '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; +} +if (!accounts.commerceProgram.value) { +accounts.commerceProgram.value = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; +} + + + + + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = {accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.buyerAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ] , programAddress, + data: getChargebackPaymentInstructionDataEncoder().encode({}), + } as ChargebackPaymentInstruction; + + return instruction; + } + + +export type ChargebackPaymentInput += { + payer: TransactionSigner; +/** Payment PDA being updated */ +payment: Address; +operatorAuthority: TransactionSigner; +/** Chargeback destination owner */ +buyer: Address; +/** Merchant PDA */ +merchant: Address; +/** Operator PDA */ +operator: Address; +/** Merchant Operator Config PDA */ +merchantOperatorConfig: Address; +mint: Address; +/** Merchant Escrow ATA (Merchant PDA is owner) */ +merchantEscrowAta: Address; +buyerAta: Address; +tokenProgram?: Address; +systemProgram?: Address; +/** Event authority PDA */ +eventAuthority?: Address; +/** Commerce Program ID */ +commerceProgram?: Address; +} + + +export function getChargebackPaymentInstruction(input: ChargebackPaymentInput, config?: { programAddress?: TProgramAddress } ): ChargebackPaymentInstruction { + // Program address. + const programAddress = config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { value: input.operatorAuthority ?? null, isWritable: false }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchantOperatorConfig: { value: input.merchantOperatorConfig ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + merchantEscrowAta: { value: input.merchantEscrowAta ?? null, isWritable: true }, + buyerAta: { value: input.buyerAta ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { value: input.commerceProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record; + + + + // Resolve default values. +if (!accounts.tokenProgram.value) { +accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; +} +if (!accounts.systemProgram.value) { +accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; +} +if (!accounts.eventAuthority.value) { +accounts.eventAuthority.value = '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; +} +if (!accounts.commerceProgram.value) { +accounts.commerceProgram.value = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; +} + + + + + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = {accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.buyerAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ] , programAddress, + data: getChargebackPaymentInstructionDataEncoder().encode({}), + } as ChargebackPaymentInstruction; + + return instruction; + } + + +export type ParsedChargebackPaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], + > = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0], + /** Payment PDA being updated */ + payment: TAccountMetas[1], + operatorAuthority: TAccountMetas[2], + /** Chargeback destination owner */ + buyer: TAccountMetas[3], + /** Merchant PDA */ + merchant: TAccountMetas[4], + /** Operator PDA */ + operator: TAccountMetas[5], + /** Merchant Operator Config PDA */ + merchantOperatorConfig: TAccountMetas[6], + mint: TAccountMetas[7], + /** Merchant Escrow ATA (Merchant PDA is owner) */ + merchantEscrowAta: TAccountMetas[8], + buyerAta: TAccountMetas[9], + tokenProgram: TAccountMetas[10], + systemProgram: TAccountMetas[11], + /** Event authority PDA */ + eventAuthority: TAccountMetas[12], + /** Commerce Program ID */ + commerceProgram: TAccountMetas[13], + }; + data: ChargebackPaymentInstructionData; + }; + +export function parseChargebackPaymentInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], + >( + instruction: Instruction + & InstructionWithAccounts + & InstructionWithData + ): ParsedChargebackPaymentInstruction { + if (instruction.accounts.length < 14) { + // 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: { + payer: getNextAccount(), + payment: getNextAccount(), + operatorAuthority: getNextAccount(), + buyer: getNextAccount(), + merchant: getNextAccount(), + operator: getNextAccount(), + merchantOperatorConfig: getNextAccount(), + mint: getNextAccount(), + merchantEscrowAta: getNextAccount(), + buyerAta: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + commerceProgram: getNextAccount(), + }, + data: getChargebackPaymentInstructionDataDecoder().decode(instruction.data), + }; +} + diff --git a/program/clients/typescript/src/generated/instructions/clearPayment.ts b/program/clients/typescript/src/generated/instructions/clearPayment.ts new file mode 100644 index 0000000..8101990 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/clearPayment.ts @@ -0,0 +1,711 @@ +/** + * 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 { + address, + combineCodec, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const CLEAR_PAYMENT_DISCRIMINATOR = 4; + +export function getClearPaymentDiscriminatorBytes() { + return getU8Encoder().encode(CLEAR_PAYMENT_DISCRIMINATOR); +} + +export type ClearPaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountPayment extends string | AccountMeta = string, + TAccountOperatorAuthority extends string | AccountMeta = string, + TAccountBuyer extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountMerchantOperatorConfig extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountMerchantEscrowAta extends string | AccountMeta = string, + TAccountMerchantSettlementAta extends string | AccountMeta = string, + TAccountOperatorSettlementAta extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + TAccountAssociatedTokenProgram extends + | string + | AccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountEventAuthority extends + | string + | AccountMeta = '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1', + TAccountCommerceProgram extends + | string + | AccountMeta = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountPayment extends string + ? WritableAccount + : TAccountPayment, + TAccountOperatorAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountOperatorAuthority, + TAccountBuyer extends string + ? ReadonlyAccount + : TAccountBuyer, + TAccountMerchant extends string + ? ReadonlyAccount + : TAccountMerchant, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountMerchantOperatorConfig extends string + ? ReadonlyAccount + : TAccountMerchantOperatorConfig, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountMerchantEscrowAta extends string + ? WritableAccount + : TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta extends string + ? WritableAccount + : TAccountMerchantSettlementAta, + TAccountOperatorSettlementAta extends string + ? WritableAccount + : TAccountOperatorSettlementAta, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountCommerceProgram extends string + ? ReadonlyAccount + : TAccountCommerceProgram, + ...TRemainingAccounts, + ] + >; + +export type ClearPaymentInstructionData = { discriminator: number }; + +export type ClearPaymentInstructionDataArgs = {}; + +export function getClearPaymentInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: CLEAR_PAYMENT_DISCRIMINATOR }) + ); +} + +export function getClearPaymentInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getClearPaymentInstructionDataCodec(): FixedSizeCodec< + ClearPaymentInstructionDataArgs, + ClearPaymentInstructionData +> { + return combineCodec( + getClearPaymentInstructionDataEncoder(), + getClearPaymentInstructionDataDecoder() + ); +} + +export type ClearPaymentAsyncInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountBuyer extends string = string, + TAccountMerchant extends string = string, + TAccountOperator extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountMerchantEscrowAta extends string = string, + TAccountMerchantSettlementAta extends string = string, + TAccountOperatorSettlementAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountCommerceProgram extends string = string, +> = { + payer: TransactionSigner; + /** New Payment PDA being created */ + payment: Address; + operatorAuthority: TransactionSigner; + buyer: Address; + /** Merchant PDA */ + merchant: Address; + /** Operator PDA */ + operator?: Address; + merchantOperatorConfig: Address; + mint: Address; + /** Merchant Escrow ATA (Merchant PDA is owner) */ + merchantEscrowAta?: Address; + /** Merchant Settlement ATA (Merchant settlement wallet is owner) */ + merchantSettlementAta: Address; + /** Operator Settlement ATA (Operator owner is owner) */ + operatorSettlementAta?: Address; + tokenProgram?: Address; + associatedTokenProgram?: Address; + systemProgram?: Address; + /** Event authority PDA */ + eventAuthority?: Address; + /** Commerce Program ID */ + commerceProgram?: Address; +}; + +export async function getClearPaymentInstructionAsync< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountBuyer extends string, + TAccountMerchant extends string, + TAccountOperator extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountMerchantEscrowAta extends string, + TAccountMerchantSettlementAta extends string, + TAccountOperatorSettlementAta extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountCommerceProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: ClearPaymentAsyncInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountOperatorSettlementAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + ClearPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountOperatorSettlementAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: false, + }, + mint: { value: input.mint ?? null, isWritable: false }, + merchantEscrowAta: { + value: input.merchantEscrowAta ?? null, + isWritable: true, + }, + merchantSettlementAta: { + value: input.merchantSettlementAta ?? null, + isWritable: true, + }, + operatorSettlementAta: { + value: input.operatorSettlementAta ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { + value: input.commerceProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.operator.value) { + accounts.operator.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode( + expectAddress(accounts.operatorAuthority.value) + ), + ], + }); + } + if (!accounts.merchantEscrowAta.value) { + accounts.merchantEscrowAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.merchant.value)), + getAddressEncoder().encode( + address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') + ), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.operatorSettlementAta.value) { + accounts.operatorSettlementAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode( + expectAddress(accounts.operatorAuthority.value) + ), + getAddressEncoder().encode( + address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') + ), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; + } + if (!accounts.commerceProgram.value) { + accounts.commerceProgram.value = + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.merchantSettlementAta), + getAccountMeta(accounts.operatorSettlementAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ], + programAddress, + data: getClearPaymentInstructionDataEncoder().encode({}), + } as ClearPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountOperatorSettlementAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >; + + return instruction; +} + +export type ClearPaymentInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountBuyer extends string = string, + TAccountMerchant extends string = string, + TAccountOperator extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountMerchantEscrowAta extends string = string, + TAccountMerchantSettlementAta extends string = string, + TAccountOperatorSettlementAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountCommerceProgram extends string = string, +> = { + payer: TransactionSigner; + /** New Payment PDA being created */ + payment: Address; + operatorAuthority: TransactionSigner; + buyer: Address; + /** Merchant PDA */ + merchant: Address; + /** Operator PDA */ + operator: Address; + merchantOperatorConfig: Address; + mint: Address; + /** Merchant Escrow ATA (Merchant PDA is owner) */ + merchantEscrowAta: Address; + /** Merchant Settlement ATA (Merchant settlement wallet is owner) */ + merchantSettlementAta: Address; + /** Operator Settlement ATA (Operator owner is owner) */ + operatorSettlementAta: Address; + tokenProgram?: Address; + associatedTokenProgram?: Address; + systemProgram?: Address; + /** Event authority PDA */ + eventAuthority?: Address; + /** Commerce Program ID */ + commerceProgram?: Address; +}; + +export function getClearPaymentInstruction< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountBuyer extends string, + TAccountMerchant extends string, + TAccountOperator extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountMerchantEscrowAta extends string, + TAccountMerchantSettlementAta extends string, + TAccountOperatorSettlementAta extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountCommerceProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: ClearPaymentInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountOperatorSettlementAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >, + config?: { programAddress?: TProgramAddress } +): ClearPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountOperatorSettlementAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: false, + }, + mint: { value: input.mint ?? null, isWritable: false }, + merchantEscrowAta: { + value: input.merchantEscrowAta ?? null, + isWritable: true, + }, + merchantSettlementAta: { + value: input.merchantSettlementAta ?? null, + isWritable: true, + }, + operatorSettlementAta: { + value: input.operatorSettlementAta ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { + value: input.commerceProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; + } + if (!accounts.commerceProgram.value) { + accounts.commerceProgram.value = + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.merchantSettlementAta), + getAccountMeta(accounts.operatorSettlementAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ], + programAddress, + data: getClearPaymentInstructionDataEncoder().encode({}), + } as ClearPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountOperatorSettlementAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >; + + return instruction; +} + +export type ParsedClearPaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + /** New Payment PDA being created */ + payment: TAccountMetas[1]; + operatorAuthority: TAccountMetas[2]; + buyer: TAccountMetas[3]; + /** Merchant PDA */ + merchant: TAccountMetas[4]; + /** Operator PDA */ + operator: TAccountMetas[5]; + merchantOperatorConfig: TAccountMetas[6]; + mint: TAccountMetas[7]; + /** Merchant Escrow ATA (Merchant PDA is owner) */ + merchantEscrowAta: TAccountMetas[8]; + /** Merchant Settlement ATA (Merchant settlement wallet is owner) */ + merchantSettlementAta: TAccountMetas[9]; + /** Operator Settlement ATA (Operator owner is owner) */ + operatorSettlementAta: TAccountMetas[10]; + tokenProgram: TAccountMetas[11]; + associatedTokenProgram: TAccountMetas[12]; + systemProgram: TAccountMetas[13]; + /** Event authority PDA */ + eventAuthority: TAccountMetas[14]; + /** Commerce Program ID */ + commerceProgram: TAccountMetas[15]; + }; + data: ClearPaymentInstructionData; +}; + +export function parseClearPaymentInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedClearPaymentInstruction { + if (instruction.accounts.length < 16) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + payment: getNextAccount(), + operatorAuthority: getNextAccount(), + buyer: getNextAccount(), + merchant: getNextAccount(), + operator: getNextAccount(), + merchantOperatorConfig: getNextAccount(), + mint: getNextAccount(), + merchantEscrowAta: getNextAccount(), + merchantSettlementAta: getNextAccount(), + operatorSettlementAta: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + commerceProgram: getNextAccount(), + }, + data: getClearPaymentInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/closePayment.ts b/program/clients/typescript/src/generated/instructions/closePayment.ts new file mode 100644 index 0000000..8ecc9c4 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/closePayment.ts @@ -0,0 +1,452 @@ +/** + * 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, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const CLOSE_PAYMENT_DISCRIMINATOR = 9; + +export function getClosePaymentDiscriminatorBytes() { + return getU8Encoder().encode(CLOSE_PAYMENT_DISCRIMINATOR); +} + +export type ClosePaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountPayment extends string | AccountMeta = string, + TAccountOperatorAuthority extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountBuyer extends string | AccountMeta = string, + TAccountMerchantOperatorConfig extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountPayment extends string + ? WritableAccount + : TAccountPayment, + TAccountOperatorAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountOperatorAuthority, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountMerchant extends string + ? ReadonlyAccount + : TAccountMerchant, + TAccountBuyer extends string + ? ReadonlyAccount + : TAccountBuyer, + TAccountMerchantOperatorConfig extends string + ? ReadonlyAccount + : TAccountMerchantOperatorConfig, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type ClosePaymentInstructionData = { discriminator: number }; + +export type ClosePaymentInstructionDataArgs = {}; + +export function getClosePaymentInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: CLOSE_PAYMENT_DISCRIMINATOR }) + ); +} + +export function getClosePaymentInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getClosePaymentInstructionDataCodec(): FixedSizeCodec< + ClosePaymentInstructionDataArgs, + ClosePaymentInstructionData +> { + return combineCodec( + getClosePaymentInstructionDataEncoder(), + getClosePaymentInstructionDataDecoder() + ); +} + +export type ClosePaymentAsyncInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountOperator extends string = string, + TAccountMerchant extends string = string, + TAccountBuyer extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + /** Payment PDA to close */ + payment: Address; + operatorAuthority: TransactionSigner; + /** Operator PDA */ + operator?: Address; + /** Merchant PDA */ + merchant: Address; + /** Buyer account */ + buyer: Address; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: Address; + /** Token mint */ + mint: Address; + systemProgram?: Address; +}; + +export async function getClosePaymentInstructionAsync< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountOperator extends string, + TAccountMerchant extends string, + TAccountBuyer extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: ClosePaymentAsyncInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + ClosePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + operator: { value: input.operator ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: false, + }, + mint: { value: input.mint ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.operator.value) { + accounts.operator.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode( + expectAddress(accounts.operatorAuthority.value) + ), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getClosePaymentInstructionDataEncoder().encode({}), + } as ClosePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram + >; + + return instruction; +} + +export type ClosePaymentInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountOperator extends string = string, + TAccountMerchant extends string = string, + TAccountBuyer extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + /** Payment PDA to close */ + payment: Address; + operatorAuthority: TransactionSigner; + /** Operator PDA */ + operator: Address; + /** Merchant PDA */ + merchant: Address; + /** Buyer account */ + buyer: Address; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: Address; + /** Token mint */ + mint: Address; + systemProgram?: Address; +}; + +export function getClosePaymentInstruction< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountOperator extends string, + TAccountMerchant extends string, + TAccountBuyer extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: ClosePaymentInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): ClosePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + operator: { value: input.operator ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: false, + }, + mint: { value: input.mint ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getClosePaymentInstructionDataEncoder().encode({}), + } as ClosePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram + >; + + return instruction; +} + +export type ParsedClosePaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + /** Payment PDA to close */ + payment: TAccountMetas[1]; + operatorAuthority: TAccountMetas[2]; + /** Operator PDA */ + operator: TAccountMetas[3]; + /** Merchant PDA */ + merchant: TAccountMetas[4]; + /** Buyer account */ + buyer: TAccountMetas[5]; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: TAccountMetas[6]; + /** Token mint */ + mint: TAccountMetas[7]; + systemProgram: TAccountMetas[8]; + }; + data: ClosePaymentInstructionData; +}; + +export function parseClosePaymentInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedClosePaymentInstruction { + if (instruction.accounts.length < 9) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + payment: getNextAccount(), + operatorAuthority: getNextAccount(), + operator: getNextAccount(), + merchant: getNextAccount(), + buyer: getNextAccount(), + merchantOperatorConfig: getNextAccount(), + mint: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getClosePaymentInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/closePaymentPermissionless.ts b/program/clients/typescript/src/generated/instructions/closePaymentPermissionless.ts new file mode 100644 index 0000000..56ad39f --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/closePaymentPermissionless.ts @@ -0,0 +1,291 @@ +/** + * 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, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const CLOSE_PAYMENT_PERMISSIONLESS_DISCRIMINATOR = 10; + +export function getClosePaymentPermissionlessDiscriminatorBytes() { + return getU8Encoder().encode(CLOSE_PAYMENT_PERMISSIONLESS_DISCRIMINATOR); +} + +export type ClosePaymentPermissionlessInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountPayment extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountBuyer extends string | AccountMeta = string, + TAccountMerchantOperatorConfig extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountPayment extends string + ? WritableAccount + : TAccountPayment, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountMerchant extends string + ? ReadonlyAccount + : TAccountMerchant, + TAccountBuyer extends string + ? ReadonlyAccount + : TAccountBuyer, + TAccountMerchantOperatorConfig extends string + ? ReadonlyAccount + : TAccountMerchantOperatorConfig, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type ClosePaymentPermissionlessInstructionData = { + discriminator: number; +}; + +export type ClosePaymentPermissionlessInstructionDataArgs = {}; + +export function getClosePaymentPermissionlessInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ + ...value, + discriminator: CLOSE_PAYMENT_PERMISSIONLESS_DISCRIMINATOR, + }) + ); +} + +export function getClosePaymentPermissionlessInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getClosePaymentPermissionlessInstructionDataCodec(): FixedSizeCodec< + ClosePaymentPermissionlessInstructionDataArgs, + ClosePaymentPermissionlessInstructionData +> { + return combineCodec( + getClosePaymentPermissionlessInstructionDataEncoder(), + getClosePaymentPermissionlessInstructionDataDecoder() + ); +} + +export type ClosePaymentPermissionlessInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperator extends string = string, + TAccountMerchant extends string = string, + TAccountBuyer extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + /** Payment PDA to close */ + payment: Address; + /** Operator PDA */ + operator: Address; + /** Merchant PDA */ + merchant: Address; + /** Buyer account */ + buyer: Address; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: Address; + /** Token mint */ + mint: Address; + systemProgram?: Address; +}; + +export function getClosePaymentPermissionlessInstruction< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperator extends string, + TAccountMerchant extends string, + TAccountBuyer extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: ClosePaymentPermissionlessInput< + TAccountPayer, + TAccountPayment, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): ClosePaymentPermissionlessInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: false, + }, + mint: { value: input.mint ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getClosePaymentPermissionlessInstructionDataEncoder().encode({}), + } as ClosePaymentPermissionlessInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperator, + TAccountMerchant, + TAccountBuyer, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountSystemProgram + >; + + return instruction; +} + +export type ParsedClosePaymentPermissionlessInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + /** Payment PDA to close */ + payment: TAccountMetas[1]; + /** Operator PDA */ + operator: TAccountMetas[2]; + /** Merchant PDA */ + merchant: TAccountMetas[3]; + /** Buyer account */ + buyer: TAccountMetas[4]; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: TAccountMetas[5]; + /** Token mint */ + mint: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + }; + data: ClosePaymentPermissionlessInstructionData; +}; + +export function parseClosePaymentPermissionlessInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedClosePaymentPermissionlessInstruction { + if (instruction.accounts.length < 8) { + // 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: { + payer: getNextAccount(), + payment: getNextAccount(), + operator: getNextAccount(), + merchant: getNextAccount(), + buyer: getNextAccount(), + merchantOperatorConfig: getNextAccount(), + mint: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getClosePaymentPermissionlessInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/createOperator.ts b/program/clients/typescript/src/generated/instructions/createOperator.ts new file mode 100644 index 0000000..3932bdc --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/createOperator.ts @@ -0,0 +1,331 @@ +/** + * 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, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const CREATE_OPERATOR_DISCRIMINATOR = 1; + +export function getCreateOperatorDiscriminatorBytes() { + return getU8Encoder().encode(CREATE_OPERATOR_DISCRIMINATOR); +} + +export type CreateOperatorInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountOperator extends string + ? WritableAccount + : TAccountOperator, + TAccountAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAuthority, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type CreateOperatorInstructionData = { + discriminator: number; + bump: number; +}; + +export type CreateOperatorInstructionDataArgs = { bump: number }; + +export function getCreateOperatorInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: CREATE_OPERATOR_DISCRIMINATOR }) + ); +} + +export function getCreateOperatorInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getCreateOperatorInstructionDataCodec(): FixedSizeCodec< + CreateOperatorInstructionDataArgs, + CreateOperatorInstructionData +> { + return combineCodec( + getCreateOperatorInstructionDataEncoder(), + getCreateOperatorInstructionDataDecoder() + ); +} + +export type CreateOperatorAsyncInput< + TAccountPayer extends string = string, + TAccountOperator extends string = string, + TAccountAuthority extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + operator?: Address; + authority: TransactionSigner; + systemProgram?: Address; + bump: CreateOperatorInstructionDataArgs['bump']; +}; + +export async function getCreateOperatorInstructionAsync< + TAccountPayer extends string, + TAccountOperator extends string, + TAccountAuthority extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: CreateOperatorAsyncInput< + TAccountPayer, + TAccountOperator, + TAccountAuthority, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + CreateOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountAuthority, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + 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.operator.value) { + accounts.operator.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode(expectAddress(accounts.authority.value)), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getCreateOperatorInstructionDataEncoder().encode( + args as CreateOperatorInstructionDataArgs + ), + } as CreateOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountAuthority, + TAccountSystemProgram + >; + + return instruction; +} + +export type CreateOperatorInput< + TAccountPayer extends string = string, + TAccountOperator extends string = string, + TAccountAuthority extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + operator: Address; + authority: TransactionSigner; + systemProgram?: Address; + bump: CreateOperatorInstructionDataArgs['bump']; +}; + +export function getCreateOperatorInstruction< + TAccountPayer extends string, + TAccountOperator extends string, + TAccountAuthority extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: CreateOperatorInput< + TAccountPayer, + TAccountOperator, + TAccountAuthority, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): CreateOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountAuthority, + TAccountSystemProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + 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.payer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getCreateOperatorInstructionDataEncoder().encode( + args as CreateOperatorInstructionDataArgs + ), + } as CreateOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountAuthority, + TAccountSystemProgram + >; + + return instruction; +} + +export type ParsedCreateOperatorInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + operator: TAccountMetas[1]; + authority: TAccountMetas[2]; + systemProgram: TAccountMetas[3]; + }; + data: CreateOperatorInstructionData; +}; + +export function parseCreateOperatorInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedCreateOperatorInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + operator: getNextAccount(), + authority: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCreateOperatorInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/emitEvent.ts b/program/clients/typescript/src/generated/instructions/emitEvent.ts new file mode 100644 index 0000000..156d189 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/emitEvent.ts @@ -0,0 +1,157 @@ +/** + * 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, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const EMIT_EVENT_DISCRIMINATOR = 228; + +export function getEmitEventDiscriminatorBytes() { + return getU8Encoder().encode(EMIT_EVENT_DISCRIMINATOR); +} + +export type EmitEventInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountEventAuthority extends + | string + | AccountMeta = '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountEventAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEventAuthority, + ...TRemainingAccounts, + ] + >; + +export type EmitEventInstructionData = { discriminator: number }; + +export type EmitEventInstructionDataArgs = {}; + +export function getEmitEventInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: EMIT_EVENT_DISCRIMINATOR }) + ); +} + +export function getEmitEventInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getEmitEventInstructionDataCodec(): FixedSizeCodec< + EmitEventInstructionDataArgs, + EmitEventInstructionData +> { + return combineCodec( + getEmitEventInstructionDataEncoder(), + getEmitEventInstructionDataDecoder() + ); +} + +export type EmitEventInput = { + eventAuthority?: TransactionSigner; +}; + +export function getEmitEventInstruction< + TAccountEventAuthority extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: EmitEventInput, + config?: { programAddress?: TProgramAddress } +): EmitEventInstruction { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [getAccountMeta(accounts.eventAuthority)], + programAddress, + data: getEmitEventInstructionDataEncoder().encode({}), + } as EmitEventInstruction; + + return instruction; +} + +export type ParsedEmitEventInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + eventAuthority: TAccountMetas[0]; + }; + data: EmitEventInstructionData; +}; + +export function parseEmitEventInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedEmitEventInstruction { + if (instruction.accounts.length < 1) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + eventAuthority: getNextAccount(), + }, + data: getEmitEventInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/index.ts b/program/clients/typescript/src/generated/instructions/index.ts new file mode 100644 index 0000000..db00dc2 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/index.ts @@ -0,0 +1,19 @@ +/** + * 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 + */ + +export * from './clearPayment'; +export * from './closePayment'; +export * from './createOperator'; +export * from './emitEvent'; +export * from './initializeMerchant'; +export * from './initializeMerchantOperatorConfig'; +export * from './makePayment'; +export * from './refundPayment'; +export * from './updateMerchantAuthority'; +export * from './updateMerchantSettlementWallet'; +export * from './updateOperatorAuthority'; diff --git a/program/clients/typescript/src/generated/instructions/initializeMerchant.ts b/program/clients/typescript/src/generated/instructions/initializeMerchant.ts new file mode 100644 index 0000000..7f91fa6 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/initializeMerchant.ts @@ -0,0 +1,361 @@ +/** + * 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, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const INITIALIZE_MERCHANT_DISCRIMINATOR = 0; + +export function getInitializeMerchantDiscriminatorBytes() { + return getU8Encoder().encode(INITIALIZE_MERCHANT_DISCRIMINATOR); +} + +export type InitializeMerchantInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountSettlementWallet extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAuthority, + TAccountMerchant extends string + ? WritableAccount + : TAccountMerchant, + TAccountSettlementWallet extends string + ? ReadonlyAccount + : TAccountSettlementWallet, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type InitializeMerchantInstructionData = { + discriminator: number; + bump: number; +}; + +export type InitializeMerchantInstructionDataArgs = { bump: number }; + +export function getInitializeMerchantInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: INITIALIZE_MERCHANT_DISCRIMINATOR }) + ); +} + +export function getInitializeMerchantInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getInitializeMerchantInstructionDataCodec(): FixedSizeCodec< + InitializeMerchantInstructionDataArgs, + InitializeMerchantInstructionData +> { + return combineCodec( + getInitializeMerchantInstructionDataEncoder(), + getInitializeMerchantInstructionDataDecoder() + ); +} + +export type InitializeMerchantAsyncInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountSettlementWallet extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + merchant?: Address; + settlementWallet: Address; + systemProgram?: Address; + bump: InitializeMerchantInstructionDataArgs['bump']; +}; + +export async function getInitializeMerchantInstructionAsync< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountSettlementWallet extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: InitializeMerchantAsyncInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountSettlementWallet, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + InitializeMerchantInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountSettlementWallet, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: true }, + settlementWallet: { + value: input.settlementWallet ?? null, + isWritable: false, + }, + 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.merchant.value) { + accounts.merchant.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('merchant'), + getAddressEncoder().encode(expectAddress(accounts.authority.value)), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.settlementWallet), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getInitializeMerchantInstructionDataEncoder().encode( + args as InitializeMerchantInstructionDataArgs + ), + } as InitializeMerchantInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountSettlementWallet, + TAccountSystemProgram + >; + + return instruction; +} + +export type InitializeMerchantInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountSettlementWallet extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + merchant: Address; + settlementWallet: Address; + systemProgram?: Address; + bump: InitializeMerchantInstructionDataArgs['bump']; +}; + +export function getInitializeMerchantInstruction< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountSettlementWallet extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: InitializeMerchantInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountSettlementWallet, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): InitializeMerchantInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountSettlementWallet, + TAccountSystemProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: true }, + settlementWallet: { + value: input.settlementWallet ?? null, + isWritable: false, + }, + 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.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.settlementWallet), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getInitializeMerchantInstructionDataEncoder().encode( + args as InitializeMerchantInstructionDataArgs + ), + } as InitializeMerchantInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountSettlementWallet, + TAccountSystemProgram + >; + + return instruction; +} + +export type ParsedInitializeMerchantInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + authority: TAccountMetas[1]; + merchant: TAccountMetas[2]; + settlementWallet: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: InitializeMerchantInstructionData; +}; + +export function parseInitializeMerchantInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedInitializeMerchantInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + authority: getNextAccount(), + merchant: getNextAccount(), + settlementWallet: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getInitializeMerchantInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/initializeMerchantOperatorConfig.ts b/program/clients/typescript/src/generated/instructions/initializeMerchantOperatorConfig.ts new file mode 100644 index 0000000..b89e28b --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/initializeMerchantOperatorConfig.ts @@ -0,0 +1,467 @@ +/** + * 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 { + AccountRole, + combineCodec, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type Codec, + type Decoder, + type Encoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + expectSome, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; +import { + getFeeTypeDecoder, + getFeeTypeEncoder, + getPolicyDataDecoder, + getPolicyDataEncoder, + type FeeType, + type FeeTypeArgs, + type PolicyData, + type PolicyDataArgs, +} from '../types'; + +export const INITIALIZE_MERCHANT_OPERATOR_CONFIG_DISCRIMINATOR = 2; + +export function getInitializeMerchantOperatorConfigDiscriminatorBytes() { + return getU8Encoder().encode( + INITIALIZE_MERCHANT_OPERATOR_CONFIG_DISCRIMINATOR + ); +} + +export type InitializeMerchantOperatorConfigInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountConfig extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAuthority, + TAccountMerchant extends string + ? ReadonlyAccount + : TAccountMerchant, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountConfig extends string + ? WritableAccount + : TAccountConfig, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type InitializeMerchantOperatorConfigInstructionData = { + discriminator: number; + version: number; + bump: number; + operatorFee: bigint; + feeType: FeeType; + daysToClose: number; + policies: Array; + acceptedCurrencies: Array
; +}; + +export type InitializeMerchantOperatorConfigInstructionDataArgs = { + version: number; + bump: number; + operatorFee: number | bigint; + feeType: FeeTypeArgs; + daysToClose: number; + policies: Array; + acceptedCurrencies: Array
; +}; + +export function getInitializeMerchantOperatorConfigInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['version', getU32Encoder()], + ['bump', getU8Encoder()], + ['operatorFee', getU64Encoder()], + ['feeType', getFeeTypeEncoder()], + ['daysToClose', getU16Encoder()], + ['policies', getArrayEncoder(getPolicyDataEncoder())], + ['acceptedCurrencies', getArrayEncoder(getAddressEncoder())], + ]), + (value) => ({ + ...value, + discriminator: INITIALIZE_MERCHANT_OPERATOR_CONFIG_DISCRIMINATOR, + }) + ); +} + +export function getInitializeMerchantOperatorConfigInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['version', getU32Decoder()], + ['bump', getU8Decoder()], + ['operatorFee', getU64Decoder()], + ['feeType', getFeeTypeDecoder()], + ['daysToClose', getU16Decoder()], + ['policies', getArrayDecoder(getPolicyDataDecoder())], + ['acceptedCurrencies', getArrayDecoder(getAddressDecoder())], + ]); +} + +export function getInitializeMerchantOperatorConfigInstructionDataCodec(): Codec< + InitializeMerchantOperatorConfigInstructionDataArgs, + InitializeMerchantOperatorConfigInstructionData +> { + return combineCodec( + getInitializeMerchantOperatorConfigInstructionDataEncoder(), + getInitializeMerchantOperatorConfigInstructionDataDecoder() + ); +} + +export type InitializeMerchantOperatorConfigAsyncInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountOperator extends string = string, + TAccountConfig extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + /** Authority of the merchant */ + authority: TransactionSigner; + /** Merchant PDA */ + merchant: Address; + /** Operator PDA */ + operator: Address; + /** The MerchantOperatorConfig PDA being initialized */ + config?: Address; + systemProgram?: Address; + version: InitializeMerchantOperatorConfigInstructionDataArgs['version']; + bump: InitializeMerchantOperatorConfigInstructionDataArgs['bump']; + operatorFee: InitializeMerchantOperatorConfigInstructionDataArgs['operatorFee']; + feeType: InitializeMerchantOperatorConfigInstructionDataArgs['feeType']; + daysToClose: InitializeMerchantOperatorConfigInstructionDataArgs['daysToClose']; + policies: InitializeMerchantOperatorConfigInstructionDataArgs['policies']; + acceptedCurrencies: InitializeMerchantOperatorConfigInstructionDataArgs['acceptedCurrencies']; +}; + +export async function getInitializeMerchantOperatorConfigInstructionAsync< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountOperator extends string, + TAccountConfig extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: InitializeMerchantOperatorConfigAsyncInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountOperator, + TAccountConfig, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + InitializeMerchantOperatorConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountOperator, + TAccountConfig, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + config: { value: input.config ?? 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.config.value) { + accounts.config.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('merchant_operator_config'), + getAddressEncoder().encode(expectAddress(accounts.merchant.value)), + getAddressEncoder().encode(expectAddress(accounts.operator.value)), + getU32Encoder().encode(expectSome(args.version)), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + + // Remaining accounts. + const remainingAccounts: AccountMeta[] = args.acceptedCurrencies.map( + (address) => ({ address, role: AccountRole.READONLY }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.config), + getAccountMeta(accounts.systemProgram), + ...remainingAccounts, + ], + programAddress, + data: getInitializeMerchantOperatorConfigInstructionDataEncoder().encode( + args as InitializeMerchantOperatorConfigInstructionDataArgs + ), + } as InitializeMerchantOperatorConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountOperator, + TAccountConfig, + TAccountSystemProgram + >; + + return instruction; +} + +export type InitializeMerchantOperatorConfigInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountOperator extends string = string, + TAccountConfig extends string = string, + TAccountSystemProgram extends string = string, +> = { + payer: TransactionSigner; + /** Authority of the merchant */ + authority: TransactionSigner; + /** Merchant PDA */ + merchant: Address; + /** Operator PDA */ + operator: Address; + /** The MerchantOperatorConfig PDA being initialized */ + config: Address; + systemProgram?: Address; + version: InitializeMerchantOperatorConfigInstructionDataArgs['version']; + bump: InitializeMerchantOperatorConfigInstructionDataArgs['bump']; + operatorFee: InitializeMerchantOperatorConfigInstructionDataArgs['operatorFee']; + feeType: InitializeMerchantOperatorConfigInstructionDataArgs['feeType']; + daysToClose: InitializeMerchantOperatorConfigInstructionDataArgs['daysToClose']; + policies: InitializeMerchantOperatorConfigInstructionDataArgs['policies']; + acceptedCurrencies: InitializeMerchantOperatorConfigInstructionDataArgs['acceptedCurrencies']; +}; + +export function getInitializeMerchantOperatorConfigInstruction< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountOperator extends string, + TAccountConfig extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: InitializeMerchantOperatorConfigInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountOperator, + TAccountConfig, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress } +): InitializeMerchantOperatorConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountOperator, + TAccountConfig, + TAccountSystemProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + config: { value: input.config ?? 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'>; + } + + // Remaining accounts. + const remainingAccounts: AccountMeta[] = args.acceptedCurrencies.map( + (address) => ({ address, role: AccountRole.READONLY }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.config), + getAccountMeta(accounts.systemProgram), + ...remainingAccounts, + ], + programAddress, + data: getInitializeMerchantOperatorConfigInstructionDataEncoder().encode( + args as InitializeMerchantOperatorConfigInstructionDataArgs + ), + } as InitializeMerchantOperatorConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountOperator, + TAccountConfig, + TAccountSystemProgram + >; + + return instruction; +} + +export type ParsedInitializeMerchantOperatorConfigInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + /** Authority of the merchant */ + authority: TAccountMetas[1]; + /** Merchant PDA */ + merchant: TAccountMetas[2]; + /** Operator PDA */ + operator: TAccountMetas[3]; + /** The MerchantOperatorConfig PDA being initialized */ + config: TAccountMetas[4]; + systemProgram: TAccountMetas[5]; + }; + data: InitializeMerchantOperatorConfigInstructionData; +}; + +export function parseInitializeMerchantOperatorConfigInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedInitializeMerchantOperatorConfigInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + authority: getNextAccount(), + merchant: getNextAccount(), + operator: getNextAccount(), + config: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getInitializeMerchantOperatorConfigInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/makePayment.ts b/program/clients/typescript/src/generated/instructions/makePayment.ts new file mode 100644 index 0000000..30b1265 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/makePayment.ts @@ -0,0 +1,706 @@ +/** + * 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 { + address, + combineCodec, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + expectSome, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const MAKE_PAYMENT_DISCRIMINATOR = 3; + +export function getMakePaymentDiscriminatorBytes() { + return getU8Encoder().encode(MAKE_PAYMENT_DISCRIMINATOR); +} + +export type MakePaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountPayment extends string | AccountMeta = string, + TAccountOperatorAuthority extends string | AccountMeta = string, + TAccountBuyer extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountMerchantOperatorConfig extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountBuyerAta extends string | AccountMeta = string, + TAccountMerchantEscrowAta extends string | AccountMeta = string, + TAccountMerchantSettlementAta extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountEventAuthority extends + | string + | AccountMeta = '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1', + TAccountCommerceProgram extends + | string + | AccountMeta = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountPayment extends string + ? WritableAccount + : TAccountPayment, + TAccountOperatorAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountOperatorAuthority, + TAccountBuyer extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountBuyer, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountMerchant extends string + ? ReadonlyAccount + : TAccountMerchant, + TAccountMerchantOperatorConfig extends string + ? WritableAccount + : TAccountMerchantOperatorConfig, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountBuyerAta extends string + ? WritableAccount + : TAccountBuyerAta, + TAccountMerchantEscrowAta extends string + ? WritableAccount + : TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta extends string + ? WritableAccount + : TAccountMerchantSettlementAta, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountCommerceProgram extends string + ? ReadonlyAccount + : TAccountCommerceProgram, + ...TRemainingAccounts, + ] + >; + +export type MakePaymentInstructionData = { + discriminator: number; + orderId: number; + amount: bigint; + bump: number; +}; + +export type MakePaymentInstructionDataArgs = { + orderId: number; + amount: number | bigint; + bump: number; +}; + +export function getMakePaymentInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['orderId', getU32Encoder()], + ['amount', getU64Encoder()], + ['bump', getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: MAKE_PAYMENT_DISCRIMINATOR }) + ); +} + +export function getMakePaymentInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['orderId', getU32Decoder()], + ['amount', getU64Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getMakePaymentInstructionDataCodec(): FixedSizeCodec< + MakePaymentInstructionDataArgs, + MakePaymentInstructionData +> { + return combineCodec( + getMakePaymentInstructionDataEncoder(), + getMakePaymentInstructionDataDecoder() + ); +} + +export type MakePaymentAsyncInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountBuyer extends string = string, + TAccountOperator extends string = string, + TAccountMerchant extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountBuyerAta extends string = string, + TAccountMerchantEscrowAta extends string = string, + TAccountMerchantSettlementAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountCommerceProgram extends string = string, +> = { + payer: TransactionSigner; + payment?: Address; + operatorAuthority: TransactionSigner; + buyer: TransactionSigner; + operator?: Address; + /** Merchant PDA */ + merchant: Address; + merchantOperatorConfig: Address; + mint: Address; + buyerAta?: Address; + merchantEscrowAta?: Address; + merchantSettlementAta: Address; + tokenProgram?: Address; + systemProgram?: Address; + /** Event authority PDA */ + eventAuthority?: Address; + /** Commerce Program ID */ + commerceProgram?: Address; + orderId: MakePaymentInstructionDataArgs['orderId']; + amount: MakePaymentInstructionDataArgs['amount']; + bump: MakePaymentInstructionDataArgs['bump']; +}; + +export async function getMakePaymentInstructionAsync< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountBuyer extends string, + TAccountOperator extends string, + TAccountMerchant extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountBuyerAta extends string, + TAccountMerchantEscrowAta extends string, + TAccountMerchantSettlementAta extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountCommerceProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: MakePaymentAsyncInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountOperator, + TAccountMerchant, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountBuyerAta, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + MakePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountOperator, + TAccountMerchant, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountBuyerAta, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + buyer: { value: input.buyer ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: true, + }, + mint: { value: input.mint ?? null, isWritable: false }, + buyerAta: { value: input.buyerAta ?? null, isWritable: true }, + merchantEscrowAta: { + value: input.merchantEscrowAta ?? null, + isWritable: true, + }, + merchantSettlementAta: { + value: input.merchantSettlementAta ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { + value: input.commerceProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.payment.value) { + accounts.payment.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('payment'), + getAddressEncoder().encode( + expectAddress(accounts.merchantOperatorConfig.value) + ), + getAddressEncoder().encode(expectAddress(accounts.buyer.value)), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + getU32Encoder().encode(expectSome(args.orderId)), + ], + }); + } + if (!accounts.operator.value) { + accounts.operator.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode( + expectAddress(accounts.operatorAuthority.value) + ), + ], + }); + } + if (!accounts.buyerAta.value) { + accounts.buyerAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.buyer.value)), + getAddressEncoder().encode( + address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') + ), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.merchantEscrowAta.value) { + accounts.merchantEscrowAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.merchant.value)), + getAddressEncoder().encode( + address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') + ), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; + } + if (!accounts.commerceProgram.value) { + accounts.commerceProgram.value = + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.buyerAta), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.merchantSettlementAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ], + programAddress, + data: getMakePaymentInstructionDataEncoder().encode( + args as MakePaymentInstructionDataArgs + ), + } as MakePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountOperator, + TAccountMerchant, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountBuyerAta, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >; + + return instruction; +} + +export type MakePaymentInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountBuyer extends string = string, + TAccountOperator extends string = string, + TAccountMerchant extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountBuyerAta extends string = string, + TAccountMerchantEscrowAta extends string = string, + TAccountMerchantSettlementAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountCommerceProgram extends string = string, +> = { + payer: TransactionSigner; + payment: Address; + operatorAuthority: TransactionSigner; + buyer: TransactionSigner; + operator: Address; + /** Merchant PDA */ + merchant: Address; + merchantOperatorConfig: Address; + mint: Address; + buyerAta: Address; + merchantEscrowAta: Address; + merchantSettlementAta: Address; + tokenProgram?: Address; + systemProgram?: Address; + /** Event authority PDA */ + eventAuthority?: Address; + /** Commerce Program ID */ + commerceProgram?: Address; + orderId: MakePaymentInstructionDataArgs['orderId']; + amount: MakePaymentInstructionDataArgs['amount']; + bump: MakePaymentInstructionDataArgs['bump']; +}; + +export function getMakePaymentInstruction< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountBuyer extends string, + TAccountOperator extends string, + TAccountMerchant extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountBuyerAta extends string, + TAccountMerchantEscrowAta extends string, + TAccountMerchantSettlementAta extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountCommerceProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: MakePaymentInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountOperator, + TAccountMerchant, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountBuyerAta, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >, + config?: { programAddress?: TProgramAddress } +): MakePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountOperator, + TAccountMerchant, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountBuyerAta, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + buyer: { value: input.buyer ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: true, + }, + mint: { value: input.mint ?? null, isWritable: false }, + buyerAta: { value: input.buyerAta ?? null, isWritable: true }, + merchantEscrowAta: { + value: input.merchantEscrowAta ?? null, + isWritable: true, + }, + merchantSettlementAta: { + value: input.merchantSettlementAta ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { + value: input.commerceProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; + } + if (!accounts.commerceProgram.value) { + accounts.commerceProgram.value = + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.buyerAta), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.merchantSettlementAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ], + programAddress, + data: getMakePaymentInstructionDataEncoder().encode( + args as MakePaymentInstructionDataArgs + ), + } as MakePaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountOperator, + TAccountMerchant, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountBuyerAta, + TAccountMerchantEscrowAta, + TAccountMerchantSettlementAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >; + + return instruction; +} + +export type ParsedMakePaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + payment: TAccountMetas[1]; + operatorAuthority: TAccountMetas[2]; + buyer: TAccountMetas[3]; + operator: TAccountMetas[4]; + /** Merchant PDA */ + merchant: TAccountMetas[5]; + merchantOperatorConfig: TAccountMetas[6]; + mint: TAccountMetas[7]; + buyerAta: TAccountMetas[8]; + merchantEscrowAta: TAccountMetas[9]; + merchantSettlementAta: TAccountMetas[10]; + tokenProgram: TAccountMetas[11]; + systemProgram: TAccountMetas[12]; + /** Event authority PDA */ + eventAuthority: TAccountMetas[13]; + /** Commerce Program ID */ + commerceProgram: TAccountMetas[14]; + }; + data: MakePaymentInstructionData; +}; + +export function parseMakePaymentInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedMakePaymentInstruction { + if (instruction.accounts.length < 15) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + payment: getNextAccount(), + operatorAuthority: getNextAccount(), + buyer: getNextAccount(), + operator: getNextAccount(), + merchant: getNextAccount(), + merchantOperatorConfig: getNextAccount(), + mint: getNextAccount(), + buyerAta: getNextAccount(), + merchantEscrowAta: getNextAccount(), + merchantSettlementAta: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + commerceProgram: getNextAccount(), + }, + data: getMakePaymentInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/refundPayment.ts b/program/clients/typescript/src/generated/instructions/refundPayment.ts new file mode 100644 index 0000000..3732941 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/refundPayment.ts @@ -0,0 +1,637 @@ +/** + * 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 { + address, + combineCodec, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const REFUND_PAYMENT_DISCRIMINATOR = 5; + +export function getRefundPaymentDiscriminatorBytes() { + return getU8Encoder().encode(REFUND_PAYMENT_DISCRIMINATOR); +} + +export type RefundPaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountPayment extends string | AccountMeta = string, + TAccountOperatorAuthority extends string | AccountMeta = string, + TAccountBuyer extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountMerchantOperatorConfig extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountMerchantEscrowAta extends string | AccountMeta = string, + TAccountBuyerAta extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountEventAuthority extends + | string + | AccountMeta = '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1', + TAccountCommerceProgram extends + | string + | AccountMeta = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountPayment extends string + ? WritableAccount + : TAccountPayment, + TAccountOperatorAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountOperatorAuthority, + TAccountBuyer extends string + ? ReadonlyAccount + : TAccountBuyer, + TAccountMerchant extends string + ? ReadonlyAccount + : TAccountMerchant, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountMerchantOperatorConfig extends string + ? ReadonlyAccount + : TAccountMerchantOperatorConfig, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountMerchantEscrowAta extends string + ? WritableAccount + : TAccountMerchantEscrowAta, + TAccountBuyerAta extends string + ? WritableAccount + : TAccountBuyerAta, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountCommerceProgram extends string + ? ReadonlyAccount + : TAccountCommerceProgram, + ...TRemainingAccounts, + ] + >; + +export type RefundPaymentInstructionData = { discriminator: number }; + +export type RefundPaymentInstructionDataArgs = {}; + +export function getRefundPaymentInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: REFUND_PAYMENT_DISCRIMINATOR }) + ); +} + +export function getRefundPaymentInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getRefundPaymentInstructionDataCodec(): FixedSizeCodec< + RefundPaymentInstructionDataArgs, + RefundPaymentInstructionData +> { + return combineCodec( + getRefundPaymentInstructionDataEncoder(), + getRefundPaymentInstructionDataDecoder() + ); +} + +export type RefundPaymentAsyncInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountBuyer extends string = string, + TAccountMerchant extends string = string, + TAccountOperator extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountMerchantEscrowAta extends string = string, + TAccountBuyerAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountCommerceProgram extends string = string, +> = { + payer: TransactionSigner; + /** Payment PDA being updated */ + payment: Address; + operatorAuthority: TransactionSigner; + /** Refund destination owner */ + buyer: Address; + /** Merchant PDA */ + merchant: Address; + /** Operator PDA */ + operator?: Address; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: Address; + mint: Address; + /** Merchant Escrow ATA (Merchant PDA is owner) */ + merchantEscrowAta?: Address; + buyerAta?: Address; + tokenProgram?: Address; + systemProgram?: Address; + /** Event authority PDA */ + eventAuthority?: Address; + /** Commerce Program ID */ + commerceProgram?: Address; +}; + +export async function getRefundPaymentInstructionAsync< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountBuyer extends string, + TAccountMerchant extends string, + TAccountOperator extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountMerchantEscrowAta extends string, + TAccountBuyerAta extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountCommerceProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: RefundPaymentAsyncInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountBuyerAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + RefundPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountBuyerAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: false, + }, + mint: { value: input.mint ?? null, isWritable: false }, + merchantEscrowAta: { + value: input.merchantEscrowAta ?? null, + isWritable: true, + }, + buyerAta: { value: input.buyerAta ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { + value: input.commerceProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.operator.value) { + accounts.operator.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode( + expectAddress(accounts.operatorAuthority.value) + ), + ], + }); + } + if (!accounts.merchantEscrowAta.value) { + accounts.merchantEscrowAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.merchant.value)), + getAddressEncoder().encode( + address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') + ), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.buyerAta.value) { + accounts.buyerAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.buyer.value)), + getAddressEncoder().encode( + address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') + ), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; + } + if (!accounts.commerceProgram.value) { + accounts.commerceProgram.value = + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.buyerAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ], + programAddress, + data: getRefundPaymentInstructionDataEncoder().encode({}), + } as RefundPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountBuyerAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >; + + return instruction; +} + +export type RefundPaymentInput< + TAccountPayer extends string = string, + TAccountPayment extends string = string, + TAccountOperatorAuthority extends string = string, + TAccountBuyer extends string = string, + TAccountMerchant extends string = string, + TAccountOperator extends string = string, + TAccountMerchantOperatorConfig extends string = string, + TAccountMint extends string = string, + TAccountMerchantEscrowAta extends string = string, + TAccountBuyerAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountCommerceProgram extends string = string, +> = { + payer: TransactionSigner; + /** Payment PDA being updated */ + payment: Address; + operatorAuthority: TransactionSigner; + /** Refund destination owner */ + buyer: Address; + /** Merchant PDA */ + merchant: Address; + /** Operator PDA */ + operator: Address; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: Address; + mint: Address; + /** Merchant Escrow ATA (Merchant PDA is owner) */ + merchantEscrowAta: Address; + buyerAta: Address; + tokenProgram?: Address; + systemProgram?: Address; + /** Event authority PDA */ + eventAuthority?: Address; + /** Commerce Program ID */ + commerceProgram?: Address; +}; + +export function getRefundPaymentInstruction< + TAccountPayer extends string, + TAccountPayment extends string, + TAccountOperatorAuthority extends string, + TAccountBuyer extends string, + TAccountMerchant extends string, + TAccountOperator extends string, + TAccountMerchantOperatorConfig extends string, + TAccountMint extends string, + TAccountMerchantEscrowAta extends string, + TAccountBuyerAta extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountCommerceProgram extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: RefundPaymentInput< + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountBuyerAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >, + config?: { programAddress?: TProgramAddress } +): RefundPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountBuyerAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + payment: { value: input.payment ?? null, isWritable: true }, + operatorAuthority: { + value: input.operatorAuthority ?? null, + isWritable: false, + }, + buyer: { value: input.buyer ?? null, isWritable: false }, + merchant: { value: input.merchant ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + merchantOperatorConfig: { + value: input.merchantOperatorConfig ?? null, + isWritable: false, + }, + mint: { value: input.mint ?? null, isWritable: false }, + merchantEscrowAta: { + value: input.merchantEscrowAta ?? null, + isWritable: true, + }, + buyerAta: { value: input.buyerAta ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + commerceProgram: { + value: input.commerceProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + '3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1' as Address<'3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1'>; + } + if (!accounts.commerceProgram.value) { + accounts.commerceProgram.value = + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.payment), + getAccountMeta(accounts.operatorAuthority), + getAccountMeta(accounts.buyer), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.merchantOperatorConfig), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.merchantEscrowAta), + getAccountMeta(accounts.buyerAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.commerceProgram), + ], + programAddress, + data: getRefundPaymentInstructionDataEncoder().encode({}), + } as RefundPaymentInstruction< + TProgramAddress, + TAccountPayer, + TAccountPayment, + TAccountOperatorAuthority, + TAccountBuyer, + TAccountMerchant, + TAccountOperator, + TAccountMerchantOperatorConfig, + TAccountMint, + TAccountMerchantEscrowAta, + TAccountBuyerAta, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountCommerceProgram + >; + + return instruction; +} + +export type ParsedRefundPaymentInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + /** Payment PDA being updated */ + payment: TAccountMetas[1]; + operatorAuthority: TAccountMetas[2]; + /** Refund destination owner */ + buyer: TAccountMetas[3]; + /** Merchant PDA */ + merchant: TAccountMetas[4]; + /** Operator PDA */ + operator: TAccountMetas[5]; + /** Merchant Operator Config PDA */ + merchantOperatorConfig: TAccountMetas[6]; + mint: TAccountMetas[7]; + /** Merchant Escrow ATA (Merchant PDA is owner) */ + merchantEscrowAta: TAccountMetas[8]; + buyerAta: TAccountMetas[9]; + tokenProgram: TAccountMetas[10]; + systemProgram: TAccountMetas[11]; + /** Event authority PDA */ + eventAuthority: TAccountMetas[12]; + /** Commerce Program ID */ + commerceProgram: TAccountMetas[13]; + }; + data: RefundPaymentInstructionData; +}; + +export function parseRefundPaymentInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedRefundPaymentInstruction { + if (instruction.accounts.length < 14) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + payment: getNextAccount(), + operatorAuthority: getNextAccount(), + buyer: getNextAccount(), + merchant: getNextAccount(), + operator: getNextAccount(), + merchantOperatorConfig: getNextAccount(), + mint: getNextAccount(), + merchantEscrowAta: getNextAccount(), + buyerAta: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + commerceProgram: getNextAccount(), + }, + data: getRefundPaymentInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/updateMerchantAuthority.ts b/program/clients/typescript/src/generated/instructions/updateMerchantAuthority.ts new file mode 100644 index 0000000..a9b0967 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/updateMerchantAuthority.ts @@ -0,0 +1,305 @@ +/** + * 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, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const UPDATE_MERCHANT_AUTHORITY_DISCRIMINATOR = 7; + +export function getUpdateMerchantAuthorityDiscriminatorBytes() { + return getU8Encoder().encode(UPDATE_MERCHANT_AUTHORITY_DISCRIMINATOR); +} + +export type UpdateMerchantAuthorityInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountNewAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAuthority extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountAuthority, + TAccountMerchant extends string + ? WritableAccount + : TAccountMerchant, + TAccountNewAuthority extends string + ? ReadonlyAccount + : TAccountNewAuthority, + ...TRemainingAccounts, + ] + >; + +export type UpdateMerchantAuthorityInstructionData = { discriminator: number }; + +export type UpdateMerchantAuthorityInstructionDataArgs = {}; + +export function getUpdateMerchantAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ + ...value, + discriminator: UPDATE_MERCHANT_AUTHORITY_DISCRIMINATOR, + }) + ); +} + +export function getUpdateMerchantAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getUpdateMerchantAuthorityInstructionDataCodec(): FixedSizeCodec< + UpdateMerchantAuthorityInstructionDataArgs, + UpdateMerchantAuthorityInstructionData +> { + return combineCodec( + getUpdateMerchantAuthorityInstructionDataEncoder(), + getUpdateMerchantAuthorityInstructionDataDecoder() + ); +} + +export type UpdateMerchantAuthorityAsyncInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountNewAuthority extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + /** Merchant PDA */ + merchant?: Address; + newAuthority: Address; +}; + +export async function getUpdateMerchantAuthorityInstructionAsync< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountNewAuthority extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: UpdateMerchantAuthorityAsyncInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewAuthority + >, + config?: { programAddress?: TProgramAddress } +): Promise< + UpdateMerchantAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewAuthority + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + merchant: { value: input.merchant ?? null, isWritable: true }, + newAuthority: { value: input.newAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.merchant.value) { + accounts.merchant.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('merchant'), + getAddressEncoder().encode(expectAddress(accounts.authority.value)), + ], + }); + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.newAuthority), + ], + programAddress, + data: getUpdateMerchantAuthorityInstructionDataEncoder().encode({}), + } as UpdateMerchantAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewAuthority + >; + + return instruction; +} + +export type UpdateMerchantAuthorityInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountNewAuthority extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + /** Merchant PDA */ + merchant: Address; + newAuthority: Address; +}; + +export function getUpdateMerchantAuthorityInstruction< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountNewAuthority extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: UpdateMerchantAuthorityInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewAuthority + >, + config?: { programAddress?: TProgramAddress } +): UpdateMerchantAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewAuthority +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + merchant: { value: input.merchant ?? null, isWritable: true }, + newAuthority: { value: input.newAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.newAuthority), + ], + programAddress, + data: getUpdateMerchantAuthorityInstructionDataEncoder().encode({}), + } as UpdateMerchantAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewAuthority + >; + + return instruction; +} + +export type ParsedUpdateMerchantAuthorityInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + authority: TAccountMetas[1]; + /** Merchant PDA */ + merchant: TAccountMetas[2]; + newAuthority: TAccountMetas[3]; + }; + data: UpdateMerchantAuthorityInstructionData; +}; + +export function parseUpdateMerchantAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedUpdateMerchantAuthorityInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + authority: getNextAccount(), + merchant: getNextAccount(), + newAuthority: getNextAccount(), + }, + data: getUpdateMerchantAuthorityInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/updateMerchantSettlementWallet.ts b/program/clients/typescript/src/generated/instructions/updateMerchantSettlementWallet.ts new file mode 100644 index 0000000..32cd377 --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/updateMerchantSettlementWallet.ts @@ -0,0 +1,313 @@ +/** + * 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, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const UPDATE_MERCHANT_SETTLEMENT_WALLET_DISCRIMINATOR = 6; + +export function getUpdateMerchantSettlementWalletDiscriminatorBytes() { + return getU8Encoder().encode(UPDATE_MERCHANT_SETTLEMENT_WALLET_DISCRIMINATOR); +} + +export type UpdateMerchantSettlementWalletInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountMerchant extends string | AccountMeta = string, + TAccountNewSettlementWallet extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAuthority extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountAuthority, + TAccountMerchant extends string + ? WritableAccount + : TAccountMerchant, + TAccountNewSettlementWallet extends string + ? ReadonlyAccount + : TAccountNewSettlementWallet, + ...TRemainingAccounts, + ] + >; + +export type UpdateMerchantSettlementWalletInstructionData = { + discriminator: number; +}; + +export type UpdateMerchantSettlementWalletInstructionDataArgs = {}; + +export function getUpdateMerchantSettlementWalletInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ + ...value, + discriminator: UPDATE_MERCHANT_SETTLEMENT_WALLET_DISCRIMINATOR, + }) + ); +} + +export function getUpdateMerchantSettlementWalletInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getUpdateMerchantSettlementWalletInstructionDataCodec(): FixedSizeCodec< + UpdateMerchantSettlementWalletInstructionDataArgs, + UpdateMerchantSettlementWalletInstructionData +> { + return combineCodec( + getUpdateMerchantSettlementWalletInstructionDataEncoder(), + getUpdateMerchantSettlementWalletInstructionDataDecoder() + ); +} + +export type UpdateMerchantSettlementWalletAsyncInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountNewSettlementWallet extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + /** Merchant PDA */ + merchant?: Address; + newSettlementWallet: Address; +}; + +export async function getUpdateMerchantSettlementWalletInstructionAsync< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountNewSettlementWallet extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: UpdateMerchantSettlementWalletAsyncInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewSettlementWallet + >, + config?: { programAddress?: TProgramAddress } +): Promise< + UpdateMerchantSettlementWalletInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewSettlementWallet + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + merchant: { value: input.merchant ?? null, isWritable: true }, + newSettlementWallet: { + value: input.newSettlementWallet ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.merchant.value) { + accounts.merchant.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('merchant'), + getAddressEncoder().encode(expectAddress(accounts.authority.value)), + ], + }); + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.newSettlementWallet), + ], + programAddress, + data: getUpdateMerchantSettlementWalletInstructionDataEncoder().encode({}), + } as UpdateMerchantSettlementWalletInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewSettlementWallet + >; + + return instruction; +} + +export type UpdateMerchantSettlementWalletInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountMerchant extends string = string, + TAccountNewSettlementWallet extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + /** Merchant PDA */ + merchant: Address; + newSettlementWallet: Address; +}; + +export function getUpdateMerchantSettlementWalletInstruction< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountMerchant extends string, + TAccountNewSettlementWallet extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: UpdateMerchantSettlementWalletInput< + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewSettlementWallet + >, + config?: { programAddress?: TProgramAddress } +): UpdateMerchantSettlementWalletInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewSettlementWallet +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + merchant: { value: input.merchant ?? null, isWritable: true }, + newSettlementWallet: { + value: input.newSettlementWallet ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.merchant), + getAccountMeta(accounts.newSettlementWallet), + ], + programAddress, + data: getUpdateMerchantSettlementWalletInstructionDataEncoder().encode({}), + } as UpdateMerchantSettlementWalletInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountMerchant, + TAccountNewSettlementWallet + >; + + return instruction; +} + +export type ParsedUpdateMerchantSettlementWalletInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + authority: TAccountMetas[1]; + /** Merchant PDA */ + merchant: TAccountMetas[2]; + newSettlementWallet: TAccountMetas[3]; + }; + data: UpdateMerchantSettlementWalletInstructionData; +}; + +export function parseUpdateMerchantSettlementWalletInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedUpdateMerchantSettlementWalletInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + authority: getNextAccount(), + merchant: getNextAccount(), + newSettlementWallet: getNextAccount(), + }, + data: getUpdateMerchantSettlementWalletInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/program/clients/typescript/src/generated/instructions/updateOperatorAuthority.ts b/program/clients/typescript/src/generated/instructions/updateOperatorAuthority.ts new file mode 100644 index 0000000..39e10aa --- /dev/null +++ b/program/clients/typescript/src/generated/instructions/updateOperatorAuthority.ts @@ -0,0 +1,311 @@ +/** + * 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, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUtf8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const UPDATE_OPERATOR_AUTHORITY_DISCRIMINATOR = 8; + +export function getUpdateOperatorAuthorityDiscriminatorBytes() { + return getU8Encoder().encode(UPDATE_OPERATOR_AUTHORITY_DISCRIMINATOR); +} + +export type UpdateOperatorAuthorityInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountNewOperatorAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAuthority extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountAuthority, + TAccountOperator extends string + ? WritableAccount + : TAccountOperator, + TAccountNewOperatorAuthority extends string + ? ReadonlyAccount + : TAccountNewOperatorAuthority, + ...TRemainingAccounts, + ] + >; + +export type UpdateOperatorAuthorityInstructionData = { discriminator: number }; + +export type UpdateOperatorAuthorityInstructionDataArgs = {}; + +export function getUpdateOperatorAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ + ...value, + discriminator: UPDATE_OPERATOR_AUTHORITY_DISCRIMINATOR, + }) + ); +} + +export function getUpdateOperatorAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getUpdateOperatorAuthorityInstructionDataCodec(): FixedSizeCodec< + UpdateOperatorAuthorityInstructionDataArgs, + UpdateOperatorAuthorityInstructionData +> { + return combineCodec( + getUpdateOperatorAuthorityInstructionDataEncoder(), + getUpdateOperatorAuthorityInstructionDataDecoder() + ); +} + +export type UpdateOperatorAuthorityAsyncInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountOperator extends string = string, + TAccountNewOperatorAuthority extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + /** Operator PDA */ + operator?: Address; + newOperatorAuthority: Address; +}; + +export async function getUpdateOperatorAuthorityInstructionAsync< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountOperator extends string, + TAccountNewOperatorAuthority extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: UpdateOperatorAuthorityAsyncInput< + TAccountPayer, + TAccountAuthority, + TAccountOperator, + TAccountNewOperatorAuthority + >, + config?: { programAddress?: TProgramAddress } +): Promise< + UpdateOperatorAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountOperator, + TAccountNewOperatorAuthority + > +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: true }, + newOperatorAuthority: { + value: input.newOperatorAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.operator.value) { + accounts.operator.value = await getProgramDerivedAddress({ + programAddress: + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode(expectAddress(accounts.authority.value)), + ], + }); + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.newOperatorAuthority), + ], + programAddress, + data: getUpdateOperatorAuthorityInstructionDataEncoder().encode({}), + } as UpdateOperatorAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountOperator, + TAccountNewOperatorAuthority + >; + + return instruction; +} + +export type UpdateOperatorAuthorityInput< + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountOperator extends string = string, + TAccountNewOperatorAuthority extends string = string, +> = { + payer: TransactionSigner; + authority: TransactionSigner; + /** Operator PDA */ + operator: Address; + newOperatorAuthority: Address; +}; + +export function getUpdateOperatorAuthorityInstruction< + TAccountPayer extends string, + TAccountAuthority extends string, + TAccountOperator extends string, + TAccountNewOperatorAuthority extends string, + TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, +>( + input: UpdateOperatorAuthorityInput< + TAccountPayer, + TAccountAuthority, + TAccountOperator, + TAccountNewOperatorAuthority + >, + config?: { programAddress?: TProgramAddress } +): UpdateOperatorAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountOperator, + TAccountNewOperatorAuthority +> { + // Program address. + const programAddress = + config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: true }, + newOperatorAuthority: { + value: input.newOperatorAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.newOperatorAuthority), + ], + programAddress, + data: getUpdateOperatorAuthorityInstructionDataEncoder().encode({}), + } as UpdateOperatorAuthorityInstruction< + TProgramAddress, + TAccountPayer, + TAccountAuthority, + TAccountOperator, + TAccountNewOperatorAuthority + >; + + return instruction; +} + +export type ParsedUpdateOperatorAuthorityInstruction< + TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + authority: TAccountMetas[1]; + /** Operator PDA */ + operator: TAccountMetas[2]; + newOperatorAuthority: TAccountMetas[3]; + }; + data: UpdateOperatorAuthorityInstructionData; +}; + +export function parseUpdateOperatorAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedUpdateOperatorAuthorityInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + authority: getNextAccount(), + operator: getNextAccount(), + newOperatorAuthority: getNextAccount(), + }, + data: getUpdateOperatorAuthorityInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/program/clients/typescript/src/generated/pdas/eventAuthority.ts b/program/clients/typescript/src/generated/pdas/eventAuthority.ts new file mode 100644 index 0000000..1e28875 --- /dev/null +++ b/program/clients/typescript/src/generated/pdas/eventAuthority.ts @@ -0,0 +1,26 @@ +/** + * 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 { + getProgramDerivedAddress, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export async function findEventAuthorityPda( + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [getUtf8Encoder().encode('event_authority')], + }); +} diff --git a/program/clients/typescript/src/generated/pdas/index.ts b/program/clients/typescript/src/generated/pdas/index.ts new file mode 100644 index 0000000..b3c3267 --- /dev/null +++ b/program/clients/typescript/src/generated/pdas/index.ts @@ -0,0 +1,13 @@ +/** + * 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 + */ + +export * from './eventAuthority'; +export * from './merchant'; +export * from './merchantOperatorConfig'; +export * from './operator'; +export * from './payment'; diff --git a/program/clients/typescript/src/generated/pdas/merchant.ts b/program/clients/typescript/src/generated/pdas/merchant.ts new file mode 100644 index 0000000..54a4c20 --- /dev/null +++ b/program/clients/typescript/src/generated/pdas/merchant.ts @@ -0,0 +1,35 @@ +/** + * 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 { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export type MerchantSeeds = { + owner: Address; +}; + +export async function findMerchantPda( + seeds: MerchantSeeds, + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode('merchant'), + getAddressEncoder().encode(seeds.owner), + ], + }); +} diff --git a/program/clients/typescript/src/generated/pdas/merchantOperatorConfig.ts b/program/clients/typescript/src/generated/pdas/merchantOperatorConfig.ts new file mode 100644 index 0000000..e7b29ba --- /dev/null +++ b/program/clients/typescript/src/generated/pdas/merchantOperatorConfig.ts @@ -0,0 +1,42 @@ +/** + * 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 { + getAddressEncoder, + getProgramDerivedAddress, + getU32Encoder, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export type MerchantOperatorConfigSeeds = { + merchant: Address; + + operator: Address; + + version: number; +}; + +export async function findMerchantOperatorConfigPda( + seeds: MerchantOperatorConfigSeeds, + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode('merchant_operator_config'), + getAddressEncoder().encode(seeds.merchant), + getAddressEncoder().encode(seeds.operator), + getU32Encoder().encode(seeds.version), + ], + }); +} diff --git a/program/clients/typescript/src/generated/pdas/operator.ts b/program/clients/typescript/src/generated/pdas/operator.ts new file mode 100644 index 0000000..9e1696f --- /dev/null +++ b/program/clients/typescript/src/generated/pdas/operator.ts @@ -0,0 +1,35 @@ +/** + * 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 { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export type OperatorSeeds = { + owner: Address; +}; + +export async function findOperatorPda( + seeds: OperatorSeeds, + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode(seeds.owner), + ], + }); +} diff --git a/program/clients/typescript/src/generated/pdas/payment.ts b/program/clients/typescript/src/generated/pdas/payment.ts new file mode 100644 index 0000000..91c4fde --- /dev/null +++ b/program/clients/typescript/src/generated/pdas/payment.ts @@ -0,0 +1,45 @@ +/** + * 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 { + getAddressEncoder, + getProgramDerivedAddress, + getU32Encoder, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export type PaymentSeeds = { + merchantOperatorConfig: Address; + + buyer: Address; + + mint: Address; + + orderId: number; +}; + +export async function findPaymentPda( + seeds: PaymentSeeds, + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode('payment'), + getAddressEncoder().encode(seeds.merchantOperatorConfig), + getAddressEncoder().encode(seeds.buyer), + getAddressEncoder().encode(seeds.mint), + getU32Encoder().encode(seeds.orderId), + ], + }); +} diff --git a/program/clients/typescript/src/generated/programs/commerceProgram.ts b/program/clients/typescript/src/generated/programs/commerceProgram.ts new file mode 100644 index 0000000..c7b90ce --- /dev/null +++ b/program/clients/typescript/src/generated/programs/commerceProgram.ts @@ -0,0 +1,130 @@ +/** + * 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 { + containsBytes, + getU8Encoder, + type Address, + type ReadonlyUint8Array, +} from '@solana/kit'; +import { + type ParsedClearPaymentInstruction, + type ParsedClosePaymentInstruction, + type ParsedCreateOperatorInstruction, + type ParsedEmitEventInstruction, + type ParsedInitializeMerchantInstruction, + type ParsedInitializeMerchantOperatorConfigInstruction, + type ParsedMakePaymentInstruction, + type ParsedRefundPaymentInstruction, + type ParsedUpdateMerchantAuthorityInstruction, + type ParsedUpdateMerchantSettlementWalletInstruction, + type ParsedUpdateOperatorAuthorityInstruction, +} from '../instructions'; + +export const COMMERCE_PROGRAM_PROGRAM_ADDRESS = + 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>; + +export enum CommerceProgramAccount { + Merchant, + MerchantOperatorConfig, + Operator, + Payment, +} + +export enum CommerceProgramInstruction { + InitializeMerchant, + CreateOperator, + InitializeMerchantOperatorConfig, + MakePayment, + ClearPayment, + RefundPayment, + UpdateMerchantSettlementWallet, + UpdateMerchantAuthority, + UpdateOperatorAuthority, + ClosePayment, + EmitEvent, +} + +export function identifyCommerceProgramInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array +): CommerceProgramInstruction { + const data = 'data' in instruction ? instruction.data : instruction; + if (containsBytes(data, getU8Encoder().encode(0), 0)) { + return CommerceProgramInstruction.InitializeMerchant; + } + if (containsBytes(data, getU8Encoder().encode(1), 0)) { + return CommerceProgramInstruction.CreateOperator; + } + if (containsBytes(data, getU8Encoder().encode(2), 0)) { + return CommerceProgramInstruction.InitializeMerchantOperatorConfig; + } + if (containsBytes(data, getU8Encoder().encode(3), 0)) { + return CommerceProgramInstruction.MakePayment; + } + if (containsBytes(data, getU8Encoder().encode(4), 0)) { + return CommerceProgramInstruction.ClearPayment; + } + if (containsBytes(data, getU8Encoder().encode(5), 0)) { + return CommerceProgramInstruction.RefundPayment; + } + if (containsBytes(data, getU8Encoder().encode(6), 0)) { + return CommerceProgramInstruction.UpdateMerchantSettlementWallet; + } + if (containsBytes(data, getU8Encoder().encode(7), 0)) { + return CommerceProgramInstruction.UpdateMerchantAuthority; + } + if (containsBytes(data, getU8Encoder().encode(8), 0)) { + return CommerceProgramInstruction.UpdateOperatorAuthority; + } + if (containsBytes(data, getU8Encoder().encode(9), 0)) { + return CommerceProgramInstruction.ClosePayment; + } + if (containsBytes(data, getU8Encoder().encode(228), 0)) { + return CommerceProgramInstruction.EmitEvent; + } + throw new Error( + 'The provided instruction could not be identified as a commerceProgram instruction.' + ); +} + +export type ParsedCommerceProgramInstruction< + TProgram extends string = 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT', +> = + | ({ + instructionType: CommerceProgramInstruction.InitializeMerchant; + } & ParsedInitializeMerchantInstruction) + | ({ + instructionType: CommerceProgramInstruction.CreateOperator; + } & ParsedCreateOperatorInstruction) + | ({ + instructionType: CommerceProgramInstruction.InitializeMerchantOperatorConfig; + } & ParsedInitializeMerchantOperatorConfigInstruction) + | ({ + instructionType: CommerceProgramInstruction.MakePayment; + } & ParsedMakePaymentInstruction) + | ({ + instructionType: CommerceProgramInstruction.ClearPayment; + } & ParsedClearPaymentInstruction) + | ({ + instructionType: CommerceProgramInstruction.RefundPayment; + } & ParsedRefundPaymentInstruction) + | ({ + instructionType: CommerceProgramInstruction.UpdateMerchantSettlementWallet; + } & ParsedUpdateMerchantSettlementWalletInstruction) + | ({ + instructionType: CommerceProgramInstruction.UpdateMerchantAuthority; + } & ParsedUpdateMerchantAuthorityInstruction) + | ({ + instructionType: CommerceProgramInstruction.UpdateOperatorAuthority; + } & ParsedUpdateOperatorAuthorityInstruction) + | ({ + instructionType: CommerceProgramInstruction.ClosePayment; + } & ParsedClosePaymentInstruction) + | ({ + instructionType: CommerceProgramInstruction.EmitEvent; + } & ParsedEmitEventInstruction); diff --git a/program/clients/typescript/src/generated/programs/index.ts b/program/clients/typescript/src/generated/programs/index.ts new file mode 100644 index 0000000..96e5fd5 --- /dev/null +++ b/program/clients/typescript/src/generated/programs/index.ts @@ -0,0 +1,9 @@ +/** + * 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 + */ + +export * from './commerceProgram'; diff --git a/program/clients/typescript/src/generated/shared/index.ts b/program/clients/typescript/src/generated/shared/index.ts new file mode 100644 index 0000000..8841a27 --- /dev/null +++ b/program/clients/typescript/src/generated/shared/index.ts @@ -0,0 +1,164 @@ +/** + * 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 { + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + type AccountMeta, + type AccountSignerMeta, + type Address, + type ProgramDerivedAddress, + type TransactionSigner, + upgradeRoleToSigner, +} from '@solana/kit'; + +/** + * Asserts that the given value is not null or undefined. + * @internal + */ +export function expectSome(value: T | null | undefined): T { + if (value === null || value === undefined) { + throw new Error('Expected a value but received null or undefined.'); + } + return value; +} + +/** + * Asserts that the given value is a PublicKey. + * @internal + */ +export function expectAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): Address { + if (!value) { + throw new Error('Expected a Address.'); + } + if (typeof value === 'object' && 'address' in value) { + return value.address; + } + if (Array.isArray(value)) { + return value[0] as Address; + } + return value as Address; +} + +/** + * Asserts that the given value is a PDA. + * @internal + */ +export function expectProgramDerivedAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): ProgramDerivedAddress { + if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) { + throw new Error('Expected a ProgramDerivedAddress.'); + } + return value; +} + +/** + * Asserts that the given value is a TransactionSigner. + * @internal + */ +export function expectTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): TransactionSigner { + if (!value || !isTransactionSigner(value)) { + throw new Error('Expected a TransactionSigner.'); + } + return value; +} + +/** + * Defines an instruction account to resolve. + * @internal + */ +export type ResolvedAccount< + T extends string = string, + U extends + | Address + | ProgramDerivedAddress + | TransactionSigner + | null = + | Address + | ProgramDerivedAddress + | TransactionSigner + | null, +> = { + isWritable: boolean; + value: U; +}; + +/** + * Defines an instruction that stores additional bytes on-chain. + * @internal + */ +export type InstructionWithByteDelta = { + byteDelta: number; +}; + +/** + * Get account metas and signers from resolved accounts. + * @internal + */ +export function getAccountMetaFactory( + programAddress: Address, + optionalAccountStrategy: 'omitted' | 'programId' +) { + return ( + account: ResolvedAccount + ): AccountMeta | AccountSignerMeta | undefined => { + if (!account.value) { + if (optionalAccountStrategy === 'omitted') return; + return Object.freeze({ + address: programAddress, + role: AccountRole.READONLY, + }); + } + + const writableRole = account.isWritable + ? AccountRole.WRITABLE + : AccountRole.READONLY; + return Object.freeze({ + address: expectAddress(account.value), + role: isTransactionSigner(account.value) + ? upgradeRoleToSigner(writableRole) + : writableRole, + ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), + }); + }; +} + +export function isTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner +): value is TransactionSigner { + return ( + !!value && + typeof value === 'object' && + 'address' in value && + kitIsTransactionSigner(value) + ); +} diff --git a/program/clients/typescript/src/generated/types/chargebackPolicy.ts b/program/clients/typescript/src/generated/types/chargebackPolicy.ts new file mode 100644 index 0000000..6ca51ad --- /dev/null +++ b/program/clients/typescript/src/generated/types/chargebackPolicy.ts @@ -0,0 +1,37 @@ +/** + * 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, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder } from '@solana/kit'; + + + +export type ChargebackPolicy = { maxAmount: bigint; maxTimeAfterPurchase: bigint; }; + +export type ChargebackPolicyArgs = { maxAmount: number | bigint; maxTimeAfterPurchase: number | bigint; }; + + + + +export function getChargebackPolicyEncoder(): FixedSizeEncoder { + return getStructEncoder([['maxAmount', getU64Encoder()], ['maxTimeAfterPurchase', getU64Encoder()]]); +} + + + +export function getChargebackPolicyDecoder(): FixedSizeDecoder { + return getStructDecoder([['maxAmount', getU64Decoder()], ['maxTimeAfterPurchase', getU64Decoder()]]); +} + + + + +export function getChargebackPolicyCodec(): FixedSizeCodec { + return combineCodec(getChargebackPolicyEncoder(), getChargebackPolicyDecoder()); +} + + diff --git a/program/clients/typescript/src/generated/types/feeType.ts b/program/clients/typescript/src/generated/types/feeType.ts new file mode 100644 index 0000000..b8f4e63 --- /dev/null +++ b/program/clients/typescript/src/generated/types/feeType.ts @@ -0,0 +1,35 @@ +/** + * 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, + getEnumDecoder, + getEnumEncoder, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export enum FeeType { + Bps, + Fixed, +} + +export type FeeTypeArgs = FeeType; + +export function getFeeTypeEncoder(): FixedSizeEncoder { + return getEnumEncoder(FeeType); +} + +export function getFeeTypeDecoder(): FixedSizeDecoder { + return getEnumDecoder(FeeType); +} + +export function getFeeTypeCodec(): FixedSizeCodec { + return combineCodec(getFeeTypeEncoder(), getFeeTypeDecoder()); +} diff --git a/program/clients/typescript/src/generated/types/index.ts b/program/clients/typescript/src/generated/types/index.ts new file mode 100644 index 0000000..9a07acd --- /dev/null +++ b/program/clients/typescript/src/generated/types/index.ts @@ -0,0 +1,17 @@ +/** + * 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 + */ + +export * from './feeType'; +export * from './paymentClearedEvent'; +export * from './paymentCreatedEvent'; +export * from './paymentRefundedEvent'; +export * from './policyData'; +export * from './policyType'; +export * from './refundPolicy'; +export * from './settlementPolicy'; +export * from './status'; diff --git a/program/clients/typescript/src/generated/types/paymentChargebackedEvent.ts b/program/clients/typescript/src/generated/types/paymentChargebackedEvent.ts new file mode 100644 index 0000000..89dd033 --- /dev/null +++ b/program/clients/typescript/src/generated/types/paymentChargebackedEvent.ts @@ -0,0 +1,37 @@ +/** + * 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, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder } from '@solana/kit'; + + + +export type PaymentChargebackedEvent = { discriminator: number; buyer: Address; merchant: Address; operator: Address; amount: bigint; orderId: number; }; + +export type PaymentChargebackedEventArgs = { discriminator: number; buyer: Address; merchant: Address; operator: Address; amount: number | bigint; orderId: number; }; + + + + +export function getPaymentChargebackedEventEncoder(): FixedSizeEncoder { + return getStructEncoder([['discriminator', getU8Encoder()], ['buyer', getAddressEncoder()], ['merchant', getAddressEncoder()], ['operator', getAddressEncoder()], ['amount', getU64Encoder()], ['orderId', getU32Encoder()]]); +} + + + +export function getPaymentChargebackedEventDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()], ['buyer', getAddressDecoder()], ['merchant', getAddressDecoder()], ['operator', getAddressDecoder()], ['amount', getU64Decoder()], ['orderId', getU32Decoder()]]); +} + + + + +export function getPaymentChargebackedEventCodec(): FixedSizeCodec { + return combineCodec(getPaymentChargebackedEventEncoder(), getPaymentChargebackedEventDecoder()); +} + + diff --git a/program/clients/typescript/src/generated/types/paymentClearedEvent.ts b/program/clients/typescript/src/generated/types/paymentClearedEvent.ts new file mode 100644 index 0000000..a1df8e9 --- /dev/null +++ b/program/clients/typescript/src/generated/types/paymentClearedEvent.ts @@ -0,0 +1,79 @@ +/** + * 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, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type PaymentClearedEvent = { + discriminator: number; + buyer: Address; + merchant: Address; + operator: Address; + amount: bigint; + operatorFee: bigint; + orderId: number; +}; + +export type PaymentClearedEventArgs = { + discriminator: number; + buyer: Address; + merchant: Address; + operator: Address; + amount: number | bigint; + operatorFee: number | bigint; + orderId: number; +}; + +export function getPaymentClearedEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['buyer', getAddressEncoder()], + ['merchant', getAddressEncoder()], + ['operator', getAddressEncoder()], + ['amount', getU64Encoder()], + ['operatorFee', getU64Encoder()], + ['orderId', getU32Encoder()], + ]); +} + +export function getPaymentClearedEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['buyer', getAddressDecoder()], + ['merchant', getAddressDecoder()], + ['operator', getAddressDecoder()], + ['amount', getU64Decoder()], + ['operatorFee', getU64Decoder()], + ['orderId', getU32Decoder()], + ]); +} + +export function getPaymentClearedEventCodec(): FixedSizeCodec< + PaymentClearedEventArgs, + PaymentClearedEvent +> { + return combineCodec( + getPaymentClearedEventEncoder(), + getPaymentClearedEventDecoder() + ); +} diff --git a/program/clients/typescript/src/generated/types/paymentCreatedEvent.ts b/program/clients/typescript/src/generated/types/paymentCreatedEvent.ts new file mode 100644 index 0000000..817ba84 --- /dev/null +++ b/program/clients/typescript/src/generated/types/paymentCreatedEvent.ts @@ -0,0 +1,75 @@ +/** + * 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, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type PaymentCreatedEvent = { + discriminator: number; + buyer: Address; + merchant: Address; + operator: Address; + amount: bigint; + orderId: number; +}; + +export type PaymentCreatedEventArgs = { + discriminator: number; + buyer: Address; + merchant: Address; + operator: Address; + amount: number | bigint; + orderId: number; +}; + +export function getPaymentCreatedEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['buyer', getAddressEncoder()], + ['merchant', getAddressEncoder()], + ['operator', getAddressEncoder()], + ['amount', getU64Encoder()], + ['orderId', getU32Encoder()], + ]); +} + +export function getPaymentCreatedEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['buyer', getAddressDecoder()], + ['merchant', getAddressDecoder()], + ['operator', getAddressDecoder()], + ['amount', getU64Decoder()], + ['orderId', getU32Decoder()], + ]); +} + +export function getPaymentCreatedEventCodec(): FixedSizeCodec< + PaymentCreatedEventArgs, + PaymentCreatedEvent +> { + return combineCodec( + getPaymentCreatedEventEncoder(), + getPaymentCreatedEventDecoder() + ); +} diff --git a/program/clients/typescript/src/generated/types/paymentRefundedEvent.ts b/program/clients/typescript/src/generated/types/paymentRefundedEvent.ts new file mode 100644 index 0000000..99886de --- /dev/null +++ b/program/clients/typescript/src/generated/types/paymentRefundedEvent.ts @@ -0,0 +1,75 @@ +/** + * 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, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type PaymentRefundedEvent = { + discriminator: number; + buyer: Address; + merchant: Address; + operator: Address; + amount: bigint; + orderId: number; +}; + +export type PaymentRefundedEventArgs = { + discriminator: number; + buyer: Address; + merchant: Address; + operator: Address; + amount: number | bigint; + orderId: number; +}; + +export function getPaymentRefundedEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['buyer', getAddressEncoder()], + ['merchant', getAddressEncoder()], + ['operator', getAddressEncoder()], + ['amount', getU64Encoder()], + ['orderId', getU32Encoder()], + ]); +} + +export function getPaymentRefundedEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['buyer', getAddressDecoder()], + ['merchant', getAddressDecoder()], + ['operator', getAddressDecoder()], + ['amount', getU64Decoder()], + ['orderId', getU32Decoder()], + ]); +} + +export function getPaymentRefundedEventCodec(): FixedSizeCodec< + PaymentRefundedEventArgs, + PaymentRefundedEvent +> { + return combineCodec( + getPaymentRefundedEventEncoder(), + getPaymentRefundedEventDecoder() + ); +} diff --git a/program/clients/typescript/src/generated/types/policyData.ts b/program/clients/typescript/src/generated/types/policyData.ts new file mode 100644 index 0000000..9a7952f --- /dev/null +++ b/program/clients/typescript/src/generated/types/policyData.ts @@ -0,0 +1,111 @@ +/** + * 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, + getDiscriminatedUnionDecoder, + getDiscriminatedUnionEncoder, + getStructDecoder, + getStructEncoder, + getTupleDecoder, + getTupleEncoder, + type Codec, + type Decoder, + type Encoder, + type GetDiscriminatedUnionVariant, + type GetDiscriminatedUnionVariantContent, +} from '@solana/kit'; +import { + getRefundPolicyDecoder, + getRefundPolicyEncoder, + getSettlementPolicyDecoder, + getSettlementPolicyEncoder, + type RefundPolicy, + type RefundPolicyArgs, + type SettlementPolicy, + type SettlementPolicyArgs, +} from '.'; + +export type PolicyData = + | { __kind: 'Refund'; fields: readonly [RefundPolicy] } + | { __kind: 'Settlement'; fields: readonly [SettlementPolicy] }; + +export type PolicyDataArgs = + | { __kind: 'Refund'; fields: readonly [RefundPolicyArgs] } + | { __kind: 'Settlement'; fields: readonly [SettlementPolicyArgs] }; + +export function getPolicyDataEncoder(): Encoder { + return getDiscriminatedUnionEncoder([ + [ + 'Refund', + getStructEncoder([ + ['fields', getTupleEncoder([getRefundPolicyEncoder()])], + ]), + ], + [ + 'Settlement', + getStructEncoder([ + ['fields', getTupleEncoder([getSettlementPolicyEncoder()])], + ]), + ], + ]); +} + +export function getPolicyDataDecoder(): Decoder { + return getDiscriminatedUnionDecoder([ + [ + 'Refund', + getStructDecoder([ + ['fields', getTupleDecoder([getRefundPolicyDecoder()])], + ]), + ], + [ + 'Settlement', + getStructDecoder([ + ['fields', getTupleDecoder([getSettlementPolicyDecoder()])], + ]), + ], + ]); +} + +export function getPolicyDataCodec(): Codec { + return combineCodec(getPolicyDataEncoder(), getPolicyDataDecoder()); +} + +// Data Enum Helpers. +export function policyData( + kind: 'Refund', + data: GetDiscriminatedUnionVariantContent< + PolicyDataArgs, + '__kind', + 'Refund' + >['fields'] +): GetDiscriminatedUnionVariant; +export function policyData( + kind: 'Settlement', + data: GetDiscriminatedUnionVariantContent< + PolicyDataArgs, + '__kind', + 'Settlement' + >['fields'] +): GetDiscriminatedUnionVariant; +export function policyData( + kind: K, + data?: Data +) { + return Array.isArray(data) + ? { __kind: kind, fields: data } + : { __kind: kind, ...(data ?? {}) }; +} + +export function isPolicyData( + kind: K, + value: PolicyData +): value is PolicyData & { __kind: K } { + return value.__kind === kind; +} diff --git a/program/clients/typescript/src/generated/types/policyType.ts b/program/clients/typescript/src/generated/types/policyType.ts new file mode 100644 index 0000000..17a7290 --- /dev/null +++ b/program/clients/typescript/src/generated/types/policyType.ts @@ -0,0 +1,38 @@ +/** + * 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, + getEnumDecoder, + getEnumEncoder, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export enum PolicyType { + Refund, + Settlement, +} + +export type PolicyTypeArgs = PolicyType; + +export function getPolicyTypeEncoder(): FixedSizeEncoder { + return getEnumEncoder(PolicyType); +} + +export function getPolicyTypeDecoder(): FixedSizeDecoder { + return getEnumDecoder(PolicyType); +} + +export function getPolicyTypeCodec(): FixedSizeCodec< + PolicyTypeArgs, + PolicyType +> { + return combineCodec(getPolicyTypeEncoder(), getPolicyTypeDecoder()); +} diff --git a/program/clients/typescript/src/generated/types/refundPolicy.ts b/program/clients/typescript/src/generated/types/refundPolicy.ts new file mode 100644 index 0000000..17cfae8 --- /dev/null +++ b/program/clients/typescript/src/generated/types/refundPolicy.ts @@ -0,0 +1,46 @@ +/** + * 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, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type RefundPolicy = { maxAmount: bigint; maxTimeAfterPurchase: bigint }; + +export type RefundPolicyArgs = { + maxAmount: number | bigint; + maxTimeAfterPurchase: number | bigint; +}; + +export function getRefundPolicyEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['maxAmount', getU64Encoder()], + ['maxTimeAfterPurchase', getU64Encoder()], + ]); +} + +export function getRefundPolicyDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['maxAmount', getU64Decoder()], + ['maxTimeAfterPurchase', getU64Decoder()], + ]); +} + +export function getRefundPolicyCodec(): FixedSizeCodec< + RefundPolicyArgs, + RefundPolicy +> { + return combineCodec(getRefundPolicyEncoder(), getRefundPolicyDecoder()); +} diff --git a/program/clients/typescript/src/generated/types/settlementPolicy.ts b/program/clients/typescript/src/generated/types/settlementPolicy.ts new file mode 100644 index 0000000..4f504a5 --- /dev/null +++ b/program/clients/typescript/src/generated/types/settlementPolicy.ts @@ -0,0 +1,60 @@ +/** + * 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, + getBooleanDecoder, + getBooleanEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type SettlementPolicy = { + minSettlementAmount: bigint; + settlementFrequencyHours: number; + autoSettle: boolean; +}; + +export type SettlementPolicyArgs = { + minSettlementAmount: number | bigint; + settlementFrequencyHours: number; + autoSettle: boolean; +}; + +export function getSettlementPolicyEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['minSettlementAmount', getU64Encoder()], + ['settlementFrequencyHours', getU32Encoder()], + ['autoSettle', getBooleanEncoder()], + ]); +} + +export function getSettlementPolicyDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['minSettlementAmount', getU64Decoder()], + ['settlementFrequencyHours', getU32Decoder()], + ['autoSettle', getBooleanDecoder()], + ]); +} + +export function getSettlementPolicyCodec(): FixedSizeCodec< + SettlementPolicyArgs, + SettlementPolicy +> { + return combineCodec( + getSettlementPolicyEncoder(), + getSettlementPolicyDecoder() + ); +} diff --git a/program/clients/typescript/src/generated/types/status.ts b/program/clients/typescript/src/generated/types/status.ts new file mode 100644 index 0000000..9eb0dbe --- /dev/null +++ b/program/clients/typescript/src/generated/types/status.ts @@ -0,0 +1,36 @@ +/** + * 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, + getEnumDecoder, + getEnumEncoder, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export enum Status { + Paid, + Cleared, + Refunded, +} + +export type StatusArgs = Status; + +export function getStatusEncoder(): FixedSizeEncoder { + return getEnumEncoder(Status); +} + +export function getStatusDecoder(): FixedSizeDecoder { + return getEnumDecoder(Status); +} + +export function getStatusCodec(): FixedSizeCodec { + return combineCodec(getStatusEncoder(), getStatusDecoder()); +}