@reyaxyz/api-sdk 0.111.11 → 0.111.12

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 CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-1.7%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-7.89%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-0.63%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-1.71%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-1.67%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-7.96%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-0.64%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-1.68%25-red.svg?style=flat) |
10
10
 
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
17
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -64,7 +53,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
64
53
  Object.defineProperty(exports, "__esModule", { value: true });
65
54
  var common_1 = require("@reyaxyz/common");
66
55
  var ethers_1 = require("ethers");
67
- var types_1 = require("./types");
68
56
  var utils_1 = require("./utils");
69
57
  var ConditionalOrdersClient = /** @class */ (function (_super) {
70
58
  __extends(ConditionalOrdersClient, _super);
@@ -139,14 +127,14 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
139
127
  case 0: return [4 /*yield*/, (0, common_1.signCancelConditionalOrder)(params.signer, params.orderId)];
140
128
  case 1:
141
129
  signature = _a.sent();
142
- uri = "/api/conditional-orders/sl/cancel-order";
130
+ uri = "/api/conditional-orders/cancel-order";
143
131
  return [4 /*yield*/, this.put(uri, {}, {
144
132
  orderId: params.orderId,
145
133
  userSignature: signature,
146
134
  })];
147
135
  case 2:
148
136
  res = _a.sent();
149
- return [2 /*return*/, this.mapFromStopLossToConditionalOrder(res)];
137
+ return [2 /*return*/, res];
150
138
  }
151
139
  });
152
140
  });
@@ -190,10 +178,10 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
190
178
  var _c;
191
179
  return __generator(this, function (_d) {
192
180
  switch (_d.label) {
193
- case 0: return [4 /*yield*/, this.parseSlOrderInputs(params.signer, params.marginAccountId, params.marketId, params.stopLossPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
181
+ case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
194
182
  case 1:
195
183
  inputs = _d.sent();
196
- uri = "/api/conditional-orders/sl/create-order";
184
+ uri = "/api/conditional-orders/create-order";
197
185
  _a = this.post;
198
186
  _b = [uri,
199
187
  {}];
@@ -201,7 +189,8 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
201
189
  accountId: params.marginAccountId,
202
190
  marketId: params.marketId,
203
191
  isLong: inputs.positionBase < 0,
204
- stopPrice: params.stopLossPrice
192
+ orderType: params.orderType,
193
+ triggerPrice: params.triggerPrice
205
194
  };
206
195
  return [4 /*yield*/, params.signer.getAddress()];
207
196
  case 2: return [4 /*yield*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
@@ -215,7 +204,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
215
204
  _c)]))];
216
205
  case 3:
217
206
  result = _d.sent();
218
- return [2 /*return*/, this.mapFromStopLossToConditionalOrder(result)];
207
+ return [2 /*return*/, result];
219
208
  }
220
209
  });
221
210
  });
@@ -259,10 +248,10 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
259
248
  var _c;
260
249
  return __generator(this, function (_d) {
261
250
  switch (_d.label) {
262
- case 0: return [4 /*yield*/, this.parseSlOrderInputs(params.signer, params.marginAccountId, params.marketId, params.stopLossPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
251
+ case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
263
252
  case 1:
264
253
  inputs = _d.sent();
265
- uri = "/api/conditional-orders/sl/update-order";
254
+ uri = "/api/conditional-orders/update-order";
266
255
  _a = this.post;
267
256
  _b = [uri,
268
257
  {}];
@@ -270,7 +259,8 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
270
259
  accountId: params.marginAccountId,
271
260
  marketId: params.marketId,
272
261
  isLong: inputs.positionBase < 0,
273
- stopPrice: params.stopLossPrice
262
+ oderrType: params.orderType,
263
+ triggerPrice: params.triggerPrice
274
264
  };
275
265
  return [4 /*yield*/, params.signer.getAddress()];
276
266
  case 2: return [4 /*yield*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
@@ -284,7 +274,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
284
274
  _c)]))];
285
275
  case 3:
286
276
  result = _d.sent();
287
- return [2 /*return*/, this.mapFromStopLossToConditionalOrder(result)];
277
+ return [2 /*return*/, result];
288
278
  }
289
279
  });
290
280
  });
@@ -298,6 +288,39 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
298
288
  });
299
289
  });
300
290
  };
291
+ ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds) {
292
+ return __awaiter(this, void 0, void 0, function () {
293
+ var position, positionBase, isLongOrder, orderPriceLimit, inputs, creationTimestampMs, nonce, signature;
294
+ return __generator(this, function (_a) {
295
+ switch (_a.label) {
296
+ case 0: return [4 /*yield*/, this.getPosition(accountId, marketId)];
297
+ case 1:
298
+ position = _a.sent();
299
+ positionBase = position.base;
300
+ if (positionBase === 0) {
301
+ throw new Error('Position with no exposure');
302
+ }
303
+ isLongOrder = positionBase < 0;
304
+ orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
305
+ inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(triggerPrice), orderPriceLimit]);
306
+ creationTimestampMs = Date.now();
307
+ nonce = (0, utils_1.createNonce)(accountId, marketId, creationTimestampMs);
308
+ return [4 /*yield*/, (0, common_1.signConditionalOrder)(signer, this.reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, nonce, common_1.CONDITIONAL_ORDER_SIG_DEADLINE)];
309
+ case 2:
310
+ signature = _a.sent();
311
+ return [2 /*return*/, {
312
+ signature: signature,
313
+ positionBase: positionBase,
314
+ orderPriceLimit: orderPriceLimit,
315
+ nonce: nonce,
316
+ deadline: common_1.CONDITIONAL_ORDER_SIG_DEADLINE,
317
+ creationTimestampMs: creationTimestampMs,
318
+ }];
319
+ }
320
+ });
321
+ });
322
+ };
323
+ // todo: IR deprecate
301
324
  ConditionalOrdersClient.prototype.parseSlOrderInputs = function (signer, accountId, marketId, stopLossPrice, exchangeId, counterpartyAccountIds) {
302
325
  return __awaiter(this, void 0, void 0, function () {
303
326
  var position, positionBase, isLongOrder, orderPriceLimit, inputs, creationTimestampMs, nonce, signature;
@@ -315,7 +338,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
315
338
  inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(stopLossPrice), orderPriceLimit]);
316
339
  creationTimestampMs = Date.now();
317
340
  nonce = (0, utils_1.createNonce)(accountId, marketId, creationTimestampMs);
318
- return [4 /*yield*/, (0, common_1.signConditionalOrder)(signer, this.reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, types_1.ConditionalOrderTypeInContract.StopLoss, inputs, nonce, common_1.CONDITIONAL_ORDER_SIG_DEADLINE)];
341
+ return [4 /*yield*/, (0, common_1.signConditionalOrder)(signer, this.reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, common_1.ConditionalOrderType.STOP_LOSS, inputs, nonce, common_1.CONDITIONAL_ORDER_SIG_DEADLINE)];
319
342
  case 2:
320
343
  signature = _a.sent();
321
344
  return [2 /*return*/, {
@@ -330,10 +353,6 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
330
353
  });
331
354
  });
332
355
  };
333
- // todo: IR deprecate after mocks are implementes
334
- ConditionalOrdersClient.prototype.mapFromStopLossToConditionalOrder = function (order) {
335
- return __assign(__assign({}, order), { orderType: common_1.conditionalOrderTypeNames[common_1.ConditionalOrderType.STOP_LOSS], triggerPrice: order.stopPrice });
336
- };
337
356
  return ConditionalOrdersClient;
338
357
  }(common_1.RestClient));
339
358
  exports.default = ConditionalOrdersClient;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAayB;AACzB,iCAAkC;AAElC,iCAoBiB;AACjB,iCAAsC;AAEtC;IAAqD,2CAAU;IAG7D,iCAAY,WAAwB,EAAE,IAAY;QAChD,YAAA,MAAK,YAAC,IAAI,CAAC,SAAC;QACZ,KAAI,CAAC,WAAW,GAAG,WAAW,CAAC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AC;AAAD,CAAC,AApSD,CAAqD,mBAAU,GAoS9D","sourcesContent":["import {\n calculateMaxPriceLimit,\n PositionEntity,\n RestClient,\n ReyaChainId,\n signConditionalOrder,\n signCancelConditionalOrder,\n StopLossOrder,\n ConditionalOrder,\n ConditionalOrderType,\n scale,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n conditionalOrderTypeNames,\n} from '@reyaxyz/common';\nimport { AbiCoder } from 'ethers';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport {\n AlreadyGaveTradePermissionParams,\n AlreadyGaveTradePermissionResult,\n CancelConditionalOrderParams,\n CancelConditionalOrderResult,\n CancelSLOrderParams,\n CancelSLOrderResult,\n ConditionalOrderTypeInContract,\n GetConditionalOrdersHistoryForMarginAccountPaginatedParams,\n GetConditionalOrdersHistoryForMarginAccountPaginatedResult,\n GetConditionalOrdersHistoryForMarginAccountParams,\n GetConditionalOrdersHistoryForMarginAccountResult,\n RegisterConditionalOrderParams,\n RegisterConditionalOrderResult,\n RegisterSLOrderParams,\n RegisterSLOrderResult,\n UpdateConditionalOrderParams,\n UpdateConditionalOrderResult,\n UpdateSLOrderParams,\n UpdateSLOrderResult,\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 getConditionalOrdersHistoryForMarginAccountPaginated(\n params: GetConditionalOrdersHistoryForMarginAccountPaginatedParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountPaginatedResult> {\n const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}/paginated`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountPaginatedResult>(\n uri,\n {\n page: params.page,\n perPage: params.perPage,\n },\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 cancelSLOrder(\n params: CancelSLOrderParams,\n ): Promise<CancelSLOrderResult> {\n const signature = await signCancelConditionalOrder(\n params.signer,\n params.orderId,\n );\n\n const uri = `/api/conditional-orders/sl/cancel-order`;\n return this.put<StopLossOrder>(\n uri,\n {},\n {\n orderId: params.orderId,\n userSignature: signature,\n },\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/sl/cancel-order`;\n const res = await this.put<StopLossOrder>(\n uri,\n {},\n {\n orderId: params.orderId,\n userSignature: signature,\n },\n );\n return this.mapFromStopLossToConditionalOrder(res);\n }\n\n async registerSLOrder(\n params: RegisterSLOrderParams,\n ): Promise<RegisterSLOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/create-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n }\n\n async registerConditionalOrder(\n params: RegisterConditionalOrderParams,\n ): Promise<RegisterConditionalOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/create-order`;\n const result = await this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n return this.mapFromStopLossToConditionalOrder(result);\n }\n\n async updateSLOrder(\n params: UpdateSLOrderParams,\n ): Promise<UpdateSLOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/update-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n }\n\n async updateConditionalOrder(\n params: UpdateConditionalOrderParams,\n ): Promise<UpdateConditionalOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/update-order`;\n const result = await this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n return this.mapFromStopLossToConditionalOrder(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 parseSlOrderInputs(\n signer: Signer | JsonRpcSigner,\n accountId: number,\n marketId: number,\n stopLossPrice: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n ): Promise<{\n signature: string;\n positionBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Position with no exposure');\n }\n\n const isLongOrder = positionBase < 0;\n const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(stopLossPrice), orderPriceLimit],\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 ConditionalOrderTypeInContract.StopLoss,\n inputs,\n nonce,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n );\n\n return {\n signature,\n positionBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n\n // todo: IR deprecate after mocks are implementes\n private mapFromStopLossToConditionalOrder(\n order: StopLossOrder,\n ): ConditionalOrder {\n return {\n ...order,\n orderType: conditionalOrderTypeNames[ConditionalOrderType.STOP_LOSS],\n triggerPrice: order.stopPrice,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAYyB;AACzB,iCAAkC;AAsBlC,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,sFAAoD,GAA1D,UACE,MAAkE;;;;gBAE5D,GAAG,GAAG,wDAAiD,MAAM,CAAC,eAAe,eAAY,CAAC;gBAChG,sBAAO,IAAI,CAAC,GAAG,CACb,GAAG,EACH;wBACE,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,OAAO,EAAE,MAAM,CAAC,OAAO;qBACxB,CACF,EAAC;;;KACH;IAEK,6DAA2B,GAAjC,UACE,MAAwC;;;;;;wBAElC,GAAG,GAAG,wDAAiD,MAAM,CAAC,SAAS,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ACjC,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,6BAAoB,CAAC,SAAS,EAC9B,MAAM,EACN,KAAK,EACL,uCAA8B,CAC/B,EAAA;;wBAXK,SAAS,GAAG,SAWjB;wBAED,sBAAO;gCACL,SAAS,WAAA;gCACT,YAAY,cAAA;gCACZ,eAAe,iBAAA;gCACf,KAAK,OAAA;gCACL,QAAQ,EAAE,uCAA8B;gCACxC,mBAAmB,qBAAA;6BACpB,EAAC;;;;KACH;IACH,8BAAC;AAAD,CAAC,AAtVD,CAAqD,mBAAU,GAsV9D","sourcesContent":["import {\n calculateMaxPriceLimit,\n PositionEntity,\n RestClient,\n ReyaChainId,\n signConditionalOrder,\n signCancelConditionalOrder,\n StopLossOrder,\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 CancelSLOrderParams,\n CancelSLOrderResult,\n GetConditionalOrdersHistoryForMarginAccountPaginatedParams,\n GetConditionalOrdersHistoryForMarginAccountPaginatedResult,\n GetConditionalOrdersHistoryForMarginAccountParams,\n GetConditionalOrdersHistoryForMarginAccountResult,\n RegisterConditionalOrderParams,\n RegisterConditionalOrderResult,\n RegisterSLOrderParams,\n RegisterSLOrderResult,\n UpdateConditionalOrderParams,\n UpdateConditionalOrderResult,\n UpdateSLOrderParams,\n UpdateSLOrderResult,\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 getConditionalOrdersHistoryForMarginAccountPaginated(\n params: GetConditionalOrdersHistoryForMarginAccountPaginatedParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountPaginatedResult> {\n const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}/paginated`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountPaginatedResult>(\n uri,\n {\n page: params.page,\n perPage: params.perPage,\n },\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 cancelSLOrder(\n params: CancelSLOrderParams,\n ): Promise<CancelSLOrderResult> {\n const signature = await signCancelConditionalOrder(\n params.signer,\n params.orderId,\n );\n\n const uri = `/api/conditional-orders/sl/cancel-order`;\n return this.put<StopLossOrder>(\n uri,\n {},\n {\n orderId: params.orderId,\n userSignature: signature,\n },\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 registerSLOrder(\n params: RegisterSLOrderParams,\n ): Promise<RegisterSLOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/create-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\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 );\n\n // create new entry\n const uri = `/api/conditional-orders/create-order`;\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n orderType: params.orderType,\n triggerPrice: params.triggerPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n return result;\n }\n\n async updateSLOrder(\n params: UpdateSLOrderParams,\n ): Promise<UpdateSLOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/update-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\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 );\n\n // create new entry\n const uri = `/api/conditional-orders/update-order`;\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n oderrType: params.orderType,\n triggerPrice: params.triggerPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\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 ): Promise<{\n signature: string;\n positionBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Position with no exposure');\n }\n\n const isLongOrder = positionBase < 0;\n const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],\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 positionBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n\n // todo: IR deprecate\n private async parseSlOrderInputs(\n signer: Signer | JsonRpcSigner,\n accountId: number,\n marketId: number,\n stopLossPrice: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n ): Promise<{\n signature: string;\n positionBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Position with no exposure');\n }\n\n const isLongOrder = positionBase < 0;\n const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(stopLossPrice), orderPriceLimit],\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 ConditionalOrderType.STOP_LOSS,\n inputs,\n nonce,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n );\n\n return {\n signature,\n positionBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n}\n"]}
@@ -1,8 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConditionalOrderTypeInContract = void 0;
4
- var ConditionalOrderTypeInContract;
5
- (function (ConditionalOrderTypeInContract) {
6
- ConditionalOrderTypeInContract[ConditionalOrderTypeInContract["StopLoss"] = 0] = "StopLoss";
7
- })(ConditionalOrderTypeInContract || (exports.ConditionalOrderTypeInContract = ConditionalOrderTypeInContract = {}));
8
3
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":";;;AAwBA,IAAY,8BAEX;AAFD,WAAY,8BAA8B;IACxC,2FAAc,CAAA;AAChB,CAAC,EAFW,8BAA8B,8CAA9B,8BAA8B,QAEzC","sourcesContent":["import {\n StopLossOrder,\n ConditionalOrder,\n UnifiedConditionalOrderType,\n} from '@reyaxyz/common';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';\n\n// todo: IR to deprecate\nexport type CancelSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n orderId: string;\n};\n\n// todo: IR to deprecate\nexport type CancelSLOrderResult = StopLossOrder;\n\nexport type CancelConditionalOrderParams = {\n signer: Signer | JsonRpcSigner;\n orderId: string;\n};\n\nexport type CancelConditionalOrderResult = ConditionalOrder;\n\nexport enum ConditionalOrderTypeInContract {\n 'StopLoss' = 0,\n}\n\nexport type ConditionalOrderDetails = {\n accountId: number;\n marketId: number;\n exchangeId: number;\n counterpartyAccountIds: number[];\n orderType: number;\n inputs: string;\n signer: string;\n nonce: bigint;\n};\n\nexport type OrderSupportingParams = {\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n currentPrice: number;\n};\n\n// todo: IR to deprecate\nexport type RegisterSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type RegisterConditionalOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\n// todo: IR to deprecate\nexport type UpdateSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type UpdateConditionalOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\n// todo: IR to deprecate\nexport type RegisterSLOrderResult = StopLossOrder;\nexport type UpdateSLOrderResult = StopLossOrder;\n\nexport type RegisterConditionalOrderResult = ConditionalOrder;\nexport type UpdateConditionalOrderResult = ConditionalOrder;\n\nexport type AlreadyGaveTradePermissionParams = {\n accountId: number;\n};\n\nexport type AlreadyGaveTradePermissionResult = {\n permissionGiven: boolean;\n};\n\n// ---- Conditional Orders History ---\nexport type GetConditionalOrdersHistoryForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\nexport type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n page: number;\n perPage: number;\n};\n\nexport type GetConditionalOrdersHistoryForMarginAccountResult =\n UnifiedConditionalOrderType[];\nexport type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {\n data: UnifiedConditionalOrderType[];\n totalCount: number;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n StopLossOrder,\n ConditionalOrder,\n UnifiedConditionalOrderType,\n ConditionalOrderType,\n} from '@reyaxyz/common';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';\n\n// todo: IR to deprecate\nexport type CancelSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n orderId: string;\n};\n\n// todo: IR to deprecate\nexport type CancelSLOrderResult = StopLossOrder;\n\nexport type CancelConditionalOrderParams = {\n signer: Signer | JsonRpcSigner;\n orderId: string;\n};\n\nexport type CancelConditionalOrderResult = ConditionalOrder;\n\nexport type ConditionalOrderDetails = {\n accountId: number;\n marketId: number;\n exchangeId: number;\n counterpartyAccountIds: number[];\n orderType: number;\n inputs: string;\n signer: string;\n nonce: bigint;\n};\n\nexport type OrderSupportingParams = {\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n currentPrice: number;\n};\n\n// todo: IR to deprecate\nexport type RegisterSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type RegisterConditionalOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n triggerPrice: number;\n orderType: ConditionalOrderType;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\n// todo: IR to deprecate\nexport type UpdateSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type UpdateConditionalOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n triggerPrice: number;\n orderType: ConditionalOrderType;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\n// todo: IR to deprecate\nexport type RegisterSLOrderResult = StopLossOrder;\nexport type UpdateSLOrderResult = StopLossOrder;\n\nexport type RegisterConditionalOrderResult = ConditionalOrder;\nexport type UpdateConditionalOrderResult = ConditionalOrder;\n\nexport type AlreadyGaveTradePermissionParams = {\n accountId: number;\n};\n\nexport type AlreadyGaveTradePermissionResult = {\n permissionGiven: boolean;\n};\n\n// ---- Conditional Orders History ---\nexport type GetConditionalOrdersHistoryForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\nexport type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n page: number;\n perPage: number;\n};\n\nexport type GetConditionalOrdersHistoryForMarginAccountResult =\n UnifiedConditionalOrderType[];\nexport type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {\n data: UnifiedConditionalOrderType[];\n totalCount: number;\n};\n"]}
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.FundingRateHistoryGranularity = exports.AllMarginAccountsBalanceGranularity = exports.MarginAccountCollateralsBalanceGranularity = exports.MarginAccountBalanceGranularity = exports.LpBalanceGranularity = exports.MoneyInOutChainId = exports.ReyaChainId = exports.CandlesResolution = void 0;
17
+ exports.ConditionalOrderType = exports.FundingRateHistoryGranularity = exports.AllMarginAccountsBalanceGranularity = exports.MarginAccountCollateralsBalanceGranularity = exports.MarginAccountBalanceGranularity = exports.LpBalanceGranularity = exports.MoneyInOutChainId = exports.ReyaChainId = exports.CandlesResolution = void 0;
18
18
  // reexporting what we want to share with integrators
19
19
  var common_1 = require("@reyaxyz/common");
20
20
  Object.defineProperty(exports, "CandlesResolution", { enumerable: true, get: function () { return common_1.CandlesResolution; } });
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "MarginAccountBalanceGranularity", { enumerable:
25
25
  Object.defineProperty(exports, "MarginAccountCollateralsBalanceGranularity", { enumerable: true, get: function () { return common_1.MarginAccountCollateralsBalanceGranularity; } });
26
26
  Object.defineProperty(exports, "AllMarginAccountsBalanceGranularity", { enumerable: true, get: function () { return common_1.AllMarginAccountsBalanceGranularity; } });
27
27
  Object.defineProperty(exports, "FundingRateHistoryGranularity", { enumerable: true, get: function () { return common_1.FundingRateHistoryGranularity; } });
28
+ Object.defineProperty(exports, "ConditionalOrderType", { enumerable: true, get: function () { return common_1.ConditionalOrderType; } });
28
29
  __exportStar(require("./modules/account/types"), exports);
29
30
  __exportStar(require("./modules/conditional-orders/types"), exports);
30
31
  __exportStar(require("./modules/lp/types"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD,0CA6ByB;AA3BvB,2GAAA,iBAAiB,OAAA;AAYjB,qGAAA,WAAW,OAAA;AACX,2GAAA,iBAAiB,OAAA;AAGjB,8GAAA,oBAAoB,OAAA;AACpB,yHAAA,+BAA+B,OAAA;AAE/B,oIAAA,0CAA0C,OAAA;AAG1C,6HAAA,mCAAmC,OAAA;AAEnC,uHAAA,6BAA6B,OAAA;AAI/B,0DAAwC;AACxC,qEAAmD;AACnD,qDAAmC;AACnC,0DAAwC;AACxC,yDAAuC;AACvC,mEAAiD;AACjD,wDAAsC;AACtC,iFAA+D;AAC/D,4EAA0D;AAC1D,kFAAgE;AAChE,6EAA2D;AAC3D,yEAAuD;AACvD,mFAAiE;AACjE,yFAAuE;AACvE,8EAA4D;AAC5D,+DAA6C;AAC7C,yEAAuD;AACvD,kFAAgE;AAChE,4EAA0D","sourcesContent":["// reexporting what we want to share with integrators\nexport {\n Candle,\n CandlesResolution,\n MarketEntity,\n LpTransactionHistoryEntity,\n TradingHistoryEntity,\n PositionHistoryEntity,\n PositionEntity,\n TransactionHistoryType,\n MarginAccountTransactionHistoryType,\n MarginAccountTransactionHistoryEntity,\n MarginAccountEntity,\n LpPositionEntity,\n LpPoolEntity,\n ReyaChainId,\n MoneyInOutChainId,\n GetLpPoolPerformanceChartDataResult,\n GetLpPoolBalanceChartDataResult,\n LpBalanceGranularity,\n MarginAccountBalanceGranularity,\n GetMarginAccountBalanceChartDataResult,\n MarginAccountCollateralsBalanceGranularity,\n GetMarginAccountCollateralsBalanceChartDataResult,\n GetAllMarginAccountsBalanceChartDataResult,\n AllMarginAccountsBalanceGranularity,\n GetFundingRateChartDataResult,\n FundingRateHistoryGranularity,\n MoneyInOutConfigurationPerTokenName,\n UnifiedConditionalOrderType,\n} from '@reyaxyz/common';\nexport * from './modules/account/types';\nexport * from './modules/conditional-orders/types';\nexport * from './modules/lp/types';\nexport * from './modules/markets/types';\nexport * from './modules/tokens/types';\nexport * from './modules/trade.simulation/types';\nexport * from './modules/owner/types';\nexport * from './modules/deposit-existing-MA.simulation/types';\nexport * from './modules/deposit-new-MA.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/edit-collateral.simulation/types';\nexport * from './modules/withdraw-MA.simulation/types';\nexport * from './modules/withdraw-passive-pool.simulation/types';\nexport * from './modules/transfer-margin-between-MAs.simulation/types';\nexport * from './modules/transfer-MA-Pool.simulation/types';\nexport * from './modules/funding-rate/types';\nexport * from './modules/depth-chart.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/isolated-order.simulation/types';\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD,0CA8ByB;AA5BvB,2GAAA,iBAAiB,OAAA;AAYjB,qGAAA,WAAW,OAAA;AACX,2GAAA,iBAAiB,OAAA;AAGjB,8GAAA,oBAAoB,OAAA;AACpB,yHAAA,+BAA+B,OAAA;AAE/B,oIAAA,0CAA0C,OAAA;AAG1C,6HAAA,mCAAmC,OAAA;AAEnC,uHAAA,6BAA6B,OAAA;AAG7B,8GAAA,oBAAoB,OAAA;AAEtB,0DAAwC;AACxC,qEAAmD;AACnD,qDAAmC;AACnC,0DAAwC;AACxC,yDAAuC;AACvC,mEAAiD;AACjD,wDAAsC;AACtC,iFAA+D;AAC/D,4EAA0D;AAC1D,kFAAgE;AAChE,6EAA2D;AAC3D,yEAAuD;AACvD,mFAAiE;AACjE,yFAAuE;AACvE,8EAA4D;AAC5D,+DAA6C;AAC7C,yEAAuD;AACvD,kFAAgE;AAChE,4EAA0D","sourcesContent":["// reexporting what we want to share with integrators\nexport {\n Candle,\n CandlesResolution,\n MarketEntity,\n LpTransactionHistoryEntity,\n TradingHistoryEntity,\n PositionHistoryEntity,\n PositionEntity,\n TransactionHistoryType,\n MarginAccountTransactionHistoryType,\n MarginAccountTransactionHistoryEntity,\n MarginAccountEntity,\n LpPositionEntity,\n LpPoolEntity,\n ReyaChainId,\n MoneyInOutChainId,\n GetLpPoolPerformanceChartDataResult,\n GetLpPoolBalanceChartDataResult,\n LpBalanceGranularity,\n MarginAccountBalanceGranularity,\n GetMarginAccountBalanceChartDataResult,\n MarginAccountCollateralsBalanceGranularity,\n GetMarginAccountCollateralsBalanceChartDataResult,\n GetAllMarginAccountsBalanceChartDataResult,\n AllMarginAccountsBalanceGranularity,\n GetFundingRateChartDataResult,\n FundingRateHistoryGranularity,\n MoneyInOutConfigurationPerTokenName,\n UnifiedConditionalOrderType,\n ConditionalOrderType,\n} from '@reyaxyz/common';\nexport * from './modules/account/types';\nexport * from './modules/conditional-orders/types';\nexport * from './modules/lp/types';\nexport * from './modules/markets/types';\nexport * from './modules/tokens/types';\nexport * from './modules/trade.simulation/types';\nexport * from './modules/owner/types';\nexport * from './modules/deposit-existing-MA.simulation/types';\nexport * from './modules/deposit-new-MA.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/edit-collateral.simulation/types';\nexport * from './modules/withdraw-MA.simulation/types';\nexport * from './modules/withdraw-passive-pool.simulation/types';\nexport * from './modules/transfer-margin-between-MAs.simulation/types';\nexport * from './modules/transfer-MA-Pool.simulation/types';\nexport * from './modules/funding-rate/types';\nexport * from './modules/depth-chart.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/isolated-order.simulation/types';\n"]}
@@ -13,7 +13,7 @@ export default class ConditionalOrdersClient extends RestClient {
13
13
  updateSLOrder(params: UpdateSLOrderParams): Promise<UpdateSLOrderResult>;
14
14
  updateConditionalOrder(params: UpdateConditionalOrderParams): Promise<UpdateConditionalOrderResult>;
15
15
  private getPosition;
16
+ private parseConditionalOrderInputs;
16
17
  private parseSlOrderInputs;
17
- private mapFromStopLossToConditionalOrder;
18
18
  }
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -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,EASZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAAgC,EAChC,gCAAgC,EAChC,4BAA4B,EAC5B,4BAA4B,EAC5B,mBAAmB,EACnB,mBAAmB,EAEnB,0DAA0D,EAC1D,0DAA0D,EAC1D,iDAAiD,EACjD,iDAAiD,EACjD,8BAA8B,EAC9B,8BAA8B,EAC9B,qBAAqB,EACrB,qBAAqB,EACrB,4BAA4B,EAC5B,4BAA4B,EAC5B,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB,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,oDAAoD,CACxD,MAAM,EAAE,0DAA0D,GACjE,OAAO,CAAC,0DAA0D,CAAC;IAWhE,2BAA2B,CA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;IAOvD,oDAAoD,CACxD,MAAM,EAAE,0DAA0D,GACjE,OAAO,CAAC,0DAA0D,CAAC;IAWhE,2BAA2B,CAC/B,MAAM,EAAE,gCAAgC,GACvC,OAAO,CAAC,gCAAgC,CAAC;IAStC,aAAa,CACjB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;IAiBzB,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,4BAA4B,CAAC;IAkBlC,eAAe,CACnB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAgC3B,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,8BAA8B,CAAC;IAmCpC,aAAa,CACjB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;IAgCzB,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,4BAA4B,CAAC;YAmC1B,WAAW;YAQX,2BAA2B;YAyD3B,kBAAkB;CAsDjC"}
@@ -1,4 +1,4 @@
1
- import { StopLossOrder, ConditionalOrder, UnifiedConditionalOrderType } from '@reyaxyz/common';
1
+ import { StopLossOrder, ConditionalOrder, UnifiedConditionalOrderType, ConditionalOrderType } from '@reyaxyz/common';
2
2
  import { Signer, JsonRpcSigner } from 'ethers';
3
3
  import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
4
4
  export type CancelSLOrderParams = {
@@ -11,9 +11,6 @@ export type CancelConditionalOrderParams = {
11
11
  orderId: string;
12
12
  };
13
13
  export type CancelConditionalOrderResult = ConditionalOrder;
14
- export declare enum ConditionalOrderTypeInContract {
15
- 'StopLoss' = 0
16
- }
17
14
  export type ConditionalOrderDetails = {
18
15
  accountId: number;
19
16
  marketId: number;
@@ -39,7 +36,8 @@ export type RegisterSLOrderParams = {
39
36
  export type RegisterConditionalOrderParams = {
40
37
  signer: Signer | JsonRpcSigner;
41
38
  marginAccountId: MarginAccountEntity['id'];
42
- stopLossPrice: number;
39
+ triggerPrice: number;
40
+ orderType: ConditionalOrderType;
43
41
  marketId: number;
44
42
  supportingParams: OrderSupportingParams;
45
43
  };
@@ -53,7 +51,8 @@ export type UpdateSLOrderParams = {
53
51
  export type UpdateConditionalOrderParams = {
54
52
  signer: Signer | JsonRpcSigner;
55
53
  marginAccountId: MarginAccountEntity['id'];
56
- stopLossPrice: number;
54
+ triggerPrice: number;
55
+ orderType: ConditionalOrderType;
57
56
  marketId: number;
58
57
  supportingParams: OrderSupportingParams;
59
58
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,2BAA2B,EAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpE,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,4BAA4B,GAAG;IACzC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;AAE5D,oBAAY,8BAA8B;IACxC,UAAU,IAAI;CACf;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,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F,MAAM,MAAM,iDAAiD,GAC3D,2BAA2B,EAAE,CAAC;AAChC,MAAM,MAAM,0DAA0D,GAAG;IACvE,IAAI,EAAE,2BAA2B,EAAE,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -1,4 +1,4 @@
1
- export { Candle, CandlesResolution, MarketEntity, LpTransactionHistoryEntity, TradingHistoryEntity, PositionHistoryEntity, PositionEntity, TransactionHistoryType, MarginAccountTransactionHistoryType, MarginAccountTransactionHistoryEntity, MarginAccountEntity, LpPositionEntity, LpPoolEntity, ReyaChainId, MoneyInOutChainId, GetLpPoolPerformanceChartDataResult, GetLpPoolBalanceChartDataResult, LpBalanceGranularity, MarginAccountBalanceGranularity, GetMarginAccountBalanceChartDataResult, MarginAccountCollateralsBalanceGranularity, GetMarginAccountCollateralsBalanceChartDataResult, GetAllMarginAccountsBalanceChartDataResult, AllMarginAccountsBalanceGranularity, GetFundingRateChartDataResult, FundingRateHistoryGranularity, MoneyInOutConfigurationPerTokenName, UnifiedConditionalOrderType, } from '@reyaxyz/common';
1
+ export { Candle, CandlesResolution, MarketEntity, LpTransactionHistoryEntity, TradingHistoryEntity, PositionHistoryEntity, PositionEntity, TransactionHistoryType, MarginAccountTransactionHistoryType, MarginAccountTransactionHistoryEntity, MarginAccountEntity, LpPositionEntity, LpPoolEntity, ReyaChainId, MoneyInOutChainId, GetLpPoolPerformanceChartDataResult, GetLpPoolBalanceChartDataResult, LpBalanceGranularity, MarginAccountBalanceGranularity, GetMarginAccountBalanceChartDataResult, MarginAccountCollateralsBalanceGranularity, GetMarginAccountCollateralsBalanceChartDataResult, GetAllMarginAccountsBalanceChartDataResult, AllMarginAccountsBalanceGranularity, GetFundingRateChartDataResult, FundingRateHistoryGranularity, MoneyInOutConfigurationPerTokenName, UnifiedConditionalOrderType, ConditionalOrderType, } from '@reyaxyz/common';
2
2
  export * from './modules/account/types';
3
3
  export * from './modules/conditional-orders/types';
4
4
  export * from './modules/lp/types';
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,sBAAsB,EACtB,mCAAmC,EACnC,qCAAqC,EACrC,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,+BAA+B,EAC/B,sCAAsC,EACtC,0CAA0C,EAC1C,iDAAiD,EACjD,0CAA0C,EAC1C,mCAAmC,EACnC,6BAA6B,EAC7B,6BAA6B,EAC7B,mCAAmC,EACnC,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC;AAChE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,kDAAkD,CAAC;AACjE,cAAc,wDAAwD,CAAC;AACvE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,2CAA2C,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,sBAAsB,EACtB,mCAAmC,EACnC,qCAAqC,EACrC,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,+BAA+B,EAC/B,sCAAsC,EACtC,0CAA0C,EAC1C,iDAAiD,EACjD,0CAA0C,EAC1C,mCAAmC,EACnC,6BAA6B,EAC7B,6BAA6B,EAC7B,mCAAmC,EACnC,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC;AAChE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,kDAAkD,CAAC;AACjE,cAAc,wDAAwD,CAAC;AACvE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,2CAA2C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/api-sdk",
3
- "version": "0.111.11",
3
+ "version": "0.111.12",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -33,14 +33,14 @@
33
33
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
34
34
  },
35
35
  "dependencies": {
36
- "@reyaxyz/common": "0.168.2",
36
+ "@reyaxyz/common": "0.168.3",
37
37
  "bignumber.js": "^9.1.2",
38
38
  "ethers": "6.9.0",
39
39
  "isomorphic-ws": "^5.0.0",
40
40
  "ws": "^8.16.0"
41
41
  },
42
42
  "packageManager": "pnpm@8.3.1",
43
- "gitHead": "b01c55e38e69285f81bed6e9f618b20ffa90243e",
43
+ "gitHead": "0cc4ace92ab0b412f79e25976330ddac070bf272",
44
44
  "devDependencies": {
45
45
  "@types/ws": "8.5.10"
46
46
  }
@@ -10,7 +10,6 @@ import {
10
10
  ConditionalOrderType,
11
11
  scale,
12
12
  CONDITIONAL_ORDER_SIG_DEADLINE,
13
- conditionalOrderTypeNames,
14
13
  } from '@reyaxyz/common';
15
14
  import { AbiCoder } from 'ethers';
16
15
  import { Signer, JsonRpcSigner } from 'ethers';
@@ -21,7 +20,6 @@ import {
21
20
  CancelConditionalOrderResult,
22
21
  CancelSLOrderParams,
23
22
  CancelSLOrderResult,
24
- ConditionalOrderTypeInContract,
25
23
  GetConditionalOrdersHistoryForMarginAccountPaginatedParams,
26
24
  GetConditionalOrdersHistoryForMarginAccountPaginatedResult,
27
25
  GetConditionalOrdersHistoryForMarginAccountParams,
@@ -106,8 +104,8 @@ export default class ConditionalOrdersClient extends RestClient {
106
104
  params.orderId,
107
105
  );
108
106
 
109
- const uri = `/api/conditional-orders/sl/cancel-order`;
110
- const res = await this.put<StopLossOrder>(
107
+ const uri = `/api/conditional-orders/cancel-order`;
108
+ const res = await this.put<ConditionalOrder>(
111
109
  uri,
112
110
  {},
113
111
  {
@@ -115,7 +113,7 @@ export default class ConditionalOrdersClient extends RestClient {
115
113
  userSignature: signature,
116
114
  },
117
115
  );
118
- return this.mapFromStopLossToConditionalOrder(res);
116
+ return res;
119
117
  }
120
118
 
121
119
  async registerSLOrder(
@@ -155,25 +153,27 @@ export default class ConditionalOrdersClient extends RestClient {
155
153
  async registerConditionalOrder(
156
154
  params: RegisterConditionalOrderParams,
157
155
  ): Promise<RegisterConditionalOrderResult> {
158
- const inputs = await this.parseSlOrderInputs(
156
+ const inputs = await this.parseConditionalOrderInputs(
159
157
  params.signer,
160
158
  params.marginAccountId,
161
159
  params.marketId,
162
- params.stopLossPrice,
160
+ params.orderType,
161
+ params.triggerPrice,
163
162
  params.supportingParams.exchangeId,
164
163
  params.supportingParams.counterpartyAccountIds,
165
164
  );
166
165
 
167
166
  // create new entry
168
- const uri = `/api/conditional-orders/sl/create-order`;
169
- const result = await this.post<StopLossOrder>(
167
+ const uri = `/api/conditional-orders/create-order`;
168
+ const result = await this.post<ConditionalOrder>(
170
169
  uri,
171
170
  {},
172
171
  {
173
172
  accountId: params.marginAccountId,
174
173
  marketId: params.marketId,
175
174
  isLong: inputs.positionBase < 0,
176
- stopPrice: params.stopLossPrice,
175
+ orderType: params.orderType,
176
+ triggerPrice: params.triggerPrice,
177
177
  signerWallet: await params.signer.getAddress(),
178
178
  nonce: inputs.nonce.toString(),
179
179
  signature: inputs.signature,
@@ -184,7 +184,7 @@ export default class ConditionalOrdersClient extends RestClient {
184
184
  timestampMs: inputs.creationTimestampMs,
185
185
  },
186
186
  );
187
- return this.mapFromStopLossToConditionalOrder(result);
187
+ return result;
188
188
  }
189
189
 
190
190
  async updateSLOrder(
@@ -224,25 +224,27 @@ export default class ConditionalOrdersClient extends RestClient {
224
224
  async updateConditionalOrder(
225
225
  params: UpdateConditionalOrderParams,
226
226
  ): Promise<UpdateConditionalOrderResult> {
227
- const inputs = await this.parseSlOrderInputs(
227
+ const inputs = await this.parseConditionalOrderInputs(
228
228
  params.signer,
229
229
  params.marginAccountId,
230
230
  params.marketId,
231
- params.stopLossPrice,
231
+ params.orderType,
232
+ params.triggerPrice,
232
233
  params.supportingParams.exchangeId,
233
234
  params.supportingParams.counterpartyAccountIds,
234
235
  );
235
236
 
236
237
  // create new entry
237
- const uri = `/api/conditional-orders/sl/update-order`;
238
- const result = await this.post<StopLossOrder>(
238
+ const uri = `/api/conditional-orders/update-order`;
239
+ const result = await this.post<ConditionalOrder>(
239
240
  uri,
240
241
  {},
241
242
  {
242
243
  accountId: params.marginAccountId,
243
244
  marketId: params.marketId,
244
245
  isLong: inputs.positionBase < 0,
245
- stopPrice: params.stopLossPrice,
246
+ oderrType: params.orderType,
247
+ triggerPrice: params.triggerPrice,
246
248
  signerWallet: await params.signer.getAddress(),
247
249
  nonce: inputs.nonce.toString(),
248
250
  signature: inputs.signature,
@@ -253,7 +255,7 @@ export default class ConditionalOrdersClient extends RestClient {
253
255
  timestampMs: inputs.creationTimestampMs,
254
256
  },
255
257
  );
256
- return this.mapFromStopLossToConditionalOrder(result);
258
+ return result;
257
259
  }
258
260
 
259
261
  private async getPosition(
@@ -264,11 +266,12 @@ export default class ConditionalOrdersClient extends RestClient {
264
266
  return this.get<PositionEntity>(uri);
265
267
  }
266
268
 
267
- private async parseSlOrderInputs(
269
+ private async parseConditionalOrderInputs(
268
270
  signer: Signer | JsonRpcSigner,
269
271
  accountId: number,
270
272
  marketId: number,
271
- stopLossPrice: number,
273
+ orderType: ConditionalOrderType,
274
+ triggerPrice: number,
272
275
  exchangeId: number,
273
276
  counterpartyAccountIds: number[],
274
277
  ): Promise<{
@@ -291,7 +294,7 @@ export default class ConditionalOrdersClient extends RestClient {
291
294
 
292
295
  const inputs = AbiCoder.defaultAbiCoder().encode(
293
296
  ['bool', 'uint256', 'uint256'],
294
- [isLongOrder, scale(18)(stopLossPrice), orderPriceLimit],
297
+ [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],
295
298
  );
296
299
  const creationTimestampMs = Date.now();
297
300
  const nonce = createNonce(accountId, marketId, creationTimestampMs);
@@ -303,7 +306,7 @@ export default class ConditionalOrdersClient extends RestClient {
303
306
  marketId,
304
307
  exchangeId,
305
308
  counterpartyAccountIds,
306
- ConditionalOrderTypeInContract.StopLoss,
309
+ orderType,
307
310
  inputs,
308
311
  nonce,
309
312
  CONDITIONAL_ORDER_SIG_DEADLINE,
@@ -319,14 +322,59 @@ export default class ConditionalOrdersClient extends RestClient {
319
322
  };
320
323
  }
321
324
 
322
- // todo: IR deprecate after mocks are implementes
323
- private mapFromStopLossToConditionalOrder(
324
- order: StopLossOrder,
325
- ): ConditionalOrder {
325
+ // todo: IR deprecate
326
+ private async parseSlOrderInputs(
327
+ signer: Signer | JsonRpcSigner,
328
+ accountId: number,
329
+ marketId: number,
330
+ stopLossPrice: number,
331
+ exchangeId: number,
332
+ counterpartyAccountIds: number[],
333
+ ): Promise<{
334
+ signature: string;
335
+ positionBase: number;
336
+ orderPriceLimit: bigint;
337
+ nonce: bigint;
338
+ deadline: number;
339
+ creationTimestampMs: number;
340
+ }> {
341
+ const position = await this.getPosition(accountId, marketId);
342
+ const positionBase = position.base;
343
+
344
+ if (positionBase === 0) {
345
+ throw new Error('Position with no exposure');
346
+ }
347
+
348
+ const isLongOrder = positionBase < 0;
349
+ const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
350
+
351
+ const inputs = AbiCoder.defaultAbiCoder().encode(
352
+ ['bool', 'uint256', 'uint256'],
353
+ [isLongOrder, scale(18)(stopLossPrice), orderPriceLimit],
354
+ );
355
+ const creationTimestampMs = Date.now();
356
+ const nonce = createNonce(accountId, marketId, creationTimestampMs);
357
+
358
+ const signature = await signConditionalOrder(
359
+ signer,
360
+ this.reyaChainId,
361
+ accountId,
362
+ marketId,
363
+ exchangeId,
364
+ counterpartyAccountIds,
365
+ ConditionalOrderType.STOP_LOSS,
366
+ inputs,
367
+ nonce,
368
+ CONDITIONAL_ORDER_SIG_DEADLINE,
369
+ );
370
+
326
371
  return {
327
- ...order,
328
- orderType: conditionalOrderTypeNames[ConditionalOrderType.STOP_LOSS],
329
- triggerPrice: order.stopPrice,
372
+ signature,
373
+ positionBase,
374
+ orderPriceLimit,
375
+ nonce,
376
+ deadline: CONDITIONAL_ORDER_SIG_DEADLINE,
377
+ creationTimestampMs,
330
378
  };
331
379
  }
332
380
  }
@@ -2,6 +2,7 @@ import {
2
2
  StopLossOrder,
3
3
  ConditionalOrder,
4
4
  UnifiedConditionalOrderType,
5
+ ConditionalOrderType,
5
6
  } from '@reyaxyz/common';
6
7
  import { Signer, JsonRpcSigner } from 'ethers';
7
8
  import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
@@ -22,10 +23,6 @@ export type CancelConditionalOrderParams = {
22
23
 
23
24
  export type CancelConditionalOrderResult = ConditionalOrder;
24
25
 
25
- export enum ConditionalOrderTypeInContract {
26
- 'StopLoss' = 0,
27
- }
28
-
29
26
  export type ConditionalOrderDetails = {
30
27
  accountId: number;
31
28
  marketId: number;
@@ -55,7 +52,8 @@ export type RegisterSLOrderParams = {
55
52
  export type RegisterConditionalOrderParams = {
56
53
  signer: Signer | JsonRpcSigner;
57
54
  marginAccountId: MarginAccountEntity['id'];
58
- stopLossPrice: number;
55
+ triggerPrice: number;
56
+ orderType: ConditionalOrderType;
59
57
  marketId: number;
60
58
  supportingParams: OrderSupportingParams;
61
59
  };
@@ -72,7 +70,8 @@ export type UpdateSLOrderParams = {
72
70
  export type UpdateConditionalOrderParams = {
73
71
  signer: Signer | JsonRpcSigner;
74
72
  marginAccountId: MarginAccountEntity['id'];
75
- stopLossPrice: number;
73
+ triggerPrice: number;
74
+ orderType: ConditionalOrderType;
76
75
  marketId: number;
77
76
  supportingParams: OrderSupportingParams;
78
77
  };
@@ -28,6 +28,7 @@ export {
28
28
  FundingRateHistoryGranularity,
29
29
  MoneyInOutConfigurationPerTokenName,
30
30
  UnifiedConditionalOrderType,
31
+ ConditionalOrderType,
31
32
  } from '@reyaxyz/common';
32
33
  export * from './modules/account/types';
33
34
  export * from './modules/conditional-orders/types';