@drift-labs/sdk 2.49.0-beta.4 → 2.49.0-beta.5

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.
@@ -1229,8 +1229,11 @@ export class DriftClient {
1229
1229
  return this.getUser(subAccountId).getUserAccountAndSlot();
1230
1230
  }
1231
1231
 
1232
- public getSpotPosition(marketIndex: number): SpotPosition | undefined {
1233
- return this.getUserAccount().spotPositions.find(
1232
+ public getSpotPosition(
1233
+ marketIndex: number,
1234
+ subAccountId?: number
1235
+ ): SpotPosition | undefined {
1236
+ return this.getUserAccount(subAccountId).spotPositions.find(
1234
1237
  (spotPosition) => spotPosition.marketIndex === marketIndex
1235
1238
  );
1236
1239
  }
@@ -1531,14 +1534,17 @@ export class DriftClient {
1531
1534
  };
1532
1535
  }
1533
1536
 
1534
- public getOrder(orderId: number): Order | undefined {
1535
- return this.getUserAccount()?.orders.find(
1537
+ public getOrder(orderId: number, subAccountId?: number): Order | undefined {
1538
+ return this.getUserAccount(subAccountId)?.orders.find(
1536
1539
  (order) => order.orderId === orderId
1537
1540
  );
1538
1541
  }
1539
1542
 
1540
- public getOrderByUserId(userOrderId: number): Order | undefined {
1541
- return this.getUserAccount()?.orders.find(
1543
+ public getOrderByUserId(
1544
+ userOrderId: number,
1545
+ subAccountId?: number
1546
+ ): Order | undefined {
1547
+ return this.getUserAccount(subAccountId)?.orders.find(
1542
1548
  (order) => order.userOrderId === userOrderId
1543
1549
  );
1544
1550
  }
@@ -1587,11 +1593,11 @@ export class DriftClient {
1587
1593
  /**
1588
1594
  * Deposit funds into the given spot market
1589
1595
  *
1590
- * @param amount
1591
- * @param marketIndex
1596
+ * @param amount to deposit
1597
+ * @param marketIndex spot market index to deposit into
1592
1598
  * @param associatedTokenAccount can be the wallet public key if using native sol
1593
- * @param subAccountId
1594
- * @param reduceOnly
1599
+ * @param subAccountId subaccountId to deposit
1600
+ * @param reduceOnly if true, deposit must not increase account risk
1595
1601
  */
1596
1602
  public async deposit(
1597
1603
  amount: BN,
@@ -1671,7 +1677,7 @@ export class DriftClient {
1671
1677
  const userAccountPublicKey = await getUserAccountPublicKey(
1672
1678
  this.program.programId,
1673
1679
  this.authority,
1674
- subAccountId ?? this.activeSubAccountId
1680
+ subAccountId
1675
1681
  );
1676
1682
 
1677
1683
  let remainingAccounts = [];
@@ -1967,7 +1973,8 @@ export class DriftClient {
1967
1973
  amount: BN,
1968
1974
  marketIndex: number,
1969
1975
  associatedTokenAddress: PublicKey,
1970
- reduceOnly = false
1976
+ reduceOnly = false,
1977
+ subAccountId?: number
1971
1978
  ): Promise<TransactionSignature> {
1972
1979
  const withdrawIxs = [];
1973
1980
 
@@ -2011,7 +2018,8 @@ export class DriftClient {
2011
2018
  amount,
2012
2019
  spotMarketAccount.marketIndex,
2013
2020
  associatedTokenAddress,
2014
- reduceOnly
2021
+ reduceOnly,
2022
+ subAccountId
2015
2023
  );
2016
2024
 
2017
2025
  withdrawIxs.push(withdrawCollateralIx);
@@ -2044,12 +2052,13 @@ export class DriftClient {
2044
2052
  amount: BN,
2045
2053
  marketIndex: number,
2046
2054
  userTokenAccount: PublicKey,
2047
- reduceOnly = false
2055
+ reduceOnly = false,
2056
+ subAccountId?: number
2048
2057
  ): Promise<TransactionInstruction> {
2049
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2058
+ const user = await this.getUserAccountPublicKey(subAccountId);
2050
2059
 
2051
2060
  const remainingAccounts = this.getRemainingAccounts({
2052
- userAccounts: [this.getUserAccount()],
2061
+ userAccounts: [this.getUserAccount(subAccountId)],
2053
2062
  useMarketLastSlotCache: true,
2054
2063
  writableSpotMarketIndexes: [marketIndex],
2055
2064
  readableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
@@ -2067,7 +2076,7 @@ export class DriftClient {
2067
2076
  spotMarket: spotMarketAccount.pubkey,
2068
2077
  spotMarketVault: spotMarketAccount.vault,
2069
2078
  driftSigner: this.getSignerPublicKey(),
2070
- user: userAccountPublicKey,
2079
+ user,
2071
2080
  userStats: this.getUserStatsAccountPublicKey(),
2072
2081
  userTokenAccount: userTokenAccount,
2073
2082
  authority: this.wallet.publicKey,
@@ -2244,11 +2253,16 @@ export class DriftClient {
2244
2253
  public async removePerpLpShares(
2245
2254
  marketIndex: number,
2246
2255
  sharesToBurn?: BN,
2247
- txParams?: TxParams
2256
+ txParams?: TxParams,
2257
+ subAccountId?: number
2248
2258
  ): Promise<TransactionSignature> {
2249
2259
  const { txSig } = await this.sendTransaction(
2250
2260
  await this.buildTransaction(
2251
- await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn),
2261
+ await this.getRemovePerpLpSharesIx(
2262
+ marketIndex,
2263
+ sharesToBurn,
2264
+ subAccountId
2265
+ ),
2252
2266
  txParams
2253
2267
  ),
2254
2268
  [],
@@ -2316,18 +2330,19 @@ export class DriftClient {
2316
2330
 
2317
2331
  public async getRemovePerpLpSharesIx(
2318
2332
  marketIndex: number,
2319
- sharesToBurn?: BN
2333
+ sharesToBurn?: BN,
2334
+ subAccountId?: number
2320
2335
  ): Promise<TransactionInstruction> {
2321
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2336
+ const user = await this.getUserAccountPublicKey(subAccountId);
2322
2337
 
2323
2338
  const remainingAccounts = this.getRemainingAccounts({
2324
- userAccounts: [this.getUserAccount()],
2339
+ userAccounts: [this.getUserAccount(subAccountId)],
2325
2340
  useMarketLastSlotCache: true,
2326
2341
  writablePerpMarketIndexes: [marketIndex],
2327
2342
  });
2328
2343
 
2329
2344
  if (sharesToBurn == undefined) {
2330
- const userAccount = this.getUserAccount();
2345
+ const userAccount = this.getUserAccount(subAccountId);
2331
2346
  const perpPosition = userAccount.perpPositions.filter(
2332
2347
  (position) => position.marketIndex === marketIndex
2333
2348
  )[0];
@@ -2341,7 +2356,7 @@ export class DriftClient {
2341
2356
  {
2342
2357
  accounts: {
2343
2358
  state: await this.getStatePublicKey(),
2344
- user: userAccountPublicKey,
2359
+ user,
2345
2360
  authority: this.wallet.publicKey,
2346
2361
  },
2347
2362
  remainingAccounts: remainingAccounts,
@@ -2352,11 +2367,12 @@ export class DriftClient {
2352
2367
  public async addPerpLpShares(
2353
2368
  amount: BN,
2354
2369
  marketIndex: number,
2355
- txParams?: TxParams
2370
+ txParams?: TxParams,
2371
+ subAccountId?: number
2356
2372
  ): Promise<TransactionSignature> {
2357
2373
  const { txSig, slot } = await this.sendTransaction(
2358
2374
  await this.buildTransaction(
2359
- await this.getAddPerpLpSharesIx(amount, marketIndex),
2375
+ await this.getAddPerpLpSharesIx(amount, marketIndex, subAccountId),
2360
2376
  txParams
2361
2377
  ),
2362
2378
  [],
@@ -2368,11 +2384,12 @@ export class DriftClient {
2368
2384
 
2369
2385
  public async getAddPerpLpSharesIx(
2370
2386
  amount: BN,
2371
- marketIndex: number
2387
+ marketIndex: number,
2388
+ subAccountId?: number
2372
2389
  ): Promise<TransactionInstruction> {
2373
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2390
+ const user = await this.getUserAccountPublicKey(subAccountId);
2374
2391
  const remainingAccounts = this.getRemainingAccounts({
2375
- userAccounts: [this.getUserAccount()],
2392
+ userAccounts: [this.getUserAccount(subAccountId)],
2376
2393
  useMarketLastSlotCache: true,
2377
2394
  writablePerpMarketIndexes: [marketIndex],
2378
2395
  });
@@ -2380,7 +2397,7 @@ export class DriftClient {
2380
2397
  return this.program.instruction.addPerpLpShares(amount, marketIndex, {
2381
2398
  accounts: {
2382
2399
  state: await this.getStatePublicKey(),
2383
- user: userAccountPublicKey,
2400
+ user,
2384
2401
  authority: this.wallet.publicKey,
2385
2402
  },
2386
2403
  remainingAccounts: remainingAccounts,
@@ -2423,15 +2440,22 @@ export class DriftClient {
2423
2440
  direction: PositionDirection,
2424
2441
  amount: BN,
2425
2442
  marketIndex: number,
2426
- limitPrice?: BN
2443
+ limitPrice?: BN,
2444
+ subAccountId?: number
2427
2445
  ): Promise<TransactionSignature> {
2428
- return await this.placeAndTakePerpOrder({
2429
- orderType: OrderType.MARKET,
2430
- marketIndex,
2431
- direction,
2432
- baseAssetAmount: amount,
2433
- price: limitPrice,
2434
- });
2446
+ return await this.placeAndTakePerpOrder(
2447
+ {
2448
+ orderType: OrderType.MARKET,
2449
+ marketIndex,
2450
+ direction,
2451
+ baseAssetAmount: amount,
2452
+ price: limitPrice,
2453
+ },
2454
+ undefined,
2455
+ undefined,
2456
+ undefined,
2457
+ subAccountId
2458
+ );
2435
2459
  }
2436
2460
 
2437
2461
  public async sendSignedTx(tx: Transaction): Promise<TransactionSignature> {
@@ -2474,11 +2498,15 @@ export class DriftClient {
2474
2498
  const orderId = userAccount.nextOrderId;
2475
2499
  const bracketOrderIxs = [];
2476
2500
 
2477
- const placePerpOrderIx = await this.getPlacePerpOrderIx(orderParams);
2501
+ const placePerpOrderIx = await this.getPlacePerpOrderIx(
2502
+ orderParams,
2503
+ userAccount.subAccountId
2504
+ );
2478
2505
 
2479
2506
  for (const bracketOrderParams of bracketOrdersParams) {
2480
2507
  const placeBracketOrderIx = await this.getPlacePerpOrderIx(
2481
- bracketOrderParams
2508
+ bracketOrderParams,
2509
+ userAccount.subAccountId
2482
2510
  );
2483
2511
  bracketOrderIxs.push(placeBracketOrderIx);
2484
2512
  }
@@ -2489,7 +2517,8 @@ export class DriftClient {
2489
2517
  cancelOrdersIx = await this.getCancelOrdersIx(
2490
2518
  orderParams.marketType,
2491
2519
  orderParams.marketIndex,
2492
- null
2520
+ null,
2521
+ userAccount.subAccountId
2493
2522
  );
2494
2523
 
2495
2524
  //@ts-ignore
@@ -2516,7 +2545,8 @@ export class DriftClient {
2516
2545
  marketIndex,
2517
2546
  },
2518
2547
  makerInfo,
2519
- referrerInfo
2548
+ referrerInfo,
2549
+ userAccount.subAccountId
2520
2550
  );
2521
2551
 
2522
2552
  const versionedFillTx = await this.buildTransaction(
@@ -2593,11 +2623,12 @@ export class DriftClient {
2593
2623
 
2594
2624
  public async placePerpOrder(
2595
2625
  orderParams: OptionalOrderParams,
2596
- txParams?: TxParams
2626
+ txParams?: TxParams,
2627
+ subAccountId?: number
2597
2628
  ): Promise<TransactionSignature> {
2598
2629
  const { txSig, slot } = await this.sendTransaction(
2599
2630
  await this.buildTransaction(
2600
- await this.getPlacePerpOrderIx(orderParams),
2631
+ await this.getPlacePerpOrderIx(orderParams, subAccountId),
2601
2632
  txParams
2602
2633
  ),
2603
2634
  [],
@@ -2608,13 +2639,14 @@ export class DriftClient {
2608
2639
  }
2609
2640
 
2610
2641
  public async getPlacePerpOrderIx(
2611
- orderParams: OptionalOrderParams
2642
+ orderParams: OptionalOrderParams,
2643
+ subAccountId?: number
2612
2644
  ): Promise<TransactionInstruction> {
2613
2645
  orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
2614
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2646
+ const user = await this.getUserAccountPublicKey(subAccountId);
2615
2647
 
2616
2648
  const remainingAccounts = this.getRemainingAccounts({
2617
- userAccounts: [this.getUserAccount()],
2649
+ userAccounts: [this.getUserAccount(subAccountId)],
2618
2650
  useMarketLastSlotCache: true,
2619
2651
  readablePerpMarketIndex: orderParams.marketIndex,
2620
2652
  });
@@ -2622,7 +2654,7 @@ export class DriftClient {
2622
2654
  return await this.program.instruction.placePerpOrder(orderParams, {
2623
2655
  accounts: {
2624
2656
  state: await this.getStatePublicKey(),
2625
- user: userAccountPublicKey,
2657
+ user,
2626
2658
  userStats: this.getUserStatsAccountPublicKey(),
2627
2659
  authority: this.wallet.publicKey,
2628
2660
  },
@@ -2766,11 +2798,12 @@ export class DriftClient {
2766
2798
 
2767
2799
  public async cancelOrder(
2768
2800
  orderId?: number,
2769
- txParams?: TxParams
2801
+ txParams?: TxParams,
2802
+ subAccountId?: number
2770
2803
  ): Promise<TransactionSignature> {
2771
2804
  const { txSig } = await this.sendTransaction(
2772
2805
  await this.buildTransaction(
2773
- await this.getCancelOrderIx(orderId),
2806
+ await this.getCancelOrderIx(orderId, subAccountId),
2774
2807
  txParams
2775
2808
  ),
2776
2809
  [],
@@ -2780,19 +2813,20 @@ export class DriftClient {
2780
2813
  }
2781
2814
 
2782
2815
  public async getCancelOrderIx(
2783
- orderId?: number
2816
+ orderId?: number,
2817
+ subAccountId?: number
2784
2818
  ): Promise<TransactionInstruction> {
2785
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2819
+ const user = await this.getUserAccountPublicKey(subAccountId);
2786
2820
 
2787
2821
  const remainingAccounts = this.getRemainingAccounts({
2788
- userAccounts: [this.getUserAccount()],
2822
+ userAccounts: [this.getUserAccount(subAccountId)],
2789
2823
  useMarketLastSlotCache: true,
2790
2824
  });
2791
2825
 
2792
2826
  return await this.program.instruction.cancelOrder(orderId ?? null, {
2793
2827
  accounts: {
2794
2828
  state: await this.getStatePublicKey(),
2795
- user: userAccountPublicKey,
2829
+ user,
2796
2830
  authority: this.wallet.publicKey,
2797
2831
  },
2798
2832
  remainingAccounts,
@@ -2801,11 +2835,12 @@ export class DriftClient {
2801
2835
 
2802
2836
  public async cancelOrderByUserId(
2803
2837
  userOrderId: number,
2804
- txParams?: TxParams
2838
+ txParams?: TxParams,
2839
+ subAccountId?: number
2805
2840
  ): Promise<TransactionSignature> {
2806
2841
  const { txSig } = await this.sendTransaction(
2807
2842
  await this.buildTransaction(
2808
- await this.getCancelOrderByUserIdIx(userOrderId),
2843
+ await this.getCancelOrderByUserIdIx(userOrderId, subAccountId),
2809
2844
  txParams
2810
2845
  ),
2811
2846
  [],
@@ -2815,22 +2850,23 @@ export class DriftClient {
2815
2850
  }
2816
2851
 
2817
2852
  public async getCancelOrderByUserIdIx(
2818
- userOrderId: number
2853
+ userOrderId: number,
2854
+ subAccountId?: number
2819
2855
  ): Promise<TransactionInstruction> {
2820
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2856
+ const user = await this.getUserAccountPublicKey(subAccountId);
2821
2857
 
2822
2858
  const order = this.getOrderByUserId(userOrderId);
2823
2859
  const oracle = this.getPerpMarketAccount(order.marketIndex).amm.oracle;
2824
2860
 
2825
2861
  const remainingAccounts = this.getRemainingAccounts({
2826
- userAccounts: [this.getUserAccount()],
2862
+ userAccounts: [this.getUserAccount(subAccountId)],
2827
2863
  useMarketLastSlotCache: true,
2828
2864
  });
2829
2865
 
2830
2866
  return await this.program.instruction.cancelOrderByUserId(userOrderId, {
2831
2867
  accounts: {
2832
2868
  state: await this.getStatePublicKey(),
2833
- user: userAccountPublicKey,
2869
+ user,
2834
2870
  authority: this.wallet.publicKey,
2835
2871
  oracle,
2836
2872
  },
@@ -2840,11 +2876,12 @@ export class DriftClient {
2840
2876
 
2841
2877
  public async cancelOrdersByIds(
2842
2878
  orderIds?: number[],
2843
- txParams?: TxParams
2879
+ txParams?: TxParams,
2880
+ subAccountId?: number
2844
2881
  ): Promise<TransactionSignature> {
2845
2882
  const { txSig } = await this.sendTransaction(
2846
2883
  await this.buildTransaction(
2847
- await this.getCancelOrdersByIdsIx(orderIds),
2884
+ await this.getCancelOrdersByIdsIx(orderIds, subAccountId),
2848
2885
  txParams
2849
2886
  ),
2850
2887
  [],
@@ -2854,19 +2891,20 @@ export class DriftClient {
2854
2891
  }
2855
2892
 
2856
2893
  public async getCancelOrdersByIdsIx(
2857
- orderIds?: number[]
2894
+ orderIds?: number[],
2895
+ subAccountId?: number
2858
2896
  ): Promise<TransactionInstruction> {
2859
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2897
+ const user = await this.getUserAccountPublicKey(subAccountId);
2860
2898
 
2861
2899
  const remainingAccounts = this.getRemainingAccounts({
2862
- userAccounts: [this.getUserAccount()],
2900
+ userAccounts: [this.getUserAccount(subAccountId)],
2863
2901
  useMarketLastSlotCache: true,
2864
2902
  });
2865
2903
 
2866
2904
  return await this.program.instruction.cancelOrdersByIds(orderIds, {
2867
2905
  accounts: {
2868
2906
  state: await this.getStatePublicKey(),
2869
- user: userAccountPublicKey,
2907
+ user,
2870
2908
  authority: this.wallet.publicKey,
2871
2909
  },
2872
2910
  remainingAccounts,
@@ -2877,11 +2915,17 @@ export class DriftClient {
2877
2915
  marketType?: MarketType,
2878
2916
  marketIndex?: number,
2879
2917
  direction?: PositionDirection,
2880
- txParams?: TxParams
2918
+ txParams?: TxParams,
2919
+ subAccountId?: number
2881
2920
  ): Promise<TransactionSignature> {
2882
2921
  const { txSig } = await this.sendTransaction(
2883
2922
  await this.buildTransaction(
2884
- await this.getCancelOrdersIx(marketType, marketIndex, direction),
2923
+ await this.getCancelOrdersIx(
2924
+ marketType,
2925
+ marketIndex,
2926
+ direction,
2927
+ subAccountId
2928
+ ),
2885
2929
  txParams
2886
2930
  ),
2887
2931
  [],
@@ -2893,9 +2937,10 @@ export class DriftClient {
2893
2937
  public async getCancelOrdersIx(
2894
2938
  marketType: MarketType | null,
2895
2939
  marketIndex: number | null,
2896
- direction: PositionDirection | null
2940
+ direction: PositionDirection | null,
2941
+ subAccountId?: number
2897
2942
  ): Promise<TransactionInstruction> {
2898
- const userAccountPublicKey = await this.getUserAccountPublicKey();
2943
+ const user = await this.getUserAccountPublicKey(subAccountId);
2899
2944
 
2900
2945
  let readablePerpMarketIndex = undefined;
2901
2946
  let readableSpotMarketIndexes = undefined;
@@ -2909,7 +2954,7 @@ export class DriftClient {
2909
2954
  }
2910
2955
 
2911
2956
  const remainingAccounts = this.getRemainingAccounts({
2912
- userAccounts: [this.getUserAccount()],
2957
+ userAccounts: [this.getUserAccount(subAccountId)],
2913
2958
  readablePerpMarketIndex,
2914
2959
  readableSpotMarketIndexes,
2915
2960
  useMarketLastSlotCache: true,
@@ -2922,7 +2967,7 @@ export class DriftClient {
2922
2967
  {
2923
2968
  accounts: {
2924
2969
  state: await this.getStatePublicKey(),
2925
- user: userAccountPublicKey,
2970
+ user,
2926
2971
  authority: this.wallet.publicKey,
2927
2972
  },
2928
2973
  remainingAccounts,
@@ -2937,15 +2982,17 @@ export class DriftClient {
2937
2982
  direction?: PositionDirection;
2938
2983
  },
2939
2984
  placeOrderParams: OrderParams[],
2940
- txParams?: TxParams
2985
+ txParams?: TxParams,
2986
+ subAccountId?: number
2941
2987
  ): Promise<TransactionSignature> {
2942
2988
  const ixs = [
2943
2989
  await this.getCancelOrdersIx(
2944
2990
  cancelOrderParams.marketType,
2945
2991
  cancelOrderParams.marketIndex,
2946
- cancelOrderParams.direction
2992
+ cancelOrderParams.direction,
2993
+ subAccountId
2947
2994
  ),
2948
- await this.getPlaceOrdersIx(placeOrderParams),
2995
+ await this.getPlaceOrdersIx(placeOrderParams, subAccountId),
2949
2996
  ];
2950
2997
  const tx = await this.buildTransaction(ixs, txParams);
2951
2998
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -2954,11 +3001,12 @@ export class DriftClient {
2954
3001
 
2955
3002
  public async placeOrders(
2956
3003
  params: OrderParams[],
2957
- txParams?: TxParams
3004
+ txParams?: TxParams,
3005
+ subAccountId?: number
2958
3006
  ): Promise<TransactionSignature> {
2959
3007
  const { txSig } = await this.sendTransaction(
2960
3008
  await this.buildTransaction(
2961
- await this.getPlaceOrdersIx(params),
3009
+ await this.getPlaceOrdersIx(params, subAccountId),
2962
3010
  txParams
2963
3011
  ),
2964
3012
  [],
@@ -2968,9 +3016,10 @@ export class DriftClient {
2968
3016
  }
2969
3017
 
2970
3018
  public async getPlaceOrdersIx(
2971
- params: OrderParams[]
3019
+ params: OrderParams[],
3020
+ subAccountId?: number
2972
3021
  ): Promise<TransactionInstruction> {
2973
- const userAccountPublicKey = await this.getUserAccountPublicKey();
3022
+ const user = await this.getUserAccountPublicKey(subAccountId);
2974
3023
 
2975
3024
  const readablePerpMarketIndex: number[] = [];
2976
3025
  const readableSpotMarketIndexes: number[] = [];
@@ -2986,7 +3035,7 @@ export class DriftClient {
2986
3035
  }
2987
3036
 
2988
3037
  const remainingAccounts = this.getRemainingAccounts({
2989
- userAccounts: [this.getUserAccount()],
3038
+ userAccounts: [this.getUserAccount(subAccountId)],
2990
3039
  readablePerpMarketIndex,
2991
3040
  readableSpotMarketIndexes,
2992
3041
  useMarketLastSlotCache: true,
@@ -2995,7 +3044,7 @@ export class DriftClient {
2995
3044
  return await this.program.instruction.placeOrders(params, {
2996
3045
  accounts: {
2997
3046
  state: await this.getStatePublicKey(),
2998
- user: userAccountPublicKey,
3047
+ user,
2999
3048
  userStats: this.getUserStatsAccountPublicKey(),
3000
3049
  authority: this.wallet.publicKey,
3001
3050
  },
@@ -3009,7 +3058,8 @@ export class DriftClient {
3009
3058
  order?: Pick<Order, 'marketIndex' | 'orderId'>,
3010
3059
  makerInfo?: MakerInfo | MakerInfo[],
3011
3060
  referrerInfo?: ReferrerInfo,
3012
- txParams?: TxParams
3061
+ txParams?: TxParams,
3062
+ fillerPublicKey?: number
3013
3063
  ): Promise<TransactionSignature> {
3014
3064
  const { txSig } = await this.sendTransaction(
3015
3065
  await this.buildTransaction(
@@ -3018,7 +3068,8 @@ export class DriftClient {
3018
3068
  user,
3019
3069
  order,
3020
3070
  makerInfo,
3021
- referrerInfo
3071
+ referrerInfo,
3072
+ fillerPublicKey
3022
3073
  ),
3023
3074
  txParams
3024
3075
  ),
@@ -3033,14 +3084,15 @@ export class DriftClient {
3033
3084
  userAccount: UserAccount,
3034
3085
  order: Pick<Order, 'marketIndex' | 'orderId'>,
3035
3086
  makerInfo?: MakerInfo | MakerInfo[],
3036
- referrerInfo?: ReferrerInfo
3087
+ referrerInfo?: ReferrerInfo,
3088
+ fillerSubAccountId?: number
3037
3089
  ): Promise<TransactionInstruction> {
3038
3090
  const userStatsPublicKey = getUserStatsAccountPublicKey(
3039
3091
  this.program.programId,
3040
3092
  userAccount.authority
3041
3093
  );
3042
3094
 
3043
- const fillerPublicKey = await this.getUserAccountPublicKey();
3095
+ const filler = await this.getUserAccountPublicKey(fillerSubAccountId);
3044
3096
  const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
3045
3097
 
3046
3098
  const marketIndex = order
@@ -3099,7 +3151,7 @@ export class DriftClient {
3099
3151
  return await this.program.instruction.fillPerpOrder(orderId, null, {
3100
3152
  accounts: {
3101
3153
  state: await this.getStatePublicKey(),
3102
- filler: fillerPublicKey,
3154
+ filler,
3103
3155
  fillerStats: fillerStatsPublicKey,
3104
3156
  user: userAccountPublicKey,
3105
3157
  userStats: userStatsPublicKey,
@@ -3109,14 +3161,16 @@ export class DriftClient {
3109
3161
  });
3110
3162
  }
3111
3163
 
3112
- public async getRevertFillIx(): Promise<TransactionInstruction> {
3113
- const fillerPublicKey = await this.getUserAccountPublicKey();
3164
+ public async getRevertFillIx(
3165
+ fillerPublicKey?: PublicKey
3166
+ ): Promise<TransactionInstruction> {
3167
+ const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
3114
3168
  const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
3115
3169
 
3116
3170
  return this.program.instruction.revertFill({
3117
3171
  accounts: {
3118
3172
  state: await this.getStatePublicKey(),
3119
- filler: fillerPublicKey,
3173
+ filler,
3120
3174
  fillerStats: fillerStatsPublicKey,
3121
3175
  authority: this.wallet.publicKey,
3122
3176
  },
@@ -3125,11 +3179,12 @@ export class DriftClient {
3125
3179
 
3126
3180
  public async placeSpotOrder(
3127
3181
  orderParams: OptionalOrderParams,
3128
- txParams?: TxParams
3182
+ txParams?: TxParams,
3183
+ subAccountId?: number
3129
3184
  ): Promise<TransactionSignature> {
3130
3185
  const { txSig, slot } = await this.sendTransaction(
3131
3186
  await this.buildTransaction(
3132
- await this.getPlaceSpotOrderIx(orderParams),
3187
+ await this.getPlaceSpotOrderIx(orderParams, subAccountId),
3133
3188
  txParams
3134
3189
  ),
3135
3190
  [],
@@ -3141,13 +3196,16 @@ export class DriftClient {
3141
3196
  }
3142
3197
 
3143
3198
  public async getPlaceSpotOrderIx(
3144
- orderParams: OptionalOrderParams
3199
+ orderParams: OptionalOrderParams,
3200
+ subAccountId?: number
3145
3201
  ): Promise<TransactionInstruction> {
3146
3202
  orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
3147
- const userAccountPublicKey = await this.getUserAccountPublicKey();
3203
+ const userAccountPublicKey = await this.getUserAccountPublicKey(
3204
+ subAccountId
3205
+ );
3148
3206
 
3149
3207
  const remainingAccounts = this.getRemainingAccounts({
3150
- userAccounts: [this.getUserAccount()],
3208
+ userAccounts: [this.getUserAccount(subAccountId)],
3151
3209
  useMarketLastSlotCache: true,
3152
3210
  readableSpotMarketIndexes: [
3153
3211
  orderParams.marketIndex,
@@ -3203,14 +3261,15 @@ export class DriftClient {
3203
3261
  | SerumV3FulfillmentConfigAccount
3204
3262
  | PhoenixV1FulfillmentConfigAccount,
3205
3263
  makerInfo?: MakerInfo,
3206
- referrerInfo?: ReferrerInfo
3264
+ referrerInfo?: ReferrerInfo,
3265
+ fillerPublicKey?: PublicKey
3207
3266
  ): Promise<TransactionInstruction> {
3208
3267
  const userStatsPublicKey = getUserStatsAccountPublicKey(
3209
3268
  this.program.programId,
3210
3269
  userAccount.authority
3211
3270
  );
3212
3271
 
3213
- const fillerPublicKey = await this.getUserAccountPublicKey();
3272
+ const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
3214
3273
  const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
3215
3274
 
3216
3275
  const marketIndex = order
@@ -3270,7 +3329,7 @@ export class DriftClient {
3270
3329
  {
3271
3330
  accounts: {
3272
3331
  state: await this.getStatePublicKey(),
3273
- filler: fillerPublicKey,
3332
+ filler,
3274
3333
  fillerStats: fillerStatsPublicKey,
3275
3334
  user: userAccountPublicKey,
3276
3335
  userStats: userStatsPublicKey,
@@ -3983,11 +4042,17 @@ export class DriftClient {
3983
4042
  userAccountPublicKey: PublicKey,
3984
4043
  user: UserAccount,
3985
4044
  order: Order,
3986
- txParams?: TxParams
4045
+ txParams?: TxParams,
4046
+ fillerPublicKey?: PublicKey
3987
4047
  ): Promise<TransactionSignature> {
3988
4048
  const { txSig } = await this.sendTransaction(
3989
4049
  await this.buildTransaction(
3990
- await this.getTriggerOrderIx(userAccountPublicKey, user, order),
4050
+ await this.getTriggerOrderIx(
4051
+ userAccountPublicKey,
4052
+ user,
4053
+ order,
4054
+ fillerPublicKey
4055
+ ),
3991
4056
  txParams
3992
4057
  ),
3993
4058
  [],
@@ -3999,9 +4064,10 @@ export class DriftClient {
3999
4064
  public async getTriggerOrderIx(
4000
4065
  userAccountPublicKey: PublicKey,
4001
4066
  userAccount: UserAccount,
4002
- order: Order
4067
+ order: Order,
4068
+ fillerPublicKey?: PublicKey
4003
4069
  ): Promise<TransactionInstruction> {
4004
- const fillerPublicKey = await this.getUserAccountPublicKey();
4070
+ const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
4005
4071
 
4006
4072
  let remainingAccountsParams;
4007
4073
  if (isVariant(order.marketType, 'perp')) {
@@ -4024,7 +4090,7 @@ export class DriftClient {
4024
4090
  return await this.program.instruction.triggerOrder(orderId, {
4025
4091
  accounts: {
4026
4092
  state: await this.getStatePublicKey(),
4027
- filler: fillerPublicKey,
4093
+ filler,
4028
4094
  user: userAccountPublicKey,
4029
4095
  authority: this.wallet.publicKey,
4030
4096
  },
@@ -4035,11 +4101,16 @@ export class DriftClient {
4035
4101
  public async forceCancelOrders(
4036
4102
  userAccountPublicKey: PublicKey,
4037
4103
  user: UserAccount,
4038
- txParams?: TxParams
4104
+ txParams?: TxParams,
4105
+ fillerPublicKey?: PublicKey
4039
4106
  ): Promise<TransactionSignature> {
4040
4107
  const { txSig } = await this.sendTransaction(
4041
4108
  await this.buildTransaction(
4042
- await this.getForceCancelOrdersIx(userAccountPublicKey, user),
4109
+ await this.getForceCancelOrdersIx(
4110
+ userAccountPublicKey,
4111
+ user,
4112
+ fillerPublicKey
4113
+ ),
4043
4114
  txParams
4044
4115
  ),
4045
4116
  [],
@@ -4050,9 +4121,10 @@ export class DriftClient {
4050
4121
 
4051
4122
  public async getForceCancelOrdersIx(
4052
4123
  userAccountPublicKey: PublicKey,
4053
- userAccount: UserAccount
4124
+ userAccount: UserAccount,
4125
+ fillerPublicKey?: PublicKey
4054
4126
  ): Promise<TransactionInstruction> {
4055
- const fillerPublicKey = await this.getUserAccountPublicKey();
4127
+ const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
4056
4128
 
4057
4129
  const remainingAccounts = this.getRemainingAccounts({
4058
4130
  userAccounts: [userAccount],
@@ -4062,7 +4134,7 @@ export class DriftClient {
4062
4134
  return await this.program.instruction.forceCancelOrders({
4063
4135
  accounts: {
4064
4136
  state: await this.getStatePublicKey(),
4065
- filler: fillerPublicKey,
4137
+ filler,
4066
4138
  user: userAccountPublicKey,
4067
4139
  authority: this.wallet.publicKey,
4068
4140
  },
@@ -4073,11 +4145,16 @@ export class DriftClient {
4073
4145
  public async updateUserIdle(
4074
4146
  userAccountPublicKey: PublicKey,
4075
4147
  user: UserAccount,
4076
- txParams?: TxParams
4148
+ txParams?: TxParams,
4149
+ fillerPublicKey?: PublicKey
4077
4150
  ): Promise<TransactionSignature> {
4078
4151
  const { txSig } = await this.sendTransaction(
4079
4152
  await this.buildTransaction(
4080
- await this.getUpdateUserIdleIx(userAccountPublicKey, user),
4153
+ await this.getUpdateUserIdleIx(
4154
+ userAccountPublicKey,
4155
+ user,
4156
+ fillerPublicKey
4157
+ ),
4081
4158
  txParams
4082
4159
  ),
4083
4160
  [],
@@ -4088,9 +4165,10 @@ export class DriftClient {
4088
4165
 
4089
4166
  public async getUpdateUserIdleIx(
4090
4167
  userAccountPublicKey: PublicKey,
4091
- userAccount: UserAccount
4168
+ userAccount: UserAccount,
4169
+ fillerPublicKey?: PublicKey
4092
4170
  ): Promise<TransactionInstruction> {
4093
- const fillerPublicKey = await this.getUserAccountPublicKey();
4171
+ const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
4094
4172
 
4095
4173
  const remainingAccounts = this.getRemainingAccounts({
4096
4174
  userAccounts: [userAccount],
@@ -4099,7 +4177,7 @@ export class DriftClient {
4099
4177
  return await this.program.instruction.updateUserIdle({
4100
4178
  accounts: {
4101
4179
  state: await this.getStatePublicKey(),
4102
- filler: fillerPublicKey,
4180
+ filler,
4103
4181
  user: userAccountPublicKey,
4104
4182
  authority: this.wallet.publicKey,
4105
4183
  },
@@ -4110,11 +4188,16 @@ export class DriftClient {
4110
4188
  public async updateUserOpenOrdersCount(
4111
4189
  userAccountPublicKey: PublicKey,
4112
4190
  user: UserAccount,
4113
- txParams?: TxParams
4191
+ txParams?: TxParams,
4192
+ fillerPublicKey?: PublicKey
4114
4193
  ): Promise<TransactionSignature> {
4115
4194
  const { txSig } = await this.sendTransaction(
4116
4195
  await this.buildTransaction(
4117
- await this.getUpdateUserOpenOrdersCountIx(userAccountPublicKey, user),
4196
+ await this.getUpdateUserOpenOrdersCountIx(
4197
+ userAccountPublicKey,
4198
+ user,
4199
+ fillerPublicKey
4200
+ ),
4118
4201
  txParams
4119
4202
  ),
4120
4203
  [],
@@ -4125,9 +4208,10 @@ export class DriftClient {
4125
4208
 
4126
4209
  public async getUpdateUserOpenOrdersCountIx(
4127
4210
  userAccountPublicKey: PublicKey,
4128
- userAccount: UserAccount
4211
+ userAccount: UserAccount,
4212
+ fillerPublicKey?: PublicKey
4129
4213
  ): Promise<TransactionInstruction> {
4130
- const fillerPublicKey = await this.getUserAccountPublicKey();
4214
+ const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
4131
4215
 
4132
4216
  const remainingAccounts = this.getRemainingAccounts({
4133
4217
  userAccounts: [userAccount],
@@ -4136,7 +4220,7 @@ export class DriftClient {
4136
4220
  return await this.program.instruction.updateUserOpenOrdersCount({
4137
4221
  accounts: {
4138
4222
  state: await this.getStatePublicKey(),
4139
- filler: fillerPublicKey,
4223
+ filler,
4140
4224
  user: userAccountPublicKey,
4141
4225
  authority: this.wallet.publicKey,
4142
4226
  },
@@ -4148,14 +4232,16 @@ export class DriftClient {
4148
4232
  orderParams: OptionalOrderParams,
4149
4233
  makerInfo?: MakerInfo | MakerInfo[],
4150
4234
  referrerInfo?: ReferrerInfo,
4151
- txParams?: TxParams
4235
+ txParams?: TxParams,
4236
+ subAccountId?: number
4152
4237
  ): Promise<TransactionSignature> {
4153
4238
  const { txSig, slot } = await this.sendTransaction(
4154
4239
  await this.buildTransaction(
4155
4240
  await this.getPlaceAndTakePerpOrderIx(
4156
4241
  orderParams,
4157
4242
  makerInfo,
4158
- referrerInfo
4243
+ referrerInfo,
4244
+ subAccountId
4159
4245
  ),
4160
4246
  txParams
4161
4247
  ),
@@ -4169,11 +4255,12 @@ export class DriftClient {
4169
4255
  public async getPlaceAndTakePerpOrderIx(
4170
4256
  orderParams: OptionalOrderParams,
4171
4257
  makerInfo?: MakerInfo | MakerInfo[],
4172
- referrerInfo?: ReferrerInfo
4258
+ referrerInfo?: ReferrerInfo,
4259
+ subAccountId?: number
4173
4260
  ): Promise<TransactionInstruction> {
4174
4261
  orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
4175
4262
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
4176
- const userAccountPublicKey = await this.getUserAccountPublicKey();
4263
+ const user = await this.getUserAccountPublicKey(subAccountId);
4177
4264
 
4178
4265
  makerInfo = Array.isArray(makerInfo)
4179
4266
  ? makerInfo
@@ -4181,7 +4268,7 @@ export class DriftClient {
4181
4268
  ? [makerInfo]
4182
4269
  : [];
4183
4270
 
4184
- const userAccounts = [this.getUserAccount()];
4271
+ const userAccounts = [this.getUserAccount(subAccountId)];
4185
4272
  for (const maker of makerInfo) {
4186
4273
  userAccounts.push(maker.makerUserAccount);
4187
4274
  }
@@ -4229,7 +4316,7 @@ export class DriftClient {
4229
4316
  {
4230
4317
  accounts: {
4231
4318
  state: await this.getStatePublicKey(),
4232
- user: userAccountPublicKey,
4319
+ user,
4233
4320
  userStats: userStatsPublicKey,
4234
4321
  authority: this.wallet.publicKey,
4235
4322
  },
@@ -4242,14 +4329,16 @@ export class DriftClient {
4242
4329
  orderParams: OptionalOrderParams,
4243
4330
  takerInfo: TakerInfo,
4244
4331
  referrerInfo?: ReferrerInfo,
4245
- txParams?: TxParams
4332
+ txParams?: TxParams,
4333
+ subAccountId?: number
4246
4334
  ): Promise<TransactionSignature> {
4247
4335
  const { txSig, slot } = await this.sendTransaction(
4248
4336
  await this.buildTransaction(
4249
4337
  await this.getPlaceAndMakePerpOrderIx(
4250
4338
  orderParams,
4251
4339
  takerInfo,
4252
- referrerInfo
4340
+ referrerInfo,
4341
+ subAccountId
4253
4342
  ),
4254
4343
  txParams
4255
4344
  ),
@@ -4265,14 +4354,18 @@ export class DriftClient {
4265
4354
  public async getPlaceAndMakePerpOrderIx(
4266
4355
  orderParams: OptionalOrderParams,
4267
4356
  takerInfo: TakerInfo,
4268
- referrerInfo?: ReferrerInfo
4357
+ referrerInfo?: ReferrerInfo,
4358
+ subAccountId?: number
4269
4359
  ): Promise<TransactionInstruction> {
4270
4360
  orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
4271
4361
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
4272
- const userAccountPublicKey = await this.getUserAccountPublicKey();
4362
+ const user = await this.getUserAccountPublicKey(subAccountId);
4273
4363
 
4274
4364
  const remainingAccounts = this.getRemainingAccounts({
4275
- userAccounts: [this.getUserAccount(), takerInfo.takerUserAccount],
4365
+ userAccounts: [
4366
+ this.getUserAccount(subAccountId),
4367
+ takerInfo.takerUserAccount,
4368
+ ],
4276
4369
  useMarketLastSlotCache: true,
4277
4370
  writablePerpMarketIndexes: [orderParams.marketIndex],
4278
4371
  });
@@ -4297,7 +4390,7 @@ export class DriftClient {
4297
4390
  {
4298
4391
  accounts: {
4299
4392
  state: await this.getStatePublicKey(),
4300
- user: userAccountPublicKey,
4393
+ user,
4301
4394
  userStats: userStatsPublicKey,
4302
4395
  taker: takerInfo.taker,
4303
4396
  takerStats: takerInfo.takerStats,
@@ -4313,7 +4406,8 @@ export class DriftClient {
4313
4406
  fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
4314
4407
  makerInfo?: MakerInfo,
4315
4408
  referrerInfo?: ReferrerInfo,
4316
- txParams?: TxParams
4409
+ txParams?: TxParams,
4410
+ subAccountId?: number
4317
4411
  ): Promise<TransactionSignature> {
4318
4412
  const { txSig, slot } = await this.sendTransaction(
4319
4413
  await this.buildTransaction(
@@ -4321,7 +4415,8 @@ export class DriftClient {
4321
4415
  orderParams,
4322
4416
  fulfillmentConfig,
4323
4417
  makerInfo,
4324
- referrerInfo
4418
+ referrerInfo,
4419
+ subAccountId
4325
4420
  ),
4326
4421
  txParams
4327
4422
  ),
@@ -4337,13 +4432,14 @@ export class DriftClient {
4337
4432
  orderParams: OptionalOrderParams,
4338
4433
  fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
4339
4434
  makerInfo?: MakerInfo,
4340
- referrerInfo?: ReferrerInfo
4435
+ referrerInfo?: ReferrerInfo,
4436
+ subAccountId?: number
4341
4437
  ): Promise<TransactionInstruction> {
4342
4438
  orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
4343
- const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
4344
- const userAccountPublicKey = await this.getUserAccountPublicKey();
4439
+ const userStatsPublicKey = this.getUserStatsAccountPublicKey();
4440
+ const user = await this.getUserAccountPublicKey(subAccountId);
4345
4441
 
4346
- const userAccounts = [this.getUserAccount()];
4442
+ const userAccounts = [this.getUserAccount(subAccountId)];
4347
4443
  if (makerInfo !== undefined) {
4348
4444
  userAccounts.push(makerInfo.makerUserAccount);
4349
4445
  }
@@ -4397,7 +4493,7 @@ export class DriftClient {
4397
4493
  {
4398
4494
  accounts: {
4399
4495
  state: await this.getStatePublicKey(),
4400
- user: userAccountPublicKey,
4496
+ user,
4401
4497
  userStats: userStatsPublicKey,
4402
4498
  authority: this.wallet.publicKey,
4403
4499
  },
@@ -4411,7 +4507,8 @@ export class DriftClient {
4411
4507
  takerInfo: TakerInfo,
4412
4508
  fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
4413
4509
  referrerInfo?: ReferrerInfo,
4414
- txParams?: TxParams
4510
+ txParams?: TxParams,
4511
+ subAccountId?: number
4415
4512
  ): Promise<TransactionSignature> {
4416
4513
  const { txSig, slot } = await this.sendTransaction(
4417
4514
  await this.buildTransaction(
@@ -4419,7 +4516,8 @@ export class DriftClient {
4419
4516
  orderParams,
4420
4517
  takerInfo,
4421
4518
  fulfillmentConfig,
4422
- referrerInfo
4519
+ referrerInfo,
4520
+ subAccountId
4423
4521
  ),
4424
4522
  txParams
4425
4523
  ),
@@ -4435,14 +4533,18 @@ export class DriftClient {
4435
4533
  orderParams: OptionalOrderParams,
4436
4534
  takerInfo: TakerInfo,
4437
4535
  fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
4438
- referrerInfo?: ReferrerInfo
4536
+ referrerInfo?: ReferrerInfo,
4537
+ subAccountId?: number
4439
4538
  ): Promise<TransactionInstruction> {
4440
4539
  orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
4441
4540
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
4442
- const userAccountPublicKey = await this.getUserAccountPublicKey();
4541
+ const user = await this.getUserAccountPublicKey(subAccountId);
4443
4542
 
4444
4543
  const remainingAccounts = this.getRemainingAccounts({
4445
- userAccounts: [this.getUserAccount(), takerInfo.takerUserAccount],
4544
+ userAccounts: [
4545
+ this.getUserAccount(subAccountId),
4546
+ takerInfo.takerUserAccount,
4547
+ ],
4446
4548
  useMarketLastSlotCache: true,
4447
4549
  writableSpotMarketIndexes: [
4448
4550
  orderParams.marketIndex,
@@ -4477,7 +4579,7 @@ export class DriftClient {
4477
4579
  {
4478
4580
  accounts: {
4479
4581
  state: await this.getStatePublicKey(),
4480
- user: userAccountPublicKey,
4582
+ user,
4481
4583
  userStats: userStatsPublicKey,
4482
4584
  taker: takerInfo.taker,
4483
4585
  takerStats: takerInfo.takerStats,
@@ -4493,21 +4595,29 @@ export class DriftClient {
4493
4595
  */
4494
4596
  public async closePosition(
4495
4597
  marketIndex: number,
4496
- limitPrice?: BN
4598
+ limitPrice?: BN,
4599
+ subAccountId?: number
4497
4600
  ): Promise<TransactionSignature> {
4498
- const userPosition = this.getUser().getPerpPosition(marketIndex);
4601
+ const userPosition =
4602
+ this.getUser(subAccountId).getPerpPosition(marketIndex);
4499
4603
  if (!userPosition) {
4500
4604
  throw Error(`No position in market ${marketIndex.toString()}`);
4501
4605
  }
4502
4606
 
4503
- return await this.placeAndTakePerpOrder({
4504
- orderType: OrderType.MARKET,
4505
- marketIndex,
4506
- direction: findDirectionToClose(userPosition),
4507
- baseAssetAmount: userPosition.baseAssetAmount.abs(),
4508
- reduceOnly: true,
4509
- price: limitPrice,
4510
- });
4607
+ return await this.placeAndTakePerpOrder(
4608
+ {
4609
+ orderType: OrderType.MARKET,
4610
+ marketIndex,
4611
+ direction: findDirectionToClose(userPosition),
4612
+ baseAssetAmount: userPosition.baseAssetAmount.abs(),
4613
+ reduceOnly: true,
4614
+ price: limitPrice,
4615
+ },
4616
+ undefined,
4617
+ undefined,
4618
+ undefined,
4619
+ subAccountId
4620
+ );
4511
4621
  }
4512
4622
 
4513
4623
  /**
@@ -4592,11 +4702,12 @@ export class DriftClient {
4592
4702
  maxTs?: BN;
4593
4703
  policy?: ModifyOrderPolicy;
4594
4704
  },
4595
- txParams?: TxParams
4705
+ txParams?: TxParams,
4706
+ subAccountId?: number
4596
4707
  ): Promise<TransactionSignature> {
4597
4708
  const { txSig } = await this.sendTransaction(
4598
4709
  await this.buildTransaction(
4599
- await this.getModifyOrderIx(orderParams),
4710
+ await this.getModifyOrderIx(orderParams, subAccountId),
4600
4711
  txParams
4601
4712
  ),
4602
4713
  [],
@@ -4605,43 +4716,46 @@ export class DriftClient {
4605
4716
  return txSig;
4606
4717
  }
4607
4718
 
4608
- public async getModifyOrderIx({
4609
- orderId,
4610
- newDirection,
4611
- newBaseAmount,
4612
- newLimitPrice,
4613
- newOraclePriceOffset,
4614
- newTriggerPrice,
4615
- newTriggerCondition,
4616
- auctionDuration,
4617
- auctionStartPrice,
4618
- auctionEndPrice,
4619
- reduceOnly,
4620
- postOnly,
4621
- immediateOrCancel,
4622
- maxTs,
4623
- policy,
4624
- }: {
4625
- orderId: number;
4626
- newDirection?: PositionDirection;
4627
- newBaseAmount?: BN;
4628
- newLimitPrice?: BN;
4629
- newOraclePriceOffset?: number;
4630
- newTriggerPrice?: BN;
4631
- newTriggerCondition?: OrderTriggerCondition;
4632
- auctionDuration?: number;
4633
- auctionStartPrice?: BN;
4634
- auctionEndPrice?: BN;
4635
- reduceOnly?: boolean;
4636
- postOnly?: boolean;
4637
- immediateOrCancel?: boolean;
4638
- maxTs?: BN;
4639
- policy?: ModifyOrderPolicy;
4640
- }): Promise<TransactionInstruction> {
4641
- const userAccountPublicKey = await this.getUserAccountPublicKey();
4719
+ public async getModifyOrderIx(
4720
+ {
4721
+ orderId,
4722
+ newDirection,
4723
+ newBaseAmount,
4724
+ newLimitPrice,
4725
+ newOraclePriceOffset,
4726
+ newTriggerPrice,
4727
+ newTriggerCondition,
4728
+ auctionDuration,
4729
+ auctionStartPrice,
4730
+ auctionEndPrice,
4731
+ reduceOnly,
4732
+ postOnly,
4733
+ immediateOrCancel,
4734
+ maxTs,
4735
+ policy,
4736
+ }: {
4737
+ orderId: number;
4738
+ newDirection?: PositionDirection;
4739
+ newBaseAmount?: BN;
4740
+ newLimitPrice?: BN;
4741
+ newOraclePriceOffset?: number;
4742
+ newTriggerPrice?: BN;
4743
+ newTriggerCondition?: OrderTriggerCondition;
4744
+ auctionDuration?: number;
4745
+ auctionStartPrice?: BN;
4746
+ auctionEndPrice?: BN;
4747
+ reduceOnly?: boolean;
4748
+ postOnly?: boolean;
4749
+ immediateOrCancel?: boolean;
4750
+ maxTs?: BN;
4751
+ policy?: ModifyOrderPolicy;
4752
+ },
4753
+ subAccountId?: number
4754
+ ): Promise<TransactionInstruction> {
4755
+ const user = await this.getUserAccountPublicKey(subAccountId);
4642
4756
 
4643
4757
  const remainingAccounts = this.getRemainingAccounts({
4644
- userAccounts: [this.getUserAccount()],
4758
+ userAccounts: [this.getUserAccount(subAccountId)],
4645
4759
  useMarketLastSlotCache: true,
4646
4760
  });
4647
4761
 
@@ -4666,7 +4780,7 @@ export class DriftClient {
4666
4780
  return await this.program.instruction.modifyOrder(orderId, orderParams, {
4667
4781
  accounts: {
4668
4782
  state: await this.getStatePublicKey(),
4669
- user: userAccountPublicKey,
4783
+ user,
4670
4784
  userStats: this.getUserStatsAccountPublicKey(),
4671
4785
  authority: this.wallet.publicKey,
4672
4786
  },
@@ -4710,11 +4824,12 @@ export class DriftClient {
4710
4824
  policy?: ModifyOrderPolicy;
4711
4825
  maxTs?: BN;
4712
4826
  },
4713
- txParams?: TxParams
4827
+ txParams?: TxParams,
4828
+ subAccountId?: number
4714
4829
  ): Promise<TransactionSignature> {
4715
4830
  const { txSig } = await this.sendTransaction(
4716
4831
  await this.buildTransaction(
4717
- await this.getModifyOrderByUserIdIx(orderParams),
4832
+ await this.getModifyOrderByUserIdIx(orderParams, subAccountId),
4718
4833
  txParams
4719
4834
  ),
4720
4835
  [],
@@ -4723,44 +4838,47 @@ export class DriftClient {
4723
4838
  return txSig;
4724
4839
  }
4725
4840
 
4726
- public async getModifyOrderByUserIdIx({
4727
- userOrderId,
4728
- newDirection,
4729
- newBaseAmount,
4730
- newLimitPrice,
4731
- newOraclePriceOffset,
4732
- newTriggerPrice,
4733
- newTriggerCondition,
4734
- auctionDuration,
4735
- auctionStartPrice,
4736
- auctionEndPrice,
4737
- reduceOnly,
4738
- postOnly,
4739
- immediateOrCancel,
4740
- maxTs,
4741
- policy,
4742
- }: {
4743
- userOrderId: number;
4744
- newDirection?: PositionDirection;
4745
- newBaseAmount?: BN;
4746
- newLimitPrice?: BN;
4747
- newOraclePriceOffset?: number;
4748
- newTriggerPrice?: BN;
4749
- newTriggerCondition?: OrderTriggerCondition;
4750
- auctionDuration?: number;
4751
- auctionStartPrice?: BN;
4752
- auctionEndPrice?: BN;
4753
- reduceOnly?: boolean;
4754
- postOnly?: boolean;
4755
- immediateOrCancel?: boolean;
4756
- policy?: ModifyOrderPolicy;
4757
- maxTs?: BN;
4758
- txParams?: TxParams;
4759
- }): Promise<TransactionInstruction> {
4760
- const userAccountPublicKey = await this.getUserAccountPublicKey();
4841
+ public async getModifyOrderByUserIdIx(
4842
+ {
4843
+ userOrderId,
4844
+ newDirection,
4845
+ newBaseAmount,
4846
+ newLimitPrice,
4847
+ newOraclePriceOffset,
4848
+ newTriggerPrice,
4849
+ newTriggerCondition,
4850
+ auctionDuration,
4851
+ auctionStartPrice,
4852
+ auctionEndPrice,
4853
+ reduceOnly,
4854
+ postOnly,
4855
+ immediateOrCancel,
4856
+ maxTs,
4857
+ policy,
4858
+ }: {
4859
+ userOrderId: number;
4860
+ newDirection?: PositionDirection;
4861
+ newBaseAmount?: BN;
4862
+ newLimitPrice?: BN;
4863
+ newOraclePriceOffset?: number;
4864
+ newTriggerPrice?: BN;
4865
+ newTriggerCondition?: OrderTriggerCondition;
4866
+ auctionDuration?: number;
4867
+ auctionStartPrice?: BN;
4868
+ auctionEndPrice?: BN;
4869
+ reduceOnly?: boolean;
4870
+ postOnly?: boolean;
4871
+ immediateOrCancel?: boolean;
4872
+ policy?: ModifyOrderPolicy;
4873
+ maxTs?: BN;
4874
+ txParams?: TxParams;
4875
+ },
4876
+ subAccountId?: number
4877
+ ): Promise<TransactionInstruction> {
4878
+ const user = await this.getUserAccountPublicKey(subAccountId);
4761
4879
 
4762
4880
  const remainingAccounts = this.getRemainingAccounts({
4763
- userAccounts: [this.getUserAccount()],
4881
+ userAccounts: [this.getUserAccount(subAccountId)],
4764
4882
  useMarketLastSlotCache: true,
4765
4883
  });
4766
4884
 
@@ -4787,7 +4905,7 @@ export class DriftClient {
4787
4905
  {
4788
4906
  accounts: {
4789
4907
  state: await this.getStatePublicKey(),
4790
- user: userAccountPublicKey,
4908
+ user,
4791
4909
  userStats: this.getUserStatsAccountPublicKey(),
4792
4910
  authority: this.wallet.publicKey,
4793
4911
  },
@@ -4883,7 +5001,8 @@ export class DriftClient {
4883
5001
  marketIndex: number,
4884
5002
  maxBaseAssetAmount: BN,
4885
5003
  limitPrice?: BN,
4886
- txParams?: TxParams
5004
+ txParams?: TxParams,
5005
+ liquidatorSubAccountId?: number
4887
5006
  ): Promise<TransactionSignature> {
4888
5007
  const { txSig, slot } = await this.sendTransaction(
4889
5008
  await this.buildTransaction(
@@ -4892,7 +5011,8 @@ export class DriftClient {
4892
5011
  userAccount,
4893
5012
  marketIndex,
4894
5013
  maxBaseAssetAmount,
4895
- limitPrice
5014
+ limitPrice,
5015
+ liquidatorSubAccountId
4896
5016
  ),
4897
5017
  txParams
4898
5018
  ),
@@ -4908,18 +5028,21 @@ export class DriftClient {
4908
5028
  userAccount: UserAccount,
4909
5029
  marketIndex: number,
4910
5030
  maxBaseAssetAmount: BN,
4911
- limitPrice?: BN
5031
+ limitPrice?: BN,
5032
+ liquidatorSubAccountId?: number
4912
5033
  ): Promise<TransactionInstruction> {
4913
5034
  const userStatsPublicKey = getUserStatsAccountPublicKey(
4914
5035
  this.program.programId,
4915
5036
  userAccount.authority
4916
5037
  );
4917
5038
 
4918
- const liquidatorPublicKey = await this.getUserAccountPublicKey();
5039
+ const liquidator = await this.getUserAccountPublicKey(
5040
+ liquidatorSubAccountId
5041
+ );
4919
5042
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
4920
5043
 
4921
5044
  const remainingAccounts = this.getRemainingAccounts({
4922
- userAccounts: [this.getUserAccount(), userAccount],
5045
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
4923
5046
  useMarketLastSlotCache: true,
4924
5047
  writablePerpMarketIndexes: [marketIndex],
4925
5048
  });
@@ -4934,7 +5057,7 @@ export class DriftClient {
4934
5057
  authority: this.wallet.publicKey,
4935
5058
  user: userAccountPublicKey,
4936
5059
  userStats: userStatsPublicKey,
4937
- liquidator: liquidatorPublicKey,
5060
+ liquidator,
4938
5061
  liquidatorStats: liquidatorStatsPublicKey,
4939
5062
  },
4940
5063
  remainingAccounts: remainingAccounts,
@@ -4949,7 +5072,8 @@ export class DriftClient {
4949
5072
  liabilityMarketIndex: number,
4950
5073
  maxLiabilityTransfer: BN,
4951
5074
  limitPrice?: BN,
4952
- txParams?: TxParams
5075
+ txParams?: TxParams,
5076
+ liquidatorSubAccountId?: number
4953
5077
  ): Promise<TransactionSignature> {
4954
5078
  const { txSig, slot } = await this.sendTransaction(
4955
5079
  await this.buildTransaction(
@@ -4959,7 +5083,8 @@ export class DriftClient {
4959
5083
  assetMarketIndex,
4960
5084
  liabilityMarketIndex,
4961
5085
  maxLiabilityTransfer,
4962
- limitPrice
5086
+ limitPrice,
5087
+ liquidatorSubAccountId
4963
5088
  ),
4964
5089
  txParams
4965
5090
  ),
@@ -4977,18 +5102,21 @@ export class DriftClient {
4977
5102
  assetMarketIndex: number,
4978
5103
  liabilityMarketIndex: number,
4979
5104
  maxLiabilityTransfer: BN,
4980
- limitPrice?: BN
5105
+ limitPrice?: BN,
5106
+ liquidatorSubAccountId?: number
4981
5107
  ): Promise<TransactionInstruction> {
4982
5108
  const userStatsPublicKey = getUserStatsAccountPublicKey(
4983
5109
  this.program.programId,
4984
5110
  userAccount.authority
4985
5111
  );
4986
5112
 
4987
- const liquidatorPublicKey = await this.getUserAccountPublicKey();
4988
- const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
5113
+ const liquidator = await this.getUserAccountPublicKey(
5114
+ liquidatorSubAccountId
5115
+ );
5116
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
4989
5117
 
4990
5118
  const remainingAccounts = this.getRemainingAccounts({
4991
- userAccounts: [this.getUserAccount(), userAccount],
5119
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
4992
5120
  useMarketLastSlotCache: true,
4993
5121
  writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
4994
5122
  });
@@ -5004,7 +5132,7 @@ export class DriftClient {
5004
5132
  authority: this.wallet.publicKey,
5005
5133
  user: userAccountPublicKey,
5006
5134
  userStats: userStatsPublicKey,
5007
- liquidator: liquidatorPublicKey,
5135
+ liquidator,
5008
5136
  liquidatorStats: liquidatorStatsPublicKey,
5009
5137
  },
5010
5138
  remainingAccounts: remainingAccounts,
@@ -5019,7 +5147,8 @@ export class DriftClient {
5019
5147
  liabilityMarketIndex: number,
5020
5148
  maxLiabilityTransfer: BN,
5021
5149
  limitPrice?: BN,
5022
- txParams?: TxParams
5150
+ txParams?: TxParams,
5151
+ liquidatorSubAccountId?: number
5023
5152
  ): Promise<TransactionSignature> {
5024
5153
  const { txSig, slot } = await this.sendTransaction(
5025
5154
  await this.buildTransaction(
@@ -5029,7 +5158,8 @@ export class DriftClient {
5029
5158
  perpMarketIndex,
5030
5159
  liabilityMarketIndex,
5031
5160
  maxLiabilityTransfer,
5032
- limitPrice
5161
+ limitPrice,
5162
+ liquidatorSubAccountId
5033
5163
  ),
5034
5164
  txParams
5035
5165
  ),
@@ -5047,18 +5177,21 @@ export class DriftClient {
5047
5177
  perpMarketIndex: number,
5048
5178
  liabilityMarketIndex: number,
5049
5179
  maxLiabilityTransfer: BN,
5050
- limitPrice?: BN
5180
+ limitPrice?: BN,
5181
+ liquidatorSubAccountId?: number
5051
5182
  ): Promise<TransactionInstruction> {
5052
5183
  const userStatsPublicKey = getUserStatsAccountPublicKey(
5053
5184
  this.program.programId,
5054
5185
  userAccount.authority
5055
5186
  );
5056
5187
 
5057
- const liquidatorPublicKey = await this.getUserAccountPublicKey();
5058
- const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
5188
+ const liquidator = await this.getUserAccountPublicKey(
5189
+ liquidatorSubAccountId
5190
+ );
5191
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5059
5192
 
5060
5193
  const remainingAccounts = this.getRemainingAccounts({
5061
- userAccounts: [this.getUserAccount(), userAccount],
5194
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5062
5195
  writablePerpMarketIndexes: [perpMarketIndex],
5063
5196
  writableSpotMarketIndexes: [liabilityMarketIndex],
5064
5197
  });
@@ -5074,7 +5207,7 @@ export class DriftClient {
5074
5207
  authority: this.wallet.publicKey,
5075
5208
  user: userAccountPublicKey,
5076
5209
  userStats: userStatsPublicKey,
5077
- liquidator: liquidatorPublicKey,
5210
+ liquidator,
5078
5211
  liquidatorStats: liquidatorStatsPublicKey,
5079
5212
  },
5080
5213
  remainingAccounts: remainingAccounts,
@@ -5089,7 +5222,8 @@ export class DriftClient {
5089
5222
  assetMarketIndex: number,
5090
5223
  maxPnlTransfer: BN,
5091
5224
  limitPrice?: BN,
5092
- txParams?: TxParams
5225
+ txParams?: TxParams,
5226
+ liquidatorSubAccountId?: number
5093
5227
  ): Promise<TransactionSignature> {
5094
5228
  const { txSig, slot } = await this.sendTransaction(
5095
5229
  await this.buildTransaction(
@@ -5099,7 +5233,8 @@ export class DriftClient {
5099
5233
  perpMarketIndex,
5100
5234
  assetMarketIndex,
5101
5235
  maxPnlTransfer,
5102
- limitPrice
5236
+ limitPrice,
5237
+ liquidatorSubAccountId
5103
5238
  ),
5104
5239
  txParams
5105
5240
  ),
@@ -5117,18 +5252,21 @@ export class DriftClient {
5117
5252
  perpMarketIndex: number,
5118
5253
  assetMarketIndex: number,
5119
5254
  maxPnlTransfer: BN,
5120
- limitPrice?: BN
5255
+ limitPrice?: BN,
5256
+ liquidatorSubAccountId?: number
5121
5257
  ): Promise<TransactionInstruction> {
5122
5258
  const userStatsPublicKey = getUserStatsAccountPublicKey(
5123
5259
  this.program.programId,
5124
5260
  userAccount.authority
5125
5261
  );
5126
5262
 
5127
- const liquidatorPublicKey = await this.getUserAccountPublicKey();
5128
- const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
5263
+ const liquidator = await this.getUserAccountPublicKey(
5264
+ liquidatorSubAccountId
5265
+ );
5266
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5129
5267
 
5130
5268
  const remainingAccounts = this.getRemainingAccounts({
5131
- userAccounts: [this.getUserAccount(), userAccount],
5269
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5132
5270
  writablePerpMarketIndexes: [perpMarketIndex],
5133
5271
  writableSpotMarketIndexes: [assetMarketIndex],
5134
5272
  });
@@ -5144,7 +5282,7 @@ export class DriftClient {
5144
5282
  authority: this.wallet.publicKey,
5145
5283
  user: userAccountPublicKey,
5146
5284
  userStats: userStatsPublicKey,
5147
- liquidator: liquidatorPublicKey,
5285
+ liquidator,
5148
5286
  liquidatorStats: liquidatorStatsPublicKey,
5149
5287
  },
5150
5288
  remainingAccounts: remainingAccounts,
@@ -5156,14 +5294,16 @@ export class DriftClient {
5156
5294
  userAccountPublicKey: PublicKey,
5157
5295
  userAccount: UserAccount,
5158
5296
  marketIndex: number,
5159
- txParams?: TxParams
5297
+ txParams?: TxParams,
5298
+ liquidatorSubAccountId?: number
5160
5299
  ): Promise<TransactionSignature> {
5161
5300
  const { txSig } = await this.sendTransaction(
5162
5301
  await this.buildTransaction(
5163
5302
  await this.getResolvePerpBankruptcyIx(
5164
5303
  userAccountPublicKey,
5165
5304
  userAccount,
5166
- marketIndex
5305
+ marketIndex,
5306
+ liquidatorSubAccountId
5167
5307
  ),
5168
5308
  txParams
5169
5309
  ),
@@ -5176,18 +5316,21 @@ export class DriftClient {
5176
5316
  public async getResolvePerpBankruptcyIx(
5177
5317
  userAccountPublicKey: PublicKey,
5178
5318
  userAccount: UserAccount,
5179
- marketIndex: number
5319
+ marketIndex: number,
5320
+ liquidatorSubAccountId?: number
5180
5321
  ): Promise<TransactionInstruction> {
5181
5322
  const userStatsPublicKey = getUserStatsAccountPublicKey(
5182
5323
  this.program.programId,
5183
5324
  userAccount.authority
5184
5325
  );
5185
5326
 
5186
- const liquidatorPublicKey = await this.getUserAccountPublicKey();
5187
- const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
5327
+ const liquidator = await this.getUserAccountPublicKey(
5328
+ liquidatorSubAccountId
5329
+ );
5330
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5188
5331
 
5189
5332
  const remainingAccounts = this.getRemainingAccounts({
5190
- userAccounts: [this.getUserAccount(), userAccount],
5333
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5191
5334
  writablePerpMarketIndexes: [marketIndex],
5192
5335
  writableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
5193
5336
  });
@@ -5203,7 +5346,7 @@ export class DriftClient {
5203
5346
  authority: this.wallet.publicKey,
5204
5347
  user: userAccountPublicKey,
5205
5348
  userStats: userStatsPublicKey,
5206
- liquidator: liquidatorPublicKey,
5349
+ liquidator,
5207
5350
  liquidatorStats: liquidatorStatsPublicKey,
5208
5351
  spotMarketVault: spotMarket.vault,
5209
5352
  insuranceFundVault: spotMarket.insuranceFund.vault,
@@ -5219,14 +5362,16 @@ export class DriftClient {
5219
5362
  userAccountPublicKey: PublicKey,
5220
5363
  userAccount: UserAccount,
5221
5364
  marketIndex: number,
5222
- txParams?: TxParams
5365
+ txParams?: TxParams,
5366
+ liquidatorSubAccountId?: number
5223
5367
  ): Promise<TransactionSignature> {
5224
5368
  const { txSig } = await this.sendTransaction(
5225
5369
  await this.buildTransaction(
5226
5370
  await this.getResolveSpotBankruptcyIx(
5227
5371
  userAccountPublicKey,
5228
5372
  userAccount,
5229
- marketIndex
5373
+ marketIndex,
5374
+ liquidatorSubAccountId
5230
5375
  ),
5231
5376
  txParams
5232
5377
  ),
@@ -5239,18 +5384,21 @@ export class DriftClient {
5239
5384
  public async getResolveSpotBankruptcyIx(
5240
5385
  userAccountPublicKey: PublicKey,
5241
5386
  userAccount: UserAccount,
5242
- marketIndex: number
5387
+ marketIndex: number,
5388
+ liquidatorSubAccountId?: number
5243
5389
  ): Promise<TransactionInstruction> {
5244
5390
  const userStatsPublicKey = getUserStatsAccountPublicKey(
5245
5391
  this.program.programId,
5246
5392
  userAccount.authority
5247
5393
  );
5248
5394
 
5249
- const liquidatorPublicKey = await this.getUserAccountPublicKey();
5250
- const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
5395
+ const liquidator = await this.getUserAccountPublicKey(
5396
+ liquidatorSubAccountId
5397
+ );
5398
+ const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5251
5399
 
5252
5400
  const remainingAccounts = this.getRemainingAccounts({
5253
- userAccounts: [this.getUserAccount(), userAccount],
5401
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5254
5402
  writableSpotMarketIndexes: [marketIndex],
5255
5403
  });
5256
5404
 
@@ -5263,7 +5411,7 @@ export class DriftClient {
5263
5411
  user: userAccountPublicKey,
5264
5412
  userStats: userStatsPublicKey,
5265
5413
  liquidatorStats: liquidatorStatsPublicKey,
5266
- liquidator: liquidatorPublicKey,
5414
+ liquidator,
5267
5415
  spotMarketVault: spotMarket.vault,
5268
5416
  insuranceFundVault: spotMarket.insuranceFund.vault,
5269
5417
  driftSigner: this.getSignerPublicKey(),