Skip to content
Closed
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
448 changes: 447 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pinocchio-log-macro = { version = "0.5", path = "sdk/log/macro" }
pinocchio-pubkey = { version = "0.3", path = "sdk/pubkey" }
quote = "1.0"
regex = "1"
solana-address = { version = "1.0.0", features = ["decode"] }
solana-pubkey = { version = "2" }
syn = "1.0"

[workspace.metadata.cli]
Expand Down
3 changes: 2 additions & 1 deletion programs/system/src/instructions/allocate_with_seed.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
Expand Down Expand Up @@ -56,7 +57,7 @@ impl AllocateWithSeed<'_, '_, '_> {
// - [.. +32]: owner pubkey
let mut instruction_data = [0; 112];
instruction_data[0] = 9;
instruction_data[4..36].copy_from_slice(self.base.key());
instruction_data[4..36].copy_from_slice(pubkey_as_slice(self.base.key()));
instruction_data[36..44].copy_from_slice(&u64::to_le_bytes(self.seed.len() as u64));

let offset = 44 + self.seed.len();
Expand Down
3 changes: 2 additions & 1 deletion programs/system/src/instructions/assign_with_seed.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
Expand Down Expand Up @@ -51,7 +52,7 @@ impl AssignWithSeed<'_, '_, '_> {
// - [.. +32]: owner pubkey
let mut instruction_data = [0; 104];
instruction_data[0] = 10;
instruction_data[4..36].copy_from_slice(self.base.key());
instruction_data[4..36].copy_from_slice(pubkey_as_slice(self.base.key()));
instruction_data[36..44].copy_from_slice(&u64::to_le_bytes(self.seed.len() as u64));

let offset = 44 + self.seed.len();
Expand Down
3 changes: 2 additions & 1 deletion programs/system/src/instructions/authorize_nonce_account.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
Expand Down Expand Up @@ -43,7 +44,7 @@ impl AuthorizeNonceAccount<'_, '_> {
// - [4..12]: lamports
let mut instruction_data = [0; 36];
instruction_data[0] = 7;
instruction_data[4..36].copy_from_slice(self.new_authority);
instruction_data[4..36].copy_from_slice(pubkey_as_slice(self.new_authority));

let instruction = Instruction {
program_id: &crate::ID,
Expand Down
4 changes: 3 additions & 1 deletion programs/system/src/instructions/create_account_with_seed.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
Expand Down Expand Up @@ -91,7 +92,8 @@ impl<'a, 'b, 'c> CreateAccountWithSeed<'a, 'b, 'c> {
// - [.. +32]: owner pubkey
let mut instruction_data = [0; 120];
instruction_data[0] = 3;
instruction_data[4..36].copy_from_slice(self.base.unwrap_or(self.from).key());
instruction_data[4..36]
.copy_from_slice(pubkey_as_slice(self.base.unwrap_or(self.from).key()));
instruction_data[36..44].copy_from_slice(&u64::to_le_bytes(self.seed.len() as u64));

let offset = 44 + self.seed.len();
Expand Down
3 changes: 2 additions & 1 deletion programs/system/src/instructions/initialize_nonce_account.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand Down Expand Up @@ -45,7 +46,7 @@ impl InitializeNonceAccount<'_, '_> {
// - [4..36]: authority pubkey
let mut instruction_data = [0; 36];
instruction_data[0] = 6;
instruction_data[4..36].copy_from_slice(self.authority);
instruction_data[4..36].copy_from_slice(pubkey_as_slice(self.authority));

let instruction = Instruction {
program_id: &crate::ID,
Expand Down
6 changes: 3 additions & 3 deletions programs/token-2022/src/instructions/initialize_account_2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new Token Account.
///
/// ### Accounts:
Expand Down Expand Up @@ -47,7 +47,7 @@ impl InitializeAccount2<'_, '_> {
// Set discriminator as u8 at offset [0]
write_bytes(&mut instruction_data, &[16]);
// Set owner as [u8; 32] at offset [1..33]
write_bytes(&mut instruction_data[1..], self.owner);
write_bytes(&mut instruction_data[1..], pubkey_as_slice(self.owner));

let instruction = Instruction {
program_id: self.token_program,
Expand Down
6 changes: 3 additions & 3 deletions programs/token-2022/src/instructions/initialize_account_3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new Token Account.
///
/// ### Accounts:
Expand Down Expand Up @@ -43,7 +43,7 @@ impl InitializeAccount3<'_, '_> {
// Set discriminator as u8 at offset [0]
write_bytes(&mut instruction_data, &[18]);
// Set owner as [u8; 32] at offset [1..33]
write_bytes(&mut instruction_data[1..], self.owner);
write_bytes(&mut instruction_data[1..], pubkey_as_slice(self.owner));

let instruction = Instruction {
program_id: self.token_program,
Expand Down
11 changes: 7 additions & 4 deletions programs/token-2022/src/instructions/initialize_mint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new mint.
///
/// ### Accounts:
Expand Down Expand Up @@ -53,12 +53,15 @@ impl InitializeMint<'_, '_> {
// Set decimals as u8 at offset [1]
write_bytes(&mut instruction_data[1..2], &[self.decimals]);
// Set mint_authority as Pubkey at offset [2..34]
write_bytes(&mut instruction_data[2..34], self.mint_authority);
write_bytes(
&mut instruction_data[2..34],
pubkey_as_slice(self.mint_authority),
);

if let Some(freeze_auth) = self.freeze_authority {
// Set Option = `true` & freeze_authority at offset [34..67]
write_bytes(&mut instruction_data[34..35], &[1]);
write_bytes(&mut instruction_data[35..], freeze_auth);
write_bytes(&mut instruction_data[35..], pubkey_as_slice(freeze_auth));
} else {
// Set Option = `false`
write_bytes(&mut instruction_data[34..35], &[0]);
Expand Down
11 changes: 7 additions & 4 deletions programs/token-2022/src/instructions/initialize_mint_2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new mint.
///
/// ### Accounts:
Expand Down Expand Up @@ -47,12 +47,15 @@ impl InitializeMint2<'_, '_> {
// Set decimals as u8 at offset [1]
write_bytes(&mut instruction_data[1..2], &[self.decimals]);
// Set mint_authority as Pubkey at offset [2..34]
write_bytes(&mut instruction_data[2..34], self.mint_authority);
write_bytes(
&mut instruction_data[2..34],
pubkey_as_slice(self.mint_authority),
);

if let Some(freeze_auth) = self.freeze_authority {
// Set Option = `true` & freeze_authority at offset [34..67]
write_bytes(&mut instruction_data[34..35], &[1]);
write_bytes(&mut instruction_data[35..], freeze_auth);
write_bytes(&mut instruction_data[35..], pubkey_as_slice(freeze_auth));
} else {
// Set Option = `false`
write_bytes(&mut instruction_data[34..35], &[0]);
Expand Down
6 changes: 3 additions & 3 deletions programs/token-2022/src/instructions/set_authority.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

#[repr(u8)]
#[derive(Clone, Copy)]
pub enum AuthorityType {
Expand Down Expand Up @@ -67,7 +67,7 @@ impl SetAuthority<'_, '_> {
if let Some(new_authority) = self.new_authority {
// Set new_authority as [u8; 32] at offset [2..35]
write_bytes(&mut instruction_data[2..3], &[1]);
write_bytes(&mut instruction_data[3..], new_authority);
write_bytes(&mut instruction_data[3..], pubkey_as_slice(new_authority));
} else {
write_bytes(&mut instruction_data[2..3], &[0]);
// Adjust length if no new authority
Expand Down
6 changes: 3 additions & 3 deletions programs/token/src/instructions/initialize_account_2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new Token Account.
///
/// ### Accounts:
Expand Down Expand Up @@ -45,7 +45,7 @@ impl InitializeAccount2<'_> {
// Set discriminator as u8 at offset [0]
write_bytes(&mut instruction_data, &[16]);
// Set owner as [u8; 32] at offset [1..33]
write_bytes(&mut instruction_data[1..], self.owner);
write_bytes(&mut instruction_data[1..], pubkey_as_slice(self.owner));

let instruction = Instruction {
program_id: &crate::ID,
Expand Down
6 changes: 3 additions & 3 deletions programs/token/src/instructions/initialize_account_3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new Token Account.
///
/// ### Accounts:
Expand Down Expand Up @@ -41,7 +41,7 @@ impl InitializeAccount3<'_> {
// Set discriminator as u8 at offset [0]
write_bytes(&mut instruction_data, &[18]);
// Set owner as [u8; 32] at offset [1..33]
write_bytes(&mut instruction_data[1..], self.owner);
write_bytes(&mut instruction_data[1..], pubkey_as_slice(self.owner));

let instruction = Instruction {
program_id: &crate::ID,
Expand Down
11 changes: 7 additions & 4 deletions programs/token/src/instructions/initialize_mint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new mint.
///
/// ### Accounts:
Expand Down Expand Up @@ -51,12 +51,15 @@ impl InitializeMint<'_> {
// Set decimals as u8 at offset [1]
write_bytes(&mut instruction_data[1..2], &[self.decimals]);
// Set mint_authority as Pubkey at offset [2..34]
write_bytes(&mut instruction_data[2..34], self.mint_authority);
write_bytes(
&mut instruction_data[2..34],
pubkey_as_slice(self.mint_authority),
);

if let Some(freeze_auth) = self.freeze_authority {
// Set Option = `true` & freeze_authority at offset [34..67]
write_bytes(&mut instruction_data[34..35], &[1]);
write_bytes(&mut instruction_data[35..], freeze_auth);
write_bytes(&mut instruction_data[35..], pubkey_as_slice(freeze_auth));
} else {
// Set Option = `false`
write_bytes(&mut instruction_data[34..35], &[0]);
Expand Down
11 changes: 7 additions & 4 deletions programs/token/src/instructions/initialize_mint_2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
cpi::invoke,
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

/// Initialize a new mint.
///
/// ### Accounts:
Expand Down Expand Up @@ -45,12 +45,15 @@ impl InitializeMint2<'_> {
// Set decimals as u8 at offset [1]
write_bytes(&mut instruction_data[1..2], &[self.decimals]);
// Set mint_authority as Pubkey at offset [2..34]
write_bytes(&mut instruction_data[2..34], self.mint_authority);
write_bytes(
&mut instruction_data[2..34],
pubkey_as_slice(self.mint_authority),
);

if let Some(freeze_auth) = self.freeze_authority {
// Set Option = `true` & freeze_authority at offset [34..67]
write_bytes(&mut instruction_data[34..35], &[1]);
write_bytes(&mut instruction_data[35..], freeze_auth);
write_bytes(&mut instruction_data[35..], pubkey_as_slice(freeze_auth));
} else {
// Set Option = `false`
write_bytes(&mut instruction_data[34..35], &[0]);
Expand Down
6 changes: 3 additions & 3 deletions programs/token/src/instructions/set_authority.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::slice::from_raw_parts;

use crate::{write_bytes, UNINIT_BYTE};
use pinocchio::pubkey::pubkey_as_slice;
use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
Expand All @@ -8,8 +10,6 @@ use pinocchio::{
ProgramResult,
};

use crate::{write_bytes, UNINIT_BYTE};

#[repr(u8)]
#[derive(Clone, Copy)]
pub enum AuthorityType {
Expand Down Expand Up @@ -65,7 +65,7 @@ impl SetAuthority<'_> {
if let Some(new_authority) = self.new_authority {
// Set new_authority as [u8; 32] at offset [2..35]
write_bytes(&mut instruction_data[2..3], &[1]);
write_bytes(&mut instruction_data[3..], new_authority);
write_bytes(&mut instruction_data[3..], pubkey_as_slice(new_authority));
} else {
write_bytes(&mut instruction_data[2..3], &[0]);
// Adjust length if no new authority
Expand Down
6 changes: 6 additions & 0 deletions sdk/pinocchio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ unexpected_cfgs = { level = "warn", check-cfg = [

[features]
std = []
solana-address1 = ["dep:solana-address"]
solana-pubkey2 = ["dep:solana-pubkey"]

[dependencies]
solana-address = { workspace = true, optional = true }
solana-pubkey = { workspace = true, optional = true }

[dev-dependencies]
five8_const = { workspace = true }
Loading