@@ -9,7 +9,7 @@ use serum_dex::state::ToAlignedBytes;
99use std:: convert:: { identity, TryInto } ;
1010use std:: mem:: size_of;
1111
12- use crate :: controller:: token:: close_vault;
12+ use crate :: controller:: token:: { close_vault, initialize_token_account } ;
1313use crate :: error:: ErrorCode ;
1414use crate :: ids:: { admin_hot_wallet, amm_spread_adjust_wallet, mm_oracle_crank_wallet} ;
1515use crate :: instructions:: constraints:: * ;
@@ -150,15 +150,19 @@ pub fn handle_initialize_spot_market(
150150 let state = & mut ctx. accounts . state ;
151151 let spot_market_pubkey = ctx. accounts . spot_market . key ( ) ;
152152
153- // protocol must be authority of collateral vault
154- if ctx. accounts . spot_market_vault . owner != state. signer {
155- return Err ( ErrorCode :: InvalidSpotMarketAuthority . into ( ) ) ;
156- }
153+ initialize_token_account (
154+ & ctx. accounts . token_program ,
155+ & ctx. accounts . spot_market_vault ,
156+ & ctx. accounts . drift_signer ,
157+ & ctx. accounts . spot_market_mint ,
158+ ) ?;
157159
158- // protocol must be authority of collateral vault
159- if ctx. accounts . insurance_fund_vault . owner != state. signer {
160- return Err ( ErrorCode :: InvalidInsuranceFundAuthority . into ( ) ) ;
161- }
160+ initialize_token_account (
161+ & ctx. accounts . token_program ,
162+ & ctx. accounts . insurance_fund_vault ,
163+ & ctx. accounts . drift_signer ,
164+ & ctx. accounts . spot_market_mint ,
165+ ) ?;
162166
163167 validate_borrow_rate ( optimal_utilization, optimal_borrow_rate, max_borrow_rate, 0 ) ?;
164168
@@ -284,7 +288,7 @@ pub fn handle_initialize_spot_market(
284288 historical_oracle_data : historical_oracle_data_default,
285289 historical_index_data : historical_index_data_default,
286290 mint : ctx. accounts . spot_market_mint . key ( ) ,
287- vault : * ctx. accounts . spot_market_vault . to_account_info ( ) . key ,
291+ vault : ctx. accounts . spot_market_vault . key ( ) ,
288292 revenue_pool : PoolBalance {
289293 scaled_balance : 0 ,
290294 market_index : spot_market_index,
@@ -341,7 +345,7 @@ pub fn handle_initialize_spot_market(
341345 pool_id : 0 ,
342346 padding : [ 0 ; 40 ] ,
343347 insurance_fund : InsuranceFund {
344- vault : * ctx. accounts . insurance_fund_vault . to_account_info ( ) . key ,
348+ vault : ctx. accounts . insurance_fund_vault . key ( ) ,
345349 unstaking_period : THIRTEEN_DAY ,
346350 total_factor : if_total_factor,
347351 user_factor : if_total_factor / 2 ,
@@ -1626,7 +1630,6 @@ pub fn handle_recenter_perp_market_amm_crank(
16261630 depth : Option < u128 > ,
16271631) -> Result < ( ) > {
16281632 let perp_market = & mut load_mut ! ( ctx. accounts. perp_market) ?;
1629- let spot_market = & mut load ! ( ctx. accounts. spot_market) ?;
16301633
16311634 let clock = Clock :: get ( ) ?;
16321635 let price_oracle = & ctx. accounts . oracle ;
@@ -4861,9 +4864,6 @@ pub fn handle_initialize_if_rebalance_config(
48614864 ctx : Context < InitializeIfRebalanceConfig > ,
48624865 params : IfRebalanceConfigParams ,
48634866) -> Result < ( ) > {
4864- let clock = Clock :: get ( ) ?;
4865- let now = clock. unix_timestamp ;
4866-
48674867 let pubkey = ctx. accounts . if_rebalance_config . to_account_info ( ) . key ;
48684868 let mut config = ctx. accounts . if_rebalance_config . load_init ( ) ?;
48694869
@@ -5099,25 +5099,30 @@ pub struct InitializeSpotMarket<'info> {
50995099 payer = admin
51005100 ) ]
51015101 pub spot_market : AccountLoader < ' info , SpotMarket > ,
5102+ #[ account(
5103+ mint:: token_program = token_program,
5104+ ) ]
51025105 pub spot_market_mint : Box < InterfaceAccount < ' info , Mint > > ,
51035106 #[ account(
51045107 init,
51055108 seeds = [ b"spot_market_vault" . as_ref( ) , state. number_of_spot_markets. to_le_bytes( ) . as_ref( ) ] ,
51065109 bump,
51075110 payer = admin,
5108- token :: mint = spot_market_mint,
5109- token :: authority = drift_signer
5111+ space = get_vault_len ( & spot_market_mint) ? ,
5112+ owner = token_program . key ( )
51105113 ) ]
5111- pub spot_market_vault : Box < InterfaceAccount < ' info , TokenAccount > > ,
5114+ /// CHECK: checked in `initialize_spot_market`
5115+ pub spot_market_vault : AccountInfo < ' info > ,
51125116 #[ account(
51135117 init,
51145118 seeds = [ b"insurance_fund_vault" . as_ref( ) , state. number_of_spot_markets. to_le_bytes( ) . as_ref( ) ] ,
51155119 bump,
51165120 payer = admin,
5117- token :: mint = spot_market_mint,
5118- token :: authority = drift_signer
5121+ space = get_vault_len ( & spot_market_mint) ? ,
5122+ owner = token_program . key ( )
51195123 ) ]
5120- pub insurance_fund_vault : Box < InterfaceAccount < ' info , TokenAccount > > ,
5124+ /// CHECK: checked in `initialize_spot_market`
5125+ pub insurance_fund_vault : AccountInfo < ' info > ,
51215126 #[ account(
51225127 constraint = state. signer. eq( & drift_signer. key( ) )
51235128 ) ]
0 commit comments