@drift-labs/sdk 0.1.19-master.0 → 0.1.21-master.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +32 -0
  2. package/lib/accounts/bulkAccountLoader.d.ts.map +1 -0
  3. package/lib/accounts/bulkAccountLoader.js +175 -0
  4. package/lib/accounts/bulkUserSubscription.d.ts +8 -0
  5. package/lib/accounts/bulkUserSubscription.d.ts.map +1 -0
  6. package/lib/accounts/bulkUserSubscription.js +28 -0
  7. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +46 -0
  8. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts.map +1 -0
  9. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +206 -0
  10. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
  11. package/lib/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -0
  12. package/lib/accounts/pollingTokenAccountSubscriber.js +79 -0
  13. package/lib/accounts/pollingUserAccountSubscriber.d.ts +31 -0
  14. package/lib/accounts/pollingUserAccountSubscriber.d.ts.map +1 -0
  15. package/lib/accounts/pollingUserAccountSubscriber.js +123 -0
  16. package/lib/accounts/types.d.ts +30 -0
  17. package/lib/accounts/types.d.ts.map +1 -1
  18. package/lib/accounts/utils.d.ts +2 -0
  19. package/lib/accounts/utils.d.ts.map +1 -0
  20. package/lib/accounts/utils.js +7 -0
  21. package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -2
  22. package/lib/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
  23. package/lib/accounts/webSocketAccountSubscriber.js +43 -12
  24. package/lib/accounts/{defaultClearingHouseAccountSubscriber.d.ts → webSocketClearingHouseAccountSubscriber.d.ts} +4 -2
  25. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts.map +1 -0
  26. package/lib/accounts/{defaultClearingHouseAccountSubscriber.js → webSocketClearingHouseAccountSubscriber.js} +5 -4
  27. package/lib/accounts/{defaultUserAccountSubscriber.d.ts → webSocketUserAccountSubscriber.d.ts} +4 -2
  28. package/lib/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -0
  29. package/lib/accounts/{defaultUserAccountSubscriber.js → webSocketUserAccountSubscriber.js} +5 -4
  30. package/lib/admin.d.ts +1 -0
  31. package/lib/admin.d.ts.map +1 -1
  32. package/lib/admin.js +23 -14
  33. package/lib/clearingHouse.d.ts +12 -2
  34. package/lib/clearingHouse.d.ts.map +1 -1
  35. package/lib/clearingHouse.js +28 -17
  36. package/lib/clearingHouseUser.d.ts +11 -3
  37. package/lib/clearingHouseUser.d.ts.map +1 -1
  38. package/lib/clearingHouseUser.js +46 -36
  39. package/lib/constants/markets.d.ts +2 -1
  40. package/lib/constants/markets.d.ts.map +1 -1
  41. package/lib/constants/markets.js +20 -15
  42. package/lib/constants/numericConstants.d.ts +3 -1
  43. package/lib/constants/numericConstants.d.ts.map +1 -1
  44. package/lib/constants/numericConstants.js +15 -17
  45. package/lib/examples/makeTradeExample.js +6 -6
  46. package/lib/factory/clearingHouse.d.ts +26 -0
  47. package/lib/factory/clearingHouse.d.ts.map +1 -0
  48. package/lib/factory/clearingHouse.js +64 -0
  49. package/lib/factory/clearingHouseUser.d.ts +20 -0
  50. package/lib/factory/clearingHouseUser.d.ts.map +1 -0
  51. package/lib/factory/clearingHouseUser.js +34 -0
  52. package/lib/index.d.ts +8 -2
  53. package/lib/index.d.ts.map +1 -1
  54. package/lib/index.js +9 -2
  55. package/lib/math/amm.js +7 -7
  56. package/lib/math/conversion.d.ts +1 -1
  57. package/lib/math/conversion.d.ts.map +1 -1
  58. package/lib/math/conversion.js +1 -1
  59. package/lib/math/funding.js +1 -1
  60. package/lib/math/insuranceFund.d.ts +2 -1
  61. package/lib/math/insuranceFund.d.ts.map +1 -1
  62. package/lib/math/insuranceFund.js +3 -6
  63. package/lib/math/market.js +1 -1
  64. package/lib/math/position.d.ts +2 -1
  65. package/lib/math/position.d.ts.map +1 -1
  66. package/lib/math/position.js +3 -6
  67. package/lib/math/trade.js +16 -16
  68. package/lib/math/utils.d.ts +2 -1
  69. package/lib/math/utils.d.ts.map +1 -1
  70. package/lib/math/utils.js +3 -3
  71. package/lib/mockUSDCFaucet.d.ts +2 -1
  72. package/lib/mockUSDCFaucet.d.ts.map +1 -1
  73. package/lib/pythClient.js +1 -1
  74. package/lib/token/index.d.ts +4 -0
  75. package/lib/token/index.d.ts.map +1 -0
  76. package/lib/token/index.js +38 -0
  77. package/lib/types.d.ts +2 -1
  78. package/lib/types.d.ts.map +1 -1
  79. package/package.json +11 -3
  80. package/src/accounts/bulkAccountLoader.ts +215 -0
  81. package/src/accounts/bulkUserSubscription.ts +28 -0
  82. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +293 -0
  83. package/src/accounts/pollingTokenAccountSubscriber.ts +99 -0
  84. package/src/accounts/pollingUserAccountSubscriber.ts +166 -0
  85. package/src/accounts/types.ts +38 -0
  86. package/src/accounts/utils.ts +3 -0
  87. package/src/accounts/webSocketAccountSubscriber.ts +67 -17
  88. package/src/accounts/{defaultClearingHouseAccountSubscriber.ts → webSocketClearingHouseAccountSubscriber.ts} +4 -1
  89. package/src/accounts/{defaultUserAccountSubscriber.ts → webSocketUserAccountSubscriber.ts} +4 -1
  90. package/src/admin.ts +27 -18
  91. package/src/clearingHouse.ts +25 -17
  92. package/src/clearingHouseUser.ts +26 -6
  93. package/src/constants/markets.ts +9 -1
  94. package/src/constants/numericConstants.ts +2 -1
  95. package/src/examples/makeTradeExample.ts +4 -1
  96. package/src/factory/clearingHouse.ts +125 -0
  97. package/src/factory/clearingHouseUser.ts +73 -0
  98. package/src/index.ts +8 -2
  99. package/src/math/conversion.ts +1 -1
  100. package/src/math/insuranceFund.ts +1 -1
  101. package/src/math/position.ts +1 -1
  102. package/src/math/utils.ts +1 -1
  103. package/src/mockUSDCFaucet.ts +1 -1
  104. package/src/token/index.ts +37 -0
  105. package/src/types.ts +1 -1
  106. package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts.map +0 -1
  107. package/lib/accounts/defaultUserAccountSubscriber.d.ts.map +0 -1
@@ -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
  *
@@ -115,7 +126,7 @@ class ClearingHouse {
115
126
  if (this.statePublicKey) {
116
127
  return this.statePublicKey;
117
128
  }
118
- this.statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
129
+ this.statePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
119
130
  return this.statePublicKey;
120
131
  });
121
132
  }
@@ -174,7 +185,7 @@ class ClearingHouse {
174
185
  }
175
186
  getInitializeUserInstructions() {
176
187
  return __awaiter(this, void 0, void 0, function* () {
177
- const [userPublicKey, userAccountNonce] = yield (0, addresses_1.getUserAccountPublicKeyAndNonce)(this.program.programId, this.wallet.publicKey);
188
+ const [userPublicKey, userAccountNonce] = yield addresses_1.getUserAccountPublicKeyAndNonce(this.program.programId, this.wallet.publicKey);
178
189
  const remainingAccounts = [];
179
190
  const optionalAccounts = {
180
191
  whitelistToken: false,
@@ -213,7 +224,7 @@ class ClearingHouse {
213
224
  if (this.userAccountPublicKey) {
214
225
  return this.userAccountPublicKey;
215
226
  }
216
- this.userAccountPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey);
227
+ this.userAccountPublicKey = yield addresses_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey);
217
228
  return this.userAccountPublicKey;
218
229
  });
219
230
  }
@@ -303,7 +314,7 @@ class ClearingHouse {
303
314
  }
304
315
  withdrawCollateral(amount, collateralAccountPublicKey) {
305
316
  return __awaiter(this, void 0, void 0, function* () {
306
- return this.txSender.send((0, utils_1.wrapInTx)(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
317
+ return this.txSender.send(utils_1.wrapInTx(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
307
318
  });
308
319
  }
309
320
  getWithdrawCollateralIx(amount, collateralAccountPublicKey) {
@@ -332,7 +343,7 @@ class ClearingHouse {
332
343
  }
333
344
  openPosition(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
334
345
  return __awaiter(this, void 0, void 0, function* () {
335
- return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer)), [], this.opts);
346
+ return yield this.txSender.send(utils_1.wrapInTx(yield this.getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer)), [], this.opts);
336
347
  });
337
348
  }
338
349
  getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
@@ -390,7 +401,7 @@ class ClearingHouse {
390
401
  */
391
402
  closePosition(marketIndex, discountToken, referrer) {
392
403
  return __awaiter(this, void 0, void 0, function* () {
393
- return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getClosePositionIx(marketIndex, discountToken, referrer)), [], this.opts);
404
+ return yield this.txSender.send(utils_1.wrapInTx(yield this.getClosePositionIx(marketIndex, discountToken, referrer)), [], this.opts);
394
405
  });
395
406
  }
396
407
  getClosePositionIx(marketIndex, discountToken, referrer) {
@@ -438,7 +449,7 @@ class ClearingHouse {
438
449
  }
439
450
  liquidate(liquidateeUserAccountPublicKey) {
440
451
  return __awaiter(this, void 0, void 0, function* () {
441
- return this.txSender.send((0, utils_1.wrapInTx)(yield this.getLiquidateIx(liquidateeUserAccountPublicKey)), [], this.opts);
452
+ return this.txSender.send(utils_1.wrapInTx(yield this.getLiquidateIx(liquidateeUserAccountPublicKey)), [], this.opts);
442
453
  });
443
454
  }
444
455
  getLiquidateIx(liquidateeUserAccountPublicKey) {
@@ -482,7 +493,7 @@ class ClearingHouse {
482
493
  }
483
494
  updateFundingRate(oracle, marketIndex) {
484
495
  return __awaiter(this, void 0, void 0, function* () {
485
- return this.txSender.send((0, utils_1.wrapInTx)(yield this.getUpdateFundingRateIx(oracle, marketIndex)), [], this.opts);
496
+ return this.txSender.send(utils_1.wrapInTx(yield this.getUpdateFundingRateIx(oracle, marketIndex)), [], this.opts);
486
497
  });
487
498
  }
488
499
  getUpdateFundingRateIx(oracle, marketIndex) {
@@ -500,7 +511,7 @@ class ClearingHouse {
500
511
  }
501
512
  settleFundingPayment(userAccount, userPositionsAccount) {
502
513
  return __awaiter(this, void 0, void 0, function* () {
503
- return this.txSender.send((0, utils_1.wrapInTx)(yield this.getSettleFundingPaymentIx(userAccount, userPositionsAccount)), [], this.opts);
514
+ return this.txSender.send(utils_1.wrapInTx(yield this.getSettleFundingPaymentIx(userAccount, userPositionsAccount)), [], this.opts);
504
515
  });
505
516
  }
506
517
  getSettleFundingPaymentIx(userAccount, userPositionsAccount) {
@@ -1,19 +1,27 @@
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 { UserAccount, 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
- isSubscribed: boolean;
15
+ _isSubscribed: boolean;
16
16
  eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
17
+ get isSubscribed(): boolean;
18
+ set isSubscribed(val: boolean);
19
+ /**
20
+ * @deprecated You should use getClearingHouseUser factory method instead
21
+ * @param clearingHouse
22
+ * @param authority
23
+ * @returns
24
+ */
17
25
  static from(clearingHouse: ClearingHouse, authority: PublicKey): ClearingHouseUser;
18
26
  constructor(clearingHouse: ClearingHouse, authority: PublicKey, accountSubscriber: UserAccountSubscriber);
19
27
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"clearingHouseUser.d.ts","sourceRoot":"","sources":["../src/clearingHouseUser.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAc1E,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAKN,iBAAiB,EAEjB,MAAM,GAAG,CAAC;AAGX,qBAAa,iBAAiB;IAC7B,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,iBAAiB,EAAE,qBAAqB,CAAC;IACzC,oBAAoB,CAAC,EAAE,SAAS,CAAC;IACjC,YAAY,UAAS;IACrB,YAAY,EAAE,kBAAkB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;WAEpD,IAAI,CACjB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,GAClB,iBAAiB;g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AC5B,sBAAsB,EAAE,EAAE,GACxB,EAAE;IAgGL;;;;;;OAMG;IACI,8BAA8B,CACpC,iBAAiB,EAAE,EAAE,EACrB,gBAAgB,EAAE,EAAE,EACpB,SAAS,EAAE,iBAAiB,GAC1B,EAAE;IAuCL;;;;OAIG;IACI,0BAA0B,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE;IAQtD;;;;OAIG;IACH,OAAO,CAAC,oCAAoC;CAY5C"}
@@ -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
@@ -84,7 +94,7 @@ class ClearingHouseUser {
84
94
  if (this.userAccountPublicKey) {
85
95
  return this.userAccountPublicKey;
86
96
  }
87
- this.userAccountPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.clearingHouse.program.programId, this.authority);
97
+ this.userAccountPublicKey = yield addresses_1.getUserAccountPublicKey(this.clearingHouse.program.programId, this.authority);
88
98
  return this.userAccountPublicKey;
89
99
  });
90
100
  }
@@ -122,7 +132,7 @@ class ClearingHouseUser {
122
132
  .positions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
123
133
  .reduce((pnl, marketPosition) => {
124
134
  const market = this.clearingHouse.getMarket(marketPosition.marketIndex);
125
- return pnl.add((0, _1.calculatePositionPNL)(market, marketPosition, withFunding));
135
+ return pnl.add(_1.calculatePositionPNL(market, marketPosition, withFunding));
126
136
  }, numericConstants_1.ZERO);
127
137
  }
128
138
  /**
@@ -134,7 +144,7 @@ class ClearingHouseUser {
134
144
  .positions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
135
145
  .reduce((pnl, marketPosition) => {
136
146
  const market = this.clearingHouse.getMarket(marketPosition.marketIndex);
137
- return pnl.add((0, _1.calculatePositionFundingPNL)(market, marketPosition));
147
+ return pnl.add(_1.calculatePositionFundingPNL(market, marketPosition));
138
148
  }, numericConstants_1.ZERO);
139
149
  }
140
150
  /**
@@ -143,7 +153,7 @@ class ClearingHouseUser {
143
153
  */
144
154
  getTotalCollateral() {
145
155
  var _a;
146
- return ((_a = this.getUserAccount().collateral.add(this.getUnrealizedPNL(true))) !== null && _a !== void 0 ? _a : new bn_js_1.default(0));
156
+ return ((_a = this.getUserAccount().collateral.add(this.getUnrealizedPNL(true))) !== null && _a !== void 0 ? _a : new _1.BN(0));
147
157
  }
148
158
  /**
149
159
  * calculates sum of position value across all positions
@@ -152,7 +162,7 @@ class ClearingHouseUser {
152
162
  getTotalPositionValue() {
153
163
  return this.getUserPositionsAccount().positions.reduce((positionValue, marketPosition) => {
154
164
  const market = this.clearingHouse.getMarket(marketPosition.marketIndex);
155
- return positionValue.add((0, _1.calculateBaseAssetValue)(market, marketPosition));
165
+ return positionValue.add(_1.calculateBaseAssetValue(market, marketPosition));
156
166
  }, numericConstants_1.ZERO);
157
167
  }
158
168
  /**
@@ -162,7 +172,7 @@ class ClearingHouseUser {
162
172
  getPositionValue(marketIndex) {
163
173
  const userPosition = this.getUserPosition(marketIndex) || this.getEmptyPosition(marketIndex);
164
174
  const market = this.clearingHouse.getMarket(userPosition.marketIndex);
165
- return (0, _1.calculateBaseAssetValue)(market, userPosition);
175
+ return _1.calculateBaseAssetValue(market, userPosition);
166
176
  }
167
177
  getPositionSide(currentPosition) {
168
178
  if (currentPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
@@ -181,10 +191,10 @@ class ClearingHouseUser {
181
191
  */
182
192
  getPositionEstimatedExitPriceAndPnl(position, amountToClose) {
183
193
  const market = this.clearingHouse.getMarket(position.marketIndex);
184
- const entryPrice = (0, position_1.calculateEntryPrice)(position);
194
+ const entryPrice = position_1.calculateEntryPrice(position);
185
195
  if (amountToClose) {
186
196
  if (amountToClose.eq(numericConstants_1.ZERO)) {
187
- return [(0, _1.calculateMarkPrice)(market), numericConstants_1.ZERO];
197
+ return [_1.calculateMarkPrice(market), numericConstants_1.ZERO];
188
198
  }
189
199
  position = {
190
200
  baseAssetAmount: amountToClose,
@@ -193,7 +203,7 @@ class ClearingHouseUser {
193
203
  quoteAssetAmount: position.quoteAssetAmount,
194
204
  };
195
205
  }
196
- const baseAssetValue = (0, _1.calculateBaseAssetValue)(market, position);
206
+ const baseAssetValue = _1.calculateBaseAssetValue(market, position);
197
207
  if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
198
208
  return [numericConstants_1.ZERO, numericConstants_1.ZERO];
199
209
  }
@@ -300,7 +310,7 @@ class ClearingHouseUser {
300
310
 
301
311
  for 10x long, BTC down $400:
302
312
  3. (10k - 4k) / (100k - 4k) = 6k/96k => .0625 */
303
- const currentPrice = (0, _1.calculateMarkPrice)(this.clearingHouse.getMarket(targetMarket.marketIndex));
313
+ const currentPrice = _1.calculateMarkPrice(this.clearingHouse.getMarket(targetMarket.marketIndex));
304
314
  const totalCollateralUSDC = this.getTotalCollateral();
305
315
  // calculate the total position value ignoring any value from the target market of the trade
306
316
  const totalCurrentPositionValueIgnoringTargetUSDC = this.getTotalPositionValueExcludingMarket(targetMarket.marketIndex);
@@ -311,11 +321,11 @@ class ClearingHouseUser {
311
321
  const proposedMarketPosition = {
312
322
  marketIndex: targetMarket.marketIndex,
313
323
  baseAssetAmount: currentMarketPositionBaseSize.add(positionBaseSizeChange),
314
- lastCumulativeFundingRate: new bn_js_1.default(0),
315
- quoteAssetAmount: new bn_js_1.default(0),
324
+ lastCumulativeFundingRate: new _1.BN(0),
325
+ quoteAssetAmount: new _1.BN(0),
316
326
  };
317
327
  const market = this.clearingHouse.getMarket(proposedMarketPosition.marketIndex);
318
- const proposedMarketPositionValueUSDC = (0, _1.calculateBaseAssetValue)(market, proposedMarketPosition);
328
+ const proposedMarketPositionValueUSDC = _1.calculateBaseAssetValue(market, proposedMarketPosition);
319
329
  // total position value after trade
320
330
  const targetTotalPositionValueUSDC = totalCurrentPositionValueIgnoringTargetUSDC.add(proposedMarketPositionValueUSDC);
321
331
  let totalFreeCollateralUSDC = this.getTotalCollateral().sub(this.getTotalPositionValue()
@@ -329,7 +339,7 @@ class ClearingHouseUser {
329
339
  // if the position value after the trade is less than total collateral, there is no liq price
330
340
  if (targetTotalPositionValueUSDC.lte(totalFreeCollateralUSDC) &&
331
341
  proposedMarketPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
332
- return new bn_js_1.default(-1);
342
+ return new _1.BN(-1);
333
343
  }
334
344
  // get current margin ratio based on current collateral and proposed total position value
335
345
  let marginRatio;
@@ -356,7 +366,7 @@ class ClearingHouseUser {
356
366
  if (numericConstants_1.TEN_THOUSAND.lte(pctChange)) {
357
367
  // no liquidation price, position is a fully/over collateralized long
358
368
  // handle as NaN on UI
359
- return new bn_js_1.default(-1);
369
+ return new _1.BN(-1);
360
370
  }
361
371
  pctChange = numericConstants_1.TEN_THOUSAND.sub(pctChange);
362
372
  }
@@ -385,7 +395,7 @@ class ClearingHouseUser {
385
395
  const tpv = this.getTotalPositionValue();
386
396
  const partialLev = 16;
387
397
  const maintLev = 20;
388
- const thisLev = partial ? new bn_js_1.default(partialLev) : new bn_js_1.default(maintLev);
398
+ const thisLev = partial ? new _1.BN(partialLev) : new _1.BN(maintLev);
389
399
  // calculate the total position value ignoring any value from the target market of the trade
390
400
  const totalCurrentPositionValueIgnoringTargetUSDC = this.getTotalPositionValueExcludingMarket(targetMarket.marketIndex);
391
401
  const currentMarketPosition = this.getUserPosition(targetMarket.marketIndex) ||
@@ -397,10 +407,10 @@ class ClearingHouseUser {
397
407
  marketIndex: targetMarket.marketIndex,
398
408
  baseAssetAmount: proposedBaseAssetAmount,
399
409
  lastCumulativeFundingRate: currentMarketPosition.lastCumulativeFundingRate,
400
- quoteAssetAmount: new bn_js_1.default(0),
410
+ quoteAssetAmount: new _1.BN(0),
401
411
  };
402
412
  const market = this.clearingHouse.getMarket(proposedMarketPosition.marketIndex);
403
- const proposedMarketPositionValueUSDC = (0, _1.calculateBaseAssetValue)(market, proposedMarketPosition);
413
+ const proposedMarketPositionValueUSDC = _1.calculateBaseAssetValue(market, proposedMarketPosition);
404
414
  // total position value after trade
405
415
  const targetTotalPositionValueUSDC = totalCurrentPositionValueIgnoringTargetUSDC.add(proposedMarketPositionValueUSDC);
406
416
  let totalFreeCollateralUSDC = tc.sub(totalCurrentPositionValueIgnoringTargetUSDC
@@ -417,37 +427,37 @@ class ClearingHouseUser {
417
427
  .mul(thisLev)
418
428
  .sub(tpv)
419
429
  .mul(numericConstants_1.PRICE_TO_QUOTE_PRECISION)
420
- .div(thisLev.add(new bn_js_1.default(1)));
430
+ .div(thisLev.add(new _1.BN(1)));
421
431
  }
422
432
  else {
423
433
  priceDelt = tc
424
434
  .mul(thisLev)
425
435
  .sub(tpv)
426
436
  .mul(numericConstants_1.PRICE_TO_QUOTE_PRECISION)
427
- .div(thisLev.sub(new bn_js_1.default(1)));
437
+ .div(thisLev.sub(new _1.BN(1)));
428
438
  }
429
439
  let currentPrice;
430
440
  if (positionBaseSizeChange.eq(numericConstants_1.ZERO)) {
431
- currentPrice = (0, _1.calculateMarkPrice)(this.clearingHouse.getMarket(targetMarket.marketIndex));
441
+ currentPrice = _1.calculateMarkPrice(this.clearingHouse.getMarket(targetMarket.marketIndex));
432
442
  }
433
443
  else {
434
444
  const direction = positionBaseSizeChange.gt(numericConstants_1.ZERO)
435
445
  ? _1.PositionDirection.LONG
436
446
  : _1.PositionDirection.SHORT;
437
- currentPrice = (0, _1.calculateTradeSlippage)(direction, positionBaseSizeChange.abs(), this.clearingHouse.getMarket(targetMarket.marketIndex), 'base')[3]; // newPrice after swap
447
+ currentPrice = _1.calculateTradeSlippage(direction, positionBaseSizeChange.abs(), this.clearingHouse.getMarket(targetMarket.marketIndex), 'base')[3]; // newPrice after swap
438
448
  }
439
449
  // if the position value after the trade is less than total collateral, there is no liq price
440
450
  if (targetTotalPositionValueUSDC.lte(totalFreeCollateralUSDC) &&
441
451
  proposedMarketPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
442
- return new bn_js_1.default(-1);
452
+ return new _1.BN(-1);
443
453
  }
444
454
  if (proposedBaseAssetAmount.eq(numericConstants_1.ZERO))
445
- return new bn_js_1.default(-1);
455
+ return new _1.BN(-1);
446
456
  const eatMargin2 = priceDelt
447
457
  .mul(numericConstants_1.AMM_RESERVE_PRECISION)
448
458
  .div(proposedBaseAssetAmount);
449
459
  if (eatMargin2.gt(currentPrice)) {
450
- return new bn_js_1.default(-1);
460
+ return new _1.BN(-1);
451
461
  }
452
462
  const liqPrice = currentPrice.sub(eatMargin2);
453
463
  return liqPrice;
@@ -510,7 +520,7 @@ class ClearingHouseUser {
510
520
  : this.getPositionValue(targetMarketIndex);
511
521
  // get current leverage
512
522
  const currentLeverage = this.getLeverage();
513
- const remainingLeverage = bn_js_1.default.max(userMaxLeverageSetting.sub(currentLeverage), numericConstants_1.ZERO);
523
+ const remainingLeverage = _1.BN.max(userMaxLeverageSetting.sub(currentLeverage), numericConstants_1.ZERO);
514
524
  // get total collateral
515
525
  const totalCollateral = this.getTotalCollateral();
516
526
  // position side allowed based purely on current leverage
@@ -524,7 +534,7 @@ class ClearingHouseUser {
524
534
  }
525
535
  else {
526
536
  // case 2 : trade where current total position less than max, but need to account for flipping the current position over to the other side
527
- maxPositionSize = maxPositionSize.add(oppositeSizeValueUSDC.mul(new bn_js_1.default(2)));
537
+ maxPositionSize = maxPositionSize.add(oppositeSizeValueUSDC.mul(new _1.BN(2)));
528
538
  }
529
539
  }
530
540
  else {
@@ -592,7 +602,7 @@ class ClearingHouseUser {
592
602
  return newLeverage;
593
603
  }
594
604
  else {
595
- return new bn_js_1.default(0);
605
+ return new _1.BN(0);
596
606
  }
597
607
  }
598
608
  /**
@@ -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 +1 @@
1
- {"version":3,"file":"markets.d.ts","sourceRoot":"","sources":["../../src/constants/markets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,aAAK,MAAM,GAAG;IACb,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,EAAE,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAAM,EAiG3B,CAAC"}
1
+ {"version":3,"file":"markets.d.ts","sourceRoot":"","sources":["../../src/constants/markets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,KAAK,CAAC;AAEzB,aAAK,MAAM,GAAG;IACb,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,EAAE,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAAM,EAyG3B,CAAC"}
@@ -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,7 +78,7 @@ 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,
@@ -89,11 +86,19 @@ exports.Markets = [
89
86
  {
90
87
  symbol: 'ALGO-PERP',
91
88
  baseAssetSymbol: 'ALGO',
92
- marketIndex: new bn_js_1.default(10),
89
+ marketIndex: new __1.BN(10),
93
90
  devnetPythOracle: 'c1A946dY5NHuVda77C8XXtXytyR3wK1SCP3eA9VRfC3',
94
91
  mainnetPythOracle: 'HqFyq1wh1xKvL7KDqqT7NJeSPdAqsDqnmBisUC2XdXAX',
95
92
  launchTs: 1643686767000,
96
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
+ },
97
102
  // {
98
103
  // symbol: 'mSOL-PERP',
99
104
  // baseAssetSymbol: 'mSOL',
@@ -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 +1 @@
1
- {"version":3,"file":"numericConstants.d.ts","sourceRoot":"","sources":["../../src/constants/numericConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,eAAO,MAAM,IAAI,IAAY,CAAC;AAC9B,eAAO,MAAM,GAAG,IAAY,CAAC;AAC7B,eAAO,MAAM,YAAY,IAAgB,CAAC;AAC1C,eAAO,MAAM,MAAM,IAAkC,CAAC;AAEtD,eAAO,MAAM,YAAY,IAAY,CAAC;AACtC,eAAO,MAAM,sBAAsB,IAAc,CAAC;AAClD,eAAO,MAAM,yBAAyB,IAAc,CAAC;AAErD,eAAO,MAAM,eAAe,IAAkB,CAAC;AAC/C,eAAO,MAAM,oBAAoB,IAAmB,CAAC;AACrD,eAAO,MAAM,yBAAyB,IAAgB,CAAC;AACvD,eAAO,MAAM,aAAa,IAAe,CAAC;AAE1C,eAAO,MAAM,qBAAqB,IAAmB,CAAC;AACtD,eAAO,MAAM,4BAA4B,IACE,CAAC;AAC5C,eAAO,MAAM,wBAAwB,IACK,CAAC;AAC3C,eAAO,MAAM,sCAAsC,IACW,CAAC"}
1
+ {"version":3,"file":"numericConstants.d.ts","sourceRoot":"","sources":["../../src/constants/numericConstants.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,IAAI,IAAY,CAAC;AAC9B,eAAO,MAAM,GAAG,IAAY,CAAC;AAC7B,eAAO,MAAM,YAAY,IAAgB,CAAC;AAC1C,eAAO,MAAM,MAAM,IAAkC,CAAC;AAEtD,eAAO,MAAM,YAAY,IAAY,CAAC;AACtC,eAAO,MAAM,sBAAsB,IAAc,CAAC;AAClD,eAAO,MAAM,yBAAyB,IAAc,CAAC;AAErD,eAAO,MAAM,eAAe,IAAkB,CAAC;AAC/C,eAAO,MAAM,oBAAoB,IAAmB,CAAC;AACrD,eAAO,MAAM,yBAAyB,IAAgB,CAAC;AACvD,eAAO,MAAM,aAAa,IAAe,CAAC;AAE1C,eAAO,MAAM,qBAAqB,IAAmB,CAAC;AACtD,eAAO,MAAM,cAAc,IAAwB,CAAC;AACpD,eAAO,MAAM,4BAA4B,IACE,CAAC;AAC5C,eAAO,MAAM,wBAAwB,IACK,CAAC;AAC3C,eAAO,MAAM,sCAAsC,IACW,CAAC"}
@@ -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