Merge pull request #113 from drift-labs/ignore-markets
ignore markets for slot diff restart
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
|||||||
BN,
|
BN,
|
||||||
DLOBSubscriber,
|
DLOBSubscriber,
|
||||||
DLOBSubscriptionConfig,
|
DLOBSubscriptionConfig,
|
||||||
|
DriftEnv,
|
||||||
L2OrderBookGenerator,
|
L2OrderBookGenerator,
|
||||||
MarketType,
|
MarketType,
|
||||||
PositionDirection,
|
PositionDirection,
|
||||||
@@ -31,6 +32,16 @@ type wsMarketArgs = {
|
|||||||
const PERP_MAKRET_STALENESS_THRESHOLD = 10 * 60 * 1000;
|
const PERP_MAKRET_STALENESS_THRESHOLD = 10 * 60 * 1000;
|
||||||
const SPOT_MAKRET_STALENESS_THRESHOLD = 20 * 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 = {
|
export type wsMarketInfo = {
|
||||||
marketIndex: number;
|
marketIndex: number;
|
||||||
marketName: string;
|
marketName: string;
|
||||||
@@ -46,10 +57,12 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
Map<number, { slot: number; ts: number }>
|
Map<number, { slot: number; ts: number }>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
public skipSlotStalenessCheckMarkets = new Set<number>();
|
public skipSlotStalenessCheckMarketsPerp: number[];
|
||||||
|
public skipSlotStalenessCheckMarketsSpot: number[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
config: DLOBSubscriptionConfig & {
|
config: DLOBSubscriptionConfig & {
|
||||||
|
env: DriftEnv,
|
||||||
redisClient: RedisClient;
|
redisClient: RedisClient;
|
||||||
perpMarketInfos: wsMarketInfo[];
|
perpMarketInfos: wsMarketInfo[];
|
||||||
spotMarketInfos: wsMarketInfo[];
|
spotMarketInfos: wsMarketInfo[];
|
||||||
@@ -70,6 +83,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
this.lastMarketSlotMap.set(MarketType.SPOT, new Map());
|
this.lastMarketSlotMap.set(MarketType.SPOT, new Map());
|
||||||
this.lastMarketSlotMap.set(MarketType.PERP, 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) {
|
for (const market of config.perpMarketInfos) {
|
||||||
const perpMarket = this.driftClient.getPerpMarketAccount(
|
const perpMarket = this.driftClient.getPerpMarketAccount(
|
||||||
market.marketIndex
|
market.marketIndex
|
||||||
@@ -77,7 +95,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
const includeVamm = !isVariant(perpMarket.status, 'ammPaused');
|
const includeVamm = !isVariant(perpMarket.status, 'ammPaused');
|
||||||
const oracleSource = perpMarket.amm.oracleSource;
|
const oracleSource = perpMarket.amm.oracleSource;
|
||||||
if (isVariant(oracleSource, 'prelaunch')) {
|
if (isVariant(oracleSource, 'prelaunch')) {
|
||||||
this.skipSlotStalenessCheckMarkets.add(market.marketIndex);
|
this.skipSlotStalenessCheckMarketsPerp.push(market.marketIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.marketArgs.push({
|
this.marketArgs.push({
|
||||||
@@ -182,8 +200,14 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
|
|
||||||
// Check if slot diffs are too large for oracle
|
// Check if slot diffs are too large for oracle
|
||||||
const skipSlotCheck =
|
const skipSlotCheck =
|
||||||
marketType === 'perp' &&
|
(marketType === 'perp' &&
|
||||||
this.skipSlotStalenessCheckMarkets.has(marketArgs.marketIndex);
|
this.skipSlotStalenessCheckMarketsPerp.includes(
|
||||||
|
marketArgs.marketIndex
|
||||||
|
)) ||
|
||||||
|
(marketType === 'spot' &&
|
||||||
|
this.skipSlotStalenessCheckMarketsSpot.includes(
|
||||||
|
marketArgs.marketIndex
|
||||||
|
));
|
||||||
if (
|
if (
|
||||||
Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) >
|
Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) >
|
||||||
this.killSwitchSlotDiffThreshold &&
|
this.killSwitchSlotDiffThreshold &&
|
||||||
|
|||||||
@@ -391,6 +391,7 @@ const main = async () => {
|
|||||||
|
|
||||||
const dlobSubscriber = new DLOBSubscriberIO({
|
const dlobSubscriber = new DLOBSubscriberIO({
|
||||||
driftClient,
|
driftClient,
|
||||||
|
env: driftEnv,
|
||||||
dlobSource: dlobProvider,
|
dlobSource: dlobProvider,
|
||||||
slotSource,
|
slotSource,
|
||||||
updateFrequency: ORDERBOOK_UPDATE_INTERVAL,
|
updateFrequency: ORDERBOOK_UPDATE_INTERVAL,
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ const main = async () => {
|
|||||||
|
|
||||||
await driftClient.subscribe();
|
await driftClient.subscribe();
|
||||||
driftClient.eventEmitter.on('error', (e) => {
|
driftClient.eventEmitter.on('error', (e) => {
|
||||||
logger.info('clearing house error');
|
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user