From ae0f9a488982d1bdd6c89bf4bec345001b3e8898 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:43:14 +0000 Subject: [PATCH 1/5] Bumping drift-common to 4bb684c5b5f7dad7d2d472cc44296951fa815c71 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 91bcf1a..4bb684c 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 91bcf1a17eac80d2ce479be5839bdd87a9d26397 +Subproject commit 4bb684c5b5f7dad7d2d472cc44296951fa815c71 From 6f9873676e478be727ae22bff6890bb6caacfc99 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Thu, 10 Jul 2025 11:50:59 -0700 Subject: [PATCH 2/5] patch indicative liquidity filtering --- src/dlob-subscriber/DLOBSubscriberIO.ts | 50 ++++++++++++++----------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index db7636b..2e8de5c 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -227,20 +227,20 @@ export class DLOBSubscriberIO extends DLOBSubscriber { }; if (quote['bid_size'] && quote['bid_price'] != null) { - // Sanity check bid price and size - const indicativeBid: Order = Object.assign( + // Sanity check bid price and size and change to top of book if necessary + let indicativeBid: Order = Object.assign( {}, indicativeBaseOrder, { orderId: indicativeOrderId, + direction: PositionDirection.LONG, + baseAssetAmount: new BN(quote['bid_size']), oraclePriceOffset: quote['is_oracle_offset'] ? quote['bid_price'] : 0, price: quote['is_oracle_offset'] ? 0 : new BN(quote['bid_price']), - baseAssetAmount: new BN(quote['bid_size']), - direction: PositionDirection.LONG, } ); const limitPrice = getLimitPrice( @@ -248,18 +248,22 @@ export class DLOBSubscriberIO extends DLOBSubscriber { oraclePriceData, this.slotSource.getSlot() ); - if (limitPrice.lte(bestBid)) { - this.dlob.insertOrder( - indicativeBid, - INDICATIVE_QUOTES_PUBKEY, - this.slotSource.getSlot(), - false - ); - indicativeOrderId += 1; + if (limitPrice.gt(bestBid)) { + indicativeBid = Object.assign({}, indicativeBid, { + price: bestBid, + oraclePriceOffset: 0, + }); } + this.dlob.insertOrder( + indicativeBid, + INDICATIVE_QUOTES_PUBKEY, + this.slotSource.getSlot(), + false + ); + indicativeOrderId += 1; } if (quote['ask_size'] && quote['ask_price'] != null) { - const indicativeAsk: Order = Object.assign( + let indicativeAsk: Order = Object.assign( {}, indicativeBaseOrder, { @@ -279,15 +283,19 @@ export class DLOBSubscriberIO extends DLOBSubscriber { oraclePriceData, this.slotSource.getSlot() ); - if (limitPrice.gte(bestAsk)) { - this.dlob.insertOrder( - indicativeAsk, - INDICATIVE_QUOTES_PUBKEY, - this.slotSource.getSlot(), - false - ); - indicativeOrderId += 1; + if (limitPrice.lt(bestAsk)) { + indicativeAsk = Object.assign({}, indicativeAsk, { + price: bestAsk, + oraclePriceOffset: 0, + }); } + this.dlob.insertOrder( + indicativeAsk, + INDICATIVE_QUOTES_PUBKEY, + this.slotSource.getSlot(), + false + ); + indicativeOrderId += 1; } } } From a343c346e7bd8e3a8a93a70a8c887dbb0c85bb24 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Thu, 10 Jul 2025 11:52:06 -0700 Subject: [PATCH 3/5] prettify --- src/dlob-subscriber/DLOBSubscriberIO.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 2e8de5c..276c543 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -227,14 +227,12 @@ export class DLOBSubscriberIO extends DLOBSubscriber { }; if (quote['bid_size'] && quote['bid_price'] != null) { - // Sanity check bid price and size and change to top of book if necessary + // Sanity check bid price and size let indicativeBid: Order = Object.assign( {}, indicativeBaseOrder, { orderId: indicativeOrderId, - direction: PositionDirection.LONG, - baseAssetAmount: new BN(quote['bid_size']), oraclePriceOffset: quote['is_oracle_offset'] ? quote['bid_price'] : 0, From 14659a36bed0b41cd4aae19b7bc7ac8e1360c07f Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 10 Jul 2025 20:23:42 +0000 Subject: [PATCH 4/5] Bumping drift-common to 7f1dafe31227bca65ff6507737d9e0ea12e89b44 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 4bb684c..7f1dafe 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 4bb684c5b5f7dad7d2d472cc44296951fa815c71 +Subproject commit 7f1dafe31227bca65ff6507737d9e0ea12e89b44 From 68094cbda26afa75746ff5e170966733f6ce14f5 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Thu, 10 Jul 2025 13:25:54 -0700 Subject: [PATCH 5/5] include vamm in indicative quotes price min/max --- src/dlob-subscriber/DLOBSubscriberIO.ts | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 276c543..467efbc 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -13,6 +13,7 @@ import { PerpOperation, PositionDirection, ZERO, + calculateBidAskPrice, getLimitPrice, isOperationPaused, isVariant, @@ -39,7 +40,7 @@ export type wsMarketArgs = { numVammOrders?: number; fallbackL2Generators?: L2OrderBookGenerator[]; updateOnChange?: boolean; - tickSize?: BN; + tickSize: BN; }; require('dotenv').config(); @@ -162,13 +163,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber { : this.driftClient.getOracleDataForSpotMarket( marketArgs.marketIndex ); - const bestBid = dlob.getBestBid( + const bestDlobBid = dlob.getBestBid( marketArgs.marketIndex, this.slotSource.getSlot(), marketArgs.marketType, oraclePriceData ); - const bestAsk = dlob.getBestAsk( + const bestDlobAsk = dlob.getBestAsk( marketArgs.marketIndex, this.slotSource.getSlot(), marketArgs.marketType, @@ -179,6 +180,21 @@ export class DLOBSubscriberIO extends DLOBSubscriber { ? 'perp' : 'spot'; + let bestBid = bestDlobBid; + let bestAsk = bestDlobAsk; + if (marketType === 'perp') { + const [bestVammBid, bestVammAsk] = calculateBidAskPrice( + this.driftClient.getPerpMarketAccount(marketArgs.marketIndex).amm, + oraclePriceData, + true + ); + + bestBid = + bestBid && bestBid.gt(bestVammBid) ? bestBid : bestVammBid; + bestAsk = + bestAsk && bestAsk.lt(bestVammAsk) ? bestAsk : bestVammAsk; + } + const mms = await this.indicativeQuotesRedisClient.smembers( `market_mms_${marketType}_${marketArgs.marketIndex}` ); @@ -233,6 +249,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { indicativeBaseOrder, { orderId: indicativeOrderId, + baseAssetAmount: new BN(quote['bid_size']), oraclePriceOffset: quote['is_oracle_offset'] ? quote['bid_price'] : 0, @@ -246,7 +263,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { oraclePriceData, this.slotSource.getSlot() ); - if (limitPrice.gt(bestBid)) { + if (bestBid && limitPrice.gt(bestBid)) { indicativeBid = Object.assign({}, indicativeBid, { price: bestBid, oraclePriceOffset: 0, @@ -281,7 +298,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { oraclePriceData, this.slotSource.getSlot() ); - if (limitPrice.lt(bestAsk)) { + if (bestAsk && limitPrice.lt(bestAsk)) { indicativeAsk = Object.assign({}, indicativeAsk, { price: bestAsk, oraclePriceOffset: 0, @@ -425,9 +442,6 @@ export class DLOBSubscriberIO extends DLOBSubscriber { lastMarketSlotAndTime && l2Formatted['marketSlot'] !== lastMarketSlotAndTime.slot ) { - logger.warn( - `Updating market slot for ${marketArgs.marketName} from ${lastMarketSlotAndTime.slot} -> ${l2Formatted['marketSlot']}` - ); this.lastMarketSlotMap .get(marketArgs.marketType) .set(marketArgs.marketIndex, {