@reyaxyz/api-sdk 0.140.9 → 0.141.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.
- package/dist/clients/modules/isolated-order.simulation/index.js +1 -0
- package/dist/clients/modules/isolated-order.simulation/index.js.map +1 -1
- package/dist/clients/modules/isolated-order.simulation/types.js.map +1 -1
- package/dist/clients/modules/trade.simulation/index.js +2 -0
- package/dist/clients/modules/trade.simulation/index.js.map +1 -1
- package/dist/clients/modules/trade.simulation/types.js.map +1 -1
- package/dist/types/clients/modules/isolated-order.simulation/index.d.ts.map +1 -1
- package/dist/types/clients/modules/isolated-order.simulation/types.d.ts +1 -0
- package/dist/types/clients/modules/isolated-order.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/trade.simulation/index.d.ts.map +1 -1
- package/dist/types/clients/modules/trade.simulation/types.d.ts +2 -0
- package/dist/types/clients/modules/trade.simulation/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/modules/isolated-order.simulation/index.ts +2 -0
- package/src/clients/modules/isolated-order.simulation/types.ts +1 -0
- package/src/clients/modules/trade.simulation/index.ts +4 -0
- package/src/clients/modules/trade.simulation/types.ts +2 -0
|
@@ -133,6 +133,7 @@ var IsolatedOrderSimulationClient = /** @class */ (function () {
|
|
|
133
133
|
estimatedPrice: estimatedPrice,
|
|
134
134
|
estimatedSlippage: slippage * 100,
|
|
135
135
|
fees: fees,
|
|
136
|
+
takerFeesPercentage: (0, bignumber_js_1.default)(this.loadedData.feeParameter).toNumber() * 100,
|
|
136
137
|
liquidationPrice: liquidationPrice.toNumber(),
|
|
137
138
|
marginRatio: marginRatio * 100,
|
|
138
139
|
marginRatioHealth: marginRatioHealth,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA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ACpE,KAAK,CAAC;QACR,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC7E,CAAC;IACH,oCAAC;AAAD,CAAC,AAldD,IAkdC","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 customLeverage(): number | null {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n const { customLeverage } = this.loadedData;\n\n return customLeverage;\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"]}
|
|
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,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AoC,CAAC,CAAC;QACpD,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ;YAClB,eAAe,EAAE,eAAe;SACjC,CAAC;IACJ,CAAC;IAED,mDAAW,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,oCAAC;AAAD,CAAC,AApdD,IAodC","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 takerFeesPercentage:\n BigNumber(this.loadedData.feeParameter).toNumber() * 100,\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 customLeverage(): number | null {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n const { customLeverage } = this.loadedData;\n\n return customLeverage;\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n MarginAccountEntity,\n MarketEntity,\n EditCollateralAction,\n} from '@reyaxyz/common';\n\nexport type IsolatedOrderSimulationLoadDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type IsolatedOrderSimulationSimulateParams = {\n amount: number; // position size in rUSD / base terms, + for long | - for short\n isolatedPositionLeverage: number; // leverage chosen for isolated position trade\n fromBase?: boolean;\n};\n\nexport type IsolatedOrderSimulationConvertValueParams = {\n amount: number;\n fromBase: boolean;\n};\n\nexport type SimulateIsolatedOrderEntity = {\n liquidationPrice: number;\n fees: number;\n estimatedPrice: number;\n estimatedSlippage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n snappedAmount: number;\n snappedAmountInBase: number;\n requiredMargin: number;\n editCollateralActions: EditCollateralAction[];\n maxSlippage: number;\n xpEarnRange?: {\n min: number;\n max: number;\n };\n};\n\nexport type IsolatedOrderSimulationConvertValueResult = number;\n\nexport type LeverageBoundsAndAvailableMarginResult = {\n minBound: number;\n maxBound: number;\n availableMargin: number;\n};\n\nexport type LeverageBoundsAndAvailableMarginParams = {\n // Note, this amount is not expected to be snapped\n amountTradedInRusd: number;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n MarginAccountEntity,\n MarketEntity,\n EditCollateralAction,\n} from '@reyaxyz/common';\n\nexport type IsolatedOrderSimulationLoadDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type IsolatedOrderSimulationSimulateParams = {\n amount: number; // position size in rUSD / base terms, + for long | - for short\n isolatedPositionLeverage: number; // leverage chosen for isolated position trade\n fromBase?: boolean;\n};\n\nexport type IsolatedOrderSimulationConvertValueParams = {\n amount: number;\n fromBase: boolean;\n};\n\nexport type SimulateIsolatedOrderEntity = {\n liquidationPrice: number;\n fees: number;\n takerFeesPercentage: number;\n estimatedPrice: number;\n estimatedSlippage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n snappedAmount: number;\n snappedAmountInBase: number;\n requiredMargin: number;\n editCollateralActions: EditCollateralAction[];\n maxSlippage: number;\n xpEarnRange?: {\n min: number;\n max: number;\n };\n};\n\nexport type IsolatedOrderSimulationConvertValueResult = number;\n\nexport type LeverageBoundsAndAvailableMarginResult = {\n minBound: number;\n maxBound: number;\n availableMargin: number;\n};\n\nexport type LeverageBoundsAndAvailableMarginParams = {\n // Note, this amount is not expected to be snapped\n amountTradedInRusd: number;\n};\n"]}
|
|
@@ -138,6 +138,7 @@ var TradeSimulationClient = /** @class */ (function () {
|
|
|
138
138
|
estimatedPrice: estimatedPrice,
|
|
139
139
|
estimatedSlippage: slippage * 100,
|
|
140
140
|
fees: fees,
|
|
141
|
+
takerFeesPercentage: (0, bignumber_js_1.default)(tradeSimulationState.feeParameter).toNumber() * 100,
|
|
141
142
|
liquidationPrice: liquidationPrice.toNumber(),
|
|
142
143
|
marginRatio: marginRatio * 100,
|
|
143
144
|
marginRatioHealth: marginRatioHealth,
|
|
@@ -204,6 +205,7 @@ var TradeSimulationClient = /** @class */ (function () {
|
|
|
204
205
|
var xpEarnRangeMax = Math.round((100 * Math.abs(snappedAmount)) / common_2.INSTANT_TRADING_RATE_XP);
|
|
205
206
|
return {
|
|
206
207
|
fees: fees,
|
|
208
|
+
takerFeesPercentage: (0, bignumber_js_1.default)(tradeSimulationState.feeParameter).toNumber() * 100,
|
|
207
209
|
snappedAmount: snappedAmount,
|
|
208
210
|
snappedAmountInBase: snappedAmountInBase,
|
|
209
211
|
estimatedPrice: params.triggerPrice,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/trade.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,0CAMyB;AACzB,8DAAqC;AACrC,0CAA0D;AAE1D;IAUE,+BAAY,aAA4B;QAThC,aAAQ,GAAkB,IAAI,CAAC;QAC/B,cAAS,GAAkB,IAAI,CAAC;QAChC,eAAU,GAIP,IAAI,CAAC;QAId,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;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AAM,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;QAEO,IAAA,oBAAoB,GAAK,IAAI,CAAC,UAAU,qBAApB,CAAqB;QAEjD,eAAe;QACf,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,oBAAoB,CAAC,uBAAuB,CAAC,oBAAoB,CAC/D,QAAQ,CACT,GAAG,KAAK,CAAC;QACV,oBAAoB,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,QAAQ,CAAC;YACrE,KAAK,CAAC;IACV,CAAC;IACH,4BAAC;AAAD,CAAC,AA5fD,IA4fC","sourcesContent":["import {\n EstimatedPriceParams,\n EstimatedPriceResult,\n LimitTradeMaxOrderSizeParams,\n LimitTradeMaxOrderSizeResult,\n SimulateLimitTradeEntity,\n SimulateTradeEntity,\n TradeSimulationConvertValueEstimatedPriceParams,\n TradeSimulationConvertValueParams,\n TradeSimulationConvertValueResult,\n TradeSimulationLoadDataParams,\n TradeSimulationSimulateLimitParams,\n TradeSimulationSimulateParams,\n} from './types';\nimport AccountClient from '../account';\nimport {\n amountNormalizer,\n ExposureCommand,\n MarginInfo,\n PositionInfo,\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: {\n tradeSimulationState: TradeSimulationState;\n userAccountExposure: ExposureCommand;\n passivePoolExposure: ExposureCommand;\n } | null = null;\n private accountClient: AccountClient;\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: TradeSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n this.accountId = params.marginAccountId;\n\n const tradeSimulationState = await this.fetchMarketData(\n this.marketId,\n this.accountId,\n );\n\n const userAccountExposure = new ExposureCommand(\n tradeSimulationState.exposureDataAccount.accountId,\n tradeSimulationState.exposureDataAccount.rootCollateralPoolId,\n tradeSimulationState.exposureDataAccount.oraclePricePerMarket,\n tradeSimulationState.exposureDataAccount.accountBalancePerAsset,\n tradeSimulationState.exposureDataAccount.groupedByCollateral,\n tradeSimulationState.exposureDataAccount.riskMultipliers,\n tradeSimulationState.exposureDataAccount.riskMatrices,\n tradeSimulationState.exposureDataAccount.exchangeInfoPerAsset,\n tradeSimulationState.exposureDataAccount.positionInfoMarketConfiguration,\n tradeSimulationState.exposureDataAccount.uniqueTokenAddresses,\n tradeSimulationState.exposureDataAccount.uniqueQuoteCollaterals,\n tradeSimulationState.exposureDataAccount.tokenMarginInfoPerAsset,\n tradeSimulationState.exposureDataAccount.realizedPnLSum,\n tradeSimulationState.exposureDataAccount.unrealizedPnLSum,\n tradeSimulationState.exposureDataAccount.mtmRpnlSum,\n tradeSimulationState.exposureDataAccount.collateralAddressToExchangePrice,\n );\n\n const passivePoolExposure = new ExposureCommand(\n tradeSimulationState.exposureDataPassivePool.accountId,\n tradeSimulationState.exposureDataPassivePool.rootCollateralPoolId,\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket,\n tradeSimulationState.exposureDataPassivePool.accountBalancePerAsset,\n tradeSimulationState.exposureDataPassivePool.groupedByCollateral,\n tradeSimulationState.exposureDataPassivePool.riskMultipliers,\n tradeSimulationState.exposureDataPassivePool.riskMatrices,\n tradeSimulationState.exposureDataPassivePool.exchangeInfoPerAsset,\n tradeSimulationState.exposureDataPassivePool.positionInfoMarketConfiguration,\n tradeSimulationState.exposureDataPassivePool.uniqueTokenAddresses,\n tradeSimulationState.exposureDataPassivePool.uniqueQuoteCollaterals,\n tradeSimulationState.exposureDataPassivePool.tokenMarginInfoPerAsset,\n tradeSimulationState.exposureDataPassivePool.realizedPnLSum,\n tradeSimulationState.exposureDataPassivePool.unrealizedPnLSum,\n tradeSimulationState.exposureDataPassivePool.mtmRpnlSum,\n tradeSimulationState.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n this.loadedData = {\n tradeSimulationState,\n userAccountExposure,\n passivePoolExposure,\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 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 { tradeSimulationState, userAccountExposure, passivePoolExposure } =\n this.loadedData;\n\n let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n amount = BigNumber(params.amount)\n .div(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n )\n .toNumber();\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 tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage,\n );\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n slippage,\n );\n\n const fees = ExposureCommand.calculateFee(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n amount,\n tradeSimulationState.feeParameter,\n );\n\n const {\n usdNodeMarginInfo: newMarginInfo,\n tokenMarginInfoPerAsset,\n positionInfoMarketConfiguration,\n } = userAccountExposure.getUsdNodeMarginInfoPostTrade(\n amount,\n tradeSimulationState.marketStorage.quote_collateral,\n tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage.risk_block_id,\n );\n\n const newQuoteTokenMarginInfo = tokenMarginInfoPerAsset.find(\n (marginInfo: MarginInfo) => {\n return (\n marginInfo.assetAddress ===\n tradeSimulationState.marketStorage.quote_collateral\n );\n },\n );\n\n const positionInfo = positionInfoMarketConfiguration.find(\n (positionInfo: PositionInfo) => {\n return (\n positionInfo.market_id ===\n tradeSimulationState.marketConfiguration.market_id\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 tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n BigNumber(positionInfo?.base || 0).toNumber(),\n );\n\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n const baseSpacing = amountNormalizer(\n tradeSimulationState.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 getRiskMatrixElement(): number {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { tradeSimulationState } = this.loadedData;\n\n const riskBlockId = tradeSimulationState.marketStorage.risk_block_id;\n const riskMatrices = tradeSimulationState.exposureDataAccount.riskMatrices;\n\n const riskMatrix = riskMatrices.find(\n (riskMatrix) => riskMatrix.risk_block_id === riskBlockId,\n );\n\n if (!riskMatrix) {\n throw new Error('Risk matrix not found');\n }\n\n const riskMatrixIndex =\n tradeSimulationState.marketConfiguration.risk_matrix_index;\n\n return Number(riskMatrix.matrix[riskMatrixIndex][riskMatrixIndex]);\n }\n\n // Synchronous method to simulate operations based on an amount\n simulateLimit(\n params: TradeSimulationSimulateLimitParams,\n ): SimulateLimitTradeEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { tradeSimulationState, userAccountExposure } = this.loadedData;\n\n let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n amount = BigNumber(params.amount).div(params.triggerPrice).toNumber();\n }\n\n const baseSpacing = amountNormalizer(\n tradeSimulationState.marketConfiguration.base_spacing,\n ).toNumber();\n\n const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);\n const snappedAmount = snappedAmountInBase * params.triggerPrice;\n\n const fees = ExposureCommand.calculateFee(\n params.triggerPrice,\n amount,\n tradeSimulationState.feeParameter,\n );\n\n const marginBalance =\n userAccountExposure.getUsdNodeMarginInfo.marginBalance;\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const imrMultiplier = amountNormalizer(\n String(userAccountExposure.riskMultipliers.im_multiplier),\n ).toNumber();\n\n const riskMatrixElement = this.getRiskMatrixElement();\n\n const accountLMR =\n userAccountExposure.getUsdNodeMarginInfo.liquidationMarginRequirement;\n const accountIMR = accountLMR * imrMultiplier;\n\n const limitOrderLMR =\n Math.sqrt(riskMatrixElement) * Math.abs(snappedAmount);\n const limitOrderIMR = limitOrderLMR * imrMultiplier;\n\n const requiredMargin = accountIMR + limitOrderIMR;\n\n const liquidationMarginRequirement =\n userAccountExposure.getUsdNodeMarginInfo.liquidationMarginRequirement +\n limitOrderLMR;\n\n const marginRatio = ExposureCommand.getMarginRatio({\n marginBalance,\n liquidationMarginRequirement,\n });\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\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 fees,\n snappedAmount,\n snappedAmountInBase,\n estimatedPrice: params.triggerPrice,\n marginRatio: marginRatio * 100,\n marginRatioHealth,\n availableMargin,\n marginBalance,\n requiredMargin,\n xpEarnRange: {\n min: xpEarnRangeMin,\n max: xpEarnRangeMax,\n },\n };\n }\n\n getMaxAmountForLimitOrder(\n params: LimitTradeMaxOrderSizeParams,\n ): LimitTradeMaxOrderSizeResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { userAccountExposure, tradeSimulationState } = this.loadedData;\n\n const riskMatrixElement = this.getRiskMatrixElement();\n\n const imrMultiplier = amountNormalizer(\n String(userAccountExposure.riskMultipliers.im_multiplier),\n ).toNumber();\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const maxAmountSize = Math.max(\n (availableMargin / Math.sqrt(riskMatrixElement) / imrMultiplier) * 0.97, // @todo implement dynamic buffer\n 0,\n );\n const maxAmountBase = maxAmountSize / params.triggerPrice;\n\n const minAmountBase = amountNormalizer(\n tradeSimulationState.marketConfiguration.minimum_order_base,\n ).toNumber();\n\n const minAmountSize = minAmountBase * params.triggerPrice;\n\n return {\n maxAmountBase,\n maxAmountSize,\n minAmountBase,\n minAmountSize,\n };\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 const { tradeSimulationState } = this.loadedData;\n\n if (!params.fromBase)\n return BigNumber(params.amount)\n .div(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n )\n .toNumber();\n else\n return BigNumber(params.amount)\n .times(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.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 { tradeSimulationState, passivePoolExposure } = this.loadedData;\n\n const amountForSlippage = params.fromBase\n ? params.amount\n : BigNumber(params.amount)\n .div(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amountForSlippage).negated().toNumber(),\n tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage,\n );\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.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 customLeverage(): number | null {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { tradeSimulationState } = this.loadedData;\n\n return tradeSimulationState.customLeverage;\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 { tradeSimulationState, passivePoolExposure } = this.loadedData;\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(params.amount).negated().toNumber(),\n tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage,\n );\n\n const price =\n tradeSimulationState.exposureDataAccount.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ];\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.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\n const { tradeSimulationState } = this.loadedData;\n\n // update price\n const marketId = this.marketId;\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n marketId\n ] = price;\n tradeSimulationState.exposureDataAccount.oraclePricePerMarket[marketId] =\n price;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/trade.simulation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AC;QAC/B,oBAAoB,CAAC,uBAAuB,CAAC,oBAAoB,CAC/D,QAAQ,CACT,GAAG,KAAK,CAAC;QACV,oBAAoB,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,QAAQ,CAAC;YACrE,KAAK,CAAC;IACV,CAAC;IACH,4BAAC;AAAD,CAAC,AAhgBD,IAggBC","sourcesContent":["import {\n EstimatedPriceParams,\n EstimatedPriceResult,\n LimitTradeMaxOrderSizeParams,\n LimitTradeMaxOrderSizeResult,\n SimulateLimitTradeEntity,\n SimulateTradeEntity,\n TradeSimulationConvertValueEstimatedPriceParams,\n TradeSimulationConvertValueParams,\n TradeSimulationConvertValueResult,\n TradeSimulationLoadDataParams,\n TradeSimulationSimulateLimitParams,\n TradeSimulationSimulateParams,\n} from './types';\nimport AccountClient from '../account';\nimport {\n amountNormalizer,\n ExposureCommand,\n MarginInfo,\n PositionInfo,\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: {\n tradeSimulationState: TradeSimulationState;\n userAccountExposure: ExposureCommand;\n passivePoolExposure: ExposureCommand;\n } | null = null;\n private accountClient: AccountClient;\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: TradeSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n this.accountId = params.marginAccountId;\n\n const tradeSimulationState = await this.fetchMarketData(\n this.marketId,\n this.accountId,\n );\n\n const userAccountExposure = new ExposureCommand(\n tradeSimulationState.exposureDataAccount.accountId,\n tradeSimulationState.exposureDataAccount.rootCollateralPoolId,\n tradeSimulationState.exposureDataAccount.oraclePricePerMarket,\n tradeSimulationState.exposureDataAccount.accountBalancePerAsset,\n tradeSimulationState.exposureDataAccount.groupedByCollateral,\n tradeSimulationState.exposureDataAccount.riskMultipliers,\n tradeSimulationState.exposureDataAccount.riskMatrices,\n tradeSimulationState.exposureDataAccount.exchangeInfoPerAsset,\n tradeSimulationState.exposureDataAccount.positionInfoMarketConfiguration,\n tradeSimulationState.exposureDataAccount.uniqueTokenAddresses,\n tradeSimulationState.exposureDataAccount.uniqueQuoteCollaterals,\n tradeSimulationState.exposureDataAccount.tokenMarginInfoPerAsset,\n tradeSimulationState.exposureDataAccount.realizedPnLSum,\n tradeSimulationState.exposureDataAccount.unrealizedPnLSum,\n tradeSimulationState.exposureDataAccount.mtmRpnlSum,\n tradeSimulationState.exposureDataAccount.collateralAddressToExchangePrice,\n );\n\n const passivePoolExposure = new ExposureCommand(\n tradeSimulationState.exposureDataPassivePool.accountId,\n tradeSimulationState.exposureDataPassivePool.rootCollateralPoolId,\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket,\n tradeSimulationState.exposureDataPassivePool.accountBalancePerAsset,\n tradeSimulationState.exposureDataPassivePool.groupedByCollateral,\n tradeSimulationState.exposureDataPassivePool.riskMultipliers,\n tradeSimulationState.exposureDataPassivePool.riskMatrices,\n tradeSimulationState.exposureDataPassivePool.exchangeInfoPerAsset,\n tradeSimulationState.exposureDataPassivePool.positionInfoMarketConfiguration,\n tradeSimulationState.exposureDataPassivePool.uniqueTokenAddresses,\n tradeSimulationState.exposureDataPassivePool.uniqueQuoteCollaterals,\n tradeSimulationState.exposureDataPassivePool.tokenMarginInfoPerAsset,\n tradeSimulationState.exposureDataPassivePool.realizedPnLSum,\n tradeSimulationState.exposureDataPassivePool.unrealizedPnLSum,\n tradeSimulationState.exposureDataPassivePool.mtmRpnlSum,\n tradeSimulationState.exposureDataPassivePool.collateralAddressToExchangePrice,\n );\n\n this.loadedData = {\n tradeSimulationState,\n userAccountExposure,\n passivePoolExposure,\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 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 { tradeSimulationState, userAccountExposure, passivePoolExposure } =\n this.loadedData;\n\n let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n amount = BigNumber(params.amount)\n .div(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n )\n .toNumber();\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 tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage,\n );\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n slippage,\n );\n\n const fees = ExposureCommand.calculateFee(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n amount,\n tradeSimulationState.feeParameter,\n );\n\n const {\n usdNodeMarginInfo: newMarginInfo,\n tokenMarginInfoPerAsset,\n positionInfoMarketConfiguration,\n } = userAccountExposure.getUsdNodeMarginInfoPostTrade(\n amount,\n tradeSimulationState.marketStorage.quote_collateral,\n tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage.risk_block_id,\n );\n\n const newQuoteTokenMarginInfo = tokenMarginInfoPerAsset.find(\n (marginInfo: MarginInfo) => {\n return (\n marginInfo.assetAddress ===\n tradeSimulationState.marketStorage.quote_collateral\n );\n },\n );\n\n const positionInfo = positionInfoMarketConfiguration.find(\n (positionInfo: PositionInfo) => {\n return (\n positionInfo.market_id ===\n tradeSimulationState.marketConfiguration.market_id\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 tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n BigNumber(positionInfo?.base || 0).toNumber(),\n );\n\n const marginRatio = ExposureCommand.getMarginRatio(newMarginInfo);\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\n const baseSpacing = amountNormalizer(\n tradeSimulationState.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 takerFeesPercentage:\n BigNumber(tradeSimulationState.feeParameter).toNumber() * 100,\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 getRiskMatrixElement(): number {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { tradeSimulationState } = this.loadedData;\n\n const riskBlockId = tradeSimulationState.marketStorage.risk_block_id;\n const riskMatrices = tradeSimulationState.exposureDataAccount.riskMatrices;\n\n const riskMatrix = riskMatrices.find(\n (riskMatrix) => riskMatrix.risk_block_id === riskBlockId,\n );\n\n if (!riskMatrix) {\n throw new Error('Risk matrix not found');\n }\n\n const riskMatrixIndex =\n tradeSimulationState.marketConfiguration.risk_matrix_index;\n\n return Number(riskMatrix.matrix[riskMatrixIndex][riskMatrixIndex]);\n }\n\n // Synchronous method to simulate operations based on an amount\n simulateLimit(\n params: TradeSimulationSimulateLimitParams,\n ): SimulateLimitTradeEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { tradeSimulationState, userAccountExposure } = this.loadedData;\n\n let amount;\n if (params.fromBase) {\n amount = params.amount;\n } else {\n amount = BigNumber(params.amount).div(params.triggerPrice).toNumber();\n }\n\n const baseSpacing = amountNormalizer(\n tradeSimulationState.marketConfiguration.base_spacing,\n ).toNumber();\n\n const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);\n const snappedAmount = snappedAmountInBase * params.triggerPrice;\n\n const fees = ExposureCommand.calculateFee(\n params.triggerPrice,\n amount,\n tradeSimulationState.feeParameter,\n );\n\n const marginBalance =\n userAccountExposure.getUsdNodeMarginInfo.marginBalance;\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const imrMultiplier = amountNormalizer(\n String(userAccountExposure.riskMultipliers.im_multiplier),\n ).toNumber();\n\n const riskMatrixElement = this.getRiskMatrixElement();\n\n const accountLMR =\n userAccountExposure.getUsdNodeMarginInfo.liquidationMarginRequirement;\n const accountIMR = accountLMR * imrMultiplier;\n\n const limitOrderLMR =\n Math.sqrt(riskMatrixElement) * Math.abs(snappedAmount);\n const limitOrderIMR = limitOrderLMR * imrMultiplier;\n\n const requiredMargin = accountIMR + limitOrderIMR;\n\n const liquidationMarginRequirement =\n userAccountExposure.getUsdNodeMarginInfo.liquidationMarginRequirement +\n limitOrderLMR;\n\n const marginRatio = ExposureCommand.getMarginRatio({\n marginBalance,\n liquidationMarginRequirement,\n });\n\n const marginRatioHealth = ExposureCommand.evaluateHealthStatus(\n marginRatio * 100,\n );\n\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 fees,\n takerFeesPercentage:\n BigNumber(tradeSimulationState.feeParameter).toNumber() * 100,\n snappedAmount,\n snappedAmountInBase,\n estimatedPrice: params.triggerPrice,\n marginRatio: marginRatio * 100,\n marginRatioHealth,\n availableMargin,\n marginBalance,\n requiredMargin,\n xpEarnRange: {\n min: xpEarnRangeMin,\n max: xpEarnRangeMax,\n },\n };\n }\n\n getMaxAmountForLimitOrder(\n params: LimitTradeMaxOrderSizeParams,\n ): LimitTradeMaxOrderSizeResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { userAccountExposure, tradeSimulationState } = this.loadedData;\n\n const riskMatrixElement = this.getRiskMatrixElement();\n\n const imrMultiplier = amountNormalizer(\n String(userAccountExposure.riskMultipliers.im_multiplier),\n ).toNumber();\n\n const availableMargin =\n userAccountExposure.getUsdNodeMarginInfo.initialDelta;\n\n const maxAmountSize = Math.max(\n (availableMargin / Math.sqrt(riskMatrixElement) / imrMultiplier) * 0.97, // @todo implement dynamic buffer\n 0,\n );\n const maxAmountBase = maxAmountSize / params.triggerPrice;\n\n const minAmountBase = amountNormalizer(\n tradeSimulationState.marketConfiguration.minimum_order_base,\n ).toNumber();\n\n const minAmountSize = minAmountBase * params.triggerPrice;\n\n return {\n maxAmountBase,\n maxAmountSize,\n minAmountBase,\n minAmountSize,\n };\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 const { tradeSimulationState } = this.loadedData;\n\n if (!params.fromBase)\n return BigNumber(params.amount)\n .div(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n )\n .toNumber();\n else\n return BigNumber(params.amount)\n .times(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.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 { tradeSimulationState, passivePoolExposure } = this.loadedData;\n\n const amountForSlippage = params.fromBase\n ? params.amount\n : BigNumber(params.amount)\n .div(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ],\n )\n .toNumber();\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(amountForSlippage).negated().toNumber(),\n tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage,\n );\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.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 customLeverage(): number | null {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const { tradeSimulationState } = this.loadedData;\n\n return tradeSimulationState.customLeverage;\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 { tradeSimulationState, passivePoolExposure } = this.loadedData;\n\n const slippage = passivePoolExposure.getSlippage(\n BigNumber(params.amount).negated().toNumber(),\n tradeSimulationState.marketConfiguration,\n tradeSimulationState.marketStorage,\n );\n\n const price =\n tradeSimulationState.exposureDataAccount.oraclePricePerMarket[\n tradeSimulationState.marketConfiguration.market_id\n ];\n\n const estimatedPrice = ExposureCommand.calculateEstimatedPrice(\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n tradeSimulationState.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\n const { tradeSimulationState } = this.loadedData;\n\n // update price\n const marketId = this.marketId;\n tradeSimulationState.exposureDataPassivePool.oraclePricePerMarket[\n marketId\n ] = price;\n tradeSimulationState.exposureDataAccount.oraclePricePerMarket[marketId] =\n price;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/trade.simulation/types.ts"],"names":[],"mappings":"","sourcesContent":["import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';\n\nexport type TradeSimulationLoadDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type TradeSimulationSimulateParams = {\n amount: number; // position size / base, + for long | - for short\n fromBase?: boolean;\n};\n\nexport type TradeSimulationConvertValueParams = {\n amount: number;\n fromBase: boolean;\n};\n\nexport type EstimatedPriceParams = {\n amount: number; // amount in base\n};\n\nexport type EstimatedPriceResult = {\n estimatedPrice: number;\n markPrice: number;\n};\n\nexport type TradeSimulationConvertValueEstimatedPriceParams = {\n amount: number;\n fromBase: boolean;\n};\n\nexport type TradeSimulationConvertValueEstimatedPriceResult = number;\n\nexport type SimulateTradeEntity = {\n liquidationPrice: number;\n fees: number;\n estimatedPrice: number;\n estimatedSlippage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n availableMargin: number;\n marginBalance: number;\n requiredMargin: number;\n snappedAmount: number;\n snappedAmountInBase: number;\n xpEarnRange?: {\n min: number;\n max: number;\n };\n maxSlippage: number;\n};\n\nexport type TradeSimulationSimulateLimitParams = {\n triggerPrice: number;\n amount: number; // position size / base, + for long | - for short\n fromBase?: boolean;\n};\n\nexport type SimulateLimitTradeEntity = {\n fees: number;\n snappedAmount: number;\n snappedAmountInBase: number;\n estimatedPrice: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n availableMargin: number;\n marginBalance: number;\n requiredMargin: number;\n xpEarnRange: {\n min: number;\n max: number;\n };\n};\n\nexport type LimitTradeMaxOrderSizeParams = {\n triggerPrice: number;\n};\n\nexport type LimitTradeMaxOrderSizeResult = {\n maxAmountBase: number;\n maxAmountSize: number;\n minAmountBase: number;\n minAmountSize: number;\n};\n\nexport type TradeSimulationConvertValueResult = number;\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/trade.simulation/types.ts"],"names":[],"mappings":"","sourcesContent":["import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';\n\nexport type TradeSimulationLoadDataParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type TradeSimulationSimulateParams = {\n amount: number; // position size / base, + for long | - for short\n fromBase?: boolean;\n};\n\nexport type TradeSimulationConvertValueParams = {\n amount: number;\n fromBase: boolean;\n};\n\nexport type EstimatedPriceParams = {\n amount: number; // amount in base\n};\n\nexport type EstimatedPriceResult = {\n estimatedPrice: number;\n markPrice: number;\n};\n\nexport type TradeSimulationConvertValueEstimatedPriceParams = {\n amount: number;\n fromBase: boolean;\n};\n\nexport type TradeSimulationConvertValueEstimatedPriceResult = number;\n\nexport type SimulateTradeEntity = {\n liquidationPrice: number;\n fees: number;\n takerFeesPercentage: number;\n estimatedPrice: number;\n estimatedSlippage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n availableMargin: number;\n marginBalance: number;\n requiredMargin: number;\n snappedAmount: number;\n snappedAmountInBase: number;\n xpEarnRange?: {\n min: number;\n max: number;\n };\n maxSlippage: number;\n};\n\nexport type TradeSimulationSimulateLimitParams = {\n triggerPrice: number;\n amount: number; // position size / base, + for long | - for short\n fromBase?: boolean;\n};\n\nexport type SimulateLimitTradeEntity = {\n fees: number;\n takerFeesPercentage: number;\n snappedAmount: number;\n snappedAmountInBase: number;\n estimatedPrice: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n availableMargin: number;\n marginBalance: number;\n requiredMargin: number;\n xpEarnRange: {\n min: number;\n max: number;\n };\n};\n\nexport type LimitTradeMaxOrderSizeParams = {\n triggerPrice: number;\n};\n\nexport type LimitTradeMaxOrderSizeResult = {\n maxAmountBase: number;\n maxAmountSize: number;\n minAmountBase: number;\n minAmountSize: number;\n};\n\nexport type TradeSimulationConvertValueResult = number;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,yCAAyC,EACzC,yCAAyC,EACzC,qCAAqC,EACrC,qCAAqC,EACrC,sCAAsC,EACtC,sCAAsC,EACvC,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAEL,eAAe,EACf,oBAAoB,EAGrB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,oBAAoB,EACpB,oBA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I9B,YAAY,CACV,MAAM,EAAE,yCAAyC,GAChD,yCAAyC;IAuB5C,0BAA0B,CACxB,MAAM,EAAE,+CAA+C,GACtD,iCAAiC;IAmDpC,cAAc,IAAI,MAAM,GAAG,IAAI;IAS/B,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB;IA+ClE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAc/D,qBAAqB,CACnB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM;IAQT,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM;IAwCtD,gCAAgC,CAAC,EAC/B,kBAAkB,GACnB,EAAE,sCAAsC,GAAG,sCAAsC;IAsElF,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAUjC"}
|
|
@@ -15,6 +15,7 @@ export type IsolatedOrderSimulationConvertValueParams = {
|
|
|
15
15
|
export type SimulateIsolatedOrderEntity = {
|
|
16
16
|
liquidationPrice: number;
|
|
17
17
|
fees: number;
|
|
18
|
+
takerFeesPercentage: number;
|
|
18
19
|
estimatedPrice: number;
|
|
19
20
|
estimatedSlippage: number;
|
|
20
21
|
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/isolated-order.simulation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,qCAAqC,GAAG;IAClD,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IAC7B,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,wBA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.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,EACnB,+CAA+C,EAC/C,iCAAiC,EACjC,iCAAiC,EACjC,6BAA6B,EAC7B,kCAAkC,EAClC,6BAA6B,EAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,YAAY,CAAC;AAWvC,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAIF;IAChB,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAMlC,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAsDjD,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,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,EACnB,+CAA+C,EAC/C,iCAAiC,EACjC,iCAAiC,EACjC,6BAA6B,EAC7B,kCAAkC,EAClC,6BAA6B,EAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,YAAY,CAAC;AAWvC,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAIF;IAChB,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAMlC,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAsDjD,eAAe;IAW7B,QAAQ,CAAC,MAAM,EAAE,6BAA6B,GAAG,mBAAmB;IAiJpE,oBAAoB,IAAI,MAAM;IAyB9B,aAAa,CACX,MAAM,EAAE,kCAAkC,GACzC,wBAAwB;IAwF3B,yBAAyB,CACvB,MAAM,EAAE,4BAA4B,GACnC,4BAA4B;IAoC/B,YAAY,CACV,MAAM,EAAE,iCAAiC,GACxC,iCAAiC;IAyBpC,0BAA0B,CACxB,MAAM,EAAE,+CAA+C,GACtD,iCAAiC;IAkCpC,cAAc,IAAI,MAAM,GAAG,IAAI;IAU/B,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB;IA+BlE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAc/D,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAejC"}
|
|
@@ -26,6 +26,7 @@ export type TradeSimulationConvertValueEstimatedPriceResult = number;
|
|
|
26
26
|
export type SimulateTradeEntity = {
|
|
27
27
|
liquidationPrice: number;
|
|
28
28
|
fees: number;
|
|
29
|
+
takerFeesPercentage: number;
|
|
29
30
|
estimatedPrice: number;
|
|
30
31
|
estimatedSlippage: number;
|
|
31
32
|
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
@@ -48,6 +49,7 @@ export type TradeSimulationSimulateLimitParams = {
|
|
|
48
49
|
};
|
|
49
50
|
export type SimulateLimitTradeEntity = {
|
|
50
51
|
fees: number;
|
|
52
|
+
takerFeesPercentage: number;
|
|
51
53
|
snappedAmount: number;
|
|
52
54
|
snappedAmountInBase: number;
|
|
53
55
|
estimatedPrice: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,EAAE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G;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;IAC1D,iBAAiB,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;IAC5D,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE;QACX,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.141.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@reyaxyz/common": "0.
|
|
36
|
+
"@reyaxyz/common": "0.223.0",
|
|
37
37
|
"@simplewebauthn/types": "^10.0.0",
|
|
38
38
|
"axios": "^1.6.2",
|
|
39
39
|
"bignumber.js": "^9.1.2",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ws": "^8.16.0"
|
|
43
43
|
},
|
|
44
44
|
"packageManager": "pnpm@8.3.1",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "4920624119e860744d655ebd1756114470e8a912",
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/ws": "8.5.10"
|
|
48
48
|
}
|
|
@@ -194,6 +194,8 @@ export default class IsolatedOrderSimulationClient {
|
|
|
194
194
|
estimatedPrice: estimatedPrice,
|
|
195
195
|
estimatedSlippage: slippage * 100,
|
|
196
196
|
fees: fees,
|
|
197
|
+
takerFeesPercentage:
|
|
198
|
+
BigNumber(this.loadedData.feeParameter).toNumber() * 100,
|
|
197
199
|
liquidationPrice: liquidationPrice.toNumber(),
|
|
198
200
|
marginRatio: marginRatio * 100,
|
|
199
201
|
marginRatioHealth: marginRatioHealth,
|
|
@@ -23,6 +23,7 @@ export type IsolatedOrderSimulationConvertValueParams = {
|
|
|
23
23
|
export type SimulateIsolatedOrderEntity = {
|
|
24
24
|
liquidationPrice: number;
|
|
25
25
|
fees: number;
|
|
26
|
+
takerFeesPercentage: number;
|
|
26
27
|
estimatedPrice: number;
|
|
27
28
|
estimatedSlippage: number;
|
|
28
29
|
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
@@ -231,6 +231,8 @@ export default class TradeSimulationClient {
|
|
|
231
231
|
estimatedPrice,
|
|
232
232
|
estimatedSlippage: slippage * 100,
|
|
233
233
|
fees,
|
|
234
|
+
takerFeesPercentage:
|
|
235
|
+
BigNumber(tradeSimulationState.feeParameter).toNumber() * 100,
|
|
234
236
|
liquidationPrice: liquidationPrice.toNumber(),
|
|
235
237
|
marginRatio: marginRatio * 100,
|
|
236
238
|
marginRatioHealth,
|
|
@@ -345,6 +347,8 @@ export default class TradeSimulationClient {
|
|
|
345
347
|
|
|
346
348
|
return {
|
|
347
349
|
fees,
|
|
350
|
+
takerFeesPercentage:
|
|
351
|
+
BigNumber(tradeSimulationState.feeParameter).toNumber() * 100,
|
|
348
352
|
snappedAmount,
|
|
349
353
|
snappedAmountInBase,
|
|
350
354
|
estimatedPrice: params.triggerPrice,
|
|
@@ -34,6 +34,7 @@ export type TradeSimulationConvertValueEstimatedPriceResult = number;
|
|
|
34
34
|
export type SimulateTradeEntity = {
|
|
35
35
|
liquidationPrice: number;
|
|
36
36
|
fees: number;
|
|
37
|
+
takerFeesPercentage: number;
|
|
37
38
|
estimatedPrice: number;
|
|
38
39
|
estimatedSlippage: number;
|
|
39
40
|
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
@@ -58,6 +59,7 @@ export type TradeSimulationSimulateLimitParams = {
|
|
|
58
59
|
|
|
59
60
|
export type SimulateLimitTradeEntity = {
|
|
60
61
|
fees: number;
|
|
62
|
+
takerFeesPercentage: number;
|
|
61
63
|
snappedAmount: number;
|
|
62
64
|
snappedAmountInBase: number;
|
|
63
65
|
estimatedPrice: number;
|