Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spot filler fix #97

Merged
merged 4 commits into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading