1
1
use anchor_compressed_token:: ErrorCode ;
2
2
use anchor_lang:: solana_program:: program_error:: ProgramError ;
3
3
use light_account_checks:: packed_accounts:: ProgramPackedAccounts ;
4
- use light_ctoken_types :: instructions :: transfer2 :: ZCompressedTokenInstructionDataTransfer2 ;
4
+ use light_sdk_types :: ACCOUNT_COMPRESSION_PROGRAM_ID ;
5
5
use pinocchio:: { account_info:: AccountInfo , pubkey:: Pubkey } ;
6
6
use spl_pod:: solana_msg:: msg;
7
7
@@ -90,17 +90,16 @@ impl<'info> Transfer2Accounts<'info> {
90
90
pub fn cpi_accounts (
91
91
& self ,
92
92
all_accounts : & ' info [ AccountInfo ] ,
93
- inputs : & ZCompressedTokenInstructionDataTransfer2 ,
94
93
packed_accounts : & ' info ProgramPackedAccounts < ' info , AccountInfo > ,
95
94
) -> Result < ( & ' info [ AccountInfo ] , Vec < & ' info Pubkey > ) , ProgramError > {
96
95
// Extract tree accounts using highest index approach
97
- let ( tree_accounts, tree_accounts_count ) = extract_tree_accounts ( inputs , packed_accounts) ? ;
96
+ let tree_accounts = extract_tree_accounts ( packed_accounts) ;
98
97
99
98
// Calculate static accounts count after skipping index 0 (system accounts only)
100
99
let static_accounts_count = self . static_accounts_count ( ) ?;
101
100
102
101
// Include static CPI accounts + tree accounts based on highest tree index
103
- let cpi_accounts_end = 1 + static_accounts_count + tree_accounts_count ;
102
+ let cpi_accounts_end = 1 + static_accounts_count + tree_accounts . len ( ) ;
104
103
if all_accounts. len ( ) < cpi_accounts_end {
105
104
msg ! (
106
105
"Accounts len {} < expected cpi accounts len {}" ,
@@ -118,29 +117,13 @@ impl<'info> Transfer2Accounts<'info> {
118
117
// TODO: unit test.
119
118
/// Extract tree accounts by finding the highest tree index and using it as closing offset
120
119
pub fn extract_tree_accounts < ' info > (
121
- inputs : & ZCompressedTokenInstructionDataTransfer2 ,
122
120
packed_accounts : & ' info ProgramPackedAccounts < ' info , AccountInfo > ,
123
- ) -> Result < ( Vec < & ' info Pubkey > , usize ) , ProgramError > {
124
- // Find highest tree index from input and output data to determine tree accounts range
125
- let mut highest_tree_index = 0u8 ;
126
- for input_data in inputs. in_token_data . iter ( ) {
127
- highest_tree_index =
128
- highest_tree_index. max ( input_data. merkle_context . merkle_tree_pubkey_index ) ;
129
- highest_tree_index = highest_tree_index. max ( input_data. merkle_context . queue_pubkey_index ) ;
130
- }
131
- for output_data in inputs. out_token_data . iter ( ) {
132
- highest_tree_index = highest_tree_index. max ( output_data. merkle_tree ) ;
133
- }
134
-
135
- // Tree accounts span from index 0 to highest_tree_index in remaining accounts
136
- let tree_accounts_count = highest_tree_index + 1 ;
137
- // Extract tree account pubkeys from the determined range
138
- // Note: Don't switch to ArrayVec it results in weird memory access with non deterministic values.
139
- let mut tree_accounts = Vec :: with_capacity ( tree_accounts_count. into ( ) ) ;
140
- for i in 0 ..tree_accounts_count {
141
- let account_key = packed_accounts. get_u8 ( i, "tree account" ) ?. key ( ) ;
142
- tree_accounts. push ( account_key) ;
121
+ ) -> Vec < & ' info Pubkey > {
122
+ let mut tree_accounts = Vec :: with_capacity ( 8 ) ;
123
+ for account_info in packed_accounts. accounts {
124
+ if account_info. is_owned_by ( & ACCOUNT_COMPRESSION_PROGRAM_ID ) {
125
+ tree_accounts. push ( account_info. key ( ) ) ;
126
+ }
143
127
}
144
-
145
- Ok ( ( tree_accounts, tree_accounts_count. into ( ) ) )
128
+ tree_accounts
146
129
}
0 commit comments