Skip to content

Commit f5a4484

Browse files
wip
1 parent d26e049 commit f5a4484

File tree

3 files changed

+80
-12
lines changed

3 files changed

+80
-12
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,13 @@ use borsh::BorshSerialize as AnchorSerialize;
66
use light_compressed_account::instruction_data::{
77
compressed_proof::CompressedProof, cpi_context::CompressedCpiContext,
88
};
9-
pub use light_compressed_token::process_transfer::CompressedTokenInstructionDataTransfer;
109
use solana_program::{
1110
instruction::{AccountMeta, Instruction},
1211
program_error::ProgramError,
1312
pubkey::Pubkey,
1413
};
1514

16-
/// From light-compressed-token::process_transfer::InputTokenDataWithContext.
17-
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)]
18-
pub struct InputTokenDataWithContext {
19-
pub amount: u64,
20-
pub delegate_index: Option<u8>,
21-
pub merkle_context: PackedMerkleContext,
22-
pub root_index: u16,
23-
pub lamports: Option<u64>,
24-
/// Placeholder for TokenExtension tlv data (unimplemented)
25-
pub tlv: Option<Vec<u8>>,
26-
}
15+
use crate::state::{CompressedTokenInstructionDataTransfer, InputTokenDataWithContext};
2716

2817
/// Return Instruction to decompress compressed token accounts.
2918
/// Proof can be None if prove_by_index is used.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod cpi;
2+
pub mod state;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#[cfg(feature = "anchor")]
2+
use anchor_lang::{AnchorDeserialize, AnchorSerialize};
3+
#[cfg(not(feature = "anchor"))]
4+
use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize};
5+
use light_compressed_account::{
6+
compressed_account::{CompressedAccountWithMerkleContext, PackedMerkleContext},
7+
instruction_data::{compressed_proof::CompressedProof, cpi_context::CompressedCpiContext},
8+
};
9+
use solana_program::pubkey::Pubkey;
10+
11+
#[derive(Clone, Copy, Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize)]
12+
#[repr(u8)]
13+
pub enum AccountState {
14+
Initialized,
15+
Frozen,
16+
}
17+
18+
#[derive(Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize, Clone)]
19+
pub struct TokenData {
20+
/// The mint associated with this account
21+
pub mint: Pubkey,
22+
/// The owner of this account.
23+
pub owner: Pubkey,
24+
/// The amount of tokens this account holds.
25+
pub amount: u64,
26+
/// If `delegate` is `Some` then `delegated_amount` represents
27+
/// the amount authorized by the delegate
28+
pub delegate: Option<Pubkey>,
29+
/// The account's state
30+
pub state: AccountState,
31+
/// Placeholder for TokenExtension tlv data (unimplemented)
32+
pub tlv: Option<Vec<u8>>,
33+
}
34+
35+
#[derive(Debug, Clone)]
36+
pub struct TokenDataWithMerkleContext {
37+
pub token_data: TokenData,
38+
pub compressed_account: CompressedAccountWithMerkleContext,
39+
}
40+
41+
#[derive(Debug, Clone, AnchorDeserialize, AnchorSerialize)]
42+
pub struct CompressedTokenInstructionDataTransfer {
43+
pub proof: Option<CompressedProof>,
44+
pub mint: Pubkey,
45+
/// Is required if the signer is delegate,
46+
/// -> delegate is authority account,
47+
/// owner = Some(owner) is the owner of the token account.
48+
pub delegated_transfer: Option<DelegatedTransfer>,
49+
pub input_token_data_with_context: Vec<InputTokenDataWithContext>,
50+
pub output_compressed_accounts: Vec<PackedTokenTransferOutputData>,
51+
pub is_compress: bool,
52+
pub compress_or_decompress_amount: Option<u64>,
53+
pub cpi_context: Option<CompressedCpiContext>,
54+
pub lamports_change_account_merkle_tree_index: Option<u8>,
55+
pub with_transaction_hash: bool,
56+
}
57+
58+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)]
59+
pub struct InputTokenDataWithContext {
60+
pub amount: u64,
61+
pub delegate_index: Option<u8>,
62+
pub merkle_context: PackedMerkleContext,
63+
pub root_index: u16,
64+
pub lamports: Option<u64>,
65+
/// Placeholder for TokenExtension tlv data (unimplemented)
66+
pub tlv: Option<Vec<u8>>,
67+
}
68+
69+
/// Struct to provide the owner when the delegate is signer of the transaction.
70+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)]
71+
pub struct DelegatedTransfer {
72+
pub owner: Pubkey,
73+
/// Index of change compressed account in output compressed accounts. In
74+
/// case that the delegate didn't spend the complete delegated compressed
75+
/// account balance the change compressed account will be delegated to her
76+
/// as well.
77+
pub delegate_change_account_index: Option<u8>,
78+
}

0 commit comments

Comments
 (0)