@reyaxyz/api-sdk 0.112.1 → 0.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,7 +116,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
116
116
  var _c;
117
117
  return __generator(this, function (_d) {
118
118
  switch (_d.label) {
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)];
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.amountInBase)];
120
120
  case 1:
121
121
  inputs = _d.sent();
122
122
  uri = "/api/conditional-orders/create-or-update-order";
@@ -125,20 +125,21 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
125
125
  {}];
126
126
  _c = {
127
127
  accountId: params.marginAccountId,
128
+ poolId: params.supportingParams.counterpartyAccountIds[0],
129
+ deadline: inputs.deadline,
130
+ exchangeId: params.supportingParams.exchangeId,
131
+ isLong: inputs.actualAmountInBase > 0,
128
132
  marketId: params.marketId,
129
- isLong: inputs.actualOrderSize > 0,
133
+ nonce: inputs.nonce.toString(),
134
+ orderPriceLimit: inputs.orderPriceLimit.toString(),
130
135
  orderType: params.orderType,
131
- triggerPrice: params.triggerPrice
136
+ signature: inputs.signature
132
137
  };
133
138
  return [4 /*yield*/, params.signer.getAddress()];
134
139
  case 2: return [4 /*yield*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
135
- _c.nonce = inputs.nonce.toString(),
136
- _c.signature = inputs.signature,
137
- _c.deadline = inputs.deadline,
138
- _c.orderPriceLimit = inputs.orderPriceLimit.toString(),
139
- _c.exchangeId = params.supportingParams.exchangeId,
140
- _c.poolId = params.supportingParams.counterpartyAccountIds[0],
141
140
  _c.timestampMs = inputs.creationTimestampMs,
141
+ _c.triggerPrice = params.triggerPrice,
142
+ _c.orderBase = params.amountInBase,
142
143
  _c)]))];
143
144
  case 3:
144
145
  result = _d.sent();
@@ -153,7 +154,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
153
154
  var _c;
154
155
  return __generator(this, function (_d) {
155
156
  switch (_d.label) {
156
- case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds)];
157
+ case 0: return [4 /*yield*/, this.parseConditionalOrderInputs(params.signer, params.marginAccountId, params.marketId, params.orderType, params.triggerPrice, params.supportingParams.exchangeId, params.supportingParams.counterpartyAccountIds, params.amountInBase)];
157
158
  case 1:
158
159
  inputs = _d.sent();
159
160
  uri = "/api/conditional-orders/create-or-update-order";
@@ -162,21 +163,22 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
162
163
  {}];
163
164
  _c = {
164
165
  accountId: params.marginAccountId,
166
+ poolId: params.supportingParams.counterpartyAccountIds[0],
167
+ deadline: inputs.deadline,
168
+ exchangeId: params.supportingParams.exchangeId,
169
+ isLong: inputs.actualAmountInBase > 0,
165
170
  marketId: params.marketId,
166
- isLong: inputs.actualOrderSize > 0,
171
+ nonce: inputs.nonce.toString(),
172
+ orderPriceLimit: inputs.orderPriceLimit.toString(),
167
173
  orderType: params.orderType,
168
- triggerPrice: params.triggerPrice
174
+ signature: inputs.signature
169
175
  };
170
176
  return [4 /*yield*/, params.signer.getAddress()];
171
177
  case 2: return [4 /*yield*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
172
- _c.nonce = inputs.nonce.toString(),
173
- _c.signature = inputs.signature,
174
- _c.deadline = inputs.deadline,
175
- _c.orderPriceLimit = inputs.orderPriceLimit.toString(),
176
- _c.exchangeId = params.supportingParams.exchangeId,
177
- _c.poolId = params.supportingParams.counterpartyAccountIds[0],
178
178
  _c.timestampMs = inputs.creationTimestampMs,
179
+ _c.triggerPrice = params.triggerPrice,
179
180
  _c.cancelOrderId = params.cancelOrderId,
181
+ _c.orderBase = params.amountInBase,
180
182
  _c)]))];
181
183
  case 3:
182
184
  result = _d.sent();
@@ -194,23 +196,23 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
194
196
  });
195
197
  });
196
198
  };
197
- ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds, orderSize) {
199
+ ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds, amountInBase) {
198
200
  return __awaiter(this, void 0, void 0, function () {
199
- var inputs, actualOrderSize, isLongOrder, orderPriceLimit, position, positionBase, creationTimestampMs, nonce, signature;
201
+ var inputs, actualAmountInBase, isLongOrder, orderPriceLimit, position, positionBase, creationTimestampMs, nonce, signature;
200
202
  return __generator(this, function (_a) {
201
203
  switch (_a.label) {
202
204
  case 0:
203
205
  if (!(orderType === common_1.ConditionalOrderType.LIMIT_ORDER)) return [3 /*break*/, 1];
204
- if (orderSize === undefined) {
206
+ if (amountInBase === undefined) {
205
207
  throw new Error('Order base is required for limit orders');
206
208
  }
207
- if (orderSize === 0) {
209
+ if (amountInBase === 0) {
208
210
  throw new Error('Cannot create an empty limit order');
209
211
  }
210
- actualOrderSize = orderSize;
211
- isLongOrder = actualOrderSize > 0;
212
+ actualAmountInBase = amountInBase;
213
+ isLongOrder = actualAmountInBase > 0;
212
214
  orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
213
- inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['int256', 'uint256'], [(0, common_1.scale)(18)(orderSize), (0, common_1.scale)(18)(triggerPrice)]);
215
+ inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['int256', 'uint256'], [(0, common_1.scale)(18)(amountInBase), (0, common_1.scale)(18)(triggerPrice)]);
214
216
  return [3 /*break*/, 3];
215
217
  case 1: return [4 /*yield*/, this.getPosition(accountId, marketId)];
216
218
  case 2:
@@ -219,8 +221,8 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
219
221
  if (positionBase === 0) {
220
222
  throw new Error('Cannot create SL or TP order for closed positions');
221
223
  }
222
- actualOrderSize = -positionBase;
223
- isLongOrder = actualOrderSize > 0;
224
+ actualAmountInBase = -positionBase;
225
+ isLongOrder = actualAmountInBase > 0;
224
226
  orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
225
227
  inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(triggerPrice), orderPriceLimit]);
226
228
  _a.label = 3;
@@ -232,7 +234,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
232
234
  signature = _a.sent();
233
235
  return [2 /*return*/, {
234
236
  signature: signature,
235
- actualOrderSize: actualOrderSize,
237
+ actualAmountInBase: actualAmountInBase,
236
238
  orderPriceLimit: orderPriceLimit,
237
239
  nonce: nonce,
238
240
  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,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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AA8B,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
+ {"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,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yaChainId,\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.amountInBase,\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 poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualAmountInBase > 0,\n marketId: params.marketId,\n nonce: inputs.nonce.toString(),\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n orderType: params.orderType,\n signature: inputs.signature,\n signerWallet: await params.signer.getAddress(),\n timestampMs: inputs.creationTimestampMs,\n triggerPrice: params.triggerPrice,\n orderBase: params.amountInBase,\n },\n );\n return result;\n }\n\n async updateConditionalOrder(\n params: UpdateConditionalOrderParams,\n ): Promise<UpdateConditionalOrderResult> {\n const inputs = await this.parseConditionalOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.orderType,\n params.triggerPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n params.amountInBase,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/create-or-update-order`;\n const result = await this.post<ConditionalOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualAmountInBase > 0,\n marketId: params.marketId,\n nonce: inputs.nonce.toString(),\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n orderType: params.orderType,\n signature: inputs.signature,\n signerWallet: await params.signer.getAddress(),\n timestampMs: inputs.creationTimestampMs,\n triggerPrice: params.triggerPrice,\n cancelOrderId: params.cancelOrderId,\n orderBase: params.amountInBase,\n },\n );\n return result;\n }\n\n private async getPosition(\n accountId: number,\n marketId: number,\n ): Promise<PositionEntity> {\n const uri = `/api/accounts/marginAccount/position/${accountId}/${marketId}`;\n return this.get<PositionEntity>(uri);\n }\n\n private async parseConditionalOrderInputs(\n signer: Signer | JsonRpcSigner,\n accountId: number,\n marketId: number,\n orderType: ConditionalOrderType,\n triggerPrice: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n amountInBase?: number,\n ): Promise<{\n signature: string;\n actualAmountInBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n let inputs: string;\n let actualAmountInBase: number;\n let isLongOrder: boolean;\n let orderPriceLimit: bigint;\n\n if (orderType === ConditionalOrderType.LIMIT_ORDER) {\n if (amountInBase === undefined) {\n throw new Error('Order base is required for limit orders');\n }\n\n if (amountInBase === 0) {\n throw new Error('Cannot create an empty limit order');\n }\n\n actualAmountInBase = amountInBase;\n isLongOrder = actualAmountInBase > 0;\n orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [scale(18)(amountInBase), scale(18)(triggerPrice)],\n );\n } else {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Cannot create SL or TP order for closed positions');\n }\n\n actualAmountInBase = -positionBase;\n isLongOrder = actualAmountInBase > 0;\n orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(triggerPrice), orderPriceLimit],\n );\n }\n\n const creationTimestampMs = Date.now();\n const nonce = createNonce(accountId, marketId, creationTimestampMs);\n\n const signature = await signConditionalOrder(\n signer,\n this.reyaChainId,\n accountId,\n marketId,\n exchangeId,\n counterpartyAccountIds,\n orderType,\n inputs,\n nonce,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n );\n\n return {\n signature,\n actualAmountInBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n}\n"]}
@@ -1 +1 @@
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
+ {"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 amountInBase?: 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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,WAAW,EAOZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAA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AO,CAAC,iDAAiD,CAAC;IAOvD,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;IAqCpC,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,4BAA4B,CAAC;YAsC1B,WAAW;YAQX,2BAA2B;CAkF1C"}
@@ -28,7 +28,7 @@ export type RegisterConditionalOrderParams = {
28
28
  orderType: ConditionalOrderType;
29
29
  marketId: number;
30
30
  supportingParams: OrderSupportingParams;
31
- orderSize?: number;
31
+ amountInBase?: number;
32
32
  };
33
33
  export type UpdateConditionalOrderParams = {
34
34
  cancelOrderId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,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;AAEpE,MAAM,MAAM,4BAA4B,GAAG;IACzC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;AAE5D,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM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ACzC,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.1",
3
+ "version": "0.114.0",
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.1",
36
+ "@reyaxyz/common": "0.173.0",
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": "c7053b78e27781ced35be45a7f5b663f2a2592c8",
43
+ "gitHead": "aec841130b8cf3bf0e29e0debe7996804ba02a3b",
44
44
  "devDependencies": {
45
45
  "@types/ws": "8.5.10"
46
46
  }
@@ -86,7 +86,7 @@ export default class ConditionalOrdersClient extends RestClient {
86
86
  params.triggerPrice,
87
87
  params.supportingParams.exchangeId,
88
88
  params.supportingParams.counterpartyAccountIds,
89
- params.orderSize,
89
+ params.amountInBase,
90
90
  );
91
91
 
92
92
  // create new entry
@@ -96,18 +96,19 @@ export default class ConditionalOrdersClient extends RestClient {
96
96
  {},
97
97
  {
98
98
  accountId: params.marginAccountId,
99
+ poolId: params.supportingParams.counterpartyAccountIds[0],
100
+ deadline: inputs.deadline,
101
+ exchangeId: params.supportingParams.exchangeId,
102
+ isLong: inputs.actualAmountInBase > 0,
99
103
  marketId: params.marketId,
100
- isLong: inputs.actualOrderSize > 0,
101
- orderType: params.orderType,
102
- triggerPrice: params.triggerPrice,
103
- signerWallet: await params.signer.getAddress(),
104
104
  nonce: inputs.nonce.toString(),
105
- signature: inputs.signature,
106
- deadline: inputs.deadline,
107
105
  orderPriceLimit: inputs.orderPriceLimit.toString(),
108
- exchangeId: params.supportingParams.exchangeId,
109
- poolId: params.supportingParams.counterpartyAccountIds[0],
106
+ orderType: params.orderType,
107
+ signature: inputs.signature,
108
+ signerWallet: await params.signer.getAddress(),
110
109
  timestampMs: inputs.creationTimestampMs,
110
+ triggerPrice: params.triggerPrice,
111
+ orderBase: params.amountInBase,
111
112
  },
112
113
  );
113
114
  return result;
@@ -124,6 +125,7 @@ export default class ConditionalOrdersClient extends RestClient {
124
125
  params.triggerPrice,
125
126
  params.supportingParams.exchangeId,
126
127
  params.supportingParams.counterpartyAccountIds,
128
+ params.amountInBase,
127
129
  );
128
130
 
129
131
  // create new entry
@@ -133,19 +135,20 @@ export default class ConditionalOrdersClient extends RestClient {
133
135
  {},
134
136
  {
135
137
  accountId: params.marginAccountId,
138
+ poolId: params.supportingParams.counterpartyAccountIds[0],
139
+ deadline: inputs.deadline,
140
+ exchangeId: params.supportingParams.exchangeId,
141
+ isLong: inputs.actualAmountInBase > 0,
136
142
  marketId: params.marketId,
137
- isLong: inputs.actualOrderSize > 0,
138
- orderType: params.orderType,
139
- triggerPrice: params.triggerPrice,
140
- signerWallet: await params.signer.getAddress(),
141
143
  nonce: inputs.nonce.toString(),
142
- signature: inputs.signature,
143
- deadline: inputs.deadline,
144
144
  orderPriceLimit: inputs.orderPriceLimit.toString(),
145
- exchangeId: params.supportingParams.exchangeId,
146
- poolId: params.supportingParams.counterpartyAccountIds[0],
145
+ orderType: params.orderType,
146
+ signature: inputs.signature,
147
+ signerWallet: await params.signer.getAddress(),
147
148
  timestampMs: inputs.creationTimestampMs,
149
+ triggerPrice: params.triggerPrice,
148
150
  cancelOrderId: params.cancelOrderId,
151
+ orderBase: params.amountInBase,
149
152
  },
150
153
  );
151
154
  return result;
@@ -167,36 +170,36 @@ export default class ConditionalOrdersClient extends RestClient {
167
170
  triggerPrice: number,
168
171
  exchangeId: number,
169
172
  counterpartyAccountIds: number[],
170
- orderSize?: number,
173
+ amountInBase?: number,
171
174
  ): Promise<{
172
175
  signature: string;
173
- actualOrderSize: number;
176
+ actualAmountInBase: number;
174
177
  orderPriceLimit: bigint;
175
178
  nonce: bigint;
176
179
  deadline: number;
177
180
  creationTimestampMs: number;
178
181
  }> {
179
182
  let inputs: string;
180
- let actualOrderSize: number;
183
+ let actualAmountInBase: number;
181
184
  let isLongOrder: boolean;
182
185
  let orderPriceLimit: bigint;
183
186
 
184
187
  if (orderType === ConditionalOrderType.LIMIT_ORDER) {
185
- if (orderSize === undefined) {
188
+ if (amountInBase === undefined) {
186
189
  throw new Error('Order base is required for limit orders');
187
190
  }
188
191
 
189
- if (orderSize === 0) {
192
+ if (amountInBase === 0) {
190
193
  throw new Error('Cannot create an empty limit order');
191
194
  }
192
195
 
193
- actualOrderSize = orderSize;
194
- isLongOrder = actualOrderSize > 0;
196
+ actualAmountInBase = amountInBase;
197
+ isLongOrder = actualAmountInBase > 0;
195
198
  orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
196
199
 
197
200
  inputs = AbiCoder.defaultAbiCoder().encode(
198
201
  ['int256', 'uint256'],
199
- [scale(18)(orderSize), scale(18)(triggerPrice)],
202
+ [scale(18)(amountInBase), scale(18)(triggerPrice)],
200
203
  );
201
204
  } else {
202
205
  const position = await this.getPosition(accountId, marketId);
@@ -206,8 +209,8 @@ export default class ConditionalOrdersClient extends RestClient {
206
209
  throw new Error('Cannot create SL or TP order for closed positions');
207
210
  }
208
211
 
209
- actualOrderSize = -positionBase;
210
- isLongOrder = actualOrderSize > 0;
212
+ actualAmountInBase = -positionBase;
213
+ isLongOrder = actualAmountInBase > 0;
211
214
  orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
212
215
 
213
216
  inputs = AbiCoder.defaultAbiCoder().encode(
@@ -234,7 +237,7 @@ export default class ConditionalOrdersClient extends RestClient {
234
237
 
235
238
  return {
236
239
  signature,
237
- actualOrderSize,
240
+ actualAmountInBase,
238
241
  orderPriceLimit,
239
242
  nonce,
240
243
  deadline: CONDITIONAL_ORDER_SIG_DEADLINE,
@@ -37,7 +37,7 @@ export type RegisterConditionalOrderParams = {
37
37
  orderType: ConditionalOrderType;
38
38
  marketId: number;
39
39
  supportingParams: OrderSupportingParams;
40
- orderSize?: number;
40
+ amountInBase?: number;
41
41
  };
42
42
 
43
43
  export type UpdateConditionalOrderParams = {