Skip to content

Commit a30d026

Browse files
authored
Merge pull request #429 from drift-labs/master
fix place sim guard
2 parents 51bd2dc + 5595334 commit a30d026

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

src/experimental-bots/swift/placerExample.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ import { RuntimeSpec } from 'src/metrics';
2626
import WebSocket from 'ws';
2727
import nacl from 'tweetnacl';
2828
import { decodeUTF8 } from 'tweetnacl-util';
29-
import { getWallet, simulateAndGetTxWithCUs, sleepMs } from '../../utils';
29+
import {
30+
getWallet,
31+
simulateAndGetTxWithCUs,
32+
SimulateAndGetTxWithCUsResponse,
33+
sleepMs,
34+
} from '../../utils';
3035
import {
3136
ComputeBudgetProgram,
3237
Keypair,
@@ -283,15 +288,22 @@ export class SwiftPlacer {
283288
true
284289
);
285290

286-
const resp = await simulateAndGetTxWithCUs({
287-
connection: this.driftClient.connection,
288-
payerPublicKey: this.driftClient.wallet.payer!.publicKey,
289-
ixs: [...computeBudgetIxs, ...ixs, fillIx],
290-
cuLimitMultiplier: 1.5,
291-
lookupTableAccounts:
292-
await this.driftClient.fetchAllLookupTableAccounts(),
293-
doSimulation: true,
294-
});
291+
let resp: SimulateAndGetTxWithCUsResponse | undefined;
292+
try {
293+
resp = await simulateAndGetTxWithCUs({
294+
connection: this.driftClient.connection,
295+
payerPublicKey: this.driftClient.wallet.payer!.publicKey,
296+
ixs: [...computeBudgetIxs, ...ixs, fillIx],
297+
cuLimitMultiplier: 1.5,
298+
lookupTableAccounts:
299+
await this.driftClient.fetchAllLookupTableAccounts(),
300+
doSimulation: true,
301+
});
302+
} catch (e) {
303+
console.error(e);
304+
return;
305+
}
306+
295307
if (resp.simError) {
296308
console.log(resp.simTxLogs);
297309
return;

src/experimental-bots/swift/takerExample.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
digestSignature,
88
generateSignedMsgUuid,
99
BN,
10+
OrderParams,
1011
} from '@drift-labs/sdk';
1112
import { RuntimeSpec } from 'src/metrics';
1213
import * as axios from 'axios';
@@ -53,28 +54,27 @@ export class SwiftTaker {
5354
const highPrice = oracleInfo.price.muln(101).divn(100);
5455
const lowPrice = oracleInfo.price;
5556

57+
const marketOrderParams = getMarketOrderParams({
58+
marketIndex,
59+
marketType: MarketType.PERP,
60+
direction,
61+
baseAssetAmount: this.driftClient
62+
.getPerpMarketAccount(marketIndex)!
63+
.amm.minOrderSize.muln(2),
64+
auctionStartPrice: isVariant(direction, 'long') ? lowPrice : highPrice,
65+
auctionEndPrice: isVariant(direction, 'long') ? highPrice : lowPrice,
66+
auctionDuration: 50,
67+
});
68+
5669
const orderMessage = {
57-
signedMsgOrderParams: getMarketOrderParams({
58-
marketIndex,
59-
marketType: MarketType.PERP,
60-
direction,
61-
baseAssetAmount: this.driftClient
62-
.getPerpMarketAccount(marketIndex)!
63-
.amm.minOrderSize.muln(2),
64-
auctionStartPrice: isVariant(direction, 'long')
65-
? lowPrice
66-
: highPrice,
67-
auctionEndPrice: isVariant(direction, 'long') ? highPrice : lowPrice,
68-
auctionDuration: 50,
69-
}),
70+
signedMsgOrderParams: marketOrderParams as OrderParams,
7071
subAccountId: this.driftClient.activeSubAccountId,
7172
slot: new BN(slot),
7273
uuid: generateSignedMsgUuid(),
7374
stopLossOrderParams: null,
7475
takeProfitOrderParams: null,
7576
};
7677
const { orderParams: message, signature } =
77-
//@ts-ignore
7878
this.driftClient.signSignedMsgOrderParamsMessage(orderMessage);
7979

8080
const hash = digestSignature(Uint8Array.from(signature));

0 commit comments

Comments
 (0)