Skip to content

Commit b2a2364

Browse files
ananas-blockSwenSchaeferjohannclaude
authored
feat: pinocchio sdk (#1783)
* feat: add pinocchio-sdk feat: add cpi_signer_macro feat: add light-program-test, light-client docs Co-authored-by: Swen Schäferjohann <42959314+SwenSchaeferjohann@users.noreply.github.com> * refactor: unify CpiAccounts in sdk-types * feat: add PackedTreeInfo::get_tree_pubkey() * refactor: small ix into sdk-types * fix: don't run light-client doc test * cleanup * refactor: AddressTreeInfo * simplify error conversion * fix: typo * unify program id constants * fix enum typo * Revert "simplify error conversion" This reverts commit ff99942. * fixed stuff * refactor: rename duplicate AccountInfoTrait -> CompressedAccountInfoTrait * revert: remove program changes from pinocchio-sdk commit Reverts only the changes made to the programs/ directory in commit b3f14e7 while preserving all other changes from that commit. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * cleanup * feat: add select_state_tree_info, chore: return Result from get_random_state_tree_info * fix: account compression tests * refactor: add result to handle out of bounds errors * cleanup * refactor: migrate light sdk errors to 16k namespace --------- Co-authored-by: Swen Schäferjohann <42959314+SwenSchaeferjohann@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent c0a089e commit b2a2364

File tree

111 files changed

+3911
-1165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3911
-1165
lines changed

.github/workflows/light-examples-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- program: sdk-test-program
5757
sub-tests: '["cargo-test-sbf -p sdk-test"]'
5858
- program: sdk-anchor-test-program
59-
sub-tests: '["cargo-test-sbf -p sdk-anchor-test"]'
59+
sub-tests: '["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk-pinocchio-test"]'
6060

6161
steps:
6262
- name: Checkout sources

Cargo.lock

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ members = [
2121
"sdk-libs/client",
2222
"sdk-libs/macros",
2323
"sdk-libs/sdk",
24+
"sdk-libs/sdk-pinocchio",
25+
"sdk-libs/sdk-types",
2426
"sdk-libs/photon-api",
2527
"sdk-libs/program-test",
2628
"xtask",
@@ -38,6 +40,7 @@ members = [
3840
# Issue is that anchor discriminator now returns a slice instead of an array
3941
"program-tests/sdk-anchor-test/programs/sdk-anchor-test",
4042
"program-tests/sdk-test",
43+
"program-tests/sdk-pinocchio-test",
4144
"program-tests/create-address-test-program",
4245
"program-tests/utils",
4346
"program-tests/merkle-tree",
@@ -153,7 +156,9 @@ light-merkle-tree-reference = { path = "program-tests/merkle-tree", version = "2
153156
light-heap = { path = "program-libs/heap", version = "1.1.0" }
154157
light-prover-client = { path = "prover/client", version = "1.3.0" }
155158
light-sdk = { path = "sdk-libs/sdk", version = "0.12.0" }
159+
light-sdk-pinocchio = { path = "sdk-libs/sdk-pinocchio", version = "0.12.0" }
156160
light-sdk-macros = { path = "sdk-libs/macros", version = "0.6.0" }
161+
light-sdk-types = { path = "sdk-libs/sdk-types", version = "0.9.1" }
157162
light-compressed-account = { path = "program-libs/compressed-account", version = "0.2.0" }
158163
light-account-checks = { path = "program-libs/account-checks", version = "0.2.0" }
159164
light-verifier = { path = "program-libs/verifier", version = "2.0.0" }

examples/anchor/counter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"]
2323
anchor-lang = { workspace = true }
2424
light-hasher = { workspace = true, features = ["solana"] }
2525
light-sdk = { workspace = true, features = ["anchor"] }
26+
light-sdk-types = { workspace = true }
2627
light-compressed-account = { workspace = true }
2728

2829
[dev-dependencies]

examples/anchor/counter/src/lib.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ use anchor_lang::{prelude::*, AnchorDeserialize, Discriminator};
44
use light_sdk::{
55
account::LightAccount,
66
address::v1::derive_address,
7-
cpi::{CpiAccounts, CpiInputs},
7+
cpi::{CpiAccounts, CpiInputs, CpiSigner},
8+
derive_light_cpi_signer,
89
instruction::{
910
account_meta::{CompressedAccountMeta, CompressedAccountMetaClose},
10-
tree_info::PackedAddressTreeInfo,
11+
PackedAddressTreeInfo, ValidityProof,
1112
},
12-
LightDiscriminator, LightHasher, ValidityProof,
13+
LightDiscriminator, LightHasher,
1314
};
1415

1516
declare_id!("GRLu2hKaAiMbxpkAM1HeXzks9YeGuz18SEgXEizVvPqX");
1617

18+
pub const LIGHT_CPI_SIGNER: CpiSigner =
19+
derive_light_cpi_signer!("GRLu2hKaAiMbxpkAM1HeXzks9YeGuz18SEgXEizVvPqX");
20+
1721
#[program]
1822
pub mod counter {
1923

@@ -33,15 +37,14 @@ pub mod counter {
3337
let light_cpi_accounts = CpiAccounts::new(
3438
ctx.accounts.signer.as_ref(),
3539
ctx.remaining_accounts,
36-
crate::ID,
37-
)
38-
.map_err(ProgramError::from)?;
40+
crate::LIGHT_CPI_SIGNER,
41+
);
3942

4043
let (address, address_seed) = derive_address(
4144
&[b"counter", ctx.accounts.signer.key().as_ref()],
42-
&light_cpi_accounts.tree_accounts()
43-
[address_tree_info.address_merkle_tree_pubkey_index as usize]
44-
.key(),
45+
&address_tree_info
46+
.get_tree_pubkey(&light_cpi_accounts)
47+
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
4548
&crate::ID,
4649
);
4750

@@ -94,9 +97,8 @@ pub mod counter {
9497
let light_cpi_accounts = CpiAccounts::new(
9598
ctx.accounts.signer.as_ref(),
9699
ctx.remaining_accounts,
97-
crate::ID,
98-
)
99-
.map_err(ProgramError::from)?;
100+
crate::LIGHT_CPI_SIGNER,
101+
);
100102

101103
let cpi_inputs = CpiInputs::new(
102104
proof,
@@ -133,9 +135,8 @@ pub mod counter {
133135
let light_cpi_accounts = CpiAccounts::new(
134136
ctx.accounts.signer.as_ref(),
135137
ctx.remaining_accounts,
136-
crate::ID,
137-
)
138-
.map_err(ProgramError::from)?;
138+
crate::LIGHT_CPI_SIGNER,
139+
);
139140

140141
let cpi_inputs = CpiInputs::new(
141142
proof,
@@ -170,9 +171,8 @@ pub mod counter {
170171
let light_cpi_accounts = CpiAccounts::new(
171172
ctx.accounts.signer.as_ref(),
172173
ctx.remaining_accounts,
173-
crate::ID,
174-
)
175-
.map_err(ProgramError::from)?;
174+
crate::LIGHT_CPI_SIGNER,
175+
);
176176
let cpi_inputs = CpiInputs::new(
177177
proof,
178178
vec![counter.to_account_info().map_err(ProgramError::from)?],
@@ -207,9 +207,8 @@ pub mod counter {
207207
let light_cpi_accounts = CpiAccounts::new(
208208
ctx.accounts.signer.as_ref(),
209209
ctx.remaining_accounts,
210-
crate::ID,
211-
)
212-
.map_err(ProgramError::from)?;
210+
crate::LIGHT_CPI_SIGNER,
211+
);
213212

214213
let cpi_inputs = CpiInputs::new(
215214
proof,

examples/anchor/counter/tests/test.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use light_sdk::{
1010
address::v1::derive_address,
1111
instruction::{
1212
account_meta::{CompressedAccountMeta, CompressedAccountMetaClose},
13-
accounts::SystemAccountMetaConfig,
14-
pack_accounts::PackedAccounts,
13+
PackedAccounts, SystemAccountMetaConfig,
1514
},
1615
};
1716
use solana_sdk::{
@@ -138,7 +137,7 @@ where
138137
.value;
139138

140139
let output_state_tree_index = rpc
141-
.get_random_state_tree_info()
140+
.get_random_state_tree_info()?
142141
.pack_output_tree_index(&mut remaining_accounts)?;
143142
let packed_address_tree_info = rpc_result
144143
.pack_tree_infos(&mut remaining_accounts)

examples/anchor/memo/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use light_sdk::{
1717
address::derive_address,
1818
instruction_data::LightInstructionData,
1919
tree_info::{AddressTreeInfo, PackedAccounts},
20-
utils::get_cpi_authority_pda,
20+
find_cpi_signer_macro,
2121
verify::find_cpi_signer,
2222
PROGRAM_ID_ACCOUNT_COMPRESSION, PROGRAM_ID_LIGHT_SYSTEM, PROGRAM_ID_NOOP,
2323
};
@@ -66,7 +66,7 @@ async fn test_memo_program() {
6666
&memo::ID,
6767
);
6868

69-
let account_compression_authority = get_cpi_authority_pda(&PROGRAM_ID_LIGHT_SYSTEM);
69+
let account_compression_authority = find_cpi_signer_macro!(&PROGRAM_ID_LIGHT_SYSTEM);
7070
let registered_program_pda = Pubkey::find_program_address(
7171
&[PROGRAM_ID_LIGHT_SYSTEM.to_bytes().as_slice()],
7272
&PROGRAM_ID_ACCOUNT_COMPRESSION,

examples/anchor/name-service-without-macros/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use light_sdk::{
2020
error::LightSdkError,
2121
instruction_data::LightInstructionData,
2222
tree_info::{AddressTreeInfo, PackedAccounts},
23-
utils::get_cpi_authority_pda,
23+
find_cpi_signer_macro,
2424
verify::find_cpi_signer,
2525
PROGRAM_ID_ACCOUNT_COMPRESSION, PROGRAM_ID_LIGHT_SYSTEM, PROGRAM_ID_NOOP,
2626
};
@@ -76,7 +76,7 @@ async fn test_name_service() {
7676
&name_service_without_macros::ID,
7777
);
7878

79-
let account_compression_authority = get_cpi_authority_pda(&PROGRAM_ID_LIGHT_SYSTEM);
79+
let account_compression_authority = find_cpi_signer_macro!(&PROGRAM_ID_LIGHT_SYSTEM);
8080
let registered_program_pda = Pubkey::find_program_address(
8181
&[PROGRAM_ID_LIGHT_SYSTEM.to_bytes().as_slice()],
8282
&PROGRAM_ID_ACCOUNT_COMPRESSION,

examples/anchor/name-service/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use light_sdk::{
2020
pack_address_merkle_context, pack_merkle_context, AddressTreeInfo, MerkleContext,
2121
PackedAddressTreeInfo, PackedMerkleContext, PackedAccounts,
2222
},
23-
utils::get_cpi_authority_pda,
23+
find_cpi_signer_macro,
2424
verify::find_cpi_signer,
2525
PROGRAM_ID_ACCOUNT_COMPRESSION, PROGRAM_ID_LIGHT_SYSTEM, PROGRAM_ID_NOOP,
2626
};
@@ -83,7 +83,7 @@ async fn test_name_service() {
8383
let address_merkle_context =
8484
pack_address_merkle_context(&address_merkle_context, &mut remaining_accounts);
8585

86-
let account_compression_authority = get_cpi_authority_pda(&PROGRAM_ID_LIGHT_SYSTEM);
86+
let account_compression_authority = find_cpi_signer_macro!(&PROGRAM_ID_LIGHT_SYSTEM);
8787
let registered_program_pda = Pubkey::find_program_address(
8888
&[PROGRAM_ID_LIGHT_SYSTEM.to_bytes().as_slice()],
8989
&PROGRAM_ID_ACCOUNT_COMPRESSION,

examples/anchor/token-escrow/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ account-compression = { workspace = true, features = ["cpi"] }
2727
light-hasher = { workspace = true }
2828
light-sdk = { workspace = true }
2929
light-compressed-account = { workspace = true, features = ["anchor"] }
30+
light-sdk-types = { workspace = true }
3031

3132
[target.'cfg(not(target_os = "solana"))'.dependencies]
3233
solana-sdk = { workspace = true }

0 commit comments

Comments
 (0)