From 58526bd9d160253b6742c7e456236d349bff0056 Mon Sep 17 00:00:00 2001 From: wphan Date: Mon, 27 Nov 2023 14:50:32 -0800 Subject: [PATCH] bump sdk, new user stats map loading --- example/clientWithSlot.ts | 4 ++-- package.json | 4 ++-- src/index.ts | 40 +++++++++++++++++++-------------------- yarn.lock | 8 ++++---- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/example/clientWithSlot.ts b/example/clientWithSlot.ts index 9f9315b..a03e28d 100644 --- a/example/clientWithSlot.ts +++ b/example/clientWithSlot.ts @@ -55,8 +55,8 @@ const driftClientPublicKey = new PublicKey(sdkConfig.DRIFT_PROGRAM_ID); let lastSeenSlot = 0; /********** initializing driftClient as usual **********/ -var accountSubscription: DriftClientSubscriptionConfig; -var logProviderConfig: LogProviderConfig; +let accountSubscription: DriftClientSubscriptionConfig; +let logProviderConfig: LogProviderConfig; if (useWebsocket) { accountSubscription = { type: 'websocket', diff --git a/package.json b/package.json index 13043b6..96e87a8 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.2", + "@drift-labs/sdk": "2.48.0-beta.4", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", @@ -64,4 +64,4 @@ "lint:fix": "eslint . --ext ts --fix", "playground": "ts-node src/playground.ts" } -} +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index c3775e5..50c90ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,10 @@ import { DLOBOrdersCoder, DLOBSubscriber, DriftClient, + DriftClientSubscriptionConfig, DriftEnv, + SlotSource, + SlotSubscriber, UserMap, UserStatsMap, Wallet, @@ -214,7 +217,6 @@ const main = async () => { programID: clearingHousePublicKey, accountSubscription, env: driftEnv, - userStats: true, }); const dlobCoder = DLOBOrdersCoder.create(); @@ -229,24 +231,22 @@ const main = async () => { lastSlotReceived = slotSource.getSlot(); }, ORDERBOOK_UPDATE_INTERVAL); + const userStatsMap = new UserStatsMap(driftClient); + logger.info(`Initializing userMap...`); const initUserMapStart = Date.now(); const userMap = new UserMap( driftClient, driftClient.userAccountSubscriptionConfig, - false + false, + async (authorities) => { + await userStatsMap.sync(authorities); + }, + { hasOpenOrders: true } ); await userMap.subscribe(); logger.info(`userMap initialized in ${Date.now() - initUserMapStart} ms`); - logger.info(`Initializing userStatsMap...`); - const initUserStatsMapStart = Date.now(); - const userStatsMap = new UserStatsMap(driftClient, accountSubscription); - await userStatsMap.subscribe(); - logger.info( - `userStatsMap initialized in ${Date.now() - initUserStatsMapStart} ms` - ); - logger.info(`Initializing DLOBSubscriber...`); const initDlobSubscriberStart = Date.now(); const dlobSubscriber = new DLOBSubscriber({ @@ -650,11 +650,11 @@ const main = async () => { numVammOrders: parseInt((numVammOrders ?? '100') as string), fallbackL2Generators: isSpot ? [ - `${includePhoenix}`.toLowerCase() === 'true' && - MARKET_SUBSCRIBERS[normedMarketIndex].phoenix, - `${includeSerum}`.toLowerCase() === 'true' && - MARKET_SUBSCRIBERS[normedMarketIndex].serum, - ].filter((a) => !!a) + `${includePhoenix}`.toLowerCase() === 'true' && + MARKET_SUBSCRIBERS[normedMarketIndex].phoenix, + `${includeSerum}`.toLowerCase() === 'true' && + MARKET_SUBSCRIBERS[normedMarketIndex].serum, + ].filter((a) => !!a) : [], }); @@ -768,11 +768,11 @@ const main = async () => { : `${normedParam['includeVamm']}`.toLowerCase() === 'true', fallbackL2Generators: isSpot ? [ - `${normedParam['includePhoenix']}`.toLowerCase() === 'true' && - MARKET_SUBSCRIBERS[normedMarketIndex].phoenix, - `${normedParam['includeSerum']}`.toLowerCase() === 'true' && - MARKET_SUBSCRIBERS[normedMarketIndex].serum, - ].filter((a) => !!a) + `${normedParam['includePhoenix']}`.toLowerCase() === 'true' && + MARKET_SUBSCRIBERS[normedMarketIndex].phoenix, + `${normedParam['includeSerum']}`.toLowerCase() === 'true' && + MARKET_SUBSCRIBERS[normedMarketIndex].serum, + ].filter((a) => !!a) : [], }); diff --git a/yarn.lock b/yarn.lock index cd8e73d..53969be 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.2": - version "2.48.0-beta.2" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.48.0-beta.2.tgz#447cdd132e99e7283eecb96adbce6709724f4e3f" - integrity sha512-zp0OxvuwDDLoqN1GfknPuEDCwPVzLRvRVpnrJFzeTNgBS1ish0ZmqtM5URFMHuXJ9ZaEt3gezqhhlqRID917rQ== +"@drift-labs/sdk@2.48.0-beta.4": + version "2.48.0-beta.4" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.48.0-beta.4.tgz#80395976b04d59fa5340e5c9a7839c72b3ee3c2e" + integrity sha512-gsxKL1xOAtOlybDaI+kAvA070WfqnkaGCPyAs87gILYDAVrCyoGX37EE6e3v098X3qsR0VIAjaVlCqz4nZfPwg== dependencies: "@coral-xyz/anchor" "0.28.1-beta.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2"