From 551fc34217284f8788b9ebae66f3a0065a7a6f26 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 10 Dec 2024 12:00:34 -0800 Subject: [PATCH 1/3] no market fix for l2/batchL2 --- drift-common | 2 +- src/index.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/drift-common b/drift-common index 006397d..e91ef8b 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 006397d9c8f1b0aaf4d42186534bcf3252d1abcd +Subproject commit e91ef8b3ea8ca61bba760e4b8804cd9d12c1f26d diff --git a/src/index.ts b/src/index.ts index a092bb1..0732a00 100644 --- a/src/index.ts +++ b/src/index.ts @@ -546,10 +546,34 @@ const main = async (): Promise => { selectMostRecentBySlot ); const depthToUse = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); - redisL2['bids'] = redisL2['bids']?.slice(0, depthToUse); - redisL2['asks'] = redisL2['asks']?.slice(0, depthToUse); if (redisL2) { + redisL2['bids'] = redisL2['bids']?.slice(0, depthToUse); + redisL2['asks'] = redisL2['asks']?.slice(0, depthToUse); l2Formatted = JSON.stringify(redisL2); + } else { + const oracleData = isSpot + ? driftClient.getOracleDataForSpotMarket(normedMarketIndex) + : driftClient.getOracleDataForPerpMarket(normedMarketIndex); + const response = { + bids: [], + asks: [], + marketType: normedMarketType, + marketIndex: normedMarketIndex, + marketName: undefined, + slot: dlobProvider.getSlot(), + oracle: oracleData.price.toNumber(), + oracleData: { + price: oracleData.price.toNumber(), + slot: oracleData.slot.toNumber(), + confidence: oracleData.confidence.toNumber(), + hasSufficientNumberOfDataPoints: true, + twap: oracleData.twap.toNumber(), + twapConfidence: oracleData.twapConfidence.toNumber(), + }, + ts: Date.now(), + marketSlot: dlobProvider.getSlot(), + }; + l2Formatted = JSON.stringify(response); } if (l2Formatted) { @@ -636,10 +660,34 @@ const main = async (): Promise => { selectMostRecentBySlot ); const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); - redisL2['bids'] = redisL2['bids']?.slice(0, depth); - redisL2['asks'] = redisL2['asks']?.slice(0, depth); if (redisL2) { + redisL2['bids'] = redisL2['bids']?.slice(0, depth); + redisL2['asks'] = redisL2['asks']?.slice(0, depth); l2Formatted = redisL2; + } else { + const oracleData = isSpot + ? driftClient.getOracleDataForSpotMarket(normedMarketIndex) + : driftClient.getOracleDataForPerpMarket(normedMarketIndex); + const response = { + bids: [], + asks: [], + marketType: normedMarketType, + marketIndex: normedMarketIndex, + marketName: undefined, + slot: dlobProvider.getSlot(), + oracle: oracleData.price.toNumber(), + oracleData: { + price: oracleData.price.toNumber(), + slot: oracleData.slot.toNumber(), + confidence: oracleData.confidence.toNumber(), + hasSufficientNumberOfDataPoints: true, + twap: oracleData.twap.toNumber(), + twapConfidence: oracleData.twapConfidence.toNumber(), + }, + ts: Date.now(), + marketSlot: dlobProvider.getSlot(), + }; + l2Formatted = JSON.stringify(response); } if (l2Formatted) { From 176f2a9a9cb7613adea2c9f98401c7c2e67ebcba Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 10 Dec 2024 12:12:44 -0800 Subject: [PATCH 2/3] fix --- src/index.ts | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0732a00..ff9d212 100644 --- a/src/index.ts +++ b/src/index.ts @@ -546,15 +546,22 @@ const main = async (): Promise => { selectMostRecentBySlot ); const depthToUse = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); + let cacheMiss = true; if (redisL2) { + cacheMiss = false; redisL2['bids'] = redisL2['bids']?.slice(0, depthToUse); redisL2['asks'] = redisL2['asks']?.slice(0, depthToUse); - l2Formatted = JSON.stringify(redisL2); + l2Formatted = redisL2; } else { + console.log( + `No L2 found for ${getVariant( + normedMarketType + )} market ${normedMarketIndex}` + ); const oracleData = isSpot ? driftClient.getOracleDataForSpotMarket(normedMarketIndex) : driftClient.getOracleDataForPerpMarket(normedMarketIndex); - const response = { + l2Formatted = { bids: [], asks: [], marketType: normedMarketType, @@ -573,26 +580,14 @@ const main = async (): Promise => { ts: Date.now(), marketSlot: dlobProvider.getSlot(), }; - l2Formatted = JSON.stringify(response); - } - - if (l2Formatted) { - cacheHitCounter.add(1, { - miss: false, - path: req.baseUrl + req.path, - }); - res.writeHead(200); - res.end(l2Formatted); - return; - } else { - cacheHitCounter.add(1, { - miss: true, - path: req.baseUrl + req.path, - }); - res.writeHead(500); - res.end('No dlob data found'); - return; } + cacheHitCounter.add(1, { + miss: cacheMiss, + path: req.baseUrl + req.path, + }); + res.writeHead(200); + res.end(JSON.stringify(l2Formatted)); + return; } catch (err) { next(err); } @@ -660,15 +655,22 @@ const main = async (): Promise => { selectMostRecentBySlot ); const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); + let cacheMiss = true; if (redisL2) { + cacheMiss = false; redisL2['bids'] = redisL2['bids']?.slice(0, depth); redisL2['asks'] = redisL2['asks']?.slice(0, depth); l2Formatted = redisL2; } else { + console.log( + `No L2 found for ${getVariant( + normedMarketType + )} market ${normedMarketIndex}` + ); const oracleData = isSpot ? driftClient.getOracleDataForSpotMarket(normedMarketIndex) : driftClient.getOracleDataForPerpMarket(normedMarketIndex); - const response = { + l2Formatted = { bids: [], asks: [], marketType: normedMarketType, @@ -687,17 +689,16 @@ const main = async (): Promise => { ts: Date.now(), marketSlot: dlobProvider.getSlot(), }; - l2Formatted = JSON.stringify(response); } if (l2Formatted) { cacheHitCounter.add(1, { - miss: false, + miss: cacheMiss, path: req.baseUrl + req.path, }); } else { cacheHitCounter.add(1, { - miss: true, + miss: cacheMiss, path: req.baseUrl + req.path, }); } From 91c125f2359771697ee0b90719b0e0ee069c1f7e Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 10 Dec 2024 12:13:23 -0800 Subject: [PATCH 3/3] bump common --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index e91ef8b..006397d 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit e91ef8b3ea8ca61bba760e4b8804cd9d12c1f26d +Subproject commit 006397d9c8f1b0aaf4d42186534bcf3252d1abcd