|
| 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