Skip to content

Commit 071b6c9

Browse files
committed
swift placer: always submit order tx with deposit
1 parent dc82a03 commit 071b6c9

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

drift-common

Submodule drift-common updated 196 files

src/experimental-bots/swift/placerExample.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,23 @@ export class SwiftPlacer {
369369
);
370370
}
371371

372+
const hasPreDeposit = preDepositTx.length > 0;
373+
if (hasPreDeposit) {
374+
logger.info(`order with deposit: ${preDepositTx}`);
375+
const preDepositTxRaw = Buffer.from(preDepositTx, 'base64');
376+
this.driftClient.txSender
377+
.sendRawTransaction(preDepositTxRaw, {
378+
skipPreflight: true,
379+
maxRetries: 0,
380+
})
381+
.then((res) => {
382+
logger.info(`sent deposit tx: ${res.txSig}@${res.slot}`);
383+
})
384+
.catch((err) => {
385+
logger.warn(`failed deposit tx: ${err}`);
386+
});
387+
}
388+
372389
let resp: SimulateAndGetTxWithCUsResponse | undefined;
373390
try {
374391
resp = await simulateAndGetTxWithCUs({
@@ -385,7 +402,9 @@ export class SwiftPlacer {
385402
return;
386403
}
387404

388-
if (resp.simError) {
405+
// allow orders with pre-deposit to be submitted avoid race conditions
406+
// with the sim
407+
if (!hasPreDeposit && resp.simError) {
389408
logger.info(
390409
`${logPrefix}: ${JSON.stringify(resp.simError)}, ${
391410
resp.simTxLogs
@@ -399,22 +418,6 @@ export class SwiftPlacer {
399418
);
400419
logger.info(`${logPrefix}: placing order: ${orderStr}`);
401420

402-
if (preDepositTx.length > 0) {
403-
logger.info(`order with deposit: ${preDepositTx}`);
404-
const preDepositTxRaw = Buffer.from(preDepositTx, 'base64');
405-
this.driftClient.txSender
406-
.sendRawTransaction(preDepositTxRaw, {
407-
skipPreflight: true,
408-
maxRetries: 0,
409-
})
410-
.then((res) => {
411-
logger.info(`sent deposit tx: ${res.txSig}@${res.slot}`);
412-
})
413-
.catch((err) => {
414-
logger.warn(`failed deposit tx: ${err}`);
415-
});
416-
}
417-
418421
this.driftClient.txSender
419422
.sendVersionedTransaction(resp.tx)
420423
.then((r) => {

0 commit comments

Comments
 (0)