@drift-labs/jit-proxy 0.3.0 → 0.5.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.
@@ -14,6 +14,7 @@ export declare type JitIxParams = {
14
14
  postOnly: PostOnlyParams | null;
15
15
  priceType?: PriceType;
16
16
  referrerInfo?: ReferrerInfo;
17
+ subAccountId?: number;
17
18
  };
18
19
  export declare class PriceType {
19
20
  static readonly LIMIT: {
@@ -31,5 +32,5 @@ export declare class JitProxyClient {
31
32
  programId: PublicKey;
32
33
  });
33
34
  jit(params: JitIxParams, txParams?: TxParams): Promise<TxSigAndSlot>;
34
- getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly, priceType, }: JitIxParams): Promise<TransactionInstruction>;
35
+ getJitIx({ takerKey, takerStatsKey, taker, takerOrderId, maxPosition, minPosition, bid, ask, postOnly, priceType, referrerInfo, subAccountId }: JitIxParams): Promise<TransactionInstruction>;
35
36
  }
@@ -19,10 +19,11 @@ 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, subAccountId }) {
23
+ subAccountId = subAccountId || this.driftClient.activeSubAccountId;
23
24
  const order = taker.orders.find((order) => order.orderId === takerOrderId);
24
25
  const remainingAccounts = this.driftClient.getRemainingAccounts({
25
- userAccounts: [taker, this.driftClient.getUserAccount()],
26
+ userAccounts: [taker, this.driftClient.getUserAccount(subAccountId)],
26
27
  writableSpotMarketIndexes: sdk_1.isVariant(order.marketType, 'spot')
27
28
  ? [order.marketIndex, sdk_1.QUOTE_SPOT_MARKET_INDEX]
28
29
  : [],
@@ -30,6 +31,18 @@ class JitProxyClient {
30
31
  ? [order.marketIndex]
31
32
  : [],
32
33
  });
34
+ if (referrerInfo) {
35
+ remainingAccounts.push({
36
+ pubkey: referrerInfo.referrer,
37
+ isWritable: true,
38
+ isSigner: false,
39
+ });
40
+ remainingAccounts.push({
41
+ pubkey: referrerInfo.referrerStats,
42
+ isWritable: true,
43
+ isSigner: false,
44
+ });
45
+ }
33
46
  if (sdk_1.isVariant(order.marketType, 'spot')) {
34
47
  remainingAccounts.push({
35
48
  pubkey: this.driftClient.getSpotMarketAccount(order.marketIndex).vault,
@@ -57,7 +70,7 @@ class JitProxyClient {
57
70
  taker: takerKey,
58
71
  takerStats: takerStatsKey,
59
72
  state: await this.driftClient.getStatePublicKey(),
60
- user: await this.driftClient.getUserAccountPublicKey(),
73
+ user: await this.driftClient.getUserAccountPublicKey(subAccountId),
61
74
  userStats: this.driftClient.getUserStatsAccountPublicKey(),
62
75
  driftProgram: this.driftClient.program.programId,
63
76
  })
package/lib/jitter.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare type JitParams = {
9
9
  minPosition: BN;
10
10
  maxPosition: any;
11
11
  priceType: PriceType;
12
+ subAccountId?: number;
12
13
  };
13
14
  export declare class Jitter {
14
15
  auctionSubscriber: AuctionSubscriber;
package/lib/jitter.js CHANGED
@@ -80,6 +80,7 @@ class Jitter {
80
80
  postOnly: null,
81
81
  priceType: params.priceType,
82
82
  referrerInfo,
83
+ subAccountId: params.subAccountId,
83
84
  });
84
85
  console.log(`Filled ${orderSignature} txSig ${txSig}`);
85
86
  await sleep(10000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/jit-proxy",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "dependencies": {
5
5
  "@coral-xyz/anchor": "^0.26.0",
6
6
  "@solana/web3.js": "1.73.2",
@@ -25,6 +25,7 @@ export type JitIxParams = {
25
25
  postOnly: PostOnlyParams | null;
26
26
  priceType?: PriceType;
27
27
  referrerInfo?: ReferrerInfo;
28
+ subAccountId?: number;
28
29
  };
29
30
 
30
31
  export class PriceType {
@@ -67,10 +68,13 @@ export class JitProxyClient {
67
68
  ask,
68
69
  postOnly = null,
69
70
  priceType = PriceType.LIMIT,
71
+ referrerInfo,
72
+ subAccountId
70
73
  }: JitIxParams): Promise<TransactionInstruction> {
74
+ subAccountId = subAccountId || this.driftClient.activeSubAccountId;
71
75
  const order = taker.orders.find((order) => order.orderId === takerOrderId);
72
76
  const remainingAccounts = this.driftClient.getRemainingAccounts({
73
- userAccounts: [taker, this.driftClient.getUserAccount()],
77
+ userAccounts: [taker, this.driftClient.getUserAccount(subAccountId)],
74
78
  writableSpotMarketIndexes: isVariant(order.marketType, 'spot')
75
79
  ? [order.marketIndex, QUOTE_SPOT_MARKET_INDEX]
76
80
  : [],
@@ -79,6 +83,19 @@ export class JitProxyClient {
79
83
  : [],
80
84
  });
81
85
 
86
+ if (referrerInfo) {
87
+ remainingAccounts.push({
88
+ pubkey: referrerInfo.referrer,
89
+ isWritable: true,
90
+ isSigner: false,
91
+ });
92
+ remainingAccounts.push({
93
+ pubkey: referrerInfo.referrerStats,
94
+ isWritable: true,
95
+ isSigner: false,
96
+ });
97
+ }
98
+
82
99
  if (isVariant(order.marketType, 'spot')) {
83
100
  remainingAccounts.push({
84
101
  pubkey: this.driftClient.getSpotMarketAccount(order.marketIndex).vault,
@@ -108,7 +125,7 @@ export class JitProxyClient {
108
125
  taker: takerKey,
109
126
  takerStats: takerStatsKey,
110
127
  state: await this.driftClient.getStatePublicKey(),
111
- user: await this.driftClient.getUserAccountPublicKey(),
128
+ user: await this.driftClient.getUserAccountPublicKey(subAccountId),
112
129
  userStats: this.driftClient.getUserStatsAccountPublicKey(),
113
130
  driftProgram: this.driftClient.program.programId,
114
131
  })
package/src/jitter.ts CHANGED
@@ -16,12 +16,14 @@ export type UserFilter = (
16
16
  userKey: string,
17
17
  order: Order
18
18
  ) => boolean;
19
+
19
20
  export type JitParams = {
20
21
  bid: BN;
21
22
  ask: BN;
22
23
  minPosition: BN;
23
24
  maxPosition;
24
25
  priceType: PriceType;
26
+ subAccountId?: number;
25
27
  };
26
28
 
27
29
  export class Jitter {
@@ -159,6 +161,7 @@ export class Jitter {
159
161
  postOnly: null,
160
162
  priceType: params.priceType,
161
163
  referrerInfo,
164
+ subAccountId: params.subAccountId,
162
165
  });
163
166
 
164
167
  console.log(`Filled ${orderSignature} txSig ${txSig}`);