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
2 changes: 1 addition & 1 deletion .github/workflows/light-examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- program: sdk-test-program
sub-tests: '["cargo-test-sbf -p sdk-test"]'
- program: sdk-anchor-test-program
sub-tests: '["cargo-test-sbf -p sdk-anchor-test"]'
sub-tests: '["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk-pinocchio-test"]'

steps:
- name: Checkout sources
Expand Down
64 changes: 64 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ members = [
"sdk-libs/client",
"sdk-libs/macros",
"sdk-libs/sdk",
"sdk-libs/sdk-pinocchio",
"sdk-libs/sdk-types",
"sdk-libs/photon-api",
"sdk-libs/program-test",
"xtask",
Expand All @@ -38,6 +40,7 @@ members = [
# Issue is that anchor discriminator now returns a slice instead of an array
"program-tests/sdk-anchor-test/programs/sdk-anchor-test",
"program-tests/sdk-test",
"program-tests/sdk-pinocchio-test",
"program-tests/create-address-test-program",
"program-tests/utils",
"program-tests/merkle-tree",
Expand Down Expand Up @@ -153,7 +156,9 @@ light-merkle-tree-reference = { path = "program-tests/merkle-tree", version = "2
light-heap = { path = "program-libs/heap", version = "1.1.0" }
light-prover-client = { path = "prover/client", version = "1.3.0" }
light-sdk = { path = "sdk-libs/sdk", version = "0.12.0" }
light-sdk-pinocchio = { path = "sdk-libs/sdk-pinocchio", version = "0.12.0" }
light-sdk-macros = { path = "sdk-libs/macros", version = "0.6.0" }
light-sdk-types = { path = "sdk-libs/sdk-types", version = "0.9.1" }
light-compressed-account = { path = "program-libs/compressed-account", version = "0.2.0" }
light-account-checks = { path = "program-libs/account-checks", version = "0.2.0" }
light-verifier = { path = "program-libs/verifier", version = "2.0.0" }
Expand Down
1 change: 1 addition & 0 deletions examples/anchor/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"]
anchor-lang = { workspace = true }
light-hasher = { workspace = true, features = ["solana"] }
light-sdk = { workspace = true, features = ["anchor"] }
light-sdk-types = { workspace = true }
light-compressed-account = { workspace = true }

[dev-dependencies]
Expand Down
41 changes: 20 additions & 21 deletions examples/anchor/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ use anchor_lang::{prelude::*, AnchorDeserialize, Discriminator};
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
cpi::{CpiAccounts, CpiInputs},
cpi::{CpiAccounts, CpiInputs, CpiSigner},
derive_light_cpi_signer,
instruction::{
account_meta::{CompressedAccountMeta, CompressedAccountMetaClose},
tree_info::PackedAddressTreeInfo,
PackedAddressTreeInfo, ValidityProof,
},
LightDiscriminator, LightHasher, ValidityProof,
LightDiscriminator, LightHasher,
};

declare_id!("GRLu2hKaAiMbxpkAM1HeXzks9YeGuz18SEgXEizVvPqX");

pub const LIGHT_CPI_SIGNER: CpiSigner =
derive_light_cpi_signer!("GRLu2hKaAiMbxpkAM1HeXzks9YeGuz18SEgXEizVvPqX");

#[program]
pub mod counter {

Expand All @@ -33,15 +37,14 @@ pub mod counter {
let light_cpi_accounts = CpiAccounts::new(
ctx.accounts.signer.as_ref(),
ctx.remaining_accounts,
crate::ID,
)
.map_err(ProgramError::from)?;
crate::LIGHT_CPI_SIGNER,
);

let (address, address_seed) = derive_address(
&[b"counter", ctx.accounts.signer.key().as_ref()],
&light_cpi_accounts.tree_accounts()
[address_tree_info.address_merkle_tree_pubkey_index as usize]
.key(),
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
&crate::ID,
);

Expand Down Expand Up @@ -94,9 +97,8 @@ pub mod counter {
let light_cpi_accounts = CpiAccounts::new(
ctx.accounts.signer.as_ref(),
ctx.remaining_accounts,
crate::ID,
)
.map_err(ProgramError::from)?;
crate::LIGHT_CPI_SIGNER,
);

let cpi_inputs = CpiInputs::new(
proof,
Expand Down Expand Up @@ -133,9 +135,8 @@ pub mod counter {
let light_cpi_accounts = CpiAccounts::new(
ctx.accounts.signer.as_ref(),
ctx.remaining_accounts,
crate::ID,
)
.map_err(ProgramError::from)?;
crate::LIGHT_CPI_SIGNER,
);

let cpi_inputs = CpiInputs::new(
proof,
Expand Down Expand Up @@ -170,9 +171,8 @@ pub mod counter {
let light_cpi_accounts = CpiAccounts::new(
ctx.accounts.signer.as_ref(),
ctx.remaining_accounts,
crate::ID,
)
.map_err(ProgramError::from)?;
crate::LIGHT_CPI_SIGNER,
);
let cpi_inputs = CpiInputs::new(
proof,
vec![counter.to_account_info().map_err(ProgramError::from)?],
Expand Down Expand Up @@ -207,9 +207,8 @@ pub mod counter {
let light_cpi_accounts = CpiAccounts::new(
ctx.accounts.signer.as_ref(),
ctx.remaining_accounts,
crate::ID,
)
.map_err(ProgramError::from)?;
crate::LIGHT_CPI_SIGNER,
);

let cpi_inputs = CpiInputs::new(
proof,
Expand Down
5 changes: 2 additions & 3 deletions examples/anchor/counter/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use light_sdk::{
address::v1::derive_address,
instruction::{
account_meta::{CompressedAccountMeta, CompressedAccountMetaClose},
accounts::SystemAccountMetaConfig,
pack_accounts::PackedAccounts,
PackedAccounts, SystemAccountMetaConfig,
},
};
use solana_sdk::{
Expand Down Expand Up @@ -138,7 +137,7 @@ where
.value;

let output_state_tree_index = rpc
.get_random_state_tree_info()
.get_random_state_tree_info()?
.pack_output_tree_index(&mut remaining_accounts)?;
let packed_address_tree_info = rpc_result
.pack_tree_infos(&mut remaining_accounts)
Expand Down
4 changes: 2 additions & 2 deletions examples/anchor/memo/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use light_sdk::{
address::derive_address,
instruction_data::LightInstructionData,
tree_info::{AddressTreeInfo, PackedAccounts},
utils::get_cpi_authority_pda,
find_cpi_signer_macro,
verify::find_cpi_signer,
PROGRAM_ID_ACCOUNT_COMPRESSION, PROGRAM_ID_LIGHT_SYSTEM, PROGRAM_ID_NOOP,
};
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn test_memo_program() {
&memo::ID,
);

let account_compression_authority = get_cpi_authority_pda(&PROGRAM_ID_LIGHT_SYSTEM);
let account_compression_authority = find_cpi_signer_macro!(&PROGRAM_ID_LIGHT_SYSTEM);
let registered_program_pda = Pubkey::find_program_address(
&[PROGRAM_ID_LIGHT_SYSTEM.to_bytes().as_slice()],
&PROGRAM_ID_ACCOUNT_COMPRESSION,
Expand Down
4 changes: 2 additions & 2 deletions examples/anchor/name-service-without-macros/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use light_sdk::{
error::LightSdkError,
instruction_data::LightInstructionData,
tree_info::{AddressTreeInfo, PackedAccounts},
utils::get_cpi_authority_pda,
find_cpi_signer_macro,
verify::find_cpi_signer,
PROGRAM_ID_ACCOUNT_COMPRESSION, PROGRAM_ID_LIGHT_SYSTEM, PROGRAM_ID_NOOP,
};
Expand Down Expand Up @@ -76,7 +76,7 @@ async fn test_name_service() {
&name_service_without_macros::ID,
);

let account_compression_authority = get_cpi_authority_pda(&PROGRAM_ID_LIGHT_SYSTEM);
let account_compression_authority = find_cpi_signer_macro!(&PROGRAM_ID_LIGHT_SYSTEM);
let registered_program_pda = Pubkey::find_program_address(
&[PROGRAM_ID_LIGHT_SYSTEM.to_bytes().as_slice()],
&PROGRAM_ID_ACCOUNT_COMPRESSION,
Expand Down
4 changes: 2 additions & 2 deletions examples/anchor/name-service/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use light_sdk::{
pack_address_merkle_context, pack_merkle_context, AddressTreeInfo, MerkleContext,
PackedAddressTreeInfo, PackedMerkleContext, PackedAccounts,
},
utils::get_cpi_authority_pda,
find_cpi_signer_macro,
verify::find_cpi_signer,
PROGRAM_ID_ACCOUNT_COMPRESSION, PROGRAM_ID_LIGHT_SYSTEM, PROGRAM_ID_NOOP,
};
Expand Down Expand Up @@ -83,7 +83,7 @@ async fn test_name_service() {
let address_merkle_context =
pack_address_merkle_context(&address_merkle_context, &mut remaining_accounts);

let account_compression_authority = get_cpi_authority_pda(&PROGRAM_ID_LIGHT_SYSTEM);
let account_compression_authority = find_cpi_signer_macro!(&PROGRAM_ID_LIGHT_SYSTEM);
let registered_program_pda = Pubkey::find_program_address(
&[PROGRAM_ID_LIGHT_SYSTEM.to_bytes().as_slice()],
&PROGRAM_ID_ACCOUNT_COMPRESSION,
Expand Down
1 change: 1 addition & 0 deletions examples/anchor/token-escrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ account-compression = { workspace = true, features = ["cpi"] }
light-hasher = { workspace = true }
light-sdk = { workspace = true }
light-compressed-account = { workspace = true, features = ["anchor"] }
light-sdk-types = { workspace = true }

[target.'cfg(not(target_os = "solana"))'.dependencies]
solana-sdk = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,10 @@ fn cpi_compressed_pda_transfer<'info>(
let light_accounts = CpiAccounts::new_with_config(
ctx.accounts.signer.as_ref(),
&system_accounts,
CpiAccountsConfig {
self_program: crate::ID,
cpi_context: true,
..Default::default()
},
)
.unwrap();
CpiAccountsConfig::new_with_cpi_context(crate::LIGHT_CPI_SIGNER),
);

verify_borsh(&light_accounts, &inputs_struct).map_err(ProgramError::from)?;
verify_borsh(light_accounts, &inputs_struct).map_err(ProgramError::from)?;

Ok(())
}
Expand Down
Loading