11use anchor_lang:: prelude:: * ;
2- use anchor_spl:: token_interface:: { self , Mint , TokenAccount , TokenInterface , TransferChecked } ;
2+ use anchor_spl:: {
3+ token:: Token ,
4+ token_2022:: Token2022 ,
5+ token_interface:: { self , Mint , TokenAccount , TransferChecked } ,
6+ } ;
37
48use portal:: constants:: PORTAL_AUTHORITY_SEED ;
59
@@ -31,7 +35,8 @@ pub struct FinalizeBridgeSpl<'info> {
3135 #[ account( mut ) ]
3236 pub to_token_account : InterfaceAccount < ' info , TokenAccount > ,
3337
34- pub token_program : Interface < ' info , TokenInterface > ,
38+ pub token_program : Program < ' info , Token > ,
39+ pub token_program_2022 : Program < ' info , Token2022 > ,
3540}
3641
3742pub fn finalize_bridge_spl_handler (
@@ -47,8 +52,15 @@ pub fn finalize_bridge_spl_handler(
4752 & [ ctx. bumps . token_vault ] ,
4853 ] ] ;
4954
55+ let token_program_info = if ctx. accounts . mint . to_account_info ( ) . owner == & anchor_spl:: token:: ID
56+ {
57+ ctx. accounts . token_program . to_account_info ( )
58+ } else {
59+ ctx. accounts . token_program_2022 . to_account_info ( )
60+ } ;
61+
5062 let cpi_ctx = CpiContext :: new_with_signer (
51- ctx . accounts . token_program . to_account_info ( ) ,
63+ token_program_info ,
5264 TransferChecked {
5365 mint : ctx. accounts . mint . to_account_info ( ) ,
5466 from : ctx. accounts . token_vault . to_account_info ( ) ,
@@ -64,7 +76,7 @@ pub fn finalize_bridge_spl_handler(
6476mod tests {
6577 use super :: * ;
6678
67- use anchor_lang:: InstructionData ;
79+ use anchor_lang:: { solana_program :: native_token :: LAMPORTS_PER_SOL , InstructionData } ;
6880 use anchor_spl:: token:: spl_token:: state:: Account as TokenAccount ;
6981 use litesvm:: LiteSVM ;
7082 use solana_instruction:: Instruction ;
@@ -79,15 +91,21 @@ mod tests {
7991 use crate :: {
8092 test_utils:: {
8193 mock_mint, mock_remote_call, mock_token_account, mock_token_vault, portal_authority,
82- SPL_TOKEN_PROGRAM_ID ,
8394 } ,
8495 ID as TOKEN_BRIDGE_PROGRAM_ID ,
8596 } ;
8697
87- const LAMPORTS_PER_SOL : u64 = 1_000_000_000 ;
98+ #[ test]
99+ fn test_finalize_bridge_spl_success_token ( ) {
100+ test_finalize_bridge_spl_success_token_impl ( anchor_spl:: token:: ID ) ;
101+ }
88102
89103 #[ test]
90- fn test_finalize_bridge_spl_success ( ) {
104+ fn test_finalize_bridge_spl_success_token_2022 ( ) {
105+ test_finalize_bridge_spl_success_token_impl ( anchor_spl:: token_2022:: ID ) ;
106+ }
107+
108+ fn test_finalize_bridge_spl_success_token_impl ( token_program_id : Pubkey ) {
91109 let mut svm = LiteSVM :: new ( ) ;
92110 svm. add_program_from_file (
93111 TOKEN_BRIDGE_PROGRAM_ID ,
@@ -113,14 +131,27 @@ mod tests {
113131
114132 // Create mint
115133 let mint = Keypair :: new ( ) . pubkey ( ) ;
116- mock_mint ( & mut svm, mint, decimals) ;
134+ mock_mint ( & mut svm, mint, decimals, token_program_id ) ;
117135
118136 // Create token vault with funds
119- let token_vault = mock_token_vault ( & mut svm, mint, remote_token, vault_initial_balance) ;
137+ let token_vault = mock_token_vault (
138+ & mut svm,
139+ mint,
140+ remote_token,
141+ vault_initial_balance,
142+ token_program_id,
143+ ) ;
120144
121145 // Create destination token account
122146 let to_token_account = Keypair :: new ( ) . pubkey ( ) ;
123- mock_token_account ( & mut svm, to_token_account, mint, recipient_pk, 0 ) ;
147+ mock_token_account (
148+ & mut svm,
149+ to_token_account,
150+ mint,
151+ recipient_pk,
152+ 0 ,
153+ token_program_id,
154+ ) ;
124155
125156 // Compute the portal authority PDA
126157 let portal_authority = portal_authority ( ) ;
@@ -131,7 +162,8 @@ mod tests {
131162 mint,
132163 token_vault,
133164 to_token_account,
134- token_program : SPL_TOKEN_PROGRAM_ID ,
165+ token_program : anchor_spl:: token:: ID ,
166+ token_program_2022 : anchor_spl:: token_2022:: ID ,
135167 }
136168 . to_account_metas ( None )
137169 . into_iter ( )
0 commit comments