Skip to content

Commit 3c7a934

Browse files
committed
pmm dlob server
1 parent a5d8d81 commit 3c7a934

File tree

6 files changed

+109
-78
lines changed

6 files changed

+109
-78
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bash redisCluster.sh create
8080

8181
In second terminal, run:
8282
```
83-
yarn run dlob-publisher
83+
yarn run dlob-publish
8484
```
8585

8686
In a third terminal, run:

build_all.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
git submodule init
2+
git submodule update --recursive
3+
4+
echo "building sdk..."
5+
cd drift-common/protocol/sdk
6+
yarn clean && yarn && yarn build
7+
cd ../../..
8+
9+
echo "building drift-common..."
10+
cd drift-common/common-ts
11+
yarn clean && yarn && yarn build
12+
cd ../..
13+
14+
echo "building dlob server..."
15+
yarn clean && yarn && yarn build

src/dlob-subscriber/DLOBSubscriberIO.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,15 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
263263
});
264264

265265
this.redisClient.publish(
266-
`${clientPrefix}orderbook_${marketType}_${marketArgs.marketIndex}`,
266+
`${clientPrefix}orderbook_${marketType}_${marketArgs.marketIndex}${
267+
this.protectedMakerView ? '_pmm' : ''
268+
}`,
267269
l2Formatted
268270
);
269271
this.redisClient.set(
270-
`last_update_orderbook_${marketType}_${marketArgs.marketIndex}`,
272+
`last_update_orderbook_${marketType}_${marketArgs.marketIndex}${
273+
this.protectedMakerView ? '_pmm' : ''
274+
}`,
271275
l2Formatted_depth100
272276
);
273277
const oraclePriceData =
@@ -350,7 +354,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
350354
);
351355

352356
this.redisClient.set(
353-
`last_update_orderbook_l3_${marketType}_${marketArgs.marketIndex}`,
357+
`last_update_orderbook_l3_${marketType}_${marketArgs.marketIndex}${
358+
this.protectedMakerView ? '_pmm' : ''
359+
}`,
354360
l3
355361
);
356362
}

src/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ const main = async (): Promise<void> => {
520520

521521
app.get('/l2', async (req, res, next) => {
522522
try {
523-
const { marketName, marketIndex, marketType, depth } = req.query;
523+
const { marketName, marketIndex, marketType, depth, includePmm } =
524+
req.query;
524525

525526
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
526527
driftClient,
@@ -535,14 +536,14 @@ const main = async (): Promise<void> => {
535536
}
536537

537538
const isSpot = isVariant(normedMarketType, 'spot');
538-
539+
const includePmmStr = (includePmm as string)?.toLowerCase() === 'true';
539540
const adjustedDepth = depth ?? '100';
540541

541542
let l2Formatted: any;
542543
const redisL2 = await fetchFromRedis(
543544
`last_update_orderbook_${
544545
isSpot ? 'spot' : 'perp'
545-
}_${normedMarketIndex}`,
546+
}_${normedMarketIndex}${includePmmStr ? '_pmm' : ''}`,
546547
selectMostRecentBySlot
547548
);
548549
const depthToUse = Math.min(parseInt(adjustedDepth as string) ?? 1, 100);
@@ -604,6 +605,7 @@ const main = async (): Promise<void> => {
604605
includePhoenix,
605606
includeOpenbook,
606607
includeOracle,
608+
includePmm,
607609
} = req.query;
608610

609611
const normedParams = normalizeBatchQueryParams({
@@ -615,6 +617,7 @@ const main = async (): Promise<void> => {
615617
includePhoenix: includePhoenix as string | undefined,
616618
includeOpenbook: includeOpenbook as string | undefined,
617619
includeOracle: includeOracle as string | undefined,
620+
includePmm: includePmm as string | undefined,
618621
});
619622

620623
if (normedParams === undefined) {
@@ -645,13 +648,14 @@ const main = async (): Promise<void> => {
645648
}
646649

647650
const isSpot = isVariant(normedMarketType, 'spot');
651+
const normedIncludePmm = normedParam['includePmm'] == 'true';
648652

649653
const adjustedDepth = normedParam['depth'] ?? '100';
650654
let l2Formatted: any;
651655
const redisL2 = await fetchFromRedis(
652656
`last_update_orderbook_${
653657
isSpot ? 'spot' : 'perp'
654-
}_${normedMarketIndex}`,
658+
}_${normedMarketIndex}${normedIncludePmm ? '_pmm' : ''}`,
655659
selectMostRecentBySlot
656660
);
657661
const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100);
@@ -721,7 +725,7 @@ const main = async (): Promise<void> => {
721725

722726
app.get('/l3', async (req, res, next) => {
723727
try {
724-
const { marketName, marketIndex, marketType } = req.query;
728+
const { marketName, marketIndex, marketType, includePmm } = req.query;
725729

726730
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
727731
driftClient,
@@ -736,9 +740,12 @@ const main = async (): Promise<void> => {
736740
}
737741

738742
const marketTypeStr = getVariant(normedMarketType);
743+
const normedIncludePmm = (includePmm as string)?.toLowerCase() === 'true';
739744

740745
const redisL3 = await fetchFromRedis(
741-
`last_update_orderbook_l3_${marketTypeStr}_${normedMarketIndex}`,
746+
`last_update_orderbook_l3_${marketTypeStr}_${normedMarketIndex}${
747+
normedIncludePmm ? '_pmm' : ''
748+
}`,
742749
selectMostRecentBySlot
743750
);
744751
if (redisL3) {

src/publishers/dlobPublisher.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,25 @@ const main = async () => {
497497
perpMarketInfos,
498498
spotMarketInfos,
499499
killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD,
500+
protectedMakerView: false,
500501
});
501502
await dlobSubscriber.subscribe();
503+
504+
const dlobSubscriberPmm = new DLOBSubscriberIO({
505+
driftClient,
506+
env: driftEnv,
507+
dlobSource: dlobProvider,
508+
slotSource,
509+
updateFrequency: ORDERBOOK_UPDATE_INTERVAL,
510+
redisClient,
511+
spotMarketSubscribers: MARKET_SUBSCRIBERS,
512+
perpMarketInfos,
513+
spotMarketInfos,
514+
killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD,
515+
protectedMakerView: true,
516+
});
517+
await dlobSubscriberPmm.subscribe();
518+
502519
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
503520
const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => {
504521
setTimeout(() => {

0 commit comments

Comments
 (0)