Skip to content

feat: compressed token sdk #1826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
59 changes: 59 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ members = [
"sdk-libs/sdk-types",
"sdk-libs/photon-api",
"sdk-libs/program-test",
"sdk-libs/compressed-token-types",
"sdk-libs/compressed-token-sdk",
"xtask",
"examples/anchor/token-escrow",
# "examples/anchor/name-service-without-macros",
Expand All @@ -40,6 +42,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-token-test",
"program-tests/sdk-pinocchio-test",
"program-tests/create-address-test-program",
"program-tests/utils",
Expand All @@ -60,6 +63,10 @@ strip = "none"
[profile.release]
overflow-checks = true

[workspace.package]
version = "0.1.0"
edition = "2021"

[workspace.dependencies]
solana-banks-client = { version = "2.2" }
solana-banks-interface = { version = "2.2" }
Expand Down Expand Up @@ -175,6 +182,8 @@ account-compression = { path = "programs/account-compression", version = "2.0.0"
light-compressed-token = { path = "programs/compressed-token", version = "2.0.0", features = [
"cpi",
] }
light-compressed-token-types = { path = "sdk-libs/compressed-token-types", name = "light-compressed-token-types" }
light-compressed-token-sdk = { path = "sdk-libs/compressed-token-sdk" }
light-system-program-anchor = { path = "anchor-programs/system", version = "2.0.0", features = [
"cpi",
] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ fn cpi_compressed_pda_transfer<'info>(
.clone(),
];
system_accounts.extend_from_slice(ctx.remaining_accounts);
let light_accounts = CpiAccounts::new_with_config(
let light_accounts = CpiAccounts::try_new_with_config(
ctx.accounts.signer.as_ref(),
&system_accounts,
CpiAccountsConfig::new_with_cpi_context(crate::LIGHT_CPI_SIGNER),
);
)
.unwrap();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ fn cpi_compressed_pda_withdrawal<'info>(
.clone(),
];
system_accounts.extend_from_slice(ctx.remaining_accounts);
let light_accounts = CpiAccounts::new_with_config(
let light_accounts = CpiAccounts::try_new_with_config(
ctx.accounts.signer.as_ref(),
&system_accounts,
CpiAccountsConfig::new_with_cpi_context(crate::LIGHT_CPI_SIGNER),
);
)
.unwrap();
verify_borsh(light_accounts, &inputs_struct).unwrap();

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::error::AccountError;

/// Trait to abstract over different AccountInfo implementations (pinocchio vs solana)
pub trait AccountInfoTrait {
type Pubkey: Copy + Clone;
type Pubkey: Copy + Clone + std::fmt::Debug;
type DataRef<'a>: Deref<Target = [u8]>
where
Self: 'a;
Expand Down
2 changes: 1 addition & 1 deletion program-libs/compressed-account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ light-zero-copy = { workspace = true, features = ["std"] }
light-macros = { workspace = true }
pinocchio = { workspace = true, optional = true }
solana-program-error = { workspace = true, optional = true }

solana-msg = { workspace = true }
# Feature-gated dependencies
anchor-lang = { workspace = true, optional = true }
bytemuck = { workspace = true, optional = true, features = ["derive"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ pub fn hash_with_hashed_values(
vec.push(&discriminator_bytes);
vec.push(data_hash);
}

Ok(Poseidon::hashv(&vec)?)
}

Expand Down
9 changes: 3 additions & 6 deletions program-tests/create-address-test-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ pub mod system_cpi_test {
} else {
use light_sdk::cpi::CpiAccounts;
let cpi_accounts =
CpiAccounts::new_with_config(&fee_payer, ctx.remaining_accounts, config);
let account_infos = cpi_accounts
.to_account_infos()
.into_iter()
.cloned()
.collect::<Vec<_>>();
CpiAccounts::try_new_with_config(&fee_payer, ctx.remaining_accounts, config)
.unwrap();
let account_infos = cpi_accounts.to_account_infos();

let account_metas =
to_account_metas(cpi_accounts).map_err(|_| ErrorCode::AccountNotEnoughKeys)?;
Expand Down
4 changes: 2 additions & 2 deletions program-tests/sdk-pinocchio-test/src/create_pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pub fn create_pda<const BATCHED: bool>(
let instruction_data = CreatePdaInstructionData::deserialize(&mut instruction_data)
.map_err(|_| LightSdkError::Borsh)?;
let config = CpiAccountsConfig::new(crate::LIGHT_CPI_SIGNER);
let cpi_accounts = CpiAccounts::new_with_config(
let cpi_accounts = CpiAccounts::try_new_with_config(
&accounts[0],
&accounts[instruction_data.system_accounts_offset as usize..],
config,
);
)?;

let address_tree_info = instruction_data.address_tree_info;
let (address, address_seed) = if BATCHED {
Expand Down
4 changes: 2 additions & 2 deletions program-tests/sdk-pinocchio-test/src/update_pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ pub fn update_pda<const BATCHED: bool>(

let config = CpiAccountsConfig::new(crate::LIGHT_CPI_SIGNER);
sol_log_compute_units();
let cpi_accounts = CpiAccounts::new_with_config(
let cpi_accounts = CpiAccounts::try_new_with_config(
&accounts[0],
&accounts[instruction_data.system_accounts_offset as usize..],
config,
);
)?;
sol_log_compute_units();
let cpi_inputs = CpiInputs::new(
instruction_data.proof,
Expand Down
4 changes: 2 additions & 2 deletions program-tests/sdk-test/src/create_pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pub fn create_pda<const BATCHED: bool>(
let instruction_data = CreatePdaInstructionData::deserialize(&mut instruction_data)
.map_err(|_| LightSdkError::Borsh)?;
let config = CpiAccountsConfig::new(crate::LIGHT_CPI_SIGNER);
let cpi_accounts = CpiAccounts::new_with_config(
let cpi_accounts = CpiAccounts::try_new_with_config(
&accounts[0],
&accounts[instruction_data.system_accounts_offset as usize..],
config,
);
)?;

let address_tree_info = instruction_data.address_tree_info;
let (address, address_seed) = if BATCHED {
Expand Down
4 changes: 2 additions & 2 deletions program-tests/sdk-test/src/update_pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ pub fn update_pda<const BATCHED: bool>(

let config = CpiAccountsConfig::new(crate::LIGHT_CPI_SIGNER);
sol_log_compute_units();
let cpi_accounts = CpiAccounts::new_with_config(
let cpi_accounts = CpiAccounts::try_new_with_config(
&accounts[0],
&accounts[instruction_data.system_accounts_offset as usize..],
config,
);
)?;
sol_log_compute_units();
let cpi_inputs = CpiInputs::new(
instruction_data.proof,
Expand Down
Loading