@@ -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;
13+ use crate :: controller:: token:: { close_vault, 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:: * ;
@@ -146,15 +146,19 @@ pub fn handle_initialize_spot_market(
146146 let state = & mut ctx. accounts . state ;
147147 let spot_market_pubkey = ctx. accounts . spot_market . key ( ) ;
148148
149- // protocol must be authority of collateral vault
150- if ctx. accounts . spot_market_vault . owner != state. signer {
151- return Err ( ErrorCode :: InvalidSpotMarketAuthority . into ( ) ) ;
152- }
149+ initialize_token_account (
150+ & ctx. accounts . token_program ,
151+ & ctx. accounts . spot_market_vault ,
152+ & ctx. accounts . drift_signer ,
153+ & ctx. accounts . spot_market_mint ,
154+ ) ?;
153155
154- // protocol must be authority of collateral vault
155- if ctx. accounts . insurance_fund_vault . owner != state. signer {
156- return Err ( ErrorCode :: InvalidInsuranceFundAuthority . into ( ) ) ;
157- }
156+ initialize_token_account (
157+ & ctx. accounts . token_program ,
158+ & ctx. accounts . insurance_fund_vault ,
159+ & ctx. accounts . drift_signer ,
160+ & ctx. accounts . spot_market_mint ,
161+ ) ?;
158162
159163 validate_borrow_rate ( optimal_utilization, optimal_borrow_rate, max_borrow_rate, 0 ) ?;
160164
@@ -280,7 +284,7 @@ pub fn handle_initialize_spot_market(
280284 historical_oracle_data : historical_oracle_data_default,
281285 historical_index_data : historical_index_data_default,
282286 mint : ctx. accounts . spot_market_mint . key ( ) ,
283- vault : * ctx. accounts . spot_market_vault . to_account_info ( ) . key ,
287+ vault : ctx. accounts . spot_market_vault . key ( ) ,
284288 revenue_pool : PoolBalance {
285289 scaled_balance : 0 ,
286290 market_index : spot_market_index,
@@ -337,7 +341,7 @@ pub fn handle_initialize_spot_market(
337341 pool_id : 0 ,
338342 padding : [ 0 ; 40 ] ,
339343 insurance_fund : InsuranceFund {
340- vault : * ctx. accounts . insurance_fund_vault . to_account_info ( ) . key ,
344+ vault : ctx. accounts . insurance_fund_vault . key ( ) ,
341345 unstaking_period : THIRTEEN_DAY ,
342346 total_factor : if_total_factor,
343347 user_factor : if_total_factor / 2 ,
@@ -4945,25 +4949,30 @@ pub struct InitializeSpotMarket<'info> {
49454949 payer = admin
49464950 ) ]
49474951 pub spot_market : AccountLoader < ' info , SpotMarket > ,
4952+ #[ account(
4953+ mint:: token_program = token_program,
4954+ ) ]
49484955 pub spot_market_mint : Box < InterfaceAccount < ' info , Mint > > ,
49494956 #[ account(
49504957 init,
49514958 seeds = [ b"spot_market_vault" . as_ref( ) , state. number_of_spot_markets. to_le_bytes( ) . as_ref( ) ] ,
49524959 bump,
49534960 payer = admin,
4954- token :: mint = spot_market_mint,
4955- token :: authority = drift_signer
4961+ space = get_vault_len ( & spot_market_mint) ? ,
4962+ owner = token_program . key ( )
49564963 ) ]
4957- pub spot_market_vault : Box < InterfaceAccount < ' info , TokenAccount > > ,
4964+ /// CHECK: checked in `initialize_spot_market`
4965+ pub spot_market_vault : AccountInfo < ' info > ,
49584966 #[ account(
49594967 init,
49604968 seeds = [ b"insurance_fund_vault" . as_ref( ) , state. number_of_spot_markets. to_le_bytes( ) . as_ref( ) ] ,
49614969 bump,
49624970 payer = admin,
4963- token :: mint = spot_market_mint,
4964- token :: authority = drift_signer
4971+ space = get_vault_len ( & spot_market_mint) ? ,
4972+ owner = token_program . key ( )
49654973 ) ]
4966- pub insurance_fund_vault : Box < InterfaceAccount < ' info , TokenAccount > > ,
4974+ /// CHECK: checked in `initialize_spot_market`
4975+ pub insurance_fund_vault : AccountInfo < ' info > ,
49674976 #[ account(
49684977 constraint = state. signer. eq( & drift_signer. key( ) )
49694978 ) ]
0 commit comments