@reyaxyz/api-sdk 0.151.21 → 0.152.0
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/README.md +1 -1
- package/dist/clients/modules/conditional-orders/index.js +8 -10
- package/dist/clients/modules/conditional-orders/index.js.map +1 -1
- package/dist/clients/modules/depth-chart.simulation/index.js +13 -11
- package/dist/clients/modules/depth-chart.simulation/index.js.map +1 -1
- package/dist/types/clients/modules/conditional-orders/index.d.ts.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/conditional-orders/index.ts +4 -7
- package/src/clients/modules/depth-chart.simulation/index.ts +18 -10
- package/dist/clients/modules/conditional-orders/utils.js +0 -18
- package/dist/clients/modules/conditional-orders/utils.js.map +0 -1
- package/dist/types/clients/modules/conditional-orders/utils.d.ts +0 -2
- package/dist/types/clients/modules/conditional-orders/utils.d.ts.map +0 -1
- package/src/clients/modules/conditional-orders/utils.ts +0 -20
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -53,7 +53,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
var common_1 = require("@reyaxyz/common");
|
|
55
55
|
var ethers_1 = require("ethers");
|
|
56
|
-
var utils_1 = require("./utils");
|
|
57
56
|
var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
58
57
|
__extends(ConditionalOrdersClient, _super);
|
|
59
58
|
function ConditionalOrdersClient(reyaChainId, host) {
|
|
@@ -226,9 +225,9 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
226
225
|
};
|
|
227
226
|
ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds, amountInBase) {
|
|
228
227
|
return __awaiter(this, void 0, void 0, function () {
|
|
229
|
-
var inputs, actualAmountInBase, isLongOrder, orderPriceLimit, position, positionBase, creationTimestampMs,
|
|
230
|
-
return __generator(this, function (
|
|
231
|
-
switch (
|
|
228
|
+
var inputs, actualAmountInBase, isLongOrder, orderPriceLimit, position, positionBase, creationTimestampMs, _a, serializedSignature, nonce;
|
|
229
|
+
return __generator(this, function (_b) {
|
|
230
|
+
switch (_b.label) {
|
|
232
231
|
case 0:
|
|
233
232
|
if (!(orderType === common_1.ConditionalOrderType.LIMIT_ORDER)) return [3 /*break*/, 1];
|
|
234
233
|
if (amountInBase === undefined) {
|
|
@@ -244,7 +243,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
244
243
|
return [3 /*break*/, 3];
|
|
245
244
|
case 1: return [4 /*yield*/, this.getPosition(accountId, marketId)];
|
|
246
245
|
case 2:
|
|
247
|
-
position =
|
|
246
|
+
position = _b.sent();
|
|
248
247
|
positionBase = position.base;
|
|
249
248
|
if (positionBase === 0) {
|
|
250
249
|
throw new Error('Cannot create SL or TP order for closed positions');
|
|
@@ -253,15 +252,14 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
253
252
|
isLongOrder = actualAmountInBase > 0;
|
|
254
253
|
orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
|
|
255
254
|
inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(triggerPrice), orderPriceLimit]);
|
|
256
|
-
|
|
255
|
+
_b.label = 3;
|
|
257
256
|
case 3:
|
|
258
257
|
creationTimestampMs = Date.now();
|
|
259
|
-
|
|
260
|
-
return [4 /*yield*/, (0, common_1.signConditionalOrder)(signer, this.reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, nonce, common_1.CONDITIONAL_ORDER_SIG_DEADLINE)];
|
|
258
|
+
return [4 /*yield*/, (0, common_1.signOrdersGatewayOrder)(signer, this.reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, common_1.CONDITIONAL_ORDER_SIG_DEADLINE, creationTimestampMs)];
|
|
261
259
|
case 4:
|
|
262
|
-
|
|
260
|
+
_a = _b.sent(), serializedSignature = _a.serializedSignature, nonce = _a.nonce;
|
|
263
261
|
return [2 /*return*/, {
|
|
264
|
-
signature:
|
|
262
|
+
signature: serializedSignature,
|
|
265
263
|
actualAmountInBase: actualAmountInBase,
|
|
266
264
|
orderPriceLimit: orderPriceLimit,
|
|
267
265
|
nonce: nonce,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAWyB;AACzB,iCAAkC;AAiBlC,iCAAsC;AAEtC;IAAqD,2CAAU;IAG7D,iCAAY,WAAwB,EAAE,IAAY;QAChD,YAAA,MAAK,YAAC,IAAI,CAAC,SAAC;QACZ,KAAI,CAAC,WAAW,GAAG,WAAW,CAAC;;IACjC,CAAC;IAED,yCAAyC;IACnC,6EAA2C,GAAjD,UACE,MAAyD;;;;gBAEnD,GAAG,GAAG,wDAAiD,MAAM,CAAC,eAAe,CAAE,CAAC;gBACtF,sBAAO,IAAI,CAAC,GAAG,CAAoD,GAAG,EAAE;wBACtE,KAAK,EAAE,MAAM,CAAC,KAAK;qBACpB,CAAC,EAAC;;;KACJ;IAEK,6EAA2C,GAAjD,UACE,MAAyD;;;;gBAEnD,GAAG,GAAG,uDAAgD,MAAM,CAAC,aAAa,CAAE,CAAC;gBACnF,sBAAO,IAAI,CAAC,GAAG,CAAoD,GAAG,EAAE;wBACtE,KAAK,EAAE,MAAM,CAAC,KAAK;qBACpB,CAAC,EAAC;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AAY,CAAC,EAAE,eAAe,CAAC,CACxD,CAAC;;;wBAGE,mBAAmB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;wBACjC,KAAK,GAAG,IAAA,mBAAW,EAAC,SAAS,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;wBAElD,qBAAM,IAAA,6BAAoB,EAC1C,MAAM,EACN,IAAI,CAAC,WAAW,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,sBAAsB,EACtB,SAAS,EACT,MAAM,EACN,KAAK,EACL,uCAA8B,CAC/B,EAAA;;wBAXK,SAAS,GAAG,SAWjB;wBAED,sBAAO;gCACL,SAAS,WAAA;gCACT,kBAAkB,oBAAA;gCAClB,eAAe,iBAAA;gCACf,KAAK,OAAA;gCACL,QAAQ,EAAE,uCAA8B;gCACxC,mBAAmB,qBAAA;6BACpB,EAAC;;;;KACH;IACH,8BAAC;AAAD,CAAC,AAhPD,CAAqD,mBAAU,GAgP9D","sourcesContent":["import {\n calculateMaxPriceLimit,\n PositionEntity,\n RestClient,\n ReyaChainId,\n signConditionalOrder,\n signCancelConditionalOrder,\n ConditionalOrder,\n ConditionalOrderType,\n scale,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n} from '@reyaxyz/common';\nimport { AbiCoder } from 'ethers';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport {\n AlreadyGaveTradePermissionParams,\n AlreadyGaveTradePermissionResult,\n CancelConditionalOrderParams,\n CancelConditionalOrderResult,\n GetConditionalOrdersHistoryForMarginAccountParams,\n GetConditionalOrdersHistoryForMarginAccountResult,\n GetConditionalOrdersHistoryForWalletAddressParams,\n RegisterConditionalOrderParams,\n RegisterConditionalOrderResult,\n UpdateConditionalOrderParams,\n UpdateConditionalOrderResult,\n AlreadyGaveTradePermissionToWalletParams,\n AlreadyGaveTradePermissionToWalletResult,\n} from './types';\nimport { createNonce } from './utils';\n\nexport default class ConditionalOrdersClient extends RestClient {\n private reyaChainId: ReyaChainId;\n\n constructor(reyaChainId: ReyaChainId, host: string) {\n super(host);\n this.reyaChainId = reyaChainId;\n }\n\n // ------ Conditional Orders History ---\n async getConditionalOrdersHistoryForMarginAccount(\n params: GetConditionalOrdersHistoryForMarginAccountParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {\n const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {\n limit: params.limit,\n });\n }\n\n async getConditionalOrdersHistoryForWalletAddress(\n params: GetConditionalOrdersHistoryForWalletAddressParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {\n const uri = `/api/conditional-orders/get-orders-by-wallet/${params.walletAddress}`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {\n limit: params.limit,\n });\n }\n\n async alreadyGaveTradePermissions(\n params: AlreadyGaveTradePermissionParams,\n ): Promise<AlreadyGaveTradePermissionResult> {\n const uri = `/api/conditional-orders/gave-trade-permission/${params.accountId}`;\n const response = await this.get<boolean>(uri);\n\n return {\n permissionGiven: response,\n };\n }\n\n async alreadyGaveTradePermissionToWallet(\n params: AlreadyGaveTradePermissionToWalletParams,\n ): Promise<AlreadyGaveTradePermissionToWalletResult> {\n const uri = `/api/conditional-orders/gave-trade-permission-to-wallet/${params.accountId}/${params.targetWalletAddress}`;\n const response = await this.get<boolean>(uri);\n\n return {\n permissionGiven: response,\n };\n }\n\n async cancelConditionalOrder(\n params: CancelConditionalOrderParams,\n ): Promise<CancelConditionalOrderResult> {\n const signature = await signCancelConditionalOrder(\n params.signer,\n params.orderId,\n );\n\n const uri = `/api/conditional-orders/cancel-order`;\n const res = await this.put<ConditionalOrder>(\n uri,\n {},\n {\n orderId: params.orderId,\n userSignature: signature,\n },\n );\n return res;\n }\n\n async registerConditionalOrder(\n params: RegisterConditionalOrderParams,\n ): Promise<RegisterConditionalOrderResult> {\n const inputs = await this.parseConditionalOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.orderType,\n params.triggerPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n params.amountInBase,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/create-or-update-order`;\n\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualAmountInBase > 0,\n marketId: params.marketId,\n nonce: inputs.nonce.toString(),\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n orderType: params.orderType,\n signature: inputs.signature,\n signerWallet: await params.signer.getAddress(),\n timestampMs: inputs.creationTimestampMs,\n triggerPrice: params.triggerPrice,\n orderBase: params.amountInBase,\n },\n );\n return result;\n }\n\n async updateConditionalOrder(\n params: UpdateConditionalOrderParams,\n ): Promise<UpdateConditionalOrderResult> {\n const inputs = await this.parseConditionalOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.orderType,\n params.triggerPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n params.amountInBase,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/create-or-update-order`;\n\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualAmountInBase > 0,\n marketId: params.marketId,\n nonce: inputs.nonce.toString(),\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n orderType: params.orderType,\n signature: inputs.signature,\n signerWallet: await params.signer.getAddress(),\n timestampMs: inputs.creationTimestampMs,\n triggerPrice: params.triggerPrice,\n cancelOrderId: params.cancelOrderId,\n orderBase: params.amountInBase,\n },\n );\n return result;\n }\n\n private async getPosition(\n accountId: number,\n marketId: number,\n ): Promise<PositionEntity> {\n const uri = `/api/accounts/marginAccount/position/${accountId}/${marketId}`;\n return this.get<PositionEntity>(uri);\n }\n\n private async parseConditionalOrderInputs(\n signer: Signer | JsonRpcSigner,\n accountId: number,\n marketId: number,\n orderType: ConditionalOrderType,\n triggerPrice: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n amountInBase?: number,\n ): Promise<{\n signature: string;\n actualAmountInBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n let inputs: string;\n let actualAmountInBase: number;\n let isLongOrder: boolean;\n let orderPriceLimit: bigint;\n\n if (orderType === ConditionalOrderType.LIMIT_ORDER) {\n if (amountInBase === undefined) {\n throw new Error('Order base is required for limit orders');\n }\n\n if (amountInBase === 0) {\n throw new Error('Cannot create an empty limit order');\n }\n\n actualAmountInBase = amountInBase;\n isLongOrder = actualAmountInBase > 0;\n orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [scale(18)(amountInBase), scale(18)(triggerPrice)],\n );\n } else {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Cannot create SL or TP order for closed positions');\n }\n\n actualAmountInBase = -positionBase;\n isLongOrder = actualAmountInBase > 0;\n orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],\n );\n }\n\n const creationTimestampMs = Date.now();\n const nonce = createNonce(accountId, marketId, creationTimestampMs);\n\n const signature = await signConditionalOrder(\n signer,\n this.reyaChainId,\n accountId,\n marketId,\n exchangeId,\n counterpartyAccountIds,\n orderType,\n inputs,\n nonce,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n );\n\n return {\n signature,\n actualAmountInBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n}\n"]}
|
|
1
|
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A;6BACpB,EAAC;;;;KACH;IACH,8BAAC;AAAD,CAAC,AA9OD,CAAqD,mBAAU,GA8O9D","sourcesContent":["import {\n calculateMaxPriceLimit,\n PositionEntity,\n RestClient,\n ReyaChainId,\n signOrdersGatewayOrder,\n signCancelConditionalOrder,\n ConditionalOrder,\n ConditionalOrderType,\n scale,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n} from '@reyaxyz/common';\nimport { AbiCoder } from 'ethers';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport {\n AlreadyGaveTradePermissionParams,\n AlreadyGaveTradePermissionResult,\n CancelConditionalOrderParams,\n CancelConditionalOrderResult,\n GetConditionalOrdersHistoryForMarginAccountParams,\n GetConditionalOrdersHistoryForMarginAccountResult,\n GetConditionalOrdersHistoryForWalletAddressParams,\n RegisterConditionalOrderParams,\n RegisterConditionalOrderResult,\n UpdateConditionalOrderParams,\n UpdateConditionalOrderResult,\n AlreadyGaveTradePermissionToWalletParams,\n AlreadyGaveTradePermissionToWalletResult,\n} from './types';\n\nexport default class ConditionalOrdersClient extends RestClient {\n private reyaChainId: ReyaChainId;\n\n constructor(reyaChainId: ReyaChainId, host: string) {\n super(host);\n this.reyaChainId = reyaChainId;\n }\n\n // ------ Conditional Orders History ---\n async getConditionalOrdersHistoryForMarginAccount(\n params: GetConditionalOrdersHistoryForMarginAccountParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {\n const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {\n limit: params.limit,\n });\n }\n\n async getConditionalOrdersHistoryForWalletAddress(\n params: GetConditionalOrdersHistoryForWalletAddressParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {\n const uri = `/api/conditional-orders/get-orders-by-wallet/${params.walletAddress}`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {\n limit: params.limit,\n });\n }\n\n async alreadyGaveTradePermissions(\n params: AlreadyGaveTradePermissionParams,\n ): Promise<AlreadyGaveTradePermissionResult> {\n const uri = `/api/conditional-orders/gave-trade-permission/${params.accountId}`;\n const response = await this.get<boolean>(uri);\n\n return {\n permissionGiven: response,\n };\n }\n\n async alreadyGaveTradePermissionToWallet(\n params: AlreadyGaveTradePermissionToWalletParams,\n ): Promise<AlreadyGaveTradePermissionToWalletResult> {\n const uri = `/api/conditional-orders/gave-trade-permission-to-wallet/${params.accountId}/${params.targetWalletAddress}`;\n const response = await this.get<boolean>(uri);\n\n return {\n permissionGiven: response,\n };\n }\n\n async cancelConditionalOrder(\n params: CancelConditionalOrderParams,\n ): Promise<CancelConditionalOrderResult> {\n const signature = await signCancelConditionalOrder(\n params.signer,\n params.orderId,\n );\n\n const uri = `/api/conditional-orders/cancel-order`;\n const res = await this.put<ConditionalOrder>(\n uri,\n {},\n {\n orderId: params.orderId,\n userSignature: signature,\n },\n );\n return res;\n }\n\n async registerConditionalOrder(\n params: RegisterConditionalOrderParams,\n ): Promise<RegisterConditionalOrderResult> {\n const inputs = await this.parseConditionalOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.orderType,\n params.triggerPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n params.amountInBase,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/create-or-update-order`;\n\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualAmountInBase > 0,\n marketId: params.marketId,\n nonce: inputs.nonce.toString(),\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n orderType: params.orderType,\n signature: inputs.signature,\n signerWallet: await params.signer.getAddress(),\n timestampMs: inputs.creationTimestampMs,\n triggerPrice: params.triggerPrice,\n orderBase: params.amountInBase,\n },\n );\n return result;\n }\n\n async updateConditionalOrder(\n params: UpdateConditionalOrderParams,\n ): Promise<UpdateConditionalOrderResult> {\n const inputs = await this.parseConditionalOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.orderType,\n params.triggerPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n params.amountInBase,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/create-or-update-order`;\n\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualAmountInBase > 0,\n marketId: params.marketId,\n nonce: inputs.nonce.toString(),\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n orderType: params.orderType,\n signature: inputs.signature,\n signerWallet: await params.signer.getAddress(),\n timestampMs: inputs.creationTimestampMs,\n triggerPrice: params.triggerPrice,\n cancelOrderId: params.cancelOrderId,\n orderBase: params.amountInBase,\n },\n );\n return result;\n }\n\n private async getPosition(\n accountId: number,\n marketId: number,\n ): Promise<PositionEntity> {\n const uri = `/api/accounts/marginAccount/position/${accountId}/${marketId}`;\n return this.get<PositionEntity>(uri);\n }\n\n private async parseConditionalOrderInputs(\n signer: Signer | JsonRpcSigner,\n accountId: number,\n marketId: number,\n orderType: ConditionalOrderType,\n triggerPrice: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n amountInBase?: number,\n ): Promise<{\n signature: string;\n actualAmountInBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n let inputs: string;\n let actualAmountInBase: number;\n let isLongOrder: boolean;\n let orderPriceLimit: bigint;\n\n if (orderType === ConditionalOrderType.LIMIT_ORDER) {\n if (amountInBase === undefined) {\n throw new Error('Order base is required for limit orders');\n }\n\n if (amountInBase === 0) {\n throw new Error('Cannot create an empty limit order');\n }\n\n actualAmountInBase = amountInBase;\n isLongOrder = actualAmountInBase > 0;\n orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [scale(18)(amountInBase), scale(18)(triggerPrice)],\n );\n } else {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Cannot create SL or TP order for closed positions');\n }\n\n actualAmountInBase = -positionBase;\n isLongOrder = actualAmountInBase > 0;\n orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],\n );\n }\n\n const creationTimestampMs = Date.now();\n const { serializedSignature, nonce } = await signOrdersGatewayOrder(\n signer,\n this.reyaChainId,\n accountId,\n marketId,\n exchangeId,\n counterpartyAccountIds,\n orderType,\n inputs,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n );\n\n return {\n signature: serializedSignature,\n actualAmountInBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n}\n"]}
|
|
@@ -80,28 +80,30 @@ var DepthChartSimulationClient = /** @class */ (function () {
|
|
|
80
80
|
}
|
|
81
81
|
// Adjust initial step size based on max exposures
|
|
82
82
|
var maxExposure = Math.max(this.loadedData.maxOrderSizeLong, Math.abs(this.loadedData.maxOrderSizeShort));
|
|
83
|
-
var
|
|
83
|
+
var maxPriceImpact = 0.035; // 3.5%
|
|
84
|
+
var maxSize = (0, bignumber_js_1.default)(this.loadedData.netExposure)
|
|
85
|
+
.plus((0, bignumber_js_1.default)(maxExposure)
|
|
86
|
+
.times((0, common_1.amountNormalizer)(this.loadedData.depthFactor))
|
|
87
|
+
.times(maxPriceImpact)
|
|
88
|
+
.div(1 + maxPriceImpact))
|
|
89
|
+
.toNumber();
|
|
90
|
+
var maxDisplayedSize = maxExposure < maxSize ? maxExposure : maxSize;
|
|
91
|
+
var initialStepSize = maxDisplayedSize / ((params === null || params === void 0 ? void 0 : params.initialSteps) || 100);
|
|
84
92
|
var step = (params === null || params === void 0 ? void 0 : params.step) || initialStepSize;
|
|
85
|
-
var percentageChange = (params === null || params === void 0 ? void 0 : params.percentageChange) || 50;
|
|
86
|
-
var currentStep = step;
|
|
87
93
|
var leftResults = [];
|
|
88
94
|
var rightResults = [];
|
|
89
95
|
// Simplified loop conditions to focus on reaching maxExposure limits efficiently
|
|
90
96
|
var delta = 0;
|
|
91
|
-
while (Math.abs(delta) <
|
|
92
|
-
delta -=
|
|
97
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
98
|
+
delta -= step;
|
|
93
99
|
var result = this.calculate(delta);
|
|
94
|
-
if (result.priceImpact >= percentageChange)
|
|
95
|
-
break;
|
|
96
100
|
leftResults.push(result);
|
|
97
101
|
// Adjust currentStep based on your liquidity model or other factors
|
|
98
102
|
}
|
|
99
103
|
delta = 0; // Reset for the right side
|
|
100
|
-
while (Math.abs(delta) <
|
|
101
|
-
delta +=
|
|
104
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
105
|
+
delta += step;
|
|
102
106
|
var result = this.calculate(delta);
|
|
103
|
-
if (result.priceImpact >= percentageChange)
|
|
104
|
-
break;
|
|
105
107
|
rightResults.push(result);
|
|
106
108
|
// Adjust currentStep similarly
|
|
107
109
|
}
|
|
@@ -1 +1 @@
|
|
|
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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U,CAAC,SAAS,CAAC,CAAC,KAAK,CAC7D,IAAA,sBAAS,EAAC,CAAC,CAAC,CAAC,KAAK,CAChB,OAAO,CAAC,GAAG,CACT,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAC,IAAI,CACrB,YAAY,CAAC,KAAK,CAAC,IAAA,yBAAgB,EAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAClE,CACF,CACF,CACF,CAAC;QAEF,IAAM,IAAI,GAAG,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC;QAEnE,OAAO;YACL,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE;YAC9B,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE;YAC1B,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE;YAC9C,WAAW,EAAE,0BAA0B,CAAC,8BAA8B,CACpE,IAAI,CAAC,UAAU,CAAC,SAAS,EACzB,YAAY,CAAC,QAAQ,EAAE,CACxB;SACF,CAAC;IACJ,CAAC;IAEM,yDAA8B,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,AAvHD,IAuHC","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\n const maxPriceImpact = 0.035; // 3.5%\n const maxSize = BigNumber(this.loadedData.netExposure)\n .plus(\n BigNumber(maxExposure)\n .times(amountNormalizer(this.loadedData.depthFactor))\n .times(maxPriceImpact)\n .div(1 + maxPriceImpact),\n )\n .toNumber();\n\n const maxDisplayedSize = maxExposure < maxSize ? maxExposure : maxSize;\n\n const initialStepSize = maxDisplayedSize / (params?.initialSteps || 100);\n\n const step = params?.step || initialStepSize;\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) < maxDisplayedSize) {\n delta -= step;\n const result = this.calculate(delta);\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) < maxDisplayedSize) {\n delta += step;\n const result = this.calculate(delta);\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/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,WAAW,EAOZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAAgC,EAChC,gCAAgC,EAChC,4BAA4B,EAC5B,4BAA4B,EAC5B,iDAAiD,EACjD,iDAAiD,EACjD,iDAAiD,EACjD,8BAA8B,EAC9B,8BAA8B,EAC9B,4BAA4B,EAC5B,4BAA4B,EAC5B,wCAAwC,EACxC,wCAAwC,EACzC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,WAAW,EAOZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,g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AAC,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;
|
|
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;IAqDhE,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.
|
|
3
|
+
"version": "0.152.0",
|
|
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.275.0",
|
|
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": "09cb76961daa610f13180f612a26fa5e418961bf",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@reyaxyz/database": "0.123.
|
|
47
|
+
"@reyaxyz/database": "0.123.7"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
PositionEntity,
|
|
4
4
|
RestClient,
|
|
5
5
|
ReyaChainId,
|
|
6
|
-
|
|
6
|
+
signOrdersGatewayOrder,
|
|
7
7
|
signCancelConditionalOrder,
|
|
8
8
|
ConditionalOrder,
|
|
9
9
|
ConditionalOrderType,
|
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
AlreadyGaveTradePermissionToWalletParams,
|
|
28
28
|
AlreadyGaveTradePermissionToWalletResult,
|
|
29
29
|
} from './types';
|
|
30
|
-
import { createNonce } from './utils';
|
|
31
30
|
|
|
32
31
|
export default class ConditionalOrdersClient extends RestClient {
|
|
33
32
|
private reyaChainId: ReyaChainId;
|
|
@@ -245,9 +244,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
245
244
|
}
|
|
246
245
|
|
|
247
246
|
const creationTimestampMs = Date.now();
|
|
248
|
-
const nonce =
|
|
249
|
-
|
|
250
|
-
const signature = await signConditionalOrder(
|
|
247
|
+
const { serializedSignature, nonce } = await signOrdersGatewayOrder(
|
|
251
248
|
signer,
|
|
252
249
|
this.reyaChainId,
|
|
253
250
|
accountId,
|
|
@@ -256,12 +253,12 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
256
253
|
counterpartyAccountIds,
|
|
257
254
|
orderType,
|
|
258
255
|
inputs,
|
|
259
|
-
nonce,
|
|
260
256
|
CONDITIONAL_ORDER_SIG_DEADLINE,
|
|
257
|
+
creationTimestampMs,
|
|
261
258
|
);
|
|
262
259
|
|
|
263
260
|
return {
|
|
264
|
-
signature,
|
|
261
|
+
signature: serializedSignature,
|
|
265
262
|
actualAmountInBase,
|
|
266
263
|
orderPriceLimit,
|
|
267
264
|
nonce,
|
|
@@ -41,31 +41,39 @@ export default class DepthChartSimulationClient {
|
|
|
41
41
|
this.loadedData.maxOrderSizeLong,
|
|
42
42
|
Math.abs(this.loadedData.maxOrderSizeShort),
|
|
43
43
|
);
|
|
44
|
-
const initialStepSize = maxExposure / (params?.initialSteps || 100) || 10; // Customize this based on your needs
|
|
45
44
|
|
|
46
|
-
const
|
|
47
|
-
const
|
|
45
|
+
const maxPriceImpact = 0.035; // 3.5%
|
|
46
|
+
const maxSize = BigNumber(this.loadedData.netExposure)
|
|
47
|
+
.plus(
|
|
48
|
+
BigNumber(maxExposure)
|
|
49
|
+
.times(amountNormalizer(this.loadedData.depthFactor))
|
|
50
|
+
.times(maxPriceImpact)
|
|
51
|
+
.div(1 + maxPriceImpact),
|
|
52
|
+
)
|
|
53
|
+
.toNumber();
|
|
54
|
+
|
|
55
|
+
const maxDisplayedSize = maxExposure < maxSize ? maxExposure : maxSize;
|
|
48
56
|
|
|
49
|
-
const
|
|
57
|
+
const initialStepSize = maxDisplayedSize / (params?.initialSteps || 100);
|
|
58
|
+
|
|
59
|
+
const step = params?.step || initialStepSize;
|
|
50
60
|
|
|
51
61
|
const leftResults: SimulateDepthEntity[] = [];
|
|
52
62
|
const rightResults: SimulateDepthEntity[] = [];
|
|
53
63
|
|
|
54
64
|
// Simplified loop conditions to focus on reaching maxExposure limits efficiently
|
|
55
65
|
let delta = 0;
|
|
56
|
-
while (Math.abs(delta) <
|
|
57
|
-
delta -=
|
|
66
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
67
|
+
delta -= step;
|
|
58
68
|
const result = this.calculate(delta);
|
|
59
|
-
if (result.priceImpact >= percentageChange) break;
|
|
60
69
|
leftResults.push(result);
|
|
61
70
|
// Adjust currentStep based on your liquidity model or other factors
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
delta = 0; // Reset for the right side
|
|
65
|
-
while (Math.abs(delta) <
|
|
66
|
-
delta +=
|
|
74
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
75
|
+
delta += step;
|
|
67
76
|
const result = this.calculate(delta);
|
|
68
|
-
if (result.priceImpact >= percentageChange) break;
|
|
69
77
|
rightResults.push(result);
|
|
70
78
|
// Adjust currentStep similarly
|
|
71
79
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNonce = void 0;
|
|
4
|
-
function createNonce(accountId, marketId, timestampMs) {
|
|
5
|
-
// Validate the input ranges
|
|
6
|
-
if (marketId < 0 || marketId >= Math.pow(2, 32))
|
|
7
|
-
throw new Error('marketId is out of range');
|
|
8
|
-
if (accountId < 0 || accountId >= Math.pow(2, 128))
|
|
9
|
-
throw new Error('accountId is out of range');
|
|
10
|
-
if (timestampMs < 0 || timestampMs >= Math.pow(2, 64))
|
|
11
|
-
throw new Error('timestamp is out of range');
|
|
12
|
-
var hashUint256 = (BigInt(accountId) << BigInt(98)) |
|
|
13
|
-
(BigInt(timestampMs) << BigInt(32)) |
|
|
14
|
-
BigInt(marketId);
|
|
15
|
-
return hashUint256;
|
|
16
|
-
}
|
|
17
|
-
exports.createNonce = createNonce;
|
|
18
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CACzB,SAAiB,EACjB,QAAgB,EAChB,WAAmB;IAEnB,4BAA4B;IAC5B,IAAI,QAAQ,GAAG,CAAC,IAAI,QAAQ,IAAI,SAAA,CAAC,EAAI,EAAE,CAAA;QACrC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,IAAI,SAAS,GAAG,CAAC,IAAI,SAAS,IAAI,SAAA,CAAC,EAAI,GAAG,CAAA;QACxC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,IAAI,WAAW,GAAG,CAAC,IAAI,WAAW,IAAI,SAAA,CAAC,EAAI,EAAE,CAAA;QAC3C,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAE/C,IAAM,WAAW,GACf,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;QACjC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;QACnC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEnB,OAAO,WAAW,CAAC;AACrB,CAAC;AAnBD,kCAmBC","sourcesContent":["export function createNonce(\n accountId: number,\n marketId: number,\n timestampMs: number,\n): bigint {\n // Validate the input ranges\n if (marketId < 0 || marketId >= 2 ** 32)\n throw new Error('marketId is out of range');\n if (accountId < 0 || accountId >= 2 ** 128)\n throw new Error('accountId is out of range');\n if (timestampMs < 0 || timestampMs >= 2 ** 64)\n throw new Error('timestamp is out of range');\n\n const hashUint256 =\n (BigInt(accountId) << BigInt(98)) |\n (BigInt(timestampMs) << BigInt(32)) |\n BigInt(marketId);\n\n return hashUint256;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CACzB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,MAAM,CAeR"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function createNonce(
|
|
2
|
-
accountId: number,
|
|
3
|
-
marketId: number,
|
|
4
|
-
timestampMs: number,
|
|
5
|
-
): bigint {
|
|
6
|
-
// Validate the input ranges
|
|
7
|
-
if (marketId < 0 || marketId >= 2 ** 32)
|
|
8
|
-
throw new Error('marketId is out of range');
|
|
9
|
-
if (accountId < 0 || accountId >= 2 ** 128)
|
|
10
|
-
throw new Error('accountId is out of range');
|
|
11
|
-
if (timestampMs < 0 || timestampMs >= 2 ** 64)
|
|
12
|
-
throw new Error('timestamp is out of range');
|
|
13
|
-
|
|
14
|
-
const hashUint256 =
|
|
15
|
-
(BigInt(accountId) << BigInt(98)) |
|
|
16
|
-
(BigInt(timestampMs) << BigInt(32)) |
|
|
17
|
-
BigInt(marketId);
|
|
18
|
-
|
|
19
|
-
return hashUint256;
|
|
20
|
-
}
|