diff --git a/package.json b/package.json index 9b8a8f8..729e823 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "license": "Apache-2.0", "dependencies": { - "@drift-labs/sdk": "2.48.0-beta.11", + "@drift-labs/sdk": "2.48.0-beta.13", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/src/index.ts b/src/index.ts index f96be35..ad00bb5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -276,6 +276,7 @@ const main = async () => { const initUserMapStart = Date.now(); await dlobProvider.subscribe(); logger.info(`dlob provider initialized in ${Date.now() - initUserMapStart} ms`); + logger.info(`dlob provider size ${dlobProvider.size()}`); const initUserStatsMapStarts = Date.now(); await userStatsMap.sync(dlobProvider.getUniqueAuthorities()); diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index a598f30..a9d2a3e 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -9,13 +9,14 @@ import { SlotSubscriber, UserMap, Wallet, - BulkAccountLoader, + BulkAccountLoader, OrderSubscriber, SlotSource, } from '@drift-labs/sdk'; import { logger, setLogLevel } from '../utils/logger'; import { sleep } from '../utils/utils'; import { DLOBSubscriberIO } from '../dlob-subscriber/DLOBSubscriberIO'; import { RedisClient } from '../utils/redisClient'; +import {DLOBProvider, getDLOBProviderFromOrderSubscriber, getDLOBProviderFromUserMap} from "../dlobProvider"; require('dotenv').config(); const driftEnv = (process.env.ENV || 'devnet') as DriftEnv; @@ -37,6 +38,8 @@ setLogLevel(opts.debug ? 'debug' : 'info'); const endpoint = process.env.ENDPOINT; const wsEndpoint = process.env.WS_ENDPOINT; +const useOrderSubscriber = process.env.USE_ORDER_SUBSCRIBER?.toLowerCase() === 'true'; + logger.info(`RPC endpoint: ${endpoint}`); logger.info(`WS endpoint: ${wsEndpoint}`); logger.info(`DriftEnv: ${driftEnv}`); @@ -68,8 +71,6 @@ const main = async () => { env: driftEnv, }); - const slotSubscriber = new SlotSubscriber(connection, {}); - const lamportsBalance = await connection.getBalance(wallet.publicKey); logger.info( `DriftClient ProgramId: ${driftClient.program.programId.toBase58()}` @@ -83,22 +84,45 @@ const main = async () => { logger.error(e); }); - await slotSubscriber.subscribe(); + let slotSource: SlotSource; + let dlobProvider : DLOBProvider; + if (useOrderSubscriber) { + const orderSubscriber = new OrderSubscriber({ + driftClient, + subscriptionConfig: { + type: "polling", + frequency: ORDERBOOK_UPDATE_INTERVAL + }, + }); - const userMap = new UserMap( - driftClient, - driftClient.userAccountSubscriptionConfig, - false - ); - await userMap.subscribe(); + dlobProvider = getDLOBProviderFromOrderSubscriber(orderSubscriber); + + slotSource = { + getSlot: () => orderSubscriber.getSlot(), + }; + } else { + const userMap = new UserMap( + driftClient, + driftClient.userAccountSubscriptionConfig, + false + ); + + dlobProvider = getDLOBProviderFromUserMap(userMap); + + slotSource = { + getSlot: () => bulkAccountLoader.getSlot(), + }; + } + + await dlobProvider.subscribe(); const redisClient = new RedisClient(REDIS_HOST, REDIS_PORT, REDIS_PASSWORD); await redisClient.connect(); const dlobSubscriber = new DLOBSubscriberIO({ driftClient, - dlobSource: userMap, - slotSource: slotSubscriber, + dlobSource: dlobProvider, + slotSource, updateFrequency: ORDERBOOK_UPDATE_INTERVAL, redisClient, }); diff --git a/yarn.lock b/yarn.lock index 09455f5..8f7a265 100644 --- a/yarn.lock +++ b/yarn.lock @@ -80,10 +80,10 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/sdk@2.48.0-beta.11": - version "2.48.0-beta.11" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.48.0-beta.11.tgz#cd2f7b908754d49f62964ab894d3ab6c248dee3f" - integrity sha512-lhBlBUmKT3w9EMTDIBcEUdRgqZ6OHLfqPukxW4gVoa6eFqIpcaTk/DGTj3HCli6C684YwVHJfCQx4kXfffv6Sw== +"@drift-labs/sdk@2.48.0-beta.13": + version "2.48.0-beta.13" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.48.0-beta.13.tgz#0ad1cfd4daac97e1859fe617a749a2676e462b63" + integrity sha512-ogtY38Db44PVZOr8WwNHijnwVMBLFvIYNxmlE9BPehdEgIQ9PYT9QXalanhQ1Ruc/Cs5DbMIT3XvjtLyfFzEUg== dependencies: "@coral-xyz/anchor" "0.28.1-beta.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2"