Skip to content

Commit

Permalink
bump sdk, make user stats map work
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Nov 28, 2023
1 parent 36a463d commit e87b116
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 62 deletions.
17 changes: 11 additions & 6 deletions market_making_examples/jitMaker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 13 additions & 15 deletions src/bots/filler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import {
ReferrerInfo,
isOracleValid,
Expand Down Expand Up @@ -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({
Expand All @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions src/bots/fillerLite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 3 additions & 28 deletions src/bots/spotFiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import {
SerumFulfillmentConfigMap,
SerumV3FulfillmentConfigAccount,
OrderActionRecord,
BulkAccountLoader,
OrderRecord,
convertToNumber,
PRICE_PRECISION,
WrappedEvent,
DLOBNode,
UserSubscriptionConfig,
DLOBSubscriber,
SlotSubscriber,
PhoenixFulfillmentConfigMap,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -382,11 +358,10 @@ export class SpotFillerBot implements Bot {

const initPromises: Array<Promise<any>> = [];

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,
Expand Down
6 changes: 0 additions & 6 deletions src/bots/uncrossArbBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');
Expand All @@ -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.
*/
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ const runBot = async () => {
bots.push(
new SpotFillerBot(
slotSubscriber,
bulkAccountLoader,
driftClient,
userMap,
eventSubscriber,
Expand Down

0 comments on commit e87b116

Please sign in to comment.