From e62846149f43e3517e9b3a266c789116e2d49482 Mon Sep 17 00:00:00 2001 From: wphan Date: Wed, 6 Dec 2023 07:23:49 -0800 Subject: [PATCH] bump sdk --- package.json | 4 ++-- src/bots/liquidator.ts | 20 ++++++++++++++++---- src/bots/userIdleFlipper.ts | 14 ++++++++------ src/bots/userPnlSettler.ts | 14 ++++++++------ src/index.ts | 29 +++++++++++++++++++++++++---- 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 19335537..14f0a227 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.123", - "@drift-labs/sdk": "2.49.0-beta.9", + "@drift-labs/jit-proxy": "0.10.124", + "@drift-labs/sdk": "2.49.0-beta.10", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/src/bots/liquidator.ts b/src/bots/liquidator.ts index ac732a29..dca1d5bf 100644 --- a/src/bots/liquidator.ts +++ b/src/bots/liquidator.ts @@ -1039,6 +1039,10 @@ export class LiquidatorBot implements Bot { swapMode: jupSwapMode, }); + if (!jupiterRoutes) { + return undefined; + } + console.log('routes'); console.log(JSON.stringify(jupiterRoutes, null, 2)); @@ -1423,7 +1427,7 @@ export class LiquidatorBot implements Bot { } } - private liqBorrow( + private async liqBorrow( depositMarketIndextoLiq: number, borrowMarketIndextoLiq: number, borrowAmountToLiq: BN, @@ -1452,7 +1456,7 @@ export class LiquidatorBot implements Bot { logger.info( `Switching to subaccount ${subAccountToUse} for spot market ${borrowMarketIndextoLiq}` ); - this.driftClient.switchActiveUser( + await this.driftClient.switchActiveUser( subAccountToUse, this.driftClient.authority ); @@ -1800,7 +1804,12 @@ tx: ${tx} ` return b.marginRequirement.gt(a.marginRequirement) ? 1 : -1; }); - for (const { user, userKey, canBeLiquidated } of usersCanBeLiquidated) { + for (const { + user, + userKey, + marginRequirement, + canBeLiquidated, + } of usersCanBeLiquidated) { const userAcc = user.getUserAccount(); const auth = userAcc.authority.toBase58(); @@ -1864,7 +1873,10 @@ tx: ${tx} ` let liquidateeHasSpotPos = false; if (borrowMarketIndextoLiq != -1 && depositMarketIndextoLiq != -1) { liquidateeHasSpotPos = true; - this.liqBorrow( + logger.info( + `User ${userKey} has spot positions to liquidate ${canBeLiquidated}, marginRequirement: ${marginRequirement}` + ); + await this.liqBorrow( depositMarketIndextoLiq, borrowMarketIndextoLiq, borrowAmountToLiq, diff --git a/src/bots/userIdleFlipper.ts b/src/bots/userIdleFlipper.ts index efde6756..99ab93ea 100644 --- a/src/bots/userIdleFlipper.ts +++ b/src/bots/userIdleFlipper.ts @@ -51,14 +51,16 @@ export class UserIdleFlipperBot implements Bot { }, }) ); - this.userMap = new UserMap( - this.driftClient, - { + this.userMap = new UserMap({ + driftClient: this.driftClient, + subscriptionConfig: { type: 'polling', - accountLoader: bulkAccountLoader, + frequency: 60_000, + commitment: this.driftClient.opts?.commitment, }, - false - ); + skipInitialLoad: false, + includeIdle: false, + }); } public async init() { diff --git a/src/bots/userPnlSettler.ts b/src/bots/userPnlSettler.ts index ec11c29c..3d5992a7 100644 --- a/src/bots/userPnlSettler.ts +++ b/src/bots/userPnlSettler.ts @@ -88,14 +88,16 @@ export class UserPnlSettlerBot implements Bot { }, }) ); - this.userMap = new UserMap( - this.driftClient, - { + this.userMap = new UserMap({ + driftClient: this.driftClient, + subscriptionConfig: { type: 'polling', - accountLoader: bulkAccountLoader, + frequency: 60_000, + commitment: this.driftClient.opts?.commitment, }, - false - ); + skipInitialLoad: false, + includeIdle: false, + }); } public async init() { diff --git a/src/index.ts b/src/index.ts index 14caa4cb..a0385d7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -202,6 +202,21 @@ const runBot = async () => { let logProviderConfig: LogProviderConfig = { type: 'websocket', }; + let userMapSubscriptionConfig: + | { + type: 'polling'; + frequency: number; + commitment?: Commitment; + } + | { + type: 'websocket'; + resubTimeoutMs?: number; + commitment?: Commitment; + } = { + type: 'polling', + frequency: 60_000, + commitment: stateCommitment, + }; if (!config.global.websocket) { const bulkAccountLoaderConnection = new Connection(endpoint, { @@ -223,6 +238,11 @@ const runBot = async () => { type: 'polling', frequency: config.global.eventSubscriberPollingInterval, }; + userMapSubscriptionConfig = { + type: 'websocket', + resubTimeoutMs: 30_000, + commitment: stateCommitment, + }; } const opts = { @@ -345,11 +365,12 @@ const runBot = async () => { let needCheckDriftUser = false; let needForceCollateral = !!config.global.forceDeposit; let needUserMapSubscribe = false; - const userMap = new UserMap( + const userMap = new UserMap({ driftClient, - driftClient.userAccountSubscriptionConfig, - false - ); + subscriptionConfig: userMapSubscriptionConfig, + skipInitialLoad: false, + includeIdle: false, + }); if (configHasBot(config, 'filler')) { needCheckDriftUser = true; needUserMapSubscribe = true;