@reyaxyz/api-sdk 0.151.19 → 0.151.21
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/depth-chart.simulation/index.js +2 -1
- package/dist/clients/modules/depth-chart.simulation/index.js.map +1 -1
- package/dist/types/clients/modules/depth-chart.simulation/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/clients/modules/depth-chart.simulation/index.ts +8 -2
|
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var common_1 = require("@reyaxyz/common");
|
|
42
43
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
43
44
|
var DepthChartSimulationClient = /** @class */ (function () {
|
|
44
45
|
function DepthChartSimulationClient(lpClient) {
|
|
@@ -117,7 +118,7 @@ var DepthChartSimulationClient = /** @class */ (function () {
|
|
|
117
118
|
var maxOrderSize = n0Delta.gt(0)
|
|
118
119
|
? (0, bignumber_js_1.default)(this.loadedData.maxOrderSizeLong)
|
|
119
120
|
: (0, bignumber_js_1.default)(this.loadedData.maxOrderSizeShort);
|
|
120
|
-
var currentPrice = (0, bignumber_js_1.default)(this.loadedData.spotPrice).times((0, bignumber_js_1.default)(1).minus(n0Delta.div((0, bignumber_js_1.default)(n0Delta).plus(maxOrderSize))));
|
|
121
|
+
var currentPrice = (0, bignumber_js_1.default)(this.loadedData.spotPrice).times((0, bignumber_js_1.default)(1).minus(n0Delta.div((0, bignumber_js_1.default)(n0Delta).plus(maxOrderSize.times((0, common_1.amountNormalizer)(this.loadedData.depthFactor))))));
|
|
121
122
|
var size = (0, bignumber_js_1.default)(delta).div(this.loadedData.spotPrice).abs();
|
|
122
123
|
return {
|
|
123
124
|
price: currentPrice.toNumber(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/depth-chart.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/depth-chart.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,0CAAyE;AACzE,8DAAqC;AAErC;IAIE,oCAAY,QAAkB;QAHtB,aAAQ,GAAkB,IAAI,CAAC;QAC/B,eAAU,GAAgC,IAAI,CAAC;QAGrD,oBAAoB;QACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,uDAAuD;IACjD,wCAAG,GAAT,UAAU,MAAqC;;;;;;wBAC7C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;wBAEhC,KAAA,IAAI,CAAA;wBAAc,qBAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAA;;wBAAzD,GAAK,UAAU,GAAG,SAAuC,CAAC;;;;;KAC3D;IAEa,kDAAa,GAA3B,UAA4B,QAAgB;;;gBAC1C,sBAAO,IAAI,CAAC,QAAQ,CAAC,iCAAiC,CAAC;wBACrD,QAAQ,EAAE,QAAQ;qBACnB,CAAC,EAAC;;;KACJ;IAED,kDAAa,GAAb,UAAc,MAA4B;QACxC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,kDAAkD;QAClD,IAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAC1B,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAChC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAC5C,CAAC;QACF,IAAM,eAAe,GAAG,WAAW,GAAG,CAAC,CAAA,M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B,GAArC,UACE,KAAa,EACb,cAAsB;QAEtB,iCAAiC;QACjC,IAAM,eAAe,GAAG,cAAc,GAAG,KAAK,CAAC;QAE/C,IAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACrD,kCAAkC;QAClC,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC;IACtD,CAAC;IACH,iCAAC;AAAD,CAAC,AA/GD,IA+GC","sourcesContent":["import {\n GetDepthChartParams,\n GetDepthChartResult,\n DepthSimulationLoadDataParams,\n SimulateDepthEntity,\n} from './types';\n\nimport LpClient from '../lp';\nimport { DepthSimulationState, amountNormalizer } from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\n\nexport default class DepthChartSimulationClient {\n private marketId: number | null = null;\n private loadedData: DepthSimulationState | null = null;\n private lpClient: LpClient;\n constructor(lpClient: LpClient) {\n // Constructor added\n this.lpClient = lpClient;\n }\n\n // Method to asynchronously load data based on marketId\n async arm(params: DepthSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n\n this.loadedData = await this.fetchPoolData(this.marketId);\n }\n\n private async fetchPoolData(marketId: number): Promise<DepthSimulationState> {\n return this.lpClient.getLpPoolDepthChartSimulationData({\n marketId: marketId,\n });\n }\n\n getDepthChart(params?: GetDepthChartParams): GetDepthChartResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n // Adjust initial step size based on max exposures\n const maxExposure = Math.max(\n this.loadedData.maxOrderSizeLong,\n Math.abs(this.loadedData.maxOrderSizeShort),\n );\n const initialStepSize = maxExposure / (params?.initialSteps || 100) || 10; // Customize this based on your needs\n\n const step = params?.step || initialStepSize;\n const percentageChange = params?.percentageChange || 50;\n\n const currentStep = step;\n\n const leftResults: SimulateDepthEntity[] = [];\n const rightResults: SimulateDepthEntity[] = [];\n\n // Simplified loop conditions to focus on reaching maxExposure limits efficiently\n let delta = 0;\n while (Math.abs(delta) < maxExposure) {\n delta -= currentStep;\n const result = this.calculate(delta);\n if (result.priceImpact >= percentageChange) break;\n leftResults.push(result);\n // Adjust currentStep based on your liquidity model or other factors\n }\n\n delta = 0; // Reset for the right side\n while (Math.abs(delta) < maxExposure) {\n delta += currentStep;\n const result = this.calculate(delta);\n if (result.priceImpact >= percentageChange) break;\n rightResults.push(result);\n // Adjust currentStep similarly\n }\n\n return {\n leftChart: leftResults.reverse(),\n rightChart: rightResults,\n };\n }\n\n private calculate(delta: number): SimulateDepthEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const n0Delta = BigNumber(this.loadedData.netExposure).plus(delta);\n const maxOrderSize = n0Delta.gt(0)\n ? BigNumber(this.loadedData.maxOrderSizeLong)\n : BigNumber(this.loadedData.maxOrderSizeShort);\n\n const currentPrice = BigNumber(this.loadedData.spotPrice).times(\n BigNumber(1).minus(\n n0Delta.div(\n BigNumber(n0Delta).plus(\n maxOrderSize.times(amountNormalizer(this.loadedData.depthFactor)),\n ),\n ),\n ),\n );\n\n const size = BigNumber(delta).div(this.loadedData.spotPrice).abs();\n\n return {\n price: currentPrice.toNumber(),\n totalSize: size.toNumber(),\n totalCost: size.times(currentPrice).toNumber(),\n priceImpact: DepthChartSimulationClient.calculatePriceChangePercentage(\n this.loadedData.spotPrice,\n currentPrice.toNumber(),\n ),\n };\n }\n\n static calculatePriceChangePercentage(\n price: number,\n estimatedPrice: number,\n ): number {\n // Calculate the price difference\n const priceDifference = estimatedPrice - price;\n\n const absPriceDifference = Math.abs(priceDifference);\n // Calculate the percentage change\n return (absPriceDifference / Math.abs(price)) * 100;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/depth-chart.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAE9B,MAAM,SAAS,CAAC;AAEjB,OAAO,QAAQ,MAAM,OAAO,CAAC;AAI7B,MAAM,CAAC,OAAO,OAAO,0BAA0B;IAC7C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,QAAQ,CAAW;gBACf,QAAQ,EAAE,QAAQ;IAMxB,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAMjD,aAAa;IAM3B,aAAa,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,mBAAmB;IA6ChE,OAAO,CAAC,SAAS;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/depth-chart.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAE9B,MAAM,SAAS,CAAC;AAEjB,OAAO,QAAQ,MAAM,OAAO,CAAC;AAI7B,MAAM,CAAC,OAAO,OAAO,0BAA0B;IAC7C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,QAAQ,CAAW;gBACf,QAAQ,EAAE,QAAQ;IAMxB,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAMjD,aAAa;IAM3B,aAAa,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,mBAAmB;IA6ChE,OAAO,CAAC,SAAS;IAiCjB,MAAM,CAAC,8BAA8B,CACnC,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,GACrB,MAAM;CAQV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.151.
|
|
3
|
+
"version": "0.151.21",
|
|
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.274.
|
|
36
|
+
"@reyaxyz/common": "0.274.4",
|
|
37
37
|
"@simplewebauthn/types": "^10.0.0",
|
|
38
38
|
"axios": "^1.6.2",
|
|
39
39
|
"bignumber.js": "^9.1.2",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"ws": "^8.16.0"
|
|
43
43
|
},
|
|
44
44
|
"packageManager": "pnpm@8.3.1",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "b16328fd4fcad352c0099099f7a4326e2cc90884",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@reyaxyz/database": "0.123.
|
|
47
|
+
"@reyaxyz/database": "0.123.6"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from './types';
|
|
7
7
|
|
|
8
8
|
import LpClient from '../lp';
|
|
9
|
-
import { DepthSimulationState } from '@reyaxyz/common';
|
|
9
|
+
import { DepthSimulationState, amountNormalizer } from '@reyaxyz/common';
|
|
10
10
|
import BigNumber from 'bignumber.js';
|
|
11
11
|
|
|
12
12
|
export default class DepthChartSimulationClient {
|
|
@@ -87,7 +87,13 @@ export default class DepthChartSimulationClient {
|
|
|
87
87
|
: BigNumber(this.loadedData.maxOrderSizeShort);
|
|
88
88
|
|
|
89
89
|
const currentPrice = BigNumber(this.loadedData.spotPrice).times(
|
|
90
|
-
BigNumber(1).minus(
|
|
90
|
+
BigNumber(1).minus(
|
|
91
|
+
n0Delta.div(
|
|
92
|
+
BigNumber(n0Delta).plus(
|
|
93
|
+
maxOrderSize.times(amountNormalizer(this.loadedData.depthFactor)),
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
),
|
|
91
97
|
);
|
|
92
98
|
|
|
93
99
|
const size = BigNumber(delta).div(this.loadedData.spotPrice).abs();
|