From c8405085e6b9f63d6c04de5a556c0ab7892265f1 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Thu, 16 May 2024 06:40:08 -0700 Subject: [PATCH] bulk account loader for phoenix --- src/index.ts | 20 +++++++++++++++----- src/publishers/dlobPublisher.ts | 19 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 377aee7..6277091 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,8 @@ import { isVariant, OrderSubscriber, MarketType, + PhoenixSubscriber, + BulkAccountLoader, } from '@drift-labs/sdk'; import { logger, setLogLevel } from './utils/logger'; @@ -36,7 +38,6 @@ import { SubscriberLookup, addOracletoResponse, errorHandler, - getPhoenixSubscriber, getSerumSubscriber, l2WithBNToStrings, normalizeBatchQueryParams, @@ -169,11 +170,20 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => { const phoenixConfigAccount = await driftClient.getPhoenixV1FulfillmentConfig(market.phoenixMarket); if (isVariant(phoenixConfigAccount.status, 'enabled')) { - const phoenixSubscriber = getPhoenixSubscriber( - driftClient, - market, - sdkConfig + const bulkAccountLoader = new BulkAccountLoader( + driftClient.connection, + stateCommitment, + 5_000 ); + const phoenixSubscriber = new PhoenixSubscriber({ + connection: driftClient.connection, + programId: new PublicKey(sdkConfig.PHOENIX), + marketAddress: phoenixConfigAccount.phoenixMarket, + accountSubscription: { + type: 'polling', + accountLoader: bulkAccountLoader, + }, + }); await phoenixSubscriber.subscribe(); // Test get L2 to know if we should add try { diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 08e8e78..3687e2a 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -17,12 +17,12 @@ import { OracleInfo, PerpMarketConfig, SpotMarketConfig, + PhoenixSubscriber, } from '@drift-labs/sdk'; import { logger, setLogLevel } from '../utils/logger'; import { SubscriberLookup, - getPhoenixSubscriber, getSerumSubscriber, parsePositiveIntArray, sleep, @@ -206,11 +206,20 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => { logger.info( `Loading phoenix subscriber for spot market ${market.marketIndex}` ); - const phoenixSubscriber = getPhoenixSubscriber( - driftClient, - marketConfig, - sdkConfig + const bulkAccountLoader = new BulkAccountLoader( + driftClient.connection, + stateCommitment, + 5_000 ); + const phoenixSubscriber = new PhoenixSubscriber({ + connection: driftClient.connection, + programId: new PublicKey(sdkConfig.PHOENIX), + marketAddress: phoenixConfigAccount.phoenixMarket, + accountSubscription: { + type: 'polling', + accountLoader: bulkAccountLoader, + }, + }); await phoenixSubscriber.subscribe(); // Test get L2 to know if we should add try {