@reyaxyz/api-sdk 0.111.23 → 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,56 +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)];
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)];
182
120
  case 1:
183
121
  inputs = _d.sent();
184
- uri = "/api/conditional-orders/create-order";
122
+ uri = "/api/conditional-orders/create-or-update-order";
185
123
  _a = this.post;
186
124
  _b = [uri,
187
125
  {}];
188
126
  _c = {
189
127
  accountId: params.marginAccountId,
190
128
  marketId: params.marketId,
191
- isLong: inputs.positionBase < 0,
129
+ isLong: inputs.actualOrderSize > 0,
192
130
  orderType: params.orderType,
193
131
  triggerPrice: params.triggerPrice
194
132
  };
@@ -209,39 +147,6 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
209
147
  });
210
148
  });
211
149
  };
212
- ConditionalOrdersClient.prototype.updateSLOrder = function (params) {
213
- return __awaiter(this, void 0, void 0, function () {
214
- var inputs, uri, _a, _b;
215
- var _c;
216
- return __generator(this, function (_d) {
217
- switch (_d.label) {
218
- case 0: return [4 /*yield*/, this.parseSlOrderInputs(params.signer, params.marginAccountId, params.marketId, params.stopLossPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
219
- case 1:
220
- inputs = _d.sent();
221
- uri = "/api/conditional-orders/sl/update-order";
222
- _a = this.post;
223
- _b = [uri,
224
- {}];
225
- _c = {
226
- accountId: params.marginAccountId,
227
- marketId: params.marketId,
228
- isLong: inputs.positionBase < 0,
229
- stopPrice: params.stopLossPrice
230
- };
231
- return [4 /*yield*/, params.signer.getAddress()];
232
- case 2: return [2 /*return*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
233
- _c.nonce = inputs.nonce.toString(),
234
- _c.signature = inputs.signature,
235
- _c.deadline = inputs.deadline,
236
- _c.orderPriceLimit = inputs.orderPriceLimit.toString(),
237
- _c.exchangeId = params.supportingParams.exchangeId,
238
- _c.poolId = params.supportingParams.counterpartyAccountIds[0],
239
- _c.timestampMs = inputs.creationTimestampMs,
240
- _c)]))];
241
- }
242
- });
243
- });
244
- };
245
150
  ConditionalOrdersClient.prototype.updateConditionalOrder = function (params) {
246
151
  return __awaiter(this, void 0, void 0, function () {
247
152
  var inputs, uri, result, _a, _b;
@@ -251,14 +156,14 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
251
156
  case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
252
157
  case 1:
253
158
  inputs = _d.sent();
254
- uri = "/api/conditional-orders/update-order";
159
+ uri = "/api/conditional-orders/create-or-update-order";
255
160
  _a = this.post;
256
161
  _b = [uri,
257
162
  {}];
258
163
  _c = {
259
164
  accountId: params.marginAccountId,
260
165
  marketId: params.marketId,
261
- isLong: inputs.positionBase < 0,
166
+ isLong: inputs.actualOrderSize > 0,
262
167
  orderType: params.orderType,
263
168
  triggerPrice: params.triggerPrice
264
169
  };
@@ -271,6 +176,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
271
176
  _c.exchangeId = params.supportingParams.exchangeId,
272
177
  _c.poolId = params.supportingParams.counterpartyAccountIds[0],
273
178
  _c.timestampMs = inputs.creationTimestampMs,
179
+ _c.cancelOrderId = params.cancelOrderId,
274
180
  _c)]))];
275
181
  case 3:
276
182
  result = _d.sent();
@@ -288,62 +194,45 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
288
194
  });
289
195
  });
290
196
  };
291
- ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds) {
197
+ ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds, orderSize) {
292
198
  return __awaiter(this, void 0, void 0, function () {
293
- var position, positionBase, isLongOrder, orderPriceLimit, inputs, creationTimestampMs, nonce, signature;
199
+ var inputs, actualOrderSize, isLongOrder, orderPriceLimit, position, positionBase, creationTimestampMs, nonce, signature;
294
200
  return __generator(this, function (_a) {
295
201
  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');
202
+ case 0:
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');
206
+ }
207
+ if (orderSize === 0) {
208
+ throw new Error('Cannot create an empty limit order');
302
209
  }
303
- isLongOrder = positionBase < 0;
210
+ actualOrderSize = orderSize;
211
+ isLongOrder = actualOrderSize > 0;
304
212
  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)];
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)];
309
216
  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
324
- ConditionalOrdersClient.prototype.parseSlOrderInputs = function (signer, accountId, marketId, stopLossPrice, exchangeId, counterpartyAccountIds) {
325
- return __awaiter(this, void 0, void 0, function () {
326
- var position, positionBase, isLongOrder, orderPriceLimit, inputs, creationTimestampMs, nonce, signature;
327
- return __generator(this, function (_a) {
328
- switch (_a.label) {
329
- case 0: return [4 /*yield*/, this.getPosition(accountId, marketId)];
330
- case 1:
331
217
  position = _a.sent();
332
218
  positionBase = position.base;
333
219
  if (positionBase === 0) {
334
- throw new Error('Position with no exposure');
220
+ throw new Error('Cannot create SL or TP order for closed positions');
335
221
  }
336
- isLongOrder = positionBase < 0;
222
+ actualOrderSize = -positionBase;
223
+ isLongOrder = actualOrderSize > 0;
337
224
  orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
338
- 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:
339
228
  creationTimestampMs = Date.now();
340
229
  nonce = (0, utils_1.createNonce)(accountId, marketId, creationTimestampMs);
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)];
342
- 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:
343
232
  signature = _a.sent();
344
233
  return [2 /*return*/, {
345
234
  signature: signature,
346
- positionBase: positionBase,
235
+ actualOrderSize: actualOrderSize,
347
236
  orderPriceLimit: orderPriceLimit,
348
237
  nonce: nonce,
349
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/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AAA,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 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 ): 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
+ {"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,CACf,EAAA;;wBAHK,SAAS,GAAG,SAGjB;wBAEK,GAAG,GAAG,sCAAsC,CAAC;wBACvC,qBAAM,IAAI,CAAC,GAAG,CACxB,GAAG,EACH,EAAE,EACF;gCACE,OAAO,EAAE,MAAM,CAAC,OAAO;gCACvB,aAAa,EAAE,SAAS;6BACzB,CACF,EA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AChC,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};\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,GACxD,OAAO,CAAC,iDAAiD,CAAC;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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AAC;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'];
@@ -40,24 +28,11 @@ export type RegisterConditionalOrderParams = {
40
28
  orderType: ConditionalOrderType;
41
29
  marketId: number;
42
30
  supportingParams: OrderSupportingParams;
43
- };
44
- export type UpdateSLOrderParams = {
45
- signer: Signer | JsonRpcSigner;
46
- marginAccountId: MarginAccountEntity['id'];
47
- stopLossPrice: number;
48
- marketId: number;
49
- supportingParams: OrderSupportingParams;
31
+ orderSize?: number;
50
32
  };
51
33
  export type UpdateConditionalOrderParams = {
52
- signer: Signer | JsonRpcSigner;
53
- marginAccountId: MarginAccountEntity['id'];
54
- triggerPrice: number;
55
- orderType: ConditionalOrderType;
56
- marketId: number;
57
- supportingParams: OrderSupportingParams;
58
- };
59
- export type RegisterSLOrderResult = StopLossOrder;
60
- export type UpdateSLOrderResult = StopLossOrder;
34
+ cancelOrderId: string;
35
+ } & RegisterConditionalOrderParams;
61
36
  export type RegisterConditionalOrderResult = ConditionalOrder;
62
37
  export type UpdateConditionalOrderResult = ConditionalOrder;
63
38
  export type AlreadyGaveTradePermissionParams = {
@@ -71,15 +46,5 @@ export type GetConditionalOrdersHistoryForMarginAccountParams = {
71
46
  marginAccountId: MarginAccountEntity['id'];
72
47
  limit?: number;
73
48
  };
74
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {
75
- address: string;
76
- marginAccountId: MarginAccountEntity['id'];
77
- page: number;
78
- perPage: number;
79
- };
80
49
  export type GetConditionalOrdersHistoryForMarginAccountResult = UnifiedConditionalOrderType[];
81
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {
82
- data: UnifiedConditionalOrderType[];
83
- totalCount: number;
84
- };
85
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,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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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.111.23",
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.171.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": "0d16f5b523d33847de85d3abd8e6d0cceb510c46",
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,17 +86,18 @@ export default class ConditionalOrdersClient extends RestClient {
161
86
  params.triggerPrice,
162
87
  params.supportingParams.exchangeId,
163
88
  params.supportingParams.counterpartyAccountIds,
89
+ params.orderSize,
164
90
  );
165
91
 
166
92
  // create new entry
167
- const uri = `/api/conditional-orders/create-order`;
93
+ const uri = `/api/conditional-orders/create-or-update-order`;
168
94
  const result = await this.post<ConditionalOrder>(
169
95
  uri,
170
96
  {},
171
97
  {
172
98
  accountId: params.marginAccountId,
173
99
  marketId: params.marketId,
174
- isLong: inputs.positionBase < 0,
100
+ isLong: inputs.actualOrderSize > 0,
175
101
  orderType: params.orderType,
176
102
  triggerPrice: params.triggerPrice,
177
103
  signerWallet: await params.signer.getAddress(),
@@ -187,40 +113,6 @@ export default class ConditionalOrdersClient extends RestClient {
187
113
  return result;
188
114
  }
189
115
 
190
- async updateSLOrder(
191
- params: UpdateSLOrderParams,
192
- ): Promise<UpdateSLOrderResult> {
193
- const inputs = await this.parseSlOrderInputs(
194
- params.signer,
195
- params.marginAccountId,
196
- params.marketId,
197
- params.stopLossPrice,
198
- params.supportingParams.exchangeId,
199
- params.supportingParams.counterpartyAccountIds,
200
- );
201
-
202
- // create new entry
203
- const uri = `/api/conditional-orders/sl/update-order`;
204
- return this.post<StopLossOrder>(
205
- uri,
206
- {},
207
- {
208
- accountId: params.marginAccountId,
209
- marketId: params.marketId,
210
- isLong: inputs.positionBase < 0,
211
- stopPrice: params.stopLossPrice,
212
- signerWallet: await params.signer.getAddress(),
213
- nonce: inputs.nonce.toString(),
214
- signature: inputs.signature,
215
- deadline: inputs.deadline,
216
- orderPriceLimit: inputs.orderPriceLimit.toString(),
217
- exchangeId: params.supportingParams.exchangeId,
218
- poolId: params.supportingParams.counterpartyAccountIds[0],
219
- timestampMs: inputs.creationTimestampMs,
220
- },
221
- );
222
- }
223
-
224
116
  async updateConditionalOrder(
225
117
  params: UpdateConditionalOrderParams,
226
118
  ): Promise<UpdateConditionalOrderResult> {
@@ -235,14 +127,14 @@ export default class ConditionalOrdersClient extends RestClient {
235
127
  );
236
128
 
237
129
  // create new entry
238
- const uri = `/api/conditional-orders/update-order`;
130
+ const uri = `/api/conditional-orders/create-or-update-order`;
239
131
  const result = await this.post<ConditionalOrder>(
240
132
  uri,
241
133
  {},
242
134
  {
243
135
  accountId: params.marginAccountId,
244
136
  marketId: params.marketId,
245
- isLong: inputs.positionBase < 0,
137
+ isLong: inputs.actualOrderSize > 0,
246
138
  orderType: params.orderType,
247
139
  triggerPrice: params.triggerPrice,
248
140
  signerWallet: await params.signer.getAddress(),
@@ -253,6 +145,7 @@ export default class ConditionalOrdersClient extends RestClient {
253
145
  exchangeId: params.supportingParams.exchangeId,
254
146
  poolId: params.supportingParams.counterpartyAccountIds[0],
255
147
  timestampMs: inputs.creationTimestampMs,
148
+ cancelOrderId: params.cancelOrderId,
256
149
  },
257
150
  );
258
151
  return result;
@@ -274,28 +167,55 @@ export default class ConditionalOrdersClient extends RestClient {
274
167
  triggerPrice: number,
275
168
  exchangeId: number,
276
169
  counterpartyAccountIds: number[],
170
+ orderSize?: number,
277
171
  ): Promise<{
278
172
  signature: string;
279
- positionBase: number;
173
+ actualOrderSize: number;
280
174
  orderPriceLimit: bigint;
281
175
  nonce: bigint;
282
176
  deadline: number;
283
177
  creationTimestampMs: number;
284
178
  }> {
285
- const position = await this.getPosition(accountId, marketId);
286
- const positionBase = position.base;
287
-
288
- if (positionBase === 0) {
289
- 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
+ );
290
217
  }
291
218
 
292
- const isLongOrder = positionBase < 0;
293
- const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
294
-
295
- const inputs = AbiCoder.defaultAbiCoder().encode(
296
- ['bool', 'uint256', 'uint256'],
297
- [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],
298
- );
299
219
  const creationTimestampMs = Date.now();
300
220
  const nonce = createNonce(accountId, marketId, creationTimestampMs);
301
221
 
@@ -314,63 +234,7 @@ export default class ConditionalOrdersClient extends RestClient {
314
234
 
315
235
  return {
316
236
  signature,
317
- positionBase,
318
- orderPriceLimit,
319
- nonce,
320
- deadline: CONDITIONAL_ORDER_SIG_DEADLINE,
321
- creationTimestampMs,
322
- };
323
- }
324
-
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
-
371
- return {
372
- signature,
373
- positionBase,
237
+ actualOrderSize,
374
238
  orderPriceLimit,
375
239
  nonce,
376
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'];
@@ -56,29 +37,12 @@ export type RegisterConditionalOrderParams = {
56
37
  orderType: ConditionalOrderType;
57
38
  marketId: number;
58
39
  supportingParams: OrderSupportingParams;
59
- };
60
-
61
- // todo: IR to deprecate
62
- export type UpdateSLOrderParams = {
63
- signer: Signer | JsonRpcSigner;
64
- marginAccountId: MarginAccountEntity['id'];
65
- stopLossPrice: number;
66
- marketId: number;
67
- supportingParams: OrderSupportingParams;
40
+ orderSize?: number;
68
41
  };
69
42
 
70
43
  export type UpdateConditionalOrderParams = {
71
- signer: Signer | JsonRpcSigner;
72
- marginAccountId: MarginAccountEntity['id'];
73
- triggerPrice: number;
74
- orderType: ConditionalOrderType;
75
- marketId: number;
76
- supportingParams: OrderSupportingParams;
77
- };
78
-
79
- // todo: IR to deprecate
80
- export type RegisterSLOrderResult = StopLossOrder;
81
- export type UpdateSLOrderResult = StopLossOrder;
44
+ cancelOrderId: string;
45
+ } & RegisterConditionalOrderParams;
82
46
 
83
47
  export type RegisterConditionalOrderResult = ConditionalOrder;
84
48
  export type UpdateConditionalOrderResult = ConditionalOrder;
@@ -97,16 +61,6 @@ export type GetConditionalOrdersHistoryForMarginAccountParams = {
97
61
  marginAccountId: MarginAccountEntity['id'];
98
62
  limit?: number;
99
63
  };
100
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {
101
- address: string;
102
- marginAccountId: MarginAccountEntity['id'];
103
- page: number;
104
- perPage: number;
105
- };
106
64
 
107
65
  export type GetConditionalOrdersHistoryForMarginAccountResult =
108
66
  UnifiedConditionalOrderType[];
109
- export type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {
110
- data: UnifiedConditionalOrderType[];
111
- totalCount: number;
112
- };