@drift-labs/jit-proxy 0.17.79 → 0.17.80
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 +12 -0
- package/lib/jitProxyClient.js +54 -5
- package/package.json +1 -1
- package/src/jitProxyClient.ts +69 -7
package/lib/jitProxyClient.d.ts
CHANGED
|
@@ -30,6 +30,18 @@ export declare class PriceType {
|
|
|
30
30
|
oracle: {};
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Validates the price type and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
35
|
+
*/
|
|
36
|
+
export declare function validatePriceType(priceType: PriceType): typeof PriceType.LIMIT | typeof PriceType.ORACLE;
|
|
37
|
+
/**
|
|
38
|
+
* Validates the PostOnlyParams and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
39
|
+
*/
|
|
40
|
+
export declare function validatePostOnlyParams(postOnly: PostOnlyParams): typeof PostOnlyParams.NONE | typeof PostOnlyParams.MUST_POST_ONLY | typeof PostOnlyParams.TRY_POST_ONLY | typeof PostOnlyParams.SLIDE;
|
|
41
|
+
/**
|
|
42
|
+
* Validates the market type and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateMarketType(marketType: MarketType): typeof MarketType.PERP | typeof MarketType.SPOT;
|
|
33
45
|
export type OrderConstraint = {
|
|
34
46
|
maxPosition: BN;
|
|
35
47
|
minPosition: BN;
|
package/lib/jitProxyClient.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JitProxyClient = exports.PriceType = exports.DEFAULT_CU_LIMIT = void 0;
|
|
4
|
+
exports.validatePriceType = validatePriceType;
|
|
5
|
+
exports.validatePostOnlyParams = validatePostOnlyParams;
|
|
6
|
+
exports.validateMarketType = validateMarketType;
|
|
4
7
|
const sdk_1 = require("@drift-labs/sdk");
|
|
5
8
|
const jit_proxy_1 = require("./types/jit_proxy");
|
|
6
9
|
const web3_js_1 = require("@solana/web3.js");
|
|
@@ -11,6 +14,48 @@ class PriceType {
|
|
|
11
14
|
exports.PriceType = PriceType;
|
|
12
15
|
PriceType.LIMIT = { limit: {} };
|
|
13
16
|
PriceType.ORACLE = { oracle: {} };
|
|
17
|
+
/**
|
|
18
|
+
* Validates the price type and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
19
|
+
*/
|
|
20
|
+
function validatePriceType(priceType) {
|
|
21
|
+
if ((0, sdk_1.isVariant)(priceType, 'limit')) {
|
|
22
|
+
return PriceType.LIMIT;
|
|
23
|
+
}
|
|
24
|
+
if ((0, sdk_1.isVariant)(priceType, 'oracle')) {
|
|
25
|
+
return PriceType.ORACLE;
|
|
26
|
+
}
|
|
27
|
+
throw new Error('Invalid price type');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validates the PostOnlyParams and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
31
|
+
*/
|
|
32
|
+
function validatePostOnlyParams(postOnly) {
|
|
33
|
+
if ((0, sdk_1.isVariant)(postOnly, 'none')) {
|
|
34
|
+
return sdk_1.PostOnlyParams.NONE;
|
|
35
|
+
}
|
|
36
|
+
if ((0, sdk_1.isVariant)(postOnly, 'mustPostOnly')) {
|
|
37
|
+
return sdk_1.PostOnlyParams.MUST_POST_ONLY;
|
|
38
|
+
}
|
|
39
|
+
if ((0, sdk_1.isVariant)(postOnly, 'tryPostOnly')) {
|
|
40
|
+
return sdk_1.PostOnlyParams.TRY_POST_ONLY;
|
|
41
|
+
}
|
|
42
|
+
if ((0, sdk_1.isVariant)(postOnly, 'slide')) {
|
|
43
|
+
return sdk_1.PostOnlyParams.SLIDE;
|
|
44
|
+
}
|
|
45
|
+
throw new Error('Invalid post only params');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Validates the market type and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
49
|
+
*/
|
|
50
|
+
function validateMarketType(marketType) {
|
|
51
|
+
if ((0, sdk_1.isVariant)(marketType, 'perp')) {
|
|
52
|
+
return sdk_1.MarketType.PERP;
|
|
53
|
+
}
|
|
54
|
+
if ((0, sdk_1.isVariant)(marketType, 'spot')) {
|
|
55
|
+
return sdk_1.MarketType.SPOT;
|
|
56
|
+
}
|
|
57
|
+
throw new Error('Invalid market type');
|
|
58
|
+
}
|
|
14
59
|
class JitProxyClient {
|
|
15
60
|
constructor({ driftClient, programId, }) {
|
|
16
61
|
this.driftClient = driftClient;
|
|
@@ -92,8 +137,8 @@ class JitProxyClient {
|
|
|
92
137
|
minPosition,
|
|
93
138
|
bid,
|
|
94
139
|
ask,
|
|
95
|
-
postOnly,
|
|
96
|
-
priceType,
|
|
140
|
+
postOnly: validatePostOnlyParams(postOnly),
|
|
141
|
+
priceType: validatePriceType(priceType),
|
|
97
142
|
};
|
|
98
143
|
return this.program.methods
|
|
99
144
|
.jit(jitParams)
|
|
@@ -136,8 +181,8 @@ class JitProxyClient {
|
|
|
136
181
|
minPosition,
|
|
137
182
|
bid,
|
|
138
183
|
ask,
|
|
139
|
-
postOnly,
|
|
140
|
-
priceType,
|
|
184
|
+
postOnly: validatePostOnlyParams(postOnly),
|
|
185
|
+
priceType: validatePriceType(priceType),
|
|
141
186
|
};
|
|
142
187
|
return this.program.methods
|
|
143
188
|
.jitSignedMsg(jitSignedMsgParams)
|
|
@@ -174,8 +219,12 @@ class JitProxyClient {
|
|
|
174
219
|
readableSpotMarketIndexes,
|
|
175
220
|
readablePerpMarketIndex,
|
|
176
221
|
});
|
|
222
|
+
const validatedOrderConstraints = orderConstraints.map((orderConstraint) => ({
|
|
223
|
+
...orderConstraint,
|
|
224
|
+
marketType: validateMarketType(orderConstraint.marketType),
|
|
225
|
+
}));
|
|
177
226
|
return this.program.methods
|
|
178
|
-
.checkOrderConstraints(
|
|
227
|
+
.checkOrderConstraints(validatedOrderConstraints)
|
|
179
228
|
.accounts({
|
|
180
229
|
user: await this.driftClient.getUserAccountPublicKey(subAccountId),
|
|
181
230
|
})
|
package/package.json
CHANGED
package/src/jitProxyClient.ts
CHANGED
|
@@ -52,6 +52,61 @@ export class PriceType {
|
|
|
52
52
|
static readonly ORACLE = { oracle: {} };
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Validates the price type and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
57
|
+
*/
|
|
58
|
+
export function validatePriceType(
|
|
59
|
+
priceType: PriceType
|
|
60
|
+
): typeof PriceType.LIMIT | typeof PriceType.ORACLE {
|
|
61
|
+
if (isVariant(priceType, 'limit')) {
|
|
62
|
+
return PriceType.LIMIT;
|
|
63
|
+
}
|
|
64
|
+
if (isVariant(priceType, 'oracle')) {
|
|
65
|
+
return PriceType.ORACLE;
|
|
66
|
+
}
|
|
67
|
+
throw new Error('Invalid price type');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Validates the PostOnlyParams and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
72
|
+
*/
|
|
73
|
+
export function validatePostOnlyParams(
|
|
74
|
+
postOnly: PostOnlyParams
|
|
75
|
+
):
|
|
76
|
+
| typeof PostOnlyParams.NONE
|
|
77
|
+
| typeof PostOnlyParams.MUST_POST_ONLY
|
|
78
|
+
| typeof PostOnlyParams.TRY_POST_ONLY
|
|
79
|
+
| typeof PostOnlyParams.SLIDE {
|
|
80
|
+
if (isVariant(postOnly, 'none')) {
|
|
81
|
+
return PostOnlyParams.NONE;
|
|
82
|
+
}
|
|
83
|
+
if (isVariant(postOnly, 'mustPostOnly')) {
|
|
84
|
+
return PostOnlyParams.MUST_POST_ONLY;
|
|
85
|
+
}
|
|
86
|
+
if (isVariant(postOnly, 'tryPostOnly')) {
|
|
87
|
+
return PostOnlyParams.TRY_POST_ONLY;
|
|
88
|
+
}
|
|
89
|
+
if (isVariant(postOnly, 'slide')) {
|
|
90
|
+
return PostOnlyParams.SLIDE;
|
|
91
|
+
}
|
|
92
|
+
throw new Error('Invalid post only params');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Validates the market type and returns the corresponding enum value. (required for type checking because of how anchor handles recursive types in IDL)
|
|
97
|
+
*/
|
|
98
|
+
export function validateMarketType(
|
|
99
|
+
marketType: MarketType
|
|
100
|
+
): typeof MarketType.PERP | typeof MarketType.SPOT {
|
|
101
|
+
if (isVariant(marketType, 'perp')) {
|
|
102
|
+
return MarketType.PERP;
|
|
103
|
+
}
|
|
104
|
+
if (isVariant(marketType, 'spot')) {
|
|
105
|
+
return MarketType.SPOT;
|
|
106
|
+
}
|
|
107
|
+
throw new Error('Invalid market type');
|
|
108
|
+
}
|
|
109
|
+
|
|
55
110
|
export type OrderConstraint = {
|
|
56
111
|
maxPosition: BN;
|
|
57
112
|
minPosition: BN;
|
|
@@ -189,12 +244,12 @@ export class JitProxyClient {
|
|
|
189
244
|
minPosition,
|
|
190
245
|
bid,
|
|
191
246
|
ask,
|
|
192
|
-
postOnly,
|
|
193
|
-
priceType,
|
|
247
|
+
postOnly: validatePostOnlyParams(postOnly),
|
|
248
|
+
priceType: validatePriceType(priceType),
|
|
194
249
|
};
|
|
195
250
|
|
|
196
251
|
return this.program.methods
|
|
197
|
-
.jit(jitParams
|
|
252
|
+
.jit(jitParams)
|
|
198
253
|
.accounts({
|
|
199
254
|
taker: takerKey,
|
|
200
255
|
takerStats: takerStatsKey,
|
|
@@ -251,12 +306,12 @@ export class JitProxyClient {
|
|
|
251
306
|
minPosition,
|
|
252
307
|
bid,
|
|
253
308
|
ask,
|
|
254
|
-
postOnly,
|
|
255
|
-
priceType,
|
|
309
|
+
postOnly: validatePostOnlyParams(postOnly),
|
|
310
|
+
priceType: validatePriceType(priceType),
|
|
256
311
|
};
|
|
257
312
|
|
|
258
313
|
return this.program.methods
|
|
259
|
-
.jitSignedMsg(jitSignedMsgParams
|
|
314
|
+
.jitSignedMsg(jitSignedMsgParams)
|
|
260
315
|
.accounts({
|
|
261
316
|
taker: takerKey,
|
|
262
317
|
takerStats: takerStatsKey,
|
|
@@ -302,8 +357,15 @@ export class JitProxyClient {
|
|
|
302
357
|
readablePerpMarketIndex,
|
|
303
358
|
});
|
|
304
359
|
|
|
360
|
+
const validatedOrderConstraints = orderConstraints.map(
|
|
361
|
+
(orderConstraint) => ({
|
|
362
|
+
...orderConstraint,
|
|
363
|
+
marketType: validateMarketType(orderConstraint.marketType),
|
|
364
|
+
})
|
|
365
|
+
);
|
|
366
|
+
|
|
305
367
|
return this.program.methods
|
|
306
|
-
.checkOrderConstraints(
|
|
368
|
+
.checkOrderConstraints(validatedOrderConstraints)
|
|
307
369
|
.accounts({
|
|
308
370
|
user: await this.driftClient.getUserAccountPublicKey(subAccountId),
|
|
309
371
|
})
|