From a2971a1f493423ef5efbf282ee5717f3e584372f Mon Sep 17 00:00:00 2001 From: ananas Date: Thu, 23 Oct 2025 19:43:10 +0100 Subject: [PATCH 1/4] refactor: expose keccak feature --- program-libs/compressed-account/Cargo.toml | 2 ++ sdk-libs/sdk/Cargo.toml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/program-libs/compressed-account/Cargo.toml b/program-libs/compressed-account/Cargo.toml index 167f8d81c0..42454644c1 100644 --- a/program-libs/compressed-account/Cargo.toml +++ b/program-libs/compressed-account/Cargo.toml @@ -18,6 +18,8 @@ new-unique = ["dep:solana-pubkey"] profile-program = [] profile-heap = ["dep:light-heap"] poseidon = ["dep:light-poseidon", "light-hasher/poseidon"] +keccak = ["light-hasher/keccak"] +sha256 = ["light-hasher/sha256"] [dependencies] thiserror = { workspace = true } diff --git a/sdk-libs/sdk/Cargo.toml b/sdk-libs/sdk/Cargo.toml index 2e8d915b79..216f189f48 100644 --- a/sdk-libs/sdk/Cargo.toml +++ b/sdk-libs/sdk/Cargo.toml @@ -22,6 +22,8 @@ v2 = ["light-sdk-types/v2"] cpi-context = ["light-sdk-types/cpi-context"] devnet = [] poseidon = ["light-hasher/poseidon", "light-compressed-account/poseidon"] +keccak = ["light-hasher/keccak", "light-compressed-account/keccak"] +sha256 = ["light-hasher/sha256", "light-compressed-account/sha256"] merkle-tree = ["light-concurrent-merkle-tree/solana"] From d513830869940b69ef294514e1f2f8c04b8ad171 Mon Sep 17 00:00:00 2001 From: ananas Date: Thu, 23 Oct 2025 22:12:22 +0100 Subject: [PATCH 2/4] chore: add get_random_state_tree_info_v1 --- sdk-libs/client/src/rpc/client.rs | 13 +++++++++++++ sdk-libs/client/src/rpc/rpc_trait.rs | 5 +++++ sdk-libs/program-test/src/program_test/rpc.rs | 13 +++++++++++++ 3 files changed, 31 insertions(+) diff --git a/sdk-libs/client/src/rpc/client.rs b/sdk-libs/client/src/rpc/client.rs index 8944b03b5a..30ff8491a5 100644 --- a/sdk-libs/client/src/rpc/client.rs +++ b/sdk-libs/client/src/rpc/client.rs @@ -769,6 +769,19 @@ impl Rpc for LightClient { select_state_tree_info(&mut rng, &self.state_merkle_trees) } + /// Gets a random v1 state tree. + /// State trees are cached and have to be fetched or set. + fn get_random_state_tree_info_v1(&self) -> Result { + let mut rng = rand::thread_rng(); + let v1_trees: Vec = self + .state_merkle_trees + .iter() + .filter(|tree| tree.tree_type == TreeType::StateV1) + .copied() + .collect(); + select_state_tree_info(&mut rng, &v1_trees) + } + fn get_address_tree_v1(&self) -> TreeInfo { TreeInfo { tree: pubkey!("amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2"), diff --git a/sdk-libs/client/src/rpc/rpc_trait.rs b/sdk-libs/client/src/rpc/rpc_trait.rs index e156c98dde..4ae20a7303 100644 --- a/sdk-libs/client/src/rpc/rpc_trait.rs +++ b/sdk-libs/client/src/rpc/rpc_trait.rs @@ -202,8 +202,13 @@ pub trait Rpc: Send + Sync + Debug + 'static { /// Gets a random state tree info. /// State trees are cached and have to be fetched or set. + /// Returns v1 state trees by default, v2 state trees when v2 feature is enabled. fn get_random_state_tree_info(&self) -> Result; + /// Gets a random v1 state tree info. + /// State trees are cached and have to be fetched or set. + fn get_random_state_tree_info_v1(&self) -> Result; + fn get_address_tree_v1(&self) -> TreeInfo; fn get_address_tree_v2(&self) -> TreeInfo; diff --git a/sdk-libs/program-test/src/program_test/rpc.rs b/sdk-libs/program-test/src/program_test/rpc.rs index b4c564e196..9a2c85b48d 100644 --- a/sdk-libs/program-test/src/program_test/rpc.rs +++ b/sdk-libs/program-test/src/program_test/rpc.rs @@ -295,6 +295,19 @@ impl Rpc for LightProgramTest { } } + /// Gets a random v1 state tree. + /// State trees are cached and have to be fetched or set. + fn get_random_state_tree_info_v1(&self) -> Result { + use rand::Rng; + let mut rng = rand::thread_rng(); + if self.test_accounts.v1_state_trees.is_empty() { + return Err(RpcError::NoStateTreesAvailable); + } + Ok(self.test_accounts.v1_state_trees + [rng.gen_range(0..self.test_accounts.v1_state_trees.len())] + .into()) + } + fn get_address_tree_v1(&self) -> TreeInfo { TreeInfo { tree: pubkey!("amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2"), From a5d67e0c83e060dee06fffaa046639d4134a65b1 Mon Sep 17 00:00:00 2001 From: ananas Date: Thu, 23 Oct 2025 22:26:42 +0100 Subject: [PATCH 3/4] fix: add MixedTreeVersions error --- sdk-libs/client/src/indexer/error.rs | 12 ++++++++++ .../program-test/src/indexer/test_indexer.rs | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/sdk-libs/client/src/indexer/error.rs b/sdk-libs/client/src/indexer/error.rs index 2a5ca31e94..b40a0e11a1 100644 --- a/sdk-libs/client/src/indexer/error.rs +++ b/sdk-libs/client/src/indexer/error.rs @@ -54,6 +54,11 @@ pub enum IndexerError { IndexerNotSyncedToSlot, #[error("Address Merkle trees cannot be packed as output Merkle trees.")] InvalidPackTreeType, + #[error("Cannot mix v1 and v2 trees in the same validity proof. State tree version: {state_version}, Address tree version: {address_version}")] + MixedTreeVersions { + state_version: String, + address_version: String, + }, } impl IndexerError { @@ -143,6 +148,13 @@ impl Clone for IndexerError { IndexerError::NotInitialized => IndexerError::NotInitialized, IndexerError::IndexerNotSyncedToSlot => IndexerError::IndexerNotSyncedToSlot, IndexerError::InvalidPackTreeType => IndexerError::InvalidPackTreeType, + IndexerError::MixedTreeVersions { + state_version, + address_version, + } => IndexerError::MixedTreeVersions { + state_version: state_version.clone(), + address_version: address_version.clone(), + }, } } } diff --git a/sdk-libs/program-test/src/indexer/test_indexer.rs b/sdk-libs/program-test/src/indexer/test_indexer.rs index 351b6265e8..985c9f2e79 100644 --- a/sdk-libs/program-test/src/indexer/test_indexer.rs +++ b/sdk-libs/program-test/src/indexer/test_indexer.rs @@ -2222,6 +2222,28 @@ impl TestIndexer { addresses, ) .await?; + + // Validate that we're not mixing v1 and v2 tree versions + match (inclusion_payload.is_some(), non_inclusion_payload.is_some()) { + (true, true) | (false, false) => { + // Both v2 or both v1 - OK, proceed + } + (false, true) => { + // v1 state trees (height 26) with v2 address trees (height 40) + return Err(IndexerError::MixedTreeVersions { + state_version: "v1 (state tree height 26)".to_string(), + address_version: "v2 (address tree height 40)".to_string(), + }); + } + (true, false) => { + // v2 state trees with v1 address trees (height 26) + return Err(IndexerError::MixedTreeVersions { + state_version: "v2 (state tree)".to_string(), + address_version: "v1 (address tree height 26)".to_string(), + }); + } + } + let json_payload = if let Some(non_inclusion_payload) = non_inclusion_payload { From db94ec2a3b0cb16dad81d82578f19da9619ffdcc Mon Sep 17 00:00:00 2001 From: ananas Date: Fri, 24 Oct 2025 00:38:50 +0100 Subject: [PATCH 4/4] refactor: LightAccount with PubkeyTrait --- sdk-libs/client/src/rpc/client.rs | 20 ++++- sdk-libs/sdk-pinocchio/src/cpi/instruction.rs | 2 +- sdk-libs/sdk-pinocchio/src/cpi/v1/invoke.rs | 2 +- sdk-libs/sdk-pinocchio/src/cpi/v2/invoke.rs | 4 +- sdk-libs/sdk/src/account.rs | 79 +++++++++---------- sdk-libs/sdk/src/cpi/instruction.rs | 4 +- sdk-libs/sdk/src/cpi/mod.rs | 2 +- sdk-libs/sdk/src/cpi/v1/invoke.rs | 4 +- sdk-libs/sdk/src/cpi/v2/invoke.rs | 8 +- sdk-libs/sdk/src/lib.rs | 39 ++++++++- .../programs/sdk-anchor-test/src/lib.rs | 17 ++-- .../programs/sdk-anchor-test/src/read_only.rs | 8 +- sdk-tests/sdk-native-test/src/create_pda.rs | 2 +- sdk-tests/sdk-native-test/src/update_pda.rs | 2 +- .../sdk-pinocchio-v1-test/src/create_pda.rs | 5 +- .../sdk-pinocchio-v1-test/src/update_pda.rs | 5 +- .../sdk-pinocchio-v2-test/src/create_pda.rs | 5 +- .../sdk-pinocchio-v2-test/src/update_pda.rs | 5 +- .../src/ctoken_pda/create_pda.rs | 7 +- .../src/pda_ctoken/create_pda.rs | 2 +- .../src/process_create_compressed_account.rs | 7 +- .../src/process_create_escrow_pda.rs | 7 +- .../src/process_four_transfer2.rs | 2 +- .../src/process_update_deposit.rs | 2 +- .../sdk-v1-native-test/src/create_pda.rs | 2 +- .../sdk-v1-native-test/src/update_pda.rs | 2 +- 26 files changed, 140 insertions(+), 104 deletions(-) diff --git a/sdk-libs/client/src/rpc/client.rs b/sdk-libs/client/src/rpc/client.rs index 30ff8491a5..95d598d494 100644 --- a/sdk-libs/client/src/rpc/client.rs +++ b/sdk-libs/client/src/rpc/client.rs @@ -764,9 +764,27 @@ impl Rpc for LightClient { /// Gets a random active state tree. /// State trees are cached and have to be fetched or set. + /// Returns v1 state trees by default, v2 state trees when v2 feature is enabled. fn get_random_state_tree_info(&self) -> Result { let mut rng = rand::thread_rng(); - select_state_tree_info(&mut rng, &self.state_merkle_trees) + + #[cfg(feature = "v2")] + let filtered_trees: Vec = self + .state_merkle_trees + .iter() + .filter(|tree| tree.tree_type == TreeType::StateV2) + .copied() + .collect(); + + #[cfg(not(feature = "v2"))] + let filtered_trees: Vec = self + .state_merkle_trees + .iter() + .filter(|tree| tree.tree_type == TreeType::StateV1) + .copied() + .collect(); + + select_state_tree_info(&mut rng, &filtered_trees) } /// Gets a random v1 state tree. diff --git a/sdk-libs/sdk-pinocchio/src/cpi/instruction.rs b/sdk-libs/sdk-pinocchio/src/cpi/instruction.rs index aa0f993683..34492dbad9 100644 --- a/sdk-libs/sdk-pinocchio/src/cpi/instruction.rs +++ b/sdk-libs/sdk-pinocchio/src/cpi/instruction.rs @@ -8,7 +8,7 @@ pub trait LightCpiInstruction: Sized { #[cfg(feature = "light-account")] fn with_light_account( self, - account: crate::LightAccount<'_, A>, + account: crate::LightAccount, ) -> Result where A: borsh::BorshSerialize diff --git a/sdk-libs/sdk-pinocchio/src/cpi/v1/invoke.rs b/sdk-libs/sdk-pinocchio/src/cpi/v1/invoke.rs index e2486b9ebc..94f6f383d0 100644 --- a/sdk-libs/sdk-pinocchio/src/cpi/v1/invoke.rs +++ b/sdk-libs/sdk-pinocchio/src/cpi/v1/invoke.rs @@ -70,7 +70,7 @@ impl LightCpiInstruction for LightSystemProgramCpi { #[cfg(feature = "light-account")] fn with_light_account( mut self, - account: crate::LightAccount<'_, A>, + account: crate::LightAccount, ) -> Result where A: crate::BorshSerialize diff --git a/sdk-libs/sdk-pinocchio/src/cpi/v2/invoke.rs b/sdk-libs/sdk-pinocchio/src/cpi/v2/invoke.rs index 2ebb9283f6..ff379526e3 100644 --- a/sdk-libs/sdk-pinocchio/src/cpi/v2/invoke.rs +++ b/sdk-libs/sdk-pinocchio/src/cpi/v2/invoke.rs @@ -27,7 +27,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithReadOnly { #[cfg(feature = "light-account")] fn with_light_account( mut self, - account: crate::LightAccount<'_, A>, + account: crate::LightAccount, ) -> Result where A: crate::BorshSerialize @@ -98,7 +98,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithAccountInfo { #[cfg(feature = "light-account")] fn with_light_account( mut self, - account: crate::LightAccount<'_, A>, + account: crate::LightAccount, ) -> Result where A: crate::BorshSerialize diff --git a/sdk-libs/sdk/src/account.rs b/sdk-libs/sdk/src/account.rs index 4ee5a7c093..8c49c28982 100644 --- a/sdk-libs/sdk/src/account.rs +++ b/sdk-libs/sdk/src/account.rs @@ -49,7 +49,7 @@ //! # let address = [0u8; 32]; //! # let output_tree_index = 0u8; //! # let owner = Pubkey::new_unique(); -//! let mut my_compressed_account = LightAccount::<'_, CounterAccount>::new_init( +//! let mut my_compressed_account = LightAccount::::new_init( //! &program_id, //! Some(address), //! output_tree_index, @@ -78,7 +78,7 @@ //! # ..Default::default() //! # }; //! # let compressed_account_data = CounterAccount::default(); -//! let mut my_compressed_account = LightAccount::<'_, CounterAccount>::new_mut( +//! let mut my_compressed_account = LightAccount::::new_mut( //! &program_id, //! &account_meta, //! compressed_account_data, @@ -109,7 +109,7 @@ //! # ..Default::default() //! # }; //! # let compressed_account_data = CounterAccount::default(); -//! let my_compressed_account = LightAccount::<'_, CounterAccount>::new_close( +//! let my_compressed_account = LightAccount::::new_close( //! &program_id, //! &account_meta, //! compressed_account_data, @@ -148,7 +148,7 @@ pub mod sha { use super::*; /// Light Account variant that uses SHA256 hashing with flat borsh serialization. /// This is the recommended account type for most use cases. - pub type LightAccount<'a, A> = super::LightAccountInner<'a, Sha256, A, true>; + pub type LightAccount = super::LightAccountInner; } /// Poseidon hashed Light Account. @@ -175,7 +175,7 @@ pub mod poseidon { /// - Poseidon hashes inputs must be less than bn254 field size (254 bits). /// hash_to_field_size methods in light hasher can be used to hash data longer than 253 bits. /// -> use the `#[hash]` attribute for fields with data types greater than 31 bytes eg Pubkeys. - pub type LightAccount<'a, A> = super::LightAccountInner<'a, Poseidon, A, false>; + pub type LightAccount = super::LightAccountInner; } #[doc(hidden)] @@ -200,12 +200,11 @@ pub mod __internal { #[doc(hidden)] #[derive(Debug, PartialEq)] pub struct LightAccountInner< - 'a, H: Hasher, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default, const HASH_FLAT: bool, > { - owner: &'a Pubkey, + owner: Pubkey, pub account: A, account_info: CompressedAccountInfo, should_remove_data: bool, @@ -215,11 +214,10 @@ pub mod __internal { } impl< - 'a, H: Hasher, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default, const HASH_FLAT: bool, - > core::ops::Deref for LightAccountInner<'a, H, A, HASH_FLAT> + > core::ops::Deref for LightAccountInner { type Target = A; @@ -229,11 +227,10 @@ pub mod __internal { } impl< - 'a, H: Hasher, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default, const HASH_FLAT: bool, - > core::ops::DerefMut for LightAccountInner<'a, H, A, HASH_FLAT> + > core::ops::DerefMut for LightAccountInner { fn deref_mut(&mut self) -> &mut Self::Target { assert!( @@ -245,14 +242,13 @@ pub mod __internal { } impl< - 'a, H: Hasher, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default, const HASH_FLAT: bool, - > LightAccountInner<'a, H, A, HASH_FLAT> + > LightAccountInner { pub fn new_init( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, address: Option<[u8; 32]>, output_state_tree_index: u8, ) -> Self { @@ -262,7 +258,7 @@ pub mod __internal { ..Default::default() }; Self { - owner, + owner: owner.to_solana_pubkey(), account: A::default(), account_info: CompressedAccountInfo { address, @@ -304,7 +300,7 @@ pub mod __internal { } pub fn owner(&self) -> &Pubkey { - self.owner + &self.owner } pub fn in_account_info(&self) -> &Option { @@ -318,13 +314,12 @@ pub mod __internal { // Specialized implementation for HASH_FLAT = false (structured hashing with DataHasher) impl< - 'a, H: Hasher, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHasher + Default, - > LightAccountInner<'a, H, A, false> + > LightAccountInner { pub fn new_mut( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &impl CompressedAccountMetaTrait, input_account: A, ) -> Result { @@ -358,7 +353,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: input_account, account_info: CompressedAccountInfo { address: input_account_meta.get_address(), @@ -372,7 +367,7 @@ pub mod __internal { } pub fn new_empty( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &impl CompressedAccountMetaTrait, ) -> Result { let input_account_info = { @@ -404,7 +399,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: A::default(), account_info: CompressedAccountInfo { address: input_account_meta.get_address(), @@ -418,7 +413,7 @@ pub mod __internal { } pub fn new_close( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &impl CompressedAccountMetaTrait, input_account: A, ) -> Result { @@ -434,7 +429,7 @@ pub mod __internal { /// For accounts that are not closed permanently the accounts address /// continues to exist in an account with discriminator and without data. pub fn new_burn( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &CompressedAccountMetaBurn, input_account: A, ) -> Result { @@ -457,7 +452,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: input_account, account_info: CompressedAccountInfo { address: input_account_meta.get_address(), @@ -485,7 +480,7 @@ pub mod __internal { /// Poseidon for `LightAccount`. The same hasher is used for both the data hash and account hash. #[cfg(feature = "v2")] pub fn new_read_only( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &CompressedAccountMetaReadOnly, input_account: A, packed_account_pubkeys: &[Pubkey], @@ -518,7 +513,7 @@ pub mod __internal { let compressed_account = CompressedAccount { address: Some(input_account_meta.address), - owner: owner.to_bytes().into(), + owner: owner.to_array().into(), data: Some(CompressedAccountData { data: vec![], // not used for hash computation data_hash: input_data_hash, // Reuse already computed hash @@ -542,7 +537,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: input_account, account_info: CompressedAccountInfo { address: Some(input_account_meta.address), @@ -621,7 +616,7 @@ pub mod __internal { let owner = if let Some(owner) = owner { owner.to_bytes().into() } else { - (*self.owner).to_bytes().into() + self.owner.to_bytes().into() }; if let Some(mut output) = self.account_info.output.clone() { @@ -661,11 +656,11 @@ pub mod __internal { } // Specialized implementation for HASH_FLAT = true (flat serialization without DataHasher) - impl<'a, H: Hasher, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default> - LightAccountInner<'a, H, A, true> + impl + LightAccountInner { pub fn new_mut( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &impl CompressedAccountMetaTrait, input_account: A, ) -> Result { @@ -706,7 +701,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: input_account, account_info: CompressedAccountInfo { address: input_account_meta.get_address(), @@ -760,7 +755,7 @@ pub mod __internal { // } pub fn new_empty( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &impl CompressedAccountMetaTrait, ) -> Result { let input_account_info = { @@ -793,7 +788,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: A::default(), account_info: CompressedAccountInfo { address: input_account_meta.get_address(), @@ -812,7 +807,7 @@ pub mod __internal { /// Closed accounts preserve the accounts address /// in a compressed account without discriminator and data. pub fn new_close( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &impl CompressedAccountMetaTrait, input_account: A, ) -> Result { @@ -824,7 +819,7 @@ pub mod __internal { /// Burns the compressed account. /// The address of an account that is burned cannot be created again. pub fn new_burn( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &CompressedAccountMetaBurn, input_account: A, ) -> Result { @@ -853,7 +848,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: input_account, account_info: CompressedAccountInfo { address: input_account_meta.get_address(), @@ -880,7 +875,7 @@ pub mod __internal { /// Uses SHA256 flat hashing with borsh serialization (HASH_FLAT = true). #[cfg(feature = "v2")] pub fn new_read_only( - owner: &'a Pubkey, + owner: &impl crate::PubkeyTrait, input_account_meta: &CompressedAccountMetaReadOnly, input_account: A, packed_account_pubkeys: &[Pubkey], @@ -918,7 +913,7 @@ pub mod __internal { let compressed_account = CompressedAccount { address: Some(input_account_meta.address), - owner: owner.to_bytes().into(), + owner: owner.to_array().into(), data: Some(CompressedAccountData { data: vec![], // not used for hash computation data_hash: input_data_hash, // Reuse already computed hash @@ -942,7 +937,7 @@ pub mod __internal { }; Ok(Self { - owner, + owner: owner.to_solana_pubkey(), account: input_account, account_info: CompressedAccountInfo { address: Some(input_account_meta.address), @@ -1021,7 +1016,7 @@ pub mod __internal { let owner = if let Some(owner) = owner { owner.to_bytes().into() } else { - (*self.owner).to_bytes().into() + self.owner.to_bytes().into() }; if let Some(mut output) = self.account_info.output.clone() { diff --git a/sdk-libs/sdk/src/cpi/instruction.rs b/sdk-libs/sdk/src/cpi/instruction.rs index c5a9d2e9e0..d284d747dd 100644 --- a/sdk-libs/sdk/src/cpi/instruction.rs +++ b/sdk-libs/sdk/src/cpi/instruction.rs @@ -26,7 +26,7 @@ pub trait LightCpiInstruction: Sized { /// # Type Parameters /// * `A` - The compressed account data type #[must_use = "with_light_account returns a new value"] - fn with_light_account(self, account: LightAccount<'_, A>) -> Result + fn with_light_account(self, account: LightAccount) -> Result where A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default; @@ -44,7 +44,7 @@ pub trait LightCpiInstruction: Sized { #[must_use = "with_light_account_poseidon returns a new value"] fn with_light_account_poseidon( self, - account: crate::account::poseidon::LightAccount<'_, A>, + account: crate::account::poseidon::LightAccount, ) -> Result where A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHasher + Default; diff --git a/sdk-libs/sdk/src/cpi/mod.rs b/sdk-libs/sdk/src/cpi/mod.rs index fc02227bc3..c5392e5946 100644 --- a/sdk-libs/sdk/src/cpi/mod.rs +++ b/sdk-libs/sdk/src/cpi/mod.rs @@ -21,7 +21,7 @@ //! ); //! let new_address_params = address_tree_info.into_new_address_params_packed(address_seed); //! -//! let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init( +//! let mut my_compressed_account = LightAccount::::new_init( //! &crate::ID, //! Some(address), //! output_tree_index, diff --git a/sdk-libs/sdk/src/cpi/v1/invoke.rs b/sdk-libs/sdk/src/cpi/v1/invoke.rs index e32c507f0e..15a492b6a6 100644 --- a/sdk-libs/sdk/src/cpi/v1/invoke.rs +++ b/sdk-libs/sdk/src/cpi/v1/invoke.rs @@ -218,7 +218,7 @@ impl LightCpiInstruction for LightSystemProgramCpi { } } - fn with_light_account(mut self, account: LightAccount<'_, A>) -> Result + fn with_light_account(mut self, account: LightAccount) -> Result where A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default, { @@ -261,7 +261,7 @@ impl LightCpiInstruction for LightSystemProgramCpi { #[cfg(feature = "poseidon")] fn with_light_account_poseidon( mut self, - account: LightAccountPoseidon<'_, A>, + account: LightAccountPoseidon, ) -> Result where A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHasher + Default, diff --git a/sdk-libs/sdk/src/cpi/v2/invoke.rs b/sdk-libs/sdk/src/cpi/v2/invoke.rs index 8991a10893..e3841fa694 100644 --- a/sdk-libs/sdk/src/cpi/v2/invoke.rs +++ b/sdk-libs/sdk/src/cpi/v2/invoke.rs @@ -41,7 +41,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithReadOnly { } } - fn with_light_account(mut self, account: LightAccount<'_, A>) -> Result + fn with_light_account(mut self, account: LightAccount) -> Result where A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default, { @@ -98,7 +98,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithReadOnly { #[cfg(feature = "poseidon")] fn with_light_account_poseidon( mut self, - account: LightAccountPoseidon<'_, A>, + account: LightAccountPoseidon, ) -> Result where A: AnchorSerialize + AnchorDeserialize + DataHasher + LightDiscriminator + Default, @@ -203,7 +203,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithAccountInfo { } } - fn with_light_account(mut self, account: LightAccount<'_, A>) -> Result + fn with_light_account(mut self, account: LightAccount) -> Result where A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + Default, { @@ -223,7 +223,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithAccountInfo { #[cfg(feature = "poseidon")] fn with_light_account_poseidon( mut self, - account: crate::account::poseidon::LightAccount<'_, A>, + account: crate::account::poseidon::LightAccount, ) -> Result where A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHasher + Default, diff --git a/sdk-libs/sdk/src/lib.rs b/sdk-libs/sdk/src/lib.rs index b5f6f577a3..a8586aba90 100644 --- a/sdk-libs/sdk/src/lib.rs +++ b/sdk-libs/sdk/src/lib.rs @@ -107,7 +107,7 @@ //! let new_address_params = address_tree_info //! .into_new_address_params_packed(address_seed); //! -//! let mut my_compressed_account = LightAccount::<'_, CounterAccount>::new_init( +//! let mut my_compressed_account = LightAccount::::new_init( //! &crate::ID, //! Some(address), //! output_tree_index, @@ -173,3 +173,40 @@ use solana_cpi::invoke_signed; use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; use solana_pubkey::Pubkey; + +pub trait PubkeyTrait { + fn to_solana_pubkey(&self) -> Pubkey; + fn to_array(&self) -> [u8; 32]; +} + +impl PubkeyTrait for [u8; 32] { + fn to_solana_pubkey(&self) -> Pubkey { + Pubkey::from(*self) + } + + fn to_array(&self) -> [u8; 32] { + *self + } +} + +#[cfg(not(feature = "anchor"))] +impl PubkeyTrait for Pubkey { + fn to_solana_pubkey(&self) -> Pubkey { + *self + } + + fn to_array(&self) -> [u8; 32] { + self.to_bytes() + } +} + +#[cfg(feature = "anchor")] +impl PubkeyTrait for anchor_lang::prelude::Pubkey { + fn to_solana_pubkey(&self) -> Pubkey { + Pubkey::from(self.to_bytes()) + } + + fn to_array(&self) -> [u8; 32] { + self.to_bytes() + } +} diff --git a/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/lib.rs b/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/lib.rs index febaaba1d9..744ef63a26 100644 --- a/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/lib.rs +++ b/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/lib.rs @@ -54,7 +54,7 @@ pub mod sdk_anchor_test { let new_address_params = address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0)); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init( + let mut my_compressed_account = LightAccount::::new_init( &crate::ID, Some(address), output_tree_index, @@ -79,7 +79,7 @@ pub mod sdk_anchor_test { account_meta: CompressedAccountMeta, nested_data: NestedData, ) -> Result<()> { - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_mut( + let mut my_compressed_account = LightAccount::::new_mut( &crate::ID, &account_meta, my_compressed_account, @@ -106,7 +106,7 @@ pub mod sdk_anchor_test { my_compressed_account: MyCompressedAccount, account_meta: CompressedAccountMeta, ) -> Result<()> { - let my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_close( + let my_compressed_account = LightAccount::::new_close( &crate::ID, &account_meta, my_compressed_account, @@ -132,7 +132,7 @@ pub mod sdk_anchor_test { account_meta: CompressedAccountMeta, ) -> Result<()> { let my_compressed_account = - LightAccount::<'_, MyCompressedAccount>::new_empty(&crate::ID, &account_meta)?; + LightAccount::::new_empty(&crate::ID, &account_meta)?; let light_cpi_accounts = CpiAccounts::new( ctx.accounts.signer.as_ref(), @@ -153,7 +153,7 @@ pub mod sdk_anchor_test { proof: ValidityProof, account_meta: CompressedAccountMetaBurn, ) -> Result<()> { - let my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_burn( + let my_compressed_account = LightAccount::::new_burn( &crate::ID, &account_meta, MyCompressedAccount::default(), @@ -205,7 +205,6 @@ pub mod sdk_anchor_test { address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0)); let mut my_compressed_account = light_sdk::account::poseidon::LightAccount::< - '_, MyCompressedAccount, >::new_init( &crate::ID, Some(address), output_tree_index @@ -252,7 +251,7 @@ pub mod sdk_anchor_test { let new_address_params = address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0)); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init( + let mut my_compressed_account = LightAccount::::new_init( &crate::ID, Some(address), output_tree_index, @@ -277,7 +276,7 @@ pub mod sdk_anchor_test { account_meta: CompressedAccountMeta, nested_data: NestedData, ) -> Result<()> { - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_mut( + let mut my_compressed_account = LightAccount::::new_mut( &crate::ID, &account_meta, my_compressed_account, @@ -303,7 +302,7 @@ pub mod sdk_anchor_test { my_compressed_account: MyCompressedAccount, account_meta: CompressedAccountMeta, ) -> Result<()> { - let my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_close( + let my_compressed_account = LightAccount::::new_close( &crate::ID, &account_meta, my_compressed_account, diff --git a/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/read_only.rs b/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/read_only.rs index e6d25cda59..6c6416550d 100644 --- a/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/read_only.rs +++ b/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/read_only.rs @@ -35,7 +35,7 @@ pub fn process_read_sha256_light_system_cpi<'info>( .tree_pubkeys() .map_err(|_| error!(ReadOnlyError::InvalidAccount))?; - let read_only_account = LightAccount::<'_, MyCompressedAccount>::new_read_only( + let read_only_account = LightAccount::::new_read_only( &crate::ID, &account_meta, my_compressed_account, @@ -69,7 +69,7 @@ pub fn process_read_poseidon_light_system_cpi<'info>( .map_err(|_| error!(ReadOnlyError::InvalidAccount))?; let read_only_account = - light_sdk::account::poseidon::LightAccount::<'_, MyCompressedAccount>::new_read_only( + light_sdk::account::poseidon::LightAccount::::new_read_only( &crate::ID, &account_meta, my_compressed_account, @@ -102,7 +102,7 @@ pub fn process_read_sha256_lowlevel<'info>( .tree_pubkeys() .map_err(|_| error!(ReadOnlyError::InvalidAccount))?; - let read_only_account = LightAccount::<'_, MyCompressedAccount>::new_read_only( + let read_only_account = LightAccount::::new_read_only( &crate::ID, &account_meta, my_compressed_account, @@ -136,7 +136,7 @@ pub fn process_read_poseidon_lowlevel<'info>( .map_err(|_| error!(ReadOnlyError::InvalidAccount))?; let read_only_account = - light_sdk::account::poseidon::LightAccount::<'_, MyCompressedAccount>::new_read_only( + light_sdk::account::poseidon::LightAccount::::new_read_only( &crate::ID, &account_meta, my_compressed_account, diff --git a/sdk-tests/sdk-native-test/src/create_pda.rs b/sdk-tests/sdk-native-test/src/create_pda.rs index 3f98e2d73d..493517f39d 100644 --- a/sdk-tests/sdk-native-test/src/create_pda.rs +++ b/sdk-tests/sdk-native-test/src/create_pda.rs @@ -60,7 +60,7 @@ pub fn create_pda( let new_address_params = address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0)); msg!("pre account"); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init( + let mut my_compressed_account = LightAccount::::new_init( &crate::ID, Some(address), instruction_data.output_merkle_tree_index, diff --git a/sdk-tests/sdk-native-test/src/update_pda.rs b/sdk-tests/sdk-native-test/src/update_pda.rs index d2078d881d..7a648a763e 100644 --- a/sdk-tests/sdk-native-test/src/update_pda.rs +++ b/sdk-tests/sdk-native-test/src/update_pda.rs @@ -23,7 +23,7 @@ pub fn update_pda( let instruction_data = UpdatePdaInstructionData::deserialize(&mut instruction_data) .map_err(|_| LightSdkError::Borsh)?; - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_mut( + let mut my_compressed_account = LightAccount::::new_mut( &crate::ID, &instruction_data.my_compressed_account.meta, MyCompressedAccount { diff --git a/sdk-tests/sdk-pinocchio-v1-test/src/create_pda.rs b/sdk-tests/sdk-pinocchio-v1-test/src/create_pda.rs index 2588617dcc..b80294cb1f 100644 --- a/sdk-tests/sdk-pinocchio-v1-test/src/create_pda.rs +++ b/sdk-tests/sdk-pinocchio-v1-test/src/create_pda.rs @@ -34,9 +34,8 @@ pub fn create_pda(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<( let new_address_params = address_tree_info.into_new_address_params_packed(address_seed); - let program_id = crate::LIGHT_CPI_SIGNER.program_id.into(); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init( - &program_id, + let mut my_compressed_account = LightAccount::::new_init( + &crate::LIGHT_CPI_SIGNER.program_id, Some(address), instruction_data.output_merkle_tree_index, ); diff --git a/sdk-tests/sdk-pinocchio-v1-test/src/update_pda.rs b/sdk-tests/sdk-pinocchio-v1-test/src/update_pda.rs index 0c844141ab..9acc3af16e 100644 --- a/sdk-tests/sdk-pinocchio-v1-test/src/update_pda.rs +++ b/sdk-tests/sdk-pinocchio-v1-test/src/update_pda.rs @@ -25,9 +25,8 @@ pub fn update_pda(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<( .map_err(|_| LightSdkError::Borsh)?; sol_log_compute_units(); - let program_id = crate::LIGHT_CPI_SIGNER.program_id.into(); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_mut( - &program_id, + let mut my_compressed_account = LightAccount::::new_mut( + &crate::LIGHT_CPI_SIGNER.program_id, &instruction_data.my_compressed_account.meta, MyCompressedAccount { data: instruction_data.my_compressed_account.data, diff --git a/sdk-tests/sdk-pinocchio-v2-test/src/create_pda.rs b/sdk-tests/sdk-pinocchio-v2-test/src/create_pda.rs index 77648edcbf..4f04ca5162 100644 --- a/sdk-tests/sdk-pinocchio-v2-test/src/create_pda.rs +++ b/sdk-tests/sdk-pinocchio-v2-test/src/create_pda.rs @@ -47,9 +47,8 @@ pub fn create_pda(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<( let new_address_params = address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0)); - let program_id = crate::LIGHT_CPI_SIGNER.program_id.into(); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init( - &program_id, + let mut my_compressed_account = LightAccount::::new_init( + &crate::LIGHT_CPI_SIGNER.program_id, Some(address), instruction_data.output_merkle_tree_index, ); diff --git a/sdk-tests/sdk-pinocchio-v2-test/src/update_pda.rs b/sdk-tests/sdk-pinocchio-v2-test/src/update_pda.rs index f0b2430172..980432d2f5 100644 --- a/sdk-tests/sdk-pinocchio-v2-test/src/update_pda.rs +++ b/sdk-tests/sdk-pinocchio-v2-test/src/update_pda.rs @@ -24,9 +24,8 @@ pub fn update_pda( let instruction_data = UpdatePdaInstructionData::deserialize(&mut instruction_data) .map_err(|_| ProgramError::BorshIoError)?; - let program_id = LIGHT_CPI_SIGNER.program_id.into(); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_mut( - &program_id, + let mut my_compressed_account = LightAccount::::new_mut( + &LIGHT_CPI_SIGNER.program_id, &instruction_data.my_compressed_account.meta, MyCompressedAccount { data: instruction_data.my_compressed_account.data, diff --git a/sdk-tests/sdk-token-test/src/ctoken_pda/create_pda.rs b/sdk-tests/sdk-token-test/src/ctoken_pda/create_pda.rs index e5df4b5184..6917c8b641 100644 --- a/sdk-tests/sdk-token-test/src/ctoken_pda/create_pda.rs +++ b/sdk-tests/sdk-token-test/src/ctoken_pda/create_pda.rs @@ -18,11 +18,8 @@ pub fn process_create_escrow_pda<'a, 'info>( mut new_address_params: light_sdk::address::NewAddressParamsAssignedPacked, cpi_accounts: CpiAccounts<'a, 'info>, ) -> Result<()> { - let mut my_compressed_account = LightAccount::<'_, CompressedEscrowPda>::new_init( - &crate::ID, - Some(address), - output_tree_index, - ); + let mut my_compressed_account = + LightAccount::::new_init(&crate::ID, Some(address), output_tree_index); my_compressed_account.amount = amount; my_compressed_account.owner = *cpi_accounts.fee_payer().key; diff --git a/sdk-tests/sdk-token-test/src/pda_ctoken/create_pda.rs b/sdk-tests/sdk-token-test/src/pda_ctoken/create_pda.rs index f996ae5047..30c05904bc 100644 --- a/sdk-tests/sdk-token-test/src/pda_ctoken/create_pda.rs +++ b/sdk-tests/sdk-token-test/src/pda_ctoken/create_pda.rs @@ -18,7 +18,7 @@ pub fn process_create_escrow_pda_with_cpi_context<'a, 'info>( cpi_accounts: &CpiAccounts<'a, 'info>, ) -> Result<()> { let mut my_compressed_account = - LightAccount::<'_, CompressedEscrowPda>::new_init(&crate::ID, Some(address), 0); + LightAccount::::new_init(&crate::ID, Some(address), 0); my_compressed_account.amount = amount; my_compressed_account.owner = *cpi_accounts.fee_payer().key; diff --git a/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs b/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs index 0f002d9055..cfc621b790 100644 --- a/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs +++ b/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs @@ -32,11 +32,8 @@ pub fn process_create_compressed_account<'a, 'info>( address: [u8; 32], new_address_params: light_sdk::address::NewAddressParamsAssignedPacked, ) -> Result<()> { - let mut my_compressed_account = LightAccount::<'_, CompressedEscrowPda>::new_init( - &crate::ID, - Some(address), - output_tree_index, - ); + let mut my_compressed_account = + LightAccount::::new_init(&crate::ID, Some(address), output_tree_index); my_compressed_account.amount = amount; my_compressed_account.owner = *cpi_accounts.fee_payer().key; diff --git a/sdk-tests/sdk-token-test/src/process_create_escrow_pda.rs b/sdk-tests/sdk-token-test/src/process_create_escrow_pda.rs index 882772f7d1..cc506c746d 100644 --- a/sdk-tests/sdk-token-test/src/process_create_escrow_pda.rs +++ b/sdk-tests/sdk-token-test/src/process_create_escrow_pda.rs @@ -22,11 +22,8 @@ pub fn process_create_escrow_pda<'info>( crate::LIGHT_CPI_SIGNER, ); - let mut my_compressed_account = LightAccount::<'_, CompressedEscrowPda>::new_init( - &crate::ID, - Some(address), - output_tree_index, - ); + let mut my_compressed_account = + LightAccount::::new_init(&crate::ID, Some(address), output_tree_index); my_compressed_account.amount = amount; my_compressed_account.owner = *cpi_accounts.fee_payer().key; diff --git a/sdk-tests/sdk-token-test/src/process_four_transfer2.rs b/sdk-tests/sdk-token-test/src/process_four_transfer2.rs index ae16cd1a14..58171bdd82 100644 --- a/sdk-tests/sdk-token-test/src/process_four_transfer2.rs +++ b/sdk-tests/sdk-token-test/src/process_four_transfer2.rs @@ -272,7 +272,7 @@ pub fn process_update_escrow_pda( deposit_amount: u64, set_context: bool, ) -> Result<()> { - let mut my_compressed_account = LightAccount::<'_, CompressedEscrowPda>::new_mut( + let mut my_compressed_account = LightAccount::::new_mut( &crate::ID, &pda_params.account_meta, CompressedEscrowPda { diff --git a/sdk-tests/sdk-token-test/src/process_update_deposit.rs b/sdk-tests/sdk-token-test/src/process_update_deposit.rs index 19e59cf231..9303d1355a 100644 --- a/sdk-tests/sdk-token-test/src/process_update_deposit.rs +++ b/sdk-tests/sdk-token-test/src/process_update_deposit.rs @@ -34,7 +34,7 @@ pub fn process_update_escrow_pda<'a, 'info>( proof: ValidityProof, deposit_amount: u64, ) -> Result<()> { - let mut my_compressed_account = LightAccount::<'_, CompressedEscrowPda>::new_mut( + let mut my_compressed_account = LightAccount::::new_mut( &crate::ID, &pda_params.account_meta, CompressedEscrowPda { diff --git a/sdk-tests/sdk-v1-native-test/src/create_pda.rs b/sdk-tests/sdk-v1-native-test/src/create_pda.rs index ece729f1f2..e215703b5b 100644 --- a/sdk-tests/sdk-v1-native-test/src/create_pda.rs +++ b/sdk-tests/sdk-v1-native-test/src/create_pda.rs @@ -42,7 +42,7 @@ pub fn create_pda( ); let new_address_params = address_tree_info.into_new_address_params_packed(address_seed); msg!("pre account"); - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init( + let mut my_compressed_account = LightAccount::::new_init( &crate::ID, Some(address), instruction_data.output_merkle_tree_index, diff --git a/sdk-tests/sdk-v1-native-test/src/update_pda.rs b/sdk-tests/sdk-v1-native-test/src/update_pda.rs index 6ef4624a35..2917920593 100644 --- a/sdk-tests/sdk-v1-native-test/src/update_pda.rs +++ b/sdk-tests/sdk-v1-native-test/src/update_pda.rs @@ -23,7 +23,7 @@ pub fn update_pda( let instruction_data = UpdatePdaInstructionData::deserialize(&mut instruction_data) .map_err(|_| LightSdkError::Borsh)?; - let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_mut( + let mut my_compressed_account = LightAccount::::new_mut( &crate::ID, &instruction_data.my_compressed_account.meta, MyCompressedAccount {