Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ async fn test_batch_state_merkle_tree() {

let payer_pubkey = context.get_payer().pubkey();
let payer = context.get_payer().insecure_clone();
let params = InitStateTreeAccountsInstructionData::test_default();
let mut params = InitStateTreeAccountsInstructionData::test_default();
// Use network_fee below reimbursement threshold since this test
// bypasses the system program (no fees accumulate in the queue).
params.network_fee = Some(1);
let queue_account_size = get_output_queue_account_size(
params.output_queue_batch_size,
params.output_queue_zkp_batch_size,
Expand Down Expand Up @@ -752,6 +755,7 @@ pub async fn perform_batch_append(
log_wrapper: NOOP_PROGRAM_ID,
merkle_tree: merkle_tree_pubkey,
output_queue: output_queue_pubkey,
fee_payer: payer.pubkey(),
};

let instruction = Instruction {
Expand Down Expand Up @@ -2184,6 +2188,7 @@ pub async fn update_batch_address_tree(
registered_program_pda: None,
log_wrapper: NOOP_PROGRAM_ID,
merkle_tree,
fee_payer: context.get_payer().pubkey(),
};
let instructions = if mode == UpdateBatchAddressTreeTestMode::UpdateTwice {
vec![
Expand Down
25 changes: 22 additions & 3 deletions programs/account-compression/src/instructions/batch_append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use light_batched_merkle_tree::merkle_tree::{

use crate::{
emit_indexer_event,
utils::check_signer_is_registered_or_authority::{
check_signer_is_registered_or_authority, GroupAccounts,
utils::{
check_signer_is_registered_or_authority::{
check_signer_is_registered_or_authority, GroupAccounts,
},
transfer_lamports::transfer_lamports,
},
RegisteredProgram,
};
Expand All @@ -24,6 +27,9 @@ pub struct BatchAppend<'info> {
/// CHECK: in update_tree_from_output_queue_account_info.
#[account(mut)]
pub output_queue: AccountInfo<'info>,
/// CHECK: receives network fee reimbursement.
#[account(mut)]
pub fee_payer: UncheckedAccount<'info>,
}

impl<'info> GroupAccounts<'info> for BatchAppend<'info> {
Expand Down Expand Up @@ -62,6 +68,19 @@ pub fn process_batch_append_leaves<'a, 'b, 'c: 'info, 'info>(
let event = merkle_tree
.update_tree_from_output_queue_account_info(&ctx.accounts.output_queue, instruction_data)
.map_err(ProgramError::from)?;
// 4. Emit indexer event.
// 4. Transfer network fee reimbursement to fee payer.
let network_fee = merkle_tree
.get_metadata()
.metadata
.rollover_metadata
.network_fee;
if network_fee >= 5_000 {
transfer_lamports(
&ctx.accounts.output_queue.to_account_info(),
&ctx.accounts.fee_payer.to_account_info(),
network_fee * 2,
)?;
Comment thread
ananas-block marked this conversation as resolved.
}
// 5. Emit indexer event.
emit_indexer_event(event.try_to_vec()?, &ctx.accounts.log_wrapper)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use light_batched_merkle_tree::merkle_tree::{

use crate::{
emit_indexer_event,
utils::check_signer_is_registered_or_authority::{
check_signer_is_registered_or_authority, GroupAccounts,
utils::{
check_signer_is_registered_or_authority::{
check_signer_is_registered_or_authority, GroupAccounts,
},
transfer_lamports::transfer_lamports,
},
RegisteredProgram,
};
Expand All @@ -21,6 +24,9 @@ pub struct BatchUpdateAddressTree<'info> {
/// CHECK: in from_account_info.
#[account(mut)]
pub merkle_tree: AccountInfo<'info>,
/// CHECK: receives network fee reimbursement.
#[account(mut)]
pub fee_payer: UncheckedAccount<'info>,
}

impl<'info> GroupAccounts<'info> for BatchUpdateAddressTree<'info> {
Expand Down Expand Up @@ -55,6 +61,19 @@ pub fn process_batch_update_address_tree<'a, 'b, 'c: 'info, 'info>(
let event = merkle_tree
.update_tree_from_address_queue(instruction_data)
.map_err(ProgramError::from)?;
// 4. Emit indexer event.
// 4. Transfer network fee reimbursement to fee payer.
let network_fee = merkle_tree
.get_metadata()
.metadata
.rollover_metadata
.network_fee;
if network_fee >= 5_000 {
transfer_lamports(
&ctx.accounts.merkle_tree.to_account_info(),
&ctx.accounts.fee_payer.to_account_info(),
network_fee,
)?;
}
// 5. Emit indexer event.
emit_indexer_event(event.try_to_vec()?, &ctx.accounts.log_wrapper)
}
1 change: 1 addition & 0 deletions programs/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build:
cd account-compression && cargo build-sbf --features 'test, migrate-state'
cd registry && cargo build-sbf
cd compressed-token/program && cargo build-sbf
cargo build-sbf --manifest-path ../program-tests/create-address-test-program/Cargo.toml

build-compressed-token-small:
cd compressed-token/program && cargo build-sbf --features cpi-without-program-ids
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct BatchAppend<'info> {
/// CHECK: (account compression program).
#[account(mut)]
pub output_queue: AccountInfo<'info>,
/// CHECK: receives network fee reimbursement.
#[account(mut)]
pub fee_payer: UncheckedAccount<'info>,
}

pub fn process_batch_append(ctx: &Context<BatchAppend>, bump: u8, data: Vec<u8>) -> Result<()> {
Expand All @@ -35,6 +38,7 @@ pub fn process_batch_append(ctx: &Context<BatchAppend>, bump: u8, data: Vec<u8>)
registered_program_pda: Some(ctx.accounts.registered_program_pda.clone()),
log_wrapper: ctx.accounts.log_wrapper.to_account_info(),
output_queue: ctx.accounts.output_queue.to_account_info(),
fee_payer: ctx.accounts.fee_payer.to_account_info(),
};

let cpi_ctx = CpiContext::new_with_signer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub struct BatchUpdateAddressTree<'info> {
/// CHECK: (account compression program).
#[account(mut)]
pub merkle_tree: AccountInfo<'info>,
/// CHECK: receives network fee reimbursement.
#[account(mut)]
pub fee_payer: UncheckedAccount<'info>,
}

pub fn process_batch_update_address_tree(
Expand All @@ -35,6 +38,7 @@ pub fn process_batch_update_address_tree(
merkle_tree: ctx.accounts.merkle_tree.to_account_info(),
registered_program_pda: Some(ctx.accounts.registered_program_pda.clone()),
log_wrapper: ctx.accounts.log_wrapper.to_account_info(),
fee_payer: ctx.accounts.fee_payer.to_account_info(),
};

let cpi_ctx = CpiContext::new_with_signer(
Expand Down
2 changes: 2 additions & 0 deletions programs/registry/src/account_compression_cpi/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ pub fn create_batch_append_instruction(
registered_program_pda,
account_compression_program: account_compression::ID,
log_wrapper: NOOP_PUBKEY.into(),
fee_payer: forester,
};
let instruction_data = crate::instruction::BatchAppend { bump, data };
Instruction {
Expand Down Expand Up @@ -506,6 +507,7 @@ pub fn create_batch_update_address_tree_instruction(
registered_program_pda,
account_compression_program: account_compression::ID,
log_wrapper: NOOP_PUBKEY.into(),
fee_payer: forester,
};
let instruction_data = crate::instruction::BatchUpdateAddressTree { bump, data };
Instruction {
Expand Down
Loading