@drift-labs/jit-proxy 0.13.11 → 0.13.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/jitProxyClient.d.ts +5 -1
- package/lib/jitProxyClient.js +22 -5
- package/package.json +1 -1
- package/src/jitProxyClient.ts +36 -10
package/lib/jitProxyClient.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { BN, DriftClient, MakerInfo, MarketType, PostOnlyParams, ReferrerInfo, T
|
|
|
3
3
|
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
4
4
|
import { TxSigAndSlot } from '@drift-labs/sdk';
|
|
5
5
|
import { SignedSwiftOrderParams } from '@drift-labs/sdk/lib/node/swift/types';
|
|
6
|
+
export declare const DEFAULT_CU_LIMIT = 1400000;
|
|
6
7
|
export type JitIxParams = {
|
|
7
8
|
takerKey: PublicKey;
|
|
8
9
|
takerStatsKey: PublicKey;
|
|
@@ -45,7 +46,10 @@ export declare class JitProxyClient {
|
|
|
45
46
|
programId: PublicKey;
|
|
46
47
|
});
|
|
47
48
|
jit(params: JitIxParams, txParams?: TxParams): Promise<TxSigAndSlot>;
|
|
48
|
-
jitSwift(params: JitSwiftIxParams,
|
|
49
|
+
jitSwift(params: JitSwiftIxParams, computeBudgetParams?: {
|
|
50
|
+
computeUnits: number;
|
|
51
|
+
computeUnitsPrice: number;
|
|
52
|
+
}): Promise<TxSigAndSlot>;
|
|
49
53
|
getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly, priceType, referrerInfo, subAccountId, }: JitIxParams): Promise<TransactionInstruction>;
|
|
50
54
|
getJitSwiftIx({ takerKey, takerStatsKey, taker, maxPosition, minPosition, bid, ask, postOnly, priceType, referrerInfo, subAccountId, uuid, marketIndex, }: JitSwiftIxParams): Promise<TransactionInstruction>;
|
|
51
55
|
getCheckOrderConstraintIx({ subAccountId, orderConstraints, }: {
|
package/lib/jitProxyClient.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JitProxyClient = exports.PriceType = void 0;
|
|
3
|
+
exports.JitProxyClient = exports.PriceType = exports.DEFAULT_CU_LIMIT = void 0;
|
|
4
4
|
const sdk_1 = require("@drift-labs/sdk");
|
|
5
5
|
const jit_proxy_1 = require("./types/jit_proxy");
|
|
6
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
7
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
|
+
exports.DEFAULT_CU_LIMIT = 1400000;
|
|
7
9
|
class PriceType {
|
|
8
10
|
}
|
|
9
11
|
exports.PriceType = PriceType;
|
|
@@ -19,16 +21,31 @@ class JitProxyClient {
|
|
|
19
21
|
const tx = await this.driftClient.buildTransaction([ix], txParams);
|
|
20
22
|
return await this.driftClient.sendTransaction(tx);
|
|
21
23
|
}
|
|
22
|
-
async jitSwift(params,
|
|
24
|
+
async jitSwift(params, computeBudgetParams) {
|
|
25
|
+
const ixs = [
|
|
26
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
27
|
+
units: (computeBudgetParams === null || computeBudgetParams === void 0 ? void 0 : computeBudgetParams.computeUnits) || exports.DEFAULT_CU_LIMIT,
|
|
28
|
+
}),
|
|
29
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
30
|
+
microLamports: (computeBudgetParams === null || computeBudgetParams === void 0 ? void 0 : computeBudgetParams.computeUnitsPrice) || 0,
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
23
33
|
const swiftTakerIxs = await this.driftClient.getPlaceSwiftTakerPerpOrderIxs(params.signedSwiftOrderParams, params.marketIndex, {
|
|
24
34
|
taker: params.takerKey,
|
|
25
35
|
takerStats: params.takerStatsKey,
|
|
26
36
|
takerUserAccount: params.taker,
|
|
27
37
|
signingAuthority: params.authorityToUse,
|
|
28
|
-
},
|
|
38
|
+
}, ixs);
|
|
39
|
+
ixs.push(...swiftTakerIxs);
|
|
29
40
|
const ix = await this.getJitSwiftIx(params);
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
ixs.push(ix);
|
|
42
|
+
const v0Message = new web3_js_1.TransactionMessage({
|
|
43
|
+
instructions: ixs,
|
|
44
|
+
payerKey: this.driftClient.wallet.publicKey,
|
|
45
|
+
recentBlockhash: (await this.driftClient.txHandler.getLatestBlockhashForTransaction()).blockhash,
|
|
46
|
+
}).compileToV0Message(await this.driftClient.fetchAllLookupTableAccounts());
|
|
47
|
+
const tx = new web3_js_1.VersionedTransaction(v0Message);
|
|
48
|
+
return await this.driftClient.txSender.sendVersionedTransaction(tx);
|
|
32
49
|
}
|
|
33
50
|
async getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly = null, priceType = PriceType.LIMIT, referrerInfo, subAccountId, }) {
|
|
34
51
|
subAccountId =
|
package/package.json
CHANGED
package/src/jitProxyClient.ts
CHANGED
|
@@ -12,11 +12,19 @@ import {
|
|
|
12
12
|
UserAccount,
|
|
13
13
|
} from '@drift-labs/sdk';
|
|
14
14
|
import { IDL, JitProxy } from './types/jit_proxy';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
ComputeBudgetProgram,
|
|
17
|
+
PublicKey,
|
|
18
|
+
TransactionInstruction,
|
|
19
|
+
TransactionMessage,
|
|
20
|
+
VersionedTransaction,
|
|
21
|
+
} from '@solana/web3.js';
|
|
16
22
|
import { Program } from '@coral-xyz/anchor';
|
|
17
23
|
import { TxSigAndSlot } from '@drift-labs/sdk';
|
|
18
24
|
import { SignedSwiftOrderParams } from '@drift-labs/sdk/lib/node/swift/types';
|
|
19
25
|
|
|
26
|
+
export const DEFAULT_CU_LIMIT = 1_400_000;
|
|
27
|
+
|
|
20
28
|
export type JitIxParams = {
|
|
21
29
|
takerKey: PublicKey;
|
|
22
30
|
takerStatsKey: PublicKey;
|
|
@@ -77,8 +85,20 @@ export class JitProxyClient {
|
|
|
77
85
|
|
|
78
86
|
public async jitSwift(
|
|
79
87
|
params: JitSwiftIxParams,
|
|
80
|
-
|
|
88
|
+
computeBudgetParams?: {
|
|
89
|
+
computeUnits: number;
|
|
90
|
+
computeUnitsPrice: number;
|
|
91
|
+
}
|
|
81
92
|
): Promise<TxSigAndSlot> {
|
|
93
|
+
const ixs = [
|
|
94
|
+
ComputeBudgetProgram.setComputeUnitLimit({
|
|
95
|
+
units: computeBudgetParams?.computeUnits || DEFAULT_CU_LIMIT,
|
|
96
|
+
}),
|
|
97
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
98
|
+
microLamports: computeBudgetParams?.computeUnitsPrice || 0,
|
|
99
|
+
}),
|
|
100
|
+
];
|
|
101
|
+
|
|
82
102
|
const swiftTakerIxs = await this.driftClient.getPlaceSwiftTakerPerpOrderIxs(
|
|
83
103
|
params.signedSwiftOrderParams,
|
|
84
104
|
params.marketIndex,
|
|
@@ -88,17 +108,23 @@ export class JitProxyClient {
|
|
|
88
108
|
takerUserAccount: params.taker,
|
|
89
109
|
signingAuthority: params.authorityToUse,
|
|
90
110
|
},
|
|
91
|
-
|
|
92
|
-
3
|
|
111
|
+
ixs
|
|
93
112
|
);
|
|
113
|
+
ixs.push(...swiftTakerIxs);
|
|
94
114
|
|
|
95
115
|
const ix = await this.getJitSwiftIx(params);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
ixs.push(ix);
|
|
117
|
+
|
|
118
|
+
const v0Message = new TransactionMessage({
|
|
119
|
+
instructions: ixs,
|
|
120
|
+
payerKey: this.driftClient.wallet.publicKey,
|
|
121
|
+
recentBlockhash: (
|
|
122
|
+
await this.driftClient.txHandler.getLatestBlockhashForTransaction()
|
|
123
|
+
).blockhash,
|
|
124
|
+
}).compileToV0Message(await this.driftClient.fetchAllLookupTableAccounts());
|
|
125
|
+
const tx = new VersionedTransaction(v0Message);
|
|
126
|
+
|
|
127
|
+
return await this.driftClient.txSender.sendVersionedTransaction(tx);
|
|
102
128
|
}
|
|
103
129
|
|
|
104
130
|
public async getJitIx({
|