Skip to content

Commit

Permalink
bump sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Dec 6, 2023
1 parent a7d4050 commit e628461
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
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.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",
Expand Down
20 changes: 16 additions & 4 deletions src/bots/liquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -1423,7 +1427,7 @@ export class LiquidatorBot implements Bot {
}
}

private liqBorrow(
private async liqBorrow(
depositMarketIndextoLiq: number,
borrowMarketIndextoLiq: number,
borrowAmountToLiq: BN,
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions src/bots/userIdleFlipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 8 additions & 6 deletions src/bots/userPnlSettler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
29 changes: 25 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -223,6 +238,11 @@ const runBot = async () => {
type: 'polling',
frequency: config.global.eventSubscriberPollingInterval,
};
userMapSubscriptionConfig = {
type: 'websocket',
resubTimeoutMs: 30_000,
commitment: stateCommitment,
};
}

const opts = {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e628461

Please sign in to comment.