@@ -161,17 +161,25 @@ impl<'info> TransferBurn<'info> {
161161 return err ! ( ErrorCode :: ConstraintAddress ) ;
162162 }
163163
164- let session_authority_bump = get_session_authority (
165- self . common . payer . key ,
166- args. amount ,
167- args. recipient_chain ,
168- args. recipient_address ,
169- args. should_queue ,
170- self . session_authority . key ,
171- // We already validated the session in transfer_extension_burn.
172- // Also, the amount argument is different after converting to $M.
173- !self . common . from . owner . eq ( self . token_authority . key ) ,
174- ) ?;
164+ // Owner of the $M token account depends on whether this function
165+ // was called directly or by tranfer_extension_burn.
166+ let session_owner_seed = if self . common . from . owner . eq ( self . token_authority . key ) {
167+ self . common . payer . key ( )
168+ } else {
169+ self . common . from . owner . key ( )
170+ } ;
171+
172+ let ( session_authority, session_authority_bump) = Pubkey :: find_program_address (
173+ & [
174+ crate :: SESSION_AUTHORITY_SEED ,
175+ session_owner_seed. as_ref ( ) ,
176+ args. keccak256 ( ) . as_ref ( ) ,
177+ ] ,
178+ & crate :: ID ,
179+ ) ;
180+ if !self . session_authority . key ( ) . eq ( & session_authority) {
181+ return err ! ( ErrorCode :: ConstraintAddress ) ;
182+ }
175183
176184 Ok ( session_authority_bump)
177185 }
@@ -180,24 +188,34 @@ impl<'info> TransferBurn<'info> {
180188pub fn transfer_burn < ' info > (
181189 ctx : Context < ' _ , ' _ , ' _ , ' info , TransferBurn < ' info > > ,
182190 args : TransferArgs ,
191+ ) -> Result < ( ) > {
192+ let amount = args. amount ;
193+ transfer_burn_common ( ctx, args, amount)
194+ }
195+
196+ pub fn transfer_burn_common < ' info > (
197+ ctx : Context < ' _ , ' _ , ' _ , ' info , TransferBurn < ' info > > ,
198+ args : TransferArgs ,
199+ principal_amount_m : u64 ,
183200) -> Result < ( ) > {
184201 let session_authority_bump = ctx. accounts . validate_accounts ( & args) ?;
185202
186203 let accs = ctx. accounts ;
187204
188205 let TransferArgs {
189- amount : principal,
190206 recipient_chain,
191207 recipient_address,
192208 should_queue,
209+ ..
193210 } = args;
194211
195212 // The provided "amount" is the principal amount of M to bridge.
196213 // We scale this up to M units using the scaled UI config multiplier.
197214 let scaled_ui_config = earn:: utils:: conversion:: get_scaled_ui_config ( & accs. common . mint ) ?;
215+
198216 // Get the amount of M tokens to transfer using the multiplier
199217 let mut m_amount = earn:: utils:: conversion:: principal_to_amount_down (
200- principal ,
218+ principal_amount_m ,
201219 scaled_ui_config. new_multiplier . into ( ) ,
202220 ) ?;
203221
@@ -233,7 +251,7 @@ pub fn transfer_burn<'info>(
233251 accs. common . custody . to_account_info ( ) ,
234252 accs. session_authority . to_account_info ( ) ,
235253 ctx. remaining_accounts ,
236- principal ,
254+ principal_amount_m ,
237255 accs. common . mint . decimals ,
238256 & [ & [
239257 crate :: SESSION_AUTHORITY_SEED ,
@@ -254,7 +272,7 @@ pub fn transfer_burn<'info>(
254272 } ,
255273 & [ & [ crate :: TOKEN_AUTHORITY_SEED , & [ ctx. bumps . token_authority ] ] ] ,
256274 ) ,
257- principal ,
275+ principal_amount_m ,
258276 ) ?;
259277
260278 accs. common . custody . reload ( ) ?;
@@ -339,35 +357,3 @@ fn insert_into_outbox(
339357
340358 Ok ( ( ) )
341359}
342-
343- pub fn get_session_authority (
344- payer : & Pubkey ,
345- amount : u64 ,
346- recipient_chain : ChainId ,
347- recipient_address : [ u8 ; 32 ] ,
348- should_queue : bool ,
349- expected : & Pubkey ,
350- validate : bool ,
351- ) -> Result < u8 > {
352- let ( session_authority, bump) = Pubkey :: find_program_address (
353- & [
354- crate :: SESSION_AUTHORITY_SEED ,
355- payer. as_ref ( ) ,
356- TransferArgs {
357- amount,
358- recipient_chain,
359- recipient_address,
360- should_queue,
361- }
362- . keccak256 ( )
363- . as_ref ( ) ,
364- ] ,
365- & crate :: ID ,
366- ) ;
367-
368- if validate && !session_authority. eq ( expected) {
369- return err ! ( ErrorCode :: ConstraintAddress ) ;
370- }
371-
372- Ok ( bump)
373- }
0 commit comments