From 8119191f7ec4f97452616aa295544255269993bf Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Sat, 9 Dec 2023 15:17:16 -0800 Subject: [PATCH 1/3] fix spot filler websocket --- src/bots/spotFiller.ts | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/bots/spotFiller.ts b/src/bots/spotFiller.ts index dd994a1e..95e35562 100644 --- a/src/bots/spotFiller.ts +++ b/src/bots/spotFiller.ts @@ -32,6 +32,7 @@ import { TEN, NodeToTrigger, PriorityFeeCalculator, + BulkAccountLoader, } from '@drift-labs/sdk'; import { Mutex, tryAcquire, E_ALREADY_LOCKED } from 'async-mutex'; @@ -378,6 +379,17 @@ export class SpotFillerBot implements Bot { const config = initialize({ env: this.runtimeSpec.driftEnv as DriftEnv }); for (const spotMarketConfig of config.SPOT_MARKETS) { + const bulkAccountLoader = + ( + this.driftClient + .accountSubscriber as PollingDriftClientAccountSubscriber + ).accountLoader ?? + new BulkAccountLoader( + this.driftClient.connection, + 'confirmed', + this.pollingIntervalMs + ); + if (spotMarketConfig.serumMarket) { // set up fulfillment config await this.serumFulfillmentConfigMap.add( @@ -385,9 +397,14 @@ export class SpotFillerBot implements Bot { spotMarketConfig.serumMarket ); - const serumConfigAccount = this.serumFulfillmentConfigMap.get( - spotMarketConfig.marketIndex - ); + // const serumConfigAccount = this.serumFulfillmentConfigMap.get( + // spotMarketConfig.marketIndex + // ); + const serumConfigAccount = + await this.driftClient.getSerumV3FulfillmentConfig( + spotMarketConfig.serumMarket + ); + if (isVariant(serumConfigAccount.status, 'enabled')) { // set up serum price subscriber const serumSubscriber = new SerumSubscriber({ @@ -396,10 +413,7 @@ export class SpotFillerBot implements Bot { marketAddress: spotMarketConfig.serumMarket, accountSubscription: { type: 'polling', - accountLoader: ( - this.driftClient - .accountSubscriber as PollingDriftClientAccountSubscriber - ).accountLoader, + accountLoader: bulkAccountLoader, }, }); initPromises.push(serumSubscriber.subscribe()); @@ -428,10 +442,7 @@ export class SpotFillerBot implements Bot { marketAddress: spotMarketConfig.phoenixMarket, accountSubscription: { type: 'polling', - accountLoader: ( - this.driftClient - .accountSubscriber as PollingDriftClientAccountSubscriber - ).accountLoader, + accountLoader: bulkAccountLoader, }, }); initPromises.push(phoenixSubscriber.subscribe()); From 4dd0e829d7567eb05b38afe680d69dc327f158c7 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Sat, 9 Dec 2023 15:38:58 -0800 Subject: [PATCH 2/3] use whatever method drift client uses --- src/bots/spotFiller.ts | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/bots/spotFiller.ts b/src/bots/spotFiller.ts index 95e35562..786e09fa 100644 --- a/src/bots/spotFiller.ts +++ b/src/bots/spotFiller.ts @@ -379,16 +379,33 @@ export class SpotFillerBot implements Bot { const config = initialize({ env: this.runtimeSpec.driftEnv as DriftEnv }); for (const spotMarketConfig of config.SPOT_MARKETS) { - const bulkAccountLoader = + let accountSubscription: + | { + type: 'polling'; + accountLoader: BulkAccountLoader; + } + | { + type: 'websocket'; + }; + if ( ( this.driftClient .accountSubscriber as PollingDriftClientAccountSubscriber - ).accountLoader ?? - new BulkAccountLoader( - this.driftClient.connection, - 'confirmed', - this.pollingIntervalMs - ); + ).accountLoader + ) { + accountSubscription = { + type: 'polling', + accountLoader: ( + this.driftClient + .accountSubscriber as PollingDriftClientAccountSubscriber + ).accountLoader, + }; + } else { + console.log('here'); + accountSubscription = { + type: 'websocket', + }; + } if (spotMarketConfig.serumMarket) { // set up fulfillment config @@ -411,10 +428,7 @@ export class SpotFillerBot implements Bot { connection: this.driftClient.connection, programId: new PublicKey(config.SERUM_V3), marketAddress: spotMarketConfig.serumMarket, - accountSubscription: { - type: 'polling', - accountLoader: bulkAccountLoader, - }, + accountSubscription, }); initPromises.push(serumSubscriber.subscribe()); this.serumSubscribers.set( @@ -440,10 +454,7 @@ export class SpotFillerBot implements Bot { connection: this.driftClient.connection, programId: new PublicKey(config.PHOENIX), marketAddress: spotMarketConfig.phoenixMarket, - accountSubscription: { - type: 'polling', - accountLoader: bulkAccountLoader, - }, + accountSubscription, }); initPromises.push(phoenixSubscriber.subscribe()); this.phoenixSubscribers.set( From 08cffd9bc08bbeeb445064908970746b632c2322 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Sat, 9 Dec 2023 15:40:58 -0800 Subject: [PATCH 3/3] remove console log --- src/bots/spotFiller.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bots/spotFiller.ts b/src/bots/spotFiller.ts index 786e09fa..d4fb8737 100644 --- a/src/bots/spotFiller.ts +++ b/src/bots/spotFiller.ts @@ -401,7 +401,6 @@ export class SpotFillerBot implements Bot { ).accountLoader, }; } else { - console.log('here'); accountSubscription = { type: 'websocket', };