I am trying to optimize size of my code by moving logic to freeze and approve in a separate file. However when I deploy and try to call my contract, I am getting error:
'Program 8uupFNMrGzDnmXX1un2C5mYU3mXGHjRnzjYKzWig1RP consumed 11491 of 200000 compute units',
'Program failed to complete: Instruction passed to inner instruction is too large (12884932868 > 1280)',
main.rs:
use crate::utility::{self, freeze};
...
...
pub fn handler(ctx: Context<Initialize>,..){
freeze(&ctx.accounts.initializer.to_account_info(), &ctx.accounts.mint.to_account_info(),
asset_manager, ctx.accounts.initializer_deposit_token_account.clone(),
&ctx.accounts.metadata_program.to_account_info(), &ctx.accounts.edition.to_account_info(),
&ctx.accounts.token_program.to_account_info(),ctx.program_id, true)?;
}
utility.rs:
pub fn freeze<'info>(initializer: &AccountInfo<'info>,mint: &AccountInfo<'info>, asset_manager: &mut Box<Account<'info, AssetManager>>,
initializer_deposit_token_account: Account<'info, TokenAccount>, metadata_program: &AccountInfo<'info>, edition: &AccountInfo<'info>,
token_program: &AccountInfo<'info>, program_id: &Pubkey, approve: bool)-> Result<()>{
// Approve NFT delegation
let (_escrow_pda, escrow_bump) = Pubkey::find_program_address(&[&mint.key().to_bytes()], program_id);
let escrow_authority_seeds = &[asset_manager.mint.as_ref(), &[escrow_bump]];
if approve{
let _escrow_signer = &[&escrow_authority_seeds[..]];
let cpi_accounts = Approve {
to: initializer_deposit_token_account.to_account_info(),
delegate: asset_manager.to_account_info(),
authority: initializer.to_account_info(),
};
let cpi_program = token_program.to_account_info();
let cpi_context = CpiContext::new(cpi_program, cpi_accounts);
token::approve(cpi_context, 1)?;
}
// Freeze NFT account
let edition_info = find_master_edition_account(&mint.key());
invoke_signed(
&freeze_delegated_account(
metadata_program.key(),
asset_manager.key(),
initializer_deposit_token_account.key(),
edition_info.0,
mint.key(),
),
&[
asset_manager.to_account_info(),
initializer_deposit_token_account.to_account_info(),
edition.to_account_info(),
mint.to_account_info(),
],
&[escrow_authority_seeds],
)?;
Ok(())
}
However, if I copy logic from utility to main, it works fine.