File tree Expand file tree Collapse file tree 3 files changed +25
-7
lines changed
Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -217,3 +217,16 @@ pub fn initialize_token_account<'info>(
217217
218218 Ok ( ( ) )
219219}
220+
221+ pub fn initialize_immutable_owner < ' info > (
222+ token_program : & Interface < ' info , TokenInterface > ,
223+ account : & AccountInfo < ' info > ,
224+ ) -> Result < ( ) > {
225+ let accounts = :: anchor_spl:: token_interface:: InitializeImmutableOwner {
226+ account : account. to_account_info ( ) ,
227+ } ;
228+ let cpi_ctx = anchor_lang:: context:: CpiContext :: new ( token_program. to_account_info ( ) , accounts) ;
229+ :: anchor_spl:: token_interface:: initialize_immutable_owner ( cpi_ctx) ?;
230+
231+ Ok ( ( ) )
232+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ use pyth_solana_receiver_sdk::cpi::accounts::InitPriceUpdate;
1010use pyth_solana_receiver_sdk:: program:: PythSolanaReceiver ;
1111use serum_dex:: state:: ToAlignedBytes ;
1212
13- use crate :: controller:: token:: { close_vault, initialize_token_account} ;
13+ use crate :: controller:: token:: { close_vault, initialize_immutable_owner , initialize_token_account} ;
1414use crate :: error:: ErrorCode ;
1515use crate :: ids:: { admin_hot_wallet, amm_spread_adjust_wallet, mm_oracle_crank_wallet} ;
1616use crate :: instructions:: constraints:: * ;
@@ -148,6 +148,13 @@ pub fn handle_initialize_spot_market(
148148 let state = & mut ctx. accounts . state ;
149149 let spot_market_pubkey = ctx. accounts . spot_market . key ( ) ;
150150
151+ let is_token_2022 = * ctx. accounts . spot_market_mint . to_account_info ( ) . owner == Token2022 :: id ( ) ;
152+ if is_token_2022 {
153+ initialize_immutable_owner ( & ctx. accounts . token_program , & ctx. accounts . spot_market_vault ) ?;
154+
155+ initialize_immutable_owner ( & ctx. accounts . token_program , & ctx. accounts . insurance_fund_vault ) ?;
156+ }
157+
151158 initialize_token_account (
152159 & ctx. accounts . token_program ,
153160 & ctx. accounts . spot_market_vault ,
Original file line number Diff line number Diff line change @@ -159,15 +159,13 @@ pub fn get_vault_len(mint: &InterfaceAccount<Mint>) -> anchor_lang::Result<usize
159159 let mint_state = StateWithExtensions :: < Mint > :: unpack ( & mint_data) ?;
160160 let mint_extensions = match mint_state. get_extension_types ( ) {
161161 Ok ( extensions) => extensions,
162- // If we cant deserialize the mint, we use the default token account length
162+ // If we cant deserialize the mint, try assuming no extensions
163163 // Init token will fail if this size doesnt work, so worst case init account just fails
164- Err ( _) => {
165- msg ! ( "Failed to deserialize mint. Falling back to default token account length" ) ;
166- return Ok ( :: anchor_spl:: token:: TokenAccount :: LEN ) ;
167- }
164+ Err ( _) => vec ! [ ] ,
168165 } ;
169- let required_extensions =
166+ let mut required_extensions =
170167 ExtensionType :: get_required_init_account_extensions ( & mint_extensions) ;
168+ required_extensions. push ( ExtensionType :: ImmutableOwner ) ;
171169 ExtensionType :: try_calculate_account_len :: < Account > ( & required_extensions) ?
172170 } else {
173171 :: anchor_spl:: token:: TokenAccount :: LEN
You can’t perform that action at this time.
0 commit comments