From 51c8be03784b952e57c5fae0dfb49647397c3628 Mon Sep 17 00:00:00 2001 From: bigzPubkey Date: Thu, 6 Apr 2023 10:35:57 -0400 Subject: [PATCH] program: safer market initialization (#413) * bigz/market-initializer-improve * fix tests/multipleMakerOrders.ts * fix tests * fix tests/admin.ts * init delete_initialized_perp_market * fix test/ idl * fix red err tests lines * update admin.rs for deletecontext * update error code * update validate for state.number_of_markets * actually delete perp account * try fix referrer test * update idl * fix tests * CHANGELOG --------- Co-authored-by: Chris Heaney --- CHANGELOG.md | 4 ++ programs/drift/src/error.rs | 2 + programs/drift/src/instructions/admin.rs | 69 ++++++++++++++++++++++- programs/drift/src/lib.rs | 9 +++ sdk/src/adminClient.ts | 2 + sdk/src/idl/drift.json | 50 ++++++++++++++++ tests/admin.ts | 1 + tests/assetTier.ts | 1 + tests/cancelAllOrders.ts | 1 + tests/cappedSymFunding.ts | 12 +++- tests/curve.ts | 1 + tests/delistMarket.ts | 1 + tests/delistMarketLiq.ts | 1 + tests/driftClient.ts | 1 + tests/imbalancePerpPnl.ts | 1 + tests/insuranceFundStake.ts | 1 + tests/ksolver.ts | 2 + tests/liquidateBorrowForPerpPnl.ts | 1 + tests/liquidatePerp.ts | 2 + tests/liquidatePerpAndLp.ts | 2 + tests/liquidatePerpPnlForDeposit.ts | 1 + tests/liquidityProvider.ts | 2 + tests/marketOrder.ts | 2 + tests/marketOrderBaseAssetAmount.ts | 1 + tests/maxLeverageOrderParams.ts | 1 + tests/multipleMakerOrders.ts | 2 + tests/oracleOffsetOrders.ts | 1 + tests/order.ts | 3 + tests/ordersWithSpread.ts | 2 + tests/pauseExchange.ts | 1 + tests/placeAndMakePerp.ts | 1 + tests/postOnly.ts | 1 + tests/postOnlyAmmFulfillment.ts | 1 + tests/prepegMarketOrderBaseAssetAmount.ts | 2 + tests/pyth.ts | 2 + tests/referrer.ts | 1 + tests/repegAndSpread.ts | 1 + tests/roundInFavorBaseAsset.ts | 1 + tests/stopLimits.ts | 2 + tests/tradingLP.ts | 2 + tests/triggerOrders.ts | 2 +- tests/triggerSpotOrder.ts | 1 + tests/updateAMM.ts | 2 + tests/updateK.ts | 1 + tests/userAccount.ts | 1 + tests/userDelegate.ts | 1 + tests/userOrderId.ts | 2 + tests/whitelist.ts | 1 + 48 files changed, 201 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 883e75c21..5e6087c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Features + +- program: ability to delete a market that was just initialized ([#413](https://github.com/drift-labs/protocol-v2/pull/413)) - program: revenue pool wont settle to IF if utilization unhealthy ([#402](https://github.com/drift-labs/protocol-v2/pull/402)) ### Fixes + - program: add ctx.accounts.insurance_fund_vault.reload()? after vault updates ([#402](https://github.com/drift-labs/protocol-v2/pull/402)) + ### Breaking ## [2.23.0] - 2023-04-03 diff --git a/programs/drift/src/error.rs b/programs/drift/src/error.rs index b9909ea9f..b0e2e4f3f 100644 --- a/programs/drift/src/error.rs +++ b/programs/drift/src/error.rs @@ -485,6 +485,8 @@ pub enum ErrorCode { UserNotInactive, #[msg("RevertFill")] RevertFill, + #[msg("Invalid MarketAccount for Deletion")] + InvalidMarketAccountforDeletion, } #[macro_export] diff --git a/programs/drift/src/instructions/admin.rs b/programs/drift/src/instructions/admin.rs index e2fde215d..8ed2c0e44 100644 --- a/programs/drift/src/instructions/admin.rs +++ b/programs/drift/src/instructions/admin.rs @@ -51,7 +51,7 @@ use crate::validation::margin::{validate_margin, validate_margin_weights}; use crate::validation::perp_market::validate_perp_market; use crate::validation::spot_market::validate_borrow_rate; use crate::{controller, QUOTE_PRECISION_I64}; -use crate::{math, safe_increment}; +use crate::{math, safe_decrement, safe_increment}; pub fn handle_initialize(ctx: Context) -> Result<()> { let (drift_signer, drift_signer_nonce) = @@ -443,6 +443,7 @@ pub fn handle_update_serum_vault(ctx: Context) -> Result<()> { pub fn handle_initialize_perp_market( ctx: Context, + market_index: u16, amm_base_asset_reserve: u128, amm_quote_asset_reserve: u128, amm_periodicity: i64, @@ -551,7 +552,14 @@ pub fn handle_initialize_perp_market( )?; let state = &mut ctx.accounts.state; - let market_index = state.number_of_markets; + validate!( + market_index == state.number_of_markets, + ErrorCode::MarketIndexAlreadyInitialized, + "market_index={} != state.number_of_markets={}", + market_index, + state.number_of_markets + )?; + **perp_market = PerpMarket { contract_type: ContractType::Perpetual, contract_tier: ContractTier::Speculative, // default @@ -679,6 +687,46 @@ pub fn handle_initialize_perp_market( Ok(()) } +pub fn handle_delete_initialized_perp_market( + ctx: Context, + market_index: u16, +) -> Result<()> { + let perp_market = &mut ctx.accounts.perp_market.load_init()?; + let state = &mut ctx.accounts.state; + + // to preserve all protocol invariants, can only remove the last market if it hasn't been "activated" + + validate!( + state.number_of_markets - 1 == market_index, + ErrorCode::InvalidMarketAccountforDeletion, + "state.number_of_markets={} != market_index={}", + state.number_of_markets, + market_index + )?; + validate!( + perp_market.status == MarketStatus::Initialized, + ErrorCode::InvalidMarketAccountforDeletion, + "perp_market.status != Initialized", + )?; + validate!( + perp_market.number_of_users == 0, + ErrorCode::InvalidMarketAccountforDeletion, + "perp_market.number_of_users={} != 0", + perp_market.number_of_users, + )?; + validate!( + perp_market.market_index == market_index, + ErrorCode::InvalidMarketAccountforDeletion, + "market_index={} != perp_market.market_index={}", + market_index, + perp_market.market_index + )?; + + safe_decrement!(state.number_of_markets, 1); + + Ok(()) +} + #[access_control( spot_market_valid(&ctx.accounts.spot_market) )] @@ -2247,6 +2295,23 @@ pub struct InitializePerpMarket<'info> { pub system_program: Program<'info, System>, } +#[derive(Accounts)] +pub struct DeleteInitializedPerpMarket<'info> { + #[account(mut)] + pub admin: Signer<'info>, + #[account( + mut, + has_one = admin + )] + pub state: Box>, + #[account(mut, close = admin)] + pub perp_market: AccountLoader<'info, PerpMarket>, + /// CHECK: checked in `initialize_perp_market` + pub oracle: AccountInfo<'info>, + pub rent: Sysvar<'info, Rent>, + pub system_program: Program<'info, System>, +} + #[derive(Accounts)] pub struct AdminUpdatePerpMarket<'info> { pub admin: Signer<'info>, diff --git a/programs/drift/src/lib.rs b/programs/drift/src/lib.rs index 84267f18c..c52c23bb0 100644 --- a/programs/drift/src/lib.rs +++ b/programs/drift/src/lib.rs @@ -474,6 +474,7 @@ pub mod drift { pub fn initialize_perp_market( ctx: Context, + market_index: u16, amm_base_asset_reserve: u128, amm_quote_asset_reserve: u128, amm_periodicity: i64, @@ -487,6 +488,7 @@ pub mod drift { ) -> Result<()> { handle_initialize_perp_market( ctx, + market_index, amm_base_asset_reserve, amm_quote_asset_reserve, amm_periodicity, @@ -500,6 +502,13 @@ pub mod drift { ) } + pub fn delete_initialized_perp_market( + ctx: Context, + market_index: u16, + ) -> Result<()> { + handle_delete_initialized_perp_market(ctx, market_index) + } + pub fn move_amm_price( ctx: Context, base_asset_reserve: u128, diff --git a/sdk/src/adminClient.ts b/sdk/src/adminClient.ts index 04585615f..8aa1c3464 100644 --- a/sdk/src/adminClient.ts +++ b/sdk/src/adminClient.ts @@ -182,6 +182,7 @@ export class AdminClient extends DriftClient { } public async initializePerpMarket( + marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, @@ -203,6 +204,7 @@ export class AdminClient extends DriftClient { const nameBuffer = encodeName(name); const initializeMarketTx = await this.program.transaction.initializePerpMarket( + marketIndex, baseAssetReserve, quoteAssetReserve, periodicity, diff --git a/sdk/src/idl/drift.json b/sdk/src/idl/drift.json index 3f6a923e6..79bb8977d 100644 --- a/sdk/src/idl/drift.json +++ b/sdk/src/idl/drift.json @@ -2283,6 +2283,10 @@ } ], "args": [ + { + "name": "marketIndex", + "type": "u16" + }, { "name": "ammBaseAssetReserve", "type": "u128" @@ -2332,6 +2336,47 @@ } ] }, + { + "name": "deleteInitializedPerpMarket", + "accounts": [ + { + "name": "admin", + "isMut": true, + "isSigner": true + }, + { + "name": "state", + "isMut": true, + "isSigner": false + }, + { + "name": "perpMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "oracle", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "marketIndex", + "type": "u16" + } + ] + }, { "name": "moveAmmPrice", "accounts": [ @@ -8826,6 +8871,11 @@ "code": 6239, "name": "RevertFill", "msg": "RevertFill" + }, + { + "code": 6240, + "name": "InvalidMarketAccountforDeletion", + "msg": "Invalid MarketAccount for Deletion" } ] } \ No newline at end of file diff --git a/tests/admin.ts b/tests/admin.ts index c21876bca..3d4131e2e 100644 --- a/tests/admin.ts +++ b/tests/admin.ts @@ -66,6 +66,7 @@ describe('admin', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, new BN(1000), new BN(1000), diff --git a/tests/assetTier.ts b/tests/assetTier.ts index 9f80bbef1..f36d2e364 100644 --- a/tests/assetTier.ts +++ b/tests/assetTier.ts @@ -119,6 +119,7 @@ describe('asset tiers', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solOracle, AMM_RESERVE_PRECISION, AMM_RESERVE_PRECISION, diff --git a/tests/cancelAllOrders.ts b/tests/cancelAllOrders.ts index 52f1424a1..3b1e61ed9 100644 --- a/tests/cancelAllOrders.ts +++ b/tests/cancelAllOrders.ts @@ -91,6 +91,7 @@ describe('cancel all orders', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, oracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/cappedSymFunding.ts b/tests/cappedSymFunding.ts index 03bf61c16..bab61f47f 100644 --- a/tests/cappedSymFunding.ts +++ b/tests/cappedSymFunding.ts @@ -19,7 +19,6 @@ import { PRICE_PRECISION, FUNDING_RATE_BUFFER_PRECISION, PEG_PRECISION, - TestClient, User, PositionDirection, QUOTE_PRECISION, @@ -183,6 +182,7 @@ async function updateFundingRateHelper( } async function cappedSymFundingScenario( + rollingMarketNum: number, driftClient: TestClient, userAccount: User, driftClient2: TestClient, @@ -197,6 +197,7 @@ async function cappedSymFundingScenario( const periodicity = new BN(0); await driftClient.initializePerpMarket( + rollingMarketNum, priceFeedAddress, kSqrt, kSqrt, @@ -546,6 +547,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -604,6 +606,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -663,6 +666,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -720,6 +724,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -781,6 +786,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -880,6 +886,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -975,6 +982,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -1036,6 +1044,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, @@ -1098,6 +1107,7 @@ describe('capped funding', () => { totalFee, cumulativeFee, ] = await cappedSymFundingScenario( + rollingMarketNum - 1, driftClient, userAccount, driftClient2, diff --git a/tests/curve.ts b/tests/curve.ts index 290116a68..b20585465 100644 --- a/tests/curve.ts +++ b/tests/curve.ts @@ -92,6 +92,7 @@ describe('AMM Curve', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsdOracle, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/delistMarket.ts b/tests/delistMarket.ts index bb8f177c6..bac34f509 100644 --- a/tests/delistMarket.ts +++ b/tests/delistMarket.ts @@ -158,6 +158,7 @@ describe('delist market', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/delistMarketLiq.ts b/tests/delistMarketLiq.ts index 60fa9b784..f3270a419 100644 --- a/tests/delistMarketLiq.ts +++ b/tests/delistMarketLiq.ts @@ -144,6 +144,7 @@ describe('delist market, liquidation of expired position', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/driftClient.ts b/tests/driftClient.ts index 7364b842b..127b6acf9 100644 --- a/tests/driftClient.ts +++ b/tests/driftClient.ts @@ -121,6 +121,7 @@ describe('drift client', () => { const marketIndex = 0; const txSig = await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/imbalancePerpPnl.ts b/tests/imbalancePerpPnl.ts index 9545bac3b..4f76f9e6b 100644 --- a/tests/imbalancePerpPnl.ts +++ b/tests/imbalancePerpPnl.ts @@ -214,6 +214,7 @@ describe('imbalanced large perp pnl w/ borrow hitting limits', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/insuranceFundStake.ts b/tests/insuranceFundStake.ts index 5dd2448d2..f2351702e 100644 --- a/tests/insuranceFundStake.ts +++ b/tests/insuranceFundStake.ts @@ -123,6 +123,7 @@ describe('insurance fund stake', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solOracle, AMM_RESERVE_PRECISION, AMM_RESERVE_PRECISION, diff --git a/tests/ksolver.ts b/tests/ksolver.ts index 1a6d15af5..a425dbd10 100644 --- a/tests/ksolver.ts +++ b/tests/ksolver.ts @@ -208,6 +208,8 @@ describe('AMM Curve', () => { const periodicity = new BN(60 * 60); // 1 HOUR const kSqrtNorm = normAssetAmount(kSqrt, initialSOLPriceBN); await driftClient.initializePerpMarket( + 0, + solUsdOracle, kSqrtNorm, kSqrtNorm, diff --git a/tests/liquidateBorrowForPerpPnl.ts b/tests/liquidateBorrowForPerpPnl.ts index d2c76d52f..7fd31f66c 100644 --- a/tests/liquidateBorrowForPerpPnl.ts +++ b/tests/liquidateBorrowForPerpPnl.ts @@ -117,6 +117,7 @@ describe('liquidate borrow for perp pnl', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/liquidatePerp.ts b/tests/liquidatePerp.ts index c4eec82a4..dd834bce2 100644 --- a/tests/liquidatePerp.ts +++ b/tests/liquidatePerp.ts @@ -110,6 +110,8 @@ describe('liquidate perp (no open orders)', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, + oracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/liquidatePerpAndLp.ts b/tests/liquidatePerpAndLp.ts index 76032f3b3..3383255c6 100644 --- a/tests/liquidatePerpAndLp.ts +++ b/tests/liquidatePerpAndLp.ts @@ -111,6 +111,8 @@ describe('liquidate perp and lp', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, + oracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/liquidatePerpPnlForDeposit.ts b/tests/liquidatePerpPnlForDeposit.ts index 2a3e76ce6..f6652dcf1 100644 --- a/tests/liquidatePerpPnlForDeposit.ts +++ b/tests/liquidatePerpPnlForDeposit.ts @@ -118,6 +118,7 @@ describe('liquidate perp pnl for deposit', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/liquidityProvider.ts b/tests/liquidityProvider.ts index 47a43e287..d6425e1a0 100644 --- a/tests/liquidityProvider.ts +++ b/tests/liquidityProvider.ts @@ -217,6 +217,7 @@ describe('liquidity providing', () => { ); // used for trading / taking on baa await driftClient.initializePerpMarket( + 0, solusdc, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -247,6 +248,7 @@ describe('liquidity providing', () => { // second market -- used for funding .. await driftClient.initializePerpMarket( + 1, solusdc2, stableAmmInitialBaseAssetReserve, stableAmmInitialQuoteAssetReserve, diff --git a/tests/marketOrder.ts b/tests/marketOrder.ts index 375503f6f..8eb726e73 100644 --- a/tests/marketOrder.ts +++ b/tests/marketOrder.ts @@ -114,6 +114,7 @@ describe('market order', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -121,6 +122,7 @@ describe('market order', () => { ); await driftClient.initializePerpMarket( + 1, btcUsd, ammInitialBaseAssetReserve.div(new BN(3000)), ammInitialQuoteAssetReserve.div(new BN(3000)), diff --git a/tests/marketOrderBaseAssetAmount.ts b/tests/marketOrderBaseAssetAmount.ts index b5424e5f1..d5847fb83 100644 --- a/tests/marketOrderBaseAssetAmount.ts +++ b/tests/marketOrderBaseAssetAmount.ts @@ -96,6 +96,7 @@ describe('market orders', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/maxLeverageOrderParams.ts b/tests/maxLeverageOrderParams.ts index 57e33d3f2..79be945da 100644 --- a/tests/maxLeverageOrderParams.ts +++ b/tests/maxLeverageOrderParams.ts @@ -110,6 +110,7 @@ describe('max leverage order params', () => { const periodicity = new BN(0); await driftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/multipleMakerOrders.ts b/tests/multipleMakerOrders.ts index 520e14a42..4c904a7f0 100644 --- a/tests/multipleMakerOrders.ts +++ b/tests/multipleMakerOrders.ts @@ -99,6 +99,7 @@ describe('multiple maker orders', () => { const periodicity = new BN(60 * 60); // 1 HOUR await fillerDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -113,6 +114,7 @@ describe('multiple maker orders', () => { ); await fillerDriftClient.initializePerpMarket( + 1, dogUsd, ammInitialBaseAssetReserve.div(new BN(100000)), ammInitialQuoteAssetReserve.div(new BN(100000)), diff --git a/tests/oracleOffsetOrders.ts b/tests/oracleOffsetOrders.ts index 3b8310ee1..0dd283f70 100644 --- a/tests/oracleOffsetOrders.ts +++ b/tests/oracleOffsetOrders.ts @@ -99,6 +99,7 @@ describe('oracle offset', () => { const periodicity = new BN(60 * 60); // 1 HOUR await fillerDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/order.ts b/tests/order.ts index 7e5ca5699..c0c496fe2 100644 --- a/tests/order.ts +++ b/tests/order.ts @@ -151,6 +151,7 @@ describe('orders', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -164,6 +165,7 @@ describe('orders', () => { ); await driftClient.initializePerpMarket( + 1, btcUsd, ammInitialBaseAssetReserve.div(new BN(3000)), ammInitialQuoteAssetReserve.div(new BN(3000)), @@ -178,6 +180,7 @@ describe('orders', () => { ); await driftClient.initializePerpMarket( + 2, ethUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/ordersWithSpread.ts b/tests/ordersWithSpread.ts index 5e2ea9659..f1d38df07 100644 --- a/tests/ordersWithSpread.ts +++ b/tests/ordersWithSpread.ts @@ -107,6 +107,7 @@ describe('amm spread: market order', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -645,6 +646,7 @@ describe('amm spread: market order', () => { ); await driftClient.initializePerpMarket( + marketIndex2, btcUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/pauseExchange.ts b/tests/pauseExchange.ts index d85a54c9c..d909d2cef 100644 --- a/tests/pauseExchange.ts +++ b/tests/pauseExchange.ts @@ -81,6 +81,7 @@ describe('Pause exchange', () => { await driftClient.subscribe(); await driftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/placeAndMakePerp.ts b/tests/placeAndMakePerp.ts index 36e43ad0d..2a0082bf8 100644 --- a/tests/placeAndMakePerp.ts +++ b/tests/placeAndMakePerp.ts @@ -97,6 +97,7 @@ describe('place and make perp order', () => { const periodicity = new BN(0); await makerDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/postOnly.ts b/tests/postOnly.ts index 4a984f7e2..86c386c4c 100644 --- a/tests/postOnly.ts +++ b/tests/postOnly.ts @@ -106,6 +106,7 @@ describe('post only', () => { const periodicity = new BN(60 * 60); // 1 HOUR await fillerDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/postOnlyAmmFulfillment.ts b/tests/postOnlyAmmFulfillment.ts index d7e0a547f..360d4a3f6 100644 --- a/tests/postOnlyAmmFulfillment.ts +++ b/tests/postOnlyAmmFulfillment.ts @@ -106,6 +106,7 @@ describe('post only maker order w/ amm fulfillments', () => { const periodicity = new BN(60 * 60); // 1 HOUR await fillerDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/prepegMarketOrderBaseAssetAmount.ts b/tests/prepegMarketOrderBaseAssetAmount.ts index 241e5e450..9faef880f 100644 --- a/tests/prepegMarketOrderBaseAssetAmount.ts +++ b/tests/prepegMarketOrderBaseAssetAmount.ts @@ -127,6 +127,7 @@ describe('prepeg', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, @@ -147,6 +148,7 @@ describe('prepeg', () => { // init more markets const thisUsd = mockOracles[i]; await driftClient.initializePerpMarket( + i, thisUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/pyth.ts b/tests/pyth.ts index 60b2c66d8..3480e15a8 100644 --- a/tests/pyth.ts +++ b/tests/pyth.ts @@ -275,6 +275,7 @@ describe('pyth-oracle', () => { const marketIndex = 0; await driftClient.initializePerpMarket( + 0, priceFeedAddress, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, @@ -294,6 +295,7 @@ describe('pyth-oracle', () => { const marketIndex = 1; await driftClient.initializePerpMarket( + 1, priceFeedAddress, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/referrer.ts b/tests/referrer.ts index abc46efda..5e12dbfa5 100644 --- a/tests/referrer.ts +++ b/tests/referrer.ts @@ -115,6 +115,7 @@ describe('referrer', () => { const periodicity = new BN(60 * 60); // 1 HOUR await referrerDriftClient.initializePerpMarket( + 0, solOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/repegAndSpread.ts b/tests/repegAndSpread.ts index 910522eb0..791da2cd3 100644 --- a/tests/repegAndSpread.ts +++ b/tests/repegAndSpread.ts @@ -214,6 +214,7 @@ describe('repeg and spread amm', () => { const periodicity = new BN(60 * 60); // 1 HOUR // BTC await driftClient.initializePerpMarket( + 0, btcUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/roundInFavorBaseAsset.ts b/tests/roundInFavorBaseAsset.ts index eb856a7e2..0cbe503c7 100644 --- a/tests/roundInFavorBaseAsset.ts +++ b/tests/roundInFavorBaseAsset.ts @@ -87,6 +87,7 @@ describe('round in favor', () => { const periodicity = new BN(60 * 60); // 1 HOUR await primaryDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/stopLimits.ts b/tests/stopLimits.ts index 7ee436bd1..57f795ebb 100644 --- a/tests/stopLimits.ts +++ b/tests/stopLimits.ts @@ -134,6 +134,7 @@ describe('stop limit', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -142,6 +143,7 @@ describe('stop limit', () => { await driftClient.updatePerpMarketStatus(0, MarketStatus.ACTIVE); await driftClient.initializePerpMarket( + 1, btcUsd, ammInitialBaseAssetReserve.div(new BN(3000)), ammInitialQuoteAssetReserve.div(new BN(3000)), diff --git a/tests/tradingLP.ts b/tests/tradingLP.ts index cd14e4bad..e9e2d2eed 100644 --- a/tests/tradingLP.ts +++ b/tests/tradingLP.ts @@ -147,6 +147,7 @@ describe('trading liquidity providing', () => { ); // used for trading / taking on baa await driftClient.initializePerpMarket( + 0, solusdc, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -176,6 +177,7 @@ describe('trading liquidity providing', () => { // second market -- used for funding .. await driftClient.initializePerpMarket( + 1, solusdc2, stableAmmInitialBaseAssetReserve, stableAmmInitialQuoteAssetReserve, diff --git a/tests/triggerOrders.ts b/tests/triggerOrders.ts index 804e60fac..dae92147b 100644 --- a/tests/triggerOrders.ts +++ b/tests/triggerOrders.ts @@ -9,7 +9,6 @@ import { TestClient, BN, PRICE_PRECISION, - TestClient, PositionDirection, User, Wallet, @@ -124,6 +123,7 @@ describe('trigger orders', () => { const periodicity = new BN(60 * 60); // 1 HOUR await fillerDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/triggerSpotOrder.ts b/tests/triggerSpotOrder.ts index 5bb109b33..92f79e607 100644 --- a/tests/triggerSpotOrder.ts +++ b/tests/triggerSpotOrder.ts @@ -105,6 +105,7 @@ describe('trigger orders', () => { const periodicity = new BN(60 * 60); // 1 HOUR await fillerDriftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/updateAMM.ts b/tests/updateAMM.ts index 2c60e831f..7f6707c30 100644 --- a/tests/updateAMM.ts +++ b/tests/updateAMM.ts @@ -169,6 +169,7 @@ describe('update amm', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, @@ -184,6 +185,7 @@ describe('update amm', () => { // init more markets const thisUsd = mockOracles[i]; await driftClient.initializePerpMarket( + i, thisUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/updateK.ts b/tests/updateK.ts index cacd31af3..193a4fb8a 100644 --- a/tests/updateK.ts +++ b/tests/updateK.ts @@ -97,6 +97,7 @@ describe('update k', () => { }); await driftClient.initializePerpMarket( + 0, solUsdOracle, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, diff --git a/tests/userAccount.ts b/tests/userAccount.ts index 77d8d2909..d82016329 100644 --- a/tests/userAccount.ts +++ b/tests/userAccount.ts @@ -99,6 +99,7 @@ describe('User Account', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsdOracle, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/userDelegate.ts b/tests/userDelegate.ts index 6fd2f38ea..50a6a09c4 100644 --- a/tests/userDelegate.ts +++ b/tests/userDelegate.ts @@ -100,6 +100,7 @@ describe('user delegate', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetAmount, ammInitialQuoteAssetAmount, diff --git a/tests/userOrderId.ts b/tests/userOrderId.ts index 5c79bbb61..dc6c21911 100644 --- a/tests/userOrderId.ts +++ b/tests/userOrderId.ts @@ -104,6 +104,7 @@ describe('user order id', () => { const periodicity = new BN(60 * 60); // 1 HOUR await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve, @@ -118,6 +119,7 @@ describe('user order id', () => { await driftClient.updatePerpMarketStatus(0, MarketStatus.ACTIVE); await driftClient.initializePerpMarket( + 1, btcUsd, ammInitialBaseAssetReserve.div(new BN(3000)), ammInitialQuoteAssetReserve.div(new BN(3000)), diff --git a/tests/whitelist.ts b/tests/whitelist.ts index 891c361ac..2440b5886 100644 --- a/tests/whitelist.ts +++ b/tests/whitelist.ts @@ -77,6 +77,7 @@ describe('whitelist', () => { await initializeQuoteSpotMarket(driftClient, usdcMint.publicKey); await driftClient.initializePerpMarket( + 0, solUsd, ammInitialBaseAssetReserve, ammInitialQuoteAssetReserve,