@reyaxyz/sdk 0.136.16 → 0.137.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/README.md +1 -1
- package/dist/services/orders/order.js +4 -6
- package/dist/services/orders/order.js.map +1 -1
- package/dist/services/orders/types.js.map +1 -1
- package/dist/types/services/orders/order.d.ts.map +1 -1
- package/dist/types/services/orders/types.d.ts +0 -1
- package/dist/types/services/orders/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/orders/order.ts +3 -13
- package/src/services/orders/types.ts +0 -1
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -91,7 +91,7 @@ var executeMarketOrderViaOrdersGateway = function (params) { return __awaiter(vo
|
|
|
91
91
|
});
|
|
92
92
|
}); };
|
|
93
93
|
var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
94
|
-
var snappedAmount, orderBaseE18,
|
|
94
|
+
var snappedAmount, orderBaseE18, orderPriceLimitE18, result;
|
|
95
95
|
var _a, _b, _c, _d, _e, _f;
|
|
96
96
|
return __generator(this, function (_g) {
|
|
97
97
|
switch (_g.label) {
|
|
@@ -113,8 +113,7 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
113
113
|
throw new Error("Minimum trade amount ".concat(params.market.minOrderSizeBase));
|
|
114
114
|
}
|
|
115
115
|
orderBaseE18 = (0, common_3.scale)(18)(snappedAmount);
|
|
116
|
-
|
|
117
|
-
orderPriceLimitE18 = (0, common_1.calculatePriceLimitForTrade)(params.market.currentPrice, snappedAmount, slippageFactor);
|
|
116
|
+
orderPriceLimitE18 = (0, common_1.calculateMaxPriceLimit)(snappedAmount > 0);
|
|
118
117
|
return [4 /*yield*/, executeMarketOrderViaOrdersGateway({
|
|
119
118
|
signer: params.signer,
|
|
120
119
|
marginAccountId: params.marginAccountId,
|
|
@@ -149,7 +148,7 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
149
148
|
}); };
|
|
150
149
|
exports.matchOrder = matchOrder;
|
|
151
150
|
var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
152
|
-
var closingBase,
|
|
151
|
+
var closingBase, orderPriceLimit, result;
|
|
153
152
|
var _a, _b, _c, _d, _e, _f;
|
|
154
153
|
return __generator(this, function (_g) {
|
|
155
154
|
switch (_g.label) {
|
|
@@ -173,8 +172,7 @@ var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
173
172
|
throw new Error('Specified base to close is larger than the actual order.');
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
|
-
|
|
177
|
-
orderPriceLimit = (0, common_1.calculatePriceLimitForTrade)(params.market.currentPrice, -closingBase, slippageFactor);
|
|
175
|
+
orderPriceLimit = (0, common_1.calculateMaxPriceLimit)(closingBase < 0);
|
|
178
176
|
return [4 /*yield*/, executeMarketOrderViaOrdersGateway({
|
|
179
177
|
signer: params.signer,
|
|
180
178
|
marginAccountId: params.marginAccountId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,8EAA6E;AAC7E,0CAOyB;AACzB,8DAAqC;AACrC,0CAA+C;AAC/C,0CAAwC;AACxC,+CAAqD;AACrD,iCAA6C;AAE7C,IAAM,kCAAkC,GAAG,UACzC,MAAsC;;;;;gBAEhC,MAAM,GAAG,iBAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CAC9C,CAAC,QAAQ,EAAE,SAAS,CAAC,EACrB,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,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AE,MAAM,CAAC,eAAe;wBACvC,sBAAsB,EAAE,MAAM,CAAC,MAAM,CAAC,sBAAsB;wBAC5D,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE;wBAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU;wBACpC,KAAK,EAAE;4BACL,OAAO,EAAE,CAAC,IAAA,cAAK,EAAC,EAAE,CAAC,CAAC,WAAW,CAAC;4BAChC,aAAa,EAAE,eAAe;4BAC9B,IAAI,EAAE,+BAAsB,CAAC,wBAAwB;yBACtD;qBACF,CAAC,EAAA;;gBAXI,MAAM,GAAG,SAWb;gBAEF,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;wBACvC,YAAY,EAAE,MAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,CAAC,IAAI,IAAI;wBAClD,OAAO,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,YAAY,KAAI,CAAC;wBAChD,cAAc,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,cAAc,KAAI,CAAC;wBACzD,QAAQ,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,YAAY,KAAI,KAAK;wBACrD,eAAe,EAAE,MAAM,CAAC,eAAe;wBACvC,QAAQ,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,QAAQ,KAAI,CAAC;wBAC7C,cAAc,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,cAAc,KAAI,CAAC;wBACxD,IAAI,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,IAAI,KAAI,CAAC;qBACrC,EAAC;;;KACH,CAAC;AA7DW,QAAA,UAAU,cA6DrB","sourcesContent":["import {\n CloseOrderParams,\n CloseOrderResult,\n MatchOrderParams,\n MatchOrderResult,\n OrdersGatewayMarketOrderParams,\n} from './types';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport {\n calculatePriceLimitForTrade,\n ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n OrdersGatewayAbi,\n OrdersGatewayOrderType,\n signOrdersGatewayOrder,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { ContractType } from '@reyaxyz/common';\nimport { scale } from '@reyaxyz/common';\nimport { getReyaNetwork } from '../../utils/network';\nimport { AbiCoder, Interface } from 'ethers';\n\nconst executeMarketOrderViaOrdersGateway = async (\n params: OrdersGatewayMarketOrderParams,\n): Promise<TransactionExecutionOutput> => {\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [params.order.baseE18, params.order.priceLimitE18],\n );\n\n const reyaChainId = getReyaNetwork();\n const creationTimestampMs = Date.now();\n const creationTimestampSeconds = Math.floor(creationTimestampMs / 1000);\n\n const { signature, nonce } = await signOrdersGatewayOrder(\n params.signer,\n reyaChainId,\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n creationTimestampSeconds + ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n creationTimestampMs,\n );\n\n const fnSig = 'execute';\n const fnArgs = [\n [\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n await params.signer.getAddress(),\n nonce,\n ],\n [signature.v, signature.r, signature.s, signature.deadline],\n ];\n\n const ogInterface = new Interface(OrdersGatewayAbi);\n const data = ogInterface.encodeFunctionData(fnSig, fnArgs);\n\n const isFastExecutionEnabled =\n process.env.FAST_ORDER_EXECUTION === 'true' || false;\n\n const result = await signAndBroadcastTransaction(\n data,\n reyaChainId,\n ContractType.ORDERS_GATEWAY_PROXY,\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n tradeSource: params.tradeSource,\n action: isFastExecutionEnabled ? 'ioc-order-ui' : undefined,\n },\n );\n\n return result;\n};\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n if (params.amountInBase === 0) {\n throw new Error('Order cannot be of size zero.');\n }\n\n let snappedAmount = BigNumber(params.amountInBase)\n .abs()\n .dividedBy(params.market.baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(params.market.baseSpacing)\n .toNumber();\n\n if (params.amountInBase < 0) {\n snappedAmount = -snappedAmount;\n }\n\n if (Math.abs(snappedAmount) < params.market.minOrderSizeBase) {\n console.error(\n `Minimum trade amount ${params.market.minOrderSizeBase}. Entered amount ${snappedAmount}, ${params.amountInBase}`,\n );\n throw new Error(`Minimum trade amount ${params.market.minOrderSizeBase}`);\n }\n\n const orderBaseE18 = scale(18)(snappedAmount);\n const slippageFactor = 40; // 2.5%\n const orderPriceLimitE18 = calculatePriceLimitForTrade(\n params.market.currentPrice,\n snappedAmount,\n slippageFactor,\n );\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n tradeSource: params.tradeSource,\n order: {\n baseE18: orderBaseE18,\n priceLimitE18: orderPriceLimitE18,\n type: OrdersGatewayOrderType.MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n positions: result.positions,\n orders: result.orders,\n accounts: result.accounts,\n };\n};\n\nexport const closeOrder = async (\n params: CloseOrderParams,\n): Promise<CloseOrderResult> => {\n if (params.orderBase === 0) {\n throw new Error('Position is already closed.');\n }\n\n let closingBase: number = 0;\n if (params.type === 'full') {\n closingBase = params.orderBase;\n } else {\n closingBase = params.closingOrderBase;\n\n if (closingBase === 0) {\n throw new Error('Specified base to close is zero.');\n }\n\n if (closingBase * params.orderBase < 0) {\n throw new Error(\n 'Specified base to close is in different direction that the actual order.',\n );\n }\n\n if (Math.abs(closingBase) > Math.abs(params.orderBase)) {\n throw new Error(\n 'Specified base to close is larger than the actual order.',\n );\n }\n }\n\n const slippageFactor = 40; // 2.5%\n const orderPriceLimit = calculatePriceLimitForTrade(\n params.market.currentPrice,\n -closingBase,\n slippageFactor,\n );\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n order: {\n baseE18: -scale(18)(closingBase),\n priceLimitE18: orderPriceLimit,\n type: OrdersGatewayOrderType.REDUCE_ONLY_MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,8EAA6E;AAC7E,0CAOyB;AACzB,8DAAqC;AACrC,0CAA+C;AAC/C,0CAAwC;AACxC,+CAAqD;AACrD,iCAA6C;AAE7C,IAAM,kCAAkC,GAAG,UACzC,MAAsC;;;;;gBAEhC,MAAM,GAAG,iBAAQ,CAAC,eAAe,EAAE,CAAC,MAAM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vC,sBAAsB,EAAE,MAAM,CAAC,MAAM,CAAC,sBAAsB;wBAC5D,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE;wBAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU;wBACpC,KAAK,EAAE;4BACL,OAAO,EAAE,CAAC,IAAA,cAAK,EAAC,EAAE,CAAC,CAAC,WAAW,CAAC;4BAChC,aAAa,EAAE,eAAe;4BAC9B,IAAI,EAAE,+BAAsB,CAAC,wBAAwB;yBACtD;qBACF,CAAC,EAAA;;gBAXI,MAAM,GAAG,SAWb;gBAEF,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;wBACvC,YAAY,EAAE,MAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,CAAC,IAAI,IAAI;wBAClD,OAAO,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,YAAY,KAAI,CAAC;wBAChD,cAAc,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,cAAc,KAAI,CAAC;wBACzD,QAAQ,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,YAAY,KAAI,KAAK;wBACrD,eAAe,EAAE,MAAM,CAAC,eAAe;wBACvC,QAAQ,EAAE,CAAA,MAAA,MAAM,CAAC,aAAa,0CAAE,QAAQ,KAAI,CAAC;wBAC7C,cAAc,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,cAAc,KAAI,CAAC;wBACxD,IAAI,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,IAAI,KAAI,CAAC;qBACrC,EAAC;;;KACH,CAAC;AAxDW,QAAA,UAAU,cAwDrB","sourcesContent":["import {\n CloseOrderParams,\n CloseOrderResult,\n MatchOrderParams,\n MatchOrderResult,\n OrdersGatewayMarketOrderParams,\n} from './types';\nimport { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';\nimport {\n calculateMaxPriceLimit,\n ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n OrdersGatewayAbi,\n OrdersGatewayOrderType,\n signOrdersGatewayOrder,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\nimport { ContractType } from '@reyaxyz/common';\nimport { scale } from '@reyaxyz/common';\nimport { getReyaNetwork } from '../../utils/network';\nimport { AbiCoder, Interface } from 'ethers';\n\nconst executeMarketOrderViaOrdersGateway = async (\n params: OrdersGatewayMarketOrderParams,\n): Promise<TransactionExecutionOutput> => {\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [params.order.baseE18, params.order.priceLimitE18],\n );\n\n const reyaChainId = getReyaNetwork();\n const creationTimestampMs = Date.now();\n const creationTimestampSeconds = Math.floor(creationTimestampMs / 1000);\n\n const { signature, nonce } = await signOrdersGatewayOrder(\n params.signer,\n reyaChainId,\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n creationTimestampSeconds + ORDERS_GATEWAY_DEADLINE_IN_SECONDS,\n creationTimestampMs,\n );\n\n const fnSig = 'execute';\n const fnArgs = [\n [\n params.marginAccountId,\n params.marketId,\n params.exchangeId,\n params.counterpartyAccountIds,\n params.order.type,\n inputs,\n await params.signer.getAddress(),\n nonce,\n ],\n [signature.v, signature.r, signature.s, signature.deadline],\n ];\n\n const ogInterface = new Interface(OrdersGatewayAbi);\n const data = ogInterface.encodeFunctionData(fnSig, fnArgs);\n\n const isFastExecutionEnabled =\n process.env.FAST_ORDER_EXECUTION === 'true' || false;\n\n const result = await signAndBroadcastTransaction(\n data,\n reyaChainId,\n ContractType.ORDERS_GATEWAY_PROXY,\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n tradeSource: params.tradeSource,\n action: isFastExecutionEnabled ? 'ioc-order-ui' : undefined,\n },\n );\n\n return result;\n};\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n if (params.amountInBase === 0) {\n throw new Error('Order cannot be of size zero.');\n }\n\n let snappedAmount = BigNumber(params.amountInBase)\n .abs()\n .dividedBy(params.market.baseSpacing)\n .integerValue(BigNumber.ROUND_FLOOR)\n .multipliedBy(params.market.baseSpacing)\n .toNumber();\n\n if (params.amountInBase < 0) {\n snappedAmount = -snappedAmount;\n }\n\n if (Math.abs(snappedAmount) < params.market.minOrderSizeBase) {\n console.error(\n `Minimum trade amount ${params.market.minOrderSizeBase}. Entered amount ${snappedAmount}, ${params.amountInBase}`,\n );\n throw new Error(`Minimum trade amount ${params.market.minOrderSizeBase}`);\n }\n\n const orderBaseE18 = scale(18)(snappedAmount);\n const orderPriceLimitE18 = calculateMaxPriceLimit(snappedAmount > 0);\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n tradeSource: params.tradeSource,\n order: {\n baseE18: orderBaseE18,\n priceLimitE18: orderPriceLimitE18,\n type: OrdersGatewayOrderType.MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n positions: result.positions,\n orders: result.orders,\n accounts: result.accounts,\n };\n};\n\nexport const closeOrder = async (\n params: CloseOrderParams,\n): Promise<CloseOrderResult> => {\n if (params.orderBase === 0) {\n throw new Error('Position is already closed.');\n }\n\n let closingBase: number = 0;\n if (params.type === 'full') {\n closingBase = params.orderBase;\n } else {\n closingBase = params.closingOrderBase;\n\n if (closingBase === 0) {\n throw new Error('Specified base to close is zero.');\n }\n\n if (closingBase * params.orderBase < 0) {\n throw new Error(\n 'Specified base to close is in different direction that the actual order.',\n );\n }\n\n if (Math.abs(closingBase) > Math.abs(params.orderBase)) {\n throw new Error(\n 'Specified base to close is larger than the actual order.',\n );\n }\n }\n\n const orderPriceLimit = calculateMaxPriceLimit(closingBase < 0);\n\n const result = await executeMarketOrderViaOrdersGateway({\n signer: params.signer,\n marginAccountId: params.marginAccountId,\n counterpartyAccountIds: params.market.counterpartyAccountIds,\n marketId: params.market.id,\n exchangeId: params.market.exchangeId,\n order: {\n baseE18: -scale(18)(closingBase),\n priceLimitE18: orderPriceLimit,\n type: OrdersGatewayOrderType.REDUCE_ONLY_MARKET_ORDER,\n },\n });\n\n return {\n transactionHash: result?.txHash || null,\n coreSigNonce: Number(result?.coreSigNonce) || null,\n xpBoost: result.miscellaneous?.tradeXpBoost || 0,\n lotteryXpBoost: result.miscellaneous?.lotteryXpBoost || 0,\n isNftWon: result.miscellaneous?.xpNftAwarded || false,\n marginAccountId: params.marginAccountId,\n xpEarned: result.miscellaneous?.xpEarned || 0,\n executionPrice: result.tradeDetails?.executionPrice || 0,\n base: result.tradeDetails?.base || 0,\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer, JsonRpcSigner } from 'ethers';\nimport {\n CoreCommandsEIP712SignatureAndPayload,\n MarginAccountEntity,\n MarketEntity,\n MethodParameters,\n OrdersGatewayOrderType,\n OwnerMetadataEntity,\n PositionEntity,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\n\nexport type MarketParams = {\n id: MarketEntity['id'];\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer, JsonRpcSigner } from 'ethers';\nimport {\n CoreCommandsEIP712SignatureAndPayload,\n MarginAccountEntity,\n MarketEntity,\n MethodParameters,\n OrdersGatewayOrderType,\n OwnerMetadataEntity,\n PositionEntity,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\n\nexport type MarketParams = {\n id: MarketEntity['id'];\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n minOrderSizeBase: MarketEntity['minOrderSizeBase'];\n baseSpacing: MarketEntity['baseSpacing'];\n};\n\nexport type MatchOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n amountInBase: number; // amount in base\n market: MarketParams;\n tradeSource?: 'reya' | 'rage' | 'other';\n};\n\nexport type CloseOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n orderBase: PositionEntity['base'];\n market: MarketParams;\n} & (\n | {\n type: 'full';\n }\n | {\n type: 'partial';\n closingOrderBase: number;\n }\n);\n\nexport type MatchOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n lotteryXpBoost: number;\n isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n executionPrice: number;\n base: number;\n positions?: TransactionExecutionOutput['positions'];\n orders?: TransactionExecutionOutput['orders'];\n accounts?: TransactionExecutionOutput['accounts'];\n};\n\nexport type CloseOrderResult = {\n transactionHash: string | null;\n coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;\n xpBoost: number;\n lotteryXpBoost: number;\n isNftWon: boolean;\n marginAccountId: MarginAccountEntity['id'];\n xpEarned: number;\n executionPrice: number;\n base: number;\n};\n\nexport type MethodParametersAndEIP712Payload = MethodParameters &\n CoreCommandsEIP712SignatureAndPayload;\n\nexport type OrdersGatewayMarketOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n marketId: MarketEntity['id'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n order: {\n baseE18: bigint;\n priceLimitE18: bigint;\n type:\n | OrdersGatewayOrderType.MARKET_ORDER\n | OrdersGatewayOrderType.REDUCE_ONLY_MARKET_ORDER;\n };\n tradeSource?: 'reya' | 'rage' | 'other';\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AA6EjB,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AA6EjB,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAsD1B,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAsD1B,CAAC"}
|
|
@@ -4,7 +4,6 @@ export type MarketParams = {
|
|
|
4
4
|
id: MarketEntity['id'];
|
|
5
5
|
exchangeId: MarketEntity['orderInfo']['exchangeId'];
|
|
6
6
|
counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
|
|
7
|
-
currentPrice: number;
|
|
8
7
|
minOrderSizeBase: MarketEntity['minOrderSizeBase'];
|
|
9
8
|
baseSpacing: MarketEntity['baseSpacing'];
|
|
10
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,qCAAqC,EACrC,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC;IACpD,sBAAsB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAC5E,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,qCAAqC,EACrC,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC;IACpD,sBAAsB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAC5E,gBAAgB,EAAE,YAAY,CAAC,kBAAkB,CAAC,CAAC;IACnD,WAAW,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,YAAY,EAA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AAE,OAAO,CAAC;IAClB,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,gBAAgB,GAC7D,qCAAqC,CAAC;AAExC,MAAM,MAAM,8BAA8B,GAAG;IAC3C,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IAC7B,sBAAsB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAC5E,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC;IACpD,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,EACA,sBAAsB,CAAC,YAAY,GACnC,sBAAsB,CAAC,wBAAwB,CAAC;KACrD,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.137.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@reyaxyz/common": "0.
|
|
32
|
+
"@reyaxyz/common": "0.311.0",
|
|
33
33
|
"axios": "1.6.2",
|
|
34
34
|
"bignumber.js": "9.1.2",
|
|
35
35
|
"ethers": "6.9.0"
|
|
36
36
|
},
|
|
37
37
|
"packageManager": "pnpm@8.3.1",
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "820bf1d931672522440894ba3b13568bc7ea753e"
|
|
39
39
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from './types';
|
|
8
8
|
import { signAndBroadcastTransaction } from '../signAndBroadcastTransaction';
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
calculateMaxPriceLimit,
|
|
11
11
|
ORDERS_GATEWAY_DEADLINE_IN_SECONDS,
|
|
12
12
|
OrdersGatewayAbi,
|
|
13
13
|
OrdersGatewayOrderType,
|
|
@@ -107,12 +107,7 @@ export const matchOrder = async (
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const orderBaseE18 = scale(18)(snappedAmount);
|
|
110
|
-
const
|
|
111
|
-
const orderPriceLimitE18 = calculatePriceLimitForTrade(
|
|
112
|
-
params.market.currentPrice,
|
|
113
|
-
snappedAmount,
|
|
114
|
-
slippageFactor,
|
|
115
|
-
);
|
|
110
|
+
const orderPriceLimitE18 = calculateMaxPriceLimit(snappedAmount > 0);
|
|
116
111
|
|
|
117
112
|
const result = await executeMarketOrderViaOrdersGateway({
|
|
118
113
|
signer: params.signer,
|
|
@@ -174,12 +169,7 @@ export const closeOrder = async (
|
|
|
174
169
|
}
|
|
175
170
|
}
|
|
176
171
|
|
|
177
|
-
const
|
|
178
|
-
const orderPriceLimit = calculatePriceLimitForTrade(
|
|
179
|
-
params.market.currentPrice,
|
|
180
|
-
-closingBase,
|
|
181
|
-
slippageFactor,
|
|
182
|
-
);
|
|
172
|
+
const orderPriceLimit = calculateMaxPriceLimit(closingBase < 0);
|
|
183
173
|
|
|
184
174
|
const result = await executeMarketOrderViaOrdersGateway({
|
|
185
175
|
signer: params.signer,
|
|
@@ -14,7 +14,6 @@ export type MarketParams = {
|
|
|
14
14
|
id: MarketEntity['id'];
|
|
15
15
|
exchangeId: MarketEntity['orderInfo']['exchangeId'];
|
|
16
16
|
counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];
|
|
17
|
-
currentPrice: number;
|
|
18
17
|
minOrderSizeBase: MarketEntity['minOrderSizeBase'];
|
|
19
18
|
baseSpacing: MarketEntity['baseSpacing'];
|
|
20
19
|
};
|