@reyaxyz/api-sdk 0.151.22 → 0.152.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/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/types/clients/modules/conditional-orders/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/clients/modules/conditional-orders/index.ts +4 -7
- 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;;;KACJ;IAEK,6DAA2B,GAAjC,UACE,MAAwC;;;;;;wBAElC,GAAG,GAAG,wDAAiD,MAAM,CAAC,SAAS,CAAE,CAAC;wBAC/D,qBAAM,IAAI,CAAC,GAAG,CAAU,GAAG,CAAC,EA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BAAmB,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
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAWyB;AACzB,iCAA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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"]}
|
|
@@ -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,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;AAEjB,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,OAAO,CAAC,WAAW,CAAc;gBAErB,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM;IAM5C,2CAA2C,CAC/C,MAAM,EAAE,iDAAiD,GACxD,OAAO,CAAC,iDAAiD,CAAC;IAOvD,2CAA2C,CAC/C,MAAM,EAAE,iDAAiD,GACxD,OAAO,CAAC,iDAAiD,CAAC;IAOvD,2BAA2B,CAC/B,MAAM,EAAE,gCAAgC,GACvC,OAAO,CAAC,gCAAgC,CAAC;IAStC,kCAAkC,CACtC,MAAM,EAAE,wCAAwC,GAC/C,OAAO,CAAC,wCAAwC,CAAC;IAS9C,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,4BAA4B,CAAC;IAkBlC,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,8BAA8B,CAAC;IAsCpC,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,4BAA4B,CAAC;YAuC1B,WAAW;YAQX,2BAA2B;CAgF1C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.152.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.276.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": "8b99367b3a67d41955b6ccd7ef58c9e544e741eb",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@reyaxyz/database": "0.123.
|
|
47
|
+
"@reyaxyz/database": "0.123.8"
|
|
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,
|
|
@@ -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
|
-
}
|