From e87b1162d76d486376c169c2cf1496ab0821d7b9 Mon Sep 17 00:00:00 2001 From: wphan Date: Tue, 28 Nov 2023 12:42:17 -0800 Subject: [PATCH] bump sdk, make user stats map work --- market_making_examples/jitMaker/index.ts | 17 ++++++++----- package.json | 4 +-- src/bots/filler.ts | 28 ++++++++++----------- src/bots/fillerLite.ts | 5 +--- src/bots/spotFiller.ts | 31 +++--------------------- src/bots/uncrossArbBot.ts | 6 ----- src/index.ts | 1 - 7 files changed, 30 insertions(+), 62 deletions(-) diff --git a/market_making_examples/jitMaker/index.ts b/market_making_examples/jitMaker/index.ts index 2a47f88f..ca27795c 100644 --- a/market_making_examples/jitMaker/index.ts +++ b/market_making_examples/jitMaker/index.ts @@ -213,17 +213,22 @@ const main = async () => { const slotSubscriber = new SlotSubscriber(connection, {}); await slotSubscriber.subscribe(); + logger.info(`Initing usermap...`); + const initUserMapStart = Date.now(); + const userStatsMap = new UserStatsMap( + driftClient, + ); const userMap = new UserMap( driftClient, driftClient.userAccountSubscriptionConfig, - false + false, + async (authorities) => { + await userStatsMap.sync(authorities); + }, + { hasOpenOrders: true } ); await userMap.subscribe(); - const userStatsMap = new UserStatsMap( - driftClient, - driftClient.userAccountSubscriptionConfig - ); - await userStatsMap.subscribe(); + logger.info(`Usermap init took: ${Date.now() - initUserMapStart}ms`); const dlobSubscriber = new DLOBSubscriber({ driftClient, diff --git a/package.json b/package.json index aa84effe..13f9eedd 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "lib/index.js", "license": "Apache-2.0", "dependencies": { - "@drift-labs/jit-proxy": "0.10.91", - "@drift-labs/sdk": "2.48.0-beta.2", + "@drift-labs/jit-proxy": "0.10.97", + "@drift-labs/sdk": "2.48.0-beta.11", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/src/bots/filler.ts b/src/bots/filler.ts index 7aa7fbc4..fee8c26b 100644 --- a/src/bots/filler.ts +++ b/src/bots/filler.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { ReferrerInfo, isOracleValid, @@ -523,23 +522,23 @@ export class FillerBot implements Bot { public async init() { logger.info(`${this.name} initing`); - if (!this.userMap) { - this.userMap = new UserMap( - this.driftClient, - this.driftClient.userAccountSubscriptionConfig, - false - ); - await this.userMap.subscribe(); - } - - this.userStatsMap = new UserStatsMap( + logger.info(`${this.name} initing userMap`); + const startInitUserMap = Date.now(); + this.userStatsMap = new UserStatsMap(this.driftClient); + this.userMap = new UserMap( this.driftClient, - this.userStatsMapSubscriptionConfig + this.driftClient.userAccountSubscriptionConfig, + false ); - await this.userStatsMap.subscribe(); + await this.userMap.subscribe(); + + // sync userstats once + await this.userStatsMap.sync(this.userMap!.getUniqueAuthorities()); logger.info( - `initial userMap size: ${this.userMap.size()}, userStatsMap: ${this.userStatsMap.size()}` + `Initialize userMap size: ${this.userMap.size()}, userStatsMap: ${this.userStatsMap.size()}, took: ${ + Date.now() - startInitUserMap + } ms` ); this.dlobSubscriber = new DLOBSubscriber({ @@ -566,7 +565,6 @@ export class FillerBot implements Bot { await this.dlobSubscriber!.unsubscribe(); await this.userMap!.unsubscribe(); - await this.userStatsMap!.unsubscribe(); } public async startIntervalLoop(_intervalMs?: number) { diff --git a/src/bots/fillerLite.ts b/src/bots/fillerLite.ts index 26776a82..bf8d4c10 100644 --- a/src/bots/fillerLite.ts +++ b/src/bots/fillerLite.ts @@ -65,10 +65,7 @@ export class FillerLiteBot extends FillerBot { // Initializing so we can use mustGet for RPC fall back, but don't subscribe // so we don't call getProgramAccounts - this.userStatsMap = new UserStatsMap( - this.driftClient, - this.userStatsMapSubscriptionConfig - ); + this.userStatsMap = new UserStatsMap(this.driftClient); await this.orderSubscriber.subscribe(); await sleepMs(1200); // Wait a few slots to build up order book diff --git a/src/bots/spotFiller.ts b/src/bots/spotFiller.ts index e2e947e4..7d13c4d5 100644 --- a/src/bots/spotFiller.ts +++ b/src/bots/spotFiller.ts @@ -17,13 +17,11 @@ import { SerumFulfillmentConfigMap, SerumV3FulfillmentConfigAccount, OrderActionRecord, - BulkAccountLoader, OrderRecord, convertToNumber, PRICE_PRECISION, WrappedEvent, DLOBNode, - UserSubscriptionConfig, DLOBSubscriber, SlotSubscriber, PhoenixFulfillmentConfigMap, @@ -134,8 +132,6 @@ export class SpotFillerBot implements Bot { public readonly defaultIntervalMs: number = 2000; private slotSubscriber: SlotSubscriber; - private bulkAccountLoader?: BulkAccountLoader; - private userStatsMapSubscriptionConfig: UserSubscriptionConfig; private driftClient: DriftClient; private eventSubscriber: EventSubscriber; private pollingIntervalMs: number; @@ -186,38 +182,18 @@ export class SpotFillerBot implements Bot { constructor( slotSubscriber: SlotSubscriber, - bulkAccountLoader: BulkAccountLoader | undefined, driftClient: DriftClient, userMap: UserMap, eventSubscriber: EventSubscriber, runtimeSpec: RuntimeSpec, config: FillerConfig ) { - if (!bulkAccountLoader) { - throw new Error( - 'SpotFiller only works in polling mode (cannot run with --websocket flag) bulkAccountLoader is required' - ); - } this.name = config.botId; this.dryRun = config.dryRun; this.slotSubscriber = slotSubscriber; this.driftClient = driftClient; this.eventSubscriber = eventSubscriber; this.userMap = userMap; - this.bulkAccountLoader = bulkAccountLoader; - if (this.bulkAccountLoader) { - this.userStatsMapSubscriptionConfig = { - type: 'polling', - accountLoader: new BulkAccountLoader( - this.bulkAccountLoader.connection, - this.bulkAccountLoader.commitment, - 0 // no polling - ), - }; - } else { - this.userStatsMapSubscriptionConfig = - this.driftClient.userAccountSubscriptionConfig; - } this.runtimeSpec = runtimeSpec; this.pollingIntervalMs = config.fillerPollingInterval ?? this.defaultIntervalMs; @@ -382,11 +358,10 @@ export class SpotFillerBot implements Bot { const initPromises: Array> = []; - this.userStatsMap = new UserStatsMap( - this.driftClient, - this.userStatsMapSubscriptionConfig + this.userStatsMap = new UserStatsMap(this.driftClient); + initPromises.push( + this.userStatsMap.sync(this.userMap.getUniqueAuthorities()) ); - initPromises.push(this.userStatsMap.subscribe()); this.dlobSubscriber = new DLOBSubscriber({ dlobSource: this.userMap, diff --git a/src/bots/uncrossArbBot.ts b/src/bots/uncrossArbBot.ts index 6578af6d..0debbafb 100644 --- a/src/bots/uncrossArbBot.ts +++ b/src/bots/uncrossArbBot.ts @@ -9,9 +9,7 @@ import { DLOBSubscriber, UserMap, SlotSubscriber, - UserStatsMap, MakerInfo, - PerpMarkets, getUserStatsAccountPublicKey, } from '@drift-labs/sdk'; import { Mutex, tryAcquire, E_ALREADY_LOCKED } from 'async-mutex'; @@ -20,7 +18,6 @@ import { Bot } from '../types'; import { getBestLimitAskExcludePubKey, getBestLimitBidExcludePubKey, - sleepMs, } from '../utils'; import { JitProxyClient } from '@drift-labs/jit-proxy/lib'; import dotenv = require('dotenv'); @@ -29,12 +26,9 @@ dotenv.config(); import { BaseBotConfig } from 'src/config'; import { AddressLookupTableAccount, - ComputeBudgetInstruction, ComputeBudgetProgram, } from '@solana/web3.js'; -const TARGET_LEVERAGE_PER_ACCOUNT = 1; - /** * This is an example of a bot that implements the Bot interface. */ diff --git a/src/index.ts b/src/index.ts index 07119d27..40bad5b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -499,7 +499,6 @@ const runBot = async () => { bots.push( new SpotFillerBot( slotSubscriber, - bulkAccountLoader, driftClient, userMap, eventSubscriber,