@drift-labs/jit-proxy 0.10.206 → 0.10.208
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 -1
- package/lib/jitter/jitterShotgun.d.ts +2 -11
- package/lib/jitter/jitterShotgun.js +3 -1
- package/lib/jitter/jitterSniper.js +4 -4
- package/package.json +1 -1
- package/src/jitter/baseJitter.ts +2 -6
- package/src/jitter/jitterShotgun.ts +3 -18
- package/src/jitter/jitterSniper.ts +8 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="@pythnetwork/client/node_modules/@solana/web3.js" />
|
|
2
2
|
import { JitProxyClient, PriceType } from '../jitProxyClient';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { AuctionSubscriber, BN, DriftClient, Order, UserAccount, UserStatsMap } from '@drift-labs/sdk';
|
|
4
|
+
import { AuctionSubscriber, BN, DriftClient, Order, PostOnlyParams, UserAccount, UserStatsMap } from '@drift-labs/sdk';
|
|
5
5
|
export type UserFilter = (userAccount: UserAccount, userKey: string, order: Order) => boolean;
|
|
6
6
|
export type JitParams = {
|
|
7
7
|
bid: BN;
|
|
@@ -10,6 +10,7 @@ export type JitParams = {
|
|
|
10
10
|
maxPosition: any;
|
|
11
11
|
priceType: PriceType;
|
|
12
12
|
subAccountId?: number;
|
|
13
|
+
postOnlyParams?: PostOnlyParams;
|
|
13
14
|
};
|
|
14
15
|
export declare abstract class BaseJitter {
|
|
15
16
|
auctionSubscriber: AuctionSubscriber;
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
/// <reference types="@pythnetwork/client/node_modules/@solana/web3.js" />
|
|
2
|
-
import { JitProxyClient
|
|
2
|
+
import { JitProxyClient } from '../jitProxyClient';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { AuctionSubscriber,
|
|
4
|
+
import { AuctionSubscriber, DriftClient, Order, UserAccount, UserStatsMap } from '@drift-labs/sdk';
|
|
5
5
|
import { BaseJitter } from './baseJitter';
|
|
6
|
-
export type UserFilter = (userAccount: UserAccount, userKey: string, order: Order) => boolean;
|
|
7
|
-
export type JitParams = {
|
|
8
|
-
bid: BN;
|
|
9
|
-
ask: BN;
|
|
10
|
-
minPosition: BN;
|
|
11
|
-
maxPosition: any;
|
|
12
|
-
priceType: PriceType;
|
|
13
|
-
subAccountId?: number;
|
|
14
|
-
};
|
|
15
6
|
export declare class JitterShotgun extends BaseJitter {
|
|
16
7
|
constructor({ auctionSubscriber, jitProxyClient, driftClient, userStatsMap, }: {
|
|
17
8
|
driftClient: DriftClient;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JitterShotgun = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
4
5
|
const baseJitter_1 = require("./baseJitter");
|
|
5
6
|
class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
6
7
|
constructor({ auctionSubscriber, jitProxyClient, driftClient, userStatsMap, }) {
|
|
@@ -13,6 +14,7 @@ class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
|
13
14
|
}
|
|
14
15
|
createTryFill(taker, takerKey, takerStatsKey, order, orderSignature) {
|
|
15
16
|
return async () => {
|
|
17
|
+
var _a;
|
|
16
18
|
let i = 0;
|
|
17
19
|
while (i < 10) {
|
|
18
20
|
const params = this.perpParams.get(order.marketIndex);
|
|
@@ -37,7 +39,7 @@ class JitterShotgun extends baseJitter_1.BaseJitter {
|
|
|
37
39
|
minPosition: params.minPosition,
|
|
38
40
|
bid: params.bid,
|
|
39
41
|
ask: params.ask,
|
|
40
|
-
postOnly: null,
|
|
42
|
+
postOnly: (_a = params.postOnlyParams) !== null && _a !== void 0 ? _a : sdk_1.PostOnlyParams.MUST_POST_ONLY,
|
|
41
43
|
priceType: params.priceType,
|
|
42
44
|
referrerInfo,
|
|
43
45
|
subAccountId: params.subAccountId,
|
|
@@ -25,9 +25,8 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
25
25
|
const { slotsTilCross, willCross, bid, ask, auctionStartPrice, auctionEndPrice, stepSize, oraclePrice, } = this.getAuctionAndOrderDetails(order);
|
|
26
26
|
// don't increase risk if we're past max positions
|
|
27
27
|
if ((0, sdk_1.isVariant)(order.marketType, 'perp')) {
|
|
28
|
-
const currPerpPos = this.driftClient
|
|
29
|
-
.getUser()
|
|
30
|
-
.getPerpPosition(order.marketIndex);
|
|
28
|
+
const currPerpPos = this.driftClient.getUser().getPerpPosition(order.marketIndex) ||
|
|
29
|
+
this.driftClient.getUser().getEmptyPosition(order.marketIndex);
|
|
31
30
|
if (currPerpPos.baseAssetAmount.lt(sdk_1.ZERO) &&
|
|
32
31
|
(0, sdk_1.isVariant)(order.direction, 'short')) {
|
|
33
32
|
if (currPerpPos.baseAssetAmount.lte(params.minPosition)) {
|
|
@@ -65,6 +64,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
65
64
|
stepSize,
|
|
66
65
|
oraclePrice,
|
|
67
66
|
}).then(async ({ slot, updatedDetails }) => {
|
|
67
|
+
var _a;
|
|
68
68
|
if (slot === -1) {
|
|
69
69
|
console.log('Auction expired without crossing');
|
|
70
70
|
this.deleteOnGoingAuction(orderSignature);
|
|
@@ -108,7 +108,7 @@ class JitterSniper extends baseJitter_1.BaseJitter {
|
|
|
108
108
|
minPosition: params.minPosition,
|
|
109
109
|
bid: params.bid,
|
|
110
110
|
ask: params.ask,
|
|
111
|
-
postOnly: null,
|
|
111
|
+
postOnly: (_a = params.postOnlyParams) !== null && _a !== void 0 ? _a : sdk_1.PostOnlyParams.MUST_POST_ONLY,
|
|
112
112
|
priceType: params.priceType,
|
|
113
113
|
referrerInfo,
|
|
114
114
|
subAccountId: params.subAccountId,
|
package/package.json
CHANGED
package/src/jitter/baseJitter.ts
CHANGED
|
@@ -5,17 +5,12 @@ import {
|
|
|
5
5
|
AuctionSubscriber,
|
|
6
6
|
BN,
|
|
7
7
|
BulkAccountLoader,
|
|
8
|
-
convertToNumber,
|
|
9
8
|
DriftClient,
|
|
10
|
-
getAuctionPrice,
|
|
11
|
-
getAuctionPriceForOracleOffsetAuction,
|
|
12
9
|
getUserStatsAccountPublicKey,
|
|
13
10
|
hasAuctionPrice,
|
|
14
11
|
isVariant,
|
|
15
|
-
OraclePriceData,
|
|
16
12
|
Order,
|
|
17
|
-
|
|
18
|
-
SlotSubscriber,
|
|
13
|
+
PostOnlyParams,
|
|
19
14
|
UserAccount,
|
|
20
15
|
UserStatsMap,
|
|
21
16
|
} from '@drift-labs/sdk';
|
|
@@ -33,6 +28,7 @@ export type JitParams = {
|
|
|
33
28
|
maxPosition;
|
|
34
29
|
priceType: PriceType;
|
|
35
30
|
subAccountId?: number;
|
|
31
|
+
postOnlyParams?: PostOnlyParams;
|
|
36
32
|
};
|
|
37
33
|
|
|
38
34
|
export abstract class BaseJitter {
|
|
@@ -2,29 +2,14 @@ import { JitProxyClient, PriceType } from '../jitProxyClient';
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import {
|
|
4
4
|
AuctionSubscriber,
|
|
5
|
-
BN,
|
|
6
5
|
DriftClient,
|
|
7
6
|
Order,
|
|
7
|
+
PostOnlyParams,
|
|
8
8
|
UserAccount,
|
|
9
9
|
UserStatsMap,
|
|
10
10
|
} from '@drift-labs/sdk';
|
|
11
11
|
import { BaseJitter } from './baseJitter';
|
|
12
12
|
|
|
13
|
-
export type UserFilter = (
|
|
14
|
-
userAccount: UserAccount,
|
|
15
|
-
userKey: string,
|
|
16
|
-
order: Order
|
|
17
|
-
) => boolean;
|
|
18
|
-
|
|
19
|
-
export type JitParams = {
|
|
20
|
-
bid: BN;
|
|
21
|
-
ask: BN;
|
|
22
|
-
minPosition: BN;
|
|
23
|
-
maxPosition;
|
|
24
|
-
priceType: PriceType;
|
|
25
|
-
subAccountId?: number;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
13
|
export class JitterShotgun extends BaseJitter {
|
|
29
14
|
constructor({
|
|
30
15
|
auctionSubscriber,
|
|
@@ -83,7 +68,7 @@ export class JitterShotgun extends BaseJitter {
|
|
|
83
68
|
minPosition: params.minPosition,
|
|
84
69
|
bid: params.bid,
|
|
85
70
|
ask: params.ask,
|
|
86
|
-
postOnly:
|
|
71
|
+
postOnly: params.postOnlyParams ?? PostOnlyParams.MUST_POST_ONLY,
|
|
87
72
|
priceType: params.priceType,
|
|
88
73
|
referrerInfo,
|
|
89
74
|
subAccountId: params.subAccountId,
|
|
@@ -101,7 +86,7 @@ export class JitterShotgun extends BaseJitter {
|
|
|
101
86
|
console.log('Order does not cross params yet, retrying');
|
|
102
87
|
} else if (e.message.includes('0x1779')) {
|
|
103
88
|
console.log('Order could not fill');
|
|
104
|
-
}
|
|
89
|
+
} else if (e.message.includes('0x1793')) {
|
|
105
90
|
console.log('Oracle invalid, retrying');
|
|
106
91
|
} else {
|
|
107
92
|
await sleep(10000);
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
isVariant,
|
|
12
12
|
OraclePriceData,
|
|
13
13
|
Order,
|
|
14
|
+
PostOnlyParams,
|
|
14
15
|
PRICE_PRECISION,
|
|
15
16
|
SlotSubscriber,
|
|
16
17
|
UserAccount,
|
|
@@ -88,9 +89,9 @@ export class JitterSniper extends BaseJitter {
|
|
|
88
89
|
|
|
89
90
|
// don't increase risk if we're past max positions
|
|
90
91
|
if (isVariant(order.marketType, 'perp')) {
|
|
91
|
-
const currPerpPos =
|
|
92
|
-
.getUser()
|
|
93
|
-
.
|
|
92
|
+
const currPerpPos =
|
|
93
|
+
this.driftClient.getUser().getPerpPosition(order.marketIndex) ||
|
|
94
|
+
this.driftClient.getUser().getEmptyPosition(order.marketIndex);
|
|
94
95
|
if (
|
|
95
96
|
currPerpPos.baseAssetAmount.lt(ZERO) &&
|
|
96
97
|
isVariant(order.direction, 'short')
|
|
@@ -203,7 +204,8 @@ export class JitterSniper extends BaseJitter {
|
|
|
203
204
|
minPosition: params.minPosition,
|
|
204
205
|
bid: params.bid,
|
|
205
206
|
ask: params.ask,
|
|
206
|
-
postOnly:
|
|
207
|
+
postOnly:
|
|
208
|
+
params.postOnlyParams ?? PostOnlyParams.MUST_POST_ONLY,
|
|
207
209
|
priceType: params.priceType,
|
|
208
210
|
referrerInfo,
|
|
209
211
|
subAccountId: params.subAccountId,
|
|
@@ -314,7 +316,8 @@ export class JitterSniper extends BaseJitter {
|
|
|
314
316
|
|
|
315
317
|
// if it doesnt cross during auction, check if limit price crosses
|
|
316
318
|
if (!willCross) {
|
|
317
|
-
const slotAfterAuction =
|
|
319
|
+
const slotAfterAuction =
|
|
320
|
+
order.slot.toNumber() + order.auctionDuration + 1;
|
|
318
321
|
const limitPrice = getLimitPrice(order, oraclePrice, slotAfterAuction);
|
|
319
322
|
if (!limitPrice) {
|
|
320
323
|
willCross = true;
|