diff --git a/Cargo.lock b/Cargo.lock index 6f85931ac4..4224408fd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3615,10 +3615,8 @@ dependencies = [ "light-compressible", "light-hasher", "light-heap", + "light-macros", "light-program-profiler", - "light-sdk", - "light-sdk-pinocchio", - "light-sdk-types", "light-system-program-anchor", "light-token-interface", "light-zero-copy", @@ -3651,7 +3649,6 @@ dependencies = [ "light-heap", "light-macros", "light-program-profiler", - "light-sdk-types", "light-zero-copy", "pinocchio", "pinocchio-pubkey", diff --git a/program-libs/compressed-account/src/address.rs b/program-libs/compressed-account/src/address.rs index fe25d24075..b860b60133 100644 --- a/program-libs/compressed-account/src/address.rs +++ b/program-libs/compressed-account/src/address.rs @@ -2,6 +2,22 @@ use light_hasher::hash_to_field_size::hashv_to_bn254_field_size_be_const_array; use crate::{CompressedAccountError, Pubkey}; +/// A seed used to derive compressed account addresses. +#[derive(Debug, PartialEq, Clone, Copy)] +pub struct AddressSeed(pub [u8; 32]); + +impl From<[u8; 32]> for AddressSeed { + fn from(value: [u8; 32]) -> Self { + AddressSeed(value) + } +} + +impl From for [u8; 32] { + fn from(address_seed: AddressSeed) -> Self { + address_seed.0 + } +} + pub fn derive_address_legacy( merkle_tree_pubkey: &Pubkey, seed: &[u8; 32], diff --git a/program-libs/compressed-account/src/constants.rs b/program-libs/compressed-account/src/constants.rs index 0a0b17b69f..adea8113e9 100644 --- a/program-libs/compressed-account/src/constants.rs +++ b/program-libs/compressed-account/src/constants.rs @@ -1,11 +1,20 @@ use light_macros::pubkey_array; +/// ID of the account-compression program. pub const ACCOUNT_COMPRESSION_PROGRAM_ID: [u8; 32] = pubkey_array!("compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq"); -pub const SYSTEM_PROGRAM_ID: [u8; 32] = +/// ID of the light-system program. +pub const LIGHT_SYSTEM_PROGRAM_ID: [u8; 32] = pubkey_array!("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7"); +#[deprecated(since = "0.9.0", note = "Use LIGHT_SYSTEM_PROGRAM_ID instead")] +pub const SYSTEM_PROGRAM_ID: [u8; 32] = LIGHT_SYSTEM_PROGRAM_ID; pub const REGISTERED_PROGRAM_PDA: [u8; 32] = pubkey_array!("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"); +pub const ACCOUNT_COMPRESSION_AUTHORITY_PDA: [u8; 32] = + pubkey_array!("HwXnGK3tPkkVY6P439H2p68AxpeuWXd5PcrAxFpbmfbA"); +/// Seed of the CPI authority. +pub const CPI_AUTHORITY_PDA_SEED: &[u8] = b"cpi_authority"; + pub const CREATE_CPI_CONTEXT_ACCOUNT: [u8; 8] = [233, 112, 71, 66, 121, 33, 178, 188]; pub const ADDRESS_MERKLE_TREE_ACCOUNT_DISCRIMINATOR: [u8; 8] = [11, 161, 175, 9, 212, 229, 73, 73]; diff --git a/program-libs/compressed-account/src/instruction_data/data.rs b/program-libs/compressed-account/src/instruction_data/data.rs index 86768f67aa..b9cc8b166a 100644 --- a/program-libs/compressed-account/src/instruction_data/data.rs +++ b/program-libs/compressed-account/src/instruction_data/data.rs @@ -172,6 +172,53 @@ impl NewAddressParamsAssignedPacked { } } +/// Packed address tree info for instruction data. +/// Contains indices to address tree accounts and root index. +#[repr(C)] +#[cfg_attr( + all(feature = "std", feature = "anchor"), + derive(anchor_lang::AnchorDeserialize, anchor_lang::AnchorSerialize) +)] +#[cfg_attr( + not(feature = "anchor"), + derive(borsh::BorshDeserialize, borsh::BorshSerialize) +)] +#[derive(Debug, Clone, Copy, PartialEq, Default, ZeroCopyMut, light_zero_copy::ZeroCopy)] +pub struct PackedAddressTreeInfo { + pub address_merkle_tree_pubkey_index: u8, + pub address_queue_pubkey_index: u8, + pub root_index: u16, +} + +impl PackedAddressTreeInfo { + pub fn into_new_address_params_packed( + self, + seed: crate::address::AddressSeed, + ) -> NewAddressParamsPacked { + NewAddressParamsPacked { + address_merkle_tree_account_index: self.address_merkle_tree_pubkey_index, + address_queue_account_index: self.address_queue_pubkey_index, + address_merkle_tree_root_index: self.root_index, + seed: seed.0, + } + } + + pub fn into_new_address_params_assigned_packed( + self, + seed: crate::address::AddressSeed, + assigned_account_index: Option, + ) -> NewAddressParamsAssignedPacked { + NewAddressParamsAssignedPacked { + address_merkle_tree_account_index: self.address_merkle_tree_pubkey_index, + address_queue_account_index: self.address_queue_pubkey_index, + address_merkle_tree_root_index: self.root_index, + seed: seed.0, + assigned_account_index: assigned_account_index.unwrap_or_default(), + assigned_to_account: assigned_account_index.is_some(), + } + } +} + #[cfg_attr( all(feature = "std", feature = "anchor"), derive(anchor_lang::AnchorDeserialize, anchor_lang::AnchorSerialize) diff --git a/program-libs/compressible/Cargo.toml b/program-libs/compressible/Cargo.toml index 70ac69c2f1..4565ac3f50 100644 --- a/program-libs/compressible/Cargo.toml +++ b/program-libs/compressible/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" [features] default = ["solana"] solana = ["dep:solana-program-error", "light-compressed-account/solana", "light-account-checks/solana", "solana-sysvar", "solana-msg"] -anchor = ["anchor-lang", "light-compressed-account/anchor", "light-compressed-account/std", "light-account-checks/solana", "light-sdk-types/anchor"] +anchor = ["anchor-lang", "light-compressed-account/anchor", "light-compressed-account/std", "light-account-checks/solana"] pinocchio = ["dep:pinocchio", "light-compressed-account/pinocchio", "light-account-checks/pinocchio"] profile-program = [] profile-heap = ["dep:light-heap"] @@ -32,7 +32,6 @@ light-program-profiler = { workspace = true } light-heap = { workspace = true, optional = true } light-account-checks = { workspace= true } light-compressed-account = { workspace= true } -light-sdk-types = { workspace = true, features = ["std"] } aligned-sized = { workspace= true } solana-sysvar = {workspace = true, optional = true} diff --git a/program-libs/compressible/src/lib.rs b/program-libs/compressible/src/lib.rs index 1edbcaaddd..4cf42f5b2d 100644 --- a/program-libs/compressible/src/lib.rs +++ b/program-libs/compressible/src/lib.rs @@ -8,8 +8,9 @@ pub mod rent; use anchor_lang::{AnchorDeserialize, AnchorSerialize}; #[cfg(not(feature = "anchor"))] use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize}; -use light_compressed_account::instruction_data::compressed_proof::ValidityProof; -use light_sdk_types::instruction::PackedAddressTreeInfo; +use light_compressed_account::instruction_data::{ + compressed_proof::ValidityProof, data::PackedAddressTreeInfo, +}; /// Proof data for instruction params when creating new compressed accounts. /// Used in the INIT flow - pass directly to instruction data. diff --git a/programs/compressed-token/program/Cargo.toml b/programs/compressed-token/program/Cargo.toml index 2d93f0a45a..ee4be14142 100644 --- a/programs/compressed-token/program/Cargo.toml +++ b/programs/compressed-token/program/Cargo.toml @@ -50,15 +50,13 @@ light-zero-copy = { workspace = true, features = ["mut", "std", "derive"] } zerocopy = { workspace = true } anchor-compressed-token = { path = "../anchor", features = ["cpi"] } light-account-checks = { workspace = true, features = ["solana", "pinocchio", "msg"] } -light-sdk = { workspace = true } borsh = { workspace = true } -light-sdk-types = { workspace = true } light-compressible = { workspace = true, features = ["pinocchio"] } +light-macros = { workspace = true } solana-pubkey = { workspace = true } arrayvec = { workspace = true } tinyvec = { workspace = true } pinocchio = { workspace = true, features = ["std"] } -light-sdk-pinocchio = { workspace = true } light-token-interface = { workspace = true, features = ["anchor"] } light-array-map = { workspace = true } pinocchio-pubkey = { workspace = true } diff --git a/programs/compressed-token/program/src/compressed_token/mint_action/actions/mint_to.rs b/programs/compressed-token/program/src/compressed_token/mint_action/actions/mint_to.rs index 997ac5e93f..dc0ff121f5 100644 --- a/programs/compressed-token/program/src/compressed_token/mint_action/actions/mint_to.rs +++ b/programs/compressed-token/program/src/compressed_token/mint_action/actions/mint_to.rs @@ -1,8 +1,9 @@ use anchor_compressed_token::ErrorCode; use anchor_lang::solana_program::program_error::ProgramError; -use light_compressed_account::Pubkey; +use light_compressed_account::{ + instruction_data::data::ZOutputCompressedAccountWithPackedContextMut, Pubkey, +}; use light_program_profiler::profile; -use light_sdk_pinocchio::instruction::ZOutputCompressedAccountWithPackedContextMut; use light_token_interface::{ hash_cache::HashCache, instructions::mint_action::ZMintToCompressedAction, state::Mint, }; diff --git a/programs/compressed-token/program/src/compressed_token/mint_action/mint_input.rs b/programs/compressed-token/program/src/compressed_token/mint_action/mint_input.rs index c350ce74df..4b4ef31689 100644 --- a/programs/compressed-token/program/src/compressed_token/mint_action/mint_input.rs +++ b/programs/compressed-token/program/src/compressed_token/mint_action/mint_input.rs @@ -1,9 +1,10 @@ use anchor_lang::solana_program::program_error::ProgramError; use borsh::BorshSerialize; -use light_compressed_account::instruction_data::with_readonly::ZInAccountMut; +use light_compressed_account::{ + compressed_account::PackedMerkleContext, instruction_data::with_readonly::ZInAccountMut, +}; use light_hasher::{sha256::Sha256BE, Hasher}; use light_program_profiler::profile; -use light_sdk::instruction::PackedMerkleContext; use light_token_interface::state::Mint; use light_zero_copy::U16; diff --git a/programs/compressed-token/program/src/compressed_token/mint_action/processor.rs b/programs/compressed-token/program/src/compressed_token/mint_action/processor.rs index dd4cebc985..a7d0031c32 100644 --- a/programs/compressed-token/program/src/compressed_token/mint_action/processor.rs +++ b/programs/compressed-token/program/src/compressed_token/mint_action/processor.rs @@ -1,7 +1,9 @@ use anchor_compressed_token::{is_idempotent_early_exit, ErrorCode}; use anchor_lang::prelude::ProgramError; -use light_compressed_account::instruction_data::with_readonly::InstructionDataInvokeCpiWithReadOnly; -use light_sdk::instruction::PackedMerkleContext; +use light_compressed_account::{ + compressed_account::PackedMerkleContext, + instruction_data::with_readonly::InstructionDataInvokeCpiWithReadOnly, +}; use light_token_interface::{ hash_cache::HashCache, instructions::mint_action::MintActionCompressedInstructionData, state::Mint, TokenError, diff --git a/programs/compressed-token/program/src/compressed_token/transfer2/compression/spl.rs b/programs/compressed-token/program/src/compressed_token/transfer2/compression/spl.rs index cc34608600..6bd098c2b4 100644 --- a/programs/compressed-token/program/src/compressed_token/transfer2/compression/spl.rs +++ b/programs/compressed-token/program/src/compressed_token/transfer2/compression/spl.rs @@ -1,8 +1,8 @@ use anchor_compressed_token::ErrorCode; use anchor_lang::prelude::ProgramError; use light_account_checks::packed_accounts::ProgramPackedAccounts; +use light_compressed_account::constants::CPI_AUTHORITY_PDA_SEED; use light_program_profiler::profile; -use light_sdk_types::CPI_AUTHORITY_PDA_SEED; use light_token_interface::{ instructions::transfer2::{ZCompression, ZCompressionMode}, is_valid_spl_interface_pda, diff --git a/programs/compressed-token/program/src/lib.rs b/programs/compressed-token/program/src/lib.rs index 1e833f0d46..d88773e4dc 100644 --- a/programs/compressed-token/program/src/lib.rs +++ b/programs/compressed-token/program/src/lib.rs @@ -1,7 +1,8 @@ use std::mem::ManuallyDrop; use anchor_lang::solana_program::program_error::ProgramError; -use light_sdk::{cpi::CpiSigner, derive_light_cpi_signer}; +use light_compressed_account::CpiSigner; +use light_macros::derive_light_cpi_signer; use light_token_interface::LIGHT_TOKEN_PROGRAM_ID; use pinocchio::{account_info::AccountInfo, msg}; diff --git a/programs/compressed-token/program/src/shared/cpi.rs b/programs/compressed-token/program/src/shared/cpi.rs index d1efec5576..9eae6fa195 100644 --- a/programs/compressed-token/program/src/shared/cpi.rs +++ b/programs/compressed-token/program/src/shared/cpi.rs @@ -1,11 +1,11 @@ use std::mem::MaybeUninit; use anchor_lang::solana_program::program_error::ProgramError; -use light_program_profiler::profile; -use light_sdk_types::{ +use light_compressed_account::constants::{ ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, CPI_AUTHORITY_PDA_SEED, LIGHT_SYSTEM_PROGRAM_ID, REGISTERED_PROGRAM_PDA, }; +use light_program_profiler::profile; use pinocchio::{ account_info::{AccountInfo, BorrowState}, cpi::{invoke_signed_unchecked, MAX_CPI_ACCOUNTS}, diff --git a/programs/compressed-token/program/src/shared/mint_to_token_pool.rs b/programs/compressed-token/program/src/shared/mint_to_token_pool.rs index 08cb00f873..d7e84e00fc 100644 --- a/programs/compressed-token/program/src/shared/mint_to_token_pool.rs +++ b/programs/compressed-token/program/src/shared/mint_to_token_pool.rs @@ -1,6 +1,6 @@ use anchor_lang::solana_program::program_error::ProgramError; +use light_compressed_account::constants::CPI_AUTHORITY_PDA_SEED; use light_program_profiler::profile; -use light_sdk_types::CPI_AUTHORITY_PDA_SEED; use pinocchio::{ account_info::AccountInfo, instruction::{AccountMeta, Instruction, Seed, Signer}, diff --git a/programs/compressed-token/program/tests/mint.rs b/programs/compressed-token/program/tests/mint.rs index 67e3cc143e..d53aec7da8 100644 --- a/programs/compressed-token/program/tests/mint.rs +++ b/programs/compressed-token/program/tests/mint.rs @@ -171,7 +171,7 @@ fn test_rnd_create_compressed_mint_account() { if parsed_instruction_data.create_mint.is_none() { let input_account = &mut cpi_instruction_struct.input_compressed_accounts[0]; - use light_sdk::instruction::PackedMerkleContext; + use light_compressed_account::compressed_account::PackedMerkleContext; let merkle_context = PackedMerkleContext { merkle_tree_pubkey_index, queue_pubkey_index, diff --git a/programs/compressed-token/program/tests/token_input.rs b/programs/compressed-token/program/tests/token_input.rs index c7bcaa36a2..706bf51fc9 100644 --- a/programs/compressed-token/program/tests/token_input.rs +++ b/programs/compressed-token/program/tests/token_input.rs @@ -3,8 +3,9 @@ use anchor_lang::prelude::*; use borsh::{BorshDeserialize, BorshSerialize}; use light_account_checks::account_info::test_account_info::pinocchio::get_account_info; use light_array_map::ArrayMap; -use light_compressed_account::instruction_data::with_readonly::{ - InAccount, InstructionDataInvokeCpiWithReadOnly, +use light_compressed_account::{ + compressed_account::PackedMerkleContext, + instruction_data::with_readonly::{InAccount, InstructionDataInvokeCpiWithReadOnly}, }; use light_compressed_token::{ constants::{ @@ -19,7 +20,6 @@ use light_compressed_token::{ token_input::set_input_compressed_account, }, }; -use light_sdk::instruction::PackedMerkleContext; use light_token_interface::{ hash_cache::HashCache, instructions::transfer2::MultiInputTokenDataWithContext, state::CompressedTokenAccountState, diff --git a/scripts/check-dependency-constraints.sh b/scripts/check-dependency-constraints.sh new file mode 100755 index 0000000000..1238aea38d --- /dev/null +++ b/scripts/check-dependency-constraints.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Check that program-libs and programs do not depend on sdk-libs crates +# This enforces the architectural constraint that program-libs and programs +# are lower-level and should not depend on higher-level sdk-libs. + +echo "Checking dependency constraints..." + +# SDK-libs crates that program-libs and programs must NOT depend on +SDK_LIBS_CRATES=( + "light-sdk" + "light-sdk-types" + "light-sdk-macros" + "light-sdk-pinocchio" + "light-token" + "light-token-types" + "light-client" + "light-program-test" + "light-event" + "light-prover-client" + "photon-api" +) + +# Crates in program-libs that should not depend on sdk-libs +PROGRAM_LIBS_CRATES=( + "light-account-checks" + "light-batched-merkle-tree" + "light-bloom-filter" + "light-compressed-account" + "light-compressible" + "light-concurrent-merkle-tree" + "light-token-interface" + "light-hash-set" + "light-hasher" + "light-indexed-merkle-tree" + "light-macros" + "light-merkle-tree-metadata" + "light-verifier" + "light-zero-copy" + "light-zero-copy-derive" + "light-heap" + "light-array-map" + "light-indexed-array" + "aligned-sized" +) + +# Programs that should not depend on sdk-libs +PROGRAM_CRATES=( + "account-compression" + "light-compressed-token" + "light-registry" + "light-system-program" +) + +check_no_sdk_deps() { + local crate="$1" + local tree_output + tree_output=$(cargo tree -p "$crate" --edges normal 2>/dev/null) + + for sdk_crate in "${SDK_LIBS_CRATES[@]}"; do + if echo "$tree_output" | grep -q " ${sdk_crate} v"; then + echo "ERROR: $crate depends on sdk-libs crate: $sdk_crate" + return 1 + fi + done + return 0 +} + +CONSTRAINT_FAILED=0 + +echo "Checking program-libs crates do not depend on sdk-libs..." +for crate in "${PROGRAM_LIBS_CRATES[@]}"; do + if ! check_no_sdk_deps "$crate"; then + CONSTRAINT_FAILED=1 + fi +done + +echo "Checking programs do not depend on sdk-libs..." +for crate in "${PROGRAM_CRATES[@]}"; do + if ! check_no_sdk_deps "$crate"; then + CONSTRAINT_FAILED=1 + fi +done + +if [ "$CONSTRAINT_FAILED" -eq 1 ]; then + echo "" + echo "FAILED: Some program-libs or programs depend on sdk-libs crates." + echo "This is not allowed. program-libs and programs must only depend on other program-libs or external crates." + exit 1 +fi + +echo "All dependency constraints satisfied." diff --git a/scripts/lint.sh b/scripts/lint.sh index 11ee8ee6db..9bc5df33f9 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -7,6 +7,9 @@ npx nx run-many --target=lint --all cargo +nightly fmt --all -- --check cargo clippy --workspace --all-features --all-targets -- -D warnings +# Check that program-libs and programs don't depend on sdk-libs +./scripts/check-dependency-constraints.sh + echo "Testing feature combinations..." # Test no-default-features for all library crates diff --git a/sdk-libs/event/src/parse.rs b/sdk-libs/event/src/parse.rs index 595edf5a46..f8e5356636 100644 --- a/sdk-libs/event/src/parse.rs +++ b/sdk-libs/event/src/parse.rs @@ -4,8 +4,8 @@ use light_compressed_account::{ CompressedAccount, CompressedAccountData, PackedCompressedAccountWithMerkleContext, }, constants::{ - ACCOUNT_COMPRESSION_PROGRAM_ID, CREATE_CPI_CONTEXT_ACCOUNT, REGISTERED_PROGRAM_PDA, - SYSTEM_PROGRAM_ID, + ACCOUNT_COMPRESSION_PROGRAM_ID, CREATE_CPI_CONTEXT_ACCOUNT, LIGHT_SYSTEM_PROGRAM_ID, + REGISTERED_PROGRAM_PDA, }, discriminators::*, instruction_data::{ @@ -253,7 +253,7 @@ fn wrap_program_ids( let discriminator: [u8; 8] = instruction[0..8].try_into().unwrap(); if program_id == &Pubkey::default() { vec.push(ProgramId::SolanaSystem); - } else if program_id == &SYSTEM_PROGRAM_ID { + } else if program_id == &LIGHT_SYSTEM_PROGRAM_ID { if discriminator == CREATE_CPI_CONTEXT_ACCOUNT { vec.push(ProgramId::Unknown); } else { diff --git a/sdk-libs/sdk-types/src/address.rs b/sdk-libs/sdk-types/src/address.rs index b0a97c6cc4..12af181cb3 100644 --- a/sdk-libs/sdk-types/src/address.rs +++ b/sdk-libs/sdk-types/src/address.rs @@ -1,17 +1,5 @@ -#[derive(Debug, PartialEq, Clone, Copy)] -pub struct AddressSeed(pub [u8; 32]); - -impl From<[u8; 32]> for AddressSeed { - fn from(value: [u8; 32]) -> Self { - AddressSeed(value) - } -} - -impl From for [u8; 32] { - fn from(address_seed: AddressSeed) -> Self { - address_seed.0 - } -} +// Re-export AddressSeed from light-compressed-account +pub use light_compressed_account::address::AddressSeed; pub type CompressedAddress = [u8; 32]; pub mod v1 { diff --git a/sdk-libs/sdk-types/src/constants.rs b/sdk-libs/sdk-types/src/constants.rs index 96c9529a0f..2a6f18f7cb 100644 --- a/sdk-libs/sdk-types/src/constants.rs +++ b/sdk-libs/sdk-types/src/constants.rs @@ -1,22 +1,13 @@ +// Re-export core constants from light-compressed-account +pub use light_compressed_account::constants::{ + ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, CPI_AUTHORITY_PDA_SEED, + LIGHT_SYSTEM_PROGRAM_ID, REGISTERED_PROGRAM_PDA, +}; use light_macros::pubkey_array; -/// ID of the account-compression program. -pub const ACCOUNT_COMPRESSION_PROGRAM_ID: [u8; 32] = - pubkey_array!("compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq"); -/// ID of the light-system program. -pub const LIGHT_SYSTEM_PROGRAM_ID: [u8; 32] = - pubkey_array!("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7"); -pub const REGISTERED_PROGRAM_PDA: [u8; 32] = - pubkey_array!("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"); -pub const ACCOUNT_COMPRESSION_AUTHORITY_PDA: [u8; 32] = - pubkey_array!("HwXnGK3tPkkVY6P439H2p68AxpeuWXd5PcrAxFpbmfbA"); - /// ID of the light-compressed-token program. pub const LIGHT_TOKEN_PROGRAM_ID: [u8; 32] = pubkey_array!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"); - -/// Seed of the CPI authority. -pub const CPI_AUTHORITY_PDA_SEED: &[u8] = b"cpi_authority"; /// Seed of the rent sponsor PDA. pub const RENT_SPONSOR_SEED: &[u8] = b"rent_sponsor"; pub const NOOP_PROGRAM_ID: [u8; 32] = pubkey_array!("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); diff --git a/sdk-libs/sdk-types/src/instruction/tree_info.rs b/sdk-libs/sdk-types/src/instruction/tree_info.rs index b4f79c1f7c..ede5bdbc62 100644 --- a/sdk-libs/sdk-types/src/instruction/tree_info.rs +++ b/sdk-libs/sdk-types/src/instruction/tree_info.rs @@ -1,10 +1,9 @@ use light_account_checks::AccountInfoTrait; -use light_compressed_account::{ - compressed_account::PackedMerkleContext, - instruction_data::data::{NewAddressParamsAssignedPacked, NewAddressParamsPacked}, -}; +use light_compressed_account::compressed_account::PackedMerkleContext; +// Re-export from light-compressed-account +pub use light_compressed_account::instruction_data::data::PackedAddressTreeInfo; -use crate::{address::AddressSeed, cpi_accounts::TreeAccounts, AnchorDeserialize, AnchorSerialize}; +use crate::{cpi_accounts::TreeAccounts, AnchorDeserialize, AnchorSerialize}; #[derive(Debug, Clone, Copy, AnchorDeserialize, AnchorSerialize, PartialEq, Default)] pub struct PackedStateTreeInfo { @@ -26,39 +25,18 @@ impl From for PackedMerkleContext { } } -#[derive(Debug, Clone, Copy, AnchorDeserialize, AnchorSerialize, PartialEq, Default)] -pub struct PackedAddressTreeInfo { - pub address_merkle_tree_pubkey_index: u8, - pub address_queue_pubkey_index: u8, - pub root_index: u16, +/// Extension trait for PackedAddressTreeInfo SDK-specific methods. +/// Since PackedAddressTreeInfo is defined in light-compressed-account, +/// we use an extension trait to add methods that depend on SDK types. +pub trait PackedAddressTreeInfoExt { + fn get_tree_pubkey( + &self, + cpi_accounts: &impl TreeAccounts, + ) -> Result; } -impl PackedAddressTreeInfo { - pub fn into_new_address_params_packed(self, seed: AddressSeed) -> NewAddressParamsPacked { - NewAddressParamsPacked { - address_merkle_tree_account_index: self.address_merkle_tree_pubkey_index, - address_queue_account_index: self.address_queue_pubkey_index, - address_merkle_tree_root_index: self.root_index, - seed: seed.0, - } - } - - pub fn into_new_address_params_assigned_packed( - self, - seed: AddressSeed, - assigned_account_index: Option, - ) -> NewAddressParamsAssignedPacked { - NewAddressParamsAssignedPacked { - address_merkle_tree_account_index: self.address_merkle_tree_pubkey_index, - address_queue_account_index: self.address_queue_pubkey_index, - address_merkle_tree_root_index: self.root_index, - seed: seed.0, - assigned_account_index: assigned_account_index.unwrap_or_default(), - assigned_to_account: assigned_account_index.is_some(), - } - } - - pub fn get_tree_pubkey( +impl PackedAddressTreeInfoExt for PackedAddressTreeInfo { + fn get_tree_pubkey( &self, cpi_accounts: &impl TreeAccounts, ) -> Result { diff --git a/sdk-libs/sdk/src/lib.rs b/sdk-libs/sdk/src/lib.rs index a04c3d4774..fce8b42a5d 100644 --- a/sdk-libs/sdk/src/lib.rs +++ b/sdk-libs/sdk/src/lib.rs @@ -183,7 +183,9 @@ pub mod sdk_types { #[cfg(feature = "cpi-context")] pub use light_sdk_types::cpi_context_write::CpiContextWriteAccounts; pub use light_sdk_types::{ - cpi_accounts::CpiAccountsConfig, instruction::PackedAddressTreeInfo, RentSponsor, + cpi_accounts::CpiAccountsConfig, + instruction::{PackedAddressTreeInfo, PackedAddressTreeInfoExt}, + RentSponsor, }; } @@ -207,7 +209,7 @@ pub use light_sdk_macros::{ derive_light_rent_sponsor, derive_light_rent_sponsor_pda, LightDiscriminator, LightHasher, LightHasherSha, }; -pub use light_sdk_types::{constants, CpiSigner}; +pub use light_sdk_types::{constants, instruction::PackedAddressTreeInfoExt, CpiSigner}; use solana_account_info::AccountInfo; use solana_cpi::invoke_signed; use solana_instruction::{AccountMeta, Instruction}; 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 744ef63a26..db55f7f9da 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 @@ -15,7 +15,7 @@ use light_sdk::{ derive_light_cpi_signer, instruction::{ account_meta::{CompressedAccountMeta, CompressedAccountMetaBurn}, - PackedAddressTreeInfo, ValidityProof, + PackedAddressTreeInfo, PackedAddressTreeInfoExt, ValidityProof, }, LightDiscriminator, LightHasher, diff --git a/sdk-tests/sdk-native-test/src/create_pda.rs b/sdk-tests/sdk-native-test/src/create_pda.rs index 493517f39d..cc4976a4da 100644 --- a/sdk-tests/sdk-native-test/src/create_pda.rs +++ b/sdk-tests/sdk-native-test/src/create_pda.rs @@ -6,7 +6,7 @@ use light_sdk::{ LightCpiInstruction, }, error::LightSdkError, - instruction::{PackedAddressTreeInfo, ValidityProof}, + instruction::{PackedAddressTreeInfo, PackedAddressTreeInfoExt, ValidityProof}, light_hasher::hash_to_field_size::hashv_to_bn254_field_size_be_const_array, LightDiscriminator, }; 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 b80294cb1f..89bb2647a6 100644 --- a/sdk-tests/sdk-pinocchio-v1-test/src/create_pda.rs +++ b/sdk-tests/sdk-pinocchio-v1-test/src/create_pda.rs @@ -5,7 +5,7 @@ use light_sdk_pinocchio::{ InvokeLightSystemProgram, LightCpiInstruction, }, error::LightSdkError, - instruction::{PackedAddressTreeInfo, ValidityProof}, + instruction::{PackedAddressTreeInfo, PackedAddressTreeInfoExt, ValidityProof}, LightAccount, LightDiscriminator, LightHasher, }; use pinocchio::account_info::AccountInfo; diff --git a/sdk-tests/sdk-token-test/src/lib.rs b/sdk-tests/sdk-token-test/src/lib.rs index 9d5cac59bb..9124c500e6 100644 --- a/sdk-tests/sdk-token-test/src/lib.rs +++ b/sdk-tests/sdk-token-test/src/lib.rs @@ -3,7 +3,10 @@ #![allow(deprecated)] use anchor_lang::prelude::*; -use light_sdk::instruction::{PackedAddressTreeInfo, ValidityProof as LightValidityProof}; +use light_sdk::{ + instruction::{PackedAddressTreeInfo, ValidityProof as LightValidityProof}, + PackedAddressTreeInfoExt, +}; use light_token::{ compressed_token::{batch_compress::Recipient, TokenAccountMeta}, ValidityProof, 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 e215703b5b..e7e3a5fa94 100644 --- a/sdk-tests/sdk-v1-native-test/src/create_pda.rs +++ b/sdk-tests/sdk-v1-native-test/src/create_pda.rs @@ -6,7 +6,7 @@ use light_sdk::{ CpiAccountsConfig, InvokeLightSystemProgram, LightCpiInstruction, }, error::LightSdkError, - instruction::{PackedAddressTreeInfo, ValidityProof}, + instruction::{PackedAddressTreeInfo, PackedAddressTreeInfoExt, ValidityProof}, LightDiscriminator, LightHasher, }; use solana_program::{account_info::AccountInfo, msg};