@reyaxyz/api-sdk 0.113.0 → 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.
- package/dist/clients/modules/conditional-orders/index.js +16 -16
- package/dist/clients/modules/conditional-orders/index.js.map +1 -1
- package/dist/clients/modules/conditional-orders/types.js.map +1 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts +1 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/modules/conditional-orders/index.ts +17 -17
- package/src/clients/modules/conditional-orders/types.ts +1 -1
|
@@ -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.
|
|
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";
|
|
@@ -128,7 +128,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
128
128
|
poolId: params.supportingParams.counterpartyAccountIds[0],
|
|
129
129
|
deadline: inputs.deadline,
|
|
130
130
|
exchangeId: params.supportingParams.exchangeId,
|
|
131
|
-
isLong: inputs.
|
|
131
|
+
isLong: inputs.actualAmountInBase > 0,
|
|
132
132
|
marketId: params.marketId,
|
|
133
133
|
nonce: inputs.nonce.toString(),
|
|
134
134
|
orderPriceLimit: inputs.orderPriceLimit.toString(),
|
|
@@ -139,7 +139,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
139
139
|
case 2: return [4 /*yield*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
|
|
140
140
|
_c.timestampMs = inputs.creationTimestampMs,
|
|
141
141
|
_c.triggerPrice = params.triggerPrice,
|
|
142
|
-
_c.orderBase = params.
|
|
142
|
+
_c.orderBase = params.amountInBase,
|
|
143
143
|
_c)]))];
|
|
144
144
|
case 3:
|
|
145
145
|
result = _d.sent();
|
|
@@ -154,7 +154,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
154
154
|
var _c;
|
|
155
155
|
return __generator(this, function (_d) {
|
|
156
156
|
switch (_d.label) {
|
|
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.
|
|
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)];
|
|
158
158
|
case 1:
|
|
159
159
|
inputs = _d.sent();
|
|
160
160
|
uri = "/api/conditional-orders/create-or-update-order";
|
|
@@ -166,7 +166,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
166
166
|
poolId: params.supportingParams.counterpartyAccountIds[0],
|
|
167
167
|
deadline: inputs.deadline,
|
|
168
168
|
exchangeId: params.supportingParams.exchangeId,
|
|
169
|
-
isLong: inputs.
|
|
169
|
+
isLong: inputs.actualAmountInBase > 0,
|
|
170
170
|
marketId: params.marketId,
|
|
171
171
|
nonce: inputs.nonce.toString(),
|
|
172
172
|
orderPriceLimit: inputs.orderPriceLimit.toString(),
|
|
@@ -178,7 +178,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
178
178
|
_c.timestampMs = inputs.creationTimestampMs,
|
|
179
179
|
_c.triggerPrice = params.triggerPrice,
|
|
180
180
|
_c.cancelOrderId = params.cancelOrderId,
|
|
181
|
-
_c.orderBase = params.
|
|
181
|
+
_c.orderBase = params.amountInBase,
|
|
182
182
|
_c)]))];
|
|
183
183
|
case 3:
|
|
184
184
|
result = _d.sent();
|
|
@@ -196,23 +196,23 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
198
|
};
|
|
199
|
-
ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds,
|
|
199
|
+
ConditionalOrdersClient.prototype.parseConditionalOrderInputs = function (signer, accountId, marketId, orderType, triggerPrice, exchangeId, counterpartyAccountIds, amountInBase) {
|
|
200
200
|
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
-
var inputs,
|
|
201
|
+
var inputs, actualAmountInBase, isLongOrder, orderPriceLimit, position, positionBase, creationTimestampMs, nonce, signature;
|
|
202
202
|
return __generator(this, function (_a) {
|
|
203
203
|
switch (_a.label) {
|
|
204
204
|
case 0:
|
|
205
205
|
if (!(orderType === common_1.ConditionalOrderType.LIMIT_ORDER)) return [3 /*break*/, 1];
|
|
206
|
-
if (
|
|
206
|
+
if (amountInBase === undefined) {
|
|
207
207
|
throw new Error('Order base is required for limit orders');
|
|
208
208
|
}
|
|
209
|
-
if (
|
|
209
|
+
if (amountInBase === 0) {
|
|
210
210
|
throw new Error('Cannot create an empty limit order');
|
|
211
211
|
}
|
|
212
|
-
|
|
213
|
-
isLongOrder =
|
|
212
|
+
actualAmountInBase = amountInBase;
|
|
213
|
+
isLongOrder = actualAmountInBase > 0;
|
|
214
214
|
orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
|
|
215
|
-
inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['int256', 'uint256'], [(0, common_1.scale)(18)(
|
|
215
|
+
inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['int256', 'uint256'], [(0, common_1.scale)(18)(amountInBase), (0, common_1.scale)(18)(triggerPrice)]);
|
|
216
216
|
return [3 /*break*/, 3];
|
|
217
217
|
case 1: return [4 /*yield*/, this.getPosition(accountId, marketId)];
|
|
218
218
|
case 2:
|
|
@@ -221,8 +221,8 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
221
221
|
if (positionBase === 0) {
|
|
222
222
|
throw new Error('Cannot create SL or TP order for closed positions');
|
|
223
223
|
}
|
|
224
|
-
|
|
225
|
-
isLongOrder =
|
|
224
|
+
actualAmountInBase = -positionBase;
|
|
225
|
+
isLongOrder = actualAmountInBase > 0;
|
|
226
226
|
orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(isLongOrder);
|
|
227
227
|
inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['bool', 'uint256', 'uint256'], [isLongOrder, (0, common_1.scale)(18)(triggerPrice), orderPriceLimit]);
|
|
228
228
|
_a.label = 3;
|
|
@@ -234,7 +234,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
234
234
|
signature = _a.sent();
|
|
235
235
|
return [2 /*return*/, {
|
|
236
236
|
signature: signature,
|
|
237
|
-
|
|
237
|
+
actualAmountInBase: actualAmountInBase,
|
|
238
238
|
orderPriceLimit: orderPriceLimit,
|
|
239
239
|
nonce: nonce,
|
|
240
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;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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,AA1ND,CAAqD,mBAAU,GA0N9D","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 poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualOrderSize > 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.orderSize,\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.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 poolId: params.supportingParams.counterpartyAccountIds[0],\n deadline: inputs.deadline,\n exchangeId: params.supportingParams.exchangeId,\n isLong: inputs.actualOrderSize > 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.orderSize,\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;;;;;;w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,EACL,uCAA8B,CAC/B,EAAA;;wBAXK,SAAS,GAAG,SAWjB;wBAED,sBAAO;gCACL,SAAS,WAAA;gCACT,kBAAkB,oBAAA;gCAClB,eAAe,iBAAA;gCACf,KAAK,OAAA;gCACL,QAAQ,EAAE,uCAA8B;gCACxC,mBAAmB,qBAAA;6BACpB,EAAC;;;;KACH;IACH,8BAAC;AAAD,CAAC,AA1ND,CAAqD,mBAAU,GA0N9D","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.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
|
|
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"]}
|
|
@@ -28,7 +28,7 @@ export type RegisterConditionalOrderParams = {
|
|
|
28
28
|
orderType: ConditionalOrderType;
|
|
29
29
|
marketId: number;
|
|
30
30
|
supportingParams: OrderSupportingParams;
|
|
31
|
-
|
|
31
|
+
amountInBase?: number;
|
|
32
32
|
};
|
|
33
33
|
export type UpdateConditionalOrderParams = {
|
|
34
34
|
cancelOr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AAE,qBAAqB,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,8BAA8B,CAAC;AAEnC,MAAM,MAAM,8BAA8B,GAAG,gBAAgB,CAAC;AAC9D,MAAM,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;AAE5D,MAAM,MAAM,gCAAgC,GAAG;IAC7C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,iDAAiD,GAAG;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iDAAiD,GAC3D,2BAA2B,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.
|
|
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.
|
|
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": "
|
|
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.
|
|
89
|
+
params.amountInBase,
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
// create new entry
|
|
@@ -99,7 +99,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
99
99
|
poolId: params.supportingParams.counterpartyAccountIds[0],
|
|
100
100
|
deadline: inputs.deadline,
|
|
101
101
|
exchangeId: params.supportingParams.exchangeId,
|
|
102
|
-
isLong: inputs.
|
|
102
|
+
isLong: inputs.actualAmountInBase > 0,
|
|
103
103
|
marketId: params.marketId,
|
|
104
104
|
nonce: inputs.nonce.toString(),
|
|
105
105
|
orderPriceLimit: inputs.orderPriceLimit.toString(),
|
|
@@ -108,7 +108,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
108
108
|
signerWallet: await params.signer.getAddress(),
|
|
109
109
|
timestampMs: inputs.creationTimestampMs,
|
|
110
110
|
triggerPrice: params.triggerPrice,
|
|
111
|
-
orderBase: params.
|
|
111
|
+
orderBase: params.amountInBase,
|
|
112
112
|
},
|
|
113
113
|
);
|
|
114
114
|
return result;
|
|
@@ -125,7 +125,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
125
125
|
params.triggerPrice,
|
|
126
126
|
params.supportingParams.exchangeId,
|
|
127
127
|
params.supportingParams.counterpartyAccountIds,
|
|
128
|
-
params.
|
|
128
|
+
params.amountInBase,
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
// create new entry
|
|
@@ -138,7 +138,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
138
138
|
poolId: params.supportingParams.counterpartyAccountIds[0],
|
|
139
139
|
deadline: inputs.deadline,
|
|
140
140
|
exchangeId: params.supportingParams.exchangeId,
|
|
141
|
-
isLong: inputs.
|
|
141
|
+
isLong: inputs.actualAmountInBase > 0,
|
|
142
142
|
marketId: params.marketId,
|
|
143
143
|
nonce: inputs.nonce.toString(),
|
|
144
144
|
orderPriceLimit: inputs.orderPriceLimit.toString(),
|
|
@@ -148,7 +148,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
148
148
|
timestampMs: inputs.creationTimestampMs,
|
|
149
149
|
triggerPrice: params.triggerPrice,
|
|
150
150
|
cancelOrderId: params.cancelOrderId,
|
|
151
|
-
orderBase: params.
|
|
151
|
+
orderBase: params.amountInBase,
|
|
152
152
|
},
|
|
153
153
|
);
|
|
154
154
|
return result;
|
|
@@ -170,36 +170,36 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
170
170
|
triggerPrice: number,
|
|
171
171
|
exchangeId: number,
|
|
172
172
|
counterpartyAccountIds: number[],
|
|
173
|
-
|
|
173
|
+
amountInBase?: number,
|
|
174
174
|
): Promise<{
|
|
175
175
|
signature: string;
|
|
176
|
-
|
|
176
|
+
actualAmountInBase: number;
|
|
177
177
|
orderPriceLimit: bigint;
|
|
178
178
|
nonce: bigint;
|
|
179
179
|
deadline: number;
|
|
180
180
|
creationTimestampMs: number;
|
|
181
181
|
}> {
|
|
182
182
|
let inputs: string;
|
|
183
|
-
let
|
|
183
|
+
let actualAmountInBase: number;
|
|
184
184
|
let isLongOrder: boolean;
|
|
185
185
|
let orderPriceLimit: bigint;
|
|
186
186
|
|
|
187
187
|
if (orderType === ConditionalOrderType.LIMIT_ORDER) {
|
|
188
|
-
if (
|
|
188
|
+
if (amountInBase === undefined) {
|
|
189
189
|
throw new Error('Order base is required for limit orders');
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
if (
|
|
192
|
+
if (amountInBase === 0) {
|
|
193
193
|
throw new Error('Cannot create an empty limit order');
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
isLongOrder =
|
|
196
|
+
actualAmountInBase = amountInBase;
|
|
197
|
+
isLongOrder = actualAmountInBase > 0;
|
|
198
198
|
orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
|
|
199
199
|
|
|
200
200
|
inputs = AbiCoder.defaultAbiCoder().encode(
|
|
201
201
|
['int256', 'uint256'],
|
|
202
|
-
[scale(18)(
|
|
202
|
+
[scale(18)(amountInBase), scale(18)(triggerPrice)],
|
|
203
203
|
);
|
|
204
204
|
} else {
|
|
205
205
|
const position = await this.getPosition(accountId, marketId);
|
|
@@ -209,8 +209,8 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
209
209
|
throw new Error('Cannot create SL or TP order for closed positions');
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
isLongOrder =
|
|
212
|
+
actualAmountInBase = -positionBase;
|
|
213
|
+
isLongOrder = actualAmountInBase > 0;
|
|
214
214
|
orderPriceLimit = calculateMaxPriceLimit(isLongOrder);
|
|
215
215
|
|
|
216
216
|
inputs = AbiCoder.defaultAbiCoder().encode(
|
|
@@ -237,7 +237,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
237
237
|
|
|
238
238
|
return {
|
|
239
239
|
signature,
|
|
240
|
-
|
|
240
|
+
actualAmountInBase,
|
|
241
241
|
orderPriceLimit,
|
|
242
242
|
nonce,
|
|
243
243
|
deadline: CONDITIONAL_ORDER_SIG_DEADLINE,
|