@reyaxyz/api-sdk 0.111.20 → 0.111.22
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.
- package/dist/clients/modules/edit-collateral.simulation/index.js +1 -1
- package/dist/clients/modules/edit-collateral.simulation/index.js.map +1 -1
- package/dist/clients/modules/isolated-order.simulation/index.js +3 -3
- package/dist/clients/modules/isolated-order.simulation/index.js.map +1 -1
- package/dist/clients/modules/trade.simulation/index.js +4 -4
- package/dist/clients/modules/trade.simulation/index.js.map +1 -1
- package/dist/types/clients/modules/edit-collateral.simulation/index.d.ts.map +1 -1
- package/dist/types/clients/modules/isolated-order.simulation/index.d.ts.map +1 -1
- package/dist/types/clients/modules/trade.simulation/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/modules/edit-collateral.simulation/index.ts +1 -0
- package/src/clients/modules/isolated-order.simulation/index.ts +3 -0
- package/src/clients/modules/trade.simulation/index.ts +4 -0
|
@@ -70,7 +70,7 @@ var EditCollateralSimulationClient = /** @class */ (function () {
|
|
|
70
70
|
if (!this.loadedData) {
|
|
71
71
|
throw new Error('Data not loaded. Call arm() first.');
|
|
72
72
|
}
|
|
73
|
-
var userAccountExposure = new common_1.ExposureCommand(this.loadedData.exposureDataAccount.accountId, 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, this.loadedData.exposureDataAccount.collateralAddressToExchangePrice);
|
|
73
|
+
var userAccountExposure = new common_1.ExposureCommand(this.loadedData.exposureDataAccount.accountId, 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, this.loadedData.exposureDataAccount.mtmRpnlSum, this.loadedData.exposureDataAccount.collateralAddressToExchangePrice);
|
|
74
74
|
var tokenInfo = (0, common_1.getTokenInfoByAddress)(params.tokenAddress);
|
|
75
75
|
if (tokenInfo.isRUSDUnderlying) {
|
|
76
76
|
tokenInfo = (0, common_1.getTokenInfoByName)('RUSD', this.reyaChainId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/edit-collateral.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,0CAMyB;AACzB;IAKE,wCAAY,WAAwB,EAAE,aAA4B;QAH1D,cAAS,GAAkB,IAAI,CAAC;QAChC,eAAU,GAAyC,IAAI,CAAC;QAG9D,oBAAoB;QACpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,wDAAwD;IAClD,4CAAG,GAAT,UAAU,MAA8C;;;;;;wBACtD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,eAAe,CAAC;w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,CAAC,gBAAgB,EAAE,CAAC;YAC/B,SAAS,GAAG,IAAA,2BAAkB,EAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3D,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,IAAA,2BAAkB,EAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACnE,CAAC;QAED,IAAM,aAAa,GACjB,mBAAmB,CAAC,sCAAsC,CACxD,MAAM,CAAC,YAAY,EACnB,SAAS,CAAC,OAAO,CAClB,CAAC;QAEJ,IAAM,WAAW,GAAG,wBAAe,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAElE,IAAM,iBAAiB,GAAG,wBAAe,CAAC,oBAAoB,CAC5D,WAAW,GAAG,GAAG,CAClB,CAAC;QAEF,OAAO;YACL,WAAW,EAAE,WAAW,GAAG,GAAG;YAC9B,iBAAiB,EAAE,iBAAiB;SACL,CAAC;IACpC,CAAC;IACH,qCAAC;AAAD,CAAC,AAxED,IAwEC","sourcesContent":["import {\n EditCollateralSimulationLoadDataParams,\n EditCollateralSimulationSimulateParams,\n SimulateEditCollateralEntity,\n} from './types';\nimport AccountClient from '../account';\nimport {\n EditCollateralSimulationState,\n ExposureCommand,\n ReyaChainId,\n getTokenInfoByAddress,\n getTokenInfoByName,\n} from '@reyaxyz/common';\nexport default class EditCollateralSimulationClient {\n private reyaChainId: ReyaChainId;\n private accountId: number | null = null;\n private loadedData: EditCollateralSimulationState | null = null;\n private accountClient: AccountClient;\n constructor(reyaChainId: ReyaChainId, accountClient: AccountClient) {\n // Constructor added\n this.reyaChainId = reyaChainId;\n this.accountClient = accountClient;\n }\n\n // Method to asynchronously load data based on accountId\n async arm(params: EditCollateralSimulationLoadDataParams): Promise<void> {\n this.accountId = params.marginAccountId;\n\n this.loadedData =\n await this.accountClient.getEditCollateralSimulationInitialData({\n marginAccountId: this.accountId,\n });\n }\n\n // Synchronous method to simulate operations based on an amount\n simulate(\n params: EditCollateralSimulationSimulateParams,\n ): SimulateEditCollateralEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const userAccountExposure = new ExposureCommand(\n this.loadedData.exposureDataAccount.accountId,\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 this.loadedData.exposureDataAccount.mtmRpnlSum,\n this.loadedData.exposureDataAccount.collateralAddressToExchangePrice,\n );\n\n let tokenInfo = getTokenInfoByAddress(params.tokenAddress);\n if (tokenInfo.isRUSDUnderlying) {\n tokenInfo = getTokenInfoByName('RUSD', this.reyaChainId);\n } else {\n tokenInfo = getTokenInfoByName(tokenInfo.name, this.reyaChainId);\n }\n\n const newMarginInfo =\n userAccountExposure.getUsdNodeMarginInfoPostEditCollateral(\n params.signedAmount,\n tokenInfo.address,\n );\n\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n return {\n marginRatio: marginRatio * 100,\n marginRatioHealth: marginRatioHealth,\n } as SimulateEditCollateralEntity;\n }\n}\n"]}
|
|
@@ -67,7 +67,7 @@ var IsolatedOrderSimulationClient = /** @class */ (function () {
|
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
69
|
IsolatedOrderSimulationClient.genExposureCommandObject = function (exposureCommandState) {
|
|
70
|
-
return new common_1.ExposureCommand(exposureCommandState.accountId, exposureCommandState.rootCollateralPoolId, exposureCommandState.oraclePricePerMarket, exposureCommandState.accountBalancePerAsset, exposureCommandState.groupedByCollateral, exposureCommandState.riskMultipliers, exposureCommandState.riskMatrices, exposureCommandState.exchangeInfoPerAsset, exposureCommandState.positionInfoMarketConfiguration, exposureCommandState.uniqueTokenAddresses, exposureCommandState.uniqueQuoteCollaterals, exposureCommandState.tokenMarginInfoPerAsset, exposureCommandState.realizedPnLSum, exposureCommandState.unrealizedPnLSum, exposureCommandState.collateralAddressToExchangePrice);
|
|
70
|
+
return new common_1.ExposureCommand(exposureCommandState.accountId, exposureCommandState.rootCollateralPoolId, exposureCommandState.oraclePricePerMarket, exposureCommandState.accountBalancePerAsset, exposureCommandState.groupedByCollateral, exposureCommandState.riskMultipliers, exposureCommandState.riskMatrices, exposureCommandState.exchangeInfoPerAsset, exposureCommandState.positionInfoMarketConfiguration, exposureCommandState.uniqueTokenAddresses, exposureCommandState.uniqueQuoteCollaterals, exposureCommandState.tokenMarginInfoPerAsset, exposureCommandState.realizedPnLSum, exposureCommandState.unrealizedPnLSum, exposureCommandState.mtmRpnlSum, exposureCommandState.collateralAddressToExchangePrice);
|
|
71
71
|
};
|
|
72
72
|
IsolatedOrderSimulationClient.prototype.fetchMarketData = function (marketId, accountId) {
|
|
73
73
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -164,7 +164,7 @@ var IsolatedOrderSimulationClient = /** @class */ (function () {
|
|
|
164
164
|
if (!this.loadedData) {
|
|
165
165
|
throw new Error('Data not loaded. Call arm() first.');
|
|
166
166
|
}
|
|
167
|
-
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
167
|
+
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.mtmRpnlSum, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
168
168
|
var amountForSlippage = params.fromBase
|
|
169
169
|
? params.amount
|
|
170
170
|
: (0, bignumber_js_1.default)(params.amount)
|
|
@@ -181,7 +181,7 @@ var IsolatedOrderSimulationClient = /** @class */ (function () {
|
|
|
181
181
|
if (!this.loadedData) {
|
|
182
182
|
throw new Error('Data not loaded. Call arm() first.');
|
|
183
183
|
}
|
|
184
|
-
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
184
|
+
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.mtmRpnlSum, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
185
185
|
var slippage = passivePoolExposure.getSlippage((0, bignumber_js_1.default)(params.amount).negated().toNumber(), this.loadedData.marketConfiguration, this.loadedData.marketStorage);
|
|
186
186
|
var price = this.loadedData.exposureDataAccount.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id];
|
|
187
187
|
var estimatedPrice = common_1.ExposureCommand.calculateEstimatedPrice(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], slippage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,0CAMyB;AACzB,8DAAqC;AAQrC,0CAA0D;AAE1D;IAKE,uCAAY,aAA4B;QAJhC,eAAU,GAAgC,IAAI,CAAC;QAE/C,aAAQ,GAAkB,IAAI,CAAC;QAGrC,oBAAoB;QACpB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,qEAAqE;IAC/D,2CAAG,GAAT,UAAU,MAA6C;;;;;;wBACrD,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;wBAChC,KAAA,IAAI,CAAA;wBAAc,qBAAM,IAAI,CAAC,eAAe,CAC1C,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,eAAe,CACvB,EAAA;;wBAHD,GAAK,UAAU,GAAG,SAGjB,CAAC;;;;;KACH;IAEM,sDAAwB,GAA/B,UACE,oBAA0C;QAE1C,OAAO,IAAI,wBAAe,CACxB,oBAAoB,CAAC,SAAS,EAC9B,oBAAoB,CAAC,oBAAoB,EACzC,oBAAoB,CAAC,oBAAoB,EACzC,oBAAoB,CAAC,sBAAsB,EAC3C,oBAAoB,CAAC,mBAAmB,EACxC,oBAAoB,CAAC,eAAe,EACpC,oBAAoB,CAAC,YAAY,EACjC,oBAAoB,CAAC,oBAAoB,EACzC,oBAAoB,CAAC,+BAA+B,EACpD,oBAAoB,CAAC,oBAAoB,EACzC,oBAAoB,CAAC,sBAAsB,EAC3C,oBAAoB,CAAC,uBAAuB,EAC5C,oBAAoB,CAAC,cAA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CAAC,UAAU,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC7E,CAAC;IACH,oCAAC;AAAD,CAAC,AAtcD,IAscC","sourcesContent":["import {\n SimulateIsolatedOrderEntity,\n IsolatedOrderSimulationConvertValueParams,\n IsolatedOrderSimulationConvertValueResult,\n IsolatedOrderSimulationLoadDataParams,\n IsolatedOrderSimulationSimulateParams,\n LeverageBoundsAndAvailableMarginResult,\n LeverageBoundsAndAvailableMarginParams,\n} from './types';\nimport AccountClient from '../account';\nimport {\n amountNormalizer,\n ExposureCommand,\n ExposureCommandState,\n RiskMatrix,\n TradeSimulationState,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { EditCollateralAction } from '@reyaxyz/common';\nimport {\n EstimatedPriceParams,\n EstimatedPriceResult,\n TradeSimulationConvertValueEstimatedPriceParams,\n TradeSimulationConvertValueResult,\n} from '../trade.simulation/types';\nimport { INSTANT_TRADING_RATE_XP } from '@reyaxyz/common';\n\nexport default class IsolatedOrderSimulationClient {\n private loadedData: TradeSimulationState | null = null;\n private accountClient: AccountClient;\n private marketId: number | null = null;\n\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: IsolatedOrderSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n this.loadedData = await this.fetchMarketData(\n params.marketId,\n params.marginAccountId,\n );\n }\n\n static genExposureCommandObject(\n exposureCommandState: ExposureCommandState,\n ): ExposureCommand {\n return new ExposureCommand(\n exposureCommandState.accountId,\n exposureCommandState.rootCollateralPoolId,\n exposureCommandState.oraclePricePerMarket,\n exposureCommandState.accountBalancePerAsset,\n exposureCommandState.groupedByCollateral,\n exposureCommandState.riskMultipliers,\n exposureCommandState.riskMatrices,\n exposureCommandState.exchangeInfoPerAsset,\n exposureCommandState.positionInfoMarketConfiguration,\n exposureCommandState.uniqueTokenAddresses,\n exposureCommandState.uniqueQuoteCollaterals,\n exposureCommandState.tokenMarginInfoPerAsset,\n exposureCommandState.realizedPnLSum,\n exposureCommandState.unrealizedPnLSum,\n exposureCommandState.collateralAddressToExchangePrice,\n );\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\n simulate(\n params: IsolatedOrderSimulationSimulateParams,\n ): SimulateIsolatedOrderEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n amount = BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n }\n\n const userAccountExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataAccount,\n );\n\n const passivePoolExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataPassivePool,\n );\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amount).negated().toNumber(),\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\n const amountSize = estimatedPrice * amount;\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 /*\n amount of margin in rUSD terms that needs to be transferred from the source account to the destination account,\n this value is equal to absolute size in rUSD terms / leverage\n */\n\n const requiredMargin = BigNumber(amountSize)\n .abs()\n .div(BigNumber(params.isolatedPositionLeverage))\n .toNumber();\n\n const editCollateralActions: EditCollateralAction[] =\n userAccountExposure.getEditCollateralActionsToCoverMargin(requiredMargin);\n\n const newMarginInfoSource =\n userAccountExposure.getUsdNodeMarginInfoPostEditCollaterals(\n editCollateralActions,\n );\n\n /*\n * Compute Isolated Account Liquidation Margin Requirement Post Transfer + Trade\n * */\n\n const isolatedLMR = this.calculateIsolatedLMR(amountSize);\n\n /*\n * margin balance of the destination account is the requiredMargin which is expected to be transferred\n * to the destination account that performs the isolated trade\n * the liquidation price in this case is trying to estimate what the liquidation price would be all else equal for\n * the market where the trade is being made by the isolated account that is going to be created as part of isolated\n * trade operation\n * */\n const liquidationPrice = ExposureCommand.calculateLiquidation(\n requiredMargin,\n isolatedLMR,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n amount,\n );\n\n // todo: p1: margin ratio seems to be wrong on ui\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfoSource);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n\n const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);\n const snappedAmount = snappedAmountInBase * estimatedPrice;\n const xpEarnRangeMin = Math.round(\n Math.abs(snappedAmount) / INSTANT_TRADING_RATE_XP,\n );\n const xpEarnRangeMax = Math.round(\n (100 * Math.abs(snappedAmount)) / INSTANT_TRADING_RATE_XP,\n );\n\n return {\n estimatedPrice: estimatedPrice,\n estimatedSlippage: slippage * 100,\n fees: fees,\n liquidationPrice: liquidationPrice.toNumber(),\n marginRatio: marginRatio * 100,\n marginRatioHealth: marginRatioHealth,\n snappedAmount,\n snappedAmountInBase,\n requiredMargin: requiredMargin,\n editCollateralActions: editCollateralActions,\n xpEarnRange: {\n min: xpEarnRangeMin,\n max: xpEarnRangeMax,\n },\n maxSlippage: 1,\n } as SimulateIsolatedOrderEntity;\n }\n\n convertValue(\n params: IsolatedOrderSimulationConvertValueParams,\n ): IsolatedOrderSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!params.fromBase)\n return BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n else\n return BigNumber(params.amount)\n .times(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n }\n\n convertValueEstimatedPrice(\n params: TradeSimulationConvertValueEstimatedPriceParams,\n ): TradeSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n const amountForSlippage = params.fromBase\n ? params.amount\n : BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amountForSlippage).negated().toNumber(),\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\n if (!params.fromBase)\n return BigNumber(params.amount).div(estimatedPrice).toNumber();\n else return BigNumber(params.amount).times(estimatedPrice).toNumber();\n }\n\n estimatedPrice(params: EstimatedPriceParams): EstimatedPriceResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(params.amount).negated().toNumber(),\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n\n const price =\n this.loadedData.exposureDataAccount.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n slippage,\n );\n\n return {\n estimatedPrice,\n markPrice: price,\n };\n }\n\n roundToBaseSpacing(amount: number, baseSpacing: number): number {\n const snappedAmount = BigNumber(amount)\n .abs()\n .dividedBy(baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(baseSpacing)\n .toNumber();\n\n if (amount < 0) {\n return -snappedAmount;\n }\n return snappedAmount;\n }\n\n amountToSnappedAmount(\n amountInRusd: number,\n spotPrice: number,\n baseSpacing: number,\n ): number {\n const amountInBase = BigNumber(amountInRusd)\n .div(BigNumber(spotPrice))\n .toNumber();\n\n return this.roundToBaseSpacing(amountInBase, baseSpacing) * spotPrice;\n }\n\n calculateIsolatedLMR(isolatedExposure: number): number {\n // todo: p2: consider removing the need to load the entire data just to get a few vars to calc leverage bounds\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!this.loadedData.marketStorage) {\n throw new Error('Market storage not loaded');\n }\n\n // todo: p2: carefully test\n const marketRiskMatrix =\n this.loadedData.exposureDataAccount.riskMatrices.find(\n (riskMatrix: RiskMatrix) => {\n return (\n riskMatrix.risk_block_id ===\n BigNumber(\n String(this.loadedData?.marketStorage.risk_block_id),\n ).toNumber()\n );\n },\n );\n\n if (!marketRiskMatrix) {\n throw new Error('Failed to load risk matrix');\n }\n\n const marketDiagonalRiskParam =\n marketRiskMatrix.matrix[\n this.loadedData.marketConfiguration.risk_matrix_index\n ][this.loadedData.marketConfiguration.risk_matrix_index];\n const isolatedRiskMatrix: BigNumber[][] = [[marketDiagonalRiskParam]];\n const isolatedFilledExposures: BigNumber[] = [BigNumber(isolatedExposure)];\n\n return ExposureCommand.computeLiquidationMarginRequirement(\n isolatedRiskMatrix,\n isolatedFilledExposures,\n );\n }\n\n leverageBoundsAndAvailableMargin({\n amountTradedInRusd,\n }: LeverageBoundsAndAvailableMarginParams): LeverageBoundsAndAvailableMarginResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const spotPrice =\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n const snappedAmountInRusd = this.amountToSnappedAmount(\n amountTradedInRusd,\n spotPrice,\n baseSpacing,\n );\n\n /*\n todo: p2: consider introducing buffer to the leverage (e.g. to account for the effect of trade on upnl\n and actually depending on the size of the trade the estimated price would change -> different upnl\n as upnl is calculated against oracle prioce + rpnl is also affected through the fees\n * once the trader knows their trade size (in base & rusd terms), they should be able to toggle isolated trade flow\n * which will prompt the user to choose a desired leverage value\n * 0.1 can be hardcoded to be the min bound\n * to get the maximum bound we need to calculate leverage that can be achieved when IMR is reached for position\n * with 1 rUSD exposure in the market -> max leverage = 1/IMR\n * */\n\n // set max bound\n\n const lmrUnitExposure = this.calculateIsolatedLMR(1);\n\n const imrUnitExposure: BigNumber = amountNormalizer(\n String(this.loadedData.exposureDataAccount.riskMultipliers.im_multiplier),\n ).multipliedBy(lmrUnitExposure);\n\n const maxBound = BigNumber(1).dividedBy(imrUnitExposure).toNumber();\n\n // set min bound\n\n const userAccountExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataAccount,\n );\n\n /*\n max amount of margin in rUSD terms that can be transferred from the source account to the destination account\n that performs the isolated position trade\n */\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const minBound = BigNumber(snappedAmountInRusd)\n .abs()\n .dividedBy(availableMargin)\n .toNumber();\n\n if (minBound > maxBound) {\n throw Error('Min leverage bound higher than max');\n }\n\n return {\n minBound: minBound,\n maxBound: maxBound,\n availableMargin: availableMargin,\n };\n }\n\n updatePrice(price: number): void {\n if (!this.loadedData || !this.marketId) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n // update price\n const marketId = this.marketId;\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[marketId] =\n price;\n this.loadedData.exposureDataAccount.oraclePricePerMarket[marketId] = price;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js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C7E,CAAC;IACH,oCAAC;AAAD,CAAC,AAzcD,IAycC","sourcesContent":["import {\n SimulateIsolatedOrderEntity,\n IsolatedOrderSimulationConvertValueParams,\n IsolatedOrderSimulationConvertValueResult,\n IsolatedOrderSimulationLoadDataParams,\n IsolatedOrderSimulationSimulateParams,\n LeverageBoundsAndAvailableMarginResult,\n LeverageBoundsAndAvailableMarginParams,\n} from './types';\nimport AccountClient from '../account';\nimport {\n amountNormalizer,\n ExposureCommand,\n ExposureCommandState,\n RiskMatrix,\n TradeSimulationState,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { EditCollateralAction } from '@reyaxyz/common';\nimport {\n EstimatedPriceParams,\n EstimatedPriceResult,\n TradeSimulationConvertValueEstimatedPriceParams,\n TradeSimulationConvertValueResult,\n} from '../trade.simulation/types';\nimport { INSTANT_TRADING_RATE_XP } from '@reyaxyz/common';\n\nexport default class IsolatedOrderSimulationClient {\n private loadedData: TradeSimulationState | null = null;\n private accountClient: AccountClient;\n private marketId: number | null = null;\n\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: IsolatedOrderSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n this.loadedData = await this.fetchMarketData(\n params.marketId,\n params.marginAccountId,\n );\n }\n\n static genExposureCommandObject(\n exposureCommandState: ExposureCommandState,\n ): ExposureCommand {\n return new ExposureCommand(\n exposureCommandState.accountId,\n exposureCommandState.rootCollateralPoolId,\n exposureCommandState.oraclePricePerMarket,\n exposureCommandState.accountBalancePerAsset,\n exposureCommandState.groupedByCollateral,\n exposureCommandState.riskMultipliers,\n exposureCommandState.riskMatrices,\n exposureCommandState.exchangeInfoPerAsset,\n exposureCommandState.positionInfoMarketConfiguration,\n exposureCommandState.uniqueTokenAddresses,\n exposureCommandState.uniqueQuoteCollaterals,\n exposureCommandState.tokenMarginInfoPerAsset,\n exposureCommandState.realizedPnLSum,\n exposureCommandState.unrealizedPnLSum,\n exposureCommandState.mtmRpnlSum,\n exposureCommandState.collateralAddressToExchangePrice,\n );\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\n simulate(\n params: IsolatedOrderSimulationSimulateParams,\n ): SimulateIsolatedOrderEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n amount = BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n }\n\n const userAccountExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataAccount,\n );\n\n const passivePoolExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataPassivePool,\n );\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amount).negated().toNumber(),\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\n const amountSize = estimatedPrice * amount;\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 /*\n amount of margin in rUSD terms that needs to be transferred from the source account to the destination account,\n this value is equal to absolute size in rUSD terms / leverage\n */\n\n const requiredMargin = BigNumber(amountSize)\n .abs()\n .div(BigNumber(params.isolatedPositionLeverage))\n .toNumber();\n\n const editCollateralActions: EditCollateralAction[] =\n userAccountExposure.getEditCollateralActionsToCoverMargin(requiredMargin);\n\n const newMarginInfoSource =\n userAccountExposure.getUsdNodeMarginInfoPostEditCollaterals(\n editCollateralActions,\n );\n\n /*\n * Compute Isolated Account Liquidation Margin Requirement Post Transfer + Trade\n * */\n\n const isolatedLMR = this.calculateIsolatedLMR(amountSize);\n\n /*\n * margin balance of the destination account is the requiredMargin which is expected to be transferred\n * to the destination account that performs the isolated trade\n * the liquidation price in this case is trying to estimate what the liquidation price would be all else equal for\n * the market where the trade is being made by the isolated account that is going to be created as part of isolated\n * trade operation\n * */\n const liquidationPrice = ExposureCommand.calculateLiquidation(\n requiredMargin,\n isolatedLMR,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n amount,\n );\n\n // todo: p1: margin ratio seems to be wrong on ui\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfoSource);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n\n const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);\n const snappedAmount = snappedAmountInBase * estimatedPrice;\n const xpEarnRangeMin = Math.round(\n Math.abs(snappedAmount) / INSTANT_TRADING_RATE_XP,\n );\n const xpEarnRangeMax = Math.round(\n (100 * Math.abs(snappedAmount)) / INSTANT_TRADING_RATE_XP,\n );\n\n return {\n estimatedPrice: estimatedPrice,\n estimatedSlippage: slippage * 100,\n fees: fees,\n liquidationPrice: liquidationPrice.toNumber(),\n marginRatio: marginRatio * 100,\n marginRatioHealth: marginRatioHealth,\n snappedAmount,\n snappedAmountInBase,\n requiredMargin: requiredMargin,\n editCollateralActions: editCollateralActions,\n xpEarnRange: {\n min: xpEarnRangeMin,\n max: xpEarnRangeMax,\n },\n maxSlippage: 1,\n } as SimulateIsolatedOrderEntity;\n }\n\n convertValue(\n params: IsolatedOrderSimulationConvertValueParams,\n ): IsolatedOrderSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!params.fromBase)\n return BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n else\n return BigNumber(params.amount)\n .times(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n }\n\n convertValueEstimatedPrice(\n params: TradeSimulationConvertValueEstimatedPriceParams,\n ): TradeSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.mtmRpnlSum,\n this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n const amountForSlippage = params.fromBase\n ? params.amount\n : BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amountForSlippage).negated().toNumber(),\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\n if (!params.fromBase)\n return BigNumber(params.amount).div(estimatedPrice).toNumber();\n else return BigNumber(params.amount).times(estimatedPrice).toNumber();\n }\n\n estimatedPrice(params: EstimatedPriceParams): EstimatedPriceResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.mtmRpnlSum,\n this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(params.amount).negated().toNumber(),\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n\n const price =\n this.loadedData.exposureDataAccount.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n slippage,\n );\n\n return {\n estimatedPrice,\n markPrice: price,\n };\n }\n\n roundToBaseSpacing(amount: number, baseSpacing: number): number {\n const snappedAmount = BigNumber(amount)\n .abs()\n .dividedBy(baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(baseSpacing)\n .toNumber();\n\n if (amount < 0) {\n return -snappedAmount;\n }\n return snappedAmount;\n }\n\n amountToSnappedAmount(\n amountInRusd: number,\n spotPrice: number,\n baseSpacing: number,\n ): number {\n const amountInBase = BigNumber(amountInRusd)\n .div(BigNumber(spotPrice))\n .toNumber();\n\n return this.roundToBaseSpacing(amountInBase, baseSpacing) * spotPrice;\n }\n\n calculateIsolatedLMR(isolatedExposure: number): number {\n // todo: p2: consider removing the need to load the entire data just to get a few vars to calc leverage bounds\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!this.loadedData.marketStorage) {\n throw new Error('Market storage not loaded');\n }\n\n // todo: p2: carefully test\n const marketRiskMatrix =\n this.loadedData.exposureDataAccount.riskMatrices.find(\n (riskMatrix: RiskMatrix) => {\n return (\n riskMatrix.risk_block_id ===\n BigNumber(\n String(this.loadedData?.marketStorage.risk_block_id),\n ).toNumber()\n );\n },\n );\n\n if (!marketRiskMatrix) {\n throw new Error('Failed to load risk matrix');\n }\n\n const marketDiagonalRiskParam =\n marketRiskMatrix.matrix[\n this.loadedData.marketConfiguration.risk_matrix_index\n ][this.loadedData.marketConfiguration.risk_matrix_index];\n const isolatedRiskMatrix: BigNumber[][] = [[marketDiagonalRiskParam]];\n const isolatedFilledExposures: BigNumber[] = [BigNumber(isolatedExposure)];\n\n return ExposureCommand.computeLiquidationMarginRequirement(\n isolatedRiskMatrix,\n isolatedFilledExposures,\n );\n }\n\n leverageBoundsAndAvailableMargin({\n amountTradedInRusd,\n }: LeverageBoundsAndAvailableMarginParams): LeverageBoundsAndAvailableMarginResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const spotPrice =\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n const snappedAmountInRusd = this.amountToSnappedAmount(\n amountTradedInRusd,\n spotPrice,\n baseSpacing,\n );\n\n /*\n todo: p2: consider introducing buffer to the leverage (e.g. to account for the effect of trade on upnl\n and actually depending on the size of the trade the estimated price would change -> different upnl\n as upnl is calculated against oracle prioce + rpnl is also affected through the fees\n * once the trader knows their trade size (in base & rusd terms), they should be able to toggle isolated trade flow\n * which will prompt the user to choose a desired leverage value\n * 0.1 can be hardcoded to be the min bound\n * to get the maximum bound we need to calculate leverage that can be achieved when IMR is reached for position\n * with 1 rUSD exposure in the market -> max leverage = 1/IMR\n * */\n\n // set max bound\n\n const lmrUnitExposure = this.calculateIsolatedLMR(1);\n\n const imrUnitExposure: BigNumber = amountNormalizer(\n String(this.loadedData.exposureDataAccount.riskMultipliers.im_multiplier),\n ).multipliedBy(lmrUnitExposure);\n\n const maxBound = BigNumber(1).dividedBy(imrUnitExposure).toNumber();\n\n // set min bound\n\n const userAccountExposure =\n IsolatedOrderSimulationClient.genExposureCommandObject(\n this.loadedData.exposureDataAccount,\n );\n\n /*\n max amount of margin in rUSD terms that can be transferred from the source account to the destination account\n that performs the isolated position trade\n */\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const minBound = BigNumber(snappedAmountInRusd)\n .abs()\n .dividedBy(availableMargin)\n .toNumber();\n\n if (minBound > maxBound) {\n throw Error('Min leverage bound higher than max');\n }\n\n return {\n minBound: minBound,\n maxBound: maxBound,\n availableMargin: availableMargin,\n };\n }\n\n updatePrice(price: number): void {\n if (!this.loadedData || !this.marketId) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n // update price\n const marketId = this.marketId;\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[marketId] =\n price;\n this.loadedData.exposureDataAccount.oraclePricePerMarket[marketId] = price;\n }\n}\n"]}
|
|
@@ -93,8 +93,8 @@ var TradeSimulationClient = /** @class */ (function () {
|
|
|
93
93
|
.div(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id])
|
|
94
94
|
.toNumber();
|
|
95
95
|
}
|
|
96
|
-
var userAccountExposure = new common_1.ExposureCommand(this.loadedData.exposureDataAccount.accountId, 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, this.loadedData.exposureDataAccount.collateralAddressToExchangePrice);
|
|
97
|
-
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
96
|
+
var userAccountExposure = new common_1.ExposureCommand(this.loadedData.exposureDataAccount.accountId, 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, this.loadedData.exposureDataAccount.mtmRpnlSum, this.loadedData.exposureDataAccount.collateralAddressToExchangePrice);
|
|
97
|
+
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.mtmRpnlSum, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
98
98
|
/*
|
|
99
99
|
max amount of margin in rUSD terms that can be transferred from the source account to the destination account
|
|
100
100
|
that performs the isolated position trade (PRE TRADE)
|
|
@@ -163,7 +163,7 @@ var TradeSimulationClient = /** @class */ (function () {
|
|
|
163
163
|
if (!this.loadedData) {
|
|
164
164
|
throw new Error('Data not loaded. Call arm() first.');
|
|
165
165
|
}
|
|
166
|
-
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
166
|
+
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.mtmRpnlSum, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
167
167
|
var amountForSlippage = params.fromBase
|
|
168
168
|
? params.amount
|
|
169
169
|
: (0, bignumber_js_1.default)(params.amount)
|
|
@@ -180,7 +180,7 @@ var TradeSimulationClient = /** @class */ (function () {
|
|
|
180
180
|
if (!this.loadedData) {
|
|
181
181
|
throw new Error('Data not loaded. Call arm() first.');
|
|
182
182
|
}
|
|
183
|
-
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
183
|
+
var passivePoolExposure = new common_1.ExposureCommand(this.loadedData.exposureDataPassivePool.accountId, 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, this.loadedData.exposureDataPassivePool.mtmRpnlSum, this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice);
|
|
184
184
|
var slippage = passivePoolExposure.getSlippage((0, bignumber_js_1.default)(params.amount).negated().toNumber(), this.loadedData.marketConfiguration, this.loadedData.marketStorage);
|
|
185
185
|
var price = this.loadedData.exposureDataAccount.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id];
|
|
186
186
|
var estimatedPrice = common_1.ExposureCommand.calculateEstimatedPrice(this.loadedData.exposureDataPassivePool.oraclePricePerMarket[this.loadedData.marketConfiguration.market_id], slippage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/trade.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,0CAKyB;AACzB,8DAAqC;AACrC,0CAA0D;AAE1D;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,C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AQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,QAAQ,CAAC;YACpE,KAAK,CAAC;QACR,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC7E,CAAC;IACH,4BAAC;AAAD,CAAC,AAjVD,IAiVC","sourcesContent":["import {\n EstimatedPriceParams,\n EstimatedPriceResult,\n SimulateTradeEntity,\n TradeSimulationConvertValueEstimatedPriceParams,\n TradeSimulationConvertValueParams,\n TradeSimulationConvertValueResult,\n TradeSimulationLoadDataParams,\n TradeSimulationSimulateParams,\n} from './types';\nimport AccountClient from '../account';\nimport {\n amountNormalizer,\n ExposureCommand,\n MarginInfo,\n TradeSimulationState,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { INSTANT_TRADING_RATE_XP } from '@reyaxyz/common';\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 let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n 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.accountId,\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 this.loadedData.exposureDataAccount.collateralAddressToExchangePrice,\n );\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n /*\n max amount of margin in rUSD terms that can be transferred from the source account to the destination account\n that performs the isolated position trade (PRE TRADE)\n */\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const marginBalance =\n userAccountExposure.getUsdNodeMarginInfo.marginBalance;\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amount).negated().toNumber(),\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 { usdNodeMarginInfo: newMarginInfo, tokenMarginInfoPerAsset } =\n userAccountExposure.getUsdNodeMarginInfoPostTrade(\n amount,\n this.loadedData.marketStorage.quote_collateral,\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage.risk_block_id,\n );\n\n const newQuoteTokenMarginInfo = tokenMarginInfoPerAsset.find(\n (marginInfo: MarginInfo) => {\n return (\n marginInfo.assetAddress ===\n this.loadedData?.marketStorage?.quote_collateral\n );\n },\n );\n\n if (!newQuoteTokenMarginInfo) {\n throw new Error('Error performing simulation');\n }\n\n /*\n * Note, required margin is the initial margin requirement in rUSD terms of the account after the trade.\n * margin balance rusd - initial delta rusd = margin balance rusd - (margin balance rusd - imr rusd) = imr rusd\n * */\n\n const requiredMargin =\n newQuoteTokenMarginInfo.marginBalance -\n newQuoteTokenMarginInfo.initialDelta;\n\n const liquidationPrice = ExposureCommand.calculateLiquidation(\n newMarginInfo.marginBalance,\n newQuoteTokenMarginInfo.liquidationMarginRequirement,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n amount,\n );\n\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n\n const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);\n const snappedAmount = snappedAmountInBase * estimatedPrice;\n const xpEarnRangeMin = Math.round(\n Math.abs(snappedAmount) / INSTANT_TRADING_RATE_XP,\n );\n const xpEarnRangeMax = Math.round(\n (100 * Math.abs(snappedAmount)) / INSTANT_TRADING_RATE_XP,\n );\n\n return {\n estimatedPrice,\n estimatedSlippage: slippage * 100,\n fees,\n liquidationPrice: liquidationPrice.toNumber(),\n marginRatio: marginRatio * 100,\n marginRatioHealth,\n marginBalance,\n availableMargin,\n requiredMargin,\n snappedAmount,\n snappedAmountInBase,\n xpEarnRange: {\n min: xpEarnRangeMin,\n max: xpEarnRangeMax,\n },\n maxSlippage: 1,\n } as SimulateTradeEntity;\n }\n\n convertValue(\n params: TradeSimulationConvertValueParams,\n ): TradeSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!params.fromBase)\n return BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n else\n return BigNumber(params.amount)\n .times(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n }\n\n convertValueEstimatedPrice(\n params: TradeSimulationConvertValueEstimatedPriceParams,\n ): TradeSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n const amountForSlippage = params.fromBase\n ? params.amount\n : BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amountForSlippage).negated().toNumber(),\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\n if (!params.fromBase)\n return BigNumber(params.amount).div(estimatedPrice).toNumber();\n else return BigNumber(params.amount).times(estimatedPrice).toNumber();\n }\n\n estimatedPrice(params: EstimatedPriceParams): EstimatedPriceResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(params.amount).negated().toNumber(),\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n\n const price =\n this.loadedData.exposureDataAccount.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n slippage,\n );\n\n return {\n estimatedPrice,\n markPrice: price,\n };\n }\n\n roundToBaseSpacing(amount: number, baseSpacing: number): number {\n const snappedAmount = BigNumber(amount)\n .abs()\n .dividedBy(baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(baseSpacing)\n .toNumber();\n\n if (amount < 0) {\n return -snappedAmount;\n }\n return snappedAmount;\n }\n\n updatePrice(price: number): void {\n if (!this.loadedData || !this.marketId) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n // update price\n const marketId = this.marketId;\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[marketId] =\n price;\n this.loadedData.exposureDataAccount.oraclePricePerMarket[marketId] = price;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/trade.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,0CAKyB;AACzB,8DAAqC;AACrC,0CAA0D;AAE1D;IAKE,+BAAY,aAA4B;QAJhC,aAAQ,GAAkB,IAAI,CAAC;QAC/B,cAAS,GAAkB,IAAI,CAAC;QA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L,cAAc,gBAAA;YACd,SAAS,EAAE,KAAK;SACjB,CAAC;IACJ,CAAC;IAED,kDAAkB,GAAlB,UAAmB,MAAc,EAAE,WAAmB;QACpD,IAAM,aAAa,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC;aACpC,GAAG,EAAE;aACL,SAAS,CAAC,WAAW,CAAC;aACtB,YAAY,CAAC,sBAAS,CAAC,WAAW,CAAC;aACnC,YAAY,CAAC,WAAW,CAAC;aACzB,QAAQ,EAAE,CAAC;QAEd,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACf,OAAO,CAAC,aAAa,CAAC;QACxB,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,2CAAW,GAAX,UAAY,KAAa;QACvB,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QACD,eAAe;QACf,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,QAAQ,CAAC;YACpE,KAAK,CAAC;QACR,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC7E,CAAC;IACH,4BAAC;AAAD,CAAC,AArVD,IAqVC","sourcesContent":["import {\n EstimatedPriceParams,\n EstimatedPriceResult,\n SimulateTradeEntity,\n TradeSimulationConvertValueEstimatedPriceParams,\n TradeSimulationConvertValueParams,\n TradeSimulationConvertValueResult,\n TradeSimulationLoadDataParams,\n TradeSimulationSimulateParams,\n} from './types';\nimport AccountClient from '../account';\nimport {\n amountNormalizer,\n ExposureCommand,\n MarginInfo,\n TradeSimulationState,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { INSTANT_TRADING_RATE_XP } from '@reyaxyz/common';\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 let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n 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.accountId,\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 this.loadedData.exposureDataAccount.mtmRpnlSum,\n this.loadedData.exposureDataAccount.collateralAddressToExchangePrice,\n );\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.mtmRpnlSum,\n this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n /*\n max amount of margin in rUSD terms that can be transferred from the source account to the destination account\n that performs the isolated position trade (PRE TRADE)\n */\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const marginBalance =\n userAccountExposure.getUsdNodeMarginInfo.marginBalance;\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amount).negated().toNumber(),\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 { usdNodeMarginInfo: newMarginInfo, tokenMarginInfoPerAsset } =\n userAccountExposure.getUsdNodeMarginInfoPostTrade(\n amount,\n this.loadedData.marketStorage.quote_collateral,\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage.risk_block_id,\n );\n\n const newQuoteTokenMarginInfo = tokenMarginInfoPerAsset.find(\n (marginInfo: MarginInfo) => {\n return (\n marginInfo.assetAddress ===\n this.loadedData?.marketStorage?.quote_collateral\n );\n },\n );\n\n if (!newQuoteTokenMarginInfo) {\n throw new Error('Error performing simulation');\n }\n\n /*\n * Note, required margin is the initial margin requirement in rUSD terms of the account after the trade.\n * margin balance rusd - initial delta rusd = margin balance rusd - (margin balance rusd - imr rusd) = imr rusd\n * */\n\n const requiredMargin =\n newQuoteTokenMarginInfo.marginBalance -\n newQuoteTokenMarginInfo.initialDelta;\n\n const liquidationPrice = ExposureCommand.calculateLiquidation(\n newMarginInfo.marginBalance,\n newQuoteTokenMarginInfo.liquidationMarginRequirement,\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n amount,\n );\n\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n const baseSpacing = amountNormalizer(\n this.loadedData.marketConfiguration.base_spacing,\n ).toNumber();\n\n const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);\n const snappedAmount = snappedAmountInBase * estimatedPrice;\n const xpEarnRangeMin = Math.round(\n Math.abs(snappedAmount) / INSTANT_TRADING_RATE_XP,\n );\n const xpEarnRangeMax = Math.round(\n (100 * Math.abs(snappedAmount)) / INSTANT_TRADING_RATE_XP,\n );\n\n return {\n estimatedPrice,\n estimatedSlippage: slippage * 100,\n fees,\n liquidationPrice: liquidationPrice.toNumber(),\n marginRatio: marginRatio * 100,\n marginRatioHealth,\n marginBalance,\n availableMargin,\n requiredMargin,\n snappedAmount,\n snappedAmountInBase,\n xpEarnRange: {\n min: xpEarnRangeMin,\n max: xpEarnRangeMax,\n },\n maxSlippage: 1,\n } as SimulateTradeEntity;\n }\n\n convertValue(\n params: TradeSimulationConvertValueParams,\n ): TradeSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n if (!params.fromBase)\n return BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n else\n return BigNumber(params.amount)\n .times(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n }\n\n convertValueEstimatedPrice(\n params: TradeSimulationConvertValueEstimatedPriceParams,\n ): TradeSimulationConvertValueResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.mtmRpnlSum,\n this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n const amountForSlippage = params.fromBase\n ? params.amount\n : BigNumber(params.amount)\n .div(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amountForSlippage).negated().toNumber(),\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\n if (!params.fromBase)\n return BigNumber(params.amount).div(estimatedPrice).toNumber();\n else return BigNumber(params.amount).times(estimatedPrice).toNumber();\n }\n\n estimatedPrice(params: EstimatedPriceParams): EstimatedPriceResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const passivePoolExposure = new ExposureCommand(\n this.loadedData.exposureDataPassivePool.accountId,\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 this.loadedData.exposureDataPassivePool.mtmRpnlSum,\n this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(params.amount).negated().toNumber(),\n this.loadedData.marketConfiguration,\n this.loadedData.marketStorage,\n );\n\n const price =\n this.loadedData.exposureDataAccount.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ];\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[\n this.loadedData.marketConfiguration.market_id\n ],\n slippage,\n );\n\n return {\n estimatedPrice,\n markPrice: price,\n };\n }\n\n roundToBaseSpacing(amount: number, baseSpacing: number): number {\n const snappedAmount = BigNumber(amount)\n .abs()\n .dividedBy(baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(baseSpacing)\n .toNumber();\n\n if (amount < 0) {\n return -snappedAmount;\n }\n return snappedAmount;\n }\n\n updatePrice(price: number): void {\n if (!this.loadedData || !this.marketId) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n // update price\n const marketId = this.marketId;\n this.loadedData.exposureDataPassivePool.oraclePricePerMarket[marketId] =\n price;\n this.loadedData.exposureDataAccount.oraclePricePerMarket[marketId] = price;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/edit-collateral.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sCAAsC,EACtC,sCAAsC,EACtC,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAGL,WAAW,EAGZ,MAAM,iBAAiB,CAAC;AACzB,MAAM,CAAC,OAAO,OAAO,8BAA8B;IACjD,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,aAAa,CAAgB;gBACzB,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa;IAO5D,GAAG,CAAC,MAAM,EAAE,sCAAsC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxE,QAAQ,CACN,MAAM,EAAE,sCAAsC,GAC7C,4BAA4B;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/edit-collateral.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sCAAsC,EACt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,GACnB,EAAE,sCAAsC,GAAG,sCAAsC;IAsElF,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAUjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,+CAA+C,EAC/C,iCAAiC,EACjC,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,YAAY,CAAC;AAUvC,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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,+CAA+C,EAC/C,iCAAiC,EACjC,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,YAAY,CAAC;AAUvC,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;IAmKpE,YAAY,CACV,MAAM,EAAE,iCAAiC,GACxC,iCAAiC;IAuBpC,0BAA0B,CACxB,MAAM,EAAE,+CAA+C,GACtD,iCAAiC;IAmDpC,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB;IA+ClE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAc/D,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAUjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.111.
|
|
3
|
+
"version": "0.111.22",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@reyaxyz/common": "0.
|
|
36
|
+
"@reyaxyz/common": "0.170.0",
|
|
37
37
|
"bignumber.js": "^9.1.2",
|
|
38
38
|
"ethers": "6.9.0",
|
|
39
39
|
"isomorphic-ws": "^5.0.0",
|
|
40
40
|
"ws": "^8.16.0"
|
|
41
41
|
},
|
|
42
42
|
"packageManager": "pnpm@8.3.1",
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "d4b14537a28e47ad3cc5c5f360001cb6ef737643",
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/ws": "8.5.10"
|
|
46
46
|
}
|
|
@@ -55,6 +55,7 @@ export default class EditCollateralSimulationClient {
|
|
|
55
55
|
this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset,
|
|
56
56
|
this.loadedData.exposureDataAccount.realizedPnLSum,
|
|
57
57
|
this.loadedData.exposureDataAccount.unrealizedPnLSum,
|
|
58
|
+
this.loadedData.exposureDataAccount.mtmRpnlSum,
|
|
58
59
|
this.loadedData.exposureDataAccount.collateralAddressToExchangePrice,
|
|
59
60
|
);
|
|
60
61
|
|
|
@@ -62,6 +62,7 @@ export default class IsolatedOrderSimulationClient {
|
|
|
62
62
|
exposureCommandState.tokenMarginInfoPerAsset,
|
|
63
63
|
exposureCommandState.realizedPnLSum,
|
|
64
64
|
exposureCommandState.unrealizedPnLSum,
|
|
65
|
+
exposureCommandState.mtmRpnlSum,
|
|
65
66
|
exposureCommandState.collateralAddressToExchangePrice,
|
|
66
67
|
);
|
|
67
68
|
}
|
|
@@ -255,6 +256,7 @@ export default class IsolatedOrderSimulationClient {
|
|
|
255
256
|
this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,
|
|
256
257
|
this.loadedData.exposureDataPassivePool.realizedPnLSum,
|
|
257
258
|
this.loadedData.exposureDataPassivePool.unrealizedPnLSum,
|
|
259
|
+
this.loadedData.exposureDataPassivePool.mtmRpnlSum,
|
|
258
260
|
this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,
|
|
259
261
|
);
|
|
260
262
|
|
|
@@ -305,6 +307,7 @@ export default class IsolatedOrderSimulationClient {
|
|
|
305
307
|
this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,
|
|
306
308
|
this.loadedData.exposureDataPassivePool.realizedPnLSum,
|
|
307
309
|
this.loadedData.exposureDataPassivePool.unrealizedPnLSum,
|
|
310
|
+
this.loadedData.exposureDataPassivePool.mtmRpnlSum,
|
|
308
311
|
this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,
|
|
309
312
|
);
|
|
310
313
|
const slippage = passivePoolExposure.getSlippage(
|
|
@@ -79,6 +79,7 @@ export default class TradeSimulationClient {
|
|
|
79
79
|
this.loadedData.exposureDataAccount.tokenMarginInfoPerAsset,
|
|
80
80
|
this.loadedData.exposureDataAccount.realizedPnLSum,
|
|
81
81
|
this.loadedData.exposureDataAccount.unrealizedPnLSum,
|
|
82
|
+
this.loadedData.exposureDataAccount.mtmRpnlSum,
|
|
82
83
|
this.loadedData.exposureDataAccount.collateralAddressToExchangePrice,
|
|
83
84
|
);
|
|
84
85
|
|
|
@@ -97,6 +98,7 @@ export default class TradeSimulationClient {
|
|
|
97
98
|
this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,
|
|
98
99
|
this.loadedData.exposureDataPassivePool.realizedPnLSum,
|
|
99
100
|
this.loadedData.exposureDataPassivePool.unrealizedPnLSum,
|
|
101
|
+
this.loadedData.exposureDataPassivePool.mtmRpnlSum,
|
|
100
102
|
this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,
|
|
101
103
|
);
|
|
102
104
|
|
|
@@ -255,6 +257,7 @@ export default class TradeSimulationClient {
|
|
|
255
257
|
this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,
|
|
256
258
|
this.loadedData.exposureDataPassivePool.realizedPnLSum,
|
|
257
259
|
this.loadedData.exposureDataPassivePool.unrealizedPnLSum,
|
|
260
|
+
this.loadedData.exposureDataPassivePool.mtmRpnlSum,
|
|
258
261
|
this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,
|
|
259
262
|
);
|
|
260
263
|
|
|
@@ -305,6 +308,7 @@ export default class TradeSimulationClient {
|
|
|
305
308
|
this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,
|
|
306
309
|
this.loadedData.exposureDataPassivePool.realizedPnLSum,
|
|
307
310
|
this.loadedData.exposureDataPassivePool.unrealizedPnLSum,
|
|
311
|
+
this.loadedData.exposureDataPassivePool.mtmRpnlSum,
|
|
308
312
|
this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,
|
|
309
313
|
);
|
|
310
314
|
const slippage = passivePoolExposure.getSlippage(
|