Skip to content

Commit d9c9c0d

Browse files
committed
refactor: ctoken-types remove legacy instruction data, move types to mint_action dir
1 parent 1984540 commit d9c9c0d

Some content is hidden

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

60 files changed

+370
-798
lines changed

program-libs/ctoken-types/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ pub enum CTokenError {
101101

102102
#[error("Light compressed account error: {0}")]
103103
CompressedAccountError(#[from] light_compressed_account::CompressedAccountError),
104+
105+
#[error("Invalid token metadata version")]
106+
InvalidTokenMetadataVersion,
104107
}
105108

106109
impl From<CTokenError> for u32 {
@@ -136,6 +139,7 @@ impl From<CTokenError> for u32 {
136139
CTokenError::ZeroCopyExpectedFreezeAuthority => 18027,
137140
CTokenError::InvalidAuthorityType => 18029,
138141
CTokenError::ExpectedMintSignerAccount => 18030,
142+
CTokenError::InvalidTokenMetadataVersion => 18031,
139143
CTokenError::HasherError(e) => u32::from(e),
140144
CTokenError::ZeroCopyError(e) => u32::from(e),
141145
CTokenError::CompressedAccountError(e) => u32::from(e),

program-libs/ctoken-types/src/instructions/create_spl_mint.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

program-libs/ctoken-types/src/instructions/extensions/metadata_pointer.rs

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use light_compressed_account::instruction_data::zero_copy_set::CompressedCpiContextTrait;
2+
use light_zero_copy::{ZeroCopy, ZeroCopyMut};
3+
4+
use crate::{AnchorDeserialize, AnchorSerialize};
5+
6+
#[repr(C)]
7+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy, ZeroCopyMut)]
8+
pub struct CpiContext {
9+
pub set_context: bool,
10+
pub first_set_context: bool,
11+
// Used as address tree index if create mint
12+
pub in_tree_index: u8,
13+
pub in_queue_index: u8,
14+
pub out_queue_index: u8,
15+
pub token_out_queue_index: u8,
16+
// Index of the compressed account that should receive the new address (0 = mint, 1+ = token accounts)
17+
pub assigned_account_index: u8,
18+
}
19+
20+
impl CompressedCpiContextTrait for ZCpiContext<'_> {
21+
fn first_set_context(&self) -> u8 {
22+
if self.first_set_context == 0 {
23+
0
24+
} else {
25+
1
26+
}
27+
}
28+
29+
fn set_context(&self) -> u8 {
30+
if self.set_context == 0 {
31+
0
32+
} else {
33+
1
34+
}
35+
}
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use light_zero_copy::ZeroCopy;
2+
3+
use crate::{AnchorDeserialize, AnchorSerialize};
4+
5+
#[repr(C)]
6+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
7+
pub struct CreateSplMintAction {
8+
pub mint_bump: u8,
9+
}

program-libs/ctoken-types/src/instructions/create_compressed_mint.rs renamed to program-libs/ctoken-types/src/instructions/mint_action/instruction_data.rs

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use light_compressed_account::{
2-
instruction_data::{
3-
compressed_proof::CompressedProof, zero_copy_set::CompressedCpiContextTrait,
4-
},
5-
Pubkey,
6-
};
7-
use light_zero_copy::{ZeroCopy, ZeroCopyMut};
1+
use light_compressed_account::{instruction_data::compressed_proof::CompressedProof, Pubkey};
2+
use light_zero_copy::ZeroCopy;
83

4+
use super::{
5+
CpiContext, CreateSplMintAction, MintToAction, MintToDecompressedAction,
6+
RemoveMetadataKeyAction, UpdateAuthority, UpdateMetadataAuthorityAction,
7+
UpdateMetadataFieldAction,
8+
};
99
use crate::{
1010
instructions::extensions::ExtensionInstructionData,
1111
state::{CompressedMint, ExtensionStruct},
@@ -14,20 +14,48 @@ use crate::{
1414

1515
#[repr(C)]
1616
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
17-
pub struct CreateCompressedMintInstructionData {
18-
pub decimals: u8,
19-
pub mint_authority: Pubkey,
17+
pub enum Action {
18+
/// Mint compressed tokens to compressed accounts.
19+
MintTo(MintToAction),
20+
/// Update mint authority of a compressed mint account.
21+
UpdateMintAuthority(UpdateAuthority),
22+
/// Update freeze authority of a compressed mint account.
23+
UpdateFreezeAuthority(UpdateAuthority),
24+
/// Create an spl mint for a cmint.
25+
/// - existing supply is minted to a token pool account.
26+
/// - mint and freeze authority are a ctoken pda.
27+
/// - is an spl-token-2022 mint account.
28+
CreateSplMint(CreateSplMintAction),
29+
/// Mint ctokens from a cmint to a ctoken solana account
30+
/// (tokens are not compressed but not spl tokens).
31+
MintToDecompressed(MintToDecompressedAction),
32+
UpdateMetadataField(UpdateMetadataFieldAction),
33+
UpdateMetadataAuthority(UpdateMetadataAuthorityAction),
34+
RemoveMetadataKey(RemoveMetadataKeyAction),
35+
}
36+
37+
#[repr(C)]
38+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
39+
pub struct MintActionCompressedInstructionData {
40+
pub create_mint: bool,
41+
/// Only used if create mint
2042
pub mint_bump: u8,
21-
pub address_merkle_tree_root_index: u16,
22-
// compressed address TODO: make a type CompressedAddress (not straight forward because of AnchorSerialize)
23-
pub mint_address: [u8; 32],
24-
pub version: u8,
25-
pub freeze_authority: Option<Pubkey>,
26-
pub extensions: Option<Vec<ExtensionInstructionData>>,
27-
pub cpi_context: Option<CpiContext>,
28-
/// To create the compressed mint account address a proof is always required.
29-
/// Set none if used with cpi context, the proof is required with the executing cpi.
43+
/// Only set if mint already exists
44+
pub leaf_index: u32,
45+
/// Only set if mint already exists
46+
pub prove_by_index: bool,
47+
/// If create mint, root index of address proof
48+
/// If mint already exists, root index of validity proof
49+
/// If proof by index not used.
50+
pub root_index: u16,
51+
pub compressed_address: [u8; 32],
52+
/// If some -> no input because we create mint
53+
pub mint: CompressedMintInstructionData,
54+
pub token_pool_bump: u8,
55+
pub token_pool_index: u8,
56+
pub actions: Vec<Action>,
3057
pub proof: Option<CompressedProof>,
58+
pub cpi_context: Option<CpiContext>,
3159
}
3260

3361
#[repr(C)]
@@ -72,14 +100,6 @@ impl TryFrom<CompressedMint> for CompressedMintInstructionData {
72100
let converted_exts: Result<Vec<_>, Self::Error> = exts
73101
.into_iter()
74102
.map(|ext| match ext {
75-
/* ExtensionStruct::MetadataPointer(metadata_pointer) => {
76-
Ok(ExtensionInstructionData::MetadataPointer(
77-
crate::instructions::extensions::metadata_pointer::InitMetadataPointer {
78-
authority: metadata_pointer.authority,
79-
metadata_address: metadata_pointer.metadata_address,
80-
},
81-
))
82-
}*/
83103
ExtensionStruct::TokenMetadata(token_metadata) => {
84104
Ok(ExtensionInstructionData::TokenMetadata(
85105
crate::instructions::extensions::token_metadata::TokenMetadataInstructionData {
@@ -112,32 +132,3 @@ impl TryFrom<CompressedMint> for CompressedMintInstructionData {
112132
})
113133
}
114134
}
115-
#[repr(C)]
116-
#[derive(
117-
Debug, Clone, PartialEq, Eq, AnchorSerialize, AnchorDeserialize, ZeroCopy, ZeroCopyMut,
118-
)]
119-
pub struct CpiContext {
120-
pub set_context: bool,
121-
pub first_set_context: bool,
122-
pub address_tree_index: u8,
123-
pub out_queue_index: u8,
124-
pub cpi_context_pubkey: Pubkey,
125-
}
126-
127-
impl CompressedCpiContextTrait for ZCpiContext<'_> {
128-
fn first_set_context(&self) -> u8 {
129-
if self.first_set_context == 0 {
130-
0
131-
} else {
132-
1
133-
}
134-
}
135-
136-
fn set_context(&self) -> u8 {
137-
if self.set_context == 0 {
138-
0
139-
} else {
140-
1
141-
}
142-
}
143-
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use light_compressed_account::Pubkey;
2+
use light_zero_copy::ZeroCopy;
3+
4+
use crate::{AnchorDeserialize, AnchorSerialize};
5+
6+
#[repr(C)]
7+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
8+
pub struct Recipient {
9+
pub recipient: Pubkey,
10+
pub amount: u64,
11+
}
12+
13+
#[repr(C)]
14+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
15+
pub struct MintToAction {
16+
pub token_account_version: u8,
17+
pub lamports: Option<u64>,
18+
pub recipients: Vec<Recipient>,
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use light_zero_copy::ZeroCopy;
2+
3+
use crate::{AnchorDeserialize, AnchorSerialize};
4+
5+
#[repr(C)]
6+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
7+
pub struct DecompressedRecipient {
8+
pub account_index: u8, // Index into remaining accounts for the recipient token account
9+
pub amount: u64,
10+
}
11+
12+
#[repr(C)]
13+
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
14+
pub struct MintToDecompressedAction {
15+
pub recipient: DecompressedRecipient,
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
mod cpi_context;
2+
mod create_spl_mint;
3+
mod instruction_data;
4+
mod mint_to;
5+
mod mint_to_decompressed;
6+
mod update_metadata;
7+
mod update_mint;
8+
9+
pub use cpi_context::*;
10+
pub use create_spl_mint::*;
11+
pub use instruction_data::*;
12+
pub use mint_to::*;
13+
pub use mint_to_decompressed::*;
14+
pub use update_metadata::*;
15+
pub use update_mint::*;

0 commit comments

Comments
 (0)