@drift-labs/jit-proxy 0.2.0 → 0.4.0
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 +3 -2
- package/lib/jitProxyClient.js +13 -1
- package/lib/jitter.d.ts +4 -2
- package/lib/jitter.js +10 -1
- package/package.json +1 -1
- package/src/jitProxyClient.ts +16 -0
- package/src/jitter.ts +16 -2
package/lib/jitProxyClient.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import { BN, DriftClient, PostOnlyParams, TxParams, UserAccount } from '@drift-labs/sdk';
|
|
2
|
+
import { BN, DriftClient, PostOnlyParams, ReferrerInfo, TxParams, UserAccount } from '@drift-labs/sdk';
|
|
3
3
|
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
4
4
|
import { TxSigAndSlot } from '@drift-labs/sdk/lib/tx/types';
|
|
5
5
|
export declare type JitIxParams = {
|
|
@@ -13,6 +13,7 @@ export declare type JitIxParams = {
|
|
|
13
13
|
ask: BN;
|
|
14
14
|
postOnly: PostOnlyParams | null;
|
|
15
15
|
priceType?: PriceType;
|
|
16
|
+
referrerInfo?: ReferrerInfo;
|
|
16
17
|
};
|
|
17
18
|
export declare class PriceType {
|
|
18
19
|
static readonly LIMIT: {
|
|
@@ -30,5 +31,5 @@ export declare class JitProxyClient {
|
|
|
30
31
|
programId: PublicKey;
|
|
31
32
|
});
|
|
32
33
|
jit(params: JitIxParams, txParams?: TxParams): Promise<TxSigAndSlot>;
|
|
33
|
-
getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly, priceType, }: JitIxParams): Promise<TransactionInstruction>;
|
|
34
|
+
getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly, priceType, referrerInfo, }: JitIxParams): Promise<TransactionInstruction>;
|
|
34
35
|
}
|
package/lib/jitProxyClient.js
CHANGED
|
@@ -19,7 +19,7 @@ class JitProxyClient {
|
|
|
19
19
|
const tx = await this.driftClient.buildTransaction([ix], txParams);
|
|
20
20
|
return await this.driftClient.sendTransaction(tx);
|
|
21
21
|
}
|
|
22
|
-
async getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly = null, priceType = PriceType.LIMIT, }) {
|
|
22
|
+
async getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly = null, priceType = PriceType.LIMIT, referrerInfo, }) {
|
|
23
23
|
const order = taker.orders.find((order) => order.orderId === takerOrderId);
|
|
24
24
|
const remainingAccounts = this.driftClient.getRemainingAccounts({
|
|
25
25
|
userAccounts: [taker, this.driftClient.getUserAccount()],
|
|
@@ -30,6 +30,18 @@ class JitProxyClient {
|
|
|
30
30
|
? [order.marketIndex]
|
|
31
31
|
: [],
|
|
32
32
|
});
|
|
33
|
+
if (referrerInfo) {
|
|
34
|
+
remainingAccounts.push({
|
|
35
|
+
pubkey: referrerInfo.referrer,
|
|
36
|
+
isWritable: true,
|
|
37
|
+
isSigner: false,
|
|
38
|
+
});
|
|
39
|
+
remainingAccounts.push({
|
|
40
|
+
pubkey: referrerInfo.referrerStats,
|
|
41
|
+
isWritable: true,
|
|
42
|
+
isSigner: false,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
33
45
|
if (sdk_1.isVariant(order.marketType, 'spot')) {
|
|
34
46
|
remainingAccounts.push({
|
|
35
47
|
pubkey: this.driftClient.getSpotMarketAccount(order.marketIndex).vault,
|
package/lib/jitter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { JitProxyClient, PriceType } from './jitProxyClient';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { AuctionSubscriber, BN, DriftClient, Order, UserAccount } from '@drift-labs/sdk';
|
|
4
|
+
import { AuctionSubscriber, BN, DriftClient, Order, UserAccount, UserStatsMap } from '@drift-labs/sdk';
|
|
5
5
|
export declare type UserFilter = (userAccount: UserAccount, userKey: string, order: Order) => boolean;
|
|
6
6
|
export declare type JitParams = {
|
|
7
7
|
bid: BN;
|
|
@@ -14,14 +14,16 @@ export declare class Jitter {
|
|
|
14
14
|
auctionSubscriber: AuctionSubscriber;
|
|
15
15
|
driftClient: DriftClient;
|
|
16
16
|
jitProxyClient: JitProxyClient;
|
|
17
|
+
userStatsMap: UserStatsMap;
|
|
17
18
|
perpParams: Map<number, JitParams>;
|
|
18
19
|
spotParams: Map<number, JitParams>;
|
|
19
20
|
onGoingAuctions: Map<string, Promise<void>>;
|
|
20
21
|
userFilter: UserFilter;
|
|
21
|
-
constructor({ auctionSubscriber, jitProxyClient, driftClient, }: {
|
|
22
|
+
constructor({ auctionSubscriber, jitProxyClient, driftClient, userStatsMap, }: {
|
|
22
23
|
driftClient: DriftClient;
|
|
23
24
|
auctionSubscriber: AuctionSubscriber;
|
|
24
25
|
jitProxyClient: JitProxyClient;
|
|
26
|
+
userStatsMap?: UserStatsMap;
|
|
25
27
|
});
|
|
26
28
|
subscribe(): Promise<void>;
|
|
27
29
|
createTryFill(taker: UserAccount, takerKey: PublicKey, takerStatsKey: PublicKey, order: Order, orderSignature: string): () => Promise<void>;
|
package/lib/jitter.js
CHANGED
|
@@ -3,15 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Jitter = void 0;
|
|
4
4
|
const sdk_1 = require("@drift-labs/sdk");
|
|
5
5
|
class Jitter {
|
|
6
|
-
constructor({ auctionSubscriber, jitProxyClient, driftClient, }) {
|
|
6
|
+
constructor({ auctionSubscriber, jitProxyClient, driftClient, userStatsMap, }) {
|
|
7
7
|
this.perpParams = new Map();
|
|
8
8
|
this.spotParams = new Map();
|
|
9
9
|
this.onGoingAuctions = new Map();
|
|
10
10
|
this.auctionSubscriber = auctionSubscriber;
|
|
11
11
|
this.driftClient = driftClient;
|
|
12
12
|
this.jitProxyClient = jitProxyClient;
|
|
13
|
+
this.userStatsMap = userStatsMap || new sdk_1.UserStatsMap(this.driftClient, {
|
|
14
|
+
type: 'polling',
|
|
15
|
+
accountLoader: new sdk_1.BulkAccountLoader(this.driftClient.connection, 'confirmed', 0),
|
|
16
|
+
});
|
|
13
17
|
}
|
|
14
18
|
async subscribe() {
|
|
19
|
+
await this.driftClient.subscribe();
|
|
20
|
+
await this.userStatsMap.subscribe();
|
|
15
21
|
await this.auctionSubscriber.subscribe();
|
|
16
22
|
this.auctionSubscriber.eventEmitter.on('onAccountUpdate', async (taker, takerKey, slot) => {
|
|
17
23
|
const takerKeyString = takerKey.toBase58();
|
|
@@ -58,6 +64,8 @@ class Jitter {
|
|
|
58
64
|
this.onGoingAuctions.delete(orderSignature);
|
|
59
65
|
return;
|
|
60
66
|
}
|
|
67
|
+
const takerStats = await this.userStatsMap.mustGet(taker.authority.toString());
|
|
68
|
+
const referrerInfo = takerStats.getReferrerInfo();
|
|
61
69
|
console.log(`Trying to fill ${orderSignature}`);
|
|
62
70
|
try {
|
|
63
71
|
const { txSig } = await this.jitProxyClient.jit({
|
|
@@ -71,6 +79,7 @@ class Jitter {
|
|
|
71
79
|
ask: params.ask,
|
|
72
80
|
postOnly: null,
|
|
73
81
|
priceType: params.priceType,
|
|
82
|
+
referrerInfo,
|
|
74
83
|
});
|
|
75
84
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|
|
76
85
|
await sleep(10000);
|
package/package.json
CHANGED
package/src/jitProxyClient.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
isVariant,
|
|
5
5
|
PostOnlyParams,
|
|
6
6
|
QUOTE_SPOT_MARKET_INDEX,
|
|
7
|
+
ReferrerInfo,
|
|
7
8
|
TxParams,
|
|
8
9
|
UserAccount,
|
|
9
10
|
} from '@drift-labs/sdk';
|
|
@@ -23,6 +24,7 @@ export type JitIxParams = {
|
|
|
23
24
|
ask: BN;
|
|
24
25
|
postOnly: PostOnlyParams | null;
|
|
25
26
|
priceType?: PriceType;
|
|
27
|
+
referrerInfo?: ReferrerInfo;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export class PriceType {
|
|
@@ -65,6 +67,7 @@ export class JitProxyClient {
|
|
|
65
67
|
ask,
|
|
66
68
|
postOnly = null,
|
|
67
69
|
priceType = PriceType.LIMIT,
|
|
70
|
+
referrerInfo,
|
|
68
71
|
}: JitIxParams): Promise<TransactionInstruction> {
|
|
69
72
|
const order = taker.orders.find((order) => order.orderId === takerOrderId);
|
|
70
73
|
const remainingAccounts = this.driftClient.getRemainingAccounts({
|
|
@@ -77,6 +80,19 @@ export class JitProxyClient {
|
|
|
77
80
|
: [],
|
|
78
81
|
});
|
|
79
82
|
|
|
83
|
+
if (referrerInfo) {
|
|
84
|
+
remainingAccounts.push({
|
|
85
|
+
pubkey: referrerInfo.referrer,
|
|
86
|
+
isWritable: true,
|
|
87
|
+
isSigner: false,
|
|
88
|
+
});
|
|
89
|
+
remainingAccounts.push({
|
|
90
|
+
pubkey: referrerInfo.referrerStats,
|
|
91
|
+
isWritable: true,
|
|
92
|
+
isSigner: false,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
if (isVariant(order.marketType, 'spot')) {
|
|
81
97
|
remainingAccounts.push({
|
|
82
98
|
pubkey: this.driftClient.getSpotMarketAccount(order.marketIndex).vault,
|
package/src/jitter.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { JitProxyClient, PriceType } from './jitProxyClient';
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import {
|
|
4
4
|
AuctionSubscriber,
|
|
5
|
-
BN,
|
|
5
|
+
BN, BulkAccountLoader,
|
|
6
6
|
DriftClient,
|
|
7
7
|
getUserStatsAccountPublicKey,
|
|
8
8
|
hasAuctionPrice,
|
|
9
9
|
isVariant,
|
|
10
10
|
Order,
|
|
11
|
-
UserAccount,
|
|
11
|
+
UserAccount, UserMap, UserStatsMap,
|
|
12
12
|
} from '@drift-labs/sdk';
|
|
13
13
|
|
|
14
14
|
export type UserFilter = (
|
|
@@ -28,6 +28,7 @@ export class Jitter {
|
|
|
28
28
|
auctionSubscriber: AuctionSubscriber;
|
|
29
29
|
driftClient: DriftClient;
|
|
30
30
|
jitProxyClient: JitProxyClient;
|
|
31
|
+
userStatsMap: UserStatsMap;
|
|
31
32
|
|
|
32
33
|
perpParams = new Map<number, JitParams>();
|
|
33
34
|
spotParams = new Map<number, JitParams>();
|
|
@@ -40,17 +41,26 @@ export class Jitter {
|
|
|
40
41
|
auctionSubscriber,
|
|
41
42
|
jitProxyClient,
|
|
42
43
|
driftClient,
|
|
44
|
+
userStatsMap,
|
|
43
45
|
}: {
|
|
44
46
|
driftClient: DriftClient;
|
|
45
47
|
auctionSubscriber: AuctionSubscriber;
|
|
46
48
|
jitProxyClient: JitProxyClient;
|
|
49
|
+
userStatsMap?: UserStatsMap;
|
|
47
50
|
}) {
|
|
48
51
|
this.auctionSubscriber = auctionSubscriber;
|
|
49
52
|
this.driftClient = driftClient;
|
|
50
53
|
this.jitProxyClient = jitProxyClient;
|
|
54
|
+
this.userStatsMap = userStatsMap || new UserStatsMap(this.driftClient, {
|
|
55
|
+
type: 'polling',
|
|
56
|
+
accountLoader: new BulkAccountLoader(this.driftClient.connection, 'confirmed', 0),
|
|
57
|
+
});
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
async subscribe(): Promise<void> {
|
|
61
|
+
await this.driftClient.subscribe();
|
|
62
|
+
await this.userStatsMap.subscribe();
|
|
63
|
+
|
|
54
64
|
await this.auctionSubscriber.subscribe();
|
|
55
65
|
this.auctionSubscriber.eventEmitter.on(
|
|
56
66
|
'onAccountUpdate',
|
|
@@ -132,6 +142,9 @@ export class Jitter {
|
|
|
132
142
|
return;
|
|
133
143
|
}
|
|
134
144
|
|
|
145
|
+
const takerStats = await this.userStatsMap.mustGet(taker.authority.toString());
|
|
146
|
+
const referrerInfo = takerStats.getReferrerInfo();
|
|
147
|
+
|
|
135
148
|
console.log(`Trying to fill ${orderSignature}`);
|
|
136
149
|
try {
|
|
137
150
|
const { txSig } = await this.jitProxyClient.jit({
|
|
@@ -145,6 +158,7 @@ export class Jitter {
|
|
|
145
158
|
ask: params.ask,
|
|
146
159
|
postOnly: null,
|
|
147
160
|
priceType: params.priceType,
|
|
161
|
+
referrerInfo,
|
|
148
162
|
});
|
|
149
163
|
|
|
150
164
|
console.log(`Filled ${orderSignature} txSig ${txSig}`);
|