Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-boxes-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codama/renderers-rust": minor
---

Extract `solana-instruction` from `solana-program`
1 change: 1 addition & 0 deletions packages/renderers-rust/e2e/anchor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/renderers-rust/e2e/anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ num-traits = "^0.2"
serde = { version = "^1.0", features = ["derive"], optional = true }
serde_with = { version = "^3.0", optional = true }
solana-program = "2.2.1"
solana-instruction = "2.2.1"
solana-pubkey = { version = "2.2.1", features = ["curve25519"] }
solana-client = { version = "~1.18", optional = true }
solana-sdk = { version = "~1.18", optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,37 @@ pub struct CreateGuard {
}

impl CreateGuard {
pub fn instruction(
&self,
args: CreateGuardInstructionArgs,
) -> solana_program::instruction::Instruction {
pub fn instruction(&self, args: CreateGuardInstructionArgs) -> 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: CreateGuardInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
remaining_accounts: &[solana_instruction::AccountMeta],
) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
self.guard, false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.mint, true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
accounts.push(solana_instruction::AccountMeta::new(self.guard, false));
accounts.push(solana_instruction::AccountMeta::new(self.mint, true));
accounts.push(solana_instruction::AccountMeta::new(
self.mint_token_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.guard_authority,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.payer, true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new(self.payer, true));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.associated_token_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
Expand All @@ -80,7 +71,7 @@ impl CreateGuard {
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);

solana_program::instruction::Instruction {
solana_instruction::Instruction {
program_id: crate::WEN_TRANSFER_GUARD_ID,
accounts,
data,
Expand Down Expand Up @@ -147,7 +138,7 @@ pub struct CreateGuardBuilder {
cpi_rule: Option<CpiRule>,
transfer_amount_rule: Option<TransferAmountRule>,
additional_fields_rule: Option<Vec<MetadataAdditionalFieldRule>>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl CreateGuardBuilder {
Expand Down Expand Up @@ -237,24 +228,21 @@ impl CreateGuardBuilder {
}
/// Add an additional account to the instruction.
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: solana_program::instruction::AccountMeta,
) -> &mut Self {
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_program::instruction::AccountMeta],
accounts: &[solana_instruction::AccountMeta],
) -> &mut Self {
self.__remaining_accounts.extend_from_slice(accounts);
self
}
#[allow(clippy::clone_on_copy)]
pub fn instruction(&self) -> solana_program::instruction::Instruction {
pub fn instruction(&self) -> solana_instruction::Instruction {
let accounts = CreateGuard {
guard: self.guard.expect("guard is not set"),
mint: self.mint.expect("mint is not set"),
Expand Down Expand Up @@ -386,40 +374,31 @@ impl<'a, 'b> CreateGuardCpi<'a, 'b> {
)],
) -> solana_program::entrypoint::ProgramResult {
let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
*self.guard.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.mint.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
accounts.push(solana_instruction::AccountMeta::new(*self.guard.key, false));
accounts.push(solana_instruction::AccountMeta::new(*self.mint.key, true));
accounts.push(solana_instruction::AccountMeta::new(
*self.mint_token_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.guard_authority.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.payer.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.associated_token_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
accounts.push(solana_instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_signer: remaining_account.1,
is_writable: remaining_account.2,
Expand All @@ -429,7 +408,7 @@ impl<'a, 'b> CreateGuardCpi<'a, 'b> {
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);

let instruction = solana_program::instruction::Instruction {
let instruction = solana_instruction::Instruction {
program_id: crate::WEN_TRANSFER_GUARD_ID,
accounts,
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,40 @@ pub struct Execute {
}

impl Execute {
pub fn instruction(
&self,
args: ExecuteInstructionArgs,
) -> solana_program::instruction::Instruction {
pub fn instruction(&self, args: ExecuteInstructionArgs) -> 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: ExecuteInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
remaining_accounts: &[solana_instruction::AccountMeta],
) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.source_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.mint, false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.destination_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.owner_delegate,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.extra_metas_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.guard, false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.instruction_sysvar_account,
false,
));
Expand All @@ -72,7 +69,7 @@ impl Execute {
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);

solana_program::instruction::Instruction {
solana_instruction::Instruction {
program_id: crate::WEN_TRANSFER_GUARD_ID,
accounts,
data,
Expand Down Expand Up @@ -127,7 +124,7 @@ pub struct ExecuteBuilder {
guard: Option<solana_pubkey::Pubkey>,
instruction_sysvar_account: Option<solana_pubkey::Pubkey>,
amount: Option<u64>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl ExecuteBuilder {
Expand Down Expand Up @@ -180,24 +177,21 @@ impl ExecuteBuilder {
}
/// Add an additional account to the instruction.
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: solana_program::instruction::AccountMeta,
) -> &mut Self {
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_program::instruction::AccountMeta],
accounts: &[solana_instruction::AccountMeta],
) -> &mut Self {
self.__remaining_accounts.extend_from_slice(accounts);
self
}
#[allow(clippy::clone_on_copy)]
pub fn instruction(&self) -> solana_program::instruction::Instruction {
pub fn instruction(&self) -> solana_instruction::Instruction {
let accounts = Execute {
source_account: self.source_account.expect("source_account is not set"),
mint: self.mint.expect("mint is not set"),
Expand Down Expand Up @@ -313,36 +307,36 @@ impl<'a, 'b> ExecuteCpi<'a, 'b> {
)],
) -> solana_program::entrypoint::ProgramResult {
let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.source_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.mint.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.destination_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.owner_delegate.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.extra_metas_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.guard.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.instruction_sysvar_account.key,
false,
));
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
accounts.push(solana_instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_signer: remaining_account.1,
is_writable: remaining_account.2,
Expand All @@ -352,7 +346,7 @@ impl<'a, 'b> ExecuteCpi<'a, 'b> {
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);

let instruction = solana_program::instruction::Instruction {
let instruction = solana_instruction::Instruction {
program_id: crate::WEN_TRANSFER_GUARD_ID,
accounts,
data,
Expand Down
Loading