@drift-labs/sdk 0.2.0-master.26 → 0.2.0-master.27

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 (143) hide show
  1. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +1 -0
  2. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +3 -0
  3. package/lib/accounts/types.d.ts +1 -0
  4. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +1 -0
  5. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +3 -0
  6. package/lib/admin.d.ts +5 -2
  7. package/lib/admin.js +30 -4
  8. package/lib/clearingHouse.d.ts +2 -0
  9. package/lib/clearingHouse.js +14 -1
  10. package/lib/clearingHouseUser.d.ts +11 -9
  11. package/lib/clearingHouseUser.js +182 -106
  12. package/lib/config.js +1 -1
  13. package/lib/dlob/DLOB.d.ts +73 -0
  14. package/lib/dlob/DLOB.js +557 -0
  15. package/lib/dlob/DLOBNode.d.ts +52 -0
  16. package/lib/dlob/DLOBNode.js +82 -0
  17. package/lib/dlob/NodeList.d.ts +26 -0
  18. package/lib/dlob/NodeList.js +138 -0
  19. package/lib/idl/clearing_house.json +122 -202
  20. package/lib/index.d.ts +5 -0
  21. package/lib/index.js +5 -0
  22. package/lib/math/market.d.ts +1 -1
  23. package/lib/math/market.js +1 -1
  24. package/lib/math/orders.d.ts +3 -3
  25. package/lib/math/orders.js +31 -16
  26. package/lib/math/spotBalance.d.ts +3 -0
  27. package/lib/math/spotBalance.js +18 -1
  28. package/lib/math/spotPosition.d.ts +5 -1
  29. package/lib/math/spotPosition.js +16 -1
  30. package/lib/types.d.ts +24 -23
  31. package/lib/types.js +9 -3
  32. package/lib/userMap/userMap.d.ts +25 -0
  33. package/lib/userMap/userMap.js +73 -0
  34. package/lib/userMap/userStatsMap.d.ts +19 -0
  35. package/lib/userMap/userStatsMap.js +68 -0
  36. package/package.json +6 -3
  37. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
  38. package/src/accounts/types.ts +1 -0
  39. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
  40. package/src/addresses/marketAddresses.js +26 -0
  41. package/src/admin.ts +50 -8
  42. package/src/assert/assert.js +1 -1
  43. package/src/clearingHouse.ts +23 -1
  44. package/src/clearingHouseUser.ts +364 -165
  45. package/src/config.ts +1 -1
  46. package/src/constants/banks.js +42 -0
  47. package/src/constants/{perpMarkets.js → markets.js} +11 -11
  48. package/src/dlob/DLOB.ts +884 -0
  49. package/src/dlob/DLOBNode.ts +163 -0
  50. package/src/dlob/NodeList.ts +185 -0
  51. package/src/events/eventList.js +23 -66
  52. package/src/events/txEventCache.js +19 -22
  53. package/src/examples/makeTradeExample.js +157 -0
  54. package/src/factory/bigNum.js +180 -183
  55. package/src/factory/oracleClient.js +9 -9
  56. package/src/idl/clearing_house.json +122 -202
  57. package/src/index.ts +5 -0
  58. package/src/math/auction.js +10 -10
  59. package/src/math/conversion.js +3 -4
  60. package/src/math/funding.js +175 -223
  61. package/src/math/market.ts +1 -1
  62. package/src/math/orders.ts +29 -21
  63. package/src/math/repeg.js +40 -40
  64. package/src/math/spotBalance.ts +26 -0
  65. package/src/math/spotPosition.ts +42 -1
  66. package/src/math/trade.js +74 -81
  67. package/src/math/utils.js +7 -8
  68. package/src/math/utils.js.map +1 -0
  69. package/src/oracles/oracleClientCache.js +9 -10
  70. package/src/oracles/pythClient.js +17 -52
  71. package/src/oracles/quoteAssetOracleClient.js +13 -44
  72. package/src/oracles/switchboardClient.js +37 -69
  73. package/src/oracles/types.js +1 -1
  74. package/src/token/index.js +4 -4
  75. package/src/tx/types.js +1 -1
  76. package/src/tx/utils.js +6 -7
  77. package/src/types.ts +25 -23
  78. package/src/userMap/userMap.ts +100 -0
  79. package/src/userMap/userStatsMap.ts +110 -0
  80. package/src/userName.js +5 -5
  81. package/src/util/computeUnits.js +11 -46
  82. package/src/util/getTokenAddress.js +9 -0
  83. package/src/util/promiseTimeout.js +5 -5
  84. package/src/util/tps.js +12 -46
  85. package/src/wallet.js +18 -55
  86. package/tests/bn/test.ts +2 -3
  87. package/tests/dlob/helpers.ts +322 -0
  88. package/tests/dlob/test.ts +2865 -0
  89. package/my-script/.env +0 -7
  90. package/my-script/getUserStats.ts +0 -106
  91. package/my-script/multiConnections.ts +0 -119
  92. package/my-script/test-regex.ts +0 -11
  93. package/my-script/utils.ts +0 -52
  94. package/src/accounts/bulkAccountLoader.js +0 -249
  95. package/src/accounts/bulkUserStatsSubscription.js +0 -75
  96. package/src/accounts/bulkUserSubscription.js +0 -75
  97. package/src/accounts/fetch.js +0 -92
  98. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
  99. package/src/accounts/pollingOracleSubscriber.js +0 -156
  100. package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
  101. package/src/accounts/pollingUserAccountSubscriber.js +0 -208
  102. package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
  103. package/src/accounts/types.js +0 -28
  104. package/src/accounts/utils.js +0 -7
  105. package/src/accounts/webSocketAccountSubscriber.js +0 -138
  106. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
  107. package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
  108. package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
  109. package/src/addresses/pda.js +0 -186
  110. package/src/admin.js +0 -1284
  111. package/src/clearingHouse.js +0 -3433
  112. package/src/clearingHouseConfig.js +0 -2
  113. package/src/clearingHouseUser.js +0 -874
  114. package/src/clearingHouseUserConfig.js +0 -2
  115. package/src/clearingHouseUserStats.js +0 -115
  116. package/src/clearingHouseUserStatsConfig.js +0 -2
  117. package/src/config.js +0 -80
  118. package/src/constants/numericConstants.js +0 -48
  119. package/src/constants/spotMarkets.js +0 -51
  120. package/src/events/eventSubscriber.js +0 -202
  121. package/src/events/fetchLogs.js +0 -117
  122. package/src/events/pollingLogProvider.js +0 -113
  123. package/src/events/sort.js +0 -41
  124. package/src/events/types.js +0 -25
  125. package/src/events/webSocketLogProvider.js +0 -76
  126. package/src/index.js +0 -75
  127. package/src/math/amm.js +0 -422
  128. package/src/math/insurance.js +0 -27
  129. package/src/math/margin.js +0 -77
  130. package/src/math/market.js +0 -105
  131. package/src/math/oracles.js +0 -56
  132. package/src/math/orders.js +0 -153
  133. package/src/math/position.js +0 -172
  134. package/src/math/spotBalance.js +0 -176
  135. package/src/math/spotMarket.js +0 -8
  136. package/src/math/spotPosition.js +0 -8
  137. package/src/orderParams.js +0 -28
  138. package/src/serum/serumSubscriber.js +0 -102
  139. package/src/serum/types.js +0 -2
  140. package/src/slot/SlotSubscriber.js +0 -86
  141. package/src/tokenFaucet.js +0 -323
  142. package/src/tx/retryTxSender.js +0 -280
  143. package/src/types.js +0 -216
@@ -53,6 +53,7 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
53
53
  getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
54
54
  getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
55
55
  getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
56
+ getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
56
57
  getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
57
58
  }
58
59
  declare type ClearingHouseAccounts = {
@@ -262,6 +262,9 @@ class PollingClearingHouseAccountSubscriber {
262
262
  getSpotMarketAccountAndSlot(marketIndex) {
263
263
  return this.spotMarket.get(marketIndex.toNumber());
264
264
  }
265
+ getSpotMarketAccountsAndSlots() {
266
+ return Array.from(this.spotMarket.values());
267
+ }
265
268
  getOraclePriceDataAndSlot(oraclePublicKey) {
266
269
  this.assertIsSubscribed();
267
270
  if (oraclePublicKey.equals(web3_js_1.PublicKey.default)) {
@@ -38,6 +38,7 @@ export interface ClearingHouseAccountSubscriber {
38
38
  getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
39
39
  getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
40
40
  getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
41
+ getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
41
42
  getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
42
43
  }
43
44
  export interface UserAccountEvents {
@@ -45,5 +45,6 @@ export declare class WebSocketClearingHouseAccountSubscriber implements Clearing
45
45
  getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
46
46
  getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
47
47
  getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
48
+ getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
48
49
  getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
49
50
  }
@@ -181,6 +181,9 @@ class WebSocketClearingHouseAccountSubscriber {
181
181
  return this.spotMarketAccountSubscribers.get(marketIndex.toNumber())
182
182
  .dataAndSlot;
183
183
  }
184
+ getSpotMarketAccountsAndSlots() {
185
+ return Array.from(this.spotMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
186
+ }
184
187
  getOraclePriceDataAndSlot(oraclePublicKey) {
185
188
  this.assertIsSubscribed();
186
189
  if (oraclePublicKey.equals(web3_js_1.PublicKey.default)) {
package/lib/admin.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare class Admin extends ClearingHouse {
10
10
  initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidationFee?: BN): Promise<TransactionSignature>;
11
11
  moveAmmPrice(marketIndex: BN, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
12
12
  updateK(sqrtK: BN, marketIndex: BN): Promise<TransactionSignature>;
13
+ updateConcentrationScale(marketIndex: BN, concentrationScale: BN): Promise<TransactionSignature>;
13
14
  moveAmmToPrice(perpMarketIndex: BN, targetPrice: BN): Promise<TransactionSignature>;
14
15
  repegAmmCurve(newPeg: BN, marketIndex: BN): Promise<TransactionSignature>;
15
16
  updateAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
@@ -32,7 +33,8 @@ export declare class Admin extends ClearingHouse {
32
33
  updateFee(fees: FeeStructure): Promise<TransactionSignature>;
33
34
  updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
34
35
  updateWithdrawGuardThreshold(marketIndex: BN, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
35
- updateSpotMarketIfFactor(marketIndex: BN, userIfFactor: BN, totalIfFactor: BN, liquidationIfFactor: BN): Promise<TransactionSignature>;
36
+ updateSpotMarketIfFactor(marketIndex: BN, userIfFactor: BN, totalIfFactor: BN): Promise<TransactionSignature>;
37
+ updateSpotMarketRevenueSettlePeriod(marketIndex: BN, revenueSettlePeriod: BN): Promise<TransactionSignature>;
36
38
  updateInsuranceWithdrawEscrowPeriod(marketIndex: BN, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionSignature>;
37
39
  updateLpCooldownTime(marketIndex: BN, cooldownTime: BN): Promise<TransactionSignature>;
38
40
  updateMarketOracle(marketIndex: BN, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
@@ -45,7 +47,8 @@ export declare class Admin extends ClearingHouse {
45
47
  updateFundingPaused(fundingPaused: boolean): Promise<TransactionSignature>;
46
48
  updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
47
49
  disableAdminControlsPrices(): Promise<TransactionSignature>;
48
- updateAuctionDuration(minDuration: BN | number, maxDuration: BN | number): Promise<TransactionSignature>;
50
+ updatePerpAuctionDuration(minDuration: BN | number): Promise<TransactionSignature>;
51
+ updateSpotAuctionDuration(defaultAuctionDuration: number): Promise<TransactionSignature>;
49
52
  updateMaxBaseAssetAmountRatio(marketIndex: BN, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
50
53
  updateMaxSlippageRatio(marketIndex: BN, maxSlippageRatio: number): Promise<TransactionSignature>;
51
54
  updateMarketMaxImbalances(marketIndex: BN, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionSignature>;
package/lib/admin.js CHANGED
@@ -148,6 +148,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
148
148
  },
149
149
  });
150
150
  }
151
+ async updateConcentrationScale(marketIndex, concentrationScale) {
152
+ return await this.program.rpc.updateConcentrationScale(concentrationScale, {
153
+ accounts: {
154
+ state: await this.getStatePublicKey(),
155
+ admin: this.wallet.publicKey,
156
+ market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
157
+ },
158
+ });
159
+ }
151
160
  async moveAmmToPrice(perpMarketIndex, targetPrice) {
152
161
  const market = this.getPerpMarketAccount(perpMarketIndex);
153
162
  const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
@@ -373,8 +382,17 @@ class Admin extends clearingHouse_1.ClearingHouse {
373
382
  },
374
383
  });
375
384
  }
376
- async updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, liquidationIfFactor) {
377
- return await this.program.rpc.updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, liquidationIfFactor, {
385
+ async updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor) {
386
+ return await this.program.rpc.updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, {
387
+ accounts: {
388
+ admin: this.wallet.publicKey,
389
+ state: await this.getStatePublicKey(),
390
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
391
+ },
392
+ });
393
+ }
394
+ async updateSpotMarketRevenueSettlePeriod(marketIndex, revenueSettlePeriod) {
395
+ return await this.program.rpc.updateSpotMarketRevenueSettlePeriod(revenueSettlePeriod, {
378
396
  accounts: {
379
397
  admin: this.wallet.publicKey,
380
398
  state: await this.getStatePublicKey(),
@@ -484,8 +502,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
484
502
  },
485
503
  });
486
504
  }
487
- async updateAuctionDuration(minDuration, maxDuration) {
488
- return await this.program.rpc.updateAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(), {
505
+ async updatePerpAuctionDuration(minDuration) {
506
+ return await this.program.rpc.updatePerpAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), {
507
+ accounts: {
508
+ admin: this.wallet.publicKey,
509
+ state: await this.getStatePublicKey(),
510
+ },
511
+ });
512
+ }
513
+ async updateSpotAuctionDuration(defaultAuctionDuration) {
514
+ return await this.program.rpc.updateSpotAuctionDuration(defaultAuctionDuration, {
489
515
  accounts: {
490
516
  admin: this.wallet.publicKey,
491
517
  state: await this.getStatePublicKey(),
@@ -53,6 +53,7 @@ export declare class ClearingHouse {
53
53
  getPerpMarketAccount(marketIndex: BN | number): PerpMarketAccount | undefined;
54
54
  getPerpMarketAccounts(): PerpMarketAccount[];
55
55
  getSpotMarketAccount(marketIndex: BN | number): SpotMarketAccount | undefined;
56
+ getSpotMarketAccounts(): SpotMarketAccount[];
56
57
  getQuoteSpotMarketAccount(): SpotMarketAccount;
57
58
  getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
58
59
  getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
@@ -69,6 +70,7 @@ export declare class ClearingHouse {
69
70
  getInitializeUserInstructions(userId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
70
71
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
71
72
  updateUserName(name: string, userId?: number): Promise<TransactionSignature>;
73
+ updateUserCustomMarginRatio(marginRatio: number, userId?: number): Promise<TransactionSignature>;
72
74
  getUser(userId?: number): ClearingHouseUser;
73
75
  getUsers(): ClearingHouseUser[];
74
76
  getUserStats(): ClearingHouseUserStats;
@@ -188,6 +188,11 @@ class ClearingHouse {
188
188
  marketIndex = marketIndex instanceof anchor_1.BN ? marketIndex : new anchor_1.BN(marketIndex);
189
189
  return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).data;
190
190
  }
191
+ getSpotMarketAccounts() {
192
+ return this.accountSubscriber
193
+ .getSpotMarketAccountsAndSlots()
194
+ .map((value) => value.data);
195
+ }
191
196
  getQuoteSpotMarketAccount() {
192
197
  return this.accountSubscriber.getSpotMarketAccountAndSlot(numericConstants_1.QUOTE_SPOT_MARKET_INDEX).data;
193
198
  }
@@ -296,6 +301,14 @@ class ClearingHouse {
296
301
  },
297
302
  });
298
303
  }
304
+ async updateUserCustomMarginRatio(marginRatio, userId = 0) {
305
+ return await this.program.rpc.updateUserCustomMarginRatio(userId, marginRatio, {
306
+ accounts: {
307
+ user: await this.getUserAccountPublicKey(),
308
+ authority: this.wallet.publicKey,
309
+ },
310
+ });
311
+ }
299
312
  getUser(userId) {
300
313
  userId = userId !== null && userId !== void 0 ? userId : this.activeUserId;
301
314
  if (!this.users.has(userId)) {
@@ -384,7 +397,7 @@ class ClearingHouse {
384
397
  perpMarketAccountMap.set(params.readablePerpMarketIndex.toNumber(), {
385
398
  pubkey: marketAccount.pubkey,
386
399
  isSigner: false,
387
- isWritable: true,
400
+ isWritable: false,
388
401
  });
389
402
  oracleAccountMap.set(marketAccount.amm.oracle.toString(), {
390
403
  pubkey: marketAccount.amm.oracle,
@@ -6,7 +6,7 @@ import StrictEventEmitter from 'strict-event-emitter-types';
6
6
  import { ClearingHouse } from './clearingHouse';
7
7
  import { MarginCategory, Order, UserAccount, PerpPosition } from './types';
8
8
  import { UserAccountSubscriber, UserAccountEvents, DataAndSlot } from './accounts/types';
9
- import { PositionDirection, BN } from '.';
9
+ import { PositionDirection, BN, SpotMarketAccount } from '.';
10
10
  import { OraclePriceData } from './oracles/types';
11
11
  import { ClearingHouseUserConfig } from './clearingHouseUserConfig';
12
12
  export declare class ClearingHouseUser {
@@ -70,7 +70,7 @@ export declare class ClearingHouseUser {
70
70
  /**
71
71
  * @returns The margin requirement of a certain type (Initial or Maintenance) in USDC. : QUOTE_PRECISION
72
72
  */
73
- getMarginRequirement(type: MarginCategory, liquidationBuffer?: BN): BN;
73
+ getMarginRequirement(marginCategory: MarginCategory, liquidationBuffer?: BN): BN;
74
74
  /**
75
75
  * @returns The initial margin requirement in USDC. : QUOTE_PRECISION
76
76
  */
@@ -89,8 +89,10 @@ export declare class ClearingHouseUser {
89
89
  * @returns : Precision QUOTE_PRECISION
90
90
  */
91
91
  getUnrealizedFundingPNL(marketIndex?: BN): BN;
92
- getSpotMarketLiabilityValue(marketIndex?: BN, withWeightMarginCategory?: MarginCategory, liquidationBuffer?: BN): BN;
93
- getSpotMarketAssetValue(marketIndex?: BN, withWeightMarginCategory?: MarginCategory): BN;
92
+ getSpotMarketLiabilityValue(marketIndex?: BN, marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
93
+ getSpotLiabilityValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory, liquidationBuffer?: BN): BN;
94
+ getSpotMarketAssetValue(marketIndex?: BN, marginCategory?: MarginCategory, includeOpenOrders?: boolean): BN;
95
+ getSpotAssetValue(tokenAmount: BN, oraclePriceData: OraclePriceData, spotMarketAccount: SpotMarketAccount, marginCategory?: MarginCategory): BN;
94
96
  getNetSpotMarketValue(withWeightMarginCategory?: MarginCategory): BN;
95
97
  /**
96
98
  * calculates TotalCollateral: collateral + unrealized pnl
@@ -101,12 +103,12 @@ export declare class ClearingHouseUser {
101
103
  * calculates sum of position value across all positions in margin system
102
104
  * @returns : Precision QUOTE_PRECISION
103
105
  */
104
- getTotalPositionValue(): BN;
106
+ getTotalPerpPositionValue(marginCategory?: MarginCategory, liquidationBuffer?: BN, includeOpenOrders?: boolean): BN;
105
107
  /**
106
108
  * calculates position value in margin system
107
109
  * @returns : Precision QUOTE_PRECISION
108
110
  */
109
- getPositionValue(marketIndex: BN, oraclePriceData: OraclePriceData): BN;
111
+ getPerpPositionValue(marketIndex: BN, oraclePriceData: OraclePriceData): BN;
110
112
  getPositionSide(currentPosition: Pick<PerpPosition, 'baseAssetAmount'>): PositionDirection | undefined;
111
113
  /**
112
114
  * calculates average exit price (optionally for closing up to 100% of position)
@@ -117,7 +119,7 @@ export declare class ClearingHouseUser {
117
119
  * calculates current user leverage across all positions
118
120
  * @returns : Precision TEN_THOUSAND
119
121
  */
120
- getLeverage(): BN;
122
+ getLeverage(marginCategory?: MarginCategory): BN;
121
123
  /**
122
124
  * calculates max allowable leverage exceeding hitting requirement category
123
125
  * @params category {Initial, Partial, Maintenance}
@@ -128,7 +130,7 @@ export declare class ClearingHouseUser {
128
130
  * calculates margin ratio: total collateral / |total position value|
129
131
  * @returns : Precision TEN_THOUSAND
130
132
  */
131
- getMarginRatio(): BN;
133
+ getMarginRatio(marginCategory?: MarginCategory): BN;
132
134
  canBeLiquidated(): boolean;
133
135
  /**
134
136
  * Checks if any user position cumulative funding differs from respective market cumulative funding
@@ -191,7 +193,7 @@ export declare class ClearingHouseUser {
191
193
  * @param marketToIgnore
192
194
  * @returns positionValue : Precision QUOTE_PRECISION
193
195
  */
194
- private getTotalPositionValueExcludingMarket;
196
+ private getTotalPerpPositionValueExcludingMarket;
195
197
  private getOracleDataForMarket;
196
198
  private getOracleDataForSpotMarket;
197
199
  }