Skip to content

Commit

Permalink
fixed naming inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block committed Mar 27, 2024
1 parent 03f10ad commit be243f0
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 50 deletions.
4 changes: 2 additions & 2 deletions js/compressed-token/src/get-compressed-token-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
16 changes: 12 additions & 4 deletions js/compressed-token/src/idl/psp_compressed_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ export type PspCompressedToken = {
};
},
{
name: 'indexMerkleTreeAccount';
name: 'merkleTreePubkeyIndex';
type: 'u8';
},
{
name: 'indexNullifierArrayAccount';
name: 'indexNullifierQueuePubkeyIndex';
type: 'u8';
},
{
Expand Down Expand Up @@ -327,6 +327,10 @@ export type PspCompressedToken = {
option: 'u64';
};
},
{
name: 'isCompress';
type: 'bool';
},
{
name: 'deCompressAmount';
type: {
Expand Down Expand Up @@ -903,11 +907,11 @@ export const IDL: PspCompressedToken = {
},
},
{
name: 'indexMerkleTreeAccount',
name: 'merkleTreePubkeyIndex',
type: 'u8',
},
{
name: 'indexNullifierArrayAccount',
name: 'indexNullifierQueuePubkeyIndex',
type: 'u8',
},
{
Expand Down Expand Up @@ -1026,6 +1030,10 @@ export const IDL: PspCompressedToken = {
option: 'u64',
},
},
{
name: 'isCompress',
type: 'bool',
},
{
name: 'deCompressAmount',
type: {
Expand Down
6 changes: 3 additions & 3 deletions js/compressed-token/src/instructions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand All @@ -64,7 +64,7 @@ export async function createTransferInstruction(
}
packedInputCompressedAccountsWithMerkleContext[
i
].indexNullifierArrayAccount = remainingAccountsMap.get(mt)!;
].nullifierQueuePubkeyIndex = remainingAccountsMap.get(mt)!;
});

outputStateTrees.forEach((mt, i) => {
Expand Down
16 changes: 12 additions & 4 deletions js/stateless.js/src/idls/psp_compressed_pda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ export type PspCompressedPda = {
};
},
{
name: 'indexMerkleTreeAccount';
name: 'merkleTreePubkeyIndex';
type: 'u8';
},
{
name: 'indexNullifierArrayAccount';
name: 'indexNullifierQueuePubkeyIndex';
type: 'u8';
},
{
Expand Down Expand Up @@ -221,6 +221,10 @@ export type PspCompressedPda = {
option: 'u64';
};
},
{
name: 'isCompress';
type: 'bool';
},
{
name: 'deCompressAmount';
type: {
Expand Down Expand Up @@ -556,11 +560,11 @@ export const IDL: PspCompressedPda = {
},
},
{
name: 'indexMerkleTreeAccount',
name: 'merkleTreePubkeyIndex',
type: 'u8',
},
{
name: 'indexNullifierArrayAccount',
name: 'indexNullifierQueuePubkeyIndex',
type: 'u8',
},
{
Expand Down Expand Up @@ -679,6 +683,10 @@ export const IDL: PspCompressedPda = {
option: 'u64',
},
},
{
name: 'isCompress',
type: 'bool',
},
{
name: 'deCompressAmount',
type: {
Expand Down
4 changes: 2 additions & 2 deletions js/stateless.js/src/instruction/pack-compressed-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export function packCompressedAccounts(
address: account.address,
data: account.data,
},
indexMerkleTreeAccount: indexMerkleTree,
indexNullifierArrayAccount: indexNullifierQueue,
merkleTreePubkeyIndex: indexMerkleTree,
nullifierQueuePubkeyIndex: indexNullifierQueue,
leafIndex: account.leafIndex,
});
});
Expand Down
5 changes: 3 additions & 2 deletions js/stateless.js/src/state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -43,6 +43,7 @@ export interface PublicTransactionEvent {
outputLeafIndices: number[]; // Vec<u32>
relayFee: BN | null; // Option<u64>
deCompressAmount: BN | null; // Option<u64>
isCompress: boolean; // bool
pubkeyArray: PublicKey[]; // Vec<PublicKey>
message: Uint8Array | null; // Option<bytes>
}
Expand Down
4 changes: 2 additions & 2 deletions programs/compressed-pda/src/compressed_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 2 additions & 0 deletions programs/compressed-pda/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct PublicTransactionEvent {
pub output_state_merkle_tree_account_indices: Vec<u8>,
pub output_leaf_indices: Vec<u32>,
pub relay_fee: Option<u64>,
pub is_compress: bool,
pub de_compress_amount: Option<u64>,
pub pubkey_array: Vec<Pubkey>,
pub message: Option<Vec<u8>>,
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions programs/compressed-pda/src/nullify_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<Pubkey>>();
let mut indexed_array_account_infos = Vec::<AccountInfo>::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::<IndexedArrayAccount>::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()?;
Expand All @@ -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());
}
}
Expand Down
18 changes: 9 additions & 9 deletions programs/compressed-pda/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
}
Expand All @@ -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();
Expand Down Expand Up @@ -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!(
Expand Down
20 changes: 10 additions & 10 deletions programs/compressed-pda/src/verify_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn fetch_roots<'a, 'b, 'c: 'info, 'info>(
{
let merkle_tree = AccountLoader::<StateMerkleTreeAccount>::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()?;
Expand Down Expand Up @@ -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,
)?;
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
},
];
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
},
];
Expand Down
4 changes: 2 additions & 2 deletions programs/compressed-pda/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions programs/compressed-token/src/process_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions programs/compressed-token/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be243f0

Please sign in to comment.