From 93ebd77a00408bdfe164e906b653c84433cdf0bd Mon Sep 17 00:00:00 2001 From: ananas-block Date: Thu, 19 Dec 2024 17:58:57 +0000 Subject: [PATCH] chore: relax order of accounts for decompress --- .../compressed-token/src/spl_compression.rs | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/programs/compressed-token/src/spl_compression.rs b/programs/compressed-token/src/spl_compression.rs index c1ba678fc..af6e8aa93 100644 --- a/programs/compressed-token/src/spl_compression.rs +++ b/programs/compressed-token/src/spl_compression.rs @@ -65,6 +65,8 @@ pub fn decompress_spl_tokens<'info>( }; let mint_bytes = inputs.mint.to_bytes(); + let mut token_pool_bumps = (0..crate::NUM_MAX_POOL_ACCOUNTS).collect::>(); + for i in 0..crate::NUM_MAX_POOL_ACCOUNTS { if i != 0 { token_pool_pda = ctx.remaining_accounts[i as usize - 1].to_account_info(); @@ -75,24 +77,32 @@ pub fn decompress_spl_tokens<'info>( .amount; let witdrawal_amount = std::cmp::min(amount, token_pool_amount); - spl_token_pool_derivation( - mint_bytes.as_slice(), - &crate::ID, - &token_pool_pda.key(), - &[i], - )?; + for (index, i) in token_pool_bumps.iter().enumerate() { + match check_spl_token_pool_derivation( + mint_bytes.as_slice(), + &crate::ID, + &token_pool_pda.key(), + &[*i], + ) { + true => { + transfer( + token_pool_pda.to_account_info(), + recipient.to_account_info(), + ctx.accounts.cpi_authority_pda.to_account_info(), + ctx.accounts + .token_program + .as_ref() + .unwrap() + .to_account_info(), + witdrawal_amount, + )?; + token_pool_bumps.remove(index); + return Ok(()); + } + false => {} + } + } - transfer( - token_pool_pda.to_account_info(), - recipient.to_account_info(), - ctx.accounts.cpi_authority_pda.to_account_info(), - ctx.accounts - .token_program - .as_ref() - .unwrap() - .to_account_info(), - witdrawal_amount, - )?; amount = amount.saturating_sub(witdrawal_amount); msg!("Amount: {}", amount); msg!("Witdrawal Amount: {}", witdrawal_amount);