Skip to content

Commit

Permalink
Merge pull request #96 from drift-labs/nour/spot-filler-fix
Browse files Browse the repository at this point in the history
fix spot filler websocket
  • Loading branch information
NourAlharithi authored Dec 10, 2023
2 parents 5892678 + 08cffd9 commit 205522a
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions src/bots/spotFiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
TEN,
NodeToTrigger,
PriorityFeeCalculator,
BulkAccountLoader,
} from '@drift-labs/sdk';
import { Mutex, tryAcquire, E_ALREADY_LOCKED } from 'async-mutex';

Expand Down Expand Up @@ -378,29 +379,55 @@ export class SpotFillerBot implements Bot {

const config = initialize({ env: this.runtimeSpec.driftEnv as DriftEnv });
for (const spotMarketConfig of config.SPOT_MARKETS) {
let accountSubscription:
| {
type: 'polling';
accountLoader: BulkAccountLoader;
}
| {
type: 'websocket';
};
if (
(
this.driftClient
.accountSubscriber as PollingDriftClientAccountSubscriber
).accountLoader
) {
accountSubscription = {
type: 'polling',
accountLoader: (
this.driftClient
.accountSubscriber as PollingDriftClientAccountSubscriber
).accountLoader,
};
} else {
accountSubscription = {
type: 'websocket',
};
}

if (spotMarketConfig.serumMarket) {
// set up fulfillment config
await this.serumFulfillmentConfigMap.add(
spotMarketConfig.marketIndex,
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({
connection: this.driftClient.connection,
programId: new PublicKey(config.SERUM_V3),
marketAddress: spotMarketConfig.serumMarket,
accountSubscription: {
type: 'polling',
accountLoader: (
this.driftClient
.accountSubscriber as PollingDriftClientAccountSubscriber
).accountLoader,
},
accountSubscription,
});
initPromises.push(serumSubscriber.subscribe());
this.serumSubscribers.set(
Expand All @@ -426,13 +453,7 @@ export class SpotFillerBot implements Bot {
connection: this.driftClient.connection,
programId: new PublicKey(config.PHOENIX),
marketAddress: spotMarketConfig.phoenixMarket,
accountSubscription: {
type: 'polling',
accountLoader: (
this.driftClient
.accountSubscriber as PollingDriftClientAccountSubscriber
).accountLoader,
},
accountSubscription,
});
initPromises.push(phoenixSubscriber.subscribe());
this.phoenixSubscribers.set(
Expand Down

0 comments on commit 205522a

Please sign in to comment.