diff --git a/js/compressed-token/src/get-compressed-token-accounts.ts b/js/compressed-token/src/get-compressed-token-accounts.ts index f184d0aa13..bf7a315311 100644 --- a/js/compressed-token/src/get-compressed-token-accounts.ts +++ b/js/compressed-token/src/get-compressed-token-accounts.ts @@ -60,9 +60,9 @@ async function parseEventWithTokenTlvData( const inputCompressedAccountWithParsedTokenData: CompressedAccountWithParsedTokenData[] = event.inputCompressedAccounts.map((compressedAccount, i) => { const merkleContext: MerkleContext = { - merkleTree: pubkeyArray[compressedAccount.indexMerkleTreeAccount], + merkleTree: pubkeyArray[compressedAccount.merkleTreePubkeyIndex], nullifierQueue: - pubkeyArray[compressedAccount.indexNullifierArrayAccount], + pubkeyArray[compressedAccount.nullifierQueuePubkeyIndex], hash: inputHashes[i], leafIndex: compressedAccount.leafIndex, }; diff --git a/js/compressed-token/src/idl/psp_compressed_token.ts b/js/compressed-token/src/idl/psp_compressed_token.ts index c4352afea6..c9786ed97c 100644 --- a/js/compressed-token/src/idl/psp_compressed_token.ts +++ b/js/compressed-token/src/idl/psp_compressed_token.ts @@ -204,11 +204,11 @@ export type PspCompressedToken = { }; }, { - name: 'indexMerkleTreeAccount'; + name: 'merkleTreePubkeyIndex'; type: 'u8'; }, { - name: 'indexNullifierArrayAccount'; + name: 'indexNullifierQueuePubkeyIndex'; type: 'u8'; }, { @@ -327,6 +327,10 @@ export type PspCompressedToken = { option: 'u64'; }; }, + { + name: 'isCompress'; + type: 'bool'; + }, { name: 'deCompressAmount'; type: { @@ -903,11 +907,11 @@ export const IDL: PspCompressedToken = { }, }, { - name: 'indexMerkleTreeAccount', + name: 'merkleTreePubkeyIndex', type: 'u8', }, { - name: 'indexNullifierArrayAccount', + name: 'indexNullifierQueuePubkeyIndex', type: 'u8', }, { @@ -1026,6 +1030,10 @@ export const IDL: PspCompressedToken = { option: 'u64', }, }, + { + name: 'isCompress', + type: 'bool', + }, { name: 'deCompressAmount', type: { diff --git a/js/compressed-token/src/instructions/transfer.ts b/js/compressed-token/src/instructions/transfer.ts index a5cc68426b..a0506c1c6b 100644 --- a/js/compressed-token/src/instructions/transfer.ts +++ b/js/compressed-token/src/instructions/transfer.ts @@ -52,8 +52,8 @@ export async function createTransferInstruction( inputCompressedAccount.data = null; packedInputCompressedAccountsWithMerkleContext.push({ compressedAccount: inputCompressedAccount, - indexMerkleTreeAccount: remainingAccountsMap.get(mt)!, - indexNullifierArrayAccount: 0, // Will be set in the next loop + merkleTreePubkeyIndex: remainingAccountsMap.get(mt)!, + nullifierQueuePubkeyIndex: 0, // Will be set in the next loop leafIndex: inputCompressedAccount.leafIndex, }); }); @@ -64,7 +64,7 @@ export async function createTransferInstruction( } packedInputCompressedAccountsWithMerkleContext[ i - ].indexNullifierArrayAccount = remainingAccountsMap.get(mt)!; + ].nullifierQueuePubkeyIndex = remainingAccountsMap.get(mt)!; }); outputStateTrees.forEach((mt, i) => { diff --git a/js/stateless.js/src/idls/psp_compressed_pda.ts b/js/stateless.js/src/idls/psp_compressed_pda.ts index 24c9904b62..474e530da3 100644 --- a/js/stateless.js/src/idls/psp_compressed_pda.ts +++ b/js/stateless.js/src/idls/psp_compressed_pda.ts @@ -98,11 +98,11 @@ export type PspCompressedPda = { }; }, { - name: 'indexMerkleTreeAccount'; + name: 'merkleTreePubkeyIndex'; type: 'u8'; }, { - name: 'indexNullifierArrayAccount'; + name: 'indexNullifierQueuePubkeyIndex'; type: 'u8'; }, { @@ -221,6 +221,10 @@ export type PspCompressedPda = { option: 'u64'; }; }, + { + name: 'isCompress'; + type: 'bool'; + }, { name: 'deCompressAmount'; type: { @@ -556,11 +560,11 @@ export const IDL: PspCompressedPda = { }, }, { - name: 'indexMerkleTreeAccount', + name: 'merkleTreePubkeyIndex', type: 'u8', }, { - name: 'indexNullifierArrayAccount', + name: 'indexNullifierQueuePubkeyIndex', type: 'u8', }, { @@ -679,6 +683,10 @@ export const IDL: PspCompressedPda = { option: 'u64', }, }, + { + name: 'isCompress', + type: 'bool', + }, { name: 'deCompressAmount', type: { diff --git a/js/stateless.js/src/instruction/pack-compressed-accounts.ts b/js/stateless.js/src/instruction/pack-compressed-accounts.ts index a1a0b3c245..eb3f343d72 100644 --- a/js/stateless.js/src/instruction/pack-compressed-accounts.ts +++ b/js/stateless.js/src/instruction/pack-compressed-accounts.ts @@ -102,8 +102,8 @@ export function packCompressedAccounts( address: account.address, data: account.data, }, - indexMerkleTreeAccount: indexMerkleTree, - indexNullifierArrayAccount: indexNullifierQueue, + merkleTreePubkeyIndex: indexMerkleTree, + nullifierQueuePubkeyIndex: indexNullifierQueue, leafIndex: account.leafIndex, }); }); diff --git a/js/stateless.js/src/state/types.ts b/js/stateless.js/src/state/types.ts index 58f9f63c0a..46746fffd5 100644 --- a/js/stateless.js/src/state/types.ts +++ b/js/stateless.js/src/state/types.ts @@ -4,8 +4,8 @@ import { PublicKey } from '@solana/web3.js'; /// TODO: Consider flattening and implementing an IR in Beet. export interface PackedCompressedAccountWithMerkleContext { compressedAccount: CompressedAccount; - indexMerkleTreeAccount: number; // u8 - indexNullifierArrayAccount: number; // u8 + merkleTreePubkeyIndex: number; // u8 + nullifierQueuePubkeyIndex: number; // u8 leafIndex: number; // u32 FIXME: switch on-chain to u64. // Missing: hash } @@ -43,6 +43,7 @@ export interface PublicTransactionEvent { outputLeafIndices: number[]; // Vec relayFee: BN | null; // Option deCompressAmount: BN | null; // Option + isCompress: boolean; // bool pubkeyArray: PublicKey[]; // Vec message: Uint8Array | null; // Option } diff --git a/programs/compressed-pda/src/compressed_account.rs b/programs/compressed-pda/src/compressed_account.rs index f1dd5f5477..2bd71664d0 100644 --- a/programs/compressed-pda/src/compressed_account.rs +++ b/programs/compressed-pda/src/compressed_account.rs @@ -5,8 +5,8 @@ use light_utils::hash_to_bn254_field_size_le; #[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)] pub struct CompressedAccountWithMerkleContext { pub compressed_account: CompressedAccount, - pub index_merkle_tree_account: u8, - pub index_nullifier_array_account: u8, + pub merkle_tree_pubkey_index: u8, + pub index_nullifier_queue_pubkey_index: u8, pub leaf_index: u32, } diff --git a/programs/compressed-pda/src/event.rs b/programs/compressed-pda/src/event.rs index e3caae3e11..d7893ced19 100644 --- a/programs/compressed-pda/src/event.rs +++ b/programs/compressed-pda/src/event.rs @@ -20,6 +20,7 @@ pub struct PublicTransactionEvent { pub output_state_merkle_tree_account_indices: Vec, pub output_leaf_indices: Vec, pub relay_fee: Option, + pub is_compress: bool, pub de_compress_amount: Option, pub pubkey_array: Vec, pub message: Option>, @@ -65,6 +66,7 @@ pub fn emit_state_transition_event<'a, 'b, 'c: 'info, 'info>( pubkey_array: ctx.remaining_accounts.iter().map(|x| x.key()).collect(), de_compress_amount: None, message: None, + is_compress: false, }; invoke_indexer_transaction_event(&event, &ctx.accounts.noop_program)?; Ok(event) diff --git a/programs/compressed-pda/src/nullify_state.rs b/programs/compressed-pda/src/nullify_state.rs index a8f204962c..db79ed2c78 100644 --- a/programs/compressed-pda/src/nullify_state.rs +++ b/programs/compressed-pda/src/nullify_state.rs @@ -15,14 +15,15 @@ pub fn insert_nullifiers<'a, 'b, 'c: 'info, 'info>( let state_merkle_tree_pubkeys = inputs .input_compressed_accounts_with_merkle_context .iter() - .map(|account| ctx.remaining_accounts[account.index_merkle_tree_account as usize].key()) + .map(|account| ctx.remaining_accounts[account.merkle_tree_pubkey_index as usize].key()) .collect::>(); let mut indexed_array_account_infos = Vec::::new(); for account in inputs.input_compressed_accounts_with_merkle_context.iter() { - indexed_array_account_infos - .push(ctx.remaining_accounts[account.index_nullifier_array_account as usize].clone()); + indexed_array_account_infos.push( + ctx.remaining_accounts[account.index_nullifier_queue_pubkey_index as usize].clone(), + ); let unpacked_queue_account = AccountLoader::::try_from( - &ctx.remaining_accounts[account.index_nullifier_array_account as usize], + &ctx.remaining_accounts[account.index_nullifier_queue_pubkey_index as usize], ) .unwrap(); let array_account = unpacked_queue_account.load()?; @@ -34,7 +35,7 @@ pub fn insert_nullifiers<'a, 'b, 'c: 'info, 'info>( if !account_is_associated_with_state_merkle_tree { msg!( "Nullifier queue account {:?} is not associated with any state Merkle tree. Provided state Merkle trees {:?}", - ctx.remaining_accounts[account.index_nullifier_array_account as usize].key(), state_merkle_tree_pubkeys); + ctx.remaining_accounts[account.index_nullifier_queue_pubkey_index as usize].key(), state_merkle_tree_pubkeys); return Err(crate::ErrorCode::InvalidNullifierQueue.into()); } } diff --git a/programs/compressed-pda/src/sdk.rs b/programs/compressed-pda/src/sdk.rs index e266997c03..e196591f16 100644 --- a/programs/compressed-pda/src/sdk.rs +++ b/programs/compressed-pda/src/sdk.rs @@ -42,8 +42,8 @@ pub fn create_execute_compressed_instruction( }; _input_compressed_accounts.push(CompressedAccountWithMerkleContext { compressed_account: input_compressed_accounts[i].clone(), - index_merkle_tree_account: *remaining_accounts.get(mt).unwrap() as u8, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: *remaining_accounts.get(mt).unwrap() as u8, + index_nullifier_queue_pubkey_index: 0, leaf_index: input_compressed_accounts_leaf_indices[i], }); } @@ -55,7 +55,7 @@ pub fn create_execute_compressed_instruction( remaining_accounts.insert(*mt, i + len); } }; - _input_compressed_accounts[i].index_nullifier_array_account = + _input_compressed_accounts[i].index_nullifier_queue_pubkey_index = *remaining_accounts.get(mt).unwrap() as u8; } let len: usize = remaining_accounts.len(); @@ -376,36 +376,36 @@ mod test { assert_eq!(instruction.accounts[0], ref_account_meta); assert_eq!( deserialized_instruction_data.input_compressed_accounts_with_merkle_context[0] - .index_nullifier_array_account, + .index_nullifier_queue_pubkey_index, 1 ); assert_eq!( deserialized_instruction_data.input_compressed_accounts_with_merkle_context[1] - .index_nullifier_array_account, + .index_nullifier_queue_pubkey_index, 1 ); assert_eq!( instruction.accounts[7 + deserialized_instruction_data .input_compressed_accounts_with_merkle_context[0] - .index_merkle_tree_account as usize], + .merkle_tree_pubkey_index as usize], AccountMeta::new(merkle_tree_pubkey, false) ); assert_eq!( instruction.accounts[7 + deserialized_instruction_data .input_compressed_accounts_with_merkle_context[1] - .index_merkle_tree_account as usize], + .merkle_tree_pubkey_index as usize], AccountMeta::new(merkle_tree_pubkey, false) ); assert_eq!( instruction.accounts[7 + deserialized_instruction_data .input_compressed_accounts_with_merkle_context[0] - .index_nullifier_array_account as usize], + .index_nullifier_queue_pubkey_index as usize], AccountMeta::new(nullifier_array_pubkey, false) ); assert_eq!( instruction.accounts[7 + deserialized_instruction_data .input_compressed_accounts_with_merkle_context[1] - .index_nullifier_array_account as usize], + .index_nullifier_queue_pubkey_index as usize], AccountMeta::new(nullifier_array_pubkey, false) ); assert_eq!( diff --git a/programs/compressed-pda/src/verify_state.rs b/programs/compressed-pda/src/verify_state.rs index ad5be74044..5eea8edd5c 100644 --- a/programs/compressed-pda/src/verify_state.rs +++ b/programs/compressed-pda/src/verify_state.rs @@ -25,7 +25,7 @@ pub fn fetch_roots<'a, 'b, 'c: 'info, 'info>( { let merkle_tree = AccountLoader::::try_from( &ctx.remaining_accounts - [input_compressed_account_with_context.index_merkle_tree_account as usize], + [input_compressed_account_with_context.merkle_tree_pubkey_index as usize], ) .unwrap(); let merkle_tree = merkle_tree.load()?; @@ -88,7 +88,7 @@ pub fn hash_input_compressed_accounts<'a, 'b, 'c: 'info, 'info>( .compressed_account .hash( &ctx.remaining_accounts - [input_compressed_account_with_context.index_merkle_tree_account as usize] + [input_compressed_account_with_context.merkle_tree_pubkey_index as usize] .key(), &input_compressed_account_with_context.leaf_index, )?; @@ -465,8 +465,8 @@ mod test { address: None, data: None, }, - index_merkle_tree_account: 0, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: 0, + index_nullifier_queue_pubkey_index: 0, leaf_index: 0, }, CompressedAccountWithMerkleContext { @@ -476,8 +476,8 @@ mod test { address: None, data: None, }, - index_merkle_tree_account: 0, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: 0, + index_nullifier_queue_pubkey_index: 0, leaf_index: 1, }, ]; @@ -510,8 +510,8 @@ mod test { address: None, data: None, }, - index_merkle_tree_account: 0, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: 0, + index_nullifier_queue_pubkey_index: 0, leaf_index: 0, }, CompressedAccountWithMerkleContext { @@ -521,8 +521,8 @@ mod test { address: None, data: None, }, - index_merkle_tree_account: 0, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: 0, + index_nullifier_queue_pubkey_index: 0, leaf_index: 1, }, ]; diff --git a/programs/compressed-pda/tests/test.rs b/programs/compressed-pda/tests/test.rs index a19281005c..17505215d1 100644 --- a/programs/compressed-pda/tests/test.rs +++ b/programs/compressed-pda/tests/test.rs @@ -655,8 +655,8 @@ impl MockIndexer { .push(CompressedAccountWithMerkleContext { compressed_account: compressed_account.clone(), leaf_index: event.output_leaf_indices[i as usize], - index_merkle_tree_account: 0, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: 0, + index_nullifier_queue_pubkey_index: 0, }); indices.push(self.compressed_accounts.len() - 1); self.merkle_tree diff --git a/programs/compressed-token/src/process_transfer.rs b/programs/compressed-token/src/process_transfer.rs index af099a0088..f6d31bac29 100644 --- a/programs/compressed-token/src/process_transfer.rs +++ b/programs/compressed-token/src/process_transfer.rs @@ -435,8 +435,8 @@ pub mod transfer_sdk { input_compressed_accounts_with_merkle_context.push( CompressedAccountWithMerkleContext { compressed_account: input_compressed_account, - index_merkle_tree_account: *remaining_accounts.get(mt).unwrap() as u8, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: *remaining_accounts.get(mt).unwrap() as u8, + index_nullifier_queue_pubkey_index: 0, leaf_index: *leaf_index, }, ); @@ -449,7 +449,7 @@ pub mod transfer_sdk { remaining_accounts.insert(*mt, i + len); } }; - input_compressed_accounts_with_merkle_context[i].index_nullifier_array_account = + input_compressed_accounts_with_merkle_context[i].index_nullifier_queue_pubkey_index = *remaining_accounts.get(mt).unwrap() as u8; } let len: usize = remaining_accounts.len(); diff --git a/programs/compressed-token/tests/test.rs b/programs/compressed-token/tests/test.rs index 1974e3ac8e..26e513e593 100644 --- a/programs/compressed-token/tests/test.rs +++ b/programs/compressed-token/tests/test.rs @@ -1319,8 +1319,8 @@ impl MockIndexer { .push(CompressedAccountWithMerkleContext { compressed_account: compressed_account.clone(), leaf_index: event.output_leaf_indices[i as usize], - index_merkle_tree_account: 0, - index_nullifier_array_account: 0, + merkle_tree_pubkey_index: 0, + index_nullifier_queue_pubkey_index: 0, }); indices.push(self.compressed_accounts.len() - 1); self.merkle_tree