@drift-labs/jit-proxy 0.10.201 → 0.10.203
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/jitter/baseJitter.d.ts +2 -0
- package/lib/jitter/baseJitter.js +9 -0
- package/lib/jitter/jitterShotgun.js +8 -4
- package/lib/jitter/jitterSniper.js +12 -9
- package/package.json +1 -1
- package/src/jitter/baseJitter.ts +11 -0
- package/src/jitter/jitterShotgun.ts +8 -5
- package/src/jitter/jitterSniper.ts +11 -9
|
@@ -18,6 +18,7 @@ export declare abstract class BaseJitter {
|
|
|
18
18
|
userStatsMap: UserStatsMap;
|
|
19
19
|
perpParams: Map<number, JitParams>;
|
|
20
20
|
spotParams: Map<number, JitParams>;
|
|
21
|
+
seenOrders: Set<string>;
|
|
21
22
|
onGoingAuctions: Map<string, Promise<void>>;
|
|
22
23
|
userFilter: UserFilter;
|
|
23
24
|
computeUnits: number;
|
|
@@ -30,6 +31,7 @@ export declare abstract class BaseJitter {
|
|
|
30
31
|
});
|
|
31
32
|
subscribe(): Promise<void>;
|
|
32
33
|
createTryFill(taker: UserAccount, takerKey: PublicKey, takerStatsKey: PublicKey, order: Order, orderSignature: string): () => Promise<void>;
|
|
34
|
+
deleteOnGoingAuction(orderSignature: string): void;
|
|
33
35
|
getOrderSignatures(takerKey: string, orderId: number): string;
|
|
34
36
|
updatePerpParams(marketIndex: number, params: JitParams): void;
|
|
35
37
|
updateSpotParams(marketIndex: number, params: JitParams): void;
|
package/lib/jitter/baseJitter.js
CHANGED
|
@@ -6,6 +6,7 @@ class BaseJitter {
|
|
|
6
6
|
constructor({ auctionSubscriber, jitProxyClient, driftClient, userStatsMap, }) {
|
|
7
7
|
this.perpParams = new Map();
|
|
8
8
|
this.spotParams = new Map();
|
|
9
|
+
this.seenOrders = new Set();
|
|
9
10
|
this.onGoingAuctions = new Map();
|
|
10
11
|
this.auctionSubscriber = auctionSubscriber;
|
|
11
12
|
this.driftClient = driftClient;
|
|
@@ -33,6 +34,10 @@ class BaseJitter {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
const orderSignature = this.getOrderSignatures(takerKeyString, order.orderId);
|
|
37
|
+
if (this.seenOrders.has(orderSignature)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
this.seenOrders.add(orderSignature);
|
|
36
41
|
if (this.onGoingAuctions.has(orderSignature)) {
|
|
37
42
|
continue;
|
|
38
43
|
}
|
|
@@ -68,6 +73,10 @@ class BaseJitter {
|
|
|
68
73
|
createTryFill(taker, takerKey, takerStatsKey, order, orderSignature) {
|
|
69
74
|
throw new Error('Not implemented');
|
|
70
75
|
}
|
|
76
|
+
deleteOnGoingAuction(orderSignature) {
|
|
77
|
+
this.onGoingAuctions.delete(orderSignature);
|
|
78
|
+
this.seenOrders.delete(orderSignature);
|
|
79
|
+
}
|
|
71
80
|
getOrderSignatures(takerKey, orderId) {
|
|
72
81
|
return `${takerKey}-${orderId}`;
|
|
73
82
|
}
|
|
@@ -17,7 +17,7 @@ class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
|
17
17
|
while (i < 10) {
|
|
18
18
|
const params = this.perpParams.get(order.marketIndex);
|
|
19
19
|
if (!params) {
|
|
20
|
-
this.
|
|
20
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const takerStats = await this.userStatsMap.mustGet(taker.authority.toString());
|
|
@@ -44,7 +44,7 @@ class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
|
44
44
|
}, txParams);
|
|
45
45
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
46
46
|
await sleep(10000);
|
|
47
|
-
this.
|
|
47
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
|
@@ -52,18 +52,22 @@ class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
|
52
52
|
if (e.message.includes('0x1770') || e.message.includes('0x1771')) {
|
|
53
53
|
console.log('Order does not cross params yet, retrying');
|
|
54
54
|
}
|
|
55
|
+
else if (e.message.includes('0x1779')) {
|
|
56
|
+
console.log('Order could not fill');
|
|
57
|
+
}
|
|
55
58
|
else if (e.message.includes('0x1793')) {
|
|
56
59
|
console.log('Oracle invalid, retrying');
|
|
57
60
|
}
|
|
58
61
|
else {
|
|
59
62
|
await sleep(10000);
|
|
60
|
-
this.
|
|
63
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
61
64
|
return;
|
|
62
65
|
}
|
|
63
66
|
}
|
|
67
|
+
await sleep(200);
|
|
64
68
|
i++;
|
|
65
69
|
}
|
|
66
|
-
this.
|
|
70
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
67
71
|
};
|
|
68
72
|
}
|
|
69
73
|
}
|
|
@@ -17,7 +17,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
17
17
|
return async () => {
|
|
18
18
|
const params = this.perpParams.get(order.marketIndex);
|
|
19
19
|
if (!params) {
|
|
20
|
-
this.
|
|
20
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const takerStats = await this.userStatsMap.mustGet(taker.authority.toString());
|
|
@@ -32,7 +32,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
32
32
|
(0, sdk_1.isVariant)(order.direction, 'short')) {
|
|
33
33
|
if (currPerpPos.baseAssetAmount.lte(params.minPosition)) {
|
|
34
34
|
console.log(`Order would increase existing short (mkt ${(0, sdk_1.getVariant)(order.marketType)}-${order.marketIndex}) too much`);
|
|
35
|
-
this.
|
|
35
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -40,7 +40,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
40
40
|
(0, sdk_1.isVariant)(order.direction, 'long')) {
|
|
41
41
|
if (currPerpPos.baseAssetAmount.gte(params.maxPosition)) {
|
|
42
42
|
console.log(`Order would increase existing long (mkt ${(0, sdk_1.getVariant)(order.marketType)}-${order.marketIndex}) too much`);
|
|
43
|
-
this.
|
|
43
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -67,7 +67,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
67
67
|
}).then(async ({ slot, updatedDetails }) => {
|
|
68
68
|
if (slot === -1) {
|
|
69
69
|
console.log('Auction expired without crossing');
|
|
70
|
-
this.
|
|
70
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
const params = (0, sdk_1.isVariant)(order.marketType, 'perp')
|
|
@@ -93,7 +93,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
93
93
|
submitting" ${(0, sdk_1.convertToNumber)(params.bid, sdk_1.PRICE_PRECISION)}@${(0, sdk_1.convertToNumber)(params.ask, sdk_1.PRICE_PRECISION)}
|
|
94
94
|
`);
|
|
95
95
|
let i = 0;
|
|
96
|
-
while (i <
|
|
96
|
+
while (i < 10) {
|
|
97
97
|
try {
|
|
98
98
|
const txParams = {
|
|
99
99
|
computeUnits: this.computeUnits,
|
|
@@ -115,7 +115,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
115
115
|
}, txParams);
|
|
116
116
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
117
117
|
await sleep(3000);
|
|
118
|
-
this.
|
|
118
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
catch (e) {
|
|
@@ -123,20 +123,23 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
123
123
|
if (e.message.includes('0x1770') || e.message.includes('0x1771')) {
|
|
124
124
|
console.log('Order does not cross params yet');
|
|
125
125
|
}
|
|
126
|
+
else if (e.message.includes('0x1779')) {
|
|
127
|
+
console.log('Order could not fill');
|
|
128
|
+
}
|
|
126
129
|
else if (e.message.includes('0x1793')) {
|
|
127
130
|
console.log('Oracle invalid');
|
|
128
131
|
}
|
|
129
132
|
else {
|
|
130
133
|
await sleep(3000);
|
|
131
|
-
this.
|
|
134
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
132
135
|
return;
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
|
-
await sleep(
|
|
138
|
+
await sleep(200);
|
|
136
139
|
i++;
|
|
137
140
|
}
|
|
138
141
|
});
|
|
139
|
-
this.
|
|
142
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
140
143
|
};
|
|
141
144
|
}
|
|
142
145
|
getAuctionAndOrderDetails(order) {
|
package/package.json
CHANGED
package/src/jitter/baseJitter.ts
CHANGED
|
@@ -44,6 +44,7 @@ export abstract class BaseJitter {
|
|
|
44
44
|
perpParams = new Map<number, JitParams>();
|
|
45
45
|
spotParams = new Map<number, JitParams>();
|
|
46
46
|
|
|
47
|
+
seenOrders = new Set<string>();
|
|
47
48
|
onGoingAuctions = new Map<string, Promise<void>>();
|
|
48
49
|
|
|
49
50
|
userFilter: UserFilter;
|
|
@@ -107,6 +108,11 @@ export abstract class BaseJitter {
|
|
|
107
108
|
order.orderId
|
|
108
109
|
);
|
|
109
110
|
|
|
111
|
+
if (this.seenOrders.has(orderSignature)) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
this.seenOrders.add(orderSignature);
|
|
115
|
+
|
|
110
116
|
if (this.onGoingAuctions.has(orderSignature)) {
|
|
111
117
|
continue;
|
|
112
118
|
}
|
|
@@ -175,6 +181,11 @@ export abstract class BaseJitter {
|
|
|
175
181
|
throw new Error('Not implemented');
|
|
176
182
|
}
|
|
177
183
|
|
|
184
|
+
deleteOnGoingAuction(orderSignature: string): void {
|
|
185
|
+
this.onGoingAuctions.delete(orderSignature);
|
|
186
|
+
this.seenOrders.delete(orderSignature);
|
|
187
|
+
}
|
|
188
|
+
|
|
178
189
|
getOrderSignatures(takerKey: string, orderId: number): string {
|
|
179
190
|
return `${takerKey}-${orderId}`;
|
|
180
191
|
}
|
|
@@ -57,7 +57,7 @@ export class JitterShotgun extends BaseJitter {
|
|
|
57
57
|
while (i < 10) {
|
|
58
58
|
const params = this.perpParams.get(order.marketIndex);
|
|
59
59
|
if (!params) {
|
|
60
|
-
this.
|
|
60
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -90,24 +90,27 @@ export class JitterShotgun extends BaseJitter {
|
|
|
90
90
|
|
|
91
91
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
92
92
|
await sleep(10000);
|
|
93
|
-
this.
|
|
93
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
94
94
|
return;
|
|
95
95
|
} catch (e) {
|
|
96
96
|
console.error(`Failed to fill ${orderSignature}`);
|
|
97
97
|
if (e.message.includes('0x1770') || e.message.includes('0x1771')) {
|
|
98
98
|
console.log('Order does not cross params yet, retrying');
|
|
99
|
-
} else if (e.message.includes('
|
|
99
|
+
} else if (e.message.includes('0x1779')) {
|
|
100
|
+
console.log('Order could not fill');
|
|
101
|
+
} else if (e.message.includes('0x1793')) {
|
|
100
102
|
console.log('Oracle invalid, retrying');
|
|
101
103
|
} else {
|
|
102
104
|
await sleep(10000);
|
|
103
|
-
this.
|
|
105
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
104
106
|
return;
|
|
105
107
|
}
|
|
106
108
|
}
|
|
109
|
+
await sleep(200);
|
|
107
110
|
i++;
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
this.
|
|
113
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
111
114
|
};
|
|
112
115
|
}
|
|
113
116
|
}
|
|
@@ -65,7 +65,7 @@ export class JitterSniper extends BaseJitter {
|
|
|
65
65
|
return async () => {
|
|
66
66
|
const params = this.perpParams.get(order.marketIndex);
|
|
67
67
|
if (!params) {
|
|
68
|
-
this.
|
|
68
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -100,7 +100,7 @@ export class JitterSniper extends BaseJitter {
|
|
|
100
100
|
order.marketType
|
|
101
101
|
)}-${order.marketIndex}) too much`
|
|
102
102
|
);
|
|
103
|
-
this.
|
|
103
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
} else if (
|
|
@@ -113,7 +113,7 @@ export class JitterSniper extends BaseJitter {
|
|
|
113
113
|
order.marketType
|
|
114
114
|
)}-${order.marketIndex}) too much`
|
|
115
115
|
);
|
|
116
|
-
this.
|
|
116
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -152,7 +152,7 @@ export class JitterSniper extends BaseJitter {
|
|
|
152
152
|
).then(async ({ slot, updatedDetails }) => {
|
|
153
153
|
if (slot === -1) {
|
|
154
154
|
console.log('Auction expired without crossing');
|
|
155
|
-
this.
|
|
155
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
158
|
|
|
@@ -186,7 +186,7 @@ export class JitterSniper extends BaseJitter {
|
|
|
186
186
|
)}
|
|
187
187
|
`);
|
|
188
188
|
let i = 0;
|
|
189
|
-
while (i <
|
|
189
|
+
while (i < 10) {
|
|
190
190
|
try {
|
|
191
191
|
const txParams = {
|
|
192
192
|
computeUnits: this.computeUnits,
|
|
@@ -209,25 +209,27 @@ export class JitterSniper extends BaseJitter {
|
|
|
209
209
|
|
|
210
210
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
211
211
|
await sleep(3000);
|
|
212
|
-
this.
|
|
212
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
213
213
|
return;
|
|
214
214
|
} catch (e) {
|
|
215
215
|
console.error(`Failed to fill ${orderSignature}`);
|
|
216
216
|
if (e.message.includes('0x1770') || e.message.includes('0x1771')) {
|
|
217
217
|
console.log('Order does not cross params yet');
|
|
218
|
+
} else if (e.message.includes('0x1779')) {
|
|
219
|
+
console.log('Order could not fill');
|
|
218
220
|
} else if (e.message.includes('0x1793')) {
|
|
219
221
|
console.log('Oracle invalid');
|
|
220
222
|
} else {
|
|
221
223
|
await sleep(3000);
|
|
222
|
-
this.
|
|
224
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
223
225
|
return;
|
|
224
226
|
}
|
|
225
227
|
}
|
|
226
|
-
await sleep(
|
|
228
|
+
await sleep(200);
|
|
227
229
|
i++;
|
|
228
230
|
}
|
|
229
231
|
});
|
|
230
|
-
this.
|
|
232
|
+
this.deleteOnGoingAuction(orderSignature);
|
|
231
233
|
};
|
|
232
234
|
}
|
|
233
235
|
|