Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add registry deposits, withdraws #1038

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pubkey":"C388ZXSoy5p9uQUpPAtFoJHwcYhts2Xu2ArWNJUgYyji","account":{"lamports":1781760,"data":["QuAuAqeJeGsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMqaOwAAAAACAAAAAAAAAADKmjsAAAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA=","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":128}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pubkey":"5Tpw5vUpnXzSKgGpEGHuxMRFtTz6Gt6hozVqu8e5fiqt","account":{"lamports":2345520,"data":["HXXTjWOP+nLMuMIVdedaPnWzorVHJCIvMcPXWnMDRUrSS6K/PzOqzAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADKmjsAAAAAAgAAAAAAAAAAypo7AAAAAGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAA=","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":209}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pubkey":"8KEKiyAMugpKq9XCGzx81UtTBuytByW8arm9EaBVpD5k","account":{"lamports":1670400,"data":["92V2ansKL5ECY+L7WEJcIRnY07lwy9TuaZBIebD9aqhznpq8Pv+mUf0AAAAAAAAAAP//////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":112}}
{"pubkey":"8KEKiyAMugpKq9XCGzx81UtTBuytByW8arm9EaBVpD5k","account":{"lamports":1844400,"data":["YLDvkgH+Y5ICY+L7WEJcIRnY07lwy9TuaZBIebD9aqhznpq8Pv+mUf0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADKmjsAAAAAAgAAAAAAAAAAypo7AAAAAGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":137}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pubkey":"BqDEaVeLffn32a2EnsmvFFmGK4ZZgqYrDkAxpGXc1ogj","account":{"lamports":1670400,"data":["BesVNs5W82rMuMIVdedaPnWzorVHJCIvMcPXWnMDRUrSS6K/PzOqzAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","base64"],"owner":"7Z9Yuy3HkBCc2Wf3xzMGnz6qpV4n7ciwcoEMGKqhAnj1","executable":false,"rentEpoch":18446744073709551615,"space":112}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use light_system_program::{
invoke::processor::CompressedProof,
sdk::{
address::{add_and_get_remaining_account_indices, pack_new_address_params},
compressed_account::{pack_merkle_context, CompressedAccount, MerkleContext},
compressed_account::{
pack_merkle_context, CompressedAccountWithMerkleContext, MerkleContext,
},
CompressedCpiContext,
},
NewAddressParams,
Expand All @@ -22,13 +24,12 @@ use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
pub struct CreateCompressedPdaEscrowInstructionInputs<'a> {
pub lock_up_time: u64,
pub signer: &'a Pubkey,
pub input_merkle_context: &'a [MerkleContext],
pub output_compressed_account_merkle_tree_pubkeys: &'a [Pubkey],
pub output_compressed_accounts: &'a [TokenTransferOutputData],
pub root_indices: &'a [u16],
pub proof: &'a Option<CompressedProof>,
pub input_token_data: &'a [light_compressed_token::token_data::TokenData],
pub input_compressed_accounts: &'a [CompressedAccount],
pub input_compressed_accounts: &'a [CompressedAccountWithMerkleContext],
pub mint: &'a Pubkey,
pub new_address_params: NewAddressParams,
pub cpi_context_account: &'a Pubkey,
Expand All @@ -42,7 +43,6 @@ pub fn create_escrow_instruction(
let (mut remaining_accounts, inputs) = create_inputs_and_remaining_accounts_checked(
input_params.input_token_data,
input_params.input_compressed_accounts,
input_params.input_merkle_context,
None,
input_params.output_compressed_accounts,
input_params.root_indices,
Expand Down Expand Up @@ -139,7 +139,7 @@ pub struct CreateCompressedPdaWithdrawalInstructionInputs<'a> {
pub root_indices: &'a [u16],
pub proof: &'a Option<CompressedProof>,
pub input_token_data: &'a [light_compressed_token::token_data::TokenData],
pub input_compressed_accounts: &'a [CompressedAccount],
pub input_compressed_accounts: &'a [CompressedAccountWithMerkleContext],
pub mint: &'a Pubkey,
pub old_lock_up_time: u64,
pub new_lock_up_time: u64,
Expand All @@ -155,7 +155,7 @@ pub fn create_withdrawal_instruction(
let (mut remaining_accounts, inputs) = create_inputs_and_remaining_accounts_checked(
input_params.input_token_data,
input_params.input_compressed_accounts,
&[input_params.input_token_escrow_merkle_context],
// &[input_params.input_token_escrow_merkle_context],
None,
input_params.output_compressed_accounts,
input_params.root_indices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use light_system_program::{
invoke::processor::CompressedProof,
sdk::{
address::add_and_get_remaining_account_indices,
compressed_account::{CompressedAccount, MerkleContext},
compressed_account::CompressedAccountWithMerkleContext,
},
};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
Expand All @@ -26,13 +26,13 @@ use crate::escrow_with_compressed_pda::sdk::get_token_owner_pda;
pub struct CreateEscrowInstructionInputs<'a> {
pub lock_up_time: u64,
pub signer: &'a Pubkey,
pub input_merkle_context: &'a [MerkleContext],
// pub input_merkle_context: &'a [MerkleContext],
pub output_compressed_account_merkle_tree_pubkeys: &'a [Pubkey],
pub output_compressed_accounts: &'a [TokenTransferOutputData],
pub root_indices: &'a [u16],
pub proof: &'a Option<CompressedProof>,
pub input_token_data: &'a [light_compressed_token::token_data::TokenData],
pub input_compressed_accounts: &'a [CompressedAccount],
pub input_compressed_accounts: &'a [CompressedAccountWithMerkleContext],
pub mint: &'a Pubkey,
}

Expand All @@ -50,7 +50,7 @@ pub fn create_escrow_instruction(
let (mut remaining_accounts, inputs) = create_inputs_and_remaining_accounts_checked(
input_params.input_token_data,
input_params.input_compressed_accounts,
input_params.input_merkle_context,
// input_params.input_mesrkle_context,
None,
input_params.output_compressed_accounts,
input_params.root_indices,
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn create_withdrawal_escrow_instruction(
let (mut remaining_accounts, inputs) = create_inputs_and_remaining_accounts(
input_params.input_token_data,
input_params.input_compressed_accounts,
input_params.input_merkle_context,
// input_params.input_merkle_context,
None,
input_params.output_compressed_accounts,
input_params.root_indices,
Expand Down
38 changes: 19 additions & 19 deletions examples/token-escrow/programs/token-escrow/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// release compressed tokens

use light_hasher::Poseidon;
use light_system_program::sdk::{compressed_account::MerkleContext, event::PublicTransactionEvent};
use light_system_program::sdk::event::PublicTransactionEvent;
use light_test_utils::airdrop_lamports;
use light_test_utils::indexer::{Indexer, TestIndexer};
use light_test_utils::spl::{create_mint_helper, mint_tokens_helper};
Expand Down Expand Up @@ -244,14 +244,14 @@ pub async fn perform_escrow<R: RpcConnection>(
input_token_data: &[input_compressed_token_account_data.token_data],
lock_up_time: *lock_up_time,
signer: &payer_pubkey,
input_merkle_context: &[MerkleContext {
leaf_index: compressed_input_account_with_context
.merkle_context
.leaf_index,
merkle_tree_pubkey: env.merkle_tree_pubkey,
nullifier_queue_pubkey: env.nullifier_queue_pubkey,
queue_index: None,
}],
// input_merkle_context: &[MerkleContext {
// leaf_index: compressed_input_account_with_context
// .merkle_context
// .leaf_index,
// merkle_tree_pubkey: env.merkle_tree_pubkey,
// nullifier_queue_pubkey: env.nullifier_queue_pubkey,
// queue_index: None,
// }],
output_compressed_account_merkle_tree_pubkeys: &[
env.merkle_tree_pubkey,
env.merkle_tree_pubkey,
Expand All @@ -260,7 +260,7 @@ pub async fn perform_escrow<R: RpcConnection>(
root_indices: &rpc_result.root_indices,
proof: &Some(rpc_result.proof),
mint: &input_compressed_token_account_data.token_data.mint,
input_compressed_accounts: &[compressed_input_account_with_context.compressed_account],
input_compressed_accounts: &[compressed_input_account_with_context],
};
create_escrow_instruction(create_ix_inputs, *escrow_amount)
}
Expand Down Expand Up @@ -401,14 +401,14 @@ pub async fn perform_withdrawal<R: RpcConnection>(
input_token_data: &[escrow_token_data_with_context.token_data],
lock_up_time: 0,
signer: &payer_pubkey,
input_merkle_context: &[MerkleContext {
leaf_index: compressed_input_account_with_context
.merkle_context
.leaf_index,
merkle_tree_pubkey: env.merkle_tree_pubkey,
nullifier_queue_pubkey: env.nullifier_queue_pubkey,
queue_index: None,
}],
// input_merkle_context: &[MerkleContext {
// leaf_index: compressed_input_account_with_context
// .merkle_context
// .leaf_index,
// merkle_tree_pubkey: env.merkle_tree_pubkey,
// nullifier_queue_pubkey: env.nullifier_queue_pubkey,
// queue_index: None,
// }],
output_compressed_account_merkle_tree_pubkeys: &[
env.merkle_tree_pubkey,
env.merkle_tree_pubkey,
Expand All @@ -417,7 +417,7 @@ pub async fn perform_withdrawal<R: RpcConnection>(
root_indices: &rpc_result.root_indices,
proof: &Some(rpc_result.proof),
mint: &escrow_token_data_with_context.token_data.mint,
input_compressed_accounts: &[compressed_input_account_with_context.compressed_account],
input_compressed_accounts: &[compressed_input_account_with_context],
};

create_withdrawal_escrow_instruction(create_ix_inputs, *withdrawal_amount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ async fn test_escrow_with_compressed_pda() {
let rpc_error = RpcError::TransactionError(transaction_error);
assert!(matches!(result, Err(error) if error.to_string() == rpc_error.to_string()));

rpc.warp_to_slot(lock_up_time + 1).unwrap();

rpc.warp_to_slot(lockup_end + 1).unwrap();
perform_withdrawal_with_event(
&mut rpc,
&mut test_indexer,
Expand Down Expand Up @@ -251,14 +250,14 @@ async fn create_escrow_ix<R: RpcConnection>(
input_token_data: &[input_compressed_token_account_data.token_data],
lock_up_time,
signer: &payer_pubkey,
input_merkle_context: &[MerkleContext {
leaf_index: compressed_input_account_with_context
.merkle_context
.leaf_index,
merkle_tree_pubkey: env.merkle_tree_pubkey,
nullifier_queue_pubkey: env.nullifier_queue_pubkey,
queue_index: None,
}],
// input_merkle_context: &[MerkleContext {
// leaf_index: compressed_input_account_with_context
// .merkle_context
// .leaf_index,
// merkle_tree_pubkey: env.merkle_tree_pubkey,
// nullifier_queue_pubkey: env.nullifier_queue_pubkey,
// queue_index: None,
// }],
output_compressed_account_merkle_tree_pubkeys: &[
env.merkle_tree_pubkey,
env.merkle_tree_pubkey,
Expand All @@ -269,7 +268,7 @@ async fn create_escrow_ix<R: RpcConnection>(
mint: &input_compressed_token_account_data.token_data.mint,
new_address_params,
cpi_context_account: &env.cpi_context_account_pubkey,
input_compressed_accounts: &[compressed_input_account_with_context.compressed_account],
input_compressed_accounts: &[compressed_input_account_with_context],
};
let instruction = create_escrow_instruction(create_ix_inputs.clone(), escrow_amount);
(payer_pubkey, instruction)
Expand Down Expand Up @@ -482,7 +481,7 @@ pub async fn perform_withdrawal<R: RpcConnection>(
old_lock_up_time,
new_lock_up_time,
address: compressed_escrow_pda.compressed_account.address.unwrap(),
input_compressed_accounts: &[compressed_escrow_pda.compressed_account],
input_compressed_accounts: &[compressed_escrow_pda],
};
create_withdrawal_instruction(create_withdrawal_ix_inputs.clone(), escrow_amount)
}
Expand Down
11 changes: 7 additions & 4 deletions forester/src/nullifier/address/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::{ForesterConfig, RpcPool};
use account_compression::utils::constants::{
ADDRESS_MERKLE_TREE_CHANGELOG, ADDRESS_MERKLE_TREE_INDEXED_CHANGELOG,
};
use light_registry::sdk::{

use light_registry::account_compression_cpi::sdk::{
create_update_address_merkle_tree_instruction, UpdateAddressMerkleTreeInstructionInputs,
};
use light_test_utils::indexer::Indexer;
Expand Down Expand Up @@ -268,8 +269,8 @@ pub async fn update_merkle_tree<R: RpcConnection>(
) -> Result<bool, ForesterError> {
let start = Instant::now();

let update_ix =
create_update_address_merkle_tree_instruction(UpdateAddressMerkleTreeInstructionInputs {
let update_ix = create_update_address_merkle_tree_instruction(
UpdateAddressMerkleTreeInstructionInputs {
authority: config.payer_keypair.pubkey(),
address_merkle_tree: tree_data.tree_pubkey,
address_queue: tree_data.queue_pubkey,
Expand All @@ -283,7 +284,9 @@ pub async fn update_merkle_tree<R: RpcConnection>(
indexed_changelog_index: ((account_data.proof.root_seq - 1)
% ADDRESS_MERKLE_TREE_INDEXED_CHANGELOG)
as u16,
});
},
0, // TODO: add correct epoch
);

// Prepare the instructions
let instructions = vec![
Expand Down
Loading