@drift-labs/sdk 0.1.18-orders.5 → 0.1.18-orders.6

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.
@@ -50,6 +50,11 @@ export declare class ClearingHouseUser {
50
50
  * @returns Order
51
51
  */
52
52
  getOrder(orderId: BN): Order | undefined;
53
+ /**
54
+ * @param userOrderId
55
+ * @returns Order
56
+ */
57
+ getOrderByUserOrderId(userOrderId: number): Order | undefined;
53
58
  getUserAccountPublicKey(): Promise<PublicKey>;
54
59
  getUserOrdersAccountPublicKey(): Promise<PublicKey>;
55
60
  exists(): Promise<boolean>;
@@ -100,6 +100,13 @@ class ClearingHouseUser {
100
100
  getOrder(orderId) {
101
101
  return this.getUserOrdersAccount().orders.find((order) => order.orderId.eq(orderId));
102
102
  }
103
+ /**
104
+ * @param userOrderId
105
+ * @returns Order
106
+ */
107
+ getOrderByUserOrderId(userOrderId) {
108
+ return this.getUserOrdersAccount().orders.find((order) => order.userOrderId === userOrderId);
109
+ }
103
110
  getUserAccountPublicKey() {
104
111
  return __awaiter(this, void 0, void 0, function* () {
105
112
  if (this.userAccountPublicKey) {
@@ -2,6 +2,7 @@
2
2
  import { BN } from '../';
3
3
  export declare const ZERO: BN;
4
4
  export declare const ONE: BN;
5
+ export declare const TWO: BN;
5
6
  export declare const TEN_THOUSAND: BN;
6
7
  export declare const BN_MAX: BN;
7
8
  export declare const MAX_LEVERAGE: BN;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.PARTIAL_LIQUIDATION_RATIO = exports.FULL_LIQUIDATION_RATIO = exports.MAX_LEVERAGE = exports.BN_MAX = exports.TEN_THOUSAND = exports.ONE = exports.ZERO = void 0;
3
+ exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.PARTIAL_LIQUIDATION_RATIO = exports.FULL_LIQUIDATION_RATIO = exports.MAX_LEVERAGE = exports.BN_MAX = exports.TEN_THOUSAND = exports.TWO = exports.ONE = exports.ZERO = void 0;
4
4
  const __1 = require("../");
5
5
  exports.ZERO = new __1.BN(0);
6
6
  exports.ONE = new __1.BN(1);
7
+ exports.TWO = new __1.BN(2);
7
8
  exports.TEN_THOUSAND = new __1.BN(10000);
8
9
  exports.BN_MAX = new __1.BN(Number.MAX_SAFE_INTEGER);
9
10
  exports.MAX_LEVERAGE = new __1.BN(5);
@@ -572,7 +572,7 @@
572
572
  },
573
573
  {
574
574
  "name": "markets",
575
- "isMut": true,
575
+ "isMut": false,
576
576
  "isSigner": false
577
577
  },
578
578
  {
@@ -628,7 +628,7 @@
628
628
  },
629
629
  {
630
630
  "name": "markets",
631
- "isMut": true,
631
+ "isMut": false,
632
632
  "isSigner": false
633
633
  },
634
634
  {
@@ -23,8 +23,9 @@ function isOrderRiskIncreasing(user, order) {
23
23
  return true;
24
24
  }
25
25
  // if order will flip position
26
- if (position.baseAssetAmount.abs().gt(order.baseAssetAmountFilled)) {
26
+ if (order.baseAssetAmountFilled.gt(position.baseAssetAmount.abs().mul(numericConstants_1.TWO))) {
27
27
  return true;
28
28
  }
29
+ return false;
29
30
  }
30
31
  exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
package/lib/types.d.ts CHANGED
@@ -356,6 +356,7 @@ export declare type Order = {
356
356
  referrer: PublicKey;
357
357
  postOnly: boolean;
358
358
  immediateOrCancel: boolean;
359
+ oraclePriceOffset: BN;
359
360
  };
360
361
  export declare type OrderParams = {
361
362
  orderType: OrderType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.18-orders.5",
3
+ "version": "0.1.18-orders.6",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -155,6 +155,16 @@ export class ClearingHouseUser {
155
155
  );
156
156
  }
157
157
 
158
+ /**
159
+ * @param userOrderId
160
+ * @returns Order
161
+ */
162
+ public getOrderByUserOrderId(userOrderId: number): Order | undefined {
163
+ return this.getUserOrdersAccount().orders.find(
164
+ (order) => order.userOrderId === userOrderId
165
+ );
166
+ }
167
+
158
168
  public async getUserAccountPublicKey(): Promise<PublicKey> {
159
169
  if (this.userAccountPublicKey) {
160
170
  return this.userAccountPublicKey;
@@ -2,6 +2,7 @@ import { BN } from '../';
2
2
 
3
3
  export const ZERO = new BN(0);
4
4
  export const ONE = new BN(1);
5
+ export const TWO = new BN(2);
5
6
  export const TEN_THOUSAND = new BN(10000);
6
7
  export const BN_MAX = new BN(Number.MAX_SAFE_INTEGER);
7
8
 
@@ -572,7 +572,7 @@
572
572
  },
573
573
  {
574
574
  "name": "markets",
575
- "isMut": true,
575
+ "isMut": false,
576
576
  "isSigner": false
577
577
  },
578
578
  {
@@ -628,7 +628,7 @@
628
628
  },
629
629
  {
630
630
  "name": "markets",
631
- "isMut": true,
631
+ "isMut": false,
632
632
  "isSigner": false
633
633
  },
634
634
  {
@@ -1,6 +1,6 @@
1
1
  import { ClearingHouseUser } from '../clearingHouseUser';
2
2
  import { isVariant, Order } from '../types';
3
- import { ZERO } from '../constants/numericConstants';
3
+ import { ZERO, TWO } from '../constants/numericConstants';
4
4
 
5
5
  export function isOrderRiskIncreasing(
6
6
  user: ClearingHouseUser,
@@ -33,7 +33,9 @@ export function isOrderRiskIncreasing(
33
33
  }
34
34
 
35
35
  // if order will flip position
36
- if (position.baseAssetAmount.abs().gt(order.baseAssetAmountFilled)) {
36
+ if (order.baseAssetAmountFilled.gt(position.baseAssetAmount.abs().mul(TWO))) {
37
37
  return true;
38
38
  }
39
+
40
+ return false;
39
41
  }
package/src/types.ts CHANGED
@@ -359,6 +359,7 @@ export type Order = {
359
359
  referrer: PublicKey;
360
360
  postOnly: boolean;
361
361
  immediateOrCancel: boolean;
362
+ oraclePriceOffset: BN;
362
363
  };
363
364
 
364
365
  export type OrderParams = {