aftermath-ts-sdk 1.3.12-perps.1 → 1.3.12-pools-creation-fix.1

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 (106) hide show
  1. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +0 -3
  2. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +1 -1
  3. package/dist/general/apiHelpers/transactionsApiHelpers.js +0 -12
  4. package/dist/general/providers/aftermath.d.ts +5 -0
  5. package/dist/general/providers/aftermath.d.ts.map +1 -1
  6. package/dist/general/providers/aftermath.js +6 -1
  7. package/dist/general/providers/aftermathApi.d.ts +5 -0
  8. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  9. package/dist/general/providers/aftermathApi.js +5 -0
  10. package/dist/general/types/configTypes.d.ts +10 -0
  11. package/dist/general/types/configTypes.d.ts.map +1 -1
  12. package/dist/general/types/generalTypes.d.ts +0 -1
  13. package/dist/general/types/generalTypes.d.ts.map +1 -1
  14. package/dist/general/types/moveErrorsInterface.d.ts +1 -1
  15. package/dist/general/types/moveErrorsInterface.d.ts.map +1 -1
  16. package/dist/general/utils/caller.d.ts +4 -5
  17. package/dist/general/utils/caller.d.ts.map +1 -1
  18. package/dist/general/utils/caller.js +5 -12
  19. package/dist/general/utils/casting.d.ts +5 -4
  20. package/dist/general/utils/casting.d.ts.map +1 -1
  21. package/dist/general/utils/casting.js +5 -4
  22. package/dist/general/utils/helpers.d.ts +0 -1
  23. package/dist/general/utils/helpers.d.ts.map +1 -1
  24. package/dist/general/utils/helpers.js +6 -35
  25. package/dist/general/wallet/wallet.d.ts +1 -1
  26. package/dist/general/wallet/wallet.d.ts.map +1 -1
  27. package/dist/packages/coin/coin.d.ts +5 -1
  28. package/dist/packages/coin/coin.d.ts.map +1 -1
  29. package/dist/packages/coin/coin.js +12 -3
  30. package/dist/packages/farms/farms.d.ts +1 -1
  31. package/dist/packages/farms/farms.d.ts.map +1 -1
  32. package/dist/packages/farms/farmsStakedPosition.d.ts +1 -1
  33. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  34. package/dist/packages/farms/farmsStakingPool.d.ts +1 -1
  35. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  36. package/dist/packages/faucet/api/faucetApi.d.ts +17 -9
  37. package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
  38. package/dist/packages/faucet/api/faucetApi.js +49 -44
  39. package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +1 -1
  40. package/dist/packages/faucet/api/faucetApiCasting.js +5 -8
  41. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +4 -1
  42. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +1 -1
  43. package/dist/packages/faucet/faucet.d.ts +1 -1
  44. package/dist/packages/faucet/faucet.d.ts.map +1 -1
  45. package/dist/packages/faucet/faucet.js +1 -1
  46. package/dist/packages/faucet/faucetTypes.d.ts +3 -2
  47. package/dist/packages/faucet/faucetTypes.d.ts.map +1 -1
  48. package/dist/packages/multisig/multisig.d.ts +1 -1
  49. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  50. package/dist/packages/nftAmm/nftAmm.d.ts +1 -1
  51. package/dist/packages/nftAmm/nftAmm.d.ts.map +1 -1
  52. package/dist/packages/oracle/api/oracleApi.d.ts +21 -0
  53. package/dist/packages/oracle/api/oracleApi.d.ts.map +1 -0
  54. package/dist/packages/oracle/api/oracleApi.js +76 -0
  55. package/dist/packages/oracle/api/oracleApiCasting.d.ts +6 -0
  56. package/dist/packages/oracle/api/oracleApiCasting.d.ts.map +1 -0
  57. package/dist/packages/oracle/api/oracleApiCasting.js +25 -0
  58. package/dist/packages/oracle/oracle.d.ts +15 -0
  59. package/dist/packages/oracle/oracle.d.ts.map +1 -0
  60. package/dist/packages/oracle/oracle.js +46 -0
  61. package/dist/packages/oracle/oracleCastingTypes.d.ts +11 -0
  62. package/dist/packages/oracle/oracleCastingTypes.d.ts.map +1 -0
  63. package/dist/packages/oracle/oracleCastingTypes.js +2 -0
  64. package/dist/packages/oracle/oracleTypes.d.ts +10 -0
  65. package/dist/packages/oracle/oracleTypes.d.ts.map +1 -0
  66. package/dist/packages/oracle/oracleTypes.js +2 -0
  67. package/dist/packages/perpetuals/api/perpetualsApi.d.ts +204 -11
  68. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  69. package/dist/packages/perpetuals/api/perpetualsApi.js +614 -923
  70. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +18 -11
  71. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
  72. package/dist/packages/perpetuals/api/perpetualsApiCasting.js +190 -199
  73. package/dist/packages/perpetuals/perpetuals.d.ts +5 -39
  74. package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
  75. package/dist/packages/perpetuals/perpetuals.js +18 -99
  76. package/dist/packages/perpetuals/perpetualsAccount.d.ts +79 -108
  77. package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
  78. package/dist/packages/perpetuals/perpetualsAccount.js +119 -332
  79. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +148 -78
  80. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
  81. package/dist/packages/perpetuals/perpetualsMarket.d.ts +6 -29
  82. package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
  83. package/dist/packages/perpetuals/perpetualsMarket.js +16 -78
  84. package/dist/packages/perpetuals/perpetualsTypes.d.ts +259 -340
  85. package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
  86. package/dist/packages/perpetuals/perpetualsTypes.js +77 -17
  87. package/dist/packages/pools/pool.d.ts +1 -1
  88. package/dist/packages/pools/pool.d.ts.map +1 -1
  89. package/dist/packages/pools/pools.d.ts +1 -1
  90. package/dist/packages/pools/pools.d.ts.map +1 -1
  91. package/dist/packages/referralVault/referralVault.d.ts +1 -1
  92. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  93. package/dist/packages/staking/staking.d.ts +1 -1
  94. package/dist/packages/staking/staking.d.ts.map +1 -1
  95. package/dist/packages/sui/sui.d.ts +1 -1
  96. package/dist/packages/sui/sui.d.ts.map +1 -1
  97. package/dist/packages/suiFrens/stakedSuiFren.d.ts +1 -1
  98. package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +1 -1
  99. package/dist/packages/suiFrens/suiFren.d.ts +1 -1
  100. package/dist/packages/suiFrens/suiFren.d.ts.map +1 -1
  101. package/dist/packages/suiFrens/suiFrens.d.ts +1 -1
  102. package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -1
  103. package/dist/types.d.ts +1 -0
  104. package/dist/types.d.ts.map +1 -1
  105. package/dist/types.js +1 -0
  106. package/package.json +2 -1
@@ -27,24 +27,21 @@ const iFixedUtils_1 = require("../../general/utils/iFixedUtils");
27
27
  const utils_1 = require("../../general/utils");
28
28
  const perpetuals_1 = require("./perpetuals");
29
29
  const __1 = require("..");
30
- const transactions_1 = require("@mysten/sui/transactions");
31
- // TODO: create refresh account positions function ?
32
30
  class PerpetualsAccount extends caller_1.Caller {
33
31
  // =========================================================================
34
32
  // Constructor
35
33
  // =========================================================================
36
- constructor(account, accountCap, config, Provider) {
34
+ constructor(account, accountCap, config) {
37
35
  super(config, "perpetuals");
38
36
  this.account = account;
39
37
  this.accountCap = accountCap;
40
- this.Provider = Provider;
41
38
  // =========================================================================
42
39
  // Calculations
43
40
  // =========================================================================
44
41
  this.calcFreeCollateralForPosition = (inputs) => {
45
42
  var _a, _b;
46
43
  const marketId = inputs.market.marketId;
47
- const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market.emptyPosition();
44
+ const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
48
45
  const funding = this.calcUnrealizedFundingsForPosition(inputs);
49
46
  const { pnl, minInitialMargin } = this.calcPnLAndMarginForPosition(inputs);
50
47
  let collateralUsd = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.collateral) *
@@ -67,7 +64,7 @@ class PerpetualsAccount extends caller_1.Caller {
67
64
  var _a, _b;
68
65
  const { market, indexPrice, collateralPrice } = inputs;
69
66
  const marketId = market.marketId;
70
- const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : market.emptyPosition();
67
+ const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market });
71
68
  const funding = this.calcUnrealizedFundingsForPosition({
72
69
  market,
73
70
  position,
@@ -99,7 +96,7 @@ class PerpetualsAccount extends caller_1.Caller {
99
96
  this.calcUnrealizedFundingsForPosition = (inputs) => {
100
97
  var _a, _b;
101
98
  const marketId = inputs.market.marketId;
102
- const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market.emptyPosition();
99
+ const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
103
100
  const baseAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.baseAssetAmount);
104
101
  const isLong = Math.sign(baseAmount);
105
102
  if (isLong < 0) {
@@ -116,8 +113,8 @@ class PerpetualsAccount extends caller_1.Caller {
116
113
  this.calcPnLAndMarginForPosition = (inputs) => {
117
114
  var _a, _b;
118
115
  const marketId = inputs.market.marketId;
119
- const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market.emptyPosition();
120
- const marginRatioInitial = 1 / (position.leverage || 1);
116
+ const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
117
+ const marginRatioInitial = 1 / position.leverage;
121
118
  // const marginRatioInitial = inputs.market.initialMarginRatio();
122
119
  const marginRatioMaintenance = iFixedUtils_1.IFixedUtils.numberFromIFixed(inputs.market.marketParams.marginRatioMaintenance);
123
120
  const baseAssetAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.baseAssetAmount);
@@ -134,28 +131,29 @@ class PerpetualsAccount extends caller_1.Caller {
134
131
  this.calcLiquidationPriceForPosition = (inputs) => {
135
132
  var _a, _b;
136
133
  const marketId = inputs.market.marketId;
137
- const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market.emptyPosition();
134
+ const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
138
135
  const funding = this.calcUnrealizedFundingsForPosition(inputs);
136
+ const collateralUsd = iFixedUtils_1.IFixedUtils.numberFromIFixed(position === null || position === void 0 ? void 0 : position.collateral) *
137
+ inputs.collateralPrice +
138
+ funding;
139
139
  const baseAssetAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.baseAssetAmount);
140
140
  const quoteAssetAmount = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.quoteAssetNotionalAmount);
141
- const numerator = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.collateral) *
142
- inputs.collateralPrice +
143
- funding -
144
- quoteAssetAmount;
145
141
  const MMR = iFixedUtils_1.IFixedUtils.numberFromIFixed(inputs.market.marketParams.marginRatioMaintenance);
146
- const bidsQuantity = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.bidsQuantity);
147
- const asksQuantity = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.asksQuantity);
148
- const netAbs = Math.max(Math.abs(baseAssetAmount + bidsQuantity), Math.abs(baseAssetAmount - asksQuantity));
149
- const denominator = netAbs * MMR - baseAssetAmount;
150
- if (!denominator)
151
- return 0;
152
- const liquidationPrice = numerator / denominator;
153
- return liquidationPrice <= 0 ? 0 : liquidationPrice;
142
+ const numerator = collateralUsd - quoteAssetAmount;
143
+ const price = (() => {
144
+ if (baseAssetAmount > 0) {
145
+ return numerator / ((1 - MMR) * -baseAssetAmount);
146
+ }
147
+ else {
148
+ return numerator / ((1 + MMR) * -baseAssetAmount);
149
+ }
150
+ })();
151
+ return price < 0 ? 0 : price;
154
152
  };
155
153
  this.calcFreeMarginUsdForPosition = (inputs) => {
156
154
  var _a, _b;
157
155
  const marketId = inputs.market.marketId;
158
- const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : inputs.market.emptyPosition();
156
+ const position = (_b = (_a = inputs.position) !== null && _a !== void 0 ? _a : this.positionForMarketId({ marketId })) !== null && _b !== void 0 ? _b : this.emptyPosition({ market: inputs.market });
159
157
  const totalFunding = this.calcUnrealizedFundingsForPosition(inputs);
160
158
  const { pnl, minInitialMargin } = this.calcPnLAndMarginForPosition(inputs);
161
159
  let collateralUsd = iFixedUtils_1.IFixedUtils.numberFromIFixed(position.collateral) *
@@ -176,7 +174,7 @@ class PerpetualsAccount extends caller_1.Caller {
176
174
  zipped.forEach(([market, indexPrice]) => {
177
175
  var _a;
178
176
  const marketId = market.marketId;
179
- const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a : market.emptyPosition();
177
+ const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a : this.emptyPosition({ market });
180
178
  const funding = this.calcUnrealizedFundingsForPosition({
181
179
  market,
182
180
  position,
@@ -202,9 +200,9 @@ class PerpetualsAccount extends caller_1.Caller {
202
200
  };
203
201
  this.closePositionTxInputs = (inputs) => {
204
202
  var _a;
205
- const { size, market, orderDatas, collateralPrice } = inputs;
203
+ const { size, market, walletAddress, orderDatas, collateralPrice } = inputs;
206
204
  const marketId = market.marketId;
207
- const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a : market.emptyPosition();
205
+ const position = (_a = this.positionForMarketId({ marketId })) !== null && _a !== void 0 ? _a : this.emptyPosition({ market });
208
206
  // TODO: move conversion to helper function, since used often
209
207
  const ordersCollateral = __1.Coin.normalizeBalance(utils_1.Helpers.sum(orderDatas
210
208
  .filter((orderData) => orderData.marketId === market.marketId)
@@ -216,31 +214,37 @@ class PerpetualsAccount extends caller_1.Caller {
216
214
  .closePositionMarginOfError))), BigInt(0)) * BigInt(-1);
217
215
  const positionSize = BigInt(Math.round(Math.abs(utils_1.Casting.IFixed.numberFromIFixed(position.baseAssetAmount) /
218
216
  market.lotSize())));
219
- // NOTE: is this safe / correct ?
220
- const collateralChange = __1.Coin.balanceWithDecimals(BigInt(Math.round(Number(fullPositionCollateralChange) *
221
- (Number(size) / Number(positionSize)))), this.collateralDecimals());
217
+ const collateralChange = BigInt(Math.round(Number(fullPositionCollateralChange) *
218
+ (Number(size) / Number(positionSize))));
222
219
  const positionSide = perpetuals_1.Perpetuals.positionSide(position);
223
220
  return {
224
221
  size,
225
222
  marketId,
223
+ walletAddress,
226
224
  collateralChange,
227
- // leverage: position.leverage || 1,
228
- // leverage: undefined,
229
225
  side: positionSide === types_1.PerpetualsOrderSide.Bid
230
226
  ? types_1.PerpetualsOrderSide.Ask
231
227
  : types_1.PerpetualsOrderSide.Bid,
232
- // hasPosition: this.positionForMarketId({ marketId }) !== undefined,
228
+ hasPosition: this.positionForMarketId({ marketId }) !== undefined,
233
229
  };
234
230
  };
235
- // =========================================================================
236
- // Private Helpers
237
- // =========================================================================
238
- this.useProvider = () => {
239
- var _a;
240
- const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Perpetuals();
241
- if (!provider)
242
- throw new Error("missing AftermathApi Provider");
243
- return provider;
231
+ this.emptyPosition = (inputs) => {
232
+ const { market } = inputs;
233
+ return {
234
+ marketId: market.marketId,
235
+ collateralCoinType: this.accountCap.collateralCoinType,
236
+ collateral: BigInt(0),
237
+ baseAssetAmount: BigInt(0),
238
+ quoteAssetNotionalAmount: BigInt(0),
239
+ cumFundingRateLong: market.marketState.cumFundingRateLong,
240
+ cumFundingRateShort: market.marketState.cumFundingRateShort,
241
+ asksQuantity: BigInt(0),
242
+ bidsQuantity: BigInt(0),
243
+ pendingOrders: [],
244
+ makerFee: BigInt(1000000000000000000), // 100%
245
+ takerFee: BigInt(1000000000000000000), // 100%
246
+ leverage: 1,
247
+ };
244
248
  };
245
249
  }
246
250
  // =========================================================================
@@ -251,81 +255,29 @@ class PerpetualsAccount extends caller_1.Caller {
251
255
  // =========================================================================
252
256
  getDepositCollateralTx(inputs) {
253
257
  return __awaiter(this, void 0, void 0, function* () {
254
- var _a;
255
- const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
256
- return this.fetchApiTransaction("transactions/deposit-collateral", Object.assign(Object.assign({}, otherInputs), { walletAddress: this.accountCap.walletAddress, collateralCoinType: this.accountCap.collateralCoinType, accountObjectId: this.accountCap.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
257
- tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
258
- })) }), undefined, {
259
- txKind: true,
260
- });
258
+ return this.fetchApiTransaction("transactions/deposit-collateral", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
261
259
  });
262
260
  }
263
261
  getWithdrawCollateralTx(inputs) {
264
262
  return __awaiter(this, void 0, void 0, function* () {
265
- var _a;
266
- const { withdrawAmount, recipientAddress, tx: txFromInputs } = inputs;
267
- const { txKind, coinOutArg } = yield this.fetchApi("transactions/withdraw-collateral", {
268
- withdrawAmount,
269
- recipientAddress,
270
- walletAddress: this.accountCap.walletAddress,
271
- collateralCoinType: this.accountCap.collateralCoinType,
272
- accountObjectId: this.accountCap.objectId,
273
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
274
- tx: txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction(),
275
- })),
276
- });
277
- const tx = transactions_1.Transaction.fromKind(txKind);
278
- tx.setSender(this.accountCap.walletAddress);
279
- return {
280
- tx,
281
- coinOutArg,
282
- };
263
+ return this.fetchApiTransaction("transactions/withdraw-collateral", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
283
264
  });
284
265
  }
285
266
  getAllocateCollateralTx(inputs) {
286
267
  return __awaiter(this, void 0, void 0, function* () {
287
- var _a;
288
- const { tx, allocateAmount, marketId } = inputs;
289
- return this.fetchApiTransaction("transactions/allocate-collateral", {
290
- marketId,
291
- allocateAmount,
292
- accountObjectId: this.accountCap.objectId,
293
- walletAddress: this.accountCap.walletAddress,
294
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })),
295
- }, undefined, {
296
- txKind: true,
297
- });
268
+ const { market } = inputs;
269
+ return this.fetchApiTransaction("transactions/allocate-collateral", Object.assign(Object.assign({}, inputs), { packageId: market.marketData.packageId, marketInitialSharedVersion: market.marketData.initialSharedVersion, marketId: market.marketId, collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
298
270
  });
299
271
  }
300
272
  getDeallocateCollateralTx(inputs) {
301
273
  return __awaiter(this, void 0, void 0, function* () {
302
- var _a;
303
- const { tx, deallocateAmount, marketId } = inputs;
304
- return this.fetchApiTransaction("transactions/deallocate-collateral", {
305
- marketId,
306
- deallocateAmount,
307
- accountObjectId: this.accountCap.objectId,
308
- walletAddress: this.accountCap.walletAddress,
309
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })),
310
- }, undefined, {
311
- txKind: true,
312
- });
274
+ const { market } = inputs;
275
+ return this.fetchApiTransaction("transactions/deallocate-collateral", Object.assign(Object.assign({}, inputs), { packageId: market.marketData.packageId, marketInitialSharedVersion: market.marketData.initialSharedVersion, marketId: market.marketId, basePriceFeedId: market.marketParams.basePriceFeedId, collateralPriceFeedId: market.marketParams.collateralPriceFeedId, collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
313
276
  });
314
277
  }
315
278
  getTransferCollateralTx(inputs) {
316
279
  return __awaiter(this, void 0, void 0, function* () {
317
- var _a;
318
- const { transferAmount, toAccountObjectId, tx } = inputs;
319
- return this.fetchApiTransaction("transactions/transfer-collateral", {
320
- transferAmount,
321
- toAccountObjectId,
322
- walletAddress: this.accountCap.walletAddress,
323
- collateralCoinType: this.accountCap.collateralCoinType,
324
- fromAccountObjectId: this.accountCap.objectId,
325
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })),
326
- }, undefined, {
327
- txKind: true,
328
- });
280
+ return this.fetchApiTransaction("transactions/transfer-collateral", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, fromAccountCapId: this.accountCap.objectId }));
329
281
  });
330
282
  }
331
283
  // =========================================================================
@@ -333,119 +285,33 @@ class PerpetualsAccount extends caller_1.Caller {
333
285
  // =========================================================================
334
286
  getPlaceMarketOrderTx(inputs) {
335
287
  return __awaiter(this, void 0, void 0, function* () {
336
- var _a;
337
- const { tx: txFromInputs, slTp } = inputs, otherInputs = __rest(inputs, ["tx", "slTp"]);
338
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
339
- // tx.setSender(this.accountCap.walletAddress);
340
- return this.fetchApiTransaction("transactions/place-market-order", Object.assign(Object.assign({}, otherInputs), { slTp: slTp
341
- ? Object.assign({ walletAddress: this.accountCap.walletAddress }, slTp) : undefined, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId, hasPosition: this.positionForMarketId(otherInputs) !== undefined }), undefined, {
342
- txKind: true,
343
- });
288
+ return this.fetchApiTransaction("transactions/market-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, accountObjectVersion: this.accountCap.objectVersion, accountObjectDigest: this.accountCap.objectDigest, hasPosition: this.positionForMarketId(inputs) !== undefined }));
344
289
  });
345
290
  }
346
291
  getPlaceLimitOrderTx(inputs) {
347
292
  return __awaiter(this, void 0, void 0, function* () {
348
- var _a;
349
- const { tx: txFromInputs, slTp } = inputs, otherInputs = __rest(inputs, ["tx", "slTp"]);
350
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
351
- // tx.setSender(this.accountCap.walletAddress);
352
- return this.fetchApiTransaction("transactions/place-limit-order", Object.assign(Object.assign({}, otherInputs), { slTp: slTp
353
- ? Object.assign({ walletAddress: this.accountCap.walletAddress }, slTp) : undefined, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId, hasPosition: this.positionForMarketId(otherInputs) !== undefined }), undefined, {
354
- txKind: true,
355
- });
293
+ return this.fetchApiTransaction("transactions/limit-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, accountObjectVersion: this.accountCap.objectVersion, accountObjectDigest: this.accountCap.objectDigest, hasPosition: this.positionForMarketId(inputs) !== undefined }));
356
294
  });
357
295
  }
358
- getCancelOrdersTx(inputs) {
296
+ getPlaceSLTPOrder(inputs) {
359
297
  return __awaiter(this, void 0, void 0, function* () {
360
- var _a;
361
- const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
362
- return this.fetchApiTransaction("transactions/cancel-orders", Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId }), undefined, {
363
- txKind: true,
364
- });
298
+ return this.fetchApiTransaction("transactions/sltp-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, accountObjectVersion: this.accountCap.objectVersion, accountObjectDigest: this.accountCap.objectDigest }));
365
299
  });
366
300
  }
367
- getCancelStopOrdersTx(inputs) {
301
+ getCancelOrderTx(inputs) {
368
302
  return __awaiter(this, void 0, void 0, function* () {
369
- var _a;
370
- const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
371
- return this.fetchApiTransaction("transactions/cancel-stop-orders", Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId }), undefined, {
372
- txKind: true,
373
- });
374
- });
375
- }
376
- getPlaceStopOrdersTx(inputs) {
377
- return __awaiter(this, void 0, void 0, function* () {
378
- var _a;
379
- const { tx: txFromInputs, isSponsoredTx, stopOrders, gasCoinArg, } = inputs;
380
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
381
- // tx.setSender(this.accountCap.walletAddress);
382
- return this.fetchApiTransaction("transactions/place-stop-orders", {
383
- stopOrders,
384
- gasCoinArg,
385
- isSponsoredTx,
386
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
387
- walletAddress: this.accountCap.walletAddress,
388
- accountObjectId: this.accountCap.objectId,
389
- }, undefined, {
390
- txKind: true,
391
- });
303
+ return this.fetchApiTransaction("transactions/cancel-order", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
392
304
  });
393
305
  }
394
- getPlaceSlTpOrdersTx(inputs) {
395
- return __awaiter(this, void 0, void 0, function* () {
396
- var _a;
397
- const { tx: txFromInputs, isSponsoredTx, marketId } = inputs, slTpInputs = __rest(inputs, ["tx", "isSponsoredTx", "marketId"]);
398
- const position = this.positionForMarketId({ marketId });
399
- if (!position)
400
- throw new Error("you have no position for this market");
401
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
402
- // tx.setSender(this.accountCap.walletAddress);
403
- return this.fetchApiTransaction("transactions/place-sl-tp-orders", Object.assign(Object.assign({}, slTpInputs), { marketId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId, positionSide: perpetuals_1.Perpetuals.positionSide({
404
- baseAssetAmount: position.baseAssetAmount,
405
- }) }), undefined, {
406
- txKind: true,
407
- });
408
- });
409
- }
410
- getEditStopOrdersTx(inputs) {
411
- return __awaiter(this, void 0, void 0, function* () {
412
- var _a;
413
- const { tx: txFromInputs, stopOrders } = inputs;
414
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
415
- // tx.setSender(this.accountCap.walletAddress);
416
- return this.fetchApiTransaction("transactions/edit-stop-orders", {
417
- stopOrders,
418
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
419
- walletAddress: this.accountCap.walletAddress,
420
- accountObjectId: this.accountCap.objectId,
421
- }, undefined, {
422
- txKind: true,
423
- });
424
- });
425
- }
426
- getReduceOrderTx(inputs) {
306
+ getCancelOrdersTx(inputs) {
427
307
  return __awaiter(this, void 0, void 0, function* () {
428
- var _a;
429
- const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
430
- return this.fetchApiTransaction("transactions/reduce-order", Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.accountCap.walletAddress, accountObjectId: this.accountCap.objectId }), undefined, {
431
- txKind: true,
432
- });
308
+ return this.fetchApiTransaction("transactions/cancel-orders", Object.assign(Object.assign({}, inputs), { collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
433
309
  });
434
310
  }
435
- getSetLeverageTx(inputs) {
311
+ getReduceOrdersTx(inputs) {
436
312
  return __awaiter(this, void 0, void 0, function* () {
437
- var _a;
438
- const { leverage, tx, collateralChange, marketId } = inputs;
439
- return this.fetchApiTransaction("transactions/set-leverage", {
440
- leverage,
441
- marketId,
442
- collateralChange,
443
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })),
444
- walletAddress: this.accountCap.walletAddress,
445
- accountObjectId: this.accountCap.objectId,
446
- }, undefined, {
447
- txKind: true,
448
- });
313
+ const { market, orderDatas } = inputs;
314
+ return this.fetchApiTransaction("transactions/reduce-orders", Object.assign(Object.assign({}, inputs), { orderIds: orderDatas.map((order) => order.orderId), sizesToSubtract: orderDatas.map((order) => order.sizeToSubtract), packageId: market.marketData.packageId, marketInitialSharedVersion: market.marketData.initialSharedVersion, marketId: market.marketId, basePriceFeedId: market.marketParams.basePriceFeedId, collateralPriceFeedId: market.marketParams.collateralPriceFeedId, collateralCoinType: this.accountCap.collateralCoinType, accountCapId: this.accountCap.objectId }));
449
315
  });
450
316
  }
451
317
  // =========================================================================
@@ -453,52 +319,77 @@ class PerpetualsAccount extends caller_1.Caller {
453
319
  // =========================================================================
454
320
  getClosePositionTx(inputs) {
455
321
  return __awaiter(this, void 0, void 0, function* () {
456
- return this.getPlaceMarketOrderTx(Object.assign({}, this.closePositionTxInputs(inputs)));
322
+ return this.getPlaceMarketOrderTx(this.closePositionTxInputs(inputs));
457
323
  });
458
324
  }
459
325
  // =========================================================================
460
- // Interactions
326
+ // Inspections
461
327
  // =========================================================================
462
- getStopOrdersMessageToSign(inputs) {
463
- var _a;
328
+ setPositionLeverage(inputs) {
329
+ return __awaiter(this, void 0, void 0, function* () {
330
+ return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/set-position-leverage`, inputs);
331
+ });
332
+ }
333
+ // public async getAllPositionLeverages(): Promise<
334
+ // {
335
+ // marketId: PerpetualsMarketId;
336
+ // leverage: number;
337
+ // }[]
338
+ // > {
339
+ // return this.fetchApi(
340
+ // `${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/position-leverages`
341
+ // );
342
+ // }
343
+ getPositionLeverages(inputs) {
344
+ return __awaiter(this, void 0, void 0, function* () {
345
+ return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/position-leverages/${JSON.stringify(inputs.marketIds)}`);
346
+ });
347
+ }
348
+ setPositionLeverageMessageToSign(inputs) {
464
349
  return {
465
- action: "GET_STOP_ORDERS",
466
- account_id: this.accountCap.accountId
467
- .toString()
468
- .replaceAll("n", ""),
469
- clearing_house_ids: (_a = inputs === null || inputs === void 0 ? void 0 : inputs.marketIds) !== null && _a !== void 0 ? _a : [],
350
+ account_id: Number(this.accountCap.accountId),
351
+ market_id: inputs.marketId,
352
+ leverage: inputs.leverage,
470
353
  };
471
354
  }
472
- getPlaceOrderPreview(inputs, abortSignal) {
355
+ getOrderPreview(inputs, abortSignal) {
473
356
  return __awaiter(this, void 0, void 0, function* () {
474
- return this.fetchApi("previews/place-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, collateralCoinType: this.accountCap.collateralCoinType }), abortSignal);
357
+ const response = yield this.fetchApi("preview-order", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId, collateralCoinType: this.accountCap.collateralCoinType }), abortSignal);
358
+ if ("error" in response)
359
+ return response;
360
+ const { collateralChange } = response, remainingResponse = __rest(response, ["collateralChange"]);
361
+ return Object.assign(Object.assign({}, remainingResponse), { collateralChange: __1.Coin.normalizeBalance(collateralChange, this.collateralDecimals()) });
475
362
  });
476
363
  }
477
- getCancelOrdersPreview(inputs, abortSignal) {
364
+ getCancelOrdersPreview(inputs) {
478
365
  return __awaiter(this, void 0, void 0, function* () {
479
366
  // NOTE: should this case return an error instead ?
480
367
  if (Object.keys(inputs.marketIdsToData).length <= 0)
481
368
  return {
482
- collateralChange: 0,
369
+ collateralChange: BigInt(0),
483
370
  marketIdsToPositionAfterCancelOrders: {},
484
371
  };
485
- return this.fetchApi("previews/cancel-orders", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, collateralCoinType: this.accountCap.collateralCoinType }), abortSignal);
486
- });
487
- }
488
- getReduceOrderPreview(inputs, abortSignal) {
489
- return __awaiter(this, void 0, void 0, function* () {
490
- return this.fetchApi("previews/reduce-order", Object.assign(Object.assign({}, inputs), { accountObjectId: this.accountCap.objectId, collateralCoinType: this.accountCap.collateralCoinType }), abortSignal);
372
+ const response = yield this.fetchApi("preview-cancel-orders", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId, collateralCoinType: this.accountCap.collateralCoinType }));
373
+ if ("error" in response)
374
+ return response;
375
+ return {
376
+ marketIdsToPositionAfterCancelOrders: response.marketIdsToPositionAfterCancelOrders,
377
+ collateralChange: __1.Coin.normalizeBalance(response.collateralChange, this.collateralDecimals()),
378
+ };
491
379
  });
492
380
  }
493
- getSetLeveragePreview(inputs, abortSignal) {
381
+ getReduceOrdersPreview(inputs) {
494
382
  return __awaiter(this, void 0, void 0, function* () {
495
- const { marketId, leverage } = inputs;
496
- return this.fetchApi("previews/set-leverage", {
497
- marketId,
498
- leverage,
499
- accountObjectId: this.accountCap.objectId,
500
- collateralCoinType: this.accountCap.collateralCoinType,
501
- }, abortSignal);
383
+ // NOTE: should this case not throw an error instead ?
384
+ if (Object.keys(inputs.orderDatas).length <= 0)
385
+ throw new Error("no orderDatas provided");
386
+ const response = yield this.fetchApi("preview-reduce-orders", Object.assign(Object.assign({}, inputs), { orderIds: inputs.orderDatas.map((order) => order.orderId), sizesToSubtract: inputs.orderDatas.map((order) => order.sizeToSubtract), accountId: this.accountCap.accountId, collateralCoinType: this.accountCap.collateralCoinType }));
387
+ if ("error" in response)
388
+ return response;
389
+ return {
390
+ positionAfterReduceOrders: response.positionAfterReduceOrders,
391
+ collateralChange: __1.Coin.normalizeBalance(response.collateralChange, this.collateralDecimals()),
392
+ };
502
393
  });
503
394
  }
504
395
  getOrderDatas() {
@@ -512,40 +403,19 @@ class PerpetualsAccount extends caller_1.Caller {
512
403
  ], []);
513
404
  if (orderDatas.length <= 0)
514
405
  return [];
515
- return this.fetchApi("account/order-datas", {
516
- accountId: this.accountCap.accountId,
406
+ return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/order-datas`, {
517
407
  orderDatas,
518
408
  });
519
409
  });
520
410
  }
521
- getStopOrderDatas(inputs) {
522
- return __awaiter(this, void 0, void 0, function* () {
523
- const { bytes, signature, marketIds } = inputs;
524
- return this.fetchApi("account/stop-order-datas", {
525
- bytes,
526
- signature,
527
- accountId: this.accountCap.accountId,
528
- walletAddress: this.accountCap.walletAddress,
529
- marketIds: marketIds !== null && marketIds !== void 0 ? marketIds : [],
530
- });
531
- });
532
- }
533
411
  getCollateralHistory(inputs) {
534
412
  return __awaiter(this, void 0, void 0, function* () {
535
- return this.fetchApi("account/collateral-history", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId, collateralCoinType: this.accountCap.collateralCoinType }));
413
+ return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/collateral-history`, inputs);
536
414
  });
537
415
  }
538
416
  getOrderHistory(inputs) {
539
417
  return __awaiter(this, void 0, void 0, function* () {
540
- return this.fetchApi("account/trade-history", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId }));
541
- });
542
- }
543
- getMarginHistory() {
544
- return __awaiter(this, void 0, void 0, function* () {
545
- return this.fetchApi("account/trade-history", {
546
- accountId: this.accountCap.accountId,
547
- collateralCoinType: this.accountCap.collateralCoinType,
548
- });
418
+ return this.fetchApi(`${this.accountCap.collateralCoinType}/accounts/${this.accountCap.accountId}/order-history`, inputs);
549
419
  });
550
420
  }
551
421
  // =========================================================================
@@ -559,91 +429,8 @@ class PerpetualsAccount extends caller_1.Caller {
559
429
  return undefined;
560
430
  }
561
431
  }
562
- nonSlTpStopOrderDatas(inputs) {
563
- const { stopOrderDatas } = inputs;
564
- const slTpOrders = this.slTpStopOrderDatas(inputs);
565
- const stopOrders = stopOrderDatas.filter((stopOrder) => !(slTpOrders !== null && slTpOrders !== void 0 ? slTpOrders : [])
566
- .map((slTpOrder) => JSON.stringify(slTpOrder))
567
- .includes(JSON.stringify(stopOrder)));
568
- return stopOrders.length <= 0 ? undefined : stopOrders;
569
- }
570
- slTpStopOrderDatas(inputs) {
571
- const { stopOrderDatas } = inputs;
572
- let slTpOrders = [];
573
- for (const { marketId } of this.account.positions) {
574
- const { fullSlOrder, fullTpOrder, partialSlOrders, partialTpOrders, } = this.slTpStopOrderDatasForMarketId({
575
- marketId,
576
- stopOrderDatas,
577
- });
578
- slTpOrders = [
579
- ...slTpOrders,
580
- ...(fullSlOrder ? [fullSlOrder] : []),
581
- ...(fullTpOrder ? [fullTpOrder] : []),
582
- ...(partialSlOrders !== null && partialSlOrders !== void 0 ? partialSlOrders : []),
583
- ...(partialTpOrders !== null && partialTpOrders !== void 0 ? partialTpOrders : []),
584
- ];
585
- }
586
- return slTpOrders.length <= 0 ? undefined : slTpOrders;
587
- }
588
- nonSlTpStopOrderDatasForMarketId(inputs) {
589
- const { marketId, stopOrderDatas } = inputs;
590
- const position = this.positionForMarketId({ marketId });
591
- if (!position)
592
- return undefined;
593
- const { fullSlOrder, fullTpOrder, partialSlOrders, partialTpOrders } = this.slTpStopOrderDatasForMarketId(inputs);
594
- const stopOrders = stopOrderDatas.filter((stopOrder) => ![
595
- ...(fullSlOrder ? [fullSlOrder] : []),
596
- ...(fullTpOrder ? [fullTpOrder] : []),
597
- ...(partialSlOrders !== null && partialSlOrders !== void 0 ? partialSlOrders : []),
598
- ...(partialTpOrders !== null && partialTpOrders !== void 0 ? partialTpOrders : []),
599
- ]
600
- .map((slTpOrder) => JSON.stringify(slTpOrder))
601
- .includes(JSON.stringify(stopOrder)));
602
- return stopOrders.length <= 0 ? undefined : stopOrders;
603
- }
604
- slTpStopOrderDatasForMarketId(inputs) {
605
- const { marketId, stopOrderDatas } = inputs;
606
- const position = this.positionForMarketId({ marketId });
607
- if (!position || position.baseAssetAmount === BigInt(0)) {
608
- return {
609
- fullSlOrder: undefined,
610
- fullTpOrder: undefined,
611
- partialSlOrders: undefined,
612
- partialTpOrders: undefined,
613
- };
614
- }
615
- const side = !position ? undefined : perpetuals_1.Perpetuals.positionSide(position);
616
- // TODO: clean this up
617
- const fullSlOrder = stopOrderDatas.find((order) => order.marketId === marketId &&
618
- order.slTp &&
619
- order.side !== side &&
620
- order.slTp.isStopLoss &&
621
- order.size >= utils_1.Casting.i64MaxBigInt);
622
- const fullTpOrder = stopOrderDatas.find((order) => order.marketId === marketId &&
623
- order.slTp &&
624
- order.side !== side &&
625
- !order.slTp.isStopLoss &&
626
- order.size >= utils_1.Casting.i64MaxBigInt);
627
- const partialSlOrders = stopOrderDatas.filter((order) => order.marketId === marketId &&
628
- order.slTp &&
629
- order.side !== side &&
630
- order.slTp.isStopLoss &&
631
- order.size < utils_1.Casting.i64MaxBigInt);
632
- const partialTpOrders = stopOrderDatas.filter((order) => order.marketId === marketId &&
633
- order.slTp &&
634
- order.side !== side &&
635
- !order.slTp.isStopLoss &&
636
- order.size < utils_1.Casting.i64MaxBigInt);
637
- return {
638
- fullSlOrder,
639
- fullTpOrder,
640
- partialSlOrders: partialSlOrders.length <= 0 ? undefined : partialSlOrders,
641
- partialTpOrders: partialTpOrders.length <= 0 ? undefined : partialTpOrders,
642
- };
643
- }
644
432
  collateral() {
645
- return (utils_1.Casting.IFixed.numberFromIFixed(this.accountCap.collateral) +
646
- utils_1.Casting.IFixed.numberFromIFixed(this.accountCap.subAccount.collateral));
433
+ return utils_1.Casting.IFixed.numberFromIFixed(this.accountCap.collateral);
647
434
  }
648
435
  collateralDecimals() {
649
436
  return this.accountCap.collateralDecimals;