@reyaxyz/api-sdk 0.112.0 → 0.112.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 CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
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) |
9
+ | ![Statements](https://img.shields.io/badge/statements-1.71%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-7.75%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-0.66%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-1.72%25-red.svg?style=flat) |
10
10
 
@@ -73,18 +73,6 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
73
73
  });
74
74
  });
75
75
  };
76
- ConditionalOrdersClient.prototype.getConditionalOrdersHistoryForMarginAccountPaginated = function (params) {
77
- return __awaiter(this, void 0, void 0, function () {
78
- var uri;
79
- return __generator(this, function (_a) {
80
- uri = "/api/conditional-orders/get-orders-by-account/".concat(params.marginAccountId, "/paginated");
81
- return [2 /*return*/, this.get(uri, {
82
- page: params.page,
83
- perPage: params.perPage,
84
- })];
85
- });
86
- });
87
- };
88
76
  ConditionalOrdersClient.prototype.alreadyGaveTradePermissions = function (params) {
89
77
  return __awaiter(this, void 0, void 0, function () {
90
78
  var uri, response;
@@ -102,23 +90,6 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
102
90
  });
103
91
  });
104
92
  };
105
- ConditionalOrdersClient.prototype.cancelSLOrder = function (params) {
106
- return __awaiter(this, void 0, void 0, function () {
107
- var signature, uri;
108
- return __generator(this, function (_a) {
109
- switch (_a.label) {
110
- case 0: return [4 /*yield*/, (0, common_1.signCancelConditionalOrder)(params.signer, params.orderId)];
111
- case 1:
112
- signature = _a.sent();
113
- uri = "/api/conditional-orders/sl/cancel-order";
114
- return [2 /*return*/, this.put(uri, {}, {
115
- orderId: params.orderId,
116
- userSignature: signature,
117
- })];
118
- }
119
- });
120
- });
121
- };
122
93
  ConditionalOrdersClient.prototype.cancelConditionalOrder = function (params) {
123
94
  return __awaiter(this, void 0, void 0, function () {
124
95
  var signature, uri, res;
@@ -139,58 +110,23 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
139
110
  });
140
111
  });
141
112
  };
142
- ConditionalOrdersClient.prototype.registerSLOrder = function (params) {
143
- return __awaiter(this, void 0, void 0, function () {
144
- var inputs, uri, _a, _b;
145
- var _c;
146
- return __generator(this, function (_d) {
147
- switch (_d.label) {
148
- case 0: return [4 /*yield*/, this.parseSlOrderInputs(params.signer, params.marginAccountId, params.marketId, params.stopLossPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
149
- case 1:
150
- inputs = _d.sent();
151
- uri = "/api/conditional-orders/sl/create-order";
152
- _a = this.post;
153
- _b = [uri,
154
- {}];
155
- _c = {
156
- accountId: params.marginAccountId,
157
- marketId: params.marketId,
158
- isLong: inputs.positionBase < 0,
159
- stopPrice: params.stopLossPrice
160
- };
161
- return [4 /*yield*/, params.signer.getAddress()];
162
- case 2: return [2 /*return*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
163
- _c.nonce = inputs.nonce.toString(),
164
- _c.signature = inputs.signature,
165
- _c.deadline = inputs.deadline,
166
- _c.orderPriceLimit = inputs.orderPriceLimit.toString(),
167
- _c.exchangeId = params.supportingParams.exchangeId,
168
- _c.poolId = params.supportingParams.counterpartyAccountIds[0],
169
- _c.timestampMs = inputs.creationTimestampMs,
170
- _c)]))];
171
- }
172
- });
173
- });
174
- };
175
113
  ConditionalOrdersClient.prototype.registerConditionalOrder = function (params) {
176
114
  return __awaiter(this, void 0, void 0, function () {
177
115
  var inputs, uri, result, _a, _b;
178
116
  var _c;
179
117
  return __generator(this, function (_d) {
180
118
  switch (_d.label) {
181
- case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds,
182
- // TODO: @Costin to fix implementation
183
- params.orderSize)];
119
+ case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds, params.orderSize)];
184
120
  case 1:
185
121
  inputs = _d.sent();
186
- uri = "/api/conditional-orders/create-order";
122
+ uri = "/api/conditional-orders/create-or-update-order";
187
123
  _a = this.post;
188
124
  _b = [uri,
189
125
  {}];
190
126
  _c = {
191
127
  accountId: params.marginAccountId,
192
128
  marketId: params.marketId,
193
- isLong: inputs.positionBase < 0,
129
+ isLong: inputs.actualOrderSize > 0,
194
130
  orderType: params.orderType,
195
131
  triggerPrice: params.triggerPrice
196
132
  };
@@ -211,39 +147,6 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
211
147
  });
212
148
  });
213
149
  };
214
- ConditionalOrdersClient.prototype.updateSLOrder = function (params) {
215
- return __awaiter(this, void 0, void 0, function () {
216
- var inputs, uri, _a, _b;
217
- var _c;
218
- return __generator(this, function (_d) {
219
- switch (_d.label) {
220
- case 0: return [4 /*yield*/, this.parseSlOrderInputs(params.signer, params.marginAccountId, params.marketId, params.stopLossPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
221
- case 1:
222
- inputs = _d.sent();
223
- uri = "/api/conditional-orders/sl/update-order";
224
- _a = this.post;
225
- _b = [uri,
226
- {}];
227
- _c = {
228
- accountId: params.marginAccountId,
229
- marketId: params.marketId,
230
- isLong: inputs.positionBase < 0,
231
- stopPrice: params.stopLossPrice
232
- };
233
- return [4 /*yield*/, params.signer.getAddress()];
234
- case 2: return [2 /*return*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
235
- _c.nonce = inputs.nonce.toString(),
236
- _c.signature = inputs.signature,
237
- _c.deadline = inputs.deadline,
238
- _c.orderPriceLimit = inputs.orderPriceLimit.toString(),
239
- _c.exchangeId = params.supportingParams.exchangeId,
240
- _c.poolId = params.supportingParams.counterpartyAccountIds[0],
241
- _c.timestampMs = inputs.creationTimestampMs,
242
- _c)]))];
243
- }
244
- });
245
- });
246
- };
247
150
  ConditionalOrdersClient.prototype.updateConditionalOrder = function (params) {
248
151
  return __awaiter(this, void 0, void 0, function () {
249
152
  var inputs, uri, result, _a, _b;
@@ -253,14 +156,14 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
253
156
  case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
254
157
  case 1:
255
158
  inputs = _d.sent();
256
- uri = "/api/conditional-orders/update-order";
159
+ uri = "/api/conditional-orders/create-or-update-order";
257
160
  _a = this.post;
258
161
  _b = [uri,
259
162
  {}];
260
163
  _c = {
261
164
  accountId: params.marginAccountId,
262
165
  marketId: params.marketId,
263
- isLong: inputs.positionBase < 0,
166
+ isLong: inputs.actualOrderSize > 0,
264
167
  orderType: params.orderType,
265
168
  triggerPrice: params.triggerPrice
266
169
  };
@@ -273,6 +176,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
273
176
  _c.exchangeId = params.supportingParams.exchangeId,
274
177
  _c.poolId = params.supportingParams.counterpartyAccountIds[0],
275
178
  _c.timestampMs = inputs.creationTimestampMs,
179
+ _c.cancelOrderId = params.cancelOrderId,
276
180
  _c)]))];
277
181
  case 3:
278
182
  result = _d.sent();
@@ -292,63 +196,43 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
292
196
  };
293
197
  ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds, orderSize) {
294
198
  return __awaiter(this, void 0, void 0, function () {
295
- var position, positionBase, isLongOrder, orderPriceLimit, inputs, creationTimestampMs, nonce, signature;
199
+ var inputs, actualOrderSize, isLongOrder, orderPriceLimit, position, positionBase, creationTimestampMs, nonce, signature;
296
200
  return __generator(this, function (_a) {
297
201
  switch (_a.label) {
298
202
  case 0:
299
- // TODO: @Costin to fix implementation
300
- console.log('orderSize', orderSize);
301
- return [4 /*yield*/, this.getPosition(accountId, marketId)];
302
- case 1:
303
- position = _a.sent();
304
- positionBase = position.base;
305
- if (positionBase === 0) {
306
- throw new Error('Position with no exposure');
203
+ if (!(orderType === common_1.ConditionalOrderType.LIMIT_ORDER)) return [3 /*break*/, 1];
204
+ if (orderSize === undefined) {
205
+ throw new Error('Order base is required for limit orders');
307
206
  }
308
- isLongOrder = positionBase < 0;
207
+ if (orderSize === 0) {
208
+ throw new Error('Cannot create an empty limit order');
209
+ }
210
+ actualOrderSize = orderSize;
211
+ isLongOrder = actualOrderSize > 0;
309
212
  orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
310
- inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(triggerPrice), orderPriceLimit]);
311
- creationTimestampMs = Date.now();
312
- nonce = (0, utils_1.createNonce)(accountId, marketId, creationTimestampMs);
313
- return [4 /*yield*/, (0, common_1.signConditionalOrder)(signer, this.reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, nonce, common_1.CONDITIONAL_ORDER_SIG_DEADLINE)];
213
+ inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['int256', 'uint256'], [(0, common_1.scale)(18)(orderSize), (0, common_1.scale)(18)(triggerPrice)]);
214
+ return [3 /*break*/, 3];
215
+ case 1: return [4 /*yield*/, this.getPosition(accountId, marketId)];
314
216
  case 2:
315
- signature = _a.sent();
316
- return [2 /*return*/, {
317
- signature: signature,
318
- positionBase: positionBase,
319
- orderPriceLimit: orderPriceLimit,
320
- nonce: nonce,
321
- deadline: common_1.CONDITIONAL_ORDER_SIG_DEADLINE,
322
- creationTimestampMs: creationTimestampMs,
323
- }];
324
- }
325
- });
326
- });
327
- };
328
- // todo: IR deprecate
329
- ConditionalOrdersClient.prototype.parseSlOrderInputs = function (signer, accountId, marketId, stopLossPrice, exchangeId, counterpartyAccountIds) {
330
- return __awaiter(this, void 0, void 0, function () {
331
- var position, positionBase, isLongOrder, orderPriceLimit, inputs, creationTimestampMs, nonce, signature;
332
- return __generator(this, function (_a) {
333
- switch (_a.label) {
334
- case 0: return [4 /*yield*/, this.getPosition(accountId, marketId)];
335
- case 1:
336
217
  position = _a.sent();
337
218
  positionBase = position.base;
338
219
  if (positionBase === 0) {
339
- throw new Error('Position with no exposure');
220
+ throw new Error('Cannot create SL or TP order for closed positions');
340
221
  }
341
- isLongOrder = positionBase < 0;
222
+ actualOrderSize = -positionBase;
223
+ isLongOrder = actualOrderSize > 0;
342
224
  orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
343
- inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(stopLossPrice), orderPriceLimit]);
225
+ inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(triggerPrice), orderPriceLimit]);
226
+ _a.label = 3;
227
+ case 3:
344
228
  creationTimestampMs = Date.now();
345
229
  nonce = (0, utils_1.createNonce)(accountId, marketId, creationTimestampMs);
346
- 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)];
347
- case 2:
230
+ return [4 /*yield*/, (0, common_1.signConditionalOrder)(signer, this.reyaChainId, accountId, marketId, exchangeId, counterpartyAccountIds, orderType, inputs, nonce, common_1.CONDITIONAL_ORDER_SIG_DEADLINE)];
231
+ case 4:
348
232
  signature = _a.sent();
349
233
  return [2 /*return*/, {
350
234
  signature: signature,
351
- positionBase: positionBase,
235
+ actualOrderSize: actualOrderSize,
352
236
  orderPriceLimit: orderPriceLimit,
353
237
  nonce: nonce,
354
238
  deadline: common_1.CONDITIONAL_ORDER_SIG_DEADLINE,
@@ -1 +1 @@
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,CAAE,CAAC;wBAC/D,qBAAM,IAAI,CAAC,GAAG,C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,CAAC,EAAE,eAAe,CAAC,CACzD,CAAC;wBACI,mBAAmB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;wBACjC,KAAK,GAAG,IAAA,mBAAW,EAAC,SAAS,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;wBAElD,qBAAM,IAAA,6BAAoB,EAC1C,MAAM,EACN,IAAI,CAAC,WAAW,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,sBAAsB,EACtB,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,AA7VD,CAAqD,mBAAU,GA6V9D","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 // TODO: @Costin to fix implementation\n params.orderSize,\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 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 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 orderSize?: number,\n ): Promise<{\n signature: string;\n positionBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n orderSize?: number;\n }> {\n // TODO: @Costin to fix implementation\n console.log('orderSize', orderSize);\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
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAWyB;AACzB,iCAAkC;AAclC,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,6DAA2B,GAAjC,UACE,MAAwC;;;;;;wBAElC,GAAG,GAAG,wDAAiD,MAAM,CAAC,SAAS,CAAE,CAAC;wBAC/D,qBAAM,IAAI,CAAC,GAAG,CAAU,GAAG,CAAC,EAAA;;wBAAvC,QAAQ,GAAG,SAA4B;wBAE7C,sBAAO;gCACL,eAAe,EAAE,QAAQ;6BAC1B,EAAC;;;;KACH;IAEK,wDAAsB,GAA5B,UACE,MAAoC;;;;;4BAElB,qBAAM,IAAA,mCAA0B,EAChD,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,OAAO,CAC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GAAG,SAA2C;wBACtD,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC;wBAEnC,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;4BACvB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;wBACvE,CAAC;wBAED,eAAe,GAAG,CAAC,YAAY,CAAC;wBAChC,WAAW,GAAG,eAAe,GAAG,CAAC,CAAC;wBAClC,eAAe,GAAG,IAAA,+BAAsB,EAAC,WAAW,CAAC,CAAC;wBAEtD,MAAM,GAAG,iBAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACxC,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,EAC9B,CAAC,WAAW,EAAE,IAAA,cAAK,EAAC,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CACxD,CAAC;;;wBAGE,mBAAmB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;wBACjC,KAAK,GAAG,IAAA,mBAAW,EAAC,SAAS,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC;wBAElD,qBAAM,IAAA,6BAAoB,EAC1C,MAAM,EACN,IAAI,CAAC,WAAW,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,sBAAsB,EACtB,SAAS,EACT,MAAM,EACN,KAAK,EACL,uCAA8B,CAC/B,EAAA;;wBAXK,SAAS,GAAG,SAWjB;wBAED,sBAAO;gCACL,SAAS,WAAA;gCACT,eAAe,iBAAA;gCACf,eAAe,iBAAA;gCACf,KAAK,OAAA;gCACL,QAAQ,EAAE,uCAA8B;gCACxC,mBAAmB,qBAAA;6BACpB,EAAC;;;;KACH;IACH,8BAAC;AAAD,CAAC,AAvND,CAAqD,mBAAU,GAuN9D","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 RegisterConditionalOrderParams,\n RegisterConditionalOrderResult,\n UpdateConditionalOrderParams,\n UpdateConditionalOrderResult,\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 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 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.orderSize,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/create-or-update-order`;\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.actualOrderSize > 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 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/create-or-update-order`;\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.actualOrderSize > 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 cancelOrderId: params.cancelOrderId,\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 orderSize?: number,\n ): Promise<{\n signature: string;\n actualOrderSize: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n let inputs: string;\n let actualOrderSize: number;\n let isLongOrder: boolean;\n let orderPriceLimit: bigint;\n\n if (orderType === ConditionalOrderType.LIMIT_ORDER) {\n if (orderSize === undefined) {\n throw new Error('Order base is required for limit orders');\n }\n\n if (orderSize === 0) {\n throw new Error('Cannot create an empty limit order');\n }\n\n actualOrderSize = orderSize;\n isLongOrder = actualOrderSize > 0;\n orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [scale(18)(orderSize), 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 actualOrderSize = -positionBase;\n isLongOrder = actualOrderSize > 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 actualOrderSize,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n}\n"]}
@@ -1 +1 @@
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 orderSize?: number;\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"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n ConditionalOrder,\n UnifiedConditionalOrderType,\n ConditionalOrderType,\n} from '@reyaxyz/common';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';\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\nexport type RegisterConditionalOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n triggerPrice: number;\n orderType: ConditionalOrderType;\n marketId: number;\n supportingParams: OrderSupportingParams;\n orderSize?: number;\n};\n\nexport type UpdateConditionalOrderParams = {\n cancelOrderId: string;\n} & RegisterConditionalOrderParams;\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};\n\nexport type GetConditionalOrdersHistoryForMarginAccountResult =\n UnifiedConditionalOrderType[];\n"]}
@@ -1,19 +1,14 @@
1
1
  import { RestClient, ReyaChainId } from '@reyaxyz/common';
2
- import { AlreadyGaveTradePermissionParams, AlreadyGaveTradePermissionResult, CancelConditionalOrderParams, CancelConditionalOrderResult, CancelSLOrderParams, CancelSLOrderResult, GetConditionalOrdersHistoryForMarginAccountPaginatedParams, GetConditionalOrdersHistoryForMarginAccountPaginatedResult, GetConditionalOrdersHistoryForMarginAccountParams, GetConditionalOrdersHistoryForMarginAccountResult, RegisterConditionalOrderParams, RegisterConditionalOrderResult, RegisterSLOrderParams, RegisterSLOrderResult, UpdateConditionalOrderParams, UpdateConditionalOrderResult, UpdateSLOrderParams, UpdateSLOrderResult } from './types';
2
+ import { AlreadyGaveTradePermissionParams, AlreadyGaveTradePermissionResult, CancelConditionalOrderParams, CancelConditionalOrderResult, GetConditionalOrdersHistoryForMarginAccountParams, GetConditionalOrdersHistoryForMarginAccountResult, RegisterConditionalOrderParams, RegisterConditionalOrderResult, UpdateConditionalOrderParams, UpdateConditionalOrderResult } from './types';
3
3
  export default class ConditionalOrdersClient extends RestClient {
4
4
  private reyaChainId;
5
5
  constructor(reyaChainId: ReyaChainId, host: string);
6
6
  getConditionalOrdersHistoryForMarginAccount(params: GetConditionalOrdersHistoryForMarginAccountParams): Promise<GetConditionalOrdersHistoryForMarginAccountResult>;
7
- getConditionalOrdersHistoryForMarginAccountPaginated(params: GetConditionalOrdersHistoryForMarginAccountPaginatedParams): Promise<GetConditionalOrdersHistoryForMarginAccountPaginatedResult>;
8
7
  alreadyGaveTradePermissions(params: AlreadyGaveTradePermissionParams): Promise<AlreadyGaveTradePermissionResult>;
9
- cancelSLOrder(params: CancelSLOrderParams): Promise<CancelSLOrderResult>;
10
8
  cancelConditionalOrder(params: CancelConditionalOrderParams): Promise<CancelConditionalOrderResult>;
11
- registerSLOrder(params: RegisterSLOrderParams): Promise<RegisterSLOrderResult>;
12
9
  registerConditionalOrder(params: RegisterConditionalOrderParams): Promise<RegisterConditionalOrderResult>;
13
- updateSLOrder(params: UpdateSLOrderParams): Promise<UpdateSLOrderResult>;
14
10
  updateConditionalOrder(params: UpdateConditionalOrderParams): Promise<UpdateConditionalOrderResult>;
15
11
  private getPosition;
16
12
  private parseConditionalOrderInputs;
17
- private parseSlOrderInputs;
18
13
  }
19
14
  //# 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,EAQZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAAgC,EAChC,gCAAgC,EAChC,4BAA4B,EAC5B,4BAA4B,EAC5B,mBAAmB,EACnB,mBAAmB,EACnB,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,GAC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D,2BAA2B,CAC/B,MAAM,EAAE,gCAAgC,GACvC,OAAO,CAAC,gCAAgC,CAAC;IAStC,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,4BAA4B,CAAC;IAkBlC,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,8BAA8B,CAAC;IAoCpC,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,4BAA4B,CAAC;YAoC1B,WAAW;YAQX,2BAA2B;CAkF1C"}
@@ -1,11 +1,6 @@
1
- import { StopLossOrder, ConditionalOrder, UnifiedConditionalOrderType, ConditionalOrderType } from '@reyaxyz/common';
1
+ import { ConditionalOrder, UnifiedConditionalOrderType, ConditionalOrderType } from '@reyaxyz/common';
2
2
  import { Signer, JsonRpcSigner } from 'ethers';
3
3
  import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
4
- export type CancelSLOrderParams = {
5
- signer: Signer | JsonRpcSigner;
6
- orderId: string;
7
- };
8
- export type CancelSLOrderResult = StopLossOrder;
9
4
  export type CancelConditionalOrderParams = {
10
5
  signer: Signer | JsonRpcSigner;
11
6
  orderId: string;
@@ -26,13 +21,6 @@ export type OrderSupportingParams = {
26
21
  counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
27
22
  currentPrice: number;
28
23
  };
29
- export type RegisterSLOrderParams = {
30
- signer: Signer | JsonRpcSigner;
31
- marginAccountId: MarginAccountEntity['id'];
32
- stopLossPrice: number;
33
- marketId: number;
34
- supportingParams: OrderSupportingParams;
35
- };
36
24
  export type RegisterConditionalOrderParams = {
37
25
  signer: Signer | JsonRpcSigner;
38
26
  marginAccountId: MarginAccountEntity['id'];
@@ -42,23 +30,9 @@ export type RegisterConditionalOrderParams = {
42
30
  supportingParams: OrderSupportingParams;
43
31
  orderSize?: number;
44
32
  };
45
- export type UpdateSLOrderParams = {
46
- signer: Signer | JsonRpcSigner;
47
- marginAccountId: MarginAccountEntity['id'];
48
- stopLossPrice: number;
49
- marketId: number;
50
- supportingParams: OrderSupportingParams;
51
- };
52
33
  export type UpdateConditionalOrderParams = {
53
- signer: Signer | JsonRpcSigner;
54
- marginAccountId: MarginAccountEntity['id'];
55
- triggerPrice: number;
56
- orderType: ConditionalOrderType;
57
- marketId: number;
58
- supportingParams: OrderSupportingParams;
59
- };
60
- export type RegisterSLOrderResult = StopLossOrder;
61
- export type UpdateSLOrderResult = StopLossOrder;
34
+ cancelOrderId: string;
35
+ } & RegisterConditionalOrderParams;
62
36
  export type RegisterConditionalOrderResult = ConditionalOrder;
63
37
  export type UpdateConditionalOrderResult = ConditionalOrder;
64
38
  export type AlreadyGaveTradePermissionParams = {
@@ -72,15 +46,5 @@ export type GetConditionalOrdersHistoryForMarginAccountParams = {
72
46
  marginAccountId: MarginAccountEntity['id'];
73
47
  limit?: number;
74
48
  };
75
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {
76
- address: string;
77
- marginAccountId: MarginAccountEntity['id'];
78
- page: number;
79
- perPage: number;
80
- };
81
49
  export type GetConditionalOrdersHistoryForMarginAccountResult = UnifiedConditionalOrderType[];
82
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {
83
- data: UnifiedConditionalOrderType[];
84
- totalCount: number;
85
- };
86
50
  //# sourceMappingURL=types.d.ts.map
@@ -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,EAC3B,oBAAoB,EACrB,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,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EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,oBAAoB,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,qBAAqB,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,8BAA8B,CAAC;AAEnC,MAAM,MAAM,8BAA8B,GAAG,gBAAgB,CAAC;AAC9D,MAAM,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;AAE5D,MAAM,MAAM,gCAAgC,GAAG;IAC7C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,iDAAiD,GAAG;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iDAAiD,GAC3D,2BAA2B,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/api-sdk",
3
- "version": "0.112.0",
3
+ "version": "0.112.1",
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.172.0",
36
+ "@reyaxyz/common": "0.172.1",
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": "f442b34d02817bd553e3169c41b146bb06474086",
43
+ "gitHead": "c7053b78e27781ced35be45a7f5b663f2a2592c8",
44
44
  "devDependencies": {
45
45
  "@types/ws": "8.5.10"
46
46
  }
@@ -5,7 +5,6 @@ import {
5
5
  ReyaChainId,
6
6
  signConditionalOrder,
7
7
  signCancelConditionalOrder,
8
- StopLossOrder,
9
8
  ConditionalOrder,
10
9
  ConditionalOrderType,
11
10
  scale,
@@ -18,20 +17,12 @@ import {
18
17
  AlreadyGaveTradePermissionResult,
19
18
  CancelConditionalOrderParams,
20
19
  CancelConditionalOrderResult,
21
- CancelSLOrderParams,
22
- CancelSLOrderResult,
23
- GetConditionalOrdersHistoryForMarginAccountPaginatedParams,
24
- GetConditionalOrdersHistoryForMarginAccountPaginatedResult,
25
20
  GetConditionalOrdersHistoryForMarginAccountParams,
26
21
  GetConditionalOrdersHistoryForMarginAccountResult,
27
22
  RegisterConditionalOrderParams,
28
23
  RegisterConditionalOrderResult,
29
- RegisterSLOrderParams,
30
- RegisterSLOrderResult,
31
24
  UpdateConditionalOrderParams,
32
25
  UpdateConditionalOrderResult,
33
- UpdateSLOrderParams,
34
- UpdateSLOrderResult,
35
26
  } from './types';
36
27
  import { createNonce } from './utils';
37
28
 
@@ -53,19 +44,6 @@ export default class ConditionalOrdersClient extends RestClient {
53
44
  });
54
45
  }
55
46
 
56
- async getConditionalOrdersHistoryForMarginAccountPaginated(
57
- params: GetConditionalOrdersHistoryForMarginAccountPaginatedParams,
58
- ): Promise<GetConditionalOrdersHistoryForMarginAccountPaginatedResult> {
59
- const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}/paginated`;
60
- return this.get<GetConditionalOrdersHistoryForMarginAccountPaginatedResult>(
61
- uri,
62
- {
63
- page: params.page,
64
- perPage: params.perPage,
65
- },
66
- );
67
- }
68
-
69
47
  async alreadyGaveTradePermissions(
70
48
  params: AlreadyGaveTradePermissionParams,
71
49
  ): Promise<AlreadyGaveTradePermissionResult> {
@@ -77,25 +55,6 @@ export default class ConditionalOrdersClient extends RestClient {
77
55
  };
78
56
  }
79
57
 
80
- async cancelSLOrder(
81
- params: CancelSLOrderParams,
82
- ): Promise<CancelSLOrderResult> {
83
- const signature = await signCancelConditionalOrder(
84
- params.signer,
85
- params.orderId,
86
- );
87
-
88
- const uri = `/api/conditional-orders/sl/cancel-order`;
89
- return this.put<StopLossOrder>(
90
- uri,
91
- {},
92
- {
93
- orderId: params.orderId,
94
- userSignature: signature,
95
- },
96
- );
97
- }
98
-
99
58
  async cancelConditionalOrder(
100
59
  params: CancelConditionalOrderParams,
101
60
  ): Promise<CancelConditionalOrderResult> {
@@ -116,40 +75,6 @@ export default class ConditionalOrdersClient extends RestClient {
116
75
  return res;
117
76
  }
118
77
 
119
- async registerSLOrder(
120
- params: RegisterSLOrderParams,
121
- ): Promise<RegisterSLOrderResult> {
122
- const inputs = await this.parseSlOrderInputs(
123
- params.signer,
124
- params.marginAccountId,
125
- params.marketId,
126
- params.stopLossPrice,
127
- params.supportingParams.exchangeId,
128
- params.supportingParams.counterpartyAccountIds,
129
- );
130
-
131
- // create new entry
132
- const uri = `/api/conditional-orders/sl/create-order`;
133
- return this.post<StopLossOrder>(
134
- uri,
135
- {},
136
- {
137
- accountId: params.marginAccountId,
138
- marketId: params.marketId,
139
- isLong: inputs.positionBase < 0,
140
- stopPrice: params.stopLossPrice,
141
- signerWallet: await params.signer.getAddress(),
142
- nonce: inputs.nonce.toString(),
143
- signature: inputs.signature,
144
- deadline: inputs.deadline,
145
- orderPriceLimit: inputs.orderPriceLimit.toString(),
146
- exchangeId: params.supportingParams.exchangeId,
147
- poolId: params.supportingParams.counterpartyAccountIds[0],
148
- timestampMs: inputs.creationTimestampMs,
149
- },
150
- );
151
- }
152
-
153
78
  async registerConditionalOrder(
154
79
  params: RegisterConditionalOrderParams,
155
80
  ): Promise<RegisterConditionalOrderResult> {
@@ -161,19 +86,18 @@ export default class ConditionalOrdersClient extends RestClient {
161
86
  params.triggerPrice,
162
87
  params.supportingParams.exchangeId,
163
88
  params.supportingParams.counterpartyAccountIds,
164
- // TODO: @Costin to fix implementation
165
89
  params.orderSize,
166
90
  );
167
91
 
168
92
  // create new entry
169
- const uri = `/api/conditional-orders/create-order`;
93
+ const uri = `/api/conditional-orders/create-or-update-order`;
170
94
  const result = await this.post<ConditionalOrder>(
171
95
  uri,
172
96
  {},
173
97
  {
174
98
  accountId: params.marginAccountId,
175
99
  marketId: params.marketId,
176
- isLong: inputs.positionBase < 0,
100
+ isLong: inputs.actualOrderSize > 0,
177
101
  orderType: params.orderType,
178
102
  triggerPrice: params.triggerPrice,
179
103
  signerWallet: await params.signer.getAddress(),
@@ -189,40 +113,6 @@ export default class ConditionalOrdersClient extends RestClient {
189
113
  return result;
190
114
  }
191
115
 
192
- async updateSLOrder(
193
- params: UpdateSLOrderParams,
194
- ): Promise<UpdateSLOrderResult> {
195
- const inputs = await this.parseSlOrderInputs(
196
- params.signer,
197
- params.marginAccountId,
198
- params.marketId,
199
- params.stopLossPrice,
200
- params.supportingParams.exchangeId,
201
- params.supportingParams.counterpartyAccountIds,
202
- );
203
-
204
- // create new entry
205
- const uri = `/api/conditional-orders/sl/update-order`;
206
- return this.post<StopLossOrder>(
207
- uri,
208
- {},
209
- {
210
- accountId: params.marginAccountId,
211
- marketId: params.marketId,
212
- isLong: inputs.positionBase < 0,
213
- stopPrice: params.stopLossPrice,
214
- signerWallet: await params.signer.getAddress(),
215
- nonce: inputs.nonce.toString(),
216
- signature: inputs.signature,
217
- deadline: inputs.deadline,
218
- orderPriceLimit: inputs.orderPriceLimit.toString(),
219
- exchangeId: params.supportingParams.exchangeId,
220
- poolId: params.supportingParams.counterpartyAccountIds[0],
221
- timestampMs: inputs.creationTimestampMs,
222
- },
223
- );
224
- }
225
-
226
116
  async updateConditionalOrder(
227
117
  params: UpdateConditionalOrderParams,
228
118
  ): Promise<UpdateConditionalOrderResult> {
@@ -237,14 +127,14 @@ export default class ConditionalOrdersClient extends RestClient {
237
127
  );
238
128
 
239
129
  // create new entry
240
- const uri = `/api/conditional-orders/update-order`;
130
+ const uri = `/api/conditional-orders/create-or-update-order`;
241
131
  const result = await this.post<ConditionalOrder>(
242
132
  uri,
243
133
  {},
244
134
  {
245
135
  accountId: params.marginAccountId,
246
136
  marketId: params.marketId,
247
- isLong: inputs.positionBase < 0,
137
+ isLong: inputs.actualOrderSize > 0,
248
138
  orderType: params.orderType,
249
139
  triggerPrice: params.triggerPrice,
250
140
  signerWallet: await params.signer.getAddress(),
@@ -255,6 +145,7 @@ export default class ConditionalOrdersClient extends RestClient {
255
145
  exchangeId: params.supportingParams.exchangeId,
256
146
  poolId: params.supportingParams.counterpartyAccountIds[0],
257
147
  timestampMs: inputs.creationTimestampMs,
148
+ cancelOrderId: params.cancelOrderId,
258
149
  },
259
150
  );
260
151
  return result;
@@ -279,30 +170,52 @@ export default class ConditionalOrdersClient extends RestClient {
279
170
  orderSize?: number,
280
171
  ): Promise<{
281
172
  signature: string;
282
- positionBase: number;
173
+ actualOrderSize: number;
283
174
  orderPriceLimit: bigint;
284
175
  nonce: bigint;
285
176
  deadline: number;
286
177
  creationTimestampMs: number;
287
- orderSize?: number;
288
178
  }> {
289
- // TODO: @Costin to fix implementation
290
- console.log('orderSize', orderSize);
291
-
292
- const position = await this.getPosition(accountId, marketId);
293
- const positionBase = position.base;
294
-
295
- if (positionBase === 0) {
296
- throw new Error('Position with no exposure');
179
+ let inputs: string;
180
+ let actualOrderSize: number;
181
+ let isLongOrder: boolean;
182
+ let orderPriceLimit: bigint;
183
+
184
+ if (orderType === ConditionalOrderType.LIMIT_ORDER) {
185
+ if (orderSize === undefined) {
186
+ throw new Error('Order base is required for limit orders');
187
+ }
188
+
189
+ if (orderSize === 0) {
190
+ throw new Error('Cannot create an empty limit order');
191
+ }
192
+
193
+ actualOrderSize = orderSize;
194
+ isLongOrder = actualOrderSize > 0;
195
+ orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
196
+
197
+ inputs = AbiCoder.defaultAbiCoder().encode(
198
+ ['int256', 'uint256'],
199
+ [scale(18)(orderSize), scale(18)(triggerPrice)],
200
+ );
201
+ } else {
202
+ const position = await this.getPosition(accountId, marketId);
203
+ const positionBase = position.base;
204
+
205
+ if (positionBase === 0) {
206
+ throw new Error('Cannot create SL or TP order for closed positions');
207
+ }
208
+
209
+ actualOrderSize = -positionBase;
210
+ isLongOrder = actualOrderSize > 0;
211
+ orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
212
+
213
+ inputs = AbiCoder.defaultAbiCoder().encode(
214
+ ['bool', 'uint256', 'uint256'],
215
+ [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],
216
+ );
297
217
  }
298
218
 
299
- const isLongOrder = positionBase < 0;
300
- const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
301
-
302
- const inputs = AbiCoder.defaultAbiCoder().encode(
303
- ['bool', 'uint256', 'uint256'],
304
- [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],
305
- );
306
219
  const creationTimestampMs = Date.now();
307
220
  const nonce = createNonce(accountId, marketId, creationTimestampMs);
308
221
 
@@ -321,63 +234,7 @@ export default class ConditionalOrdersClient extends RestClient {
321
234
 
322
235
  return {
323
236
  signature,
324
- positionBase,
325
- orderPriceLimit,
326
- nonce,
327
- deadline: CONDITIONAL_ORDER_SIG_DEADLINE,
328
- creationTimestampMs,
329
- };
330
- }
331
-
332
- // todo: IR deprecate
333
- private async parseSlOrderInputs(
334
- signer: Signer | JsonRpcSigner,
335
- accountId: number,
336
- marketId: number,
337
- stopLossPrice: number,
338
- exchangeId: number,
339
- counterpartyAccountIds: number[],
340
- ): Promise<{
341
- signature: string;
342
- positionBase: number;
343
- orderPriceLimit: bigint;
344
- nonce: bigint;
345
- deadline: number;
346
- creationTimestampMs: number;
347
- }> {
348
- const position = await this.getPosition(accountId, marketId);
349
- const positionBase = position.base;
350
-
351
- if (positionBase === 0) {
352
- throw new Error('Position with no exposure');
353
- }
354
-
355
- const isLongOrder = positionBase < 0;
356
- const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
357
-
358
- const inputs = AbiCoder.defaultAbiCoder().encode(
359
- ['bool', 'uint256', 'uint256'],
360
- [isLongOrder, scale(18)(stopLossPrice), orderPriceLimit],
361
- );
362
- const creationTimestampMs = Date.now();
363
- const nonce = createNonce(accountId, marketId, creationTimestampMs);
364
-
365
- const signature = await signConditionalOrder(
366
- signer,
367
- this.reyaChainId,
368
- accountId,
369
- marketId,
370
- exchangeId,
371
- counterpartyAccountIds,
372
- ConditionalOrderType.STOP_LOSS,
373
- inputs,
374
- nonce,
375
- CONDITIONAL_ORDER_SIG_DEADLINE,
376
- );
377
-
378
- return {
379
- signature,
380
- positionBase,
237
+ actualOrderSize,
381
238
  orderPriceLimit,
382
239
  nonce,
383
240
  deadline: CONDITIONAL_ORDER_SIG_DEADLINE,
@@ -1,5 +1,4 @@
1
1
  import {
2
- StopLossOrder,
3
2
  ConditionalOrder,
4
3
  UnifiedConditionalOrderType,
5
4
  ConditionalOrderType,
@@ -7,15 +6,6 @@ import {
7
6
  import { Signer, JsonRpcSigner } from 'ethers';
8
7
  import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
9
8
 
10
- // todo: IR to deprecate
11
- export type CancelSLOrderParams = {
12
- signer: Signer | JsonRpcSigner;
13
- orderId: string;
14
- };
15
-
16
- // todo: IR to deprecate
17
- export type CancelSLOrderResult = StopLossOrder;
18
-
19
9
  export type CancelConditionalOrderParams = {
20
10
  signer: Signer | JsonRpcSigner;
21
11
  orderId: string;
@@ -40,15 +30,6 @@ export type OrderSupportingParams = {
40
30
  currentPrice: number;
41
31
  };
42
32
 
43
- // todo: IR to deprecate
44
- export type RegisterSLOrderParams = {
45
- signer: Signer | JsonRpcSigner;
46
- marginAccountId: MarginAccountEntity['id'];
47
- stopLossPrice: number;
48
- marketId: number;
49
- supportingParams: OrderSupportingParams;
50
- };
51
-
52
33
  export type RegisterConditionalOrderParams = {
53
34
  signer: Signer | JsonRpcSigner;
54
35
  marginAccountId: MarginAccountEntity['id'];
@@ -59,27 +40,9 @@ export type RegisterConditionalOrderParams = {
59
40
  orderSize?: number;
60
41
  };
61
42
 
62
- // todo: IR to deprecate
63
- export type UpdateSLOrderParams = {
64
- signer: Signer | JsonRpcSigner;
65
- marginAccountId: MarginAccountEntity['id'];
66
- stopLossPrice: number;
67
- marketId: number;
68
- supportingParams: OrderSupportingParams;
69
- };
70
-
71
43
  export type UpdateConditionalOrderParams = {
72
- signer: Signer | JsonRpcSigner;
73
- marginAccountId: MarginAccountEntity['id'];
74
- triggerPrice: number;
75
- orderType: ConditionalOrderType;
76
- marketId: number;
77
- supportingParams: OrderSupportingParams;
78
- };
79
-
80
- // todo: IR to deprecate
81
- export type RegisterSLOrderResult = StopLossOrder;
82
- export type UpdateSLOrderResult = StopLossOrder;
44
+ cancelOrderId: string;
45
+ } & RegisterConditionalOrderParams;
83
46
 
84
47
  export type RegisterConditionalOrderResult = ConditionalOrder;
85
48
  export type UpdateConditionalOrderResult = ConditionalOrder;
@@ -98,16 +61,6 @@ export type GetConditionalOrdersHistoryForMarginAccountParams = {
98
61
  marginAccountId: MarginAccountEntity['id'];
99
62
  limit?: number;
100
63
  };
101
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {
102
- address: string;
103
- marginAccountId: MarginAccountEntity['id'];
104
- page: number;
105
- perPage: number;
106
- };
107
64
 
108
65
  export type GetConditionalOrdersHistoryForMarginAccountResult =
109
66
  UnifiedConditionalOrderType[];
110
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {
111
- data: UnifiedConditionalOrderType[];
112
- totalCount: number;
113
- };