@@ -13,7 +13,7 @@ use crate::{
1313 error:: NTTError ,
1414 instructions:: BridgeEvent ,
1515 ntt_messages:: Mode ,
16- queue:: inbox:: { InboxItem , ReleaseStatus , TokenTransfer } ,
16+ queue:: inbox:: { InboxItem , ReleaseStatus } ,
1717} ;
1818
1919#[ derive( Accounts ) ]
@@ -58,6 +58,7 @@ pub struct ReleaseInboundMint<'info> {
5858 pub earn_program : Program < ' info , Earn > ,
5959
6060 #[ account(
61+ mut ,
6162 seeds = [ GLOBAL_SEED ] ,
6263 seeds:: program = earn:: ID ,
6364 bump = m_global. bump,
@@ -73,25 +74,16 @@ pub struct ReleaseInboundArgs {
7374pub fn release_inbound_mint < ' info > (
7475 ctx : Context < ' _ , ' _ , ' _ , ' info , ReleaseInboundMint < ' info > > ,
7576 args : ReleaseInboundArgs ,
76- ) -> Result < ( ) > {
77- release_inbound ( ctx, args, false )
78- }
79-
80- pub fn release_inbound < ' info > (
81- ctx : Context < ' _ , ' _ , ' _ , ' info , ReleaseInboundMint < ' info > > ,
82- args : ReleaseInboundArgs ,
83- release_extension : bool ,
8477) -> Result < ( ) > {
8578 let inbox_item = & mut ctx. accounts . inbox_item ;
8679
8780 // Validate token account depending on call context
8881 validate_recipient_token_account (
8982 & ctx. accounts . recipient . key ( ) ,
90- & inbox_item. transfer ,
83+ & inbox_item,
9184 & ctx. accounts . token_authority . key ( ) ,
9285 & ctx. accounts . mint . key ( ) ,
9386 & ctx. accounts . token_program . key ( ) ,
94- release_extension,
9587 ) ?;
9688
9789 if !inbox_item. try_release ( ) ? {
@@ -186,40 +178,53 @@ pub fn release_inbound<'info>(
186178
187179fn validate_recipient_token_account (
188180 recipient : & Pubkey ,
189- transfer : & TokenTransfer ,
181+ inbox_item : & InboxItem ,
190182 token_authority : & Pubkey ,
191- mint : & Pubkey ,
183+ m_mint : & Pubkey ,
192184 token_program : & Pubkey ,
193- release_extension : bool ,
194185) -> Result < ( ) > {
186+ let expected = get_inbox_recipient_token_account (
187+ & inbox_item. transfer . recipient ,
188+ & inbox_item. destination_mint ,
189+ inbox_item. transfer . amount ,
190+ token_authority,
191+ m_mint,
192+ token_program,
193+ ) ;
194+
195+ if expected. is_some ( ) && !expected. unwrap ( ) . eq ( recipient) {
196+ return err ! ( NTTError :: InvalidRecipientAddress ) ;
197+ }
198+
199+ Ok ( ( ) )
200+ }
201+
202+ pub fn get_inbox_recipient_token_account (
203+ recipient : & Pubkey ,
204+ destination_mint : & Pubkey ,
205+ amount : u64 ,
206+ token_authority : & Pubkey ,
207+ m_mint : & Pubkey ,
208+ token_program : & Pubkey ,
209+ ) -> Option < Pubkey > {
195210 // Only bridging data
196- if transfer . amount == 0 {
197- return Ok ( ( ) ) ;
211+ if amount == 0 {
212+ return None ;
198213 }
199214
200215 // Bridging to extension, require intermediate portal token account
201- if release_extension {
202- if !recipient . eq ( & get_associated_token_address_with_program_id (
216+ if !destination_mint . eq ( m_mint ) {
217+ return Some ( get_associated_token_address_with_program_id (
203218 token_authority,
204- mint ,
219+ m_mint ,
205220 token_program,
206- ) ) {
207- msg ! ( "expected recipient to be token authority" ) ;
208- return err ! ( NTTError :: InvalidRecipientAddress ) ;
209- }
210-
211- return Ok ( ( ) ) ;
221+ ) ) ;
212222 }
213223
214224 // Bridging $M, require user token account
215- if !recipient . eq ( & get_associated_token_address_with_program_id (
216- & transfer . recipient ,
217- mint ,
225+ Some ( get_associated_token_address_with_program_id (
226+ & recipient,
227+ m_mint ,
218228 token_program,
219- ) ) {
220- msg ! ( "expected recipient to match inbox item" ) ;
221- return err ! ( NTTError :: InvalidRecipientAddress ) ;
222- }
223-
224- Ok ( ( ) )
229+ ) )
225230}
0 commit comments