From ccec03624094667053923854c3899a3706ea2cd3 Mon Sep 17 00:00:00 2001 From: ananas Date: Thu, 8 Jan 2026 14:12:12 +0000 Subject: [PATCH] chore: migrate all programs from v1 to v2 state trees - Update light-sdk and light-sdk-types to use v2 feature flag - Change imports from v1 to v2 modules (address, cpi) - Use ADDRESS_TREE_V2 constant from light_sdk_types - Update address params to use into_new_address_params_assigned_packed - Migrate TypeScript tests to use deriveAddressV2, deriveAddressSeedV2 - Use batchAddressTree and feature flags in TS tests - Fix pinocchio CpiAccounts API (try_new_with_config -> new_with_config) Programs migrated: - basic-operations/native: create, update, close, burn, reinit - basic-operations/anchor: create, update, close, burn, reinit - counter: native, anchor, pinocchio - account-comparison, create-and-update, read-only --- .../programs/account-comparison/Cargo.toml | 4 +-- .../programs/account-comparison/src/lib.rs | 13 +++---- .../tests/test_compressed_account.rs | 8 ++--- basic-operations/anchor/burn/package.json | 2 +- .../anchor/burn/programs/burn/Cargo.toml | 4 +-- .../anchor/burn/programs/burn/src/lib.rs | 12 +++---- .../anchor/burn/programs/burn/tests/test.rs | 15 ++++---- basic-operations/anchor/burn/tests/burn.ts | 34 +++++++++--------- .../anchor/close/programs/close/Cargo.toml | 4 +-- .../anchor/close/programs/close/src/lib.rs | 12 +++---- .../anchor/close/programs/close/tests/test.rs | 15 ++++---- basic-operations/anchor/close/tests/close.ts | 34 +++++++++--------- .../anchor/create/programs/create/Cargo.toml | 4 +-- .../anchor/create/programs/create/src/lib.rs | 12 +++---- .../create/programs/create/tests/test.rs | 8 ++--- .../anchor/create/tests/create.ts | 30 ++++++++-------- .../anchor/reinit/programs/reinit/Cargo.toml | 4 +-- .../anchor/reinit/programs/reinit/src/lib.rs | 12 +++---- .../reinit/programs/reinit/tests/test.rs | 17 ++++----- .../anchor/reinit/tests/reinit.ts | 36 ++++++++++--------- .../anchor/update/programs/update/Cargo.toml | 4 +-- .../anchor/update/programs/update/src/lib.rs | 12 +++---- .../update/programs/update/tests/test.rs | 15 ++++---- .../anchor/update/tests/update.ts | 34 +++++++++--------- .../native/programs/burn/Cargo.toml | 4 +-- .../native/programs/burn/src/lib.rs | 10 +++--- .../native/programs/burn/src/test_helpers.rs | 2 +- .../native/programs/burn/tests/test.rs | 6 ++-- .../native/programs/close/Cargo.toml | 4 +-- .../native/programs/close/src/lib.rs | 10 +++--- .../native/programs/close/src/test_helpers.rs | 2 +- .../native/programs/close/tests/test.rs | 23 +++++------- .../native/programs/create/Cargo.toml | 4 +-- .../native/programs/create/src/lib.rs | 19 +++++----- .../native/programs/create/tests/test.rs | 19 +++++----- .../native/programs/reinit/Cargo.toml | 4 +-- .../native/programs/reinit/src/lib.rs | 10 +++--- .../programs/reinit/src/test_helpers.rs | 4 +-- .../native/programs/reinit/tests/test.rs | 6 ++-- .../native/programs/update/Cargo.toml | 4 +-- .../native/programs/update/src/lib.rs | 10 +++--- .../programs/update/src/test_helpers.rs | 2 +- .../native/programs/update/tests/test.rs | 6 ++-- counter/anchor/programs/counter/Cargo.toml | 4 +-- counter/anchor/programs/counter/src/lib.rs | 13 +++---- counter/anchor/programs/counter/tests/test.rs | 14 ++++---- counter/anchor/tests/test.ts | 32 +++++++++-------- counter/native/Cargo.toml | 4 +-- counter/native/src/lib.rs | 10 +++--- counter/native/tests/test.rs | 14 ++++---- counter/pinocchio/Cargo.toml | 6 ++-- counter/pinocchio/src/lib.rs | 25 ++++++------- counter/pinocchio/tests/test.rs | 16 ++++----- .../programs/create-and-update/Cargo.toml | 2 +- .../programs/create-and-update/src/lib.rs | 2 +- read-only/Cargo.toml | 2 +- read-only/src/lib.rs | 2 +- 57 files changed, 321 insertions(+), 319 deletions(-) diff --git a/account-comparison/programs/account-comparison/Cargo.toml b/account-comparison/programs/account-comparison/Cargo.toml index 4583158..bc183cc 100644 --- a/account-comparison/programs/account-comparison/Cargo.toml +++ b/account-comparison/programs/account-comparison/Cargo.toml @@ -20,8 +20,8 @@ idl-build = ["anchor-lang/idl-build"] [dependencies] anchor-lang = "0.31.1" light-hasher = { version = "5.0.0", features = ["solana"] } -light-sdk = { version = "0.17.1", features = ["anchor"] } -light-sdk-types = { version = "0.17.1", features = ["anchor"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } +light-sdk-types = { version = "0.17.1", features = ["anchor", "v2"] } [dev-dependencies] light-client = "0.17.2" diff --git a/account-comparison/programs/account-comparison/src/lib.rs b/account-comparison/programs/account-comparison/src/lib.rs index ebfe064..bcdb7fb 100644 --- a/account-comparison/programs/account-comparison/src/lib.rs +++ b/account-comparison/programs/account-comparison/src/lib.rs @@ -3,13 +3,13 @@ use anchor_lang::prelude::*; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, - cpi::{v1::CpiAccounts, CpiSigner}, + address::v2::derive_address, + cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, LightHasher, }; +use light_sdk_types::ADDRESS_TREE_V2; #[error_code] pub enum CustomError { @@ -25,7 +25,7 @@ const CPI_SIGNER: CpiSigner = #[program] pub mod account_comparison { use light_sdk::cpi::{ - v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, + v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, }; use light_sdk::error::LightSdkError; @@ -63,7 +63,7 @@ pub mod account_comparison { .get_tree_pubkey(&light_cpi_accounts) .map_err(|err| ProgramError::from(LightSdkError::from(err)))?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData.into()); } @@ -89,7 +89,8 @@ pub mod account_comparison { compressed_account.name = name; compressed_account.data = [1u8; 128]; - let new_address_params = address_tree_info.into_new_address_params_packed(address_seed); + let new_address_params = + address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0)); LightSystemProgramCpi::new_cpi(CPI_SIGNER, proof) .with_light_account(compressed_account)? diff --git a/account-comparison/programs/account-comparison/tests/test_compressed_account.rs b/account-comparison/programs/account-comparison/tests/test_compressed_account.rs index 7268e25..b4246b3 100644 --- a/account-comparison/programs/account-comparison/tests/test_compressed_account.rs +++ b/account-comparison/programs/account-comparison/tests/test_compressed_account.rs @@ -5,7 +5,7 @@ use light_program_test::{ program_test::LightProgramTest, AddressWithTree, Indexer, ProgramTestConfig, Rpc, RpcError, }; use light_sdk::{ - address::v1::derive_address, + address::v2::derive_address, instruction::{account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig}, }; use solana_sdk::{ @@ -24,7 +24,7 @@ async fn test_create_compressed_account() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let user = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let (address, _) = derive_address( &[b"account", user.pubkey().as_ref()], @@ -82,7 +82,7 @@ where { let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(account_comparison::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let rpc_result = rpc .get_validity_proof( @@ -141,7 +141,7 @@ where { let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(account_comparison::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; diff --git a/basic-operations/anchor/burn/package.json b/basic-operations/anchor/burn/package.json index a84ec82..84a4765 100644 --- a/basic-operations/anchor/burn/package.json +++ b/basic-operations/anchor/burn/package.json @@ -7,7 +7,7 @@ }, "dependencies": { "@coral-xyz/anchor": "0.31.1", - "@lightprotocol/stateless.js": "0.22.1-alpha.1", + "@lightprotocol/stateless.js": "0.22.1-alpha.7", "dotenv": "^16.5.0" }, "devDependencies": { diff --git a/basic-operations/anchor/burn/programs/burn/Cargo.toml b/basic-operations/anchor/burn/programs/burn/Cargo.toml index b1fc670..58f8a8f 100644 --- a/basic-operations/anchor/burn/programs/burn/Cargo.toml +++ b/basic-operations/anchor/burn/programs/burn/Cargo.toml @@ -19,8 +19,8 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] anchor-lang = "0.31.1" -light-sdk = { version = "0.17.1", features = ["anchor"] } -light-sdk-types = { version = "0.17.1", features = ["anchor"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } +light-sdk-types = { version = "0.17.1", features = ["anchor", "v2"] } [target.'cfg(not(target_os = "solana"))'.dependencies] solana-sdk = "2.2" diff --git a/basic-operations/anchor/burn/programs/burn/src/lib.rs b/basic-operations/anchor/burn/programs/burn/src/lib.rs index b4db4da..a2bb5fa 100644 --- a/basic-operations/anchor/burn/programs/burn/src/lib.rs +++ b/basic-operations/anchor/burn/programs/burn/src/lib.rs @@ -4,13 +4,13 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, - cpi::{v1::CpiAccounts, CpiSigner}, + address::v2::derive_address, + cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{account_meta::CompressedAccountMetaBurn, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("BJhPWQnD31mdo6739Mac1gLuSsbbwTmpgjHsW6shf6WA"); @@ -22,7 +22,7 @@ pub mod burn { use super::*; use light_sdk::cpi::{ - v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, + v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, }; /// Setup: Creates a compressed account @@ -43,7 +43,7 @@ pub mod burn { .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ErrorCode::AccountNotEnoughKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData.into()); } @@ -70,7 +70,7 @@ pub mod burn { LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof) .with_light_account(my_compressed_account)? - .with_new_addresses(&[address_tree_info.into_new_address_params_packed(address_seed)]) + .with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))]) .invoke(light_cpi_accounts)?; Ok(()) diff --git a/basic-operations/anchor/burn/programs/burn/tests/test.rs b/basic-operations/anchor/burn/programs/burn/tests/test.rs index f963de8..45a7be9 100644 --- a/basic-operations/anchor/burn/programs/burn/tests/test.rs +++ b/basic-operations/anchor/burn/programs/burn/tests/test.rs @@ -5,8 +5,9 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::instruction::{ - account_meta::CompressedAccountMetaBurn, PackedAccounts, SystemAccountMetaConfig, +use light_sdk::{ + address::v2::derive_address, + instruction::{account_meta::CompressedAccountMetaBurn, PackedAccounts, SystemAccountMetaConfig}, }; use burn::MyCompressedAccount; use solana_sdk::{ @@ -23,8 +24,8 @@ async fn test_burn() { let payer = rpc.get_payer().insecure_clone(); // Create account first - let address_tree_info = rpc.get_address_tree_v1(); - let (address, _) = light_sdk::address::v1::derive_address( + let address_tree_info = rpc.get_address_tree_v2(); + let (address, _) = derive_address( &[b"message", payer.pubkey().as_ref()], &address_tree_info.tree, &burn::ID, @@ -68,7 +69,7 @@ async fn burn_compressed_account( let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(burn::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; let rpc_result = rpc @@ -116,9 +117,9 @@ async fn create_compressed_account( ) -> Result { let config = SystemAccountMetaConfig::new(burn::ID); let mut remaining_accounts = PackedAccounts::default(); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/anchor/burn/tests/burn.ts b/basic-operations/anchor/burn/tests/burn.ts index 3735605..02787e9 100644 --- a/basic-operations/anchor/burn/tests/burn.ts +++ b/basic-operations/anchor/burn/tests/burn.ts @@ -7,18 +7,22 @@ import { CompressedAccountWithMerkleContext, confirmTx, createRpc, - defaultStaticAccountsStruct, defaultTestStateTreeAccounts, - deriveAddress, - deriveAddressSeed, - LightSystemProgram, + deriveAddressV2, + deriveAddressSeedV2, + batchAddressTree, PackedAccounts, Rpc, sleep, SystemAccountMetaConfig, + featureFlags, + VERSION, } from "@lightprotocol/stateless.js"; import * as assert from "assert"; +// Force V2 mode +(featureFlags as any).version = VERSION.V2; + const path = require("path"); const os = require("os"); require("dotenv").config(); @@ -45,21 +49,20 @@ describe("test-anchor-burn", () => { await sleep(2000); const outputStateTree = defaultTestStateTreeAccounts().merkleTree; - const addressTree = defaultTestStateTreeAccounts().addressTree; - const addressQueue = defaultTestStateTreeAccounts().addressQueue; + const addressTree = new web3.PublicKey(batchAddressTree); const messageSeed = new TextEncoder().encode("message"); - const seed = deriveAddressSeed( - [messageSeed, signer.publicKey.toBytes()], + const seed = deriveAddressSeedV2([messageSeed, signer.publicKey.toBytes()]); + const address = deriveAddressV2( + seed, + addressTree, new web3.PublicKey(burnProgram.idl.address), ); - const address = deriveAddress(seed, addressTree); // Step 1: Create compressed account with initial message const createTxId = await createCompressedAccount( rpc, addressTree, - addressQueue, address, burnProgram, outputStateTree, @@ -110,7 +113,6 @@ describe("test-anchor-burn", () => { async function createCompressedAccount( rpc: Rpc, addressTree: anchor.web3.PublicKey, - addressQueue: anchor.web3.PublicKey, address: anchor.web3.PublicKey, program: anchor.Program, outputStateTree: anchor.web3.PublicKey, @@ -122,18 +124,18 @@ async function createCompressedAccount( [ { tree: addressTree, - queue: addressQueue, + queue: addressTree, address: bn(address.toBytes()), }, ], ); const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const addressMerkleTreePubkeyIndex = remainingAccounts.insertOrGet(addressTree); - const addressQueuePubkeyIndex = remainingAccounts.insertOrGet(addressQueue); + const addressQueuePubkeyIndex = addressMerkleTreePubkeyIndex; const packedAddressTreeInfo = { rootIndex: proofRpcResult.rootIndices[0], addressMerkleTreePubkeyIndex, @@ -185,7 +187,7 @@ async function burnCompressedAccount( const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const merkleTreePubkeyIndex = remainingAccounts.insertOrGet( compressedAccount.treeInfo.tree, @@ -227,4 +229,4 @@ async function burnCompressedAccount( const sig = await rpc.sendTransaction(tx, [signer]); await confirmTx(rpc, sig); return sig; -} \ No newline at end of file +} diff --git a/basic-operations/anchor/close/programs/close/Cargo.toml b/basic-operations/anchor/close/programs/close/Cargo.toml index 82cd8e6..0074ca9 100644 --- a/basic-operations/anchor/close/programs/close/Cargo.toml +++ b/basic-operations/anchor/close/programs/close/Cargo.toml @@ -19,8 +19,8 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] anchor-lang = "0.31.1" -light-sdk = { version = "0.17.1", features = ["anchor"] } -light-sdk-types = { version = "0.17.1", features = ["anchor"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } +light-sdk-types = { version = "0.17.1", features = ["anchor", "v2"] } [target.'cfg(not(target_os = "solana"))'.dependencies] solana-sdk = "2.2" diff --git a/basic-operations/anchor/close/programs/close/src/lib.rs b/basic-operations/anchor/close/programs/close/src/lib.rs index 070edc8..6543792 100644 --- a/basic-operations/anchor/close/programs/close/src/lib.rs +++ b/basic-operations/anchor/close/programs/close/src/lib.rs @@ -4,13 +4,13 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, - cpi::{v1::CpiAccounts, CpiSigner}, + address::v2::derive_address, + cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("DzQ3za3DVCpXkXhmZVSrNchwbbSsJXmi9MBc8v5tvZuQ"); @@ -22,7 +22,7 @@ pub mod close { use super::*; use light_sdk::cpi::{ - v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, + v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, }; /// Setup: Create a compressed account @@ -43,7 +43,7 @@ pub mod close { .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ErrorCode::AccountNotEnoughKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData.into()); } @@ -70,7 +70,7 @@ pub mod close { LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof) .with_light_account(my_compressed_account)? - .with_new_addresses(&[address_tree_info.into_new_address_params_packed(address_seed)]) + .with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))]) .invoke(light_cpi_accounts)?; Ok(()) diff --git a/basic-operations/anchor/close/programs/close/tests/test.rs b/basic-operations/anchor/close/programs/close/tests/test.rs index 3a88726..13313bb 100644 --- a/basic-operations/anchor/close/programs/close/tests/test.rs +++ b/basic-operations/anchor/close/programs/close/tests/test.rs @@ -4,8 +4,9 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::instruction::{ - account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, +use light_sdk::{ + address::v2::derive_address, + instruction::{account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig}, }; use solana_sdk::{ instruction::{AccountMeta, Instruction}, @@ -20,8 +21,8 @@ async fn test_close() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); - let (address, _) = light_sdk::address::v1::derive_address( + let address_tree_info = rpc.get_address_tree_v2(); + let (address, _) = derive_address( &[b"message", payer.pubkey().as_ref()], &address_tree_info.tree, &close::ID, @@ -64,7 +65,7 @@ async fn close_compressed_account( let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(close::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; let rpc_result = rpc @@ -113,9 +114,9 @@ async fn create_compressed_account( ) -> Result { let config = SystemAccountMetaConfig::new(close::ID); let mut remaining_accounts = PackedAccounts::default(); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/anchor/close/tests/close.ts b/basic-operations/anchor/close/tests/close.ts index 768a7a4..1f91fab 100644 --- a/basic-operations/anchor/close/tests/close.ts +++ b/basic-operations/anchor/close/tests/close.ts @@ -7,18 +7,22 @@ import { CompressedAccountWithMerkleContext, confirmTx, createRpc, - defaultStaticAccountsStruct, defaultTestStateTreeAccounts, - deriveAddress, - deriveAddressSeed, - LightSystemProgram, + deriveAddressV2, + deriveAddressSeedV2, + batchAddressTree, PackedAccounts, Rpc, sleep, SystemAccountMetaConfig, + featureFlags, + VERSION, } from "@lightprotocol/stateless.js"; import * as assert from "assert"; +// Force V2 mode +(featureFlags as any).version = VERSION.V2; + const path = require("path"); const os = require("os"); require("dotenv").config(); @@ -45,20 +49,19 @@ describe("test-anchor-close", () => { await sleep(2000); const outputStateTree = defaultTestStateTreeAccounts().merkleTree; - const addressTree = defaultTestStateTreeAccounts().addressTree; - const addressQueue = defaultTestStateTreeAccounts().addressQueue; + const addressTree = new web3.PublicKey(batchAddressTree); const messageSeed = new TextEncoder().encode("message"); - const seed = deriveAddressSeed( - [messageSeed, signer.publicKey.toBytes()], + const seed = deriveAddressSeedV2([messageSeed, signer.publicKey.toBytes()]); + const address = deriveAddressV2( + seed, + addressTree, new web3.PublicKey(closeProgram.idl.address), ); - const address = deriveAddress(seed, addressTree); const createTxId = await createCompressedAccount( rpc, addressTree, - addressQueue, address, closeProgram, outputStateTree, @@ -109,7 +112,6 @@ describe("test-anchor-close", () => { async function createCompressedAccount( rpc: Rpc, addressTree: anchor.web3.PublicKey, - addressQueue: anchor.web3.PublicKey, address: anchor.web3.PublicKey, program: anchor.Program, outputStateTree: anchor.web3.PublicKey, @@ -121,18 +123,18 @@ async function createCompressedAccount( [ { tree: addressTree, - queue: addressQueue, + queue: addressTree, address: bn(address.toBytes()), }, ], ); const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const addressMerkleTreePubkeyIndex = remainingAccounts.insertOrGet(addressTree); - const addressQueuePubkeyIndex = remainingAccounts.insertOrGet(addressQueue); + const addressQueuePubkeyIndex = addressMerkleTreePubkeyIndex; const packedAddressTreeInfo = { rootIndex: proofRpcResult.rootIndices[0], addressMerkleTreePubkeyIndex, @@ -174,7 +176,7 @@ async function closeCompressedAccount( ) { const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const proofRpcResult = await rpc.getValidityProofV0( [ @@ -235,4 +237,4 @@ async function closeCompressedAccount( const sig = await rpc.sendTransaction(tx, [signer]); await confirmTx(rpc, sig); return sig; -} \ No newline at end of file +} diff --git a/basic-operations/anchor/create/programs/create/Cargo.toml b/basic-operations/anchor/create/programs/create/Cargo.toml index b19e2c7..2f350ba 100644 --- a/basic-operations/anchor/create/programs/create/Cargo.toml +++ b/basic-operations/anchor/create/programs/create/Cargo.toml @@ -19,9 +19,9 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] anchor-lang = "0.31.1" -light-sdk = { version = "0.17.1", features = ["anchor"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } light-hasher = { version = "5.0.0", features = ["solana"] } -light-sdk-types = { version = "0.17.1", features = ["anchor"] } +light-sdk-types = { version = "0.17.1", features = ["anchor", "v2"] } [target.'cfg(not(target_os = "solana"))'.dependencies] solana-sdk = "2.2" diff --git a/basic-operations/anchor/create/programs/create/src/lib.rs b/basic-operations/anchor/create/programs/create/src/lib.rs index dc08fcf..3a9ae34 100644 --- a/basic-operations/anchor/create/programs/create/src/lib.rs +++ b/basic-operations/anchor/create/programs/create/src/lib.rs @@ -4,13 +4,13 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, - cpi::{v1::CpiAccounts, CpiSigner}, + address::v2::derive_address, + cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("Hps5oaKdYWqjVZJnAxUE1uwbozwEgZZGCRA57p2wdqcS"); @@ -22,7 +22,7 @@ pub mod create { use super::*; use light_sdk::cpi::{ - v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, + v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, }; /// Creates a new compressed account @@ -43,7 +43,7 @@ pub mod create { .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ErrorCode::AccountNotEnoughKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData.into()); } @@ -70,7 +70,7 @@ pub mod create { LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof) .with_light_account(my_compressed_account)? - .with_new_addresses(&[address_tree_info.into_new_address_params_packed(address_seed)]) + .with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))]) .invoke(light_cpi_accounts)?; Ok(()) diff --git a/basic-operations/anchor/create/programs/create/tests/test.rs b/basic-operations/anchor/create/programs/create/tests/test.rs index bf8d851..dc7aaba 100644 --- a/basic-operations/anchor/create/programs/create/tests/test.rs +++ b/basic-operations/anchor/create/programs/create/tests/test.rs @@ -5,7 +5,7 @@ use light_program_test::{ program_test::LightProgramTest, AddressWithTree, Indexer, ProgramTestConfig, Rpc, RpcError, }; use light_sdk::{ - address::v1::derive_address, + address::v2::derive_address, instruction::{PackedAccounts, SystemAccountMetaConfig}, }; use create::MyCompressedAccount; @@ -20,7 +20,7 @@ async fn test_create() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let (address, _) = derive_address( &[b"message", payer.pubkey().as_ref()], @@ -52,9 +52,9 @@ async fn create_compressed_account( ) -> Result { let config = SystemAccountMetaConfig::new(create::ID); let mut remaining_accounts = PackedAccounts::default(); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/anchor/create/tests/create.ts b/basic-operations/anchor/create/tests/create.ts index 2b0900c..e449992 100644 --- a/basic-operations/anchor/create/tests/create.ts +++ b/basic-operations/anchor/create/tests/create.ts @@ -7,18 +7,22 @@ import { CompressedAccountWithMerkleContext, confirmTx, createRpc, - defaultStaticAccountsStruct, defaultTestStateTreeAccounts, - deriveAddress, - deriveAddressSeed, - LightSystemProgram, + deriveAddressV2, + deriveAddressSeedV2, + batchAddressTree, PackedAccounts, Rpc, sleep, SystemAccountMetaConfig, + featureFlags, + VERSION, } from "@lightprotocol/stateless.js"; import * as assert from "assert"; +// Force V2 mode +(featureFlags as any).version = VERSION.V2; + const path = require("path"); const os = require("os"); require("dotenv").config(); @@ -45,21 +49,20 @@ describe("test-anchor", () => { await sleep(2000); const outputStateTree = defaultTestStateTreeAccounts().merkleTree; - const addressTree = defaultTestStateTreeAccounts().addressTree; - const addressQueue = defaultTestStateTreeAccounts().addressQueue; + const addressTree = new web3.PublicKey(batchAddressTree); const messageSeed = new TextEncoder().encode("message"); - const seed = deriveAddressSeed( - [messageSeed, signer.publicKey.toBytes()], + const seed = deriveAddressSeedV2([messageSeed, signer.publicKey.toBytes()]); + const address = deriveAddressV2( + seed, + addressTree, new web3.PublicKey(program.idl.address), ); - const address = deriveAddress(seed, addressTree); // Create compressed account with message const txId = await createCompressedAccount( rpc, addressTree, - addressQueue, address, program, outputStateTree, @@ -97,7 +100,6 @@ describe("test-anchor", () => { async function createCompressedAccount( rpc: Rpc, addressTree: anchor.web3.PublicKey, - addressQueue: anchor.web3.PublicKey, address: anchor.web3.PublicKey, program: anchor.Program, outputStateTree: anchor.web3.PublicKey, @@ -109,18 +111,18 @@ async function createCompressedAccount( [ { tree: addressTree, - queue: addressQueue, + queue: addressTree, address: bn(address.toBytes()), }, ], ); const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const addressMerkleTreePubkeyIndex = remainingAccounts.insertOrGet(addressTree); - const addressQueuePubkeyIndex = remainingAccounts.insertOrGet(addressQueue); + const addressQueuePubkeyIndex = addressMerkleTreePubkeyIndex; const packedAddressTreeInfo = { rootIndex: proofRpcResult.rootIndices[0], addressMerkleTreePubkeyIndex, diff --git a/basic-operations/anchor/reinit/programs/reinit/Cargo.toml b/basic-operations/anchor/reinit/programs/reinit/Cargo.toml index 03c920b..045a992 100644 --- a/basic-operations/anchor/reinit/programs/reinit/Cargo.toml +++ b/basic-operations/anchor/reinit/programs/reinit/Cargo.toml @@ -19,8 +19,8 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] anchor-lang = "0.31.1" -light-sdk = { version = "0.17.1", features = ["anchor"] } -light-sdk-types = { version = "0.17.1", features = ["anchor"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } +light-sdk-types = { version = "0.17.1", features = ["anchor", "v2"] } [target.'cfg(not(target_os = "solana"))'.dependencies] solana-sdk = "2.2" diff --git a/basic-operations/anchor/reinit/programs/reinit/src/lib.rs b/basic-operations/anchor/reinit/programs/reinit/src/lib.rs index 90b314a..1a8a4a8 100644 --- a/basic-operations/anchor/reinit/programs/reinit/src/lib.rs +++ b/basic-operations/anchor/reinit/programs/reinit/src/lib.rs @@ -4,13 +4,13 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, - cpi::{v1::CpiAccounts, CpiSigner}, + address::v2::derive_address, + cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("DeSUZ4to3qN7mQimoTgvEnBXiBWeTqMVcMz3ynLaWx1t"); @@ -22,7 +22,7 @@ pub mod reinit { use super::*; use light_sdk::cpi::{ - v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, + v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, }; /// Setup: Create a compressed account @@ -43,7 +43,7 @@ pub mod reinit { .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ErrorCode::AccountNotEnoughKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData.into()); } @@ -70,7 +70,7 @@ pub mod reinit { LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof) .with_light_account(my_compressed_account)? - .with_new_addresses(&[address_tree_info.into_new_address_params_packed(address_seed)]) + .with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))]) .invoke(light_cpi_accounts)?; Ok(()) diff --git a/basic-operations/anchor/reinit/programs/reinit/tests/test.rs b/basic-operations/anchor/reinit/programs/reinit/tests/test.rs index 9653eba..774bba9 100644 --- a/basic-operations/anchor/reinit/programs/reinit/tests/test.rs +++ b/basic-operations/anchor/reinit/programs/reinit/tests/test.rs @@ -4,8 +4,9 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::instruction::{ - account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, +use light_sdk::{ + address::v2::derive_address, + instruction::{account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig}, }; use light_sdk::LightDiscriminator; use solana_sdk::{ @@ -21,8 +22,8 @@ async fn test_reinit() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); - let (address, _) = light_sdk::address::v1::derive_address( + let address_tree_info = rpc.get_address_tree_v2(); + let (address, _) = derive_address( &[b"message", payer.pubkey().as_ref()], &address_tree_info.tree, &reinit::ID, @@ -80,7 +81,7 @@ async fn close_compressed_account( let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(reinit::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; let rpc_result = rpc @@ -129,7 +130,7 @@ async fn reinit_compressed_account( let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(reinit::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; let rpc_result = rpc @@ -177,9 +178,9 @@ async fn create_compressed_account( ) -> Result { let config = SystemAccountMetaConfig::new(reinit::ID); let mut remaining_accounts = PackedAccounts::default(); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/anchor/reinit/tests/reinit.ts b/basic-operations/anchor/reinit/tests/reinit.ts index 9a5de89..aab5681 100644 --- a/basic-operations/anchor/reinit/tests/reinit.ts +++ b/basic-operations/anchor/reinit/tests/reinit.ts @@ -7,18 +7,22 @@ import { CompressedAccountWithMerkleContext, confirmTx, createRpc, - defaultStaticAccountsStruct, defaultTestStateTreeAccounts, - deriveAddress, - deriveAddressSeed, - LightSystemProgram, + deriveAddressV2, + deriveAddressSeedV2, + batchAddressTree, PackedAccounts, Rpc, sleep, SystemAccountMetaConfig, + featureFlags, + VERSION, } from "@lightprotocol/stateless.js"; import * as assert from "assert"; +// Force V2 mode +(featureFlags as any).version = VERSION.V2; + const path = require("path"); const os = require("os"); require("dotenv").config(); @@ -45,20 +49,19 @@ describe("test-anchor-reinit", () => { await sleep(2000); const outputStateTree = defaultTestStateTreeAccounts().merkleTree; - const addressTree = defaultTestStateTreeAccounts().addressTree; - const addressQueue = defaultTestStateTreeAccounts().addressQueue; + const addressTree = new web3.PublicKey(batchAddressTree); const messageSeed = new TextEncoder().encode("message"); - const seed = deriveAddressSeed( - [messageSeed, signer.publicKey.toBytes()], + const seed = deriveAddressSeedV2([messageSeed, signer.publicKey.toBytes()]); + const address = deriveAddressV2( + seed, + addressTree, new web3.PublicKey(reinitProgram.idl.address), ); - const address = deriveAddress(seed, addressTree); const createTxId = await createCompressedAccount( rpc, addressTree, - addressQueue, address, reinitProgram, outputStateTree, @@ -128,7 +131,6 @@ describe("test-anchor-reinit", () => { async function createCompressedAccount( rpc: Rpc, addressTree: anchor.web3.PublicKey, - addressQueue: anchor.web3.PublicKey, address: anchor.web3.PublicKey, program: anchor.Program, outputStateTree: anchor.web3.PublicKey, @@ -140,18 +142,18 @@ async function createCompressedAccount( [ { tree: addressTree, - queue: addressQueue, + queue: addressTree, address: bn(address.toBytes()), }, ], ); const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const addressMerkleTreePubkeyIndex = remainingAccounts.insertOrGet(addressTree); - const addressQueuePubkeyIndex = remainingAccounts.insertOrGet(addressQueue); + const addressQueuePubkeyIndex = addressMerkleTreePubkeyIndex; const packedAddressTreeInfo = { rootIndex: proofRpcResult.rootIndices[0], addressMerkleTreePubkeyIndex, @@ -193,7 +195,7 @@ async function closeCompressedAccount( ) { const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const proofRpcResult = await rpc.getValidityProofV0( [ @@ -265,7 +267,7 @@ async function reinitCompressedAccount( ) { const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const proofRpcResult = await rpc.getValidityProofV0( [ @@ -320,4 +322,4 @@ async function reinitCompressedAccount( const sig = await rpc.sendTransaction(tx, [signer]); await confirmTx(rpc, sig); return sig; -} \ No newline at end of file +} diff --git a/basic-operations/anchor/update/programs/update/Cargo.toml b/basic-operations/anchor/update/programs/update/Cargo.toml index cd23719..87b705f 100644 --- a/basic-operations/anchor/update/programs/update/Cargo.toml +++ b/basic-operations/anchor/update/programs/update/Cargo.toml @@ -19,8 +19,8 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] anchor-lang = "0.31.1" -light-sdk = { version = "0.17.1", features = ["anchor"] } -light-sdk-types = { version = "0.17.1", features = ["anchor"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } +light-sdk-types = { version = "0.17.1", features = ["anchor", "v2"] } [target.'cfg(not(target_os = "solana"))'.dependencies] solana-sdk = "2.2" diff --git a/basic-operations/anchor/update/programs/update/src/lib.rs b/basic-operations/anchor/update/programs/update/src/lib.rs index 51a3867..d50f6b7 100644 --- a/basic-operations/anchor/update/programs/update/src/lib.rs +++ b/basic-operations/anchor/update/programs/update/src/lib.rs @@ -4,13 +4,13 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, - cpi::{v1::CpiAccounts, CpiSigner}, + address::v2::derive_address, + cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("Cj3DxyqB7wJh511VKexsjKt7Hx1kvPvCBMrbLuL8grKc"); @@ -22,7 +22,7 @@ pub mod update { use super::*; use light_sdk::cpi::{ - v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, + v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, }; /// Setup: Creates a compressed account @@ -43,7 +43,7 @@ pub mod update { .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ErrorCode::AccountNotEnoughKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData.into()); } @@ -70,7 +70,7 @@ pub mod update { LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof) .with_light_account(my_compressed_account)? - .with_new_addresses(&[address_tree_info.into_new_address_params_packed(address_seed)]) + .with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))]) .invoke(light_cpi_accounts)?; Ok(()) diff --git a/basic-operations/anchor/update/programs/update/tests/test.rs b/basic-operations/anchor/update/programs/update/tests/test.rs index fd6032d..0bf8ebc 100644 --- a/basic-operations/anchor/update/programs/update/tests/test.rs +++ b/basic-operations/anchor/update/programs/update/tests/test.rs @@ -5,8 +5,9 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::instruction::{ - account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, +use light_sdk::{ + address::v2::derive_address, + instruction::{account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig}, }; use update::MyCompressedAccount; use solana_sdk::{ @@ -23,8 +24,8 @@ async fn test_update() { let payer = rpc.get_payer().insecure_clone(); // Create account first - let address_tree_info = rpc.get_address_tree_v1(); - let (address, _) = light_sdk::address::v1::derive_address( + let address_tree_info = rpc.get_address_tree_v2(); + let (address, _) = derive_address( &[b"message", payer.pubkey().as_ref()], &address_tree_info.tree, &update::ID, @@ -68,7 +69,7 @@ async fn update_compressed_account( let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(update::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; let rpc_result = rpc @@ -122,9 +123,9 @@ async fn create_compressed_account( ) -> Result { let config = SystemAccountMetaConfig::new(update::ID); let mut remaining_accounts = PackedAccounts::default(); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/anchor/update/tests/update.ts b/basic-operations/anchor/update/tests/update.ts index 87f1f60..9aab7f1 100644 --- a/basic-operations/anchor/update/tests/update.ts +++ b/basic-operations/anchor/update/tests/update.ts @@ -7,18 +7,22 @@ import { CompressedAccountWithMerkleContext, confirmTx, createRpc, - defaultStaticAccountsStruct, defaultTestStateTreeAccounts, - deriveAddress, - deriveAddressSeed, - LightSystemProgram, + deriveAddressV2, + deriveAddressSeedV2, + batchAddressTree, PackedAccounts, Rpc, sleep, SystemAccountMetaConfig, + featureFlags, + VERSION, } from "@lightprotocol/stateless.js"; import * as assert from "assert"; +// Force V2 mode +(featureFlags as any).version = VERSION.V2; + const path = require("path"); const os = require("os"); require("dotenv").config(); @@ -45,21 +49,20 @@ describe("test-anchor-update", () => { await sleep(2000); const outputStateTree = defaultTestStateTreeAccounts().merkleTree; - const addressTree = defaultTestStateTreeAccounts().addressTree; - const addressQueue = defaultTestStateTreeAccounts().addressQueue; + const addressTree = new web3.PublicKey(batchAddressTree); const messageSeed = new TextEncoder().encode("message"); - const seed = deriveAddressSeed( - [messageSeed, signer.publicKey.toBytes()], + const seed = deriveAddressSeedV2([messageSeed, signer.publicKey.toBytes()]); + const address = deriveAddressV2( + seed, + addressTree, new web3.PublicKey(updateProgram.idl.address), ); - const address = deriveAddress(seed, addressTree); // Step 1: Create compressed account with initial message using update program's create_account const createTxId = await createCompressedAccount( rpc, addressTree, - addressQueue, address, updateProgram, outputStateTree, @@ -113,7 +116,6 @@ describe("test-anchor-update", () => { async function createCompressedAccount( rpc: Rpc, addressTree: anchor.web3.PublicKey, - addressQueue: anchor.web3.PublicKey, address: anchor.web3.PublicKey, program: anchor.Program, outputStateTree: anchor.web3.PublicKey, @@ -125,18 +127,18 @@ async function createCompressedAccount( [ { tree: addressTree, - queue: addressQueue, + queue: addressTree, address: bn(address.toBytes()), }, ], ); const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const addressMerkleTreePubkeyIndex = remainingAccounts.insertOrGet(addressTree); - const addressQueuePubkeyIndex = remainingAccounts.insertOrGet(addressQueue); + const addressQueuePubkeyIndex = addressMerkleTreePubkeyIndex; const packedAddressTreeInfo = { rootIndex: proofRpcResult.rootIndices[0], addressMerkleTreePubkeyIndex, @@ -189,7 +191,7 @@ async function updateCompressedAccount( const systemAccountConfig = new SystemAccountMetaConfig(program.programId); let remainingAccounts = new PackedAccounts(); - remainingAccounts.addSystemAccounts(systemAccountConfig); + remainingAccounts.addSystemAccountsV2(systemAccountConfig); const merkleTreePubkeyIndex = remainingAccounts.insertOrGet( compressedAccount.treeInfo.tree, @@ -240,4 +242,4 @@ async function updateCompressedAccount( const sig = await rpc.sendTransaction(tx, [signer]); await confirmTx(rpc, sig); return sig; -} \ No newline at end of file +} diff --git a/basic-operations/native/programs/burn/Cargo.toml b/basic-operations/native/programs/burn/Cargo.toml index 13d9025..a168046 100644 --- a/basic-operations/native/programs/burn/Cargo.toml +++ b/basic-operations/native/programs/burn/Cargo.toml @@ -19,8 +19,8 @@ name = "test" required-features = ["test-helpers"] [dependencies] -light-sdk = "0.17.1" -light-sdk-types = "0.17.1" +light-sdk = { version = "0.17", features = ["v2"] } +light-sdk-types = { version = "0.17.1", features = ["v2"] } light-hasher = { version = "5.0.0", features = ["solana"] } light-macros = { version = "2.2.0", features = ["solana"] } solana-program = "2.2" diff --git a/basic-operations/native/programs/burn/src/lib.rs b/basic-operations/native/programs/burn/src/lib.rs index 24bb3fc..7a81cdf 100644 --- a/basic-operations/native/programs/burn/src/lib.rs +++ b/basic-operations/native/programs/burn/src/lib.rs @@ -7,10 +7,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_macros::pubkey; use light_sdk::{ account::sha::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, + address::v2::derive_address, cpi::{ - v1::{CpiAccounts, LightSystemProgramCpi}, + v2::{CpiAccounts, LightSystemProgramCpi}, CpiSigner, InvokeLightSystemProgram, LightCpiInstruction, }, derive_light_cpi_signer, @@ -18,6 +17,7 @@ use light_sdk::{ instruction::{account_meta::CompressedAccountMetaBurn, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; use solana_program::{ account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, }; @@ -87,7 +87,7 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ProgramError::NotEnoughAccountKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { solana_program::msg!("Invalid address tree"); return Err(LightSdkError::ProgramError(ProgramError::InvalidAccountData)); } @@ -100,7 +100,7 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light let new_address_params = instruction_data .address_tree_info - .into_new_address_params_packed(address_seed); + .into_new_address_params_assigned_packed(address_seed, Some(0)); let mut my_compressed_account = LightAccount::::new_init( &ID, diff --git a/basic-operations/native/programs/burn/src/test_helpers.rs b/basic-operations/native/programs/burn/src/test_helpers.rs index ccdb4fb..4c6996c 100644 --- a/basic-operations/native/programs/burn/src/test_helpers.rs +++ b/basic-operations/native/programs/burn/src/test_helpers.rs @@ -19,7 +19,7 @@ pub async fn create_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/native/programs/burn/tests/test.rs b/basic-operations/native/programs/burn/tests/test.rs index 05d74f5..b7cf66b 100644 --- a/basic-operations/native/programs/burn/tests/test.rs +++ b/basic-operations/native/programs/burn/tests/test.rs @@ -3,7 +3,7 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::address::v1::derive_address; +use light_sdk::address::v2::derive_address; use light_sdk::instruction::{ account_meta::CompressedAccountMetaBurn, PackedAccounts, SystemAccountMetaConfig, }; @@ -21,7 +21,7 @@ async fn test_burn() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let address_tree_pubkey = address_tree_info.tree; // Create compressed account @@ -75,7 +75,7 @@ pub async fn burn_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; diff --git a/basic-operations/native/programs/close/Cargo.toml b/basic-operations/native/programs/close/Cargo.toml index c2f5b2b..4940490 100644 --- a/basic-operations/native/programs/close/Cargo.toml +++ b/basic-operations/native/programs/close/Cargo.toml @@ -19,8 +19,8 @@ name = "test" required-features = ["test-helpers"] [dependencies] -light-sdk = "0.17.1" -light-sdk-types = "0.17.1" +light-sdk = { version = "0.17", features = ["v2"] } +light-sdk-types = { version = "0.17.1", features = ["v2"] } light-hasher = { version = "5.0.0", features = ["solana"] } light-macros = { version = "2.2.0", features = ["solana"] } solana-program = "2.2" diff --git a/basic-operations/native/programs/close/src/lib.rs b/basic-operations/native/programs/close/src/lib.rs index ba9af6a..078563d 100644 --- a/basic-operations/native/programs/close/src/lib.rs +++ b/basic-operations/native/programs/close/src/lib.rs @@ -7,10 +7,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_macros::pubkey; use light_sdk::{ account::sha::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, + address::v2::derive_address, cpi::{ - v1::{CpiAccounts, LightSystemProgramCpi}, + v2::{CpiAccounts, LightSystemProgramCpi}, CpiSigner, InvokeLightSystemProgram, LightCpiInstruction, }, derive_light_cpi_signer, @@ -18,6 +17,7 @@ use light_sdk::{ instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; use solana_program::{ account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, }; @@ -87,7 +87,7 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ProgramError::NotEnoughAccountKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { solana_program::msg!("Invalid address tree"); return Err(LightSdkError::ProgramError(ProgramError::InvalidAccountData)); } @@ -100,7 +100,7 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light let new_address_params = instruction_data .address_tree_info - .into_new_address_params_packed(address_seed); + .into_new_address_params_assigned_packed(address_seed, Some(0)); let mut my_compressed_account = LightAccount::::new_init( &ID, diff --git a/basic-operations/native/programs/close/src/test_helpers.rs b/basic-operations/native/programs/close/src/test_helpers.rs index ccdb4fb..4c6996c 100644 --- a/basic-operations/native/programs/close/src/test_helpers.rs +++ b/basic-operations/native/programs/close/src/test_helpers.rs @@ -19,7 +19,7 @@ pub async fn create_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/native/programs/close/tests/test.rs b/basic-operations/native/programs/close/tests/test.rs index 3b55389..2d5ae8b 100644 --- a/basic-operations/native/programs/close/tests/test.rs +++ b/basic-operations/native/programs/close/tests/test.rs @@ -3,7 +3,7 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::address::v1::derive_address; +use light_sdk::address::v2::derive_address; use light_sdk::instruction::{ account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, }; @@ -15,13 +15,11 @@ use solana_sdk::{ #[tokio::test] async fn test_close() { - let config = ProgramTestConfig::new(true, Some(vec![ - ("native_program_close", ID), - ])); + let config = ProgramTestConfig::new(true, Some(vec![("native_program_close", ID)])); let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let address_tree_pubkey = address_tree_info.tree; // Create compressed account @@ -75,7 +73,7 @@ pub async fn close_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; @@ -89,9 +87,10 @@ pub async fn close_compressed_account( .state_trees .unwrap(); - let current_account = - MyCompressedAccount::deserialize(&mut compressed_account.data.as_ref().unwrap().data.as_slice()) - .unwrap(); + let current_account = MyCompressedAccount::deserialize( + &mut compressed_account.data.as_ref().unwrap().data.as_slice(), + ) + .unwrap(); let meta = CompressedAccountMeta { tree_info: packed_accounts.packed_tree_infos[0], @@ -110,11 +109,7 @@ pub async fn close_compressed_account( let instruction = Instruction { program_id: ID, accounts: account_metas, - data: [ - &[InstructionType::Close as u8][..], - &inputs[..], - ] - .concat(), + data: [&[InstructionType::Close as u8][..], &inputs[..]].concat(), }; rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[payer]) diff --git a/basic-operations/native/programs/create/Cargo.toml b/basic-operations/native/programs/create/Cargo.toml index 6de6dab..a1b8f4d 100644 --- a/basic-operations/native/programs/create/Cargo.toml +++ b/basic-operations/native/programs/create/Cargo.toml @@ -15,8 +15,8 @@ test-helpers = ["dep:light-program-test", "dep:solana-sdk"] default = [] [dependencies] -light-sdk = "0.17.1" -light-sdk-types = "0.17.1" +light-sdk = { version = "0.17", features = ["v2"] } +light-sdk-types = { version = "0.17.1", features = ["v2"] } light-hasher = { version = "5.0.0", features = ["solana"] } light-macros = { version = "2.2.0", features = ["solana"] } solana-program = "2.2" diff --git a/basic-operations/native/programs/create/src/lib.rs b/basic-operations/native/programs/create/src/lib.rs index f44e6ff..547346f 100644 --- a/basic-operations/native/programs/create/src/lib.rs +++ b/basic-operations/native/programs/create/src/lib.rs @@ -7,10 +7,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_macros::pubkey; use light_sdk::{ account::sha::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, + address::v2::derive_address, cpi::{ - v1::{CpiAccounts, LightSystemProgramCpi}, + v2::{CpiAccounts, LightSystemProgramCpi}, CpiSigner, InvokeLightSystemProgram, LightCpiInstruction, }, derive_light_cpi_signer, @@ -18,6 +17,7 @@ use light_sdk::{ instruction::{PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; use solana_program::{ account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, }; @@ -45,9 +45,7 @@ impl TryFrom for InstructionType { } } -#[derive( - Debug, Default, Clone, BorshSerialize, BorshDeserialize, LightDiscriminator, -)] +#[derive(Debug, Default, Clone, BorshSerialize, BorshDeserialize, LightDiscriminator)] pub struct MyCompressedAccount { pub owner: Pubkey, pub message: String, @@ -78,9 +76,8 @@ pub fn process_instruction( match discriminator { InstructionType::Create => { - let instruction_data = - CreateInstructionData::try_from_slice(&instruction_data[1..]) - .map_err(|_| ProgramError::InvalidInstructionData)?; + let instruction_data = CreateInstructionData::try_from_slice(&instruction_data[1..]) + .map_err(|_| ProgramError::InvalidInstructionData)?; create(accounts, instruction_data) } } @@ -99,7 +96,7 @@ pub fn create( .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ProgramError::NotEnoughAccountKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { solana_program::msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData); } @@ -112,7 +109,7 @@ pub fn create( let new_address_params = instruction_data .address_tree_info - .into_new_address_params_packed(address_seed); + .into_new_address_params_assigned_packed(address_seed, Some(0)); let mut my_compressed_account = LightAccount::::new_init( &ID, diff --git a/basic-operations/native/programs/create/tests/test.rs b/basic-operations/native/programs/create/tests/test.rs index ff61132..b7bfa46 100644 --- a/basic-operations/native/programs/create/tests/test.rs +++ b/basic-operations/native/programs/create/tests/test.rs @@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_program_test::{ program_test::LightProgramTest, AddressWithTree, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::address::v1::derive_address; +use light_sdk::address::v2::derive_address; use light_sdk::instruction::{PackedAccounts, SystemAccountMetaConfig}; use native_program_create::{CreateInstructionData, InstructionType, MyCompressedAccount, ID}; use solana_sdk::{ @@ -17,7 +17,7 @@ async fn test_create() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let address_tree_pubkey = address_tree_info.tree; // Create compressed account @@ -49,9 +49,10 @@ async fn test_create() { assert_eq!(compressed_account.address.unwrap(), address); // Deserialize and verify the account data - let my_account = - MyCompressedAccount::deserialize(&mut compressed_account.data.as_ref().unwrap().data.as_slice()) - .unwrap(); + let my_account = MyCompressedAccount::deserialize( + &mut compressed_account.data.as_ref().unwrap().data.as_slice(), + ) + .unwrap(); assert_eq!(my_account.owner, payer.pubkey()); assert_eq!(my_account.message, "Hello, compressed world!"); } @@ -67,7 +68,7 @@ pub async fn create_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let rpc_result = rpc .get_validity_proof( @@ -96,11 +97,7 @@ pub async fn create_compressed_account( let instruction = Instruction { program_id: ID, accounts: account_metas, - data: [ - &[InstructionType::Create as u8][..], - &inputs[..], - ] - .concat(), + data: [&[InstructionType::Create as u8][..], &inputs[..]].concat(), }; rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[payer]) diff --git a/basic-operations/native/programs/reinit/Cargo.toml b/basic-operations/native/programs/reinit/Cargo.toml index 8620b7b..18c4366 100644 --- a/basic-operations/native/programs/reinit/Cargo.toml +++ b/basic-operations/native/programs/reinit/Cargo.toml @@ -19,8 +19,8 @@ name = "test" required-features = ["test-helpers"] [dependencies] -light-sdk = "0.17.1" -light-sdk-types = "0.17.1" +light-sdk = { version = "0.17", features = ["v2"] } +light-sdk-types = { version = "0.17.1", features = ["v2"] } light-hasher = { version = "5.0.0", features = ["solana"] } light-macros = { version = "2.2.0", features = ["solana"] } solana-program = "2.2" diff --git a/basic-operations/native/programs/reinit/src/lib.rs b/basic-operations/native/programs/reinit/src/lib.rs index da3cac0..77c3378 100644 --- a/basic-operations/native/programs/reinit/src/lib.rs +++ b/basic-operations/native/programs/reinit/src/lib.rs @@ -7,10 +7,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_macros::pubkey; use light_sdk::{ account::sha::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, + address::v2::derive_address, cpi::{ - v1::{CpiAccounts, LightSystemProgramCpi}, + v2::{CpiAccounts, LightSystemProgramCpi}, CpiSigner, InvokeLightSystemProgram, LightCpiInstruction, }, derive_light_cpi_signer, @@ -18,6 +17,7 @@ use light_sdk::{ instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; use solana_program::{ account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, }; @@ -95,7 +95,7 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ProgramError::NotEnoughAccountKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { solana_program::msg!("Invalid address tree"); return Err(LightSdkError::ProgramError(ProgramError::InvalidAccountData)); } @@ -108,7 +108,7 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light let new_address_params = instruction_data .address_tree_info - .into_new_address_params_packed(address_seed); + .into_new_address_params_assigned_packed(address_seed, Some(0)); let mut my_compressed_account = LightAccount::::new_init( &ID, diff --git a/basic-operations/native/programs/reinit/src/test_helpers.rs b/basic-operations/native/programs/reinit/src/test_helpers.rs index a52a62a..7bed302 100644 --- a/basic-operations/native/programs/reinit/src/test_helpers.rs +++ b/basic-operations/native/programs/reinit/src/test_helpers.rs @@ -20,7 +20,7 @@ pub async fn create_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let rpc_result = rpc .get_validity_proof( @@ -69,7 +69,7 @@ pub async fn close_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; diff --git a/basic-operations/native/programs/reinit/tests/test.rs b/basic-operations/native/programs/reinit/tests/test.rs index 1027035..27e7992 100644 --- a/basic-operations/native/programs/reinit/tests/test.rs +++ b/basic-operations/native/programs/reinit/tests/test.rs @@ -3,7 +3,7 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::address::v1::derive_address; +use light_sdk::address::v2::derive_address; use light_sdk::instruction::{ account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, }; @@ -22,7 +22,7 @@ async fn test_reinit() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let address_tree_pubkey = address_tree_info.tree; // Create compressed account @@ -98,7 +98,7 @@ pub async fn reinit_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; diff --git a/basic-operations/native/programs/update/Cargo.toml b/basic-operations/native/programs/update/Cargo.toml index 7f1cac4..4b079f2 100644 --- a/basic-operations/native/programs/update/Cargo.toml +++ b/basic-operations/native/programs/update/Cargo.toml @@ -19,8 +19,8 @@ name = "test" required-features = ["test-helpers"] [dependencies] -light-sdk = "0.17.1" -light-sdk-types = "0.17.1" +light-sdk = { version = "0.17", features = ["v2"] } +light-sdk-types = { version = "0.17.1", features = ["v2"] } light-hasher = { version = "5.0.0", features = ["solana"] } light-macros = { version = "2.2.0", features = ["solana"] } solana-program = "2.2" diff --git a/basic-operations/native/programs/update/src/lib.rs b/basic-operations/native/programs/update/src/lib.rs index 4e51406..d4237f2 100644 --- a/basic-operations/native/programs/update/src/lib.rs +++ b/basic-operations/native/programs/update/src/lib.rs @@ -7,10 +7,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_macros::pubkey; use light_sdk::{ account::sha::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, + address::v2::derive_address, cpi::{ - v1::{CpiAccounts, LightSystemProgramCpi}, + v2::{CpiAccounts, LightSystemProgramCpi}, CpiSigner, InvokeLightSystemProgram, LightCpiInstruction, }, derive_light_cpi_signer, @@ -18,6 +17,7 @@ use light_sdk::{ instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; use solana_program::{ account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, }; @@ -115,7 +115,7 @@ pub fn create( .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ProgramError::NotEnoughAccountKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { solana_program::msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData); } @@ -128,7 +128,7 @@ pub fn create( let new_address_params = instruction_data .address_tree_info - .into_new_address_params_packed(address_seed); + .into_new_address_params_assigned_packed(address_seed, Some(0)); let mut my_compressed_account = LightAccount::::new_init( &ID, diff --git a/basic-operations/native/programs/update/src/test_helpers.rs b/basic-operations/native/programs/update/src/test_helpers.rs index ccdb4fb..4c6996c 100644 --- a/basic-operations/native/programs/update/src/test_helpers.rs +++ b/basic-operations/native/programs/update/src/test_helpers.rs @@ -19,7 +19,7 @@ pub async fn create_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let rpc_result = rpc .get_validity_proof( diff --git a/basic-operations/native/programs/update/tests/test.rs b/basic-operations/native/programs/update/tests/test.rs index 087fd32..d8c2311 100644 --- a/basic-operations/native/programs/update/tests/test.rs +++ b/basic-operations/native/programs/update/tests/test.rs @@ -5,7 +5,7 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::address::v1::derive_address; +use light_sdk::address::v2::derive_address; use light_sdk::instruction::{ account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, }; @@ -23,7 +23,7 @@ async fn test_update() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let address_tree_pubkey = address_tree_info.tree; // Create compressed account @@ -83,7 +83,7 @@ pub async fn update_compressed_account( let system_account_meta_config = SystemAccountMetaConfig::new(ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; diff --git a/counter/anchor/programs/counter/Cargo.toml b/counter/anchor/programs/counter/Cargo.toml index 88f139c..c5c7184 100644 --- a/counter/anchor/programs/counter/Cargo.toml +++ b/counter/anchor/programs/counter/Cargo.toml @@ -20,8 +20,8 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] anchor-lang = "0.31.1" light-hasher = { version = "5.0.0", features = ["solana"] } -light-sdk = { version = "0.17.1", features = ["anchor"] } -light-sdk-types = { version = "0.17.1", features = ["anchor"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } +light-sdk-types = { version = "0.17.1", features = ["anchor", "v2"] } [dev-dependencies] light-client = "0.17.2" diff --git a/counter/anchor/programs/counter/src/lib.rs b/counter/anchor/programs/counter/src/lib.rs index 98074e1..8d3cb83 100644 --- a/counter/anchor/programs/counter/src/lib.rs +++ b/counter/anchor/programs/counter/src/lib.rs @@ -4,13 +4,13 @@ use anchor_lang::{prelude::*, AnchorDeserialize, Discriminator}; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, - cpi::{v1::CpiAccounts, CpiSigner}, + address::v2::derive_address, + cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, LightHasher, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("GRLu2hKaAiMbxpkAM1HeXzks9YeGuz18SEgXEizVvPqX"); @@ -22,7 +22,7 @@ pub mod counter { use super::*; use light_sdk::cpi::{ - v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, + v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction, }; pub fn create_counter<'info>( @@ -46,7 +46,7 @@ pub mod counter { .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ErrorCode::AccountNotEnoughKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData.into()); } @@ -57,7 +57,8 @@ pub mod counter { &crate::ID, ); - let new_address_params = address_tree_info.into_new_address_params_packed(address_seed); + let new_address_params = + address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0)); let mut counter = LightAccount::::new_init( &crate::ID, diff --git a/counter/anchor/programs/counter/tests/test.rs b/counter/anchor/programs/counter/tests/test.rs index 380e782..154381a 100644 --- a/counter/anchor/programs/counter/tests/test.rs +++ b/counter/anchor/programs/counter/tests/test.rs @@ -7,7 +7,7 @@ use light_program_test::{ program_test::LightProgramTest, AddressWithTree, Indexer, ProgramTestConfig, Rpc, RpcError, }; use light_sdk::{ - address::v1::derive_address, + address::v2::derive_address, instruction::{account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig}, }; use solana_sdk::{ @@ -21,7 +21,7 @@ async fn test_counter() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let (address, _) = derive_address( &[b"counter", payer.pubkey().as_ref()], @@ -125,7 +125,7 @@ where { let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(counter::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let rpc_result = rpc .get_validity_proof( @@ -182,7 +182,7 @@ where { let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(counter::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; @@ -243,7 +243,7 @@ where { let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(counter::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; @@ -303,7 +303,7 @@ where { let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(counter::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; @@ -363,7 +363,7 @@ where { let mut remaining_accounts = PackedAccounts::default(); let config = SystemAccountMetaConfig::new(counter::ID); - remaining_accounts.add_system_accounts(config)?; + remaining_accounts.add_system_accounts_v2(config)?; let hash = compressed_account.hash; diff --git a/counter/anchor/tests/test.ts b/counter/anchor/tests/test.ts index 74dde72..dce41ff 100644 --- a/counter/anchor/tests/test.ts +++ b/counter/anchor/tests/test.ts @@ -8,16 +8,20 @@ import { confirmTx, createRpc, defaultTestStateTreeAccounts, - deriveAddress, - deriveAddressSeed, - LightSystemProgram, + deriveAddressV2, + deriveAddressSeedV2, + batchAddressTree, PackedAccounts, Rpc, sleep, SystemAccountMetaConfig, + featureFlags, + VERSION, } from "@lightprotocol/stateless.js"; import { assert } from "chai"; +// Force V2 mode by overwriting the featureFlags +(featureFlags as any).version = VERSION.V2; const path = require("path"); const os = require("os"); require("dotenv").config(); @@ -44,20 +48,19 @@ describe("test-anchor", () => { await sleep(2000); const outputMerkleTree = defaultTestStateTreeAccounts().merkleTree; - const addressTree = defaultTestStateTreeAccounts().addressTree; - const addressQueue = defaultTestStateTreeAccounts().addressQueue; + const addressTree = new web3.PublicKey(batchAddressTree); const counterSeed = new TextEncoder().encode("counter"); - const seed = deriveAddressSeed( - [counterSeed, signer.publicKey.toBytes()], + const seed = deriveAddressSeedV2([counterSeed, signer.publicKey.toBytes()]); + const address = deriveAddressV2( + seed, + addressTree, new web3.PublicKey(program.idl.address) ); - const address = deriveAddress(seed, addressTree); // Create counter compressed account. await CreateCounterCompressedAccount( rpc, addressTree, - addressQueue, address, program, outputMerkleTree, @@ -116,7 +119,6 @@ describe("test-anchor", () => { async function CreateCounterCompressedAccount( rpc: Rpc, addressTree: anchor.web3.PublicKey, - addressQueue: anchor.web3.PublicKey, address: anchor.web3.PublicKey, program: anchor.Program, outputMerkleTree: anchor.web3.PublicKey, @@ -128,18 +130,18 @@ async function CreateCounterCompressedAccount( [ { tree: addressTree, - queue: addressQueue, + queue: addressTree, address: bn(address.toBytes()), }, ] ); const systemAccountConfig = SystemAccountMetaConfig.new(program.programId); let remainingAccounts = - PackedAccounts.newWithSystemAccounts(systemAccountConfig); + PackedAccounts.newWithSystemAccountsV2(systemAccountConfig); const addressMerkleTreePubkeyIndex = remainingAccounts.insertOrGet(addressTree); - const addressQueuePubkeyIndex = remainingAccounts.insertOrGet(addressQueue); + const addressQueuePubkeyIndex = addressMerkleTreePubkeyIndex; const packedAddreesMerkleContext = { rootIndex: proofRpcResult.rootIndices[0], addressMerkleTreePubkeyIndex, @@ -194,7 +196,7 @@ async function incrementCounterCompressedAccount( ); const systemAccountConfig = SystemAccountMetaConfig.new(program.programId); let remainingAccounts = - PackedAccounts.newWithSystemAccounts(systemAccountConfig); + PackedAccounts.newWithSystemAccountsV2(systemAccountConfig); const merkleTreePubkeyIndex = remainingAccounts.insertOrGet( counterAccount.treeInfo.tree @@ -262,7 +264,7 @@ async function deleteCounterCompressedAccount( ); const systemAccountConfig = SystemAccountMetaConfig.new(program.programId); let remainingAccounts = - PackedAccounts.newWithSystemAccounts(systemAccountConfig); + PackedAccounts.newWithSystemAccountsV2(systemAccountConfig); const merkleTreePubkeyIndex = remainingAccounts.insertOrGet( counterAccount.treeInfo.tree diff --git a/counter/native/Cargo.toml b/counter/native/Cargo.toml index 342bc84..6f8a719 100644 --- a/counter/native/Cargo.toml +++ b/counter/native/Cargo.toml @@ -19,8 +19,8 @@ test-sbf = [] default = [] [dependencies] -light-sdk = "0.17.1" -light-sdk-types = "0.17.1" +light-sdk = { version = "0.17", features = ["v2"] } +light-sdk-types = { version = "0.17.1", features = ["v2"] } light-hasher = { version = "5.0.0", features = ["solana"] } solana-program = "2.2" light-macros = "2.2.0" diff --git a/counter/native/src/lib.rs b/counter/native/src/lib.rs index 231783d..7499c62 100644 --- a/counter/native/src/lib.rs +++ b/counter/native/src/lib.rs @@ -4,10 +4,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_macros::pubkey; use light_sdk::{ account::LightAccount, - address::v1::derive_address, - constants::ADDRESS_TREE_V1, + address::v2::derive_address, cpi::{ - v1::{CpiAccounts, LightSystemProgramCpi}, + v2::{CpiAccounts, LightSystemProgramCpi}, CpiSigner, InvokeLightSystemProgram, LightCpiInstruction, }, derive_light_cpi_signer, @@ -15,6 +14,7 @@ use light_sdk::{ instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, LightHasher, }; +use light_sdk_types::ADDRESS_TREE_V2; use solana_program::{ account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, }; @@ -171,7 +171,7 @@ pub fn create_counter( .get_tree_pubkey(&light_cpi_accounts) .map_err(|_| ProgramError::NotEnoughAccountKeys)?; - if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 { + if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V2 { solana_program::msg!("Invalid address tree"); return Err(ProgramError::InvalidAccountData); } @@ -184,7 +184,7 @@ pub fn create_counter( let new_address_params = instuction_data .address_tree_info - .into_new_address_params_packed(address_seed); + .into_new_address_params_assigned_packed(address_seed, Some(0)); let mut counter = LightAccount::::new_init( &ID, diff --git a/counter/native/tests/test.rs b/counter/native/tests/test.rs index 0bf8c38..92bb104 100644 --- a/counter/native/tests/test.rs +++ b/counter/native/tests/test.rs @@ -9,7 +9,7 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, AddressWithTree, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::address::v1::derive_address; +use light_sdk::address::v2::derive_address; use light_sdk::instruction::{ account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, }; @@ -25,7 +25,7 @@ async fn test_counter() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let address_tree_pubkey = address_tree_info.tree; // Create counter @@ -116,7 +116,7 @@ pub async fn create_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let rpc_result = rpc .get_validity_proof( @@ -164,7 +164,7 @@ pub async fn increment_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; @@ -219,7 +219,7 @@ pub async fn decrement_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; @@ -274,7 +274,7 @@ pub async fn reset_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; @@ -329,7 +329,7 @@ pub async fn close_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; diff --git a/counter/pinocchio/Cargo.toml b/counter/pinocchio/Cargo.toml index d8e5e54..1892c54 100644 --- a/counter/pinocchio/Cargo.toml +++ b/counter/pinocchio/Cargo.toml @@ -19,8 +19,8 @@ test-sbf = [] default = [] [dependencies] -light-sdk-pinocchio = { version = "0.17.1", features = ["light-account"] } -light-sdk-types = "0.17.1" +light-sdk-pinocchio = { version = "0.17.1", features = ["light-account", "v2"] } +light-sdk-types = { version = "0.17.1", features = ["v2"] } light-hasher = "5.0.0" pinocchio = "0.9.2" light-macros = "2.2.0" @@ -34,7 +34,7 @@ tokio = "1.43.0" solana-sdk = "2.3" light-hasher = { version = "5.0.0", features = ["solana"] } light-compressed-account = { version = "0.7.0", features = ["solana"] } -light-sdk = "0.17.1" +light-sdk = { version = "0.17", features = ["v2"] } [lints.rust.unexpected_cfgs] level = "allow" diff --git a/counter/pinocchio/src/lib.rs b/counter/pinocchio/src/lib.rs index 367cd98..4c77e20 100644 --- a/counter/pinocchio/src/lib.rs +++ b/counter/pinocchio/src/lib.rs @@ -3,10 +3,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_macros::pubkey_array; use light_sdk_pinocchio::{ - address::v1::derive_address, - constants::ADDRESS_TREE_V1, + address::v2::derive_address, cpi::{ - v1::{CpiAccounts, LightSystemProgramCpi}, + v2::{CpiAccounts, LightSystemProgramCpi}, CpiAccountsConfig, CpiSigner, InvokeLightSystemProgram, LightCpiInstruction, }, derive_light_cpi_signer, @@ -14,6 +13,7 @@ use light_sdk_pinocchio::{ instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightAccount, LightDiscriminator, LightHasher, }; +use light_sdk_types::ADDRESS_TREE_V2; use pinocchio::{ account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, }; @@ -175,8 +175,7 @@ pub fn create_counter( let signer = accounts.first().ok_or(ProgramError::NotEnoughAccountKeys)?; let config = CpiAccountsConfig::new(LIGHT_CPI_SIGNER); - let cpi_accounts = CpiAccounts::try_new_with_config(signer, &accounts[1..], config) - .map_err(to_custom_error_u32)?; + let cpi_accounts = CpiAccounts::new_with_config(signer, &accounts[1..], config); let tree_pubkey = cpi_accounts .get_tree_account_info( @@ -187,7 +186,7 @@ pub fn create_counter( .map_err(to_custom_error_u32)? .key(); - if *tree_pubkey != ADDRESS_TREE_V1 { + if *tree_pubkey != ADDRESS_TREE_V2 { pinocchio::log::sol_log("Invalid address tree"); return Err(ProgramError::InvalidAccountData); } @@ -201,7 +200,7 @@ pub fn create_counter( let new_address_params = instruction_data .address_tree_info - .into_new_address_params_packed(address_seed); + .into_new_address_params_assigned_packed(address_seed, Some(0)); let mut counter = LightAccount::::new_init( &program_id, @@ -239,8 +238,7 @@ pub fn increment_counter( counter.value = counter.value.checked_add(1).ok_or(CounterError::Overflow)?; let config = CpiAccountsConfig::new(LIGHT_CPI_SIGNER); - let cpi_accounts = CpiAccounts::try_new_with_config(signer, &accounts[1..], config) - .map_err(to_custom_error_u32)?; + let cpi_accounts = CpiAccounts::new_with_config(signer, &accounts[1..], config); LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, instruction_data.proof) .with_light_account(counter) @@ -271,8 +269,7 @@ pub fn decrement_counter( .ok_or(CounterError::Underflow)?; let config = CpiAccountsConfig::new(LIGHT_CPI_SIGNER); - let cpi_accounts = CpiAccounts::try_new_with_config(signer, &accounts[1..], config) - .map_err(to_custom_error_u32)?; + let cpi_accounts = CpiAccounts::new_with_config(signer, &accounts[1..], config); LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, instruction_data.proof) .with_light_account(counter) @@ -302,8 +299,7 @@ pub fn reset_counter( counter.value = 0; let config = CpiAccountsConfig::new(LIGHT_CPI_SIGNER); - let cpi_accounts = CpiAccounts::try_new_with_config(signer, &accounts[1..], config) - .map_err(to_custom_error_u32)?; + let cpi_accounts = CpiAccounts::new_with_config(signer, &accounts[1..], config); LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, instruction_data.proof) .with_light_account(counter) @@ -329,8 +325,7 @@ pub fn close_counter( .map_err(|e| ProgramError::Custom(u64::from(e) as u32))?; let config = CpiAccountsConfig::new(LIGHT_CPI_SIGNER); - let cpi_accounts = CpiAccounts::try_new_with_config(signer, &accounts[1..], config) - .map_err(to_custom_error_u32)?; + let cpi_accounts = CpiAccounts::new_with_config(signer, &accounts[1..], config); LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, instruction_data.proof) .with_light_account(counter) diff --git a/counter/pinocchio/tests/test.rs b/counter/pinocchio/tests/test.rs index c642fb9..23e6583 100644 --- a/counter/pinocchio/tests/test.rs +++ b/counter/pinocchio/tests/test.rs @@ -9,7 +9,7 @@ use light_client::indexer::CompressedAccount; use light_program_test::{ program_test::LightProgramTest, AddressWithTree, Indexer, ProgramTestConfig, Rpc, RpcError, }; -use light_sdk::address::v1::derive_address; +use light_sdk::address::v2::derive_address; use light_sdk::instruction::{ account_meta::CompressedAccountMeta, PackedAccounts, SystemAccountMetaConfig, }; @@ -25,7 +25,7 @@ async fn test_counter() { let mut rpc = LightProgramTest::new(config).await.unwrap(); let payer = rpc.get_payer().insecure_clone(); - let address_tree_info = rpc.get_address_tree_v1(); + let address_tree_info = rpc.get_address_tree_v2(); let address_tree_pubkey = address_tree_info.tree; // Create counter @@ -34,7 +34,7 @@ async fn test_counter() { &address_tree_pubkey, &counter::ID.into(), ); - let merkle_tree_pubkey = rpc.get_random_state_tree_info_v1().unwrap().tree; + let merkle_tree_pubkey = rpc.get_random_state_tree_info().unwrap().tree; create_counter( &payer, @@ -107,7 +107,7 @@ pub async fn create_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID.into()); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let rpc_result = rpc .get_validity_proof( @@ -155,7 +155,7 @@ pub async fn increment_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID.into()); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; @@ -210,7 +210,7 @@ pub async fn decrement_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID.into()); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; @@ -265,7 +265,7 @@ pub async fn reset_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID.into()); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; @@ -320,7 +320,7 @@ pub async fn close_counter( let system_account_meta_config = SystemAccountMetaConfig::new(counter::ID.into()); let mut accounts = PackedAccounts::default(); accounts.add_pre_accounts_signer(payer.pubkey()); - accounts.add_system_accounts(system_account_meta_config)?; + accounts.add_system_accounts_v2(system_account_meta_config)?; let hash = compressed_account.hash; diff --git a/create-and-update/programs/create-and-update/Cargo.toml b/create-and-update/programs/create-and-update/Cargo.toml index 022072a..9242af6 100644 --- a/create-and-update/programs/create-and-update/Cargo.toml +++ b/create-and-update/programs/create-and-update/Cargo.toml @@ -20,7 +20,7 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] anchor-lang = "0.31.1" borsh = "0.10.4" -light-sdk = { version = "0.17.1", features = ["anchor", "v2"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } light-hasher = "5.0.0" light-sdk-types = { version = "0.17.1", features = ["v2"] } diff --git a/create-and-update/programs/create-and-update/src/lib.rs b/create-and-update/programs/create-and-update/src/lib.rs index 0082295..c5b41f9 100644 --- a/create-and-update/programs/create-and-update/src/lib.rs +++ b/create-and-update/programs/create-and-update/src/lib.rs @@ -5,12 +5,12 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; use light_sdk::{ account::LightAccount, address::v2::derive_address, - constants::ADDRESS_TREE_V2, cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof}, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("J6K7nvoVpJHfH13zn47vptnZo1JdUGCGSiVmtfkzz9NA"); diff --git a/read-only/Cargo.toml b/read-only/Cargo.toml index b04fbda..2887f00 100644 --- a/read-only/Cargo.toml +++ b/read-only/Cargo.toml @@ -14,7 +14,7 @@ test-sbf = [] [dependencies] anchor-lang = "0.31.1" borsh = "0.10.4" -light-sdk = { version = "0.17.1", features = ["anchor", "v2"] } +light-sdk = { version = "0.17", features = ["anchor", "v2"] } light-sdk-types = { version = "0.17.1", features = ["v2"] } light-compressed-account = "0.7.0" diff --git a/read-only/src/lib.rs b/read-only/src/lib.rs index 4a4e915..354ff2e 100644 --- a/read-only/src/lib.rs +++ b/read-only/src/lib.rs @@ -8,7 +8,6 @@ use light_sdk::cpi::{v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightC use light_sdk::{ account::LightAccount, address::v2::derive_address, - constants::ADDRESS_TREE_V2, cpi::{v2::CpiAccounts, CpiSigner}, derive_light_cpi_signer, instruction::{ @@ -16,6 +15,7 @@ use light_sdk::{ }, LightDiscriminator, }; +use light_sdk_types::ADDRESS_TREE_V2; declare_id!("HNqStLMpNuNJqhBF1FbGTKHEFbBLJmq8RdJJmZKWz6jH");