From a21da890e5eed15a8e06f35150434ce92894a3d5 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Wed, 13 Mar 2024 12:59:06 -0400 Subject: [PATCH 1/2] ignore markets for slot diff restart --- src/dlob-subscriber/DLOBSubscriberIO.ts | 30 +++++++++++++++++++++---- src/index.ts | 1 + src/publishers/dlobPublisher.ts | 1 + src/publishers/tradesPublisher.ts | 1 - 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index bcedda3..b96c261 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -31,6 +31,16 @@ type wsMarketArgs = { const PERP_MAKRET_STALENESS_THRESHOLD = 10 * 60 * 1000; const SPOT_MAKRET_STALENESS_THRESHOLD = 20 * 60 * 1000; +const PERP_MARKETS_TO_SKIP_SLOT_CHECK = { + 'mainnet-beta': [17, 21, 23, 25, 26], + devnet: [17, 21], +}; + +const SPOT_MARKETS_TO_SKIP_SLOT_CHECK = { + 'mainnet-beta': [6, 8, 10], + devnet: [], +}; + export type wsMarketInfo = { marketIndex: number; marketName: string; @@ -46,7 +56,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber { Map >; - public skipSlotStalenessCheckMarkets = new Set(); + public skipSlotStalenessCheckMarketsPerp: number[]; + public skipSlotStalenessCheckMarketsSpot: number[]; constructor( config: DLOBSubscriptionConfig & { @@ -70,6 +81,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber { this.lastMarketSlotMap.set(MarketType.SPOT, new Map()); this.lastMarketSlotMap.set(MarketType.PERP, new Map()); + this.skipSlotStalenessCheckMarketsPerp = + PERP_MARKETS_TO_SKIP_SLOT_CHECK[config.env]; + this.skipSlotStalenessCheckMarketsSpot = + SPOT_MARKETS_TO_SKIP_SLOT_CHECK[config.env]; + for (const market of config.perpMarketInfos) { const perpMarket = this.driftClient.getPerpMarketAccount( market.marketIndex @@ -77,7 +93,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { const includeVamm = !isVariant(perpMarket.status, 'ammPaused'); const oracleSource = perpMarket.amm.oracleSource; if (isVariant(oracleSource, 'prelaunch')) { - this.skipSlotStalenessCheckMarkets.add(market.marketIndex); + this.skipSlotStalenessCheckMarketsPerp.push(market.marketIndex); } this.marketArgs.push({ @@ -182,8 +198,14 @@ export class DLOBSubscriberIO extends DLOBSubscriber { // Check if slot diffs are too large for oracle const skipSlotCheck = - marketType === 'perp' && - this.skipSlotStalenessCheckMarkets.has(marketArgs.marketIndex); + (marketType === 'perp' && + this.skipSlotStalenessCheckMarketsPerp.includes( + marketArgs.marketIndex + )) || + (marketType === 'spot' && + this.skipSlotStalenessCheckMarketsSpot.includes( + marketArgs.marketIndex + )); if ( Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) > this.killSwitchSlotDiffThreshold && diff --git a/src/index.ts b/src/index.ts index c54604d..e955c02 100644 --- a/src/index.ts +++ b/src/index.ts @@ -345,6 +345,7 @@ const main = async (): Promise => { const initDlobSubscriberStart = Date.now(); const dlobSubscriber = new DLOBSubscriber({ driftClient, + env: driftEnv, dlobSource: dlobProvider, slotSource: dlobProvider, updateFrequency: ORDERBOOK_UPDATE_INTERVAL, diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 069d5c1..659299f 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -391,6 +391,7 @@ const main = async () => { const dlobSubscriber = new DLOBSubscriberIO({ driftClient, + env: driftEnv, dlobSource: dlobProvider, slotSource, updateFrequency: ORDERBOOK_UPDATE_INTERVAL, diff --git a/src/publishers/tradesPublisher.ts b/src/publishers/tradesPublisher.ts index 2de92c7..a4bb447 100644 --- a/src/publishers/tradesPublisher.ts +++ b/src/publishers/tradesPublisher.ts @@ -81,7 +81,6 @@ const main = async () => { await driftClient.subscribe(); driftClient.eventEmitter.on('error', (e) => { - logger.info('clearing house error'); logger.error(e); }); From b26070dd36d8c197c6d5526696a91d645ced94b3 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Wed, 13 Mar 2024 13:03:20 -0400 Subject: [PATCH 2/2] bug fix --- src/dlob-subscriber/DLOBSubscriberIO.ts | 2 ++ src/index.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index b96c261..8701970 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -2,6 +2,7 @@ import { BN, DLOBSubscriber, DLOBSubscriptionConfig, + DriftEnv, L2OrderBookGenerator, MarketType, PositionDirection, @@ -61,6 +62,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { constructor( config: DLOBSubscriptionConfig & { + env: DriftEnv, redisClient: RedisClient; perpMarketInfos: wsMarketInfo[]; spotMarketInfos: wsMarketInfo[]; diff --git a/src/index.ts b/src/index.ts index e955c02..c54604d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -345,7 +345,6 @@ const main = async (): Promise => { const initDlobSubscriberStart = Date.now(); const dlobSubscriber = new DLOBSubscriber({ driftClient, - env: driftEnv, dlobSource: dlobProvider, slotSource: dlobProvider, updateFrequency: ORDERBOOK_UPDATE_INTERVAL,