diff --git a/package.json b/package.json index 21a1f53..a7dec89 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "Apache-2.0", "dependencies": { "@coral-xyz/anchor": "^0.29.0", - "@drift-labs/sdk": "2.71.0-beta.3", + "@drift-labs/sdk": "2.72.0-beta.1", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 5cff973..bcedda3 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -46,6 +46,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber { Map >; + public skipSlotStalenessCheckMarkets = new Set(); + constructor( config: DLOBSubscriptionConfig & { redisClient: RedisClient; @@ -73,6 +75,10 @@ export class DLOBSubscriberIO extends DLOBSubscriber { market.marketIndex ); const includeVamm = !isVariant(perpMarket.status, 'ammPaused'); + const oracleSource = perpMarket.amm.oracleSource; + if (isVariant(oracleSource, 'prelaunch')) { + this.skipSlotStalenessCheckMarkets.add(market.marketIndex); + } this.marketArgs.push({ marketIndex: market.marketIndex, @@ -175,9 +181,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber { ); // Check if slot diffs are too large for oracle + const skipSlotCheck = + marketType === 'perp' && + this.skipSlotStalenessCheckMarkets.has(marketArgs.marketIndex); if ( Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) > - this.killSwitchSlotDiffThreshold + this.killSwitchSlotDiffThreshold && + !skipSlotCheck ) { console.log(`Killing process due to slot diffs for market ${marketName}: dlobProvider slot: ${slot} @@ -194,7 +204,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber { if ( lastMarketSlotAndTime && l2Formatted['marketSlot'] === lastMarketSlotAndTime.slot && - Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD + Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD && + !skipSlotCheck ) { console.log(`Killing process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms: dlobProvider slot: ${slot} @@ -329,48 +340,6 @@ export class DLOBSubscriberIO extends DLOBSubscriber { marketArgs.marketIndex ); - // Check if slot diffs are too large for oracle - if ( - Math.abs(slot - parseInt(l3['oracleData']['slot'])) > - this.killSwitchSlotDiffThreshold - ) { - console.log(`Killing process due to slot diffs for market ${marketName}: - dlobProvider slot: ${slot} - oracle slot: ${l3['oracleData']['slot']} - `); - process.exit(1); - } - - // Check if times and slots are too different for market - const MAKRET_STALENESS_THRESHOLD = - marketType === 'perp' - ? PERP_MAKRET_STALENESS_THRESHOLD - : SPOT_MAKRET_STALENESS_THRESHOLD; - if ( - lastMarketSlotAndTime && - l3['marketSlot'] === lastMarketSlotAndTime.slot && - Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD - ) { - console.log(`Killing process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms: - dlobProvider slot: ${slot} - market slot: ${l3['marketSlot']} - `); - process.exit(1); - } else if ( - lastMarketSlotAndTime && - l3['marketSlot'] !== lastMarketSlotAndTime.slot - ) { - console.log( - `Updating market slot for ${marketArgs.marketName} with slot ${l3['marketSlot']}` - ); - this.lastMarketSlotMap - .get(marketArgs.marketType) - .set(marketArgs.marketIndex, { - slot: l3['marketSlot'], - ts: Date.now(), - }); - } - this.redisClient.client.set( `last_update_orderbook_l3_${marketType}_${marketArgs.marketIndex}`, JSON.stringify(l3) diff --git a/src/index.ts b/src/index.ts index 8e3768e..c54604d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -276,7 +276,7 @@ const main = async (): Promise => { commitment: stateCommitment, }; slotSubscriber = new SlotSubscriber(connection, { - resubTimeoutMs: 5000 + resubTimeoutMs: 5000, }); await slotSubscriber.subscribe(); } @@ -785,6 +785,7 @@ const main = async (): Promise => { if (topMakers) { cacheHitCounter.add(1, { miss: false, + path: req.baseUrl + req.path, }); res.writeHead(200); res.end(JSON.stringify(topMakers)); @@ -838,6 +839,7 @@ const main = async (): Promise => { topMakers = [...topMakersSet]; cacheHitCounter.add(1, { miss: true, + path: req.baseUrl + req.path, }); res.writeHead(200); res.end(JSON.stringify(topMakers)); @@ -950,6 +952,7 @@ const main = async (): Promise => { if (l2Formatted) { cacheHitCounter.add(1, { miss: false, + path: req.baseUrl + req.path, }); res.writeHead(200); res.end(l2Formatted); @@ -986,6 +989,7 @@ const main = async (): Promise => { cacheHitCounter.add(1, { miss: true, + path: req.baseUrl + req.path, }); res.writeHead(200); res.end(JSON.stringify(l2Formatted)); @@ -1127,6 +1131,7 @@ const main = async (): Promise => { if (l2Formatted) { cacheHitCounter.add(1, { miss: false, + path: req.baseUrl + req.path, }); return l2Formatted; } @@ -1161,6 +1166,7 @@ const main = async (): Promise => { } cacheHitCounter.add(1, { miss: true, + path: req.baseUrl + req.path, }); return l2Formatted; }) @@ -1209,6 +1215,7 @@ const main = async (): Promise => { ) { cacheHitCounter.add(1, { miss: false, + path: req.baseUrl + req.path, }); res.writeHead(200); res.end(redisL3); @@ -1216,6 +1223,7 @@ const main = async (): Promise => { } else { cacheHitCounter.add(1, { miss: true, + path: req.baseUrl + req.path, }); } } diff --git a/yarn.lock b/yarn.lock index 909b69a..080757e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -115,10 +115,10 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/sdk@2.71.0-beta.3": - version "2.71.0-beta.3" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.71.0-beta.3.tgz#bddb4c5a2c3661dd12e533b4450f97d03d698a9a" - integrity sha512-/MDv4678WGrgTKOMZlemvmCnT9Xs7gbQmY2wGQQN2umzXIa/ifCovD5kSNZcARlQuZltnLv8b8Hr98euzMt5aA== +"@drift-labs/sdk@2.72.0-beta.1": + version "2.72.0-beta.1" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.72.0-beta.1.tgz#bee1269f877970f10e53f651d19aced79e75a0bc" + integrity sha512-Fgz2WFoTxFetBNBEdzPSKi6IbGnUD6zo5EqUZqW3rICJcpjvjJazKNe9NnYy6q753wnMiYcCwhn29IxcIhAl0g== dependencies: "@coral-xyz/anchor" "0.28.1-beta.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2"