Skip to content

Commit 3e77129

Browse files
committed
fix: mint to create spl mint ix data
1 parent 1b085b0 commit 3e77129

File tree

16 files changed

+103
-84
lines changed

16 files changed

+103
-84
lines changed

program-libs/compressed-account/src/instruction_data/zero_copy_set.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl ZOutputCompressedAccountWithPackedContextMut<'_> {
5050
// TODO: unit test
5151
impl ZInAccountMut<'_> {
5252
#[inline]
53-
pub fn set(
53+
pub fn set_z(
5454
&mut self,
5555
discriminator: [u8; 8],
5656
data_hash: [u8; 32],
@@ -81,6 +81,39 @@ impl ZInAccountMut<'_> {
8181
}
8282
Ok(())
8383
}
84+
85+
#[inline]
86+
pub fn set(
87+
&mut self,
88+
discriminator: [u8; 8],
89+
data_hash: [u8; 32],
90+
merkle_context: &PackedMerkleContext,
91+
root_index: U16,
92+
lamports: u64,
93+
address: Option<&[u8]>,
94+
) -> Result<(), CompressedAccountError> {
95+
self.discriminator = discriminator;
96+
// Set merkle context fields manually due to mutability constraints
97+
self.merkle_context.merkle_tree_pubkey_index = merkle_context.merkle_tree_pubkey_index;
98+
self.merkle_context.queue_pubkey_index = merkle_context.queue_pubkey_index;
99+
self.merkle_context
100+
.leaf_index
101+
.set(merkle_context.leaf_index);
102+
self.merkle_context.prove_by_index = merkle_context.prove_by_index as u8;
103+
*self.root_index = root_index;
104+
self.data_hash = data_hash;
105+
*self.lamports = lamports.into();
106+
if let Some(address) = address {
107+
self.address
108+
.as_mut()
109+
.ok_or(CompressedAccountError::InstructionDataExpectedAddress)?
110+
.copy_from_slice(address);
111+
}
112+
if self.address.is_some() && address.is_none() {
113+
return Err(CompressedAccountError::ZeroCopyExpectedAddress);
114+
}
115+
Ok(())
116+
}
84117
}
85118

86119
impl ZInstructionDataInvokeCpiWithReadOnlyMut<'_> {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use light_compressed_account::{
2-
compressed_account::PackedMerkleContext, instruction_data::compressed_proof::CompressedProof,
3-
Pubkey,
4-
};
1+
use light_compressed_account::{instruction_data::compressed_proof::CompressedProof, Pubkey};
52
use light_zero_copy::ZeroCopy;
63

74
use crate::{
@@ -26,7 +23,9 @@ pub struct CreateCompressedMintInstructionData {
2623

2724
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
2825
pub struct UpdateCompressedMintInstructionData {
29-
pub merkle_context: PackedMerkleContext,
26+
// pub merkle_context: PackedMerkleContext,
27+
pub leaf_index: u32,
28+
pub prove_by_index: bool,
3029
pub root_index: u16,
3130
pub address: [u8; 32],
3231
pub proof: Option<CompressedProof>,

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use light_compressed_account::{
2-
compressed_account::PackedMerkleContext, instruction_data::compressed_proof::CompressedProof,
3-
Pubkey,
4-
};
1+
use light_compressed_account::{instruction_data::compressed_proof::CompressedProof, Pubkey};
52
use light_zero_copy::ZeroCopy;
63

74
use crate::{
@@ -11,11 +8,11 @@ use crate::{
118

129
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
1310
pub struct CompressedMintInputs {
14-
pub merkle_context: PackedMerkleContext,
11+
pub leaf_index: u32,
12+
pub prove_by_index: bool,
1513
pub root_index: u16,
1614
pub address: [u8; 32],
1715
pub compressed_mint_input: CompressedMint, //TODO: move supply and authority last so that we can send only the hash chain.
18-
pub output_merkle_tree_index: u8,
1916
}
2017

2118
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]

programs/compressed-token/program/src/create_spl_mint/processor.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use light_ctoken_types::{
99
state::{CompressedMint, CompressedMintConfig},
1010
COMPRESSED_MINT_SEED,
1111
};
12+
use light_sdk::instruction::PackedMerkleContext;
1213
use light_zero_copy::{borsh::Deserialize, borsh_mut::DeserializeMut, ZeroCopyNew};
1314
use pinocchio::account_info::AccountInfo;
1415
use spl_token::solana_program::log::sol_log_compute_units;
@@ -85,9 +86,8 @@ pub fn process_create_spl_mint(
8586
Ok(())
8687
}
8788

88-
// TODO: remove tree indices from instructiond data we hardcode the order.
89-
//const IN_TREE: u8 = 0;
90-
//const IN_OUTPUT_QUEUE: u8 = 1;
89+
const IN_TREE: u8 = 0;
90+
const IN_OUTPUT_QUEUE: u8 = 1;
9191

9292
const OUT_OUTPUT_QUEUE: u8 = 2;
9393

@@ -146,6 +146,12 @@ fn update_compressed_mint_to_decompressed<'info>(
146146
&mut context,
147147
&instruction_data.mint,
148148
&hashed_mint_authority,
149+
PackedMerkleContext {
150+
leaf_index: instruction_data.mint.leaf_index.into(),
151+
prove_by_index: instruction_data.mint.prove_by_index(),
152+
merkle_tree_pubkey_index: IN_TREE,
153+
queue_pubkey_index: IN_OUTPUT_QUEUE,
154+
},
149155
)?;
150156

151157
// Process output compressed mint account (with is_decompressed = true)
@@ -181,7 +187,7 @@ fn update_compressed_mint_to_decompressed<'info>(
181187
mint_authority,
182188
mint_inputs.supply,
183189
mint_config,
184-
*instruction_data.mint.address,
190+
instruction_data.mint.address,
185191
OUT_OUTPUT_QUEUE,
186192
instruction_data.mint.mint.version,
187193
true, // Set is_decompressed = true for create_spl_mint

programs/compressed-token/program/src/mint/mint_input.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use light_ctoken_types::{
66
state::CompressedMint,
77
};
88
use light_hasher::{Hasher, Poseidon};
9+
use light_sdk::instruction::PackedMerkleContext;
910

1011
use crate::{
1112
constants::COMPRESSED_MINT_DISCRIMINATOR, extensions::processor::create_extension_hash_chain,
@@ -25,6 +26,7 @@ pub fn create_input_compressed_mint_account(
2526
context: &mut TokenContext,
2627
compressed_mint_inputs: &ZUpdateCompressedMintInstructionData,
2728
hashed_mint_authority: &[u8; 32],
29+
merkle_context: PackedMerkleContext,
2830
) -> Result<(), ProgramError> {
2931
// 2. Extract and validate compressed mint data
3032
let compressed_mint_input = &compressed_mint_inputs.mint;
@@ -75,8 +77,8 @@ pub fn create_input_compressed_mint_account(
7577
input_compressed_account.set(
7678
COMPRESSED_MINT_DISCRIMINATOR,
7779
data_hash,
78-
&compressed_mint_inputs.merkle_context,
79-
*compressed_mint_inputs.root_index,
80+
&merkle_context,
81+
compressed_mint_inputs.root_index,
8082
0,
8183
Some(compressed_mint_inputs.address.as_ref()),
8284
)?;

programs/compressed-token/program/src/mint_to_compressed/processor.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use light_ctoken_types::{
66
context::TokenContext, instructions::mint_to_compressed::MintToCompressedInstructionData,
77
state::CompressedMintConfig,
88
};
9+
use light_sdk::instruction::PackedMerkleContext;
910
use light_zero_copy::{borsh::Deserialize, ZeroCopyNew};
1011
use pinocchio::account_info::AccountInfo;
1112
use spl_token::solana_program::log::sol_log_compute_units;
@@ -76,6 +77,17 @@ pub fn process_mint_to_compressed(
7677
&mut context,
7778
&parsed_instruction_data.compressed_mint_inputs,
7879
&hashed_mint_authority,
80+
PackedMerkleContext {
81+
merkle_tree_pubkey_index: 0,
82+
queue_pubkey_index: 1,
83+
leaf_index: parsed_instruction_data
84+
.compressed_mint_inputs
85+
.leaf_index
86+
.into(),
87+
prove_by_index: parsed_instruction_data
88+
.compressed_mint_inputs
89+
.prove_by_index(),
90+
},
7991
)?;
8092

8193
let mint_inputs = &parsed_instruction_data.compressed_mint_inputs.mint;
@@ -112,7 +124,7 @@ pub fn process_mint_to_compressed(
112124
Some(Pubkey::from(*validated_accounts.authority.key())),
113125
supply,
114126
mint_config,
115-
*parsed_instruction_data.compressed_mint_inputs.address,
127+
parsed_instruction_data.compressed_mint_inputs.address,
116128
2,
117129
parsed_instruction_data.compressed_mint_inputs.mint.version,
118130
parsed_instruction_data

programs/compressed-token/program/src/shared/token_input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn set_input_compressed_account<const IS_FROZEN: bool>(
6363
};
6464

6565
input_compressed_account
66-
.set(
66+
.set_z(
6767
version.discriminator(),
6868
data_hash,
6969
&input_token_data.merkle_context,

sdk-libs/compressed-token-sdk/src/instructions/create_compressed_mint/account_metas.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ impl CreateCompressedMintMetaConfig {
2929
}
3030

3131
/// Create a new CreateCompressedMintMetaConfig for client-side (CPI) usage
32-
pub fn new_client(address_tree_pubkey: Pubkey, output_queue: Pubkey) -> Self {
32+
pub fn new_client(
33+
mint_seed: Pubkey,
34+
address_tree_pubkey: Pubkey,
35+
output_queue: Pubkey,
36+
) -> Self {
3337
Self {
3438
fee_payer: None,
35-
mint_signer: None,
39+
mint_signer: Some(mint_seed),
3640
address_tree_pubkey,
3741
output_queue,
3842
}

sdk-libs/compressed-token-sdk/src/instructions/create_compressed_mint/instruction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct CreateCompressedMintInputs {
2929
pub address_tree_pubkey: Pubkey,
3030
pub output_queue: Pubkey,
3131
pub extensions: Option<Vec<ExtensionInstructionData>>,
32+
pub version: u8,
3233
}
3334

3435
/// Creates a compressed mint instruction with a pre-computed mint address
@@ -47,7 +48,7 @@ pub fn create_compressed_mint_cpi(
4748
address_merkle_tree_root_index: input.address_merkle_tree_root_index,
4849
extensions: input.extensions,
4950
mint_address,
50-
version: 0,
51+
version: input.version,
5152
};
5253

5354
// Create account meta config for create_compressed_mint

sdk-libs/compressed-token-sdk/src/instructions/create_spl_mint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ pub fn create_spl_mint_instruction_with_bump(
7272
.is_none();
7373
// Create UpdateCompressedMintInstructionData from the compressed mint inputs
7474
let update_mint_data = UpdateCompressedMintInstructionData {
75-
merkle_context: compressed_mint_inputs.merkle_context,
75+
leaf_index: compressed_mint_inputs.leaf_index.into(),
76+
prove_by_index: compressed_mint_inputs.prove_by_index,
7677
root_index: compressed_mint_inputs.root_index,
7778
address: compressed_mint_inputs.address,
7879
proof: proof.into(),

0 commit comments

Comments
 (0)