@reyaxyz/api-sdk 0.21.0 → 0.22.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.
@@ -17,10 +17,9 @@ var bignumber_js_1 = __importDefault(require("bignumber.js"));
17
17
  var lodash_1 = __importDefault(require("lodash"));
18
18
  var number_1 = require("./number");
19
19
  var ExposureCommand = /** @class */ (function () {
20
- function ExposureCommand(rootCollateralPoolId, oraclePrice, rate, accountBalancePerAsset, groupedByCollateral, riskMultipliers, riskMatrices, exchangeInfoPerAsset, positionInfoMarketConfiguration, uniqueTokenAddresses, uniqueQuoteCollaterals, tokenMarginInfoPerAsset, realizedPnLSum, unrealizedPnLSum) {
20
+ function ExposureCommand(rootCollateralPoolId, oraclePricePerMarket, accountBalancePerAsset, groupedByCollateral, riskMultipliers, riskMatrices, exchangeInfoPerAsset, positionInfoMarketConfiguration, uniqueTokenAddresses, uniqueQuoteCollaterals, tokenMarginInfoPerAsset, realizedPnLSum, unrealizedPnLSum) {
21
21
  this.rootCollateralPoolId = rootCollateralPoolId;
22
- this.oraclePrice = oraclePrice;
23
- this.rate = rate;
22
+ this.oraclePricePerMarket = oraclePricePerMarket;
24
23
  this.accountBalancePerAsset = accountBalancePerAsset;
25
24
  this.groupedByCollateral = groupedByCollateral;
26
25
  this.riskMultipliers = riskMultipliers;
@@ -36,8 +35,7 @@ var ExposureCommand = /** @class */ (function () {
36
35
  ExposureCommand.prototype.getState = function () {
37
36
  return {
38
37
  rootCollateralPoolId: this.rootCollateralPoolId,
39
- oraclePrice: this.oraclePrice,
40
- rate: this.rate,
38
+ oraclePricePerMarket: this.oraclePricePerMarket,
41
39
  accountBalancePerAsset: this.accountBalancePerAsset,
42
40
  groupedByCollateral: this.groupedByCollateral,
43
41
  riskMultipliers: this.riskMultipliers,
@@ -93,14 +91,14 @@ var ExposureCommand = /** @class */ (function () {
93
91
  }
94
92
  var uniqueQuoteCollaterals = new Set(this.uniqueQuoteCollaterals);
95
93
  uniqueQuoteCollaterals.add(collateralAddress);
96
- var tokenMarginInfoPerAsset = ExposureCommand.calculateTokenMarginInfoPerAsset(this.groupedByCollateral, this.rootCollateralPoolId, this.riskMatrices, this.riskMultipliers, uniqueQuoteCollaterals, this.realizedPnLSum, this.unrealizedPnLSum, positionInfoMarketConfiguration, this.oraclePrice);
94
+ var tokenMarginInfoPerAsset = ExposureCommand.calculateTokenMarginInfoPerAsset(this.groupedByCollateral, this.rootCollateralPoolId, this.riskMatrices, this.riskMultipliers, uniqueQuoteCollaterals, this.realizedPnLSum, this.unrealizedPnLSum, positionInfoMarketConfiguration, this.oraclePricePerMarket);
97
95
  var uniqueTokenAddresses = __spreadArray([], this.uniqueTokenAddresses, true);
98
96
  if (!this.uniqueTokenAddresses.includes(collateralAddress)) {
99
97
  uniqueTokenAddresses.push(collateralAddress);
100
98
  }
101
99
  return ExposureCommand.getUsdNodeMarginInfo(this.rootCollateralPoolId, uniqueTokenAddresses, this.exchangeInfoPerAsset, tokenMarginInfoPerAsset);
102
100
  };
103
- ExposureCommand.calculateTokenMarginInfoPerAsset = function (groupedByCollateral, rootCollateralPoolId, riskMatrices, riskMultipliers, uniqueQuoteCollaterals, realizedPnLSum, unrealizedPnLSum, positionInfoMarketConfiguration, oraclePrice) {
101
+ ExposureCommand.calculateTokenMarginInfoPerAsset = function (groupedByCollateral, rootCollateralPoolId, riskMatrices, riskMultipliers, uniqueQuoteCollaterals, realizedPnLSum, unrealizedPnLSum, positionInfoMarketConfiguration, oraclePricePerMarket) {
104
102
  var _a;
105
103
  var tokenMarginInfoPerAsset = [];
106
104
  var uniqueQuoteTokens = Array.from(uniqueQuoteCollaterals);
@@ -108,7 +106,7 @@ var ExposureCommand = /** @class */ (function () {
108
106
  var uniqueTokenAddresses = Array.from(tokenUnion);
109
107
  for (var _i = 0, uniqueTokenAddresses_1 = uniqueTokenAddresses; _i < uniqueTokenAddresses_1.length; _i++) {
110
108
  var token = uniqueTokenAddresses_1[_i];
111
- tokenMarginInfoPerAsset.push(ExposureCommand.getTokenMarginInfo(rootCollateralPoolId, riskMatrices, riskMultipliers, ExposureCommand.getCollateralInfo(token, uniqueQuoteCollaterals.has(token) ? realizedPnLSum : (0, bignumber_js_1.default)(0), uniqueQuoteCollaterals.has(token) ? unrealizedPnLSum : (0, bignumber_js_1.default)(0), ((_a = groupedByCollateral[token]) === null || _a === void 0 ? void 0 : _a.amount) || 0), token, positionInfoMarketConfiguration, oraclePrice));
109
+ tokenMarginInfoPerAsset.push(ExposureCommand.getTokenMarginInfo(rootCollateralPoolId, riskMatrices, riskMultipliers, ExposureCommand.getCollateralInfo(token, uniqueQuoteCollaterals.has(token) ? realizedPnLSum : (0, bignumber_js_1.default)(0), uniqueQuoteCollaterals.has(token) ? unrealizedPnLSum : (0, bignumber_js_1.default)(0), ((_a = groupedByCollateral[token]) === null || _a === void 0 ? void 0 : _a.amount) || 0), token, positionInfoMarketConfiguration, oraclePricePerMarket, uniqueQuoteTokens));
112
110
  }
113
111
  return tokenMarginInfoPerAsset;
114
112
  };
@@ -198,7 +196,7 @@ var ExposureCommand = /** @class */ (function () {
198
196
  realBalance: (0, bignumber_js_1.default)(netDeposits).plus(realisedPnl).toNumber(),
199
197
  };
200
198
  };
201
- ExposureCommand.getTokenMarginInfo = function (rootCollateralPoolId, riskMatrices, riskMultipliers, collateralInfo, collateralAddress, positions, oraclePrice) {
199
+ ExposureCommand.getTokenMarginInfo = function (rootCollateralPoolId, riskMatrices, riskMultipliers, collateralInfo, collateralAddress, positions, oraclePricePerMarket, uniqueQuoteTokens) {
202
200
  var marginRequirements = {
203
201
  liquidationMarginRequirement: 0,
204
202
  initialMarginRequirement: 0,
@@ -207,33 +205,36 @@ var ExposureCommand = /** @class */ (function () {
207
205
  adlMarginRequirement: 0,
208
206
  initialBufferMarginRequirement: 0,
209
207
  };
210
- for (var _i = 0, riskMatrices_1 = riskMatrices; _i < riskMatrices_1.length; _i++) {
211
- var riskMatrix = riskMatrices_1[_i];
212
- var filledExposures = ExposureCommand.getBlockExposures(positions, oraclePrice);
213
- marginRequirements.liquidationMarginRequirement = (0, bignumber_js_1.default)(marginRequirements.liquidationMarginRequirement)
214
- .plus(ExposureCommand.computeLiquidationMarginRequirement(riskMatrix.matrix, filledExposures))
208
+ if (uniqueQuoteTokens.includes(collateralAddress)) {
209
+ // uniqueQuoteTokens is list is active markets tokens
210
+ for (var _i = 0, riskMatrices_1 = riskMatrices; _i < riskMatrices_1.length; _i++) {
211
+ var riskMatrix = riskMatrices_1[_i];
212
+ var filledExposures = ExposureCommand.getBlockExposures(positions, oraclePricePerMarket);
213
+ marginRequirements.liquidationMarginRequirement = (0, bignumber_js_1.default)(marginRequirements.liquidationMarginRequirement)
214
+ .plus(ExposureCommand.computeLiquidationMarginRequirement(riskMatrix.matrix, filledExposures))
215
+ .toNumber();
216
+ }
217
+ // Get the initial margin requirement
218
+ marginRequirements.initialMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.im_multiplier))
219
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
220
+ .toNumber();
221
+ // Get the maintenance margin requirement
222
+ marginRequirements.maintenanceMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.mmr_multiplier))
223
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
224
+ .toNumber();
225
+ // Get the dutch margin requirement
226
+ marginRequirements.dutchMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.dutch_multiplier))
227
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
228
+ .toNumber();
229
+ // Get the adl margin requirement
230
+ marginRequirements.adlMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.adl_multiplier))
231
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
232
+ .toNumber();
233
+ // Get the initial buffer margin requirement
234
+ marginRequirements.initialBufferMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.im_buffer_multiplier))
235
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
215
236
  .toNumber();
216
237
  }
217
- // Get the initial margin requirement
218
- marginRequirements.initialMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.im_multiplier))
219
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
220
- .toNumber();
221
- // Get the maintenance margin requirement
222
- marginRequirements.maintenanceMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.mmr_multiplier))
223
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
224
- .toNumber();
225
- // Get the dutch margin requirement
226
- marginRequirements.dutchMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.dutch_multiplier))
227
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
228
- .toNumber();
229
- // Get the adl margin requirement
230
- marginRequirements.adlMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.adl_multiplier))
231
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
232
- .toNumber();
233
- // Get the initial buffer margin requirement
234
- marginRequirements.initialBufferMarginRequirement = (0, number_1.amountNormalizer)(String(riskMultipliers.im_buffer_multiplier))
235
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
236
- .toNumber();
237
238
  return {
238
239
  assetAddress: collateralAddress,
239
240
  marginBalance: collateralInfo.marginBalance,
@@ -279,11 +280,11 @@ var ExposureCommand = /** @class */ (function () {
279
280
  }
280
281
  return (0, bignumber_js_1.default)(lmrFilledSquared).sqrt().toNumber();
281
282
  };
282
- ExposureCommand.getBlockExposures = function (positions, oraclePrice) {
283
+ ExposureCommand.getBlockExposures = function (positions, oraclePricePerMarket) {
283
284
  var filledExposures = [];
284
285
  for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
285
286
  var position = positions_1[_i];
286
- var marketFilledExposure = ExposureCommand.getAccountFilledExposures(position, position.market_configuration, oraclePrice);
287
+ var marketFilledExposure = ExposureCommand.getAccountFilledExposures(position, position.market_configuration, oraclePricePerMarket[position.market_id]);
287
288
  filledExposures[marketFilledExposure.riskMatrixIndex] = (0, bignumber_js_1.default)(filledExposures[marketFilledExposure.riskMatrixIndex] || 0)
288
289
  .plus(marketFilledExposure.exposure)
289
290
  .toNumber();
@@ -323,7 +324,7 @@ var ExposureCommand = /** @class */ (function () {
323
324
  return haircutPrice.multipliedBy(quantity).toNumber();
324
325
  };
325
326
  ExposureCommand.prototype.getSlippage = function (deltaBase, marketConfiguration, marketStorage) {
326
- var deltaExposure = (0, bignumber_js_1.default)(this.oraclePrice)
327
+ var deltaExposure = (0, bignumber_js_1.default)(this.oraclePricePerMarket[marketConfiguration.market_id])
327
328
  .times(deltaBase)
328
329
  .toNumber();
329
330
  var riskMatrixIndex = (0, bignumber_js_1.default)(String(marketConfiguration.risk_matrix_index)).toNumber();
@@ -351,7 +352,7 @@ var ExposureCommand = /** @class */ (function () {
351
352
  if (!marginInfo) {
352
353
  throw new Error("marginInfo doesn't exist");
353
354
  }
354
- var exposures = ExposureCommand.getBlockExposures(this.positionInfoMarketConfiguration, this.oraclePrice);
355
+ var exposures = ExposureCommand.getBlockExposures(this.positionInfoMarketConfiguration, this.oraclePricePerMarket);
355
356
  var _a = ExposureCommand.computeMaxExposures(riskMatrix.matrix, exposures, marginInfo.liquidationMarginRequirement, marginInfo.marginBalance < 0 ? 0 : marginInfo.marginBalance, imrMultiplier, riskMatrixIndex), maxExposureShort = _a.maxExposureShort, maxExposureLong = _a.maxExposureLong;
356
357
  return {
357
358
  maxExposureShort: maxExposureShort,
@@ -1 +1 @@
1
- {"version":3,"file":"exposure.calculator.js","sourceRoot":"/","sources":["clients/helpers/exposure.calculator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8DAAqC;AACrC,kDAAuB;AAcvB,mCAA4C;AAE5C;IAeE,yBACE,oBAA4B,EAC5B,WAAmB,EACnB,IAAY,EACZ,sBAA6C,EAC7C,mBAAwD,EACxD,eAA6C,EAC7C,YAA0B,EAC1B,oBAAoC,EACpC,+BAAkE,EAClE,oBAA8B,EAC9B,sBAAgC,EAChC,uBAAqC,EACrC,cAAyB,EAC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AAI,MAAM,IAAI,EAAE,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IACH,sBAAC;AAAD,CAAC,AAvwBD,IAuwBC;AAvwBY,0CAAe","sourcesContent":["import BigNumber from 'bignumber.js';\nimport _ from 'lodash';\nimport {\n AccountAssetBalance,\n CollateralInfo,\n ExchangeInfo,\n ExposureCommandState,\n MarginInfo,\n MarketConfiguration,\n MarketStorage,\n PositionInfo,\n PositionInfoMarketConfiguration,\n RiskMatrix,\n RiskMultipliersConfiguration,\n} from './trade.simulation.types';\nimport { amountNormalizer } from './number';\n\nexport class ExposureCommand {\n rootCollateralPoolId: number;\n oraclePrice: number;\n rate: number;\n accountBalancePerAsset: AccountAssetBalance[];\n groupedByCollateral: Record<string, AccountAssetBalance>;\n riskMultipliers: RiskMultipliersConfiguration;\n riskMatrices: RiskMatrix[];\n exchangeInfoPerAsset: ExchangeInfo[];\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[];\n uniqueTokenAddresses: string[];\n uniqueQuoteCollaterals: string[];\n tokenMarginInfoPerAsset: MarginInfo[];\n realizedPnLSum: BigNumber;\n unrealizedPnLSum: BigNumber;\n constructor(\n rootCollateralPoolId: number,\n oraclePrice: number,\n rate: number,\n accountBalancePerAsset: AccountAssetBalance[],\n groupedByCollateral: Record<string, AccountAssetBalance>,\n riskMultipliers: RiskMultipliersConfiguration,\n riskMatrices: RiskMatrix[],\n exchangeInfoPerAsset: ExchangeInfo[],\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[],\n uniqueTokenAddresses: string[],\n uniqueQuoteCollaterals: string[],\n tokenMarginInfoPerAsset: MarginInfo[],\n realizedPnLSum: BigNumber,\n unrealizedPnLSum: BigNumber,\n ) {\n this.rootCollateralPoolId = rootCollateralPoolId;\n this.oraclePrice = oraclePrice;\n this.rate = rate;\n this.accountBalancePerAsset = accountBalancePerAsset;\n this.groupedByCollateral = groupedByCollateral;\n this.riskMultipliers = riskMultipliers;\n this.riskMatrices = riskMatrices;\n this.exchangeInfoPerAsset = exchangeInfoPerAsset;\n this.positionInfoMarketConfiguration = positionInfoMarketConfiguration;\n this.uniqueTokenAddresses = uniqueTokenAddresses;\n this.uniqueQuoteCollaterals = uniqueQuoteCollaterals;\n this.tokenMarginInfoPerAsset = tokenMarginInfoPerAsset;\n this.realizedPnLSum = realizedPnLSum;\n this.unrealizedPnLSum = unrealizedPnLSum;\n }\n\n getState(): ExposureCommandState {\n return {\n rootCollateralPoolId: this.rootCollateralPoolId,\n oraclePrice: this.oraclePrice,\n rate: this.rate,\n accountBalancePerAsset: this.accountBalancePerAsset,\n groupedByCollateral: this.groupedByCollateral,\n riskMultipliers: this.riskMultipliers,\n riskMatrices: this.riskMatrices,\n exchangeInfoPerAsset: this.exchangeInfoPerAsset,\n positionInfoMarketConfiguration: this.positionInfoMarketConfiguration,\n uniqueTokenAddresses: this.uniqueTokenAddresses,\n uniqueQuoteCollaterals: this.uniqueQuoteCollaterals,\n tokenMarginInfoPerAsset: this.tokenMarginInfoPerAsset,\n realizedPnLSum: this.realizedPnLSum,\n unrealizedPnLSum: this.unrealizedPnLSum,\n };\n }\n\n get getUsdNodeMarginInfo() {\n return ExposureCommand.getUsdNodeMarginInfo(\n this.rootCollateralPoolId,\n this.uniqueTokenAddresses,\n this.exchangeInfoPerAsset,\n this.tokenMarginInfoPerAsset,\n );\n }\n\n get balancePerAsset() {\n return this.tokenMarginInfoPerAsset;\n }\n\n getUsdNodeMarginInfoPostTrade(\n positionAmount: number,\n collateralAddress: string,\n marketConfiguration: MarketConfiguration,\n ) {\n // perform deep copy of the object\n const positionInfoMarketConfiguration: PositionInfoMarketConfiguration[] =\n _.cloneDeep(this.positionInfoMarketConfiguration);\n\n // Check if the market_id already exists in the array\n const existingConfigIndex = positionInfoMarketConfiguration.findIndex(\n (config) =>\n config.market_id ===\n BigNumber(String(marketConfiguration.market_id)).toNumber(),\n );\n\n if (existingConfigIndex !== -1) {\n // If it exists, update the amount\n positionInfoMarketConfiguration[existingConfigIndex].base = BigNumber(\n positionInfoMarketConfiguration[existingConfigIndex].base,\n ).plus(positionAmount);\n } else {\n // If it doesn't exist, add a new element\n positionInfoMarketConfiguration.push({\n base: BigNumber(positionAmount),\n realized_pnl: BigNumber(0),\n last_price: BigNumber(0),\n last_timestamp: BigNumber(0),\n funding_value: BigNumber(0),\n base_multiplier: BigNumber(0),\n adl_unwind_price: BigNumber(0),\n market_id: BigNumber(String(marketConfiguration.market_id)).toNumber(),\n market_configuration: marketConfiguration,\n });\n }\n\n const uniqueQuoteCollaterals = new Set(this.uniqueQuoteCollaterals);\n uniqueQuoteCollaterals.add(collateralAddress);\n\n const tokenMarginInfoPerAsset =\n ExposureCommand.calculateTokenMarginInfoPerAsset(\n this.groupedByCollateral,\n this.rootCollateralPoolId,\n this.riskMatrices,\n this.riskMultipliers,\n uniqueQuoteCollaterals,\n this.realizedPnLSum,\n this.unrealizedPnLSum,\n positionInfoMarketConfiguration,\n this.oraclePrice,\n );\n\n const uniqueTokenAddresses = [...this.uniqueTokenAddresses];\n if (!this.uniqueTokenAddresses.includes(collateralAddress)) {\n uniqueTokenAddresses.push(collateralAddress);\n }\n\n return ExposureCommand.getUsdNodeMarginInfo(\n this.rootCollateralPoolId,\n uniqueTokenAddresses,\n this.exchangeInfoPerAsset,\n tokenMarginInfoPerAsset,\n );\n }\n\n static calculateTokenMarginInfoPerAsset(\n groupedByCollateral: Record<string, AccountAssetBalance>,\n rootCollateralPoolId: number,\n riskMatrices: RiskMatrix[],\n riskMultipliers: RiskMultipliersConfiguration,\n uniqueQuoteCollaterals: Set<string>,\n realizedPnLSum: BigNumber,\n unrealizedPnLSum: BigNumber,\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[],\n oraclePrice: number,\n ) {\n const tokenMarginInfoPerAsset: MarginInfo[] = [];\n\n const uniqueQuoteTokens: string[] = Array.from(uniqueQuoteCollaterals);\n\n const tokenUnion = new Set([\n ...Object.keys(groupedByCollateral),\n ...uniqueQuoteTokens,\n ]); // get unique union of those arrays\n const uniqueTokenAddresses: string[] = Array.from(tokenUnion);\n\n for (const token of uniqueTokenAddresses) {\n tokenMarginInfoPerAsset.push(\n ExposureCommand.getTokenMarginInfo(\n rootCollateralPoolId,\n riskMatrices,\n riskMultipliers,\n ExposureCommand.getCollateralInfo(\n token,\n uniqueQuoteCollaterals.has(token) ? realizedPnLSum : BigNumber(0),\n uniqueQuoteCollaterals.has(token) ? unrealizedPnLSum : BigNumber(0),\n groupedByCollateral[token]?.amount || 0,\n ),\n token,\n positionInfoMarketConfiguration,\n oraclePrice,\n ),\n );\n }\n\n return tokenMarginInfoPerAsset;\n }\n static calculateLiquidation(\n globalMarginInfo: MarginInfo,\n oraclePrice: number,\n positionBase: number,\n ): BigNumber {\n const liquidationPrice = BigNumber(oraclePrice).minus(\n BigNumber(globalMarginInfo.marginBalance)\n .minus(globalMarginInfo.liquidationMarginRequirement)\n .div(positionBase),\n );\n\n return BigNumber.max(0, liquidationPrice);\n }\n\n static calculateImpliedLeverage(\n notionalExposure: number,\n oldIMR: number,\n newIMR: number,\n ): number {\n const changeInImr = BigNumber(newIMR).minus(oldIMR);\n\n if (changeInImr.eq(0)) {\n return 0;\n }\n return BigNumber(notionalExposure).div(changeInImr).toNumber();\n }\n\n static combineMarginInfo(\n parentMarginInfo: MarginInfo,\n sonMarginInfo: MarginInfo,\n sonParentExchangeInfo: ExchangeInfo,\n ): MarginInfo {\n return {\n assetAddress: parentMarginInfo.assetAddress,\n marginBalance: BigNumber(parentMarginInfo.marginBalance)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n sonMarginInfo.marginBalance,\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n realBalance: BigNumber(parentMarginInfo.realBalance)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n sonMarginInfo.realBalance,\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n initialDelta: BigNumber(parentMarginInfo.initialDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.realBalance,\n sonMarginInfo.initialDelta,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n maintenanceDelta: BigNumber(parentMarginInfo.maintenanceDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.maintenanceDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n liquidationDelta: BigNumber(parentMarginInfo.liquidationDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.liquidationDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n dutchDelta: BigNumber(parentMarginInfo.dutchDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.dutchDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n adlDelta: BigNumber(parentMarginInfo.adlDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.adlDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n\n initialBufferDelta: BigNumber(parentMarginInfo.initialBufferDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.initialBufferDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n liquidationMarginRequirement: BigNumber(\n parentMarginInfo.liquidationMarginRequirement,\n )\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n sonMarginInfo.liquidationMarginRequirement,\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n };\n }\n\n static getUsdNodeMarginInfo(\n accountCollateralPoolId: number,\n quoteTokens: string[],\n exchangeInfoPerAsset: ExchangeInfo[],\n marginInfoPerToken: MarginInfo[],\n ) {\n let usdNodeMarginInfo: MarginInfo = {\n assetAddress: '',\n marginBalance: 0,\n realBalance: 0,\n initialDelta: 0,\n maintenanceDelta: 0,\n liquidationDelta: 0,\n dutchDelta: 0,\n adlDelta: 0,\n initialBufferDelta: 0,\n liquidationMarginRequirement: 0,\n };\n for (const quoteToken of quoteTokens) {\n const exchangeInfo = exchangeInfoPerAsset.find((exchangeInfo) => {\n return quoteToken === exchangeInfo.tokenAddress;\n });\n\n const marginInfo = marginInfoPerToken.find((marginInfo) => {\n return quoteToken === marginInfo.assetAddress;\n });\n\n if (!exchangeInfo || !marginInfo) {\n throw Error('Missing exchangeInfo/marginInfo');\n }\n\n usdNodeMarginInfo = ExposureCommand.combineMarginInfo(\n usdNodeMarginInfo,\n marginInfo,\n exchangeInfo,\n );\n }\n\n return usdNodeMarginInfo;\n }\n static getCollateralInfo(\n collateralAddress: string,\n realisedPnl: BigNumber,\n unrealizedPnL: BigNumber,\n netDeposits: number,\n ): CollateralInfo {\n return {\n netDeposits: netDeposits,\n marginBalance: BigNumber(netDeposits)\n .plus(realisedPnl)\n .plus(unrealizedPnL)\n .toNumber(),\n realBalance: BigNumber(netDeposits).plus(realisedPnl).toNumber(),\n };\n }\n\n static getTokenMarginInfo(\n rootCollateralPoolId: number,\n riskMatrices: RiskMatrix[],\n riskMultipliers: RiskMultipliersConfiguration,\n collateralInfo: CollateralInfo,\n collateralAddress: string,\n positions: PositionInfoMarketConfiguration[],\n oraclePrice: number,\n ): MarginInfo {\n const marginRequirements = {\n liquidationMarginRequirement: 0,\n initialMarginRequirement: 0,\n maintenanceMarginRequirement: 0,\n dutchMarginRequirement: 0,\n adlMarginRequirement: 0,\n initialBufferMarginRequirement: 0,\n };\n\n for (const riskMatrix of riskMatrices) {\n const filledExposures = ExposureCommand.getBlockExposures(\n positions,\n oraclePrice,\n );\n\n marginRequirements.liquidationMarginRequirement = BigNumber(\n marginRequirements.liquidationMarginRequirement,\n )\n .plus(\n ExposureCommand.computeLiquidationMarginRequirement(\n riskMatrix.matrix,\n filledExposures,\n ),\n )\n .toNumber();\n }\n\n // Get the initial margin requirement\n marginRequirements.initialMarginRequirement = amountNormalizer(\n String(riskMultipliers.im_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n // Get the maintenance margin requirement\n marginRequirements.maintenanceMarginRequirement = amountNormalizer(\n String(riskMultipliers.mmr_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n // Get the dutch margin requirement\n marginRequirements.dutchMarginRequirement = amountNormalizer(\n String(riskMultipliers.dutch_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n\n // Get the adl margin requirement\n marginRequirements.adlMarginRequirement = amountNormalizer(\n String(riskMultipliers.adl_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n\n // Get the initial buffer margin requirement\n marginRequirements.initialBufferMarginRequirement = amountNormalizer(\n String(riskMultipliers.im_buffer_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n\n return {\n assetAddress: collateralAddress,\n marginBalance: collateralInfo.marginBalance,\n realBalance: collateralInfo.realBalance,\n initialDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.initialMarginRequirement)\n .toNumber(),\n maintenanceDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.maintenanceMarginRequirement)\n .toNumber(),\n liquidationDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.liquidationMarginRequirement)\n .toNumber(),\n dutchDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.dutchMarginRequirement)\n .toNumber(),\n adlDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.adlMarginRequirement)\n .toNumber(),\n initialBufferDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.initialBufferMarginRequirement)\n .toNumber(),\n liquidationMarginRequirement:\n marginRequirements.liquidationMarginRequirement,\n };\n }\n\n static computeLiquidationMarginRequirement(\n matrix: BigNumber[][],\n filledExposures: BigNumber[],\n ): number {\n let lmrFilledSquared = 0;\n\n for (let i = 0; i < filledExposures.length; i++) {\n if (BigNumber(filledExposures[i]).eq(0)) {\n continue;\n }\n for (let j = 0; j < filledExposures.length; j++) {\n const riskParam = matrix[i][j];\n\n if (BigNumber(filledExposures[j]).eq(0) || BigNumber(riskParam).eq(0)) {\n continue;\n }\n\n lmrFilledSquared = BigNumber(lmrFilledSquared)\n .plus(\n BigNumber(filledExposures[i])\n .multipliedBy(filledExposures[j])\n .multipliedBy(riskParam),\n )\n .toNumber();\n }\n }\n return BigNumber(lmrFilledSquared).sqrt().toNumber();\n }\n\n static getBlockExposures(\n positions: PositionInfoMarketConfiguration[],\n oraclePrice: number,\n ): BigNumber[] {\n const filledExposures: number[] = [];\n\n for (const position of positions) {\n const marketFilledExposure = ExposureCommand.getAccountFilledExposures(\n position,\n position.market_configuration,\n oraclePrice,\n );\n filledExposures[marketFilledExposure.riskMatrixIndex] = BigNumber(\n filledExposures[marketFilledExposure.riskMatrixIndex] || 0,\n )\n .plus(marketFilledExposure.exposure)\n .toNumber();\n }\n\n return filledExposures.map((num) => BigNumber(num));\n }\n\n static getAccountFilledExposures(\n position: PositionInfo,\n marketConfiguration: MarketConfiguration,\n oraclePrice: number,\n ) {\n const base = position.base;\n\n return {\n exposure: BigNumber(oraclePrice).multipliedBy(base),\n riskMatrixIndex: BigNumber(\n String(marketConfiguration.risk_matrix_index),\n ).toNumber(),\n };\n }\n\n static computePricePnL(\n openBase: BigNumber,\n openPrice: BigNumber,\n exitPrice: BigNumber,\n ) {\n return BigNumber(\n BigNumber(exitPrice).minus(openPrice).multipliedBy(openBase),\n );\n }\n\n static getMarginRatio(marginInfo: MarginInfo) {\n if (marginInfo.liquidationMarginRequirement === 0) {\n return 0;\n }\n\n if (marginInfo.marginBalance <= 0) {\n return 1;\n }\n\n const health = BigNumber(marginInfo.liquidationMarginRequirement).div(\n marginInfo.marginBalance,\n );\n\n if (health.gt(1)) {\n return 1;\n }\n return health.toNumber();\n }\n\n static exchangeWithPriceHaircut(\n quantity: number,\n price: number,\n haircut: number,\n ) {\n // For positive quantities, the haircut is `quantity * (1 - haircut)`\n // For negative values, the haircut is `quantity / (1 - haircut)` because a negative value means the haircut should be applied from B to A.\n const calHelper = BigNumber(quantity).gt(0)\n ? BigNumber(1).minus(haircut)\n : BigNumber(1).div(BigNumber(1).minus(haircut));\n const haircutPrice = BigNumber(price).multipliedBy(calHelper);\n\n return haircutPrice.multipliedBy(quantity).toNumber();\n }\n\n getSlippage(\n deltaBase: number,\n marketConfiguration: MarketConfiguration,\n marketStorage: MarketStorage,\n ): number {\n const deltaExposure = BigNumber(this.oraclePrice)\n .times(deltaBase)\n .toNumber();\n\n const riskMatrixIndex = BigNumber(\n String(marketConfiguration.risk_matrix_index),\n ).toNumber();\n\n const { maxExposureShort, maxExposureLong, exposures } =\n this.getMaxExposure(marketConfiguration, marketStorage);\n\n const netExposure = exposures[riskMatrixIndex].plus(deltaExposure);\n const maxExposure = netExposure.lt(0) ? maxExposureShort : maxExposureLong;\n\n return BigNumber(netExposure)\n .negated()\n .div(BigNumber(maxExposure).plus(netExposure))\n .toNumber();\n }\n\n getMaxExposure(\n marketConfiguration: MarketConfiguration,\n marketStorage: MarketStorage,\n ) {\n const riskMatrix = this.riskMatrices.find((riskMatrix) => {\n return (\n riskMatrix.risk_block_id ===\n BigNumber(String(marketStorage.risk_block_id)).toNumber()\n );\n });\n\n if (!riskMatrix) {\n throw new Error(\"RiskMatrix Doesn't exist\");\n }\n\n const riskMatrixIndex = BigNumber(\n String(marketConfiguration.risk_matrix_index),\n ).toNumber();\n\n const imrMultiplier = amountNormalizer(\n String(this.riskMultipliers.im_multiplier),\n ).toNumber();\n\n const marginInfo = this.tokenMarginInfoPerAsset.find((marginInfo) => {\n return marginInfo.assetAddress === marketStorage.quote_collateral;\n });\n\n if (!marginInfo) {\n throw new Error(\"marginInfo doesn't exist\");\n }\n\n const exposures = ExposureCommand.getBlockExposures(\n this.positionInfoMarketConfiguration,\n this.oraclePrice,\n );\n\n const { maxExposureShort, maxExposureLong } =\n ExposureCommand.computeMaxExposures(\n riskMatrix.matrix,\n exposures,\n marginInfo.liquidationMarginRequirement,\n marginInfo.marginBalance < 0 ? 0 : marginInfo.marginBalance,\n imrMultiplier,\n riskMatrixIndex,\n );\n\n return {\n maxExposureShort,\n maxExposureLong,\n exposures,\n };\n }\n\n static computeMaxExposures(\n riskMatrix: BigNumber[][],\n exposures: BigNumber[],\n lmr: number,\n balance: number,\n imrMultiplier: number,\n exposureIndex: number,\n ) {\n let b = BigNumber(0);\n\n for (let i = 0; i < exposures.length; i++) {\n b = BigNumber(b).plus(\n BigNumber(exposures[i]).multipliedBy(\n BigNumber(riskMatrix[exposureIndex][i]).plus(\n riskMatrix[i][exposureIndex],\n ),\n ),\n );\n }\n const { x1, x2 } = this.solveQuadraticEquation(\n BigNumber(riskMatrix[exposureIndex][exposureIndex]).toNumber(), // changes here\n b.toNumber(),\n this.computeC(lmr, balance, imrMultiplier),\n );\n\n const maxShortExposure = BigNumber(x1).plus(exposures[exposureIndex]);\n const maxLongExposure = BigNumber(x2).plus(exposures[exposureIndex]);\n\n const availableShortExposure = maxShortExposure.lt(0)\n ? maxShortExposure.negated().toNumber()\n : 0;\n\n const availableLongExposure = maxLongExposure.gt(0)\n ? maxLongExposure.toNumber()\n : 0;\n\n return {\n maxExposureShort: availableShortExposure,\n maxExposureLong: availableLongExposure,\n };\n }\n\n static solveQuadraticEquation(a: number, b: number, c: number) {\n if (BigNumber(a).eq(0)) {\n throw new Error('ZeroQuadraticCoefficient');\n }\n\n const delta = BigNumber(b)\n .multipliedBy(b)\n .minus(BigNumber(4).multipliedBy(a).multipliedBy(c));\n\n if (delta.lt(0)) {\n throw new Error('ComplexQuadraticRoots(a, b, c)');\n }\n\n const rootDelta = delta.sqrt();\n\n const x1 = BigNumber(b)\n .multipliedBy(-1)\n .minus(rootDelta)\n .div(BigNumber(2).multipliedBy(a));\n\n const x2 = BigNumber(b)\n .multipliedBy(-1)\n .plus(rootDelta)\n .div(BigNumber(2).multipliedBy(a));\n\n return {\n x1,\n x2,\n };\n }\n\n static computeC(lmr: number, balance: number, imrMultiplier: number): number {\n const lmrSD = BigNumber(lmr);\n const lmrSquared = lmrSD.multipliedBy(lmrSD);\n\n const balanceSD = BigNumber(balance);\n const balanceSquared = balanceSD.multipliedBy(balanceSD);\n\n const imrMultiplierSD = BigNumber(imrMultiplier);\n const imrMultiplierSquared = imrMultiplierSD.multipliedBy(imrMultiplierSD);\n\n return lmrSquared\n .minus(balanceSquared.div(imrMultiplierSquared))\n .toNumber();\n }\n\n static calculateFee(\n price: number,\n amount: number,\n feeParameter: BigNumber,\n ): number {\n return BigNumber(price).times(amount).times(feeParameter).abs().toNumber(); // @todo abs value\n }\n\n static calculateEstimatedPrice(price: number, slippage: number): number {\n return BigNumber(price).times(BigNumber(1).plus(slippage)).toNumber();\n }\n\n static evaluateHealthStatus(number: number) {\n // todo update logic\n if (number >= 67) {\n return 'danger';\n } else if (number >= 34) {\n return 'warning';\n } else {\n return 'healthy';\n }\n }\n}\n"]}
1
+ {"version":3,"file":"exposure.calculator.js","sourceRoot":"/","sources":["clients/helpers/exposure.calculator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8DAAqC;AACrC,kDAAuB;AAevB,mCAA4C;A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uB,GAA9B,UAA+B,KAAa,EAAE,QAAgB;QAC5D,OAAO,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAA,sBAAS,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACxE,CAAC;IAEM,oCAAoB,GAA3B,UAA4B,MAAc;QACxC,oBAAoB;QACpB,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;YACjB,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IACH,sBAAC;AAAD,CAAC,AAxwBD,IAwwBC;AAxwBY,0CAAe","sourcesContent":["import BigNumber from 'bignumber.js';\nimport _ from 'lodash';\nimport {\n AccountAssetBalance,\n CollateralInfo,\n ExchangeInfo,\n ExposureCommandState,\n MarginInfo,\n MarketConfiguration,\n MarketIdToOraclePriceMap,\n MarketStorage,\n PositionInfo,\n PositionInfoMarketConfiguration,\n RiskMatrix,\n RiskMultipliersConfiguration,\n} from './trade.simulation.types';\nimport { amountNormalizer } from './number';\n\nexport class ExposureCommand {\n rootCollateralPoolId: number;\n oraclePricePerMarket: MarketIdToOraclePriceMap;\n accountBalancePerAsset: AccountAssetBalance[];\n groupedByCollateral: Record<string, AccountAssetBalance>;\n riskMultipliers: RiskMultipliersConfiguration;\n riskMatrices: RiskMatrix[];\n exchangeInfoPerAsset: ExchangeInfo[];\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[];\n uniqueTokenAddresses: string[];\n uniqueQuoteCollaterals: string[];\n tokenMarginInfoPerAsset: MarginInfo[];\n realizedPnLSum: BigNumber;\n unrealizedPnLSum: BigNumber;\n constructor(\n rootCollateralPoolId: number,\n oraclePricePerMarket: MarketIdToOraclePriceMap,\n accountBalancePerAsset: AccountAssetBalance[],\n groupedByCollateral: Record<string, AccountAssetBalance>,\n riskMultipliers: RiskMultipliersConfiguration,\n riskMatrices: RiskMatrix[],\n exchangeInfoPerAsset: ExchangeInfo[],\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[],\n uniqueTokenAddresses: string[],\n uniqueQuoteCollaterals: string[],\n tokenMarginInfoPerAsset: MarginInfo[],\n realizedPnLSum: BigNumber,\n unrealizedPnLSum: BigNumber,\n ) {\n this.rootCollateralPoolId = rootCollateralPoolId;\n this.oraclePricePerMarket = oraclePricePerMarket;\n this.accountBalancePerAsset = accountBalancePerAsset;\n this.groupedByCollateral = groupedByCollateral;\n this.riskMultipliers = riskMultipliers;\n this.riskMatrices = riskMatrices;\n this.exchangeInfoPerAsset = exchangeInfoPerAsset;\n this.positionInfoMarketConfiguration = positionInfoMarketConfiguration;\n this.uniqueTokenAddresses = uniqueTokenAddresses;\n this.uniqueQuoteCollaterals = uniqueQuoteCollaterals;\n this.tokenMarginInfoPerAsset = tokenMarginInfoPerAsset;\n this.realizedPnLSum = realizedPnLSum;\n this.unrealizedPnLSum = unrealizedPnLSum;\n }\n\n getState(): ExposureCommandState {\n return {\n rootCollateralPoolId: this.rootCollateralPoolId,\n oraclePricePerMarket: this.oraclePricePerMarket,\n accountBalancePerAsset: this.accountBalancePerAsset,\n groupedByCollateral: this.groupedByCollateral,\n riskMultipliers: this.riskMultipliers,\n riskMatrices: this.riskMatrices,\n exchangeInfoPerAsset: this.exchangeInfoPerAsset,\n positionInfoMarketConfiguration: this.positionInfoMarketConfiguration,\n uniqueTokenAddresses: this.uniqueTokenAddresses,\n uniqueQuoteCollaterals: this.uniqueQuoteCollaterals,\n tokenMarginInfoPerAsset: this.tokenMarginInfoPerAsset,\n realizedPnLSum: this.realizedPnLSum,\n unrealizedPnLSum: this.unrealizedPnLSum,\n };\n }\n\n get getUsdNodeMarginInfo() {\n return ExposureCommand.getUsdNodeMarginInfo(\n this.rootCollateralPoolId,\n this.uniqueTokenAddresses,\n this.exchangeInfoPerAsset,\n this.tokenMarginInfoPerAsset,\n );\n }\n\n get balancePerAsset() {\n return this.tokenMarginInfoPerAsset;\n }\n\n getUsdNodeMarginInfoPostTrade(\n positionAmount: number,\n collateralAddress: string,\n marketConfiguration: MarketConfiguration,\n ) {\n // perform deep copy of the object\n const positionInfoMarketConfiguration: PositionInfoMarketConfiguration[] =\n _.cloneDeep(this.positionInfoMarketConfiguration);\n\n // Check if the market_id already exists in the array\n const existingConfigIndex = positionInfoMarketConfiguration.findIndex(\n (config) =>\n config.market_id ===\n BigNumber(String(marketConfiguration.market_id)).toNumber(),\n );\n\n if (existingConfigIndex !== -1) {\n // If it exists, update the amount\n positionInfoMarketConfiguration[existingConfigIndex].base = BigNumber(\n positionInfoMarketConfiguration[existingConfigIndex].base,\n ).plus(positionAmount);\n } else {\n // If it doesn't exist, add a new element\n positionInfoMarketConfiguration.push({\n base: BigNumber(positionAmount),\n realized_pnl: BigNumber(0),\n last_price: BigNumber(0),\n last_timestamp: BigNumber(0),\n funding_value: BigNumber(0),\n base_multiplier: BigNumber(0),\n adl_unwind_price: BigNumber(0),\n market_id: BigNumber(String(marketConfiguration.market_id)).toNumber(),\n market_configuration: marketConfiguration,\n });\n }\n\n const uniqueQuoteCollaterals = new Set(this.uniqueQuoteCollaterals);\n uniqueQuoteCollaterals.add(collateralAddress);\n\n const tokenMarginInfoPerAsset =\n ExposureCommand.calculateTokenMarginInfoPerAsset(\n this.groupedByCollateral,\n this.rootCollateralPoolId,\n this.riskMatrices,\n this.riskMultipliers,\n uniqueQuoteCollaterals,\n this.realizedPnLSum,\n this.unrealizedPnLSum,\n positionInfoMarketConfiguration,\n this.oraclePricePerMarket,\n );\n\n const uniqueTokenAddresses = [...this.uniqueTokenAddresses];\n if (!this.uniqueTokenAddresses.includes(collateralAddress)) {\n uniqueTokenAddresses.push(collateralAddress);\n }\n\n return ExposureCommand.getUsdNodeMarginInfo(\n this.rootCollateralPoolId,\n uniqueTokenAddresses,\n this.exchangeInfoPerAsset,\n tokenMarginInfoPerAsset,\n );\n }\n\n static calculateTokenMarginInfoPerAsset(\n groupedByCollateral: Record<string, AccountAssetBalance>,\n rootCollateralPoolId: number,\n riskMatrices: RiskMatrix[],\n riskMultipliers: RiskMultipliersConfiguration,\n uniqueQuoteCollaterals: Set<string>,\n realizedPnLSum: BigNumber,\n unrealizedPnLSum: BigNumber,\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[],\n oraclePricePerMarket: MarketIdToOraclePriceMap,\n ) {\n const tokenMarginInfoPerAsset: MarginInfo[] = [];\n\n const uniqueQuoteTokens: string[] = Array.from(uniqueQuoteCollaterals);\n\n const tokenUnion = new Set([\n ...Object.keys(groupedByCollateral),\n ...uniqueQuoteTokens,\n ]); // get unique union of those arrays\n const uniqueTokenAddresses: string[] = Array.from(tokenUnion);\n\n for (const token of uniqueTokenAddresses) {\n tokenMarginInfoPerAsset.push(\n ExposureCommand.getTokenMarginInfo(\n rootCollateralPoolId,\n riskMatrices,\n riskMultipliers,\n ExposureCommand.getCollateralInfo(\n token,\n uniqueQuoteCollaterals.has(token) ? realizedPnLSum : BigNumber(0),\n uniqueQuoteCollaterals.has(token) ? unrealizedPnLSum : BigNumber(0),\n groupedByCollateral[token]?.amount || 0,\n ),\n token,\n positionInfoMarketConfiguration,\n oraclePricePerMarket,\n uniqueQuoteTokens,\n ),\n );\n }\n\n return tokenMarginInfoPerAsset;\n }\n static calculateLiquidation(\n globalMarginInfo: MarginInfo,\n oraclePrice: number,\n positionBase: number,\n ): BigNumber {\n const liquidationPrice = BigNumber(oraclePrice).minus(\n BigNumber(globalMarginInfo.marginBalance)\n .minus(globalMarginInfo.liquidationMarginRequirement)\n .div(positionBase),\n );\n\n return BigNumber.max(0, liquidationPrice);\n }\n\n static calculateImpliedLeverage(\n notionalExposure: number,\n oldIMR: number,\n newIMR: number,\n ): number {\n const changeInImr = BigNumber(newIMR).minus(oldIMR);\n\n if (changeInImr.eq(0)) {\n return 0;\n }\n return BigNumber(notionalExposure).div(changeInImr).toNumber();\n }\n\n static combineMarginInfo(\n parentMarginInfo: MarginInfo,\n sonMarginInfo: MarginInfo,\n sonParentExchangeInfo: ExchangeInfo,\n ): MarginInfo {\n return {\n assetAddress: parentMarginInfo.assetAddress,\n marginBalance: BigNumber(parentMarginInfo.marginBalance)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n sonMarginInfo.marginBalance,\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n realBalance: BigNumber(parentMarginInfo.realBalance)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n sonMarginInfo.realBalance,\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n initialDelta: BigNumber(parentMarginInfo.initialDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.realBalance,\n sonMarginInfo.initialDelta,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n maintenanceDelta: BigNumber(parentMarginInfo.maintenanceDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.maintenanceDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n liquidationDelta: BigNumber(parentMarginInfo.liquidationDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.liquidationDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n dutchDelta: BigNumber(parentMarginInfo.dutchDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.dutchDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n adlDelta: BigNumber(parentMarginInfo.adlDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.adlDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n\n initialBufferDelta: BigNumber(parentMarginInfo.initialBufferDelta)\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n BigNumber.min(\n sonMarginInfo.initialBufferDelta,\n sonMarginInfo.realBalance,\n ).toNumber(),\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n liquidationMarginRequirement: BigNumber(\n parentMarginInfo.liquidationMarginRequirement,\n )\n .plus(\n ExposureCommand.exchangeWithPriceHaircut(\n sonMarginInfo.liquidationMarginRequirement,\n sonParentExchangeInfo.price,\n sonParentExchangeInfo.priceHaircut,\n ),\n )\n .toNumber(),\n };\n }\n\n static getUsdNodeMarginInfo(\n accountCollateralPoolId: number,\n quoteTokens: string[],\n exchangeInfoPerAsset: ExchangeInfo[],\n marginInfoPerToken: MarginInfo[],\n ) {\n let usdNodeMarginInfo: MarginInfo = {\n assetAddress: '',\n marginBalance: 0,\n realBalance: 0,\n initialDelta: 0,\n maintenanceDelta: 0,\n liquidationDelta: 0,\n dutchDelta: 0,\n adlDelta: 0,\n initialBufferDelta: 0,\n liquidationMarginRequirement: 0,\n };\n for (const quoteToken of quoteTokens) {\n const exchangeInfo = exchangeInfoPerAsset.find((exchangeInfo) => {\n return quoteToken === exchangeInfo.tokenAddress;\n });\n\n const marginInfo = marginInfoPerToken.find((marginInfo) => {\n return quoteToken === marginInfo.assetAddress;\n });\n\n if (!exchangeInfo || !marginInfo) {\n throw Error('Missing exchangeInfo/marginInfo');\n }\n\n usdNodeMarginInfo = ExposureCommand.combineMarginInfo(\n usdNodeMarginInfo,\n marginInfo,\n exchangeInfo,\n );\n }\n\n return usdNodeMarginInfo;\n }\n static getCollateralInfo(\n collateralAddress: string,\n realisedPnl: BigNumber,\n unrealizedPnL: BigNumber,\n netDeposits: number,\n ): CollateralInfo {\n return {\n netDeposits: netDeposits,\n marginBalance: BigNumber(netDeposits)\n .plus(realisedPnl)\n .plus(unrealizedPnL)\n .toNumber(),\n realBalance: BigNumber(netDeposits).plus(realisedPnl).toNumber(),\n };\n }\n\n static getTokenMarginInfo(\n rootCollateralPoolId: number,\n riskMatrices: RiskMatrix[],\n riskMultipliers: RiskMultipliersConfiguration,\n collateralInfo: CollateralInfo,\n collateralAddress: string,\n positions: PositionInfoMarketConfiguration[],\n oraclePricePerMarket: MarketIdToOraclePriceMap,\n uniqueQuoteTokens: string[],\n ): MarginInfo {\n const marginRequirements = {\n liquidationMarginRequirement: 0,\n initialMarginRequirement: 0,\n maintenanceMarginRequirement: 0,\n dutchMarginRequirement: 0,\n adlMarginRequirement: 0,\n initialBufferMarginRequirement: 0,\n };\n if (uniqueQuoteTokens.includes(collateralAddress)) {\n // uniqueQuoteTokens is list is active markets tokens\n for (const riskMatrix of riskMatrices) {\n const filledExposures = ExposureCommand.getBlockExposures(\n positions,\n oraclePricePerMarket,\n );\n\n marginRequirements.liquidationMarginRequirement = BigNumber(\n marginRequirements.liquidationMarginRequirement,\n )\n .plus(\n ExposureCommand.computeLiquidationMarginRequirement(\n riskMatrix.matrix,\n filledExposures,\n ),\n )\n .toNumber();\n }\n\n // Get the initial margin requirement\n marginRequirements.initialMarginRequirement = amountNormalizer(\n String(riskMultipliers.im_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n // Get the maintenance margin requirement\n marginRequirements.maintenanceMarginRequirement = amountNormalizer(\n String(riskMultipliers.mmr_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n // Get the dutch margin requirement\n marginRequirements.dutchMarginRequirement = amountNormalizer(\n String(riskMultipliers.dutch_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n\n // Get the adl margin requirement\n marginRequirements.adlMarginRequirement = amountNormalizer(\n String(riskMultipliers.adl_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n\n // Get the initial buffer margin requirement\n marginRequirements.initialBufferMarginRequirement = amountNormalizer(\n String(riskMultipliers.im_buffer_multiplier),\n )\n .multipliedBy(marginRequirements.liquidationMarginRequirement)\n .toNumber();\n }\n return {\n assetAddress: collateralAddress,\n marginBalance: collateralInfo.marginBalance,\n realBalance: collateralInfo.realBalance,\n initialDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.initialMarginRequirement)\n .toNumber(),\n maintenanceDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.maintenanceMarginRequirement)\n .toNumber(),\n liquidationDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.liquidationMarginRequirement)\n .toNumber(),\n dutchDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.dutchMarginRequirement)\n .toNumber(),\n adlDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.adlMarginRequirement)\n .toNumber(),\n initialBufferDelta: BigNumber(collateralInfo.marginBalance)\n .minus(marginRequirements.initialBufferMarginRequirement)\n .toNumber(),\n liquidationMarginRequirement:\n marginRequirements.liquidationMarginRequirement,\n };\n }\n\n static computeLiquidationMarginRequirement(\n matrix: BigNumber[][],\n filledExposures: BigNumber[],\n ): number {\n let lmrFilledSquared = 0;\n\n for (let i = 0; i < filledExposures.length; i++) {\n if (BigNumber(filledExposures[i]).eq(0)) {\n continue;\n }\n for (let j = 0; j < filledExposures.length; j++) {\n const riskParam = matrix[i][j];\n\n if (BigNumber(filledExposures[j]).eq(0) || BigNumber(riskParam).eq(0)) {\n continue;\n }\n\n lmrFilledSquared = BigNumber(lmrFilledSquared)\n .plus(\n BigNumber(filledExposures[i])\n .multipliedBy(filledExposures[j])\n .multipliedBy(riskParam),\n )\n .toNumber();\n }\n }\n return BigNumber(lmrFilledSquared).sqrt().toNumber();\n }\n\n static getBlockExposures(\n positions: PositionInfoMarketConfiguration[],\n oraclePricePerMarket: MarketIdToOraclePriceMap,\n ): BigNumber[] {\n const filledExposures: number[] = [];\n\n for (const position of positions) {\n const marketFilledExposure = ExposureCommand.getAccountFilledExposures(\n position,\n position.market_configuration,\n oraclePricePerMarket[position.market_id],\n );\n filledExposures[marketFilledExposure.riskMatrixIndex] = BigNumber(\n filledExposures[marketFilledExposure.riskMatrixIndex] || 0,\n )\n .plus(marketFilledExposure.exposure)\n .toNumber();\n }\n\n return filledExposures.map((num) => BigNumber(num));\n }\n\n static getAccountFilledExposures(\n position: PositionInfo,\n marketConfiguration: MarketConfiguration,\n oraclePrice: number,\n ) {\n const base = position.base;\n\n return {\n exposure: BigNumber(oraclePrice).multipliedBy(base),\n riskMatrixIndex: BigNumber(\n String(marketConfiguration.risk_matrix_index),\n ).toNumber(),\n };\n }\n\n static computePricePnL(\n openBase: BigNumber,\n openPrice: BigNumber,\n exitPrice: BigNumber,\n ) {\n return BigNumber(\n BigNumber(exitPrice).minus(openPrice).multipliedBy(openBase),\n );\n }\n\n static getMarginRatio(marginInfo: MarginInfo) {\n if (marginInfo.liquidationMarginRequirement === 0) {\n return 0;\n }\n\n if (marginInfo.marginBalance <= 0) {\n return 1;\n }\n\n const health = BigNumber(marginInfo.liquidationMarginRequirement).div(\n marginInfo.marginBalance,\n );\n\n if (health.gt(1)) {\n return 1;\n }\n return health.toNumber();\n }\n\n static exchangeWithPriceHaircut(\n quantity: number,\n price: number,\n haircut: number,\n ) {\n // For positive quantities, the haircut is `quantity * (1 - haircut)`\n // For negative values, the haircut is `quantity / (1 - haircut)` because a negative value means the haircut should be applied from B to A.\n const calHelper = BigNumber(quantity).gt(0)\n ? BigNumber(1).minus(haircut)\n : BigNumber(1).div(BigNumber(1).minus(haircut));\n const haircutPrice = BigNumber(price).multipliedBy(calHelper);\n\n return haircutPrice.multipliedBy(quantity).toNumber();\n }\n\n getSlippage(\n deltaBase: number,\n marketConfiguration: MarketConfiguration,\n marketStorage: MarketStorage,\n ): number {\n const deltaExposure = BigNumber(\n this.oraclePricePerMarket[marketConfiguration.market_id],\n )\n .times(deltaBase)\n .toNumber();\n\n const riskMatrixIndex = BigNumber(\n String(marketConfiguration.risk_matrix_index),\n ).toNumber();\n\n const { maxExposureShort, maxExposureLong, exposures } =\n this.getMaxExposure(marketConfiguration, marketStorage);\n\n const netExposure = exposures[riskMatrixIndex].plus(deltaExposure);\n const maxExposure = netExposure.lt(0) ? maxExposureShort : maxExposureLong;\n\n return BigNumber(netExposure)\n .negated()\n .div(BigNumber(maxExposure).plus(netExposure))\n .toNumber();\n }\n\n getMaxExposure(\n marketConfiguration: MarketConfiguration,\n marketStorage: MarketStorage,\n ) {\n const riskMatrix = this.riskMatrices.find((riskMatrix) => {\n return (\n riskMatrix.risk_block_id ===\n BigNumber(String(marketStorage.risk_block_id)).toNumber()\n );\n });\n\n if (!riskMatrix) {\n throw new Error(\"RiskMatrix Doesn't exist\");\n }\n\n const riskMatrixIndex = BigNumber(\n String(marketConfiguration.risk_matrix_index),\n ).toNumber();\n\n const imrMultiplier = amountNormalizer(\n String(this.riskMultipliers.im_multiplier),\n ).toNumber();\n\n const marginInfo = this.tokenMarginInfoPerAsset.find((marginInfo) => {\n return marginInfo.assetAddress === marketStorage.quote_collateral;\n });\n\n if (!marginInfo) {\n throw new Error(\"marginInfo doesn't exist\");\n }\n\n const exposures = ExposureCommand.getBlockExposures(\n this.positionInfoMarketConfiguration,\n this.oraclePricePerMarket,\n );\n\n const { maxExposureShort, maxExposureLong } =\n ExposureCommand.computeMaxExposures(\n riskMatrix.matrix,\n exposures,\n marginInfo.liquidationMarginRequirement,\n marginInfo.marginBalance < 0 ? 0 : marginInfo.marginBalance,\n imrMultiplier,\n riskMatrixIndex,\n );\n\n return {\n maxExposureShort,\n maxExposureLong,\n exposures,\n };\n }\n\n static computeMaxExposures(\n riskMatrix: BigNumber[][],\n exposures: BigNumber[],\n lmr: number,\n balance: number,\n imrMultiplier: number,\n exposureIndex: number,\n ) {\n let b = BigNumber(0);\n\n for (let i = 0; i < exposures.length; i++) {\n b = BigNumber(b).plus(\n BigNumber(exposures[i]).multipliedBy(\n BigNumber(riskMatrix[exposureIndex][i]).plus(\n riskMatrix[i][exposureIndex],\n ),\n ),\n );\n }\n const { x1, x2 } = this.solveQuadraticEquation(\n BigNumber(riskMatrix[exposureIndex][exposureIndex]).toNumber(), // changes here\n b.toNumber(),\n this.computeC(lmr, balance, imrMultiplier),\n );\n\n const maxShortExposure = BigNumber(x1).plus(exposures[exposureIndex]);\n const maxLongExposure = BigNumber(x2).plus(exposures[exposureIndex]);\n\n const availableShortExposure = maxShortExposure.lt(0)\n ? maxShortExposure.negated().toNumber()\n : 0;\n\n const availableLongExposure = maxLongExposure.gt(0)\n ? maxLongExposure.toNumber()\n : 0;\n\n return {\n maxExposureShort: availableShortExposure,\n maxExposureLong: availableLongExposure,\n };\n }\n\n static solveQuadraticEquation(a: number, b: number, c: number) {\n if (BigNumber(a).eq(0)) {\n throw new Error('ZeroQuadraticCoefficient');\n }\n\n const delta = BigNumber(b)\n .multipliedBy(b)\n .minus(BigNumber(4).multipliedBy(a).multipliedBy(c));\n\n if (delta.lt(0)) {\n throw new Error('ComplexQuadraticRoots(a, b, c)');\n }\n\n const rootDelta = delta.sqrt();\n\n const x1 = BigNumber(b)\n .multipliedBy(-1)\n .minus(rootDelta)\n .div(BigNumber(2).multipliedBy(a));\n\n const x2 = BigNumber(b)\n .multipliedBy(-1)\n .plus(rootDelta)\n .div(BigNumber(2).multipliedBy(a));\n\n return {\n x1,\n x2,\n };\n }\n\n static computeC(lmr: number, balance: number, imrMultiplier: number): number {\n const lmrSD = BigNumber(lmr);\n const lmrSquared = lmrSD.multipliedBy(lmrSD);\n\n const balanceSD = BigNumber(balance);\n const balanceSquared = balanceSD.multipliedBy(balanceSD);\n\n const imrMultiplierSD = BigNumber(imrMultiplier);\n const imrMultiplierSquared = imrMultiplierSD.multipliedBy(imrMultiplierSD);\n\n return lmrSquared\n .minus(balanceSquared.div(imrMultiplierSquared))\n .toNumber();\n }\n\n static calculateFee(\n price: number,\n amount: number,\n feeParameter: BigNumber,\n ): number {\n return BigNumber(price).times(amount).times(feeParameter).abs().toNumber(); // @todo abs value\n }\n\n static calculateEstimatedPrice(price: number, slippage: number): number {\n return BigNumber(price).times(BigNumber(1).plus(slippage)).toNumber();\n }\n\n static evaluateHealthStatus(number: number) {\n // todo update logic\n if (number >= 67) {\n return 'danger';\n } else if (number >= 34) {\n return 'warning';\n } else {\n return 'healthy';\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"trade.simulation.types.js","sourceRoot":"/","sources":["clients/helpers/trade.simulation.types.ts"],"names":[],"mappings":"","sourcesContent":["import BigNumber from 'bignumber.js';\n\nexport interface MarketStorage {\n market_id: number;\n quote_collateral: string;\n instrument_address: string;\n name: string;\n risk_block_id: number;\n collateral_pool_id: number;\n block_timestamp: number;\n block_number: number;\n}\n\nexport interface MarketConfiguration {\n market_id: number;\n risk_matrix_index: number;\n max_open_interest: number;\n oracle_node_id: string;\n mtm_window: number;\n dutch_config_lambda: number;\n dutch_config_min_base: number;\n slippage_params_phi: number;\n slippage_params_beta: number;\n block_timestamp: number;\n block_number: number;\n}\n\nexport type AccountAssetBalance = {\n accountId: number;\n collateral: string;\n amount: number;\n};\n\nexport interface RiskMultipliersConfiguration {\n collateral_pool_id: number;\n im_multiplier: number;\n mmr_multiplier: number;\n dutch_multiplier: number;\n adl_multiplier: number;\n im_buffer_multiplier: number;\n block_timestamp: number;\n block_number: number;\n}\n\nexport interface RiskMatrix {\n collateral_pool_id: number;\n risk_block_id: number;\n matrix: BigNumber[][];\n}\n\nexport interface ExchangeInfo {\n price: number;\n priceHaircut: number;\n autoExchangeDiscount: number;\n tokenAddress: string;\n}\n\nexport interface PositionInfo {\n base: BigNumber;\n realized_pnl: BigNumber;\n last_price: BigNumber;\n last_timestamp: BigNumber;\n funding_value: BigNumber;\n base_multiplier: BigNumber;\n adl_unwind_price: BigNumber;\n market_id: number;\n}\n\nexport type PositionInfoMarketConfiguration = PositionInfo & {\n market_configuration: MarketConfiguration;\n};\n\nexport interface MarginInfo {\n assetAddress: string;\n marginBalance: number;\n realBalance: number;\n initialDelta: number;\n maintenanceDelta: number;\n liquidationDelta: number;\n dutchDelta: number;\n adlDelta: number;\n initialBufferDelta: number;\n liquidationMarginRequirement: number;\n}\n\nexport interface CollateralInfo {\n netDeposits: number;\n marginBalance: number;\n realBalance: number;\n}\n\nexport type ExposureCommandState = {\n rootCollateralPoolId: number;\n oraclePrice: number;\n rate: number;\n accountBalancePerAsset: AccountAssetBalance[];\n groupedByCollateral: Record<string, AccountAssetBalance>;\n riskMultipliers: RiskMultipliersConfiguration;\n riskMatrices: RiskMatrix[];\n exchangeInfoPerAsset: ExchangeInfo[];\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[];\n uniqueTokenAddresses: string[];\n uniqueQuoteCollaterals: string[];\n tokenMarginInfoPerAsset: MarginInfo[];\n realizedPnLSum: BigNumber;\n unrealizedPnLSum: BigNumber;\n};\n\nexport type TradeSimulationState = {\n feeParameter: BigNumber;\n marketStorage: MarketStorage;\n marketConfiguration: MarketConfiguration;\n exposureDataAccount: ExposureCommandState;\n exposureDataPassivePool: ExposureCommandState;\n};\n"]}
1
+ {"version":3,"file":"trade.simulation.types.js","sourceRoot":"/","sources":["clients/helpers/trade.simulation.types.ts"],"names":[],"mappings":"","sourcesContent":["import BigNumber from 'bignumber.js';\n\nexport interface MarketStorage {\n market_id: number;\n quote_collateral: string;\n instrument_address: string;\n name: string;\n risk_block_id: number;\n collateral_pool_id: number;\n block_timestamp: number;\n block_number: number;\n}\n\nexport interface MarketConfiguration {\n market_id: number;\n risk_matrix_index: number;\n max_open_base: number;\n velocity_multiplier: number;\n minimum_order_base: number;\n base_spacing: number;\n price_spacing: number;\n oracle_node_id: string;\n mtm_window: number;\n dutch_config_lambda: number;\n dutch_config_min_base: number;\n slippage_params_phi: number;\n slippage_params_beta: number;\n block_timestamp: number;\n block_number: number;\n}\n\nexport type AccountAssetBalance = {\n accountId: number;\n collateral: string;\n amount: number;\n};\n\nexport interface RiskMultipliersConfiguration {\n collateral_pool_id: number;\n im_multiplier: number;\n mmr_multiplier: number;\n dutch_multiplier: number;\n adl_multiplier: number;\n im_buffer_multiplier: number;\n block_timestamp: number;\n block_number: number;\n}\n\nexport interface RiskMatrix {\n collateral_pool_id: number;\n risk_block_id: number;\n matrix: BigNumber[][];\n}\nexport type MarketIdToOraclePriceMap = {\n [marketId: number]: number;\n};\n\nexport type CollateralAddressToExchangePriceMap = {\n [address: string]: number;\n};\n\nexport interface ExchangeInfo {\n price: number;\n priceHaircut: number;\n autoExchangeDiscount: number;\n tokenAddress: string;\n}\n\nexport interface PositionInfo {\n base: BigNumber;\n realized_pnl: BigNumber;\n last_price: BigNumber;\n last_timestamp: BigNumber;\n funding_value: BigNumber;\n base_multiplier: BigNumber;\n adl_unwind_price: BigNumber;\n market_id: number;\n}\n\nexport type PositionInfoMarketConfiguration = PositionInfo & {\n market_configuration: MarketConfiguration;\n};\n\nexport interface MarginInfo {\n assetAddress: string;\n marginBalance: number;\n realBalance: number;\n initialDelta: number;\n maintenanceDelta: number;\n liquidationDelta: number;\n dutchDelta: number;\n adlDelta: number;\n initialBufferDelta: number;\n liquidationMarginRequirement: number;\n}\n\nexport interface CollateralInfo {\n netDeposits: number;\n marginBalance: number;\n realBalance: number;\n}\n\nexport type ExposureCommandState = {\n rootCollateralPoolId: number;\n oraclePricePerMarket: MarketIdToOraclePriceMap;\n accountBalancePerAsset: AccountAssetBalance[];\n groupedByCollateral: Record<string, AccountAssetBalance>;\n riskMultipliers: RiskMultipliersConfiguration;\n riskMatrices: RiskMatrix[];\n exchangeInfoPerAsset: ExchangeInfo[];\n positionInfoMarketConfiguration: PositionInfoMarketConfiguration[];\n uniqueTokenAddresses: string[];\n uniqueQuoteCollaterals: string[];\n tokenMarginInfoPerAsset: MarginInfo[];\n realizedPnLSum: BigNumber;\n unrealizedPnLSum: BigNumber;\n};\n\nexport type TradeSimulationState = {\n feeParameter: BigNumber;\n marketStorage: MarketStorage;\n marketConfiguration: MarketConfiguration;\n exposureDataAccount: ExposureCommandState;\n exposureDataPassivePool: ExposureCommandState;\n};\n"]}
@@ -85,6 +85,7 @@ var LpClient = /** @class */ (function (_super) {
85
85
  uri = "/api/lp-pools/".concat(params.id, "/transaction-history");
86
86
  return [2 /*return*/, this.get(uri, {
87
87
  limit: params.limit,
88
+ address: params.address,
88
89
  })];
89
90
  });
90
91
  });
@@ -94,7 +95,9 @@ var LpClient = /** @class */ (function (_super) {
94
95
  var uri;
95
96
  return __generator(this, function (_a) {
96
97
  uri = "/api/lp-pools/".concat(params.id, "/positions");
97
- return [2 /*return*/, this.get(uri)];
98
+ return [2 /*return*/, this.get(uri, {
99
+ address: params.address,
100
+ })];
98
101
  });
99
102
  });
100
103
  };
@@ -1 +1 @@
1
- {"version":3,"file":"lp.js","sourceRoot":"/","sources":["clients/modules/lp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,gDAAgC;AAEhC;IAAsC,4BAAU;IAAhD;;IAmCA,CAAC;IAlCO,6BAAU,GAAhB;;;;gBACQ,GAAG,GAAG,eAAe,CAAC;gBAC5B,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,4BAAS,GAAf,UAAgB,MAAuB;;;;gBAC/B,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,CAAE,CAAC;gBACzC,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,8CAA2B,GAAjC,UACE,MAAyC;;;;gBAEnC,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,yBAAsB,CAAC;gBAC7D,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;qBACpB,CAAC,EAAC;;;KACJ;IAEK,iCAAc,GAApB,UACE,MAA+B;;;;gBAEzB,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,eAAY,CAAC;gBACnD,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,2CAAwB,GAA9B,UACE,MAAsC;;;;gBAEhC,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,sBAAmB,CAAC;gBAC1D,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;qBACxB,CAAC,EAAC;;;KACJ;IACH,eAAC;AAAD,CAAC,AAnCD,CAAsC,cAAU,GAmC/C","sourcesContent":["import {\n GetLpPoolParams,\n GetLpPoolPositionParams,\n GetLpPoolResult,\n GetLpPoolsResult,\n GetLpPoolTransactionHistoryParams,\n GetLpPoolTransactionHistoryResult,\n GetLpPositionsResult,\n GetLpPoolWithdrawBalanceParams,\n GetLpPoolWithdrawBalanceResult,\n} from '../types';\nimport RestClient from './rest';\n\nexport default class LpClient extends RestClient {\n async getLpPools(): Promise<GetLpPoolsResult> {\n const uri = '/api/lp-pools';\n return this.get(uri);\n }\n\n async getLpPool(params: GetLpPoolParams): Promise<GetLpPoolResult> {\n const uri = `/api/lp-pools/${params.id}`;\n return this.get(uri);\n }\n\n async getLpPoolTransactionHistory(\n params: GetLpPoolTransactionHistoryParams,\n ): Promise<GetLpPoolTransactionHistoryResult> {\n const uri = `/api/lp-pools/${params.id}/transaction-history`;\n return this.get(uri, {\n limit: params.limit,\n });\n }\n\n async getLpPositions(\n params: GetLpPoolPositionParams,\n ): Promise<GetLpPositionsResult> {\n const uri = `/api/lp-pools/${params.id}/positions`;\n return this.get(uri);\n }\n\n async getLpPoolWithdrawBalance(\n params: GetLpPoolWithdrawBalanceParams,\n ): Promise<GetLpPoolWithdrawBalanceResult> {\n const uri = `/api/lp-pools/${params.id}/withdraw-balance`;\n return this.get(uri, {\n address: params.address,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"lp.js","sourceRoot":"/","sources":["clients/modules/lp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,gDAAgC;AAEhC;IAAsC,4BAAU;IAAhD;;IAsCA,CAAC;IArCO,6BAAU,GAAhB;;;;gBACQ,GAAG,GAAG,eAAe,CAAC;gBAC5B,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,4BAAS,GAAf,UAAgB,MAAuB;;;;gBAC/B,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,CAAE,CAAC;gBACzC,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IAEK,8CAA2B,GAAjC,UACE,MAAyC;;;;gBAEnC,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,yBAAsB,CAAC;gBAC7D,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;qBACxB,CAAC,EAAC;;;KACJ;IAEK,iCAAc,GAApB,UACE,MAA4B;;;;gBAEtB,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,eAAY,CAAC;gBACnD,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;qBACxB,CAAC,EAAC;;;KACJ;IAEK,2CAAwB,GAA9B,UACE,MAAsC;;;;gBAEhC,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,sBAAmB,CAAC;gBAC1D,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;qBACxB,CAAC,EAAC;;;KACJ;IACH,eAAC;AAAD,CAAC,AAtCD,CAAsC,cAAU,GAsC/C","sourcesContent":["import {\n GetLpPoolParams,\n GetLpPositionsParams,\n GetLpPoolResult,\n GetLpPoolsResult,\n GetLpPoolTransactionHistoryParams,\n GetLpPoolTransactionHistoryResult,\n GetLpPositionsResult,\n GetLpPoolWithdrawBalanceParams,\n GetLpPoolWithdrawBalanceResult,\n} from '../types';\nimport RestClient from './rest';\n\nexport default class LpClient extends RestClient {\n async getLpPools(): Promise<GetLpPoolsResult> {\n const uri = '/api/lp-pools';\n return this.get(uri);\n }\n\n async getLpPool(params: GetLpPoolParams): Promise<GetLpPoolResult> {\n const uri = `/api/lp-pools/${params.id}`;\n return this.get(uri);\n }\n\n async getLpPoolTransactionHistory(\n params: GetLpPoolTransactionHistoryParams,\n ): Promise<GetLpPoolTransactionHistoryResult> {\n const uri = `/api/lp-pools/${params.id}/transaction-history`;\n return this.get(uri, {\n limit: params.limit,\n address: params.address,\n });\n }\n\n async getLpPositions(\n params: GetLpPositionsParams,\n ): Promise<GetLpPositionsResult> {\n const uri = `/api/lp-pools/${params.id}/positions`;\n return this.get(uri, {\n address: params.address,\n });\n }\n\n async getLpPoolWithdrawBalance(\n params: GetLpPoolWithdrawBalanceParams,\n ): Promise<GetLpPoolWithdrawBalanceResult> {\n const uri = `/api/lp-pools/${params.id}/withdraw-balance`;\n return this.get(uri, {\n address: params.address,\n });\n }\n}\n"]}
@@ -83,18 +83,19 @@ var TradeSimulationClient = /** @class */ (function () {
83
83
  throw new Error('Data not loaded. Call arm() first.');
84
84
  }
85
85
  var amount = (0, bignumber_js_1.default)(params.amount)
86
- .div(this.loadedData.exposureDataAccount.oraclePrice)
86
+ .div(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id])
87
87
  .toNumber();
88
- var userAccountExposure = new exposure_calculator_1.ExposureCommand(this.loadedData.exposureDataAccount.rootCollateralPoolId, this.loadedData.exposureDataAccount.oraclePrice, this.loadedData.exposureDataAccount.rate, this.loadedData.exposureDataAccount.accountBalancePerAsset, this.loadedData.exposureDataAccount.groupedByCollateral, this.loadedData.exposureDataAccount.riskMultipliers, this.loadedData.exposureDataAccount.riskMatrices, this.loadedData.exposureDataAccount.exchangeInfoPerAsset, this.loadedData.exposureDataAccount.positionInfoMarketConfiguration, this.loadedData.exposureDataAccount.uniqueTokenAddresses, this.loadedData.exposureDataAccount.uniqueQuoteCollaterals, this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset, this.loadedData.exposureDataAccount.realizedPnLSum, this.loadedData.exposureDataAccount.unrealizedPnLSum);
89
- var passivePoolExposure = new exposure_calculator_1.ExposureCommand(this.loadedData.exposureDataPassivePool.rootCollateralPoolId, this.loadedData.exposureDataPassivePool.oraclePrice, this.loadedData.exposureDataPassivePool.rate, this.loadedData.exposureDataPassivePool.accountBalancePerAsset, this.loadedData.exposureDataPassivePool.groupedByCollateral, this.loadedData.exposureDataPassivePool.riskMultipliers, this.loadedData.exposureDataPassivePool.riskMatrices, this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset, this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration, this.loadedData.exposureDataPassivePool.uniqueTokenAddresses, this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals, this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset, this.loadedData.exposureDataPassivePool.realizedPnLSum, this.loadedData.exposureDataPassivePool.unrealizedPnLSum);
88
+ var userAccountExposure = new exposure_calculator_1.ExposureCommand(this.loadedData.exposureDataAccount.rootCollateralPoolId, this.loadedData.exposureDataAccount.oraclePricePerMarket, this.loadedData.exposureDataAccount.accountBalancePerAsset, this.loadedData.exposureDataAccount.groupedByCollateral, this.loadedData.exposureDataAccount.riskMultipliers, this.loadedData.exposureDataAccount.riskMatrices, this.loadedData.exposureDataAccount.exchangeInfoPerAsset, this.loadedData.exposureDataAccount.positionInfoMarketConfiguration, this.loadedData.exposureDataAccount.uniqueTokenAddresses, this.loadedData.exposureDataAccount.uniqueQuoteCollaterals, this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset, this.loadedData.exposureDataAccount.realizedPnLSum, this.loadedData.exposureDataAccount.unrealizedPnLSum);
89
+ var passivePoolExposure = new exposure_calculator_1.ExposureCommand(this.loadedData.exposureDataPassivePool.rootCollateralPoolId, this.loadedData.exposureDataPassivePool.oraclePricePerMarket, this.loadedData.exposureDataPassivePool.accountBalancePerAsset, this.loadedData.exposureDataPassivePool.groupedByCollateral, this.loadedData.exposureDataPassivePool.riskMultipliers, this.loadedData.exposureDataPassivePool.riskMatrices, this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset, this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration, this.loadedData.exposureDataPassivePool.uniqueTokenAddresses, this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals, this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset, this.loadedData.exposureDataPassivePool.realizedPnLSum, this.loadedData.exposureDataPassivePool.unrealizedPnLSum);
90
90
  var slippage = passivePoolExposure.getSlippage(amount, this.loadedData.marketConfiguration, this.loadedData.marketStorage);
91
- var estimatedPrice = exposure_calculator_1.ExposureCommand.calculateEstimatedPrice(this.loadedData.exposureDataPassivePool.oraclePrice, slippage);
92
- var fees = exposure_calculator_1.ExposureCommand.calculateFee(this.loadedData.exposureDataAccount.oraclePrice, amount, this.loadedData.feeParameter);
91
+ var estimatedPrice = exposure_calculator_1.ExposureCommand.calculateEstimatedPrice(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], slippage);
92
+ var fees = exposure_calculator_1.ExposureCommand.calculateFee(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], amount, this.loadedData.feeParameter);
93
93
  var oldMarginInfo = userAccountExposure.getUsdNodeMarginInfo;
94
94
  var newMarginInfo = userAccountExposure.getUsdNodeMarginInfoPostTrade(amount, this.loadedData.marketStorage.quote_collateral, this.loadedData.marketConfiguration);
95
- var impliedLeverage = exposure_calculator_1.ExposureCommand.calculateImpliedLeverage(amount * this.loadedData.exposureDataAccount.oraclePrice, oldMarginInfo.marginBalance - oldMarginInfo.initialDelta, newMarginInfo.marginBalance - newMarginInfo.initialDelta);
95
+ var impliedLeverage = exposure_calculator_1.ExposureCommand.calculateImpliedLeverage(amount *
96
+ this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], oldMarginInfo.marginBalance - oldMarginInfo.initialDelta, newMarginInfo.marginBalance - newMarginInfo.initialDelta);
96
97
  var postTradeImr = newMarginInfo.marginBalance - newMarginInfo.initialDelta;
97
- var liquidationPrice = exposure_calculator_1.ExposureCommand.calculateLiquidation(newMarginInfo, this.loadedData.exposureDataAccount.oraclePrice, amount);
98
+ var liquidationPrice = exposure_calculator_1.ExposureCommand.calculateLiquidation(newMarginInfo, this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], amount);
98
99
  var marginRatio = exposure_calculator_1.ExposureCommand.getMarginRatio(newMarginInfo) * 100;
99
100
  var marginRatioHealth = exposure_calculator_1.ExposureCommand.evaluateHealthStatus(marginRatio);
100
101
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"trade.simulation.js","sourceRoot":"/","sources":["clients/modules/trade.simulation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,sEAAiE;AACjE,8DAAqC;AAErC;IAKE,+BAAY,aAA4B;QAJhC,aAAQ,GAAkB,IAAI,CAAC;QAC/B,cAAS,GAAkB,IAAI,CAAC;QAChC,eAAU,GAAgC,IAAI,CAAC;QAGrD,oBAAoB;QACpB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,qEAAqE;IAC/D,mCAAG,GAAT,UAAU,MAAqC;;;;;;wBAC7C,IAAI,CAAC,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,EAAE,YAAY;YACjB,gBAAgB,EAAE,gBAAgB,CAAC,QAAQ,EAAE;YAC7C,WAAW,EAAE,WAAW;YACxB,iBAAiB,EAAE,iBAAiB;SACd,CAAC;IAC3B,CAAC;IACH,4BAAC;AAAD,CAAC,AA7HD,IA6HC","sourcesContent":["import {\n SimulateTradeEntity,\n TradeSimulationLoadDataParams,\n TradeSimulationSimulateParams,\n} from '../types';\nimport AccountClient from './account';\nimport { TradeSimulationState } from '../helpers/trade.simulation.types';\nimport { ExposureCommand } from '../helpers/exposure.calculator';\nimport BigNumber from 'bignumber.js';\n\nexport default class TradeSimulationClient {\n private marketId: number | null = null;\n private accountId: number | null = null;\n private loadedData: TradeSimulationState | null = null;\n private accountClient: AccountClient;\n constructor(accountClient: AccountClient) {\n // Constructor added\n this.accountClient = accountClient;\n }\n\n // Method to asynchronously load data based on marketId and accountId\n async arm(params: TradeSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n this.accountId = params.marginAccountId;\n\n this.loadedData = await this.fetchMarketData(this.marketId, this.accountId);\n }\n\n private async fetchMarketData(\n marketId: number,\n accountId: number,\n ): Promise<TradeSimulationState> {\n return this.accountClient.getTransactionSimulationInitialData({\n marginAccountId: accountId,\n marketId: marketId,\n });\n }\n\n // Synchronous method to simulate operations based on an amount\n simulate(params: TradeSimulationSimulateParams): SimulateTradeEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const amount = BigNumber(params.amount)\n .div(this.loadedData.exposureDataAccount.oraclePrice)\n .toNumber();\n\n const userAccountExposure = new ExposureCommand(\n this.loadedData.exposureDataAccount.rootCollateralPoolId,\n this.loadedData.exposureDataAccount.oraclePrice,\n this.loadedData.exposureDataAccount.rate,\n this.loadedData.exposureDataAccount.accountBalancePerAsset,\n this.loadedData.exposureDataAccount.groupedByCollateral,\n this.loadedData.exposureDataAccount.riskMultipliers,\n this.loadedData.exposureDataAccount.riskMatrices,\n this.loadedData.exposureDataAccount.exchangeInfoPerAsset,\n this.loadedData.exposureDataAccount.positionInfoMarketConfiguration,\n this.loadedData.exposureDataAccount.uniqueTokenAddresses,\n this.loadedData.exposureDataAccount.uniqueQuoteCollaterals,\n this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset,\n this.loadedData.exposureDataAccount.realizedPnLSum,\n this.loadedData.exposureDataAccount.unrealizedPnLSum,\n );\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.rootCollateralPoolId,\n this.loadedData.exposureDataPassivePool.oraclePrice,\n this.loadedData.exposureDataPassivePool.rate,\n this.loadedData.exposureDataPassivePool.accountBalancePerAsset,\n this.loadedData.exposureDataPassivePool.groupedByCollateral,\n this.loadedData.exposureDataPassivePool.riskMultipliers,\n this.loadedData.exposureDataPassivePool.riskMatrices,\n this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset,\n this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration,\n this.loadedData.exposureDataPassivePool.uniqueTokenAddresses,\n this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals,\n this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,\n this.loadedData.exposureDataPassivePool.realizedPnLSum,\n this.loadedData.exposureDataPassivePool.unrealizedPnLSum,\n );\n\n const slippage = passivePoolExposure.getSlippage(\n amount,\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePrice,\n slippage,\n );\n const fees = ExposureCommand.calculateFee(\n this.loadedData.exposureDataAccount.oraclePrice,\n amount,\n this.loadedData.feeParameter,\n );\n\n const oldMarginInfo = userAccountExposure.getUsdNodeMarginInfo;\n\n const newMarginInfo = userAccountExposure.getUsdNodeMarginInfoPostTrade(\n amount,\n this.loadedData.marketStorage.quote_collateral,\n this.loadedData.marketConfiguration,\n );\n\n const impliedLeverage = ExposureCommand.calculateImpliedLeverage(\n amount * this.loadedData.exposureDataAccount.oraclePrice,\n oldMarginInfo.marginBalance - oldMarginInfo.initialDelta,\n newMarginInfo.marginBalance - newMarginInfo.initialDelta,\n );\n\n const postTradeImr =\n newMarginInfo.marginBalance - newMarginInfo.initialDelta;\n\n const liquidationPrice = ExposureCommand.calculateLiquidation(\n newMarginInfo,\n this.loadedData.exposureDataAccount.oraclePrice,\n amount,\n );\n\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo) * 100;\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(marginRatio);\n\n return {\n estimatedPrice: estimatedPrice,\n estimatedSlippage: slippage * 100,\n fees: fees,\n impliedLeverage: impliedLeverage,\n imr: postTradeImr,\n liquidationPrice: liquidationPrice.toNumber(),\n marginRatio: marginRatio,\n marginRatioHealth: marginRatioHealth,\n } as SimulateTradeEntity;\n }\n}\n"]}
1
+ {"version":3,"file":"trade.simulation.js","sourceRoot":"/","sources":["clients/modules/trade.simulation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,sEAAiE;AACjE,8DAAqC;AAErC;IAKE,+BAAY,aAA4B;QAJhC,aAAQ,GAAkB,IAAI,CAAC;QAC/B,cAAS,GAAkB,IAAI,CAAC;QAChC,eAAU,GAAgC,IAAI,CAAC;QAGrD,oBAAoB;QACpB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,qEAAqE;IAC/D,mCAAG,GAAT,UAAU,MAAqC;;;;;;wBAC7C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;wBAChC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,eAAe,CAAC;wBAExC,KAAA,IAAI,CAAA;wBAAc,qBAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,EAAA;;wBAA3E,GAAK,UAAU,GAAG,SAAyD,CAAC;;;;;KAC7E;IAEa,+CAAe,GAA7B,UACE,QAAgB,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,EAAE,iBAAiB;SACd,CAAC;IAC3B,CAAC;IACH,4BAAC;AAAD,CAAC,AAxID,IAwIC","sourcesContent":["import {\n SimulateTradeEntity,\n TradeSimulationLoadDataParams,\n TradeSimulationSimulateParams,\n} from '../types';\nimport AccountClient from './account';\nimport { TradeSimulationState } from '../helpers/trade.simulation.types';\nimport { ExposureCommand } from '../helpers/exposure.calculator';\nimport BigNumber from 'bignumber.js';\n\nexport default class TradeSimulationClient {\n private marketId: number | null = null;\n private accountId: number | null = null;\n private loadedData: TradeSimulationState | null = null;\n private accountClient: AccountClient;\n constructor(accountClient: AccountClient) {\n // Constructor added\n this.accountClient = accountClient;\n }\n\n // Method to asynchronously load data based on marketId and accountId\n async arm(params: TradeSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n this.accountId = params.marginAccountId;\n\n this.loadedData = await this.fetchMarketData(this.marketId, this.accountId);\n }\n\n private async fetchMarketData(\n marketId: number,\n accountId: number,\n ): Promise<TradeSimulationState> {\n return this.accountClient.getTransactionSimulationInitialData({\n marginAccountId: accountId,\n marketId: marketId,\n });\n }\n\n // Synchronous method to simulate operations based on an amount\n simulate(params: TradeSimulationSimulateParams): SimulateTradeEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const amount = BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const userAccountExposure = new ExposureCommand(\n this.loadedData.exposureDataAccount.rootCollateralPoolId,\n this.loadedData.exposureDataAccount.oraclePricePerMarket,\n this.loadedData.exposureDataAccount.accountBalancePerAsset,\n this.loadedData.exposureDataAccount.groupedByCollateral,\n this.loadedData.exposureDataAccount.riskMultipliers,\n this.loadedData.exposureDataAccount.riskMatrices,\n this.loadedData.exposureDataAccount.exchangeInfoPerAsset,\n this.loadedData.exposureDataAccount.positionInfoMarketConfiguration,\n this.loadedData.exposureDataAccount.uniqueTokenAddresses,\n this.loadedData.exposureDataAccount.uniqueQuoteCollaterals,\n this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset,\n this.loadedData.exposureDataAccount.realizedPnLSum,\n this.loadedData.exposureDataAccount.unrealizedPnLSum,\n );\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.rootCollateralPoolId,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket,\n this.loadedData.exposureDataPassivePool.accountBalancePerAsset,\n this.loadedData.exposureDataPassivePool.groupedByCollateral,\n this.loadedData.exposureDataPassivePool.riskMultipliers,\n this.loadedData.exposureDataPassivePool.riskMatrices,\n this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset,\n this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration,\n this.loadedData.exposureDataPassivePool.uniqueTokenAddresses,\n this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals,\n this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,\n this.loadedData.exposureDataPassivePool.realizedPnLSum,\n this.loadedData.exposureDataPassivePool.unrealizedPnLSum,\n );\n\n const slippage = passivePoolExposure.getSlippage(\n amount,\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n slippage,\n );\n const fees = ExposureCommand.calculateFee(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n amount,\n this.loadedData.feeParameter,\n );\n\n const oldMarginInfo = userAccountExposure.getUsdNodeMarginInfo;\n\n const newMarginInfo = userAccountExposure.getUsdNodeMarginInfoPostTrade(\n amount,\n this.loadedData.marketStorage.quote_collateral,\n this.loadedData.marketConfiguration,\n );\n\n const impliedLeverage = ExposureCommand.calculateImpliedLeverage(\n amount *\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n oldMarginInfo.marginBalance - oldMarginInfo.initialDelta,\n newMarginInfo.marginBalance - newMarginInfo.initialDelta,\n );\n\n const postTradeImr =\n newMarginInfo.marginBalance - newMarginInfo.initialDelta;\n\n const liquidationPrice = ExposureCommand.calculateLiquidation(\n newMarginInfo,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n amount,\n );\n\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo) * 100;\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(marginRatio);\n\n return {\n estimatedPrice: estimatedPrice,\n estimatedSlippage: slippage * 100,\n fees: fees,\n impliedLeverage: impliedLeverage,\n imr: postTradeImr,\n liquidationPrice: liquidationPrice.toNumber(),\n marginRatio: marginRatio,\n marginRatioHealth: marginRatioHealth,\n } as SimulateTradeEntity;\n }\n}\n"]}
@@ -14,7 +14,7 @@ var CandlesResolution;
14
14
  // ---- LP ----
15
15
  var SupportedChainId;
16
16
  (function (SupportedChainId) {
17
- SupportedChainId[SupportedChainId["mainnet"] = 1] = "mainnet";
18
17
  SupportedChainId[SupportedChainId["polygonMumbai"] = 80001] = "polygonMumbai";
18
+ SupportedChainId[SupportedChainId["reyaCronos"] = 1729] = "reyaCronos";
19
19
  })(SupportedChainId || (exports.SupportedChainId = SupportedChainId = {}));
20
20
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAQX;AARD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,2CAAsB,CAAA;IACtB,+CAA0B,CAAA;IAC1B,8CAAyB,CAAA;IACzB,uCAAkB,CAAA;IAClB,0CAAqB,CAAA;IACrB,qCAAgB,CAAA;AAClB,CAAC,EARW,iBAAiB,iCAAjB,iBAAiB,QAQ5B;AA2MD,eAAe;AAEf,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6DAAW,CAAA;IACX,6EAAqB,CAAA;AACvB,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B","sourcesContent":["export enum CandlesResolution {\n ONE_MINUTE = '1MIN',\n FIVE_MINUTES = '5MINS',\n FIFTEEN_MINUTES = '15MINS',\n THIRTY_MINUTES = '30MINS',\n ONE_HOUR = '1HOUR',\n FOUR_HOURS = '4HOURS',\n ONE_DAY = '1DAY',\n}\n\n// -- Candles --\nexport interface Candle {\n id: string;\n startedAt: string;\n ticker: string;\n resolution: CandlesResolution;\n low: string;\n high: string;\n open: string;\n close: string;\n baseTokenVolume: string;\n usdVolume: string;\n trades: number;\n startingOpenInterest: string;\n}\n\nexport interface MarketCandlesResponse {\n candles: Candle[];\n}\n\n// -- Markets --\n\nexport type MarketOrderInfo = {\n counterpartyAccountIds: number[];\n exchangeId: number;\n};\n\nexport type MarketEntity = {\n id: number;\n ticker: string;\n underlyingAsset: string;\n quoteToken: string;\n markPrice: number;\n isActive: boolean;\n maxLeverage: number;\n volume24H: number;\n priceChange24H: number;\n priceChange24HPercentage: number;\n openInterest: number;\n fundingRate: number;\n description: string;\n orderInfo: MarketOrderInfo;\n tickSizeDecimals: number;\n};\n\nexport type GetMarketsResult = MarketEntity[];\n\nexport type GetMarketResult = MarketEntity;\n\nexport type GetMarketParams = {\n id: MarketEntity['id'];\n};\n\nexport type GetCandlesParams = {\n marketId: MarketEntity['id'];\n resolution: CandlesResolution;\n fromISO?: string | null;\n toISO?: string | null;\n limit?: number | null;\n};\n\n// -- Account --\n\nexport type Status = 'OPEN' | 'CLOSED' | 'LIQUIDATED' | 'FILLED';\nexport type Side = 'long' | 'short';\n\nexport type GetMarginAccountsParams = {\n address: string;\n limit?: number;\n};\n\nexport type GetMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type GetPositionsForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type MarginAccountEntity = {\n id: number;\n name: string;\n marginRatioHealth: 'danger' | 'healthy' | 'warning';\n marginRatioPercentage: number;\n totalBalance: number;\n totalBalanceUnderlyingAsset: string;\n collaterals: {\n token: string;\n percentage: number;\n balance: number;\n balanceRUSD: number;\n }[];\n};\n\nexport type GetMarginAccountsResult = MarginAccountEntity[];\nexport type GetMarginAccountResult = MarginAccountEntity;\n\nexport type PositionEntity = {\n id: number;\n side: Side;\n size: number;\n base: number;\n price: number;\n markPrice: number;\n orderStatus: Status;\n realisedPnl?: number | null;\n unrealisedPnl?: number | null;\n liquidationPrice: number;\n fundingRate: number;\n market: MarketEntity;\n date: Date;\n};\n\nexport type GetPositionsForMarginAccountResult = {\n positions: PositionEntity[];\n totalUnrealizedPNL: number;\n};\n\n// --- Trading History ----\n\nexport type GetMarketTradingHistoryParams = {\n marketId: number;\n limit?: number;\n};\n\nexport type TradingHistoryEntity = {\n id: number;\n price: number;\n priceUnderlyingToken: string;\n size: number;\n sizeUnderlyingToken: string;\n timestampMillisecondsUTC: number;\n};\n\nexport type GetTradingHistoryResult = TradingHistoryEntity[];\n\n// --- Position History ---\n\nexport type GetPositionsHistoryForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type OrderType = 'market';\n\nexport type PositionHistoryType =\n | 'long-trade'\n | 'short-trade'\n | 'long-liquidation'\n | 'short-liquidation';\n\nexport type PositionHistoryEntity = {\n id: number;\n action: PositionHistoryType;\n orderType: OrderType;\n size: number;\n executionPrice: number;\n realisedPnl?: number | null;\n fees: number;\n timestamp: number;\n market: MarketEntity;\n};\n\nexport type GetPositionsHistoryForMarginAccountResult = PositionHistoryEntity[];\n\n// -- Max Order Size --\n\nexport type GetMaxOrderSizeAvailableParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n direction: 'long' | 'short';\n};\n\nexport type GetMaxOrderSizeAvailableResult = number;\n\n// --- Trade Simulation ----\n\nexport type SimulateTradeEntity = {\n liquidationPrice: number;\n fees: number;\n estimatedPrice: number;\n estimatedSlippage: number;\n imr: number;\n impliedLeverage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n};\n\nexport type TradeSimulationLoadDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type TradeSimulationSimulateParams = {\n amount: number; // position size, + for long | - for short\n};\n\n// ---- LP ----\n\nexport enum SupportedChainId {\n mainnet = 1,\n polygonMumbai = 80001,\n}\n\nexport type LpPoolEntity = {\n id: number;\n name: string;\n description: string;\n currentAPY: number;\n balanceSupplied?: number | null;\n balanceChange24H: number;\n tokenAddress: string;\n token: string;\n allowedChainsForLiquidity: number[];\n chainId: SupportedChainId;\n};\n\nexport type GetLpPoolsResult = LpPoolEntity[];\n\nexport type GetLpPoolResult = LpPoolEntity;\n\nexport type GetLpPoolParams = {\n id: LpPoolEntity['id'];\n};\n\nexport type TransactionHistoryType = 'deposit' | 'withdrawal';\n\nexport type LpTransactionHistoryEntity = {\n id: number;\n type: TransactionHistoryType;\n token: string;\n amount: number;\n transactionHash: string;\n timestamp: number;\n};\n\nexport type GetLpPoolTransactionHistoryParams = {\n id: LpPoolEntity['id'];\n limit?: number;\n};\n\nexport type GetLpPoolTransactionHistoryResult = LpTransactionHistoryEntity[];\n\nexport type GetLpPoolPositionParams = {\n id: LpPoolEntity['id'];\n};\n\nexport type LpPositionEntity = {\n id: number;\n deposited: number;\n currentBalance: number;\n pnl: number;\n fundingRate: number;\n};\n\nexport type GetLpPositionsResult = LpPositionEntity[];\n\nexport type GetLpPoolWithdrawBalanceParams = {\n id: LpPoolEntity['id'];\n address: string; // wallet address\n};\n\nexport type GetLpPoolWithdrawBalanceResult = number;\n\n// ---- Transaction Simulation ----\n\nexport type GetTransactionSimulationInitialDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAQX;AARD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,2CAAsB,CAAA;IACtB,+CAA0B,CAAA;IAC1B,8CAAyB,CAAA;IACzB,uCAAkB,CAAA;IAClB,0CAAqB,CAAA;IACrB,qCAAgB,CAAA;AAClB,CAAC,EARW,iBAAiB,iCAAjB,iBAAiB,QAQ5B;AA2MD,eAAe;AAEf,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6EAAqB,CAAA;IACrB,sEAAiB,CAAA;AACnB,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B","sourcesContent":["export enum CandlesResolution {\n ONE_MINUTE = '1MIN',\n FIVE_MINUTES = '5MINS',\n FIFTEEN_MINUTES = '15MINS',\n THIRTY_MINUTES = '30MINS',\n ONE_HOUR = '1HOUR',\n FOUR_HOURS = '4HOURS',\n ONE_DAY = '1DAY',\n}\n\n// -- Candles --\nexport interface Candle {\n id: string;\n startedAt: string;\n ticker: string;\n resolution: CandlesResolution;\n low: string;\n high: string;\n open: string;\n close: string;\n baseTokenVolume: string;\n usdVolume: string;\n trades: number;\n startingOpenInterest: string;\n}\n\nexport interface MarketCandlesResponse {\n candles: Candle[];\n}\n\n// -- Markets --\n\nexport type MarketOrderInfo = {\n counterpartyAccountIds: number[];\n exchangeId: number;\n};\n\nexport type MarketEntity = {\n id: number;\n ticker: string;\n underlyingAsset: string;\n quoteToken: string;\n markPrice: number;\n isActive: boolean;\n maxLeverage: number;\n volume24H: number;\n priceChange24H: number;\n priceChange24HPercentage: number;\n openInterest: number;\n fundingRate: number;\n description: string;\n orderInfo: MarketOrderInfo;\n tickSizeDecimals: number;\n};\n\nexport type GetMarketsResult = MarketEntity[];\n\nexport type GetMarketResult = MarketEntity;\n\nexport type GetMarketParams = {\n id: MarketEntity['id'];\n};\n\nexport type GetCandlesParams = {\n marketId: MarketEntity['id'];\n resolution: CandlesResolution;\n fromISO?: string | null;\n toISO?: string | null;\n limit?: number | null;\n};\n\n// -- Account --\n\nexport type Status = 'OPEN' | 'CLOSED' | 'LIQUIDATED' | 'FILLED';\nexport type Side = 'long' | 'short';\n\nexport type GetMarginAccountsParams = {\n address: string;\n limit?: number;\n};\n\nexport type GetMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type GetPositionsForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type MarginAccountEntity = {\n id: number;\n name: string;\n marginRatioHealth: 'danger' | 'healthy' | 'warning';\n marginRatioPercentage: number;\n totalBalance: number;\n totalBalanceUnderlyingAsset: string;\n collaterals: {\n token: string;\n percentage: number;\n balance: number;\n balanceRUSD: number;\n }[];\n};\n\nexport type GetMarginAccountsResult = MarginAccountEntity[];\nexport type GetMarginAccountResult = MarginAccountEntity;\n\nexport type PositionEntity = {\n id: number;\n side: Side;\n size: number;\n base: number;\n price: number;\n markPrice: number;\n orderStatus: Status;\n realisedPnl?: number | null;\n unrealisedPnl?: number | null;\n liquidationPrice: number;\n fundingRate: number;\n market: MarketEntity;\n date: Date;\n};\n\nexport type GetPositionsForMarginAccountResult = {\n positions: PositionEntity[];\n totalUnrealizedPNL: number;\n};\n\n// --- Trading History ----\n\nexport type GetMarketTradingHistoryParams = {\n marketId: number;\n limit?: number;\n};\n\nexport type TradingHistoryEntity = {\n id: number;\n price: number;\n priceUnderlyingToken: string;\n size: number;\n sizeUnderlyingToken: string;\n timestampMillisecondsUTC: number;\n};\n\nexport type GetTradingHistoryResult = TradingHistoryEntity[];\n\n// --- Position History ---\n\nexport type GetPositionsHistoryForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type OrderType = 'market';\n\nexport type PositionHistoryType =\n | 'long-trade'\n | 'short-trade'\n | 'long-liquidation'\n | 'short-liquidation';\n\nexport type PositionHistoryEntity = {\n id: number;\n action: PositionHistoryType;\n orderType: OrderType;\n size: number;\n executionPrice: number;\n realisedPnl?: number | null;\n fees: number;\n timestamp: number;\n market: MarketEntity;\n};\n\nexport type GetPositionsHistoryForMarginAccountResult = PositionHistoryEntity[];\n\n// -- Max Order Size --\n\nexport type GetMaxOrderSizeAvailableParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n direction: 'long' | 'short';\n};\n\nexport type GetMaxOrderSizeAvailableResult = number;\n\n// --- Trade Simulation ----\n\nexport type SimulateTradeEntity = {\n liquidationPrice: number;\n fees: number;\n estimatedPrice: number;\n estimatedSlippage: number;\n imr: number;\n impliedLeverage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n};\n\nexport type TradeSimulationLoadDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type TradeSimulationSimulateParams = {\n amount: number; // position size, + for long | - for short\n};\n\n// ---- LP ----\n\nexport enum SupportedChainId {\n polygonMumbai = 80001,\n reyaCronos = 1729,\n}\n\nexport type LpPoolEntity = {\n id: number;\n name: string;\n description: string;\n longDescription: string;\n readMoreLink: string;\n currentAPY: number;\n balanceSupplied?: number | null;\n apyChange24H: number;\n tokenAddress: string;\n token: string;\n allowedChainsForLiquidity: number[];\n chainId: SupportedChainId;\n};\n\nexport type GetLpPoolsResult = LpPoolEntity[];\n\nexport type GetLpPoolResult = LpPoolEntity;\n\nexport type GetLpPoolParams = {\n id: LpPoolEntity['id'];\n};\n\nexport type TransactionHistoryType = 'deposit' | 'withdrawal';\n\nexport type LpTransactionHistoryEntity = {\n id: number;\n type: TransactionHistoryType;\n token: string;\n amount: number;\n transactionHash: string;\n timestamp: number;\n};\n\nexport type GetLpPoolTransactionHistoryParams = {\n id: LpPoolEntity['id'];\n address: string; // wallet address\n limit?: number;\n};\n\nexport type GetLpPoolTransactionHistoryResult = LpTransactionHistoryEntity[];\n\nexport type GetLpPositionsParams = {\n id: LpPoolEntity['id'];\n address: string; // wallet address\n};\n\nexport type LpPositionEntity = {\n id: number;\n deposited: number;\n currentBalance: number;\n pnl: number;\n fundingRate: number;\n lpPool: LpPoolEntity;\n};\n\nexport type GetLpPositionsResult = LpPositionEntity[];\n\nexport type GetLpPoolWithdrawBalanceParams = {\n id: LpPoolEntity['id'];\n address: string; // wallet address\n};\n\nexport type GetLpPoolWithdrawBalanceResult = number;\n\n// ---- Transaction Simulation ----\n\nexport type GetTransactionSimulationInitialDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n"]}
@@ -1,9 +1,8 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { AccountAssetBalance, CollateralInfo, ExchangeInfo, ExposureCommandState, MarginInfo, MarketConfiguration, MarketStorage, PositionInfo, PositionInfoMarketConfiguration, RiskMatrix, RiskMultipliersConfiguration } from './trade.simulation.types';
2
+ import { AccountAssetBalance, CollateralInfo, ExchangeInfo, ExposureCommandState, MarginInfo, MarketConfiguration, MarketIdToOraclePriceMap, MarketStorage, PositionInfo, PositionInfoMarketConfiguration, RiskMatrix, RiskMultipliersConfiguration } from './trade.simulation.types';
3
3
  export declare class ExposureCommand {
4
4
  rootCollateralPoolId: number;
5
- oraclePrice: number;
6
- rate: number;
5
+ oraclePricePerMarket: MarketIdToOraclePriceMap;
7
6
  accountBalancePerAsset: AccountAssetBalance[];
8
7
  groupedByCollateral: Record<string, AccountAssetBalance>;
9
8
  riskMultipliers: RiskMultipliersConfiguration;
@@ -15,20 +14,20 @@ export declare class ExposureCommand {
15
14
  tokenMarginInfoPerAsset: MarginInfo[];
16
15
  realizedPnLSum: BigNumber;
17
16
  unrealizedPnLSum: BigNumber;
18
- constructor(rootCollateralPoolId: number, oraclePrice: number, rate: number, accountBalancePerAsset: AccountAssetBalance[], groupedByCollateral: Record<string, AccountAssetBalance>, riskMultipliers: RiskMultipliersConfiguration, riskMatrices: RiskMatrix[], exchangeInfoPerAsset: ExchangeInfo[], positionInfoMarketConfiguration: PositionInfoMarketConfiguration[], uniqueTokenAddresses: string[], uniqueQuoteCollaterals: string[], tokenMarginInfoPerAsset: MarginInfo[], realizedPnLSum: BigNumber, unrealizedPnLSum: BigNumber);
17
+ constructor(rootCollateralPoolId: number, oraclePricePerMarket: MarketIdToOraclePriceMap, accountBalancePerAsset: AccountAssetBalance[], groupedByCollateral: Record<string, AccountAssetBalance>, riskMultipliers: RiskMultipliersConfiguration, riskMatrices: RiskMatrix[], exchangeInfoPerAsset: ExchangeInfo[], positionInfoMarketConfiguration: PositionInfoMarketConfiguration[], uniqueTokenAddresses: string[], uniqueQuoteCollaterals: string[], tokenMarginInfoPerAsset: MarginInfo[], realizedPnLSum: BigNumber, unrealizedPnLSum: BigNumber);
19
18
  getState(): ExposureCommandState;
20
19
  get getUsdNodeMarginInfo(): MarginInfo;
21
20
  get balancePerAsset(): MarginInfo[];
22
21
  getUsdNodeMarginInfoPostTrade(positionAmount: number, collateralAddress: string, marketConfiguration: MarketConfiguration): MarginInfo;
23
- static calculateTokenMarginInfoPerAsset(groupedByCollateral: Record<string, AccountAssetBalance>, rootCollateralPoolId: number, riskMatrices: RiskMatrix[], riskMultipliers: RiskMultipliersConfiguration, uniqueQuoteCollaterals: Set<string>, realizedPnLSum: BigNumber, unrealizedPnLSum: BigNumber, positionInfoMarketConfiguration: PositionInfoMarketConfiguration[], oraclePrice: number): MarginInfo[];
22
+ static calculateTokenMarginInfoPerAsset(groupedByCollateral: Record<string, AccountAssetBalance>, rootCollateralPoolId: number, riskMatrices: RiskMatrix[], riskMultipliers: RiskMultipliersConfiguration, uniqueQuoteCollaterals: Set<string>, realizedPnLSum: BigNumber, unrealizedPnLSum: BigNumber, positionInfoMarketConfiguration: PositionInfoMarketConfiguration[], oraclePricePerMarket: MarketIdToOraclePriceMap): MarginInfo[];
24
23
  static calculateLiquidation(globalMarginInfo: MarginInfo, oraclePrice: number, positionBase: number): BigNumber;
25
24
  static calculateImpliedLeverage(notionalExposure: number, oldIMR: number, newIMR: number): number;
26
25
  static combineMarginInfo(parentMarginInfo: MarginInfo, sonMarginInfo: MarginInfo, sonParentExchangeInfo: ExchangeInfo): MarginInfo;
27
26
  static getUsdNodeMarginInfo(accountCollateralPoolId: number, quoteTokens: string[], exchangeInfoPerAsset: ExchangeInfo[], marginInfoPerToken: MarginInfo[]): MarginInfo;
28
27
  static getCollateralInfo(collateralAddress: string, realisedPnl: BigNumber, unrealizedPnL: BigNumber, netDeposits: number): CollateralInfo;
29
- static getTokenMarginInfo(rootCollateralPoolId: number, riskMatrices: RiskMatrix[], riskMultipliers: RiskMultipliersConfiguration, collateralInfo: CollateralInfo, collateralAddress: string, positions: PositionInfoMarketConfiguration[], oraclePrice: number): MarginInfo;
28
+ static getTokenMarginInfo(rootCollateralPoolId: number, riskMatrices: RiskMatrix[], riskMultipliers: RiskMultipliersConfiguration, collateralInfo: CollateralInfo, collateralAddress: string, positions: PositionInfoMarketConfiguration[], oraclePricePerMarket: MarketIdToOraclePriceMap, uniqueQuoteTokens: string[]): MarginInfo;
30
29
  static computeLiquidationMarginRequirement(matrix: BigNumber[][], filledExposures: BigNumber[]): number;
31
- static getBlockExposures(positions: PositionInfoMarketConfiguration[], oraclePrice: number): BigNumber[];
30
+ static getBlockExposures(positions: PositionInfoMarketConfiguration[], oraclePricePerMarket: MarketIdToOraclePriceMap): BigNumber[];
32
31
  static getAccountFilledExposures(position: PositionInfo, marketConfiguration: MarketConfiguration, oraclePrice: number): {
33
32
  exposure: BigNumber;
34
33
  riskMatrixIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"exposure.calculator.d.ts","sourceRoot":"/","sources":["clients/helpers/exposure.calculator.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,UAAU,EACV,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,+BAA+B,EA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AAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM;;;;IAoCvB,MAAM,CAAC,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;;;;IA+B7D,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM;IAe5E,MAAM,CAAC,YAAY,CACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,GACtB,MAAM;IAIT,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIvE,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM;CAU3C"}
@@ -12,7 +12,11 @@ export interface MarketStorage {
12
12
  export interface MarketConfiguration {
13
13
  market_id: number;
14
14
  risk_matrix_index: number;
15
- max_open_interest: number;
15
+ max_open_base: number;
16
+ velocity_multiplier: number;
17
+ minimum_order_base: number;
18
+ base_spacing: number;
19
+ price_spacing: number;
16
20
  oracle_node_id: string;
17
21
  mtm_window: number;
18
22
  dutch_config_lambda: number;
@@ -42,6 +46,12 @@ export interface RiskMatrix {
42
46
  risk_block_id: number;
43
47
  matrix: BigNumber[][];
44
48
  }
49
+ export type MarketIdToOraclePriceMap = {
50
+ [marketId: number]: number;
51
+ };
52
+ export type CollateralAddressToExchangePriceMap = {
53
+ [address: string]: number;
54
+ };
45
55
  export interface ExchangeInfo {
46
56
  price: number;
47
57
  priceHaircut: number;
@@ -80,8 +90,7 @@ export interface CollateralInfo {
80
90
  }
81
91
  export type ExposureCommandState = {
82
92
  rootCollateralPoolId: number;
83
- oraclePrice: number;
84
- rate: number;
93
+ oraclePricePerMarket: MarketIdToOraclePriceMap;
85
94
  accountBalancePerAsset: AccountAssetBalance[];
86
95
  groupedByCollateral: Record<string, AccountAssetBalance>;
87
96
  riskMultipliers: RiskMultipliersConfiguration;
@@ -1 +1 @@
1
- {"version":3,"file":"trade.simulation.types.d.ts","sourceRoot":"/","sources":["clients/helpers/trade.simulation.types.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,4BAA4B;IAC3C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,e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rC,+BAA+B,EAAE,+BAA+B,EAAE,CAAC;IACnE,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,uBAAuB,EAAE,UAAU,EAAE,CAAC;IACtC,cAAc,EAAE,SAAS,CAAC;IAC1B,gBAAgB,EAAE,SAAS,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,SAAS,CAAC;IACxB,aAAa,EAAE,aAAa,CAAC;IAC7B,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,mBAAmB,EAAE,oBAAoB,CAAC;IAC1C,uBAAuB,EAAE,oBAAoB,CAAC;CAC/C,CAAC"}
@@ -1,10 +1,10 @@
1
- import { GetLpPoolParams, GetLpPoolPositionParams, GetLpPoolResult, GetLpPoolsResult, GetLpPoolTransactionHistoryParams, GetLpPoolTransactionHistoryResult, GetLpPositionsResult, GetLpPoolWithdrawBalanceParams, GetLpPoolWithdrawBalanceResult } from '../types';
1
+ import { GetLpPoolParams, GetLpPositionsParams, GetLpPoolResult, GetLpPoolsResult, GetLpPoolTransactionHistoryParams, GetLpPoolTransactionHistoryResult, GetLpPositionsResult, GetLpPoolWithdrawBalanceParams, GetLpPoolWithdrawBalanceResult } from '../types';
2
2
  import RestClient from './rest';
3
3
  export default class LpClient extends RestClient {
4
4
  getLpPools(): Promise<GetLpPoolsResult>;
5
5
  getLpPool(params: GetLpPoolParams): Promise<GetLpPoolResult>;
6
6
  getLpPoolTransactionHistory(params: GetLpPoolTransactionHistoryParams): Promise<GetLpPoolTransactionHistoryResult>;
7
- getLpPositions(params: GetLpPoolPositionParams): Promise<GetLpPositionsResult>;
7
+ getLpPositions(params: GetLpPositionsParams): Promise<GetLpPositionsResult>;
8
8
  getLpPoolWithdrawBalance(params: GetLpPoolWithdrawBalanceParams): Promise<GetLpPoolWithdrawBalanceResult>;
9
9
  }
10
10
  //# sourceMappingURL=lp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lp.d.ts","sourceRoot":"/","sources":["clients/modules/lp.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,iCAAiC,EACjC,iCAAiC,EACjC,oBAAoB,EACpB,8BAA8B,EAC9B,8BAA8B,EAC/B,MAAM,UAAU,CAAC;AAClB,OAAO,UAAU,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,UAAU;IACxC,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKvC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAK5D,2BAA2B,CAC/B,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,iCAAiC,CAAC;IAOvC,cAAc,CAClB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,oBAAoB,CAAC;IAK1B,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,8BAA8B,CAAC;CAM3C"}
1
+ {"version":3,"file":"lp.d.ts","sourceRoot":"/","sources":["clients/modules/lp.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,iCAAiC,EACjC,iCAAiC,EACjC,oBAAoB,EACpB,8BAA8B,EAC9B,8BAA8B,EAC/B,MAAM,UAAU,CAAC;AAClB,OAAO,UAAU,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,UAAU;IACxC,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKvC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAK5D,2BAA2B,CAC/B,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,iCAAiC,CAAC;IAQvC,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;IAO1B,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,8BAA8B,CAAC;CAM3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"trade.simulation.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC9B,MAAM,UAAU,CAAC;AAClB,OAAO,aAAa,MAAM,WAAW,CAAC;AAKtC,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,aAAa,CAAgB;gBACzB,aAAa,EAAE,aAAa;IAMlC,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAOjD,eAAe;IAW7B,QAAQ,CAAC,MAAM,EAAE,6BAA6B,GAAG,mBAAmB;CAgGrE"}
1
+ {"version":3,"file":"trade.simulation.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC9B,MAAM,UAAU,CAAC;AAClB,OAAO,aAAa,MAAM,WAAW,CAAC;AAKtC,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,aAAa,CAAgB;gBACzB,aAAa,EAAE,aAAa;IAMlC,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAOjD,eAAe;IAW7B,QAAQ,CAAC,MAAM,EAAE,6BAA6B,GAAG,mBAAmB;CA2GrE"}
@@ -163,16 +163,18 @@ export type TradeSimulationSimulateParams = {
163
163
  amount: number;
164
164
  };
165
165
  export declare enum SupportedChainId {
166
- mainnet = 1,
167
- polygonMumbai = 80001
166
+ polygonMumbai = 80001,
167
+ reyaCronos = 1729
168
168
  }
169
169
  export type LpPoolEntity = {
170
170
  id: number;
171
171
  name: string;
172
172
  description: string;
173
+ longDescription: string;
174
+ readMoreLink: string;
173
175
  currentAPY: number;
174
176
  balanceSupplied?: number | null;
175
- balanceChange24H: number;
177
+ apyChange24H: number;
176
178
  tokenAddress: string;
177
179
  token: string;
178
180
  allowedChainsForLiquidity: number[];
@@ -194,11 +196,13 @@ export type LpTransactionHistoryEntity = {
194
196
  };
195
197
  export type GetLpPoolTransactionHistoryParams = {
196
198
  id: LpPoolEntity['id'];
199
+ address: string;
197
200
  limit?: number;
198
201
  };
199
202
  export type GetLpPoolTransactionHistoryResult = LpTransactionHistoryEntity[];
200
- export type GetLpPoolPositionParams = {
203
+ export type GetLpPositionsParams = {
201
204
  id: LpPoolEntity['id'];
205
+ address: string;
202
206
  };
203
207
  export type LpPositionEntity = {
204
208
  id: number;
@@ -206,6 +210,7 @@ export type LpPositionEntity = {
206
210
  currentBalance: number;
207
211
  pnl: number;
208
212
  fundingRate: number;
213
+ lpPool: LpPoolEntity;
209
214
  };
210
215
  export type GetLpPositionsResult = LpPositionEntity[];
211
216
  export type GetLpPoolWithdrawBalanceParams = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,UAAU,SAAS;IACnB,YAAY,UAAU;IACtB,eAAe,WAAW;IAC1B,cAAc,WAAW;IACzB,QAAQ,UAAU;IAClB,UAAU,WAAW;IACrB,OAAO,SAAS;CACjB;AAGD,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,iBAAiB,CAAC;IAC9B,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IAAI,CAAC,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,MAAM,CAAC;AAIpD,MAAM,MAAM,yCAAyC,GAAG;IACtD,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IAC7B,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;CAC5C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/api-sdk",
3
- "version": "0.21.0",
3
+ "version": "0.22.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -39,5 +39,5 @@
39
39
  "lodash": "^4.17.21"
40
40
  },
41
41
  "packageManager": "pnpm@8.10.4",
42
- "gitHead": "ed6b9e603dea797c02b530cc38df791b33289c32"
42
+ "gitHead": "8366d7bf84f63fb9f04b2c357549fed142f52cb6"
43
43
  }
@@ -7,6 +7,7 @@ import {
7
7
  ExposureCommandState,
8
8
  MarginInfo,
9
9
  MarketConfiguration,
10
+ MarketIdToOraclePriceMap,
10
11
  MarketStorage,
11
12
  PositionInfo,
12
13
  PositionInfoMarketConfiguration,
@@ -17,8 +18,7 @@ import { amountNormalizer } from './number';
17
18
 
18
19
  export class ExposureCommand {
19
20
  rootCollateralPoolId: number;
20
- oraclePrice: number;
21
- rate: number;
21
+ oraclePricePerMarket: MarketIdToOraclePriceMap;
22
22
  accountBalancePerAsset: AccountAssetBalance[];
23
23
  groupedByCollateral: Record<string, AccountAssetBalance>;
24
24
  riskMultipliers: RiskMultipliersConfiguration;
@@ -32,8 +32,7 @@ export class ExposureCommand {
32
32
  unrealizedPnLSum: BigNumber;
33
33
  constructor(
34
34
  rootCollateralPoolId: number,
35
- oraclePrice: number,
36
- rate: number,
35
+ oraclePricePerMarket: MarketIdToOraclePriceMap,
37
36
  accountBalancePerAsset: AccountAssetBalance[],
38
37
  groupedByCollateral: Record<string, AccountAssetBalance>,
39
38
  riskMultipliers: RiskMultipliersConfiguration,
@@ -47,8 +46,7 @@ export class ExposureCommand {
47
46
  unrealizedPnLSum: BigNumber,
48
47
  ) {
49
48
  this.rootCollateralPoolId = rootCollateralPoolId;
50
- this.oraclePrice = oraclePrice;
51
- this.rate = rate;
49
+ this.oraclePricePerMarket = oraclePricePerMarket;
52
50
  this.accountBalancePerAsset = accountBalancePerAsset;
53
51
  this.groupedByCollateral = groupedByCollateral;
54
52
  this.riskMultipliers = riskMultipliers;
@@ -65,8 +63,7 @@ export class ExposureCommand {
65
63
  getState(): ExposureCommandState {
66
64
  return {
67
65
  rootCollateralPoolId: this.rootCollateralPoolId,
68
- oraclePrice: this.oraclePrice,
69
- rate: this.rate,
66
+ oraclePricePerMarket: this.oraclePricePerMarket,
70
67
  accountBalancePerAsset: this.accountBalancePerAsset,
71
68
  groupedByCollateral: this.groupedByCollateral,
72
69
  riskMultipliers: this.riskMultipliers,
@@ -143,7 +140,7 @@ export class ExposureCommand {
143
140
  this.realizedPnLSum,
144
141
  this.unrealizedPnLSum,
145
142
  positionInfoMarketConfiguration,
146
- this.oraclePrice,
143
+ this.oraclePricePerMarket,
147
144
  );
148
145
 
149
146
  const uniqueTokenAddresses = [...this.uniqueTokenAddresses];
@@ -168,7 +165,7 @@ export class ExposureCommand {
168
165
  realizedPnLSum: BigNumber,
169
166
  unrealizedPnLSum: BigNumber,
170
167
  positionInfoMarketConfiguration: PositionInfoMarketConfiguration[],
171
- oraclePrice: number,
168
+ oraclePricePerMarket: MarketIdToOraclePriceMap,
172
169
  ) {
173
170
  const tokenMarginInfoPerAsset: MarginInfo[] = [];
174
171
 
@@ -194,7 +191,8 @@ export class ExposureCommand {
194
191
  ),
195
192
  token,
196
193
  positionInfoMarketConfiguration,
197
- oraclePrice,
194
+ oraclePricePerMarket,
195
+ uniqueQuoteTokens,
198
196
  ),
199
197
  );
200
198
  }
@@ -403,7 +401,8 @@ export class ExposureCommand {
403
401
  collateralInfo: CollateralInfo,
404
402
  collateralAddress: string,
405
403
  positions: PositionInfoMarketConfiguration[],
406
- oraclePrice: number,
404
+ oraclePricePerMarket: MarketIdToOraclePriceMap,
405
+ uniqueQuoteTokens: string[],
407
406
  ): MarginInfo {
408
407
  const marginRequirements = {
409
408
  liquidationMarginRequirement: 0,
@@ -413,58 +412,59 @@ export class ExposureCommand {
413
412
  adlMarginRequirement: 0,
414
413
  initialBufferMarginRequirement: 0,
415
414
  };
415
+ if (uniqueQuoteTokens.includes(collateralAddress)) {
416
+ // uniqueQuoteTokens is list is active markets tokens
417
+ for (const riskMatrix of riskMatrices) {
418
+ const filledExposures = ExposureCommand.getBlockExposures(
419
+ positions,
420
+ oraclePricePerMarket,
421
+ );
422
+
423
+ marginRequirements.liquidationMarginRequirement = BigNumber(
424
+ marginRequirements.liquidationMarginRequirement,
425
+ )
426
+ .plus(
427
+ ExposureCommand.computeLiquidationMarginRequirement(
428
+ riskMatrix.matrix,
429
+ filledExposures,
430
+ ),
431
+ )
432
+ .toNumber();
433
+ }
416
434
 
417
- for (const riskMatrix of riskMatrices) {
418
- const filledExposures = ExposureCommand.getBlockExposures(
419
- positions,
420
- oraclePrice,
421
- );
422
-
423
- marginRequirements.liquidationMarginRequirement = BigNumber(
424
- marginRequirements.liquidationMarginRequirement,
435
+ // Get the initial margin requirement
436
+ marginRequirements.initialMarginRequirement = amountNormalizer(
437
+ String(riskMultipliers.im_multiplier),
425
438
  )
426
- .plus(
427
- ExposureCommand.computeLiquidationMarginRequirement(
428
- riskMatrix.matrix,
429
- filledExposures,
430
- ),
431
- )
439
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
440
+ .toNumber();
441
+ // Get the maintenance margin requirement
442
+ marginRequirements.maintenanceMarginRequirement = amountNormalizer(
443
+ String(riskMultipliers.mmr_multiplier),
444
+ )
445
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
446
+ .toNumber();
447
+ // Get the dutch margin requirement
448
+ marginRequirements.dutchMarginRequirement = amountNormalizer(
449
+ String(riskMultipliers.dutch_multiplier),
450
+ )
451
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
432
452
  .toNumber();
433
- }
434
-
435
- // Get the initial margin requirement
436
- marginRequirements.initialMarginRequirement = amountNormalizer(
437
- String(riskMultipliers.im_multiplier),
438
- )
439
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
440
- .toNumber();
441
- // Get the maintenance margin requirement
442
- marginRequirements.maintenanceMarginRequirement = amountNormalizer(
443
- String(riskMultipliers.mmr_multiplier),
444
- )
445
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
446
- .toNumber();
447
- // Get the dutch margin requirement
448
- marginRequirements.dutchMarginRequirement = amountNormalizer(
449
- String(riskMultipliers.dutch_multiplier),
450
- )
451
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
452
- .toNumber();
453
-
454
- // Get the adl margin requirement
455
- marginRequirements.adlMarginRequirement = amountNormalizer(
456
- String(riskMultipliers.adl_multiplier),
457
- )
458
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
459
- .toNumber();
460
453
 
461
- // Get the initial buffer margin requirement
462
- marginRequirements.initialBufferMarginRequirement = amountNormalizer(
463
- String(riskMultipliers.im_buffer_multiplier),
464
- )
465
- .multipliedBy(marginRequirements.liquidationMarginRequirement)
466
- .toNumber();
454
+ // Get the adl margin requirement
455
+ marginRequirements.adlMarginRequirement = amountNormalizer(
456
+ String(riskMultipliers.adl_multiplier),
457
+ )
458
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
459
+ .toNumber();
467
460
 
461
+ // Get the initial buffer margin requirement
462
+ marginRequirements.initialBufferMarginRequirement = amountNormalizer(
463
+ String(riskMultipliers.im_buffer_multiplier),
464
+ )
465
+ .multipliedBy(marginRequirements.liquidationMarginRequirement)
466
+ .toNumber();
467
+ }
468
468
  return {
469
469
  assetAddress: collateralAddress,
470
470
  marginBalance: collateralInfo.marginBalance,
@@ -523,7 +523,7 @@ export class ExposureCommand {
523
523
 
524
524
  static getBlockExposures(
525
525
  positions: PositionInfoMarketConfiguration[],
526
- oraclePrice: number,
526
+ oraclePricePerMarket: MarketIdToOraclePriceMap,
527
527
  ): BigNumber[] {
528
528
  const filledExposures: number[] = [];
529
529
 
@@ -531,7 +531,7 @@ export class ExposureCommand {
531
531
  const marketFilledExposure = ExposureCommand.getAccountFilledExposures(
532
532
  position,
533
533
  position.market_configuration,
534
- oraclePrice,
534
+ oraclePricePerMarket[position.market_id],
535
535
  );
536
536
  filledExposures[marketFilledExposure.riskMatrixIndex] = BigNumber(
537
537
  filledExposures[marketFilledExposure.riskMatrixIndex] || 0,
@@ -607,7 +607,9 @@ export class ExposureCommand {
607
607
  marketConfiguration: MarketConfiguration,
608
608
  marketStorage: MarketStorage,
609
609
  ): number {
610
- const deltaExposure = BigNumber(this.oraclePrice)
610
+ const deltaExposure = BigNumber(
611
+ this.oraclePricePerMarket[marketConfiguration.market_id],
612
+ )
611
613
  .times(deltaBase)
612
614
  .toNumber();
613
615
 
@@ -660,7 +662,7 @@ export class ExposureCommand {
660
662
 
661
663
  const exposures = ExposureCommand.getBlockExposures(
662
664
  this.positionInfoMarketConfiguration,
663
- this.oraclePrice,
665
+ this.oraclePricePerMarket,
664
666
  );
665
667
 
666
668
  const { maxExposureShort, maxExposureLong } =
@@ -14,7 +14,11 @@ export interface MarketStorage {
14
14
  export interface MarketConfiguration {
15
15
  market_id: number;
16
16
  risk_matrix_index: number;
17
- max_open_interest: number;
17
+ max_open_base: number;
18
+ velocity_multiplier: number;
19
+ minimum_order_base: number;
20
+ base_spacing: number;
21
+ price_spacing: number;
18
22
  oracle_node_id: string;
19
23
  mtm_window: number;
20
24
  dutch_config_lambda: number;
@@ -47,6 +51,13 @@ export interface RiskMatrix {
47
51
  risk_block_id: number;
48
52
  matrix: BigNumber[][];
49
53
  }
54
+ export type MarketIdToOraclePriceMap = {
55
+ [marketId: number]: number;
56
+ };
57
+
58
+ export type CollateralAddressToExchangePriceMap = {
59
+ [address: string]: number;
60
+ };
50
61
 
51
62
  export interface ExchangeInfo {
52
63
  price: number;
@@ -91,8 +102,7 @@ export interface CollateralInfo {
91
102
 
92
103
  export type ExposureCommandState = {
93
104
  rootCollateralPoolId: number;
94
- oraclePrice: number;
95
- rate: number;
105
+ oraclePricePerMarket: MarketIdToOraclePriceMap;
96
106
  accountBalancePerAsset: AccountAssetBalance[];
97
107
  groupedByCollateral: Record<string, AccountAssetBalance>;
98
108
  riskMultipliers: RiskMultipliersConfiguration;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  GetLpPoolParams,
3
- GetLpPoolPositionParams,
3
+ GetLpPositionsParams,
4
4
  GetLpPoolResult,
5
5
  GetLpPoolsResult,
6
6
  GetLpPoolTransactionHistoryParams,
@@ -28,14 +28,17 @@ export default class LpClient extends RestClient {
28
28
  const uri = `/api/lp-pools/${params.id}/transaction-history`;
29
29
  return this.get(uri, {
30
30
  limit: params.limit,
31
+ address: params.address,
31
32
  });
32
33
  }
33
34
 
34
35
  async getLpPositions(
35
- params: GetLpPoolPositionParams,
36
+ params: GetLpPositionsParams,
36
37
  ): Promise<GetLpPositionsResult> {
37
38
  const uri = `/api/lp-pools/${params.id}/positions`;
38
- return this.get(uri);
39
+ return this.get(uri, {
40
+ address: params.address,
41
+ });
39
42
  }
40
43
 
41
44
  async getLpPoolWithdrawBalance(
@@ -43,13 +43,16 @@ export default class TradeSimulationClient {
43
43
  }
44
44
 
45
45
  const amount = BigNumber(params.amount)
46
- .div(this.loadedData.exposureDataAccount.oraclePrice)
46
+ .div(
47
+ this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
48
+ this.loadedData.marketConfiguration.market_id
49
+ ],
50
+ )
47
51
  .toNumber();
48
52
 
49
53
  const userAccountExposure = new ExposureCommand(
50
54
  this.loadedData.exposureDataAccount.rootCollateralPoolId,
51
- this.loadedData.exposureDataAccount.oraclePrice,
52
- this.loadedData.exposureDataAccount.rate,
55
+ this.loadedData.exposureDataAccount.oraclePricePerMarket,
53
56
  this.loadedData.exposureDataAccount.accountBalancePerAsset,
54
57
  this.loadedData.exposureDataAccount.groupedByCollateral,
55
58
  this.loadedData.exposureDataAccount.riskMultipliers,
@@ -65,8 +68,7 @@ export default class TradeSimulationClient {
65
68
 
66
69
  const passivePoolExposure = new ExposureCommand(
67
70
  this.loadedData.exposureDataPassivePool.rootCollateralPoolId,
68
- this.loadedData.exposureDataPassivePool.oraclePrice,
69
- this.loadedData.exposureDataPassivePool.rate,
71
+ this.loadedData.exposureDataPassivePool.oraclePricePerMarket,
70
72
  this.loadedData.exposureDataPassivePool.accountBalancePerAsset,
71
73
  this.loadedData.exposureDataPassivePool.groupedByCollateral,
72
74
  this.loadedData.exposureDataPassivePool.riskMultipliers,
@@ -86,11 +88,15 @@ export default class TradeSimulationClient {
86
88
  this.loadedData.marketStorage,
87
89
  );
88
90
  const estimatedPrice = ExposureCommand.calculateEstimatedPrice(
89
- this.loadedData.exposureDataPassivePool.oraclePrice,
91
+ this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
92
+ this.loadedData.marketConfiguration.market_id
93
+ ],
90
94
  slippage,
91
95
  );
92
96
  const fees = ExposureCommand.calculateFee(
93
- this.loadedData.exposureDataAccount.oraclePrice,
97
+ this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
98
+ this.loadedData.marketConfiguration.market_id
99
+ ],
94
100
  amount,
95
101
  this.loadedData.feeParameter,
96
102
  );
@@ -104,7 +110,10 @@ export default class TradeSimulationClient {
104
110
  );
105
111
 
106
112
  const impliedLeverage = ExposureCommand.calculateImpliedLeverage(
107
- amount * this.loadedData.exposureDataAccount.oraclePrice,
113
+ amount *
114
+ this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
115
+ this.loadedData.marketConfiguration.market_id
116
+ ],
108
117
  oldMarginInfo.marginBalance - oldMarginInfo.initialDelta,
109
118
  newMarginInfo.marginBalance - newMarginInfo.initialDelta,
110
119
  );
@@ -114,7 +123,9 @@ export default class TradeSimulationClient {
114
123
 
115
124
  const liquidationPrice = ExposureCommand.calculateLiquidation(
116
125
  newMarginInfo,
117
- this.loadedData.exposureDataAccount.oraclePrice,
126
+ this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
127
+ this.loadedData.marketConfiguration.market_id
128
+ ],
118
129
  amount,
119
130
  );
120
131
 
@@ -212,17 +212,19 @@ export type TradeSimulationSimulateParams = {
212
212
  // ---- LP ----
213
213
 
214
214
  export enum SupportedChainId {
215
- mainnet = 1,
216
215
  polygonMumbai = 80001,
216
+ reyaCronos = 1729,
217
217
  }
218
218
 
219
219
  export type LpPoolEntity = {
220
220
  id: number;
221
221
  name: string;
222
222
  description: string;
223
+ longDescription: string;
224
+ readMoreLink: string;
223
225
  currentAPY: number;
224
226
  balanceSupplied?: number | null;
225
- balanceChange24H: number;
227
+ apyChange24H: number;
226
228
  tokenAddress: string;
227
229
  token: string;
228
230
  allowedChainsForLiquidity: number[];
@@ -250,13 +252,15 @@ export type LpTransactionHistoryEntity = {
250
252
 
251
253
  export type GetLpPoolTransactionHistoryParams = {
252
254
  id: LpPoolEntity['id'];
255
+ address: string; // wallet address
253
256
  limit?: number;
254
257
  };
255
258
 
256
259
  export type GetLpPoolTransactionHistoryResult = LpTransactionHistoryEntity[];
257
260
 
258
- export type GetLpPoolPositionParams = {
261
+ export type GetLpPositionsParams = {
259
262
  id: LpPoolEntity['id'];
263
+ address: string; // wallet address
260
264
  };
261
265
 
262
266
  export type LpPositionEntity = {
@@ -265,6 +269,7 @@ export type LpPositionEntity = {
265
269
  currentBalance: number;
266
270
  pnl: number;
267
271
  fundingRate: number;
272
+ lpPool: LpPoolEntity;
268
273
  };
269
274
 
270
275
  export type GetLpPositionsResult = LpPositionEntity[];