@drift-labs/sdk 2.31.1-beta.21 → 2.31.1-beta.23

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.31.1-beta.21
1
+ 2.31.1-beta.23
@@ -273,7 +273,6 @@ export declare class DriftClient {
273
273
  signedFillTx: Transaction;
274
274
  }>;
275
275
  placePerpOrder(orderParams: OptionalOrderParams, txParams?: TxParams): Promise<TransactionSignature>;
276
- getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
277
276
  getPlacePerpOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
278
277
  updateAMMs(marketIndexes: number[], txParams?: TxParams): Promise<TransactionSignature>;
279
278
  getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
@@ -53,6 +53,7 @@ const fetch_1 = require("./accounts/fetch");
53
53
  const spotMarket_1 = require("./math/spotMarket");
54
54
  const memcmp_1 = require("./memcmp");
55
55
  const marinade_1 = require("./marinade");
56
+ const orderParams_1 = require("./orderParams");
56
57
  /**
57
58
  * # DriftClient
58
59
  * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
@@ -1393,13 +1394,8 @@ class DriftClient {
1393
1394
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
1394
1395
  return txSig;
1395
1396
  }
1396
- getOrderParams(optionalOrderParams, marketType) {
1397
- return Object.assign({}, types_1.DefaultOrderParams, optionalOrderParams, {
1398
- marketType,
1399
- });
1400
- }
1401
1397
  async getPlacePerpOrderIx(orderParams) {
1402
- orderParams = this.getOrderParams(orderParams, types_1.MarketType.PERP);
1398
+ orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
1403
1399
  const userAccountPublicKey = await this.getUserAccountPublicKey();
1404
1400
  const remainingAccounts = this.getRemainingAccounts({
1405
1401
  userAccounts: [this.getUserAccount()],
@@ -1589,6 +1585,9 @@ class DriftClient {
1589
1585
  const readablePerpMarketIndex = [];
1590
1586
  const readableSpotMarketIndexes = [];
1591
1587
  for (const param of params) {
1588
+ if (!param.marketType) {
1589
+ throw new Error('must set param.marketType');
1590
+ }
1592
1591
  if ((0, types_1.isVariant)(param.marketType, 'perp')) {
1593
1592
  readablePerpMarketIndex.push(param.marketIndex);
1594
1593
  }
@@ -1696,7 +1695,7 @@ class DriftClient {
1696
1695
  return txSig;
1697
1696
  }
1698
1697
  async getPlaceSpotOrderIx(orderParams) {
1699
- orderParams = this.getOrderParams(orderParams, types_1.MarketType.SPOT);
1698
+ orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
1700
1699
  const userAccountPublicKey = await this.getUserAccountPublicKey();
1701
1700
  const remainingAccounts = this.getRemainingAccounts({
1702
1701
  userAccounts: [this.getUserAccount()],
@@ -2209,7 +2208,7 @@ class DriftClient {
2209
2208
  return txSig;
2210
2209
  }
2211
2210
  async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo) {
2212
- orderParams = this.getOrderParams(orderParams, types_1.MarketType.PERP);
2211
+ orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
2213
2212
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
2214
2213
  const userAccountPublicKey = await this.getUserAccountPublicKey();
2215
2214
  makerInfo = Array.isArray(makerInfo)
@@ -2270,7 +2269,7 @@ class DriftClient {
2270
2269
  return txSig;
2271
2270
  }
2272
2271
  async getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo) {
2273
- orderParams = this.getOrderParams(orderParams, types_1.MarketType.PERP);
2272
+ orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
2274
2273
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
2275
2274
  const userAccountPublicKey = await this.getUserAccountPublicKey();
2276
2275
  const remainingAccounts = this.getRemainingAccounts({
@@ -2310,7 +2309,7 @@ class DriftClient {
2310
2309
  return txSig;
2311
2310
  }
2312
2311
  async getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo) {
2313
- orderParams = this.getOrderParams(orderParams, types_1.MarketType.SPOT);
2312
+ orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
2314
2313
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
2315
2314
  const userAccountPublicKey = await this.getUserAccountPublicKey();
2316
2315
  const userAccounts = [this.getUserAccount()];
@@ -2369,7 +2368,7 @@ class DriftClient {
2369
2368
  return txSig;
2370
2369
  }
2371
2370
  async getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo) {
2372
- orderParams = this.getOrderParams(orderParams, types_1.MarketType.SPOT);
2371
+ orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
2373
2372
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
2374
2373
  const userAccountPublicKey = await this.getUserAccountPublicKey();
2375
2374
  const remainingAccounts = this.getRemainingAccounts({
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.20",
2
+ "version": "2.31.1-beta.22",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -1,15 +1,28 @@
1
- import { OptionalOrderParams, OrderTriggerCondition } from './types';
1
+ import { OptionalOrderParams, OrderParams, OrderTriggerCondition } from './types';
2
2
  import { BN } from '@coral-xyz/anchor';
3
- export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
3
+ export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType'> & {
4
4
  price: BN;
5
5
  }): OptionalOrderParams;
6
- export declare function getTriggerMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
6
+ export declare function getTriggerMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType'> & {
7
7
  triggerCondition: OrderTriggerCondition;
8
8
  triggerPrice: BN;
9
9
  }): OptionalOrderParams;
10
- export declare function getTriggerLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
10
+ export declare function getTriggerLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType'> & {
11
11
  triggerCondition: OrderTriggerCondition;
12
12
  triggerPrice: BN;
13
13
  price: BN;
14
14
  }): OptionalOrderParams;
15
- export declare function getMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'>): OptionalOrderParams;
15
+ export declare function getMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType'>): OptionalOrderParams;
16
+ /**
17
+ * Creates an OrderParams object with the given OptionalOrderParams and any params to override.
18
+ *
19
+ * example:
20
+ * ```
21
+ * const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
22
+ * ```
23
+ *
24
+ * @param optionalOrderParams
25
+ * @param overridingParams
26
+ * @returns
27
+ */
28
+ export declare function getOrderParams(optionalOrderParams: OptionalOrderParams, overridingParams?: Record<string, any>): OrderParams;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMarketOrderParams = exports.getTriggerLimitOrderParams = exports.getTriggerMarketOrderParams = exports.getLimitOrderParams = void 0;
3
+ exports.getOrderParams = exports.getMarketOrderParams = exports.getTriggerLimitOrderParams = exports.getTriggerMarketOrderParams = exports.getLimitOrderParams = void 0;
4
4
  const types_1 = require("./types");
5
5
  function getLimitOrderParams(params) {
6
6
  return Object.assign({}, params, {
@@ -26,3 +26,19 @@ function getMarketOrderParams(params) {
26
26
  });
27
27
  }
28
28
  exports.getMarketOrderParams = getMarketOrderParams;
29
+ /**
30
+ * Creates an OrderParams object with the given OptionalOrderParams and any params to override.
31
+ *
32
+ * example:
33
+ * ```
34
+ * const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
35
+ * ```
36
+ *
37
+ * @param optionalOrderParams
38
+ * @param overridingParams
39
+ * @returns
40
+ */
41
+ function getOrderParams(optionalOrderParams, overridingParams = {}) {
42
+ return Object.assign({}, types_1.DefaultOrderParams, optionalOrderParams, overridingParams);
43
+ }
44
+ exports.getOrderParams = getOrderParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.31.1-beta.21",
3
+ "version": "2.31.1-beta.23",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -27,7 +27,6 @@ import {
27
27
  MakerInfo,
28
28
  TakerInfo,
29
29
  OptionalOrderParams,
30
- DefaultOrderParams,
31
30
  OrderType,
32
31
  ReferrerInfo,
33
32
  MarketType,
@@ -118,6 +117,7 @@ import { JupiterClient, Route, SwapMode } from './jupiter/jupiterClient';
118
117
  import { getNonIdleUserFilter } from './memcmp';
119
118
  import { UserStatsSubscriptionConfig } from './userStatsConfig';
120
119
  import { getMarinadeDepositIx, getMarinadeFinanceProgram } from './marinade';
120
+ import { getOrderParams } from './orderParams';
121
121
 
122
122
  type RemainingAccountParams = {
123
123
  userAccounts: UserAccount[];
@@ -2522,19 +2522,10 @@ export class DriftClient {
2522
2522
  return txSig;
2523
2523
  }
2524
2524
 
2525
- getOrderParams(
2526
- optionalOrderParams: OptionalOrderParams,
2527
- marketType: MarketType
2528
- ): OrderParams {
2529
- return Object.assign({}, DefaultOrderParams, optionalOrderParams, {
2530
- marketType,
2531
- });
2532
- }
2533
-
2534
2525
  public async getPlacePerpOrderIx(
2535
2526
  orderParams: OptionalOrderParams
2536
2527
  ): Promise<TransactionInstruction> {
2537
- orderParams = this.getOrderParams(orderParams, MarketType.PERP);
2528
+ orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
2538
2529
  const userAccountPublicKey = await this.getUserAccountPublicKey();
2539
2530
 
2540
2531
  const remainingAccounts = this.getRemainingAccounts({
@@ -2863,6 +2854,9 @@ export class DriftClient {
2863
2854
  const readablePerpMarketIndex: number[] = [];
2864
2855
  const readableSpotMarketIndexes: number[] = [];
2865
2856
  for (const param of params) {
2857
+ if (!param.marketType) {
2858
+ throw new Error('must set param.marketType');
2859
+ }
2866
2860
  if (isVariant(param.marketType, 'perp')) {
2867
2861
  readablePerpMarketIndex.push(param.marketIndex);
2868
2862
  } else {
@@ -3028,7 +3022,7 @@ export class DriftClient {
3028
3022
  public async getPlaceSpotOrderIx(
3029
3023
  orderParams: OptionalOrderParams
3030
3024
  ): Promise<TransactionInstruction> {
3031
- orderParams = this.getOrderParams(orderParams, MarketType.SPOT);
3025
+ orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
3032
3026
  const userAccountPublicKey = await this.getUserAccountPublicKey();
3033
3027
 
3034
3028
  const remainingAccounts = this.getRemainingAccounts({
@@ -3888,7 +3882,7 @@ export class DriftClient {
3888
3882
  makerInfo?: MakerInfo | MakerInfo[],
3889
3883
  referrerInfo?: ReferrerInfo
3890
3884
  ): Promise<TransactionInstruction> {
3891
- orderParams = this.getOrderParams(orderParams, MarketType.PERP);
3885
+ orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
3892
3886
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
3893
3887
  const userAccountPublicKey = await this.getUserAccountPublicKey();
3894
3888
 
@@ -3984,7 +3978,7 @@ export class DriftClient {
3984
3978
  takerInfo: TakerInfo,
3985
3979
  referrerInfo?: ReferrerInfo
3986
3980
  ): Promise<TransactionInstruction> {
3987
- orderParams = this.getOrderParams(orderParams, MarketType.PERP);
3981
+ orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
3988
3982
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
3989
3983
  const userAccountPublicKey = await this.getUserAccountPublicKey();
3990
3984
 
@@ -4056,7 +4050,7 @@ export class DriftClient {
4056
4050
  makerInfo?: MakerInfo,
4057
4051
  referrerInfo?: ReferrerInfo
4058
4052
  ): Promise<TransactionInstruction> {
4059
- orderParams = this.getOrderParams(orderParams, MarketType.SPOT);
4053
+ orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
4060
4054
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
4061
4055
  const userAccountPublicKey = await this.getUserAccountPublicKey();
4062
4056
 
@@ -4154,7 +4148,7 @@ export class DriftClient {
4154
4148
  fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
4155
4149
  referrerInfo?: ReferrerInfo
4156
4150
  ): Promise<TransactionInstruction> {
4157
- orderParams = this.getOrderParams(orderParams, MarketType.SPOT);
4151
+ orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
4158
4152
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
4159
4153
  const userAccountPublicKey = await this.getUserAccountPublicKey();
4160
4154
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.21",
2
+ "version": "2.31.1-beta.23",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -1,8 +1,14 @@
1
- import { OptionalOrderParams, OrderTriggerCondition, OrderType } from './types';
1
+ import {
2
+ DefaultOrderParams,
3
+ OptionalOrderParams,
4
+ OrderParams,
5
+ OrderTriggerCondition,
6
+ OrderType,
7
+ } from './types';
2
8
  import { BN } from '@coral-xyz/anchor';
3
9
 
4
10
  export function getLimitOrderParams(
5
- params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & { price: BN }
11
+ params: Omit<OptionalOrderParams, 'orderType'> & { price: BN }
6
12
  ): OptionalOrderParams {
7
13
  return Object.assign({}, params, {
8
14
  orderType: OrderType.LIMIT,
@@ -10,7 +16,7 @@ export function getLimitOrderParams(
10
16
  }
11
17
 
12
18
  export function getTriggerMarketOrderParams(
13
- params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
19
+ params: Omit<OptionalOrderParams, 'orderType'> & {
14
20
  triggerCondition: OrderTriggerCondition;
15
21
  triggerPrice: BN;
16
22
  }
@@ -21,7 +27,7 @@ export function getTriggerMarketOrderParams(
21
27
  }
22
28
 
23
29
  export function getTriggerLimitOrderParams(
24
- params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
30
+ params: Omit<OptionalOrderParams, 'orderType'> & {
25
31
  triggerCondition: OrderTriggerCondition;
26
32
  triggerPrice: BN;
27
33
  price: BN;
@@ -33,9 +39,33 @@ export function getTriggerLimitOrderParams(
33
39
  }
34
40
 
35
41
  export function getMarketOrderParams(
36
- params: Omit<OptionalOrderParams, 'orderType' | 'marketType'>
42
+ params: Omit<OptionalOrderParams, 'orderType'>
37
43
  ): OptionalOrderParams {
38
44
  return Object.assign({}, params, {
39
45
  orderType: OrderType.MARKET,
40
46
  });
41
47
  }
48
+
49
+ /**
50
+ * Creates an OrderParams object with the given OptionalOrderParams and any params to override.
51
+ *
52
+ * example:
53
+ * ```
54
+ * const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
55
+ * ```
56
+ *
57
+ * @param optionalOrderParams
58
+ * @param overridingParams
59
+ * @returns
60
+ */
61
+ export function getOrderParams(
62
+ optionalOrderParams: OptionalOrderParams,
63
+ overridingParams: Record<string, any> = {}
64
+ ): OrderParams {
65
+ return Object.assign(
66
+ {},
67
+ DefaultOrderParams,
68
+ optionalOrderParams,
69
+ overridingParams
70
+ );
71
+ }