Skip to content

Commit

Permalink
Merge pull request #113 from drift-labs/ignore-markets
Browse files Browse the repository at this point in the history
ignore markets for slot diff restart
  • Loading branch information
NourAlharithi authored Mar 13, 2024
2 parents 66834fc + b26070d commit bb24aac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions src/dlob-subscriber/DLOBSubscriberIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BN,
DLOBSubscriber,
DLOBSubscriptionConfig,
DriftEnv,
L2OrderBookGenerator,
MarketType,
PositionDirection,
Expand Down Expand Up @@ -31,6 +32,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;
Expand All @@ -46,10 +57,12 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
Map<number, { slot: number; ts: number }>
>;

public skipSlotStalenessCheckMarkets = new Set<number>();
public skipSlotStalenessCheckMarketsPerp: number[];
public skipSlotStalenessCheckMarketsSpot: number[];

constructor(
config: DLOBSubscriptionConfig & {
env: DriftEnv,
redisClient: RedisClient;
perpMarketInfos: wsMarketInfo[];
spotMarketInfos: wsMarketInfo[];
Expand All @@ -70,14 +83,19 @@ 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
);
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({
Expand Down Expand Up @@ -182,8 +200,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 &&
Expand Down
1 change: 1 addition & 0 deletions src/publishers/dlobPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ const main = async () => {

const dlobSubscriber = new DLOBSubscriberIO({
driftClient,
env: driftEnv,
dlobSource: dlobProvider,
slotSource,
updateFrequency: ORDERBOOK_UPDATE_INTERVAL,
Expand Down
1 change: 0 additions & 1 deletion src/publishers/tradesPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const main = async () => {

await driftClient.subscribe();
driftClient.eventEmitter.on('error', (e) => {
logger.info('clearing house error');
logger.error(e);
});

Expand Down

0 comments on commit bb24aac

Please sign in to comment.