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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions account-comparison/programs/account-comparison/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 7 additions & 6 deletions account-comparison/programs/account-comparison/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down Expand Up @@ -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());
}
Expand All @@ -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)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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()],
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion basic-operations/anchor/burn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions basic-operations/anchor/burn/programs/burn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions basic-operations/anchor/burn/programs/burn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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
Expand All @@ -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());
}
Expand All @@ -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(())
Expand Down
15 changes: 8 additions & 7 deletions basic-operations/anchor/burn/programs/burn/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -116,9 +117,9 @@ async fn create_compressed_account(
) -> Result<Signature, RpcError> {
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(
Expand Down
34 changes: 18 additions & 16 deletions basic-operations/anchor/burn/tests/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -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<Burn>,
outputStateTree: anchor.web3.PublicKey,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -227,4 +229,4 @@ async function burnCompressedAccount(
const sig = await rpc.sendTransaction(tx, [signer]);
await confirmTx(rpc, sig);
return sig;
}
}
4 changes: 2 additions & 2 deletions basic-operations/anchor/close/programs/close/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions basic-operations/anchor/close/programs/close/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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
Expand All @@ -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());
}
Expand All @@ -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(())
Expand Down
15 changes: 8 additions & 7 deletions basic-operations/anchor/close/programs/close/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -113,9 +114,9 @@ async fn create_compressed_account(
) -> Result<Signature, RpcError> {
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(
Expand Down
Loading