Skip to content

Commit 27becc5

Browse files
committed
cleanup
1 parent a8fbbc6 commit 27becc5

File tree

5 files changed

+45
-22
lines changed

5 files changed

+45
-22
lines changed

Cargo.lock

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

program-tests/sdk-token-test/tests/test.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// #![cfg(feature = "test-sbf")]
1+
#![cfg(feature = "test-sbf")]
22

33
use anchor_lang::{AccountDeserialize, InstructionData};
44
use anchor_spl::token::TokenAccount;
55
use light_compressed_token_sdk::{
66
instruction::{get_transfer_instruction_account_metas, TokenAccountsMetaConfig},
77
token_pool::get_token_pool_pda,
8-
InputTokenDataWithContext, PackedMerkleContext,
8+
InputTokenDataWithContext,
99
};
1010
use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc};
1111
use light_sdk::instruction::PackedAccounts;
@@ -219,7 +219,6 @@ async fn test() {
219219
&transfer_recipient,
220220
recipient_compressed_account,
221221
decompress_token_account_keypair.pubkey(),
222-
decompress_amount,
223222
)
224223
.await
225224
.unwrap();
@@ -354,19 +353,13 @@ async fn transfer_compressed_tokens(
354353
let token_data = vec![InputTokenDataWithContext {
355354
amount: compressed_account.token.amount,
356355
delegate_index: None,
357-
merkle_context: PackedMerkleContext {
358-
merkle_tree_pubkey_index: tree_info.merkle_tree_pubkey_index,
359-
nullifier_queue_pubkey_index: tree_info.queue_pubkey_index,
360-
leaf_index: tree_info.leaf_index,
361-
proof_by_index: tree_info.prove_by_index,
362-
},
363-
root_index: tree_info.root_index,
356+
packed_tree_info: tree_info,
364357
lamports: None,
365358
tlv: None,
366359
}];
367360

368361
let (remaining_accounts, _, _) = remaining_accounts.to_account_metas();
369-
println!("remaining_accounts {:?}", remaining_accounts);
362+
370363
let instruction = Instruction {
371364
program_id: sdk_token_test::ID,
372365
accounts: [remaining_accounts].concat(),
@@ -389,7 +382,6 @@ async fn decompress_compressed_tokens(
389382
payer: &Keypair,
390383
compressed_account: &CompressedTokenAccount,
391384
decompress_token_account: Pubkey,
392-
decompress_amount: u64,
393385
) -> Result<Signature, RpcError> {
394386
let mut remaining_accounts = PackedAccounts::default();
395387
let token_pool_pda = get_token_pool_pda(&compressed_account.token.mint);
@@ -423,13 +415,7 @@ async fn decompress_compressed_tokens(
423415
let token_data = vec![InputTokenDataWithContext {
424416
amount: compressed_account.token.amount,
425417
delegate_index: None,
426-
merkle_context: PackedMerkleContext {
427-
merkle_tree_pubkey_index: tree_info.merkle_tree_pubkey_index,
428-
nullifier_queue_pubkey_index: tree_info.queue_pubkey_index,
429-
leaf_index: tree_info.leaf_index,
430-
proof_by_index: tree_info.prove_by_index,
431-
},
432-
root_index: tree_info.root_index,
418+
packed_tree_info: tree_info,
433419
lamports: None,
434420
tlv: None,
435421
}];

sdk-libs/compressed-token-sdk/src/cpi/invoke.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ pub fn create_compressed_token_instruction(
108108

109109
for token_account in cpi_inputs.token_accounts {
110110
let (inputs, output) = token_account.into_inputs_and_outputs();
111-
input_token_data_with_context.extend(inputs);
111+
for input in inputs {
112+
input_token_data_with_context.push(input.into());
113+
}
112114
if output.amount == 0 && cpi_inputs.filter_zero_amount_outputs {
113115
} else {
114116
output_compressed_accounts.push(output);

sdk-libs/compressed-token-types/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
anchor = ["anchor-lang", "light-compressed-account/anchor"]
7+
anchor = [
8+
"anchor-lang",
9+
"light-compressed-account/anchor",
10+
"light-sdk-types/anchor",
11+
]
812

913
[dependencies]
1014
borsh = { workspace = true }
1115
light-macros = { workspace = true }
1216
anchor-lang = { workspace = true, optional = true }
17+
light-sdk-types = { workspace = true }
1318
light-account-checks = { workspace = true }
1419
light-compressed-account = { workspace = true }
1520
thiserror = { workspace = true }

sdk-libs/compressed-token-types/src/instruction/transfer.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{AnchorDeserialize, AnchorSerialize};
22
pub use light_compressed_account::instruction_data::compressed_proof::CompressedProof;
3+
use light_sdk_types::instruction::PackedStateTreeInfo;
34

45
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, PartialEq)]
56
pub struct PackedMerkleContext {
@@ -19,6 +20,16 @@ pub struct CompressedCpiContext {
1920

2021
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, PartialEq)]
2122
pub struct InputTokenDataWithContext {
23+
pub amount: u64,
24+
pub delegate_index: Option<u8>,
25+
pub packed_tree_info: PackedStateTreeInfo,
26+
pub lamports: Option<u64>,
27+
/// Placeholder for TokenExtension tlv data (unimplemented)
28+
pub tlv: Option<Vec<u8>>,
29+
}
30+
31+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, PartialEq)]
32+
pub struct InputTokenDataWithContextOnchain {
2233
pub amount: u64,
2334
pub delegate_index: Option<u8>,
2435
pub merkle_context: PackedMerkleContext,
@@ -28,6 +39,24 @@ pub struct InputTokenDataWithContext {
2839
pub tlv: Option<Vec<u8>>,
2940
}
3041

42+
impl From<InputTokenDataWithContext> for InputTokenDataWithContextOnchain {
43+
fn from(input: InputTokenDataWithContext) -> Self {
44+
Self {
45+
amount: input.amount,
46+
delegate_index: input.delegate_index,
47+
merkle_context: PackedMerkleContext {
48+
merkle_tree_pubkey_index: input.packed_tree_info.merkle_tree_pubkey_index,
49+
nullifier_queue_pubkey_index: input.packed_tree_info.queue_pubkey_index,
50+
leaf_index: input.packed_tree_info.leaf_index,
51+
proof_by_index: input.packed_tree_info.prove_by_index,
52+
},
53+
root_index: input.packed_tree_info.root_index,
54+
lamports: input.lamports,
55+
tlv: input.tlv,
56+
}
57+
}
58+
}
59+
3160
/// Struct to provide the owner when the delegate is signer of the transaction.
3261
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)]
3362
pub struct DelegatedTransfer {
@@ -47,7 +76,7 @@ pub struct CompressedTokenInstructionDataTransfer {
4776
/// -> delegate is authority account,
4877
/// owner = Some(owner) is the owner of the token account.
4978
pub delegated_transfer: Option<DelegatedTransfer>,
50-
pub input_token_data_with_context: Vec<InputTokenDataWithContext>,
79+
pub input_token_data_with_context: Vec<InputTokenDataWithContextOnchain>,
5180
pub output_compressed_accounts: Vec<PackedTokenTransferOutputData>,
5281
pub is_compress: bool,
5382
pub compress_or_decompress_amount: Option<u64>,

0 commit comments

Comments
 (0)