@drift-labs/sdk 0.1.18-orders.0 → 0.1.18-orders.4

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.
Files changed (93) hide show
  1. package/README.md +2 -1
  2. package/lib/accounts/bulkAccountLoader.d.ts +31 -0
  3. package/lib/accounts/bulkAccountLoader.js +175 -0
  4. package/lib/accounts/bulkUserSubscription.d.ts +7 -0
  5. package/lib/accounts/bulkUserSubscription.js +28 -0
  6. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +49 -0
  7. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +228 -0
  8. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +25 -0
  9. package/lib/accounts/pollingTokenAccountSubscriber.js +79 -0
  10. package/lib/accounts/pollingUserAccountSubscriber.d.ts +32 -0
  11. package/lib/accounts/pollingUserAccountSubscriber.js +133 -0
  12. package/lib/accounts/types.d.ts +34 -25
  13. package/lib/accounts/utils.d.ts +1 -0
  14. package/lib/accounts/utils.js +7 -0
  15. package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -2
  16. package/lib/accounts/webSocketAccountSubscriber.js +43 -12
  17. package/lib/accounts/{defaultClearingHouseAccountSubscriber.d.ts → webSocketClearingHouseAccountSubscriber.d.ts} +6 -4
  18. package/lib/accounts/{defaultClearingHouseAccountSubscriber.js → webSocketClearingHouseAccountSubscriber.js} +5 -4
  19. package/lib/accounts/{defaultUserAccountSubscriber.d.ts → webSocketUserAccountSubscriber.d.ts} +3 -1
  20. package/lib/accounts/{defaultUserAccountSubscriber.js → webSocketUserAccountSubscriber.js} +10 -7
  21. package/lib/addresses.d.ts +2 -2
  22. package/lib/addresses.js +4 -4
  23. package/lib/admin.d.ts +3 -0
  24. package/lib/admin.js +61 -13
  25. package/lib/clearingHouse.d.ts +20 -4
  26. package/lib/clearingHouse.js +90 -10
  27. package/lib/clearingHouseUser.d.ts +12 -4
  28. package/lib/clearingHouseUser.js +35 -25
  29. package/lib/config.js +1 -1
  30. package/lib/constants/markets.d.ts +2 -1
  31. package/lib/constants/markets.js +35 -14
  32. package/lib/constants/numericConstants.d.ts +3 -1
  33. package/lib/constants/numericConstants.js +15 -17
  34. package/lib/examples/makeTradeExample.js +1 -1
  35. package/lib/factory/clearingHouse.d.ts +25 -0
  36. package/lib/factory/clearingHouse.js +64 -0
  37. package/lib/factory/clearingHouseUser.d.ts +19 -0
  38. package/lib/factory/clearingHouseUser.js +34 -0
  39. package/lib/idl/clearing_house.json +366 -17
  40. package/lib/index.d.ts +9 -3
  41. package/lib/index.js +10 -3
  42. package/lib/math/conversion.d.ts +1 -1
  43. package/lib/math/funding.js +4 -1
  44. package/lib/math/insuranceFund.d.ts +2 -1
  45. package/lib/math/insuranceFund.js +3 -6
  46. package/lib/math/position.d.ts +2 -1
  47. package/lib/math/position.js +2 -5
  48. package/lib/math/utils.d.ts +2 -1
  49. package/lib/math/utils.js +3 -3
  50. package/lib/mockUSDCFaucet.d.ts +2 -1
  51. package/lib/orderParams.d.ts +3 -3
  52. package/lib/orderParams.js +28 -8
  53. package/lib/orders.d.ts +2 -1
  54. package/lib/token/index.d.ts +3 -0
  55. package/lib/token/index.js +38 -0
  56. package/lib/types.d.ts +20 -8
  57. package/lib/types.js +2 -2
  58. package/package.json +11 -3
  59. package/src/accounts/bulkAccountLoader.ts +215 -0
  60. package/src/accounts/bulkUserSubscription.ts +28 -0
  61. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +326 -0
  62. package/src/accounts/pollingTokenAccountSubscriber.ts +99 -0
  63. package/src/accounts/pollingUserAccountSubscriber.ts +186 -0
  64. package/src/accounts/types.ts +40 -30
  65. package/src/accounts/utils.ts +3 -0
  66. package/src/accounts/webSocketAccountSubscriber.ts +67 -17
  67. package/src/accounts/{defaultClearingHouseAccountSubscriber.ts → webSocketClearingHouseAccountSubscriber.ts} +9 -6
  68. package/src/accounts/{defaultUserAccountSubscriber.ts → webSocketUserAccountSubscriber.ts} +10 -5
  69. package/src/addresses.ts +6 -4
  70. package/src/admin.ts +73 -20
  71. package/src/clearingHouse.ts +125 -25
  72. package/src/clearingHouseUser.ts +28 -8
  73. package/src/config.ts +1 -1
  74. package/src/constants/markets.ts +25 -1
  75. package/src/constants/numericConstants.ts +2 -1
  76. package/src/examples/makeTradeExample.ts +4 -1
  77. package/src/factory/clearingHouse.ts +125 -0
  78. package/src/factory/clearingHouseUser.ts +73 -0
  79. package/src/idl/clearing_house.json +366 -17
  80. package/src/index.ts +9 -3
  81. package/src/math/conversion.ts +1 -1
  82. package/src/math/funding.ts +5 -1
  83. package/src/math/insuranceFund.ts +1 -1
  84. package/src/math/position.ts +1 -1
  85. package/src/math/utils.ts +1 -1
  86. package/src/mockUSDCFaucet.ts +1 -1
  87. package/src/orderParams.ts +30 -7
  88. package/src/orders.ts +1 -1
  89. package/src/token/index.ts +37 -0
  90. package/src/types.ts +17 -6
  91. package/lib/accounts/defaultHistoryAccountSubscriber.d.ts +0 -28
  92. package/lib/accounts/defaultHistoryAccountSubscriber.js +0 -110
  93. package/src/accounts/defaultHistoryAccountSubscriber.ts +0 -176
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
3
  import { BN, Program, Provider } from '@project-serum/anchor';
4
- import { MarketsAccount, StateAccount, CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, IWallet, LiquidationHistoryAccount, PositionDirection, TradeHistoryAccount, UserAccount, Market, OrderHistoryAccount, OrderStateAccount, OrderParams, Order } from './types';
4
+ import { MarketsAccount, StateAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, IWallet, LiquidationHistoryAccount, PositionDirection, TradeHistoryAccount, UserAccount, Market, OrderHistoryAccount, OrderStateAccount, OrderParams, Order, ExtendedCurveHistoryAccount } from './types';
5
5
  import { Connection, PublicKey, TransactionSignature, Keypair, ConfirmOptions, TransactionInstruction } from '@solana/web3.js';
6
6
  import { MockUSDCFaucet } from './mockUSDCFaucet';
7
7
  import { EventEmitter } from 'events';
@@ -12,7 +12,7 @@ import { TxSender } from './tx/types';
12
12
  * # ClearingHouse
13
13
  * 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.
14
14
  *
15
- * The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link DefaultClearingHouseAccountSubscriber}, which will use a websocket for each state account subscription.
15
+ * The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link WebSocketClearingHouseAccountSubscriber}, which will use a websocket for each state account subscription.
16
16
  * Alternatively, if you want to implement your own method of subscribing to the state accounts on the blockchain, you can implement a {@link ClearingHouseAccountSubscriber} and use it in the {@link ClearingHouse.constructor}
17
17
  */
18
18
  export declare class ClearingHouse {
@@ -23,8 +23,18 @@ export declare class ClearingHouse {
23
23
  opts?: ConfirmOptions;
24
24
  accountSubscriber: ClearingHouseAccountSubscriber;
25
25
  eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
26
- isSubscribed: boolean;
26
+ _isSubscribed: boolean;
27
27
  txSender: TxSender;
28
+ get isSubscribed(): boolean;
29
+ set isSubscribed(val: boolean);
30
+ /**
31
+ * @deprecated You should use the getClearingHouse factory method instead
32
+ * @param connection
33
+ * @param wallet
34
+ * @param clearingHouseProgramId
35
+ * @param opts
36
+ * @returns
37
+ */
28
38
  static from(connection: Connection, wallet: IWallet, clearingHouseProgramId: PublicKey, opts?: ConfirmOptions): ClearingHouse;
29
39
  constructor(connection: Connection, wallet: IWallet, program: Program, accountSubscriber: ClearingHouseAccountSubscriber, txSender: TxSender, opts: ConfirmOptions);
30
40
  /**
@@ -56,7 +66,7 @@ export declare class ClearingHouse {
56
66
  getTradeHistoryAccount(): TradeHistoryAccount;
57
67
  getLiquidationHistoryAccount(): LiquidationHistoryAccount;
58
68
  getDepositHistoryAccount(): DepositHistoryAccount;
59
- getCurveHistoryAccount(): CurveHistoryAccount;
69
+ getCurveHistoryAccount(): ExtendedCurveHistoryAccount;
60
70
  getOrderHistoryAccount(): OrderHistoryAccount;
61
71
  orderStatePublicKey?: PublicKey;
62
72
  getOrderStatePublicKey(): Promise<PublicKey>;
@@ -91,6 +101,8 @@ export declare class ClearingHouse {
91
101
  * @returns
92
102
  */
93
103
  getUserOrdersAccountPublicKey(): Promise<PublicKey>;
104
+ userOrdersExist?: boolean;
105
+ userOrdersAccountExists(): Promise<boolean>;
94
106
  depositCollateral(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionSignature>;
95
107
  getDepositCollateralInstruction(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
96
108
  /**
@@ -106,12 +118,16 @@ export declare class ClearingHouse {
106
118
  getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
107
119
  openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
108
120
  getOpenPositionIx(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
121
+ initializeUserOrdersThenPlaceOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
109
122
  placeOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
110
123
  getPlaceOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
111
124
  cancelOrder(orderId: BN): Promise<TransactionSignature>;
112
125
  getCancelOrderIx(orderId: BN): Promise<TransactionInstruction>;
126
+ cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
127
+ getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
113
128
  fillOrder(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionSignature>;
114
129
  getFillOrderIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionInstruction>;
130
+ initializeUserOrdersThenPlaceAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
115
131
  placeAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
116
132
  getPlaceAndFillOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
117
133
  /**
@@ -38,19 +38,19 @@ const anchor = __importStar(require("@project-serum/anchor"));
38
38
  const clearing_house_json_1 = __importDefault(require("./idl/clearing_house.json"));
39
39
  const web3_js_1 = require("@solana/web3.js");
40
40
  const addresses_1 = require("./addresses");
41
- const defaultClearingHouseAccountSubscriber_1 = require("./accounts/defaultClearingHouseAccountSubscriber");
42
41
  const defaultTxSender_1 = require("./tx/defaultTxSender");
43
42
  const utils_1 = require("./tx/utils");
43
+ const clearingHouse_1 = require("./factory/clearingHouse");
44
44
  /**
45
45
  * # ClearingHouse
46
46
  * 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.
47
47
  *
48
- * The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link DefaultClearingHouseAccountSubscriber}, which will use a websocket for each state account subscription.
48
+ * The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link WebSocketClearingHouseAccountSubscriber}, which will use a websocket for each state account subscription.
49
49
  * Alternatively, if you want to implement your own method of subscribing to the state accounts on the blockchain, you can implement a {@link ClearingHouseAccountSubscriber} and use it in the {@link ClearingHouse.constructor}
50
50
  */
51
51
  class ClearingHouse {
52
52
  constructor(connection, wallet, program, accountSubscriber, txSender, opts) {
53
- this.isSubscribed = false;
53
+ this._isSubscribed = false;
54
54
  this.connection = connection;
55
55
  this.wallet = wallet;
56
56
  this.opts = opts;
@@ -59,12 +59,23 @@ class ClearingHouse {
59
59
  this.eventEmitter = this.accountSubscriber.eventEmitter;
60
60
  this.txSender = txSender;
61
61
  }
62
+ get isSubscribed() {
63
+ return this._isSubscribed && this.accountSubscriber.isSubscribed;
64
+ }
65
+ set isSubscribed(val) {
66
+ this._isSubscribed = val;
67
+ }
68
+ /**
69
+ * @deprecated You should use the getClearingHouse factory method instead
70
+ * @param connection
71
+ * @param wallet
72
+ * @param clearingHouseProgramId
73
+ * @param opts
74
+ * @returns
75
+ */
62
76
  static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.Provider.defaultOptions()) {
63
- const provider = new anchor_1.Provider(connection, wallet, opts);
64
- const program = new anchor_1.Program(clearing_house_json_1.default, clearingHouseProgramId, provider);
65
- const accountSubscriber = new defaultClearingHouseAccountSubscriber_1.DefaultClearingHouseAccountSubscriber(program);
66
- const txSender = new defaultTxSender_1.DefaultTxSender(provider);
67
- return new ClearingHouse(connection, wallet, program, accountSubscriber, txSender, opts);
77
+ const config = clearingHouse_1.getWebSocketClearingHouseConfig(connection, wallet, clearingHouseProgramId, opts);
78
+ return clearingHouse_1.getClearingHouse(config);
68
79
  }
69
80
  /**
70
81
  *
@@ -230,10 +241,10 @@ class ClearingHouse {
230
241
  }
231
242
  getInitializeUserOrdersInstruction(userAccountPublicKey) {
232
243
  return __awaiter(this, void 0, void 0, function* () {
233
- const [userOrdersAccountPublicKey, userOrdersAccountNonce] = yield addresses_1.getUserOrdersAccountPublicKeyAndNonce(this.program.programId, this.wallet.publicKey);
234
244
  if (!userAccountPublicKey) {
235
245
  userAccountPublicKey = yield this.getUserAccountPublicKey();
236
246
  }
247
+ const [userOrdersAccountPublicKey, userOrdersAccountNonce] = yield addresses_1.getUserOrdersAccountPublicKeyAndNonce(this.program.programId, userAccountPublicKey);
237
248
  return yield this.program.instruction.initializeUserOrders(userOrdersAccountNonce, {
238
249
  accounts: {
239
250
  user: userAccountPublicKey,
@@ -277,10 +288,20 @@ class ClearingHouse {
277
288
  if (this.userOrdersAccountPublicKey) {
278
289
  return this.userOrdersAccountPublicKey;
279
290
  }
280
- this.userOrdersAccountPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, this.wallet.publicKey);
291
+ this.userOrdersAccountPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, yield this.getUserAccountPublicKey());
281
292
  return this.userOrdersAccountPublicKey;
282
293
  });
283
294
  }
295
+ userOrdersAccountExists() {
296
+ return __awaiter(this, void 0, void 0, function* () {
297
+ if (this.userOrdersExist) {
298
+ return this.userOrdersExist;
299
+ }
300
+ const userOrdersAccountRPCResponse = yield this.connection.getParsedAccountInfo(yield this.getUserOrdersAccountPublicKey());
301
+ this.userOrdersExist = userOrdersAccountRPCResponse.value !== null;
302
+ return this.userOrdersExist;
303
+ });
304
+ }
284
305
  depositCollateral(amount, collateralAccountPublicKey, userPositionsAccountPublicKey) {
285
306
  return __awaiter(this, void 0, void 0, function* () {
286
307
  const depositCollateralIx = yield this.getDepositCollateralInstruction(amount, collateralAccountPublicKey, userPositionsAccountPublicKey);
@@ -438,6 +459,21 @@ class ClearingHouse {
438
459
  });
439
460
  });
440
461
  }
462
+ initializeUserOrdersThenPlaceOrder(orderParams, discountToken, referrer) {
463
+ return __awaiter(this, void 0, void 0, function* () {
464
+ const instructions = [];
465
+ const userOrdersAccountExists = yield this.userOrdersAccountExists();
466
+ if (!userOrdersAccountExists) {
467
+ instructions.push(yield this.getInitializeUserOrdersInstruction());
468
+ }
469
+ instructions.push(yield this.getPlaceOrderIx(orderParams, discountToken, referrer));
470
+ const tx = new web3_js_1.Transaction();
471
+ for (const instruction of instructions) {
472
+ tx.add(instruction);
473
+ }
474
+ return yield this.txSender.send(tx, [], this.opts);
475
+ });
476
+ }
441
477
  placeOrder(orderParams, discountToken, referrer) {
442
478
  return __awaiter(this, void 0, void 0, function* () {
443
479
  return yield this.txSender.send(utils_1.wrapInTx(yield this.getPlaceOrderIx(orderParams, discountToken, referrer)), [], this.opts);
@@ -517,6 +553,33 @@ class ClearingHouse {
517
553
  });
518
554
  });
519
555
  }
556
+ cancelOrderByUserId(userOrderId) {
557
+ return __awaiter(this, void 0, void 0, function* () {
558
+ return yield this.txSender.send(utils_1.wrapInTx(yield this.getCancelOrderByUserIdIx(userOrderId)), [], this.opts);
559
+ });
560
+ }
561
+ getCancelOrderByUserIdIx(userOrderId) {
562
+ return __awaiter(this, void 0, void 0, function* () {
563
+ const userAccountPublicKey = yield this.getUserAccountPublicKey();
564
+ const userAccount = yield this.getUserAccount();
565
+ const state = this.getStateAccount();
566
+ const orderState = this.getOrderStateAccount();
567
+ return yield this.program.instruction.cancelOrderByUserId(userOrderId, {
568
+ accounts: {
569
+ state: yield this.getStatePublicKey(),
570
+ user: userAccountPublicKey,
571
+ authority: this.wallet.publicKey,
572
+ markets: state.markets,
573
+ userOrders: yield this.getUserOrdersAccountPublicKey(),
574
+ userPositions: userAccount.positions,
575
+ fundingPaymentHistory: state.fundingPaymentHistory,
576
+ fundingRateHistory: state.fundingRateHistory,
577
+ orderState: yield this.getOrderStatePublicKey(),
578
+ orderHistory: orderState.orderHistory,
579
+ },
580
+ });
581
+ });
582
+ }
520
583
  fillOrder(userAccountPublicKey, userOrdersAccountPublicKey, order) {
521
584
  return __awaiter(this, void 0, void 0, function* () {
522
585
  return yield this.txSender.send(utils_1.wrapInTx(yield this.getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order)), [], this.opts);
@@ -553,12 +616,28 @@ class ClearingHouse {
553
616
  fundingRateHistory: state.fundingRateHistory,
554
617
  orderState: yield this.getOrderStatePublicKey(),
555
618
  orderHistory: orderState.orderHistory,
619
+ extendedCurveHistory: state.extendedCurveHistory,
556
620
  oracle: oracle,
557
621
  },
558
622
  remainingAccounts,
559
623
  });
560
624
  });
561
625
  }
626
+ initializeUserOrdersThenPlaceAndFillOrder(orderParams, discountToken, referrer) {
627
+ return __awaiter(this, void 0, void 0, function* () {
628
+ const instructions = [];
629
+ const userOrdersAccountExists = yield this.userOrdersAccountExists();
630
+ if (!userOrdersAccountExists) {
631
+ instructions.push(yield this.getInitializeUserOrdersInstruction());
632
+ }
633
+ instructions.push(yield this.getPlaceAndFillOrderIx(orderParams, discountToken, referrer));
634
+ const tx = new web3_js_1.Transaction();
635
+ for (const instruction of instructions) {
636
+ tx.add(instruction);
637
+ }
638
+ return yield this.txSender.send(tx, [], this.opts);
639
+ });
640
+ }
562
641
  placeAndFillOrder(orderParams, discountToken, referrer) {
563
642
  return __awaiter(this, void 0, void 0, function* () {
564
643
  return yield this.txSender.send(utils_1.wrapInTx(yield this.getPlaceAndFillOrderIx(orderParams, discountToken, referrer)), [], this.opts);
@@ -606,6 +685,7 @@ class ClearingHouse {
606
685
  fundingRateHistory: state.fundingRateHistory,
607
686
  orderState: yield this.getOrderStatePublicKey(),
608
687
  orderHistory: orderState.orderHistory,
688
+ extendedCurveHistory: state.extendedCurveHistory,
609
689
  oracle: priceOracle,
610
690
  },
611
691
  remainingAccounts,
@@ -1,20 +1,28 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="bn.js" />
2
3
  import { PublicKey } from '@solana/web3.js';
3
- import BN from 'bn.js';
4
4
  import { EventEmitter } from 'events';
5
5
  import StrictEventEmitter from 'strict-event-emitter-types';
6
6
  import { ClearingHouse } from './clearingHouse';
7
7
  import { Order, UserAccount, UserOrdersAccount, UserPosition, UserPositionsAccount } from './types';
8
8
  import { UserAccountSubscriber, UserAccountEvents } from './accounts/types';
9
- import { PositionDirection } from '.';
9
+ import { PositionDirection, BN } from '.';
10
10
  export declare class ClearingHouseUser {
11
11
  clearingHouse: ClearingHouse;
12
12
  authority: PublicKey;
13
13
  accountSubscriber: UserAccountSubscriber;
14
14
  userAccountPublicKey?: PublicKey;
15
15
  userOrdersAccountPublicKey?: PublicKey;
16
- isSubscribed: boolean;
16
+ _isSubscribed: boolean;
17
17
  eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
18
+ get isSubscribed(): boolean;
19
+ set isSubscribed(val: boolean);
20
+ /**
21
+ * @deprecated You should use getClearingHouseUser factory method instead
22
+ * @param clearingHouse
23
+ * @param authority
24
+ * @returns
25
+ */
18
26
  static from(clearingHouse: ClearingHouse, authority: PublicKey): ClearingHouseUser;
19
27
  constructor(clearingHouse: ClearingHouse, authority: PublicKey, accountSubscriber: UserAccountSubscriber);
20
28
  /**
@@ -29,7 +37,7 @@ export declare class ClearingHouseUser {
29
37
  unsubscribe(): Promise<void>;
30
38
  getUserAccount(): UserAccount;
31
39
  getUserPositionsAccount(): UserPositionsAccount;
32
- getUserOrdersAccount(): UserOrdersAccount;
40
+ getUserOrdersAccount(): UserOrdersAccount | undefined;
33
41
  /**
34
42
  * Gets the user's current position for a given market. If the user has no position returns undefined
35
43
  * @param marketIndex
@@ -8,28 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.ClearingHouseUser = void 0;
16
- const bn_js_1 = __importDefault(require("bn.js"));
17
13
  const position_1 = require("./math/position");
18
14
  const numericConstants_1 = require("./constants/numericConstants");
19
- const defaultUserAccountSubscriber_1 = require("./accounts/defaultUserAccountSubscriber");
20
15
  const _1 = require(".");
21
16
  const addresses_1 = require("./addresses");
17
+ const clearingHouseUser_1 = require("./factory/clearingHouseUser");
22
18
  class ClearingHouseUser {
23
19
  constructor(clearingHouse, authority, accountSubscriber) {
24
- this.isSubscribed = false;
20
+ this._isSubscribed = false;
25
21
  this.clearingHouse = clearingHouse;
26
22
  this.authority = authority;
27
23
  this.accountSubscriber = accountSubscriber;
28
24
  this.eventEmitter = this.accountSubscriber.eventEmitter;
29
25
  }
26
+ get isSubscribed() {
27
+ return this._isSubscribed && this.accountSubscriber.isSubscribed;
28
+ }
29
+ set isSubscribed(val) {
30
+ this._isSubscribed = val;
31
+ }
32
+ /**
33
+ * @deprecated You should use getClearingHouseUser factory method instead
34
+ * @param clearingHouse
35
+ * @param authority
36
+ * @returns
37
+ */
30
38
  static from(clearingHouse, authority) {
31
- const accountSubscriber = new defaultUserAccountSubscriber_1.DefaultUserAccountSubscriber(clearingHouse.program, authority);
32
- return new ClearingHouseUser(clearingHouse, authority, accountSubscriber);
39
+ if (clearingHouse.accountSubscriber.type !== 'websocket')
40
+ throw 'This method only works for clearing houses with a websocket account listener. Try using the getClearingHouseUser factory method to initialize a ClearingHouseUser instead';
41
+ const config = clearingHouseUser_1.getWebSocketClearingHouseUserConfig(clearingHouse, authority);
42
+ return clearingHouseUser_1.getClearingHouseUser(config);
33
43
  }
34
44
  /**
35
45
  * Subscribe to ClearingHouseUser state accounts
@@ -104,7 +114,7 @@ class ClearingHouseUser {
104
114
  if (this.userOrdersAccountPublicKey) {
105
115
  return this.userOrdersAccountPublicKey;
106
116
  }
107
- this.userOrdersAccountPublicKey = yield _1.getUserOrdersAccountPublicKey(this.clearingHouse.program.programId, this.authority);
117
+ this.userOrdersAccountPublicKey = yield _1.getUserOrdersAccountPublicKey(this.clearingHouse.program.programId, yield this.getUserAccountPublicKey());
108
118
  return this.userOrdersAccountPublicKey;
109
119
  });
110
120
  }
@@ -163,7 +173,7 @@ class ClearingHouseUser {
163
173
  */
164
174
  getTotalCollateral() {
165
175
  var _a;
166
- return ((_a = this.getUserAccount().collateral.add(this.getUnrealizedPNL(true))) !== null && _a !== void 0 ? _a : new bn_js_1.default(0));
176
+ return ((_a = this.getUserAccount().collateral.add(this.getUnrealizedPNL(true))) !== null && _a !== void 0 ? _a : new _1.BN(0));
167
177
  }
168
178
  /**
169
179
  * calculates sum of position value across all positions
@@ -331,9 +341,9 @@ class ClearingHouseUser {
331
341
  const proposedMarketPosition = {
332
342
  marketIndex: targetMarket.marketIndex,
333
343
  baseAssetAmount: currentMarketPositionBaseSize.add(positionBaseSizeChange),
334
- lastCumulativeFundingRate: new bn_js_1.default(0),
335
- quoteAssetAmount: new bn_js_1.default(0),
336
- openOrders: new bn_js_1.default(0),
344
+ lastCumulativeFundingRate: new _1.BN(0),
345
+ quoteAssetAmount: new _1.BN(0),
346
+ openOrders: new _1.BN(0),
337
347
  };
338
348
  const market = this.clearingHouse.getMarket(proposedMarketPosition.marketIndex);
339
349
  const proposedMarketPositionValueUSDC = _1.calculateBaseAssetValue(market, proposedMarketPosition);
@@ -350,7 +360,7 @@ class ClearingHouseUser {
350
360
  // if the position value after the trade is less than total collateral, there is no liq price
351
361
  if (targetTotalPositionValueUSDC.lte(totalFreeCollateralUSDC) &&
352
362
  proposedMarketPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
353
- return new bn_js_1.default(-1);
363
+ return new _1.BN(-1);
354
364
  }
355
365
  // get current margin ratio based on current collateral and proposed total position value
356
366
  let marginRatio;
@@ -377,7 +387,7 @@ class ClearingHouseUser {
377
387
  if (numericConstants_1.TEN_THOUSAND.lte(pctChange)) {
378
388
  // no liquidation price, position is a fully/over collateralized long
379
389
  // handle as NaN on UI
380
- return new bn_js_1.default(-1);
390
+ return new _1.BN(-1);
381
391
  }
382
392
  pctChange = numericConstants_1.TEN_THOUSAND.sub(pctChange);
383
393
  }
@@ -406,7 +416,7 @@ class ClearingHouseUser {
406
416
  const tpv = this.getTotalPositionValue();
407
417
  const partialLev = 16;
408
418
  const maintLev = 20;
409
- const thisLev = partial ? new bn_js_1.default(partialLev) : new bn_js_1.default(maintLev);
419
+ const thisLev = partial ? new _1.BN(partialLev) : new _1.BN(maintLev);
410
420
  // calculate the total position value ignoring any value from the target market of the trade
411
421
  const totalCurrentPositionValueIgnoringTargetUSDC = this.getTotalPositionValueExcludingMarket(targetMarket.marketIndex);
412
422
  const currentMarketPosition = this.getUserPosition(targetMarket.marketIndex) ||
@@ -418,8 +428,8 @@ class ClearingHouseUser {
418
428
  marketIndex: targetMarket.marketIndex,
419
429
  baseAssetAmount: proposedBaseAssetAmount,
420
430
  lastCumulativeFundingRate: currentMarketPosition.lastCumulativeFundingRate,
421
- quoteAssetAmount: new bn_js_1.default(0),
422
- openOrders: new bn_js_1.default(0),
431
+ quoteAssetAmount: new _1.BN(0),
432
+ openOrders: new _1.BN(0),
423
433
  };
424
434
  const market = this.clearingHouse.getMarket(proposedMarketPosition.marketIndex);
425
435
  const proposedMarketPositionValueUSDC = _1.calculateBaseAssetValue(market, proposedMarketPosition);
@@ -439,14 +449,14 @@ class ClearingHouseUser {
439
449
  .mul(thisLev)
440
450
  .sub(tpv)
441
451
  .mul(numericConstants_1.PRICE_TO_QUOTE_PRECISION)
442
- .div(thisLev.add(new bn_js_1.default(1)));
452
+ .div(thisLev.add(new _1.BN(1)));
443
453
  }
444
454
  else {
445
455
  priceDelt = tc
446
456
  .mul(thisLev)
447
457
  .sub(tpv)
448
458
  .mul(numericConstants_1.PRICE_TO_QUOTE_PRECISION)
449
- .div(thisLev.sub(new bn_js_1.default(1)));
459
+ .div(thisLev.sub(new _1.BN(1)));
450
460
  }
451
461
  let currentPrice;
452
462
  if (positionBaseSizeChange.eq(numericConstants_1.ZERO)) {
@@ -461,15 +471,15 @@ class ClearingHouseUser {
461
471
  // if the position value after the trade is less than total collateral, there is no liq price
462
472
  if (targetTotalPositionValueUSDC.lte(totalFreeCollateralUSDC) &&
463
473
  proposedMarketPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
464
- return new bn_js_1.default(-1);
474
+ return new _1.BN(-1);
465
475
  }
466
476
  if (proposedBaseAssetAmount.eq(numericConstants_1.ZERO))
467
- return new bn_js_1.default(-1);
477
+ return new _1.BN(-1);
468
478
  const eatMargin2 = priceDelt
469
479
  .mul(numericConstants_1.AMM_RESERVE_PRECISION)
470
480
  .div(proposedBaseAssetAmount);
471
481
  if (eatMargin2.gt(currentPrice)) {
472
- return new bn_js_1.default(-1);
482
+ return new _1.BN(-1);
473
483
  }
474
484
  const liqPrice = currentPrice.sub(eatMargin2);
475
485
  return liqPrice;
@@ -522,7 +532,7 @@ class ClearingHouseUser {
522
532
  const currentLeverage = this.getLeverage();
523
533
  // remaining leverage
524
534
  // let remainingLeverage = userMaxLeverageSetting;
525
- const remainingLeverage = bn_js_1.default.max(userMaxLeverageSetting.sub(currentLeverage), numericConstants_1.ZERO);
535
+ const remainingLeverage = _1.BN.max(userMaxLeverageSetting.sub(currentLeverage), numericConstants_1.ZERO);
526
536
  // get total collateral
527
537
  const totalCollateral = this.getTotalCollateral();
528
538
  // position side allowed based purely on current leverage
@@ -531,7 +541,7 @@ class ClearingHouseUser {
531
541
  .div(numericConstants_1.TEN_THOUSAND);
532
542
  // add any position we have on the opposite side of the current trade, because we can "flip" the size of this position without taking any extra leverage.
533
543
  const oppositeSizeValueUSDC = getOppositePositionValueUSDC();
534
- maxPositionSize = maxPositionSize.add(oppositeSizeValueUSDC.mul(new bn_js_1.default(2)));
544
+ maxPositionSize = maxPositionSize.add(oppositeSizeValueUSDC.mul(new _1.BN(2)));
535
545
  // subtract oneMillionth of maxPositionSize
536
546
  // => to avoid rounding errors when taking max leverage
537
547
  const oneMilli = maxPositionSize.div(numericConstants_1.QUOTE_PRECISION);
package/lib/config.js CHANGED
@@ -5,7 +5,7 @@ exports.configs = {
5
5
  devnet: {
6
6
  ENV: 'devnet',
7
7
  PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
8
- CLEARING_HOUSE_PROGRAM_ID: 'HiZ8CnfEE9LrBZTfc8hBneWrPg1Cbsn8Wdy6SPLfae9V',
8
+ CLEARING_HOUSE_PROGRAM_ID: '3PfbDmWxR6e2rJ2brhSv7KJyUrHbSCu63d3FHqdLhxUJ',
9
9
  USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
10
10
  },
11
11
  'mainnet-beta': {
@@ -1,4 +1,5 @@
1
- import BN from 'bn.js';
1
+ /// <reference types="bn.js" />
2
+ import { BN } from '../';
2
3
  declare type Market = {
3
4
  symbol: string;
4
5
  baseAssetSymbol: string;
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Markets = void 0;
7
- const bn_js_1 = __importDefault(require("bn.js"));
4
+ const __1 = require("../");
8
5
  exports.Markets = [
9
6
  {
10
7
  symbol: 'SOL-PERP',
11
8
  baseAssetSymbol: 'SOL',
12
- marketIndex: new bn_js_1.default(0),
9
+ marketIndex: new __1.BN(0),
13
10
  devnetPythOracle: 'J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix',
14
11
  mainnetPythOracle: 'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG',
15
12
  launchTs: 1635209696886,
@@ -17,7 +14,7 @@ exports.Markets = [
17
14
  {
18
15
  symbol: 'BTC-PERP',
19
16
  baseAssetSymbol: 'BTC',
20
- marketIndex: new bn_js_1.default(1),
17
+ marketIndex: new __1.BN(1),
21
18
  devnetPythOracle: 'HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J',
22
19
  mainnetPythOracle: 'GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU',
23
20
  launchTs: 1637691088868,
@@ -25,7 +22,7 @@ exports.Markets = [
25
22
  {
26
23
  symbol: 'ETH-PERP',
27
24
  baseAssetSymbol: 'ETH',
28
- marketIndex: new bn_js_1.default(2),
25
+ marketIndex: new __1.BN(2),
29
26
  devnetPythOracle: 'EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw',
30
27
  mainnetPythOracle: 'JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB',
31
28
  launchTs: 1637691133472,
@@ -33,7 +30,7 @@ exports.Markets = [
33
30
  {
34
31
  symbol: 'LUNA-PERP',
35
32
  baseAssetSymbol: 'LUNA',
36
- marketIndex: new bn_js_1.default(3),
33
+ marketIndex: new __1.BN(3),
37
34
  devnetPythOracle: '8PugCXTAHLM9kfLSQWe2njE5pzAgUdpPk3Nx5zSm7BD3',
38
35
  mainnetPythOracle: '5bmWuR1dgP4avtGYMNKLuxumZTVKGgoN2BCMXWDNL9nY',
39
36
  launchTs: 1638821738525,
@@ -41,7 +38,7 @@ exports.Markets = [
41
38
  {
42
39
  symbol: 'AVAX-PERP',
43
40
  baseAssetSymbol: 'AVAX',
44
- marketIndex: new bn_js_1.default(4),
41
+ marketIndex: new __1.BN(4),
45
42
  devnetPythOracle: 'FVb5h1VmHPfVb1RfqZckchq18GxRv4iKt8T4eVTQAqdz',
46
43
  mainnetPythOracle: 'Ax9ujW5B9oqcv59N8m6f1BpTBq2rGeGaBcpKjC5UYsXU',
47
44
  launchTs: 1639092501080,
@@ -49,7 +46,7 @@ exports.Markets = [
49
46
  {
50
47
  symbol: 'BNB-PERP',
51
48
  baseAssetSymbol: 'BNB',
52
- marketIndex: new bn_js_1.default(5),
49
+ marketIndex: new __1.BN(5),
53
50
  devnetPythOracle: 'GwzBgrXb4PG59zjce24SF2b9JXbLEjJJTBkmytuEZj1b',
54
51
  mainnetPythOracle: '4CkQJBxhU8EZ2UjhigbtdaPbpTe6mqf811fipYBFbSYN',
55
52
  launchTs: 1639523193012,
@@ -57,7 +54,7 @@ exports.Markets = [
57
54
  {
58
55
  symbol: 'MATIC-PERP',
59
56
  baseAssetSymbol: 'MATIC',
60
- marketIndex: new bn_js_1.default(6),
57
+ marketIndex: new __1.BN(6),
61
58
  devnetPythOracle: 'FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur',
62
59
  mainnetPythOracle: '7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh',
63
60
  launchTs: 1641488603564,
@@ -65,7 +62,7 @@ exports.Markets = [
65
62
  {
66
63
  symbol: 'ATOM-PERP',
67
64
  baseAssetSymbol: 'ATOM',
68
- marketIndex: new bn_js_1.default(7),
65
+ marketIndex: new __1.BN(7),
69
66
  devnetPythOracle: '7YAze8qFUMkBnyLVdKT4TFUUFui99EwS5gfRArMcrvFk',
70
67
  mainnetPythOracle: 'CrCpTerNqtZvqLcKqz1k13oVeXV9WkMD2zA9hBKXrsbN',
71
68
  launchTs: 1641920238195,
@@ -73,7 +70,7 @@ exports.Markets = [
73
70
  {
74
71
  symbol: 'DOT-PERP',
75
72
  baseAssetSymbol: 'DOT',
76
- marketIndex: new bn_js_1.default(8),
73
+ marketIndex: new __1.BN(8),
77
74
  devnetPythOracle: '4dqq5VBpN4EwYb7wyywjjfknvMKu7m78j9mKZRXTj462',
78
75
  mainnetPythOracle: 'EcV1X1gY2yb4KXxjVQtTHTbioum2gvmPnFk4zYAt7zne',
79
76
  launchTs: 1642629253786,
@@ -81,9 +78,33 @@ exports.Markets = [
81
78
  {
82
79
  symbol: 'ADA-PERP',
83
80
  baseAssetSymbol: 'ADA',
84
- marketIndex: new bn_js_1.default(9),
81
+ marketIndex: new __1.BN(9),
85
82
  devnetPythOracle: '8oGTURNmSQkrBS1AQ5NjB2p8qY34UVmMA9ojrw8vnHus',
86
83
  mainnetPythOracle: '3pyn4svBbxJ9Wnn3RVeafyLWfzie6yC5eTig2S62v9SC',
87
84
  launchTs: 1643084413000,
88
85
  },
86
+ {
87
+ symbol: 'ALGO-PERP',
88
+ baseAssetSymbol: 'ALGO',
89
+ marketIndex: new __1.BN(10),
90
+ devnetPythOracle: 'c1A946dY5NHuVda77C8XXtXytyR3wK1SCP3eA9VRfC3',
91
+ mainnetPythOracle: 'HqFyq1wh1xKvL7KDqqT7NJeSPdAqsDqnmBisUC2XdXAX',
92
+ launchTs: 1643686767000,
93
+ },
94
+ {
95
+ symbol: 'FTT-PERP',
96
+ baseAssetSymbol: 'FTT',
97
+ marketIndex: new __1.BN(11),
98
+ devnetPythOracle: '6vivTRs5ZPeeXbjo7dfburfaYDWoXjBtdtuYgQRuGfu',
99
+ mainnetPythOracle: '8JPJJkmDScpcNmBRKGZuPuG2GYAveQgP3t5gFuMymwvF',
100
+ launchTs: 1644382122000,
101
+ },
102
+ // {
103
+ // symbol: 'mSOL-PERP',
104
+ // baseAssetSymbol: 'mSOL',
105
+ // marketIndex: new BN(11), //todo
106
+ // devnetPythOracle: '9a6RNx3tCu1TSs6TBSfV2XRXEPEZXQ6WB7jRojZRvyeZ',
107
+ // mainnetPythOracle: 'E4v1BBgoso9s64TQvmyownAVJbhbEPGyzA3qn4n46qj9',
108
+ // launchTs: 1643346125000,
109
+ // },
89
110
  ];
@@ -1,4 +1,5 @@
1
- import BN from 'bn.js';
1
+ /// <reference types="bn.js" />
2
+ import { BN } from '../';
2
3
  export declare const ZERO: BN;
3
4
  export declare const ONE: BN;
4
5
  export declare const TEN_THOUSAND: BN;
@@ -11,6 +12,7 @@ export declare const MARK_PRICE_PRECISION: BN;
11
12
  export declare const FUNDING_PAYMENT_PRECISION: BN;
12
13
  export declare const PEG_PRECISION: BN;
13
14
  export declare const AMM_RESERVE_PRECISION: BN;
15
+ export declare const BASE_PRECISION: BN;
14
16
  export declare const AMM_TO_QUOTE_PRECISION_RATIO: BN;
15
17
  export declare const PRICE_TO_QUOTE_PRECISION: BN;
16
18
  export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: BN;
@@ -1,22 +1,20 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.AMM_TO_QUOTE_PRECISION_RATIO = 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;
7
- const bn_js_1 = __importDefault(require("bn.js"));
8
- exports.ZERO = new bn_js_1.default(0);
9
- exports.ONE = new bn_js_1.default(1);
10
- exports.TEN_THOUSAND = new bn_js_1.default(10000);
11
- exports.BN_MAX = new bn_js_1.default(Number.MAX_SAFE_INTEGER);
12
- exports.MAX_LEVERAGE = new bn_js_1.default(5);
13
- exports.FULL_LIQUIDATION_RATIO = new bn_js_1.default(500);
14
- exports.PARTIAL_LIQUIDATION_RATIO = new bn_js_1.default(625);
15
- exports.QUOTE_PRECISION = new bn_js_1.default(Math.pow(10, 6));
16
- exports.MARK_PRICE_PRECISION = new bn_js_1.default(Math.pow(10, 10));
17
- exports.FUNDING_PAYMENT_PRECISION = new bn_js_1.default(10000);
18
- exports.PEG_PRECISION = new bn_js_1.default(1000);
19
- exports.AMM_RESERVE_PRECISION = new bn_js_1.default(Math.pow(10, 13));
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;
4
+ const __1 = require("../");
5
+ exports.ZERO = new __1.BN(0);
6
+ exports.ONE = new __1.BN(1);
7
+ exports.TEN_THOUSAND = new __1.BN(10000);
8
+ exports.BN_MAX = new __1.BN(Number.MAX_SAFE_INTEGER);
9
+ exports.MAX_LEVERAGE = new __1.BN(5);
10
+ exports.FULL_LIQUIDATION_RATIO = new __1.BN(500);
11
+ exports.PARTIAL_LIQUIDATION_RATIO = new __1.BN(625);
12
+ exports.QUOTE_PRECISION = new __1.BN(Math.pow(10, 6));
13
+ exports.MARK_PRICE_PRECISION = new __1.BN(Math.pow(10, 10));
14
+ exports.FUNDING_PAYMENT_PRECISION = new __1.BN(10000);
15
+ exports.PEG_PRECISION = new __1.BN(1000);
16
+ exports.AMM_RESERVE_PRECISION = new __1.BN(Math.pow(10, 13));
17
+ exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION;
20
18
  exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.div(exports.QUOTE_PRECISION); // 10^7
21
19
  exports.PRICE_TO_QUOTE_PRECISION = exports.MARK_PRICE_PRECISION.div(exports.QUOTE_PRECISION);
22
20
  exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.mul(exports.PEG_PRECISION).div(exports.QUOTE_PRECISION); // 10^10