Skip to content

Commit e6cfd33

Browse files
authored
Merge pull request #364 from drift-labs/master
mb
2 parents 7bae2e9 + 1dab870 commit e6cfd33

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"main": "lib/index.js",
66
"license": "Apache-2.0",
77
"dependencies": {
8-
"@drift-labs/jit-proxy": "0.12.82",
9-
"@drift-labs/sdk": "2.109.0-beta.0",
8+
"@drift-labs/jit-proxy": "0.12.85",
9+
"@drift-labs/sdk": "2.109.0-beta.3",
1010
"@opentelemetry/api": "1.7.0",
1111
"@opentelemetry/auto-instrumentations-node": "0.31.2",
1212
"@opentelemetry/exporter-prometheus": "0.31.0",

src/bots/pythLazerCranker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export class PythLazerCrankerBot implements Bot {
8484
this.pythLazerClient = new PythLazerSubscriber(
8585
this.globalConfig.lazerEndpoint,
8686
this.globalConfig.lazerToken,
87-
feedIdChunks
87+
feedIdChunks,
88+
this.globalConfig.driftEnv
8889
);
8990
this.decodeFunc =
9091
this.driftClient.program.account.pythLazerOracle.coder.accounts.decodeUnchecked.bind(

src/bots/trigger.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PriorityFeeCalculator,
1111
TxParams,
1212
PublicKey,
13+
BlockhashSubscriber,
1314
} from '@drift-labs/sdk';
1415
import { Mutex, tryAcquire, E_ALREADY_LOCKED } from 'async-mutex';
1516

@@ -27,7 +28,8 @@ import {
2728
View,
2829
} from '@opentelemetry/sdk-metrics-base';
2930
import { RuntimeSpec, metricAttrFromUserAccount } from '../metrics';
30-
import { getNodeToTriggerSignature } from '../utils';
31+
import { getNodeToTriggerSignature, getVersionedTransaction } from '../utils';
32+
import { AddressLookupTableAccount } from '@solana/web3.js';
3133

3234
const TRIGGER_ORDER_COOLDOWN_MS = 10000; // time to wait between triggering an order
3335

@@ -52,6 +54,8 @@ export class TriggerBot implements Bot {
5254
private driftClient: DriftClient;
5355
private slotSubscriber: SlotSubscriber;
5456
private dlobSubscriber?: DLOBSubscriber;
57+
private blockhashSubscriber: BlockhashSubscriber;
58+
private lookupTableAccount?: AddressLookupTableAccount;
5559
private triggeringNodes = new Map<string, number>();
5660
private periodicTaskMutex = new Mutex();
5761
private intervalIds: Array<NodeJS.Timer> = [];
@@ -77,6 +81,7 @@ export class TriggerBot implements Bot {
7781
constructor(
7882
driftClient: DriftClient,
7983
slotSubscriber: SlotSubscriber,
84+
blockhashSubscriber: BlockhashSubscriber,
8085
userMap: UserMap,
8186
runtimeSpec: RuntimeSpec,
8287
config: BaseBotConfig
@@ -87,6 +92,7 @@ export class TriggerBot implements Bot {
8792
this.userMap = userMap;
8893
this.runtimeSpec = runtimeSpec;
8994
this.slotSubscriber = slotSubscriber;
95+
this.blockhashSubscriber = blockhashSubscriber;
9096

9197
this.metricsPort = config.metricsPort;
9298
if (this.metricsPort) {
@@ -168,6 +174,9 @@ export class TriggerBot implements Bot {
168174
driftClient: this.driftClient,
169175
});
170176
await this.dlobSubscriber.subscribe();
177+
178+
this.lookupTableAccount =
179+
await this.driftClient.fetchMarketLookupTableAccount();
171180
}
172181

173182
public async reset() {
@@ -198,6 +207,20 @@ export class TriggerBot implements Bot {
198207
return healthy;
199208
}
200209

210+
private async getBlockhashForTx(): Promise<string> {
211+
const cachedBlockhash = this.blockhashSubscriber.getLatestBlockhash(10);
212+
if (cachedBlockhash) {
213+
return cachedBlockhash.blockhash as string;
214+
}
215+
216+
const recentBlockhash =
217+
await this.driftClient.connection.getLatestBlockhash({
218+
commitment: 'confirmed',
219+
});
220+
221+
return recentBlockhash.blockhash;
222+
}
223+
201224
private async tryTriggerForPerpMarket(market: PerpMarketAccount) {
202225
const marketIndex = market.marketIndex;
203226

@@ -258,11 +281,11 @@ export class TriggerBot implements Bot {
258281

259282
ixs.push(await this.driftClient.getRevertFillIx());
260283

261-
const tx = await this.driftClient.txSender.getVersionedTransaction(
284+
const tx = getVersionedTransaction(
285+
this.driftClient.wallet.publicKey,
262286
ixs,
263-
[],
264-
undefined,
265-
this.driftClient.opts
287+
[this.lookupTableAccount!],
288+
await this.getBlockhashForTx()
266289
);
267290

268291
this.driftClient

src/experimental-bots/swift/makerExample.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ export class SwiftMaker {
173173
})
174174
);
175175

176+
if (this.dryRun) {
177+
// console.log('Dry run, not sending transaction');
178+
return;
179+
}
180+
176181
const resp = await simulateAndGetTxWithCUs({
177182
connection: this.driftClient.connection,
178183
payerPublicKey: this.driftClient.wallet.payer!.publicKey,
@@ -185,10 +190,6 @@ export class SwiftMaker {
185190
return;
186191
}
187192

188-
if (this.dryRun) {
189-
console.log('Dry run, not sending transaction');
190-
return;
191-
}
192193
this.driftClient.txSender
193194
.sendVersionedTransaction(resp.tx)
194195
.then((response) => {

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,13 @@ const runBot = async () => {
741741
if (configHasBot(config, 'trigger')) {
742742
needUserMapSubscribe = true;
743743
needDriftStateWatcher = true;
744+
needBlockhashSubscriber = true;
745+
744746
bots.push(
745747
new TriggerBot(
746748
driftClient,
747749
slotSubscriber,
750+
blockhashSubscriber,
748751
userMap,
749752
{
750753
rpcEndpoint: endpoint,

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,20 @@
175175
enabled "2.0.x"
176176
kuler "^2.0.0"
177177

178-
"@drift-labs/[email protected].82":
179-
version "0.12.82"
180-
resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.12.82.tgz#b7befc69f3610fdbda16223f5b3e76aaffb0c242"
181-
integrity sha512-AEkQgolsEkPfkyZHiHoZ4Kgj/JoKUBdOqluexoiQLj8AIftbe/RNpKc4EgClFkM0lpLplMau20yM0Oz5LaG74g==
178+
"@drift-labs/[email protected].85":
179+
version "0.12.85"
180+
resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.12.85.tgz#3a946e428404e653e15f42cf0bd675b0aaaa1444"
181+
integrity sha512-yBkCh14OSWnKassQSQ4JXDmZe87xepGt1PNQhTAoMVlnxiZ2DxaTmc3P8H+SWr5Jk0FD6qMJFAkQJZddAhB9nw==
182182
dependencies:
183183
"@coral-xyz/anchor" "0.26.0"
184-
"@drift-labs/sdk" "2.109.0-beta.0"
184+
"@drift-labs/sdk" "2.109.0-beta.3"
185185
"@solana/web3.js" "1.91.7"
186186
tweetnacl-util "^0.15.1"
187187

188-
"@drift-labs/[email protected].0":
189-
version "2.109.0-beta.0"
190-
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.109.0-beta.0.tgz#b14ee689116798d96431e06bc175771abdb0cdd8"
191-
integrity sha512-HBZAlqz/C30jcqL+Ml6f08JinwbQOYx6p3/s9ApEdM32ZwF584vBV66KohTMf17rdYBlyrCzBNKnedvG47yljw==
188+
"@drift-labs/[email protected].3":
189+
version "2.109.0-beta.3"
190+
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.109.0-beta.3.tgz#a7e6c8698836ba59b93353509c2057f371d54df2"
191+
integrity sha512-zOO8G5Wgm5RNd1LYdS18GprmXAAUSEKaSBM7gEVadCGzQmsVbTmmT1fKCAfIHYPdjcKfM0wc41qlZQaPPZuPPw==
192192
dependencies:
193193
"@coral-xyz/anchor" "0.29.0"
194194
"@coral-xyz/anchor-30" "npm:@coral-xyz/[email protected]"

0 commit comments

Comments
 (0)