@@ -22,7 +22,6 @@ pub struct CompressAndCloseIndices {
22
22
pub authority_index : u8 ,
23
23
pub rent_recipient_index : u8 ,
24
24
pub output_tree_index : u8 ,
25
- pub amount : u64 ,
26
25
}
27
26
28
27
/// Find and validate all required account indices from packed_accounts
@@ -34,7 +33,6 @@ fn find_account_indices(
34
33
authority : impl Into < Pubkey > ,
35
34
rent_recipient_pubkey : Pubkey ,
36
35
output_tree_pubkey : Pubkey ,
37
- amount : u64 ,
38
36
) -> Result < CompressAndCloseIndices , TokenSdkError > {
39
37
let mint_pubkey = mint_pubkey. into ( ) ;
40
38
let owner_pubkey = owner_pubkey. into ( ) ;
@@ -77,7 +75,6 @@ fn find_account_indices(
77
75
authority_index,
78
76
rent_recipient_index,
79
77
output_tree_index,
80
- amount,
81
78
} )
82
79
}
83
80
@@ -105,13 +102,24 @@ pub fn compress_and_close_ctoken_accounts_with_indices<'info>(
105
102
let mut token_accounts = Vec :: with_capacity ( indices. len ( ) ) ;
106
103
107
104
for idx in indices {
105
+ // Get the amount from the source token account
106
+ let source_account = packed_accounts
107
+ . get ( idx. source_index as usize )
108
+ . ok_or ( TokenSdkError :: InvalidAccountData ) ?;
109
+
110
+ let account_data = source_account
111
+ . try_borrow_data ( )
112
+ . map_err ( |_| TokenSdkError :: AccountBorrowFailed ) ?;
113
+
114
+ let amount = light_ctoken_types:: state:: CompressedToken :: amount_from_slice ( & account_data) ?;
115
+
108
116
// Create CTokenAccount2 for CompressAndClose operation
109
117
let mut token_account =
110
118
CTokenAccount2 :: new_empty ( idx. owner_index , idx. mint_index , idx. output_tree_index ) ;
111
119
112
120
// Set up compress_and_close with actual indices
113
121
token_account. compress_and_close (
114
- idx . amount ,
122
+ amount,
115
123
idx. source_index ,
116
124
idx. authority_index ,
117
125
idx. rent_recipient_index ,
@@ -191,9 +199,6 @@ pub fn compress_and_close_ctoken_accounts<'info>(
191
199
light_ctoken_types:: state:: CompressedToken :: zero_copy_at ( & account_data)
192
200
. map_err ( |_| TokenSdkError :: InvalidAccountData ) ?;
193
201
194
- // Get the amount (full balance) - convert from zero-copy type
195
- let amount = u64:: from ( * compressed_token. amount ) ;
196
-
197
202
// Extract pubkeys from the deserialized account
198
203
let mint_pubkey = Pubkey :: from ( compressed_token. mint . to_bytes ( ) ) ;
199
204
let owner_pubkey = Pubkey :: from ( compressed_token. owner . to_bytes ( ) ) ;
@@ -254,7 +259,6 @@ pub fn compress_and_close_ctoken_accounts<'info>(
254
259
authority,
255
260
rent_recipient_pubkey. ok_or ( TokenSdkError :: InvalidAccountData ) ?,
256
261
output_tree_pubkey. ok_or ( TokenSdkError :: InvalidAccountData ) ?,
257
- amount,
258
262
) ?;
259
263
260
264
indices_vec. push ( indices) ;
0 commit comments