@reyaxyz/sdk 0.134.36 → 0.136.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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/config/index.js +5 -23
  3. package/dist/config/index.js.map +1 -1
  4. package/dist/index.js +0 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/services/orders/order.js +3 -3
  7. package/dist/services/orders/order.js.map +1 -1
  8. package/dist/services/orders/types.js.map +1 -1
  9. package/dist/types/config/index.d.ts.map +1 -1
  10. package/dist/types/index.d.ts +0 -1
  11. package/dist/types/index.d.ts.map +1 -1
  12. package/dist/types/services/orders/order.d.ts.map +1 -1
  13. package/dist/types/services/orders/types.d.ts +0 -2
  14. package/dist/types/services/orders/types.d.ts.map +1 -1
  15. package/package.json +3 -3
  16. package/src/config/index.ts +4 -25
  17. package/src/index.ts +0 -1
  18. package/src/services/orders/order.ts +4 -4
  19. package/src/services/orders/types.ts +0 -2
  20. package/dist/services/isolated-order/index.js +0 -19
  21. package/dist/services/isolated-order/index.js.map +0 -1
  22. package/dist/services/isolated-order/isolatedOrder.js +0 -105
  23. package/dist/services/isolated-order/isolatedOrder.js.map +0 -1
  24. package/dist/services/isolated-order/types.js +0 -3
  25. package/dist/services/isolated-order/types.js.map +0 -1
  26. package/dist/types/services/isolated-order/index.d.ts +0 -3
  27. package/dist/types/services/isolated-order/index.d.ts.map +0 -1
  28. package/dist/types/services/isolated-order/isolatedOrder.d.ts +0 -3
  29. package/dist/types/services/isolated-order/isolatedOrder.d.ts.map +0 -1
  30. package/dist/types/services/isolated-order/types.d.ts +0 -23
  31. package/dist/types/services/isolated-order/types.d.ts.map +0 -1
  32. package/src/services/isolated-order/index.ts +0 -2
  33. package/src/services/isolated-order/isolatedOrder.ts +0 -75
  34. package/src/services/isolated-order/types.ts +0 -28
package/README.md CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-9.16%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-5.75%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-4.1%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-8.81%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-9.45%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-5.88%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-4.16%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-9.1%25-red.svg?style=flat) |
10
10
 
@@ -60,35 +60,17 @@ var TransactionModule = /** @class */ (function (_super) {
60
60
  }
61
61
  TransactionModule.prototype.executeTransaction = function (txData, contractAddress, metadata) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
- var isReyaExecutorEnabled, result, error_1;
63
+ var result;
64
64
  return __generator(this, function (_a) {
65
65
  switch (_a.label) {
66
- case 0:
67
- isReyaExecutorEnabled = process.env.IS_REYA_EXECUTOR_ENABLED === 'true' || false;
68
- if (!isReyaExecutorEnabled) return [3 /*break*/, 4];
69
- _a.label = 1;
70
- case 1:
71
- _a.trys.push([1, 3, , 4]);
72
- return [4 /*yield*/, this.post('/api/transaction-gelato/executeReya', {}, {
73
- txData: txData,
74
- contractAddress: contractAddress,
75
- metadata: metadata,
76
- })];
77
- case 2:
78
- result = _a.sent();
79
- if (result.txHash) {
80
- return [2 /*return*/, result];
81
- }
82
- return [3 /*break*/, 4];
83
- case 3:
84
- error_1 = _a.sent();
85
- console.warn('Reya executor failed', error_1);
86
- return [3 /*break*/, 4];
87
- case 4: return [2 /*return*/, this.post('/api/transaction-gelato/executeGelato', {}, {
66
+ case 0: return [4 /*yield*/, this.post('/api/transaction-gelato/executeReya', {}, {
88
67
  txData: txData,
89
68
  contractAddress: contractAddress,
90
69
  metadata: metadata,
91
70
  })];
71
+ case 1:
72
+ result = _a.sent();
73
+ return [2 /*return*/, result];
92
74
  }
93
75
  });
94
76
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAOyB;AAOzB;IAAuC,qCAAU;IAAjD;;IA6DA,CAAC;IA5DO,8CAAkB,GAAxB,UACE,MAAc,EACd,eAAuB,EACvB,QAAsC;;;;;;wBAEhC,qBAAqB,GACzB,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,MAAM,IAAI,KAAK,CAAC;6BAEvD,qBAAqB,EAArB,wBAAqB;;;;wBAEN,qBAAM,IAAI,CAAC,IAAI,CAC5B,qCAAqC,EACrC,EAAE,EACF;gCACE,MAAM,EAAE,MAAM;gCACd,eAAe,iBAAA;gCACf,QAAQ,UAAA;6BACT,CACF,EAAA;;wBARK,MAAM,GAAG,SAQd;wBAED,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;4BAClB,sBAAO,MAAM,EAAC;wBAChB,CAAC;;;;wBAED,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,OAAK,CAAC,CAAC;;4BAIhD,sBAAO,IAAI,CAAC,IAAI,CACd,uCAAuC,EACvC,EAAE,EACF;4BACE,MAAM,EAAE,MAAM;4BACd,eAAe,iBAAA;4BACf,QAAQ,UAAA;yBACT,CACF,EAAC;;;;KACH;IAEK,kDAAsB,GAA5B,UACE,eAAuB,EACvB,eAAuB,EACvB,aAAqB,EACrB,MAAc,EACd,OAAe,EACf,IAAY;;;;gBAEN,GAAG,GAAG,wBAAiB,eAAe,8BAA2B,CAAC;gBACxE,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF;wBACE,OAAO,EAAE,eAAe;wBACxB,eAAe,EAAE,aAAa;wBAC9B,MAAM,QAAA;wBACN,QAAQ,EAAE,OAAO;wBACjB,IAAI,EAAE,I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;IAChE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC","sourcesContent":["import {\n RestClient,\n ServiceConfig,\n TransactionExecutionMetadata,\n TransactionExecutionOutput,\n CollateralWithHaircut,\n getApiClientConfig,\n} from '@reyaxyz/common';\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: TransactionExecutionMetadata,\n ): Promise<TransactionExecutionOutput> {\n const isReyaExecutorEnabled =\n process.env.IS_REYA_EXECUTOR_ENABLED === 'true' || false;\n\n if (isReyaExecutorEnabled) {\n try {\n const result = await this.post<TransactionExecutionOutput>(\n '/api/transaction-gelato/executeReya',\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n\n if (result.txHash) {\n return result;\n }\n } catch (error) {\n console.warn('Reya executor failed', error);\n }\n }\n\n return this.post<TransactionExecutionOutput>(\n '/api/transaction-gelato/executeGelato',\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n }\n\n async pushPendingTransaction(\n marginAccountId: number,\n transactionHash: string,\n sourceChainId: number,\n amount: number,\n assetId: string,\n type: string,\n ) {\n const uri = `/api/accounts/${marginAccountId}/push-pending-transaction`;\n return this.post<{ successful: boolean }>(\n uri,\n {},\n {\n tx_hash: transactionHash,\n source_chain_id: sourceChainId,\n amount,\n asset_id: assetId,\n type: type,\n },\n );\n }\n}\n\nexport class GeneralRestModule extends RestClient {\n async getCollateralInfo(): Promise<CollateralWithHaircut[]> {\n return this.get<CollateralWithHaircut[]>(\n `/api/tokens/available-collaterals/excluding-rusd/${false}`,\n );\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n getApiClientConfig('test').apiEndpoint,\n);\n\nlet generalRestModule: GeneralRestModule = new GeneralRestModule(\n getApiClientConfig('test').apiEndpoint,\n);\n\nlet config: ServiceConfig;\n\nexport const getSdkConfig = (): ServiceConfig => {\n return config;\n};\n\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n config = getApiClientConfig(environment);\n transactionModule = new TransactionModule(config.apiEndpoint);\n generalRestModule = new GeneralRestModule(config.apiEndpoint);\n};\n\nexport const getTransactionModuleClient = (): TransactionModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return transactionModule;\n};\n\nexport const getGeneralRestModuleClient = (): GeneralRestModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return generalRestModule;\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAOyB;AAOzB;IAAuC,qCAAU;IAAjD;;IAwCA,CAAC;IAvCO,8CAAkB,GAAxB,UACE,MAAc,EACd,eAAuB,EACvB,QAAsC;;;;;4BAEvB,qBAAM,IAAI,CAAC,IAAI,CAC5B,qCAAqC,EACrC,EAAE,EACF;4BACE,MAAM,EAAE,MAAM;4BACd,eAAe,iBAAA;4BACf,QAAQ,UAAA;yBACT,CACF,EAAA;;wBARK,MAAM,GAAG,SAQd;wBAED,sBAAO,MAAM,EAAC;;;;KACf;IAEK,kDAAsB,GAA5B,UACE,eAAuB,EACvB,eAAuB,EACvB,aAAqB,EACrB,MAAc,EACd,OAAe,EACf,IAAY;;;;gBAEN,GAAG,GAAG,wBAAiB,eAAe,8BAA2B,CAAC;gBACxE,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF;wBACE,OAAO,EAAE,eAAe;wBACxB,eAAe,EAAE,aAAa;wBAC9B,MAAM,QAAA;wBACN,QAAQ,EAAE,OAAO;wBACjB,IAAI,EAAE,IAAI;qBACX,CACF,EAAC;;;KACH;IACH,wBAAC;AAAD,CAAC,AAxCD,CAAuC,mBAAU,GAwChD;AAxCY,8CAAiB;AA0C9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fig,\n TransactionExecutionMetadata,\n TransactionExecutionOutput,\n CollateralWithHaircut,\n getApiClientConfig,\n} from '@reyaxyz/common';\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: TransactionExecutionMetadata,\n ): Promise<TransactionExecutionOutput> {\n const result = await this.post<TransactionExecutionOutput>(\n '/api/transaction-gelato/executeReya',\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n\n return result;\n }\n\n async pushPendingTransaction(\n marginAccountId: number,\n transactionHash: string,\n sourceChainId: number,\n amount: number,\n assetId: string,\n type: string,\n ) {\n const uri = `/api/accounts/${marginAccountId}/push-pending-transaction`;\n return this.post<{ successful: boolean }>(\n uri,\n {},\n {\n tx_hash: transactionHash,\n source_chain_id: sourceChainId,\n amount,\n asset_id: assetId,\n type: type,\n },\n );\n }\n}\n\nexport class GeneralRestModule extends RestClient {\n async getCollateralInfo(): Promise<CollateralWithHaircut[]> {\n return this.get<CollateralWithHaircut[]>(\n `/api/tokens/available-collaterals/excluding-rusd/${false}`,\n );\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n getApiClientConfig('test').apiEndpoint,\n);\n\nlet generalRestModule: GeneralRestModule = new GeneralRestModule(\n getApiClientConfig('test').apiEndpoint,\n);\n\nlet config: ServiceConfig;\n\nexport const getSdkConfig = (): ServiceConfig => {\n return config;\n};\n\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n config = getApiClientConfig(environment);\n transactionModule = new TransactionModule(config.apiEndpoint);\n generalRestModule = new GeneralRestModule(config.apiEndpoint);\n};\n\nexport const getTransactionModuleClient = (): TransactionModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return transactionModule;\n};\n\nexport const getGeneralRestModuleClient = (): GeneralRestModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return generalRestModule;\n};\n"]}
package/dist/index.js CHANGED
@@ -20,7 +20,6 @@ __exportStar(require("./services/margin-accounts"), exports);
20
20
  __exportStar(require("./services/money-flows"), exports);
21
21
  __exportStar(require("./services/orders"), exports);
22
22
  __exportStar(require("./services/conditional-orders"), exports);
23
- __exportStar(require("./services/isolated-order"), exports);
24
23
  __exportStar(require("./services/token"), exports);
25
24
  var config_1 = require("./config");
26
25
  Object.defineProperty(exports, "configureSDK", { enumerable: true, get: function () { return config_1.configureSDK; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA2C;AAC3C,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAC9C,4DAA0C;AAC1C,mDAAiC;AACjC,mCAAoE;AAA3D,sGAAA,YAAY,OAAA;AAAE,oHAAA,0BAA0B,OAAA","sourcesContent":["export * from './services/lp';\nexport * from './services/margin-accounts';\nexport * from './services/money-flows';\nexport * from './services/orders';\nexport * from './services/conditional-orders';\nexport * from './services/isolated-order';\nexport * from './services/token';\nexport { configureSDK, getTransactionModuleClient } from './config';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA2C;AAC3C,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAC9C,mDAAiC;AACjC,mCAAoE;AAA3D,sGAAA,YAAY,OAAA;AAAE,oHAAA,0BAA0B,OAAA","sourcesContent":["export * from './services/lp';\nexport * from './services/margin-accounts';\nexport * from './services/money-flows';\nexport * from './services/orders';\nexport * from './services/conditional-orders';\nexport * from './services/token';\nexport { configureSDK, getTransactionModuleClient } from './config';\n"]}
@@ -48,7 +48,7 @@ var common_3 = require("@reyaxyz/common");
48
48
  var network_1 = require("../../utils/network");
49
49
  var ethers_1 = require("ethers");
50
50
  var executeMarketOrderViaOrdersGateway = function (params) { return __awaiter(void 0, void 0, void 0, function () {
51
- var inputs, reyaChainId, creationTimestampMs, creationTimestampSeconds, _a, signature, nonce, fnSig, fnArgs, _b, ogInterface, data, result;
51
+ var inputs, reyaChainId, creationTimestampMs, creationTimestampSeconds, _a, signature, nonce, fnSig, fnArgs, _b, ogInterface, data, isFastExecutionEnabled, result;
52
52
  return __generator(this, function (_c) {
53
53
  switch (_c.label) {
54
54
  case 0:
@@ -77,10 +77,12 @@ var executeMarketOrderViaOrdersGateway = function (params) { return __awaiter(vo
77
77
  ];
78
78
  ogInterface = new ethers_1.Interface(common_1.OrdersGatewayAbi);
79
79
  data = ogInterface.encodeFunctionData(fnSig, fnArgs);
80
+ isFastExecutionEnabled = process.env.FAST_ORDER_EXECUTION === 'true' || false;
80
81
  return [4 /*yield*/, (0, signAndBroadcastTransaction_1.signAndBroadcastTransaction)(data, reyaChainId, common_2.ContractType.ORDERS_GATEWAY_PROXY, {
81
82
  accountId: params.marginAccountId,
82
83
  marketId: params.marketId,
83
84
  tradeSource: params.tradeSource,
85
+ action: isFastExecutionEnabled ? 'ioc-order-ui' : undefined,
84
86
  })];
85
87
  case 3:
86
88
  result = _c.sent();
@@ -94,7 +96,6 @@ var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
94
96
  return __generator(this, function (_g) {
95
97
  switch (_g.label) {
96
98
  case 0:
97
- console.log('match order execution v2');
98
99
  if (params.amountInBase === 0) {
99
100
  throw new Error('Order cannot be of size zero.');
100
101
  }
@@ -153,7 +154,6 @@ var closeOrder = function (params) { return __awaiter(void 0, void 0, void 0, fu
153
154
  return __generator(this, function (_g) {
154
155
  switch (_g.label) {
155
156
  case 0:
156
- console.log('close order execution v2');
157
157
  if (params.orderBase === 0) {
158
158
  throw new Error('Position is already closed.');
159
159
  }
@@ -1 +1 @@
1
- {"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;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MAAA,MAAM,CAAC,YAAY,0CAAE,cAAc,KAAI,CAAC;wBACxD,IAAI,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,IAAI,KAAI,CAAC;qBACrC,EAAC;;;KACH,CAAC;AA/DW,QAAA,UAAU,cA+DrB","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 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 },\n );\n\n return result;\n};\n\nexport const matchOrder = async (\n params: MatchOrderParams,\n): Promise<MatchOrderResult> => {\n console.log('match order execution v2');\n\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 console.log('close order execution v2');\n\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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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 +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 currentPrice: number;\n minOrderSizeBase: MarketEntity['minOrderSizeBase'];\n baseSpacing: MarketEntity['baseSpacing'];\n};\n\nexport type MatchOrderParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\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 owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\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
+ {"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 currentPrice: number;\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":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,4BAA4B,EAC5B,0BAA0B,EAC1B,qBAAqB,EAEtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,4BAA4B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AO,MAAM,YAAY,QAAO,aAE/B,CAAC;AAGF,eAAO,MAAM,YAAY,gBACV,aAAa,CAAC,aAAa,CAAC,KACxC,IAIF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC"}
@@ -3,7 +3,6 @@ export * from './services/margin-accounts';
3
3
  export * from './services/money-flows';
4
4
  export * from './services/orders';
5
5
  export * from './services/conditional-orders';
6
- export * from './services/isolated-order';
7
6
  export * from './services/token';
8
7
  export { configureSDK, getTransactionModuleClient } from './config';
9
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC"}
@@ -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;AAyEjB,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CA6D1B,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CA6D1B,CAAC"}
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,CA2D1B,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CA2D1B,CAAC"}
@@ -10,7 +10,6 @@ export type MarketParams = {
10
10
  };
11
11
  export type MatchOrderParams = {
12
12
  signer: Signer | JsonRpcSigner;
13
- owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
14
13
  marginAccountId: MarginAccountEntity['id'];
15
14
  amountInBase: number;
16
15
  market: MarketParams;
@@ -18,7 +17,6 @@ export type MatchOrderParams = {
18
17
  };
19
18
  export type CloseOrderParams = {
20
19
  signer: Signer | JsonRpcSigner;
21
- owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
22
20
  marginAccountId: MarginAccountEntity['id'];
23
21
  orderBase: PositionEntity['base'];
24
22
  market: MarketParams;
@@ -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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AAQ,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.134.36",
3
+ "version": "0.136.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.304.0",
32
+ "@reyaxyz/common": "0.305.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": "e27bdaa0240fd1e8b2a38a27586a1757737b52e4"
38
+ "gitHead": "50889c5e771c392ca79306bbcdcec44d32eadc7d"
39
39
  }
@@ -18,31 +18,8 @@ export class TransactionModule extends RestClient {
18
18
  contractAddress: string,
19
19
  metadata: TransactionExecutionMetadata,
20
20
  ): Promise<TransactionExecutionOutput> {
21
- const isReyaExecutorEnabled =
22
- process.env.IS_REYA_EXECUTOR_ENABLED === 'true' || false;
23
-
24
- if (isReyaExecutorEnabled) {
25
- try {
26
- const result = await this.post<TransactionExecutionOutput>(
27
- '/api/transaction-gelato/executeReya',
28
- {},
29
- {
30
- txData: txData,
31
- contractAddress,
32
- metadata,
33
- },
34
- );
35
-
36
- if (result.txHash) {
37
- return result;
38
- }
39
- } catch (error) {
40
- console.warn('Reya executor failed', error);
41
- }
42
- }
43
-
44
- return this.post<TransactionExecutionOutput>(
45
- '/api/transaction-gelato/executeGelato',
21
+ const result = await this.post<TransactionExecutionOutput>(
22
+ '/api/transaction-gelato/executeReya',
46
23
  {},
47
24
  {
48
25
  txData: txData,
@@ -50,6 +27,8 @@ export class TransactionModule extends RestClient {
50
27
  metadata,
51
28
  },
52
29
  );
30
+
31
+ return result;
53
32
  }
54
33
 
55
34
  async pushPendingTransaction(
package/src/index.ts CHANGED
@@ -3,6 +3,5 @@ export * from './services/margin-accounts';
3
3
  export * from './services/money-flows';
4
4
  export * from './services/orders';
5
5
  export * from './services/conditional-orders';
6
- export * from './services/isolated-order';
7
6
  export * from './services/token';
8
7
  export { configureSDK, getTransactionModuleClient } from './config';
@@ -63,6 +63,9 @@ const executeMarketOrderViaOrdersGateway = async (
63
63
  const ogInterface = new Interface(OrdersGatewayAbi);
64
64
  const data = ogInterface.encodeFunctionData(fnSig, fnArgs);
65
65
 
66
+ const isFastExecutionEnabled =
67
+ process.env.FAST_ORDER_EXECUTION === 'true' || false;
68
+
66
69
  const result = await signAndBroadcastTransaction(
67
70
  data,
68
71
  reyaChainId,
@@ -71,6 +74,7 @@ const executeMarketOrderViaOrdersGateway = async (
71
74
  accountId: params.marginAccountId,
72
75
  marketId: params.marketId,
73
76
  tradeSource: params.tradeSource,
77
+ action: isFastExecutionEnabled ? 'ioc-order-ui' : undefined,
74
78
  },
75
79
  );
76
80
 
@@ -80,8 +84,6 @@ const executeMarketOrderViaOrdersGateway = async (
80
84
  export const matchOrder = async (
81
85
  params: MatchOrderParams,
82
86
  ): Promise<MatchOrderResult> => {
83
- console.log('match order execution v2');
84
-
85
87
  if (params.amountInBase === 0) {
86
88
  throw new Error('Order cannot be of size zero.');
87
89
  }
@@ -145,8 +147,6 @@ export const matchOrder = async (
145
147
  export const closeOrder = async (
146
148
  params: CloseOrderParams,
147
149
  ): Promise<CloseOrderResult> => {
148
- console.log('close order execution v2');
149
-
150
150
  if (params.orderBase === 0) {
151
151
  throw new Error('Position is already closed.');
152
152
  }
@@ -21,7 +21,6 @@ export type MarketParams = {
21
21
 
22
22
  export type MatchOrderParams = {
23
23
  signer: Signer | JsonRpcSigner;
24
- owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
25
24
  marginAccountId: MarginAccountEntity['id'];
26
25
  amountInBase: number; // amount in base
27
26
  market: MarketParams;
@@ -30,7 +29,6 @@ export type MatchOrderParams = {
30
29
 
31
30
  export type CloseOrderParams = {
32
31
  signer: Signer | JsonRpcSigner;
33
- owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
34
32
  marginAccountId: MarginAccountEntity['id'];
35
33
  orderBase: PositionEntity['base'];
36
34
  market: MarketParams;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./isolatedOrder"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["services/isolated-order/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,kDAAgC","sourcesContent":["export * from './types';\nexport * from './isolatedOrder';\n"]}
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.isolatedOrder = void 0;
40
- var margin_accounts_1 = require("../margin-accounts");
41
- var orders_1 = require("../orders");
42
- var isolatedOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
43
- var createAccountResult, _i, _a, action, ownerWithBumpedNonce, matchOrderResult;
44
- return __generator(this, function (_b) {
45
- switch (_b.label) {
46
- case 0: return [4 /*yield*/, (0, margin_accounts_1.createAccount)({
47
- ownerAddress: params.owner.address,
48
- name: 'Isolated Trade Account',
49
- })];
50
- case 1:
51
- createAccountResult = _b.sent();
52
- if (!createAccountResult.accountId) {
53
- throw new Error('New Account Id not available to execute isolated trade');
54
- }
55
- _i = 0, _a = params.editCollateralActions;
56
- _b.label = 2;
57
- case 2:
58
- if (!(_i < _a.length)) return [3 /*break*/, 5];
59
- action = _a[_i];
60
- // todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)
61
- return [4 /*yield*/, (0, margin_accounts_1.transferMarginBetweenAccounts)({
62
- signer: params.signer,
63
- owner: params.owner,
64
- fromMarginAccountId: params.fromMarginAccountId,
65
- toMarginAccountId: createAccountResult.accountId,
66
- amount: Math.abs(action.collateralDelta),
67
- tokenAddress: action.collateralAddress,
68
- })];
69
- case 3:
70
- // todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)
71
- _b.sent();
72
- _b.label = 4;
73
- case 4:
74
- _i++;
75
- return [3 /*break*/, 2];
76
- case 5:
77
- ownerWithBumpedNonce = {
78
- coreSigNonce: params.owner.coreSigNonce + 1,
79
- address: params.owner.address,
80
- };
81
- return [4 /*yield*/, (0, orders_1.matchOrder)({
82
- signer: params.signer,
83
- owner: ownerWithBumpedNonce,
84
- marginAccountId: createAccountResult.accountId,
85
- amountInBase: params.amountInBase,
86
- market: params.market,
87
- })];
88
- case 6:
89
- matchOrderResult = _b.sent();
90
- return [2 /*return*/, {
91
- transactionHash: (matchOrderResult === null || matchOrderResult === void 0 ? void 0 : matchOrderResult.transactionHash) || null,
92
- coreSigNonce: matchOrderResult.coreSigNonce,
93
- xpBoost: matchOrderResult.xpBoost,
94
- lotteryXpBoost: matchOrderResult.lotteryXpBoost,
95
- isNftWon: matchOrderResult.isNftWon,
96
- marginAccountId: createAccountResult.accountId,
97
- xpEarned: matchOrderResult.xpEarned,
98
- executionPrice: matchOrderResult.executionPrice,
99
- base: matchOrderResult.base,
100
- }];
101
- }
102
- });
103
- }); };
104
- exports.isolatedOrder = isolatedOrder;
105
- //# sourceMappingURL=isolatedOrder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isolatedOrder.js","sourceRoot":"/","sources":["services/isolated-order/isolatedOrder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAG4B;AAC5B,oCAAuC;AAGhC,IAAM,aAAa,GAAG,UAC3B,MAA2B;;;;oBAQC,qBAAM,IAAA,+BAAa,EAAC;oBAC9C,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;oBAClC,IAAI,EAAE,wBAAwB;iBAC/B,CAAC,EAAA;;gBAHI,mBAAmB,GAAG,SAG1B;gBAEF,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;gBAC5E,CAAC;sBAIgD,EAA5B,KAAA,MAAM,CAAC,qBAAqB;;;qBAA5B,CAAA,cAA4B,CAAA;gBAAtC,MAAM;gBACf,6FAA6F;gBAC7F,qBAAM,IAAA,+CAA6B,EAAC;wBAClC,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;wBAC/C,iBAAiB,EAAE,mBAAmB,CAAC,SAAS;wBAChD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC;wBACxC,YAAY,EAAE,MAAM,CAAC,iBAAiB;qBACvC,CAAC,EAAA;;gBARF,6FAA6F;gBAC7F,SAOE,CAAC;;;gBATgB,IAA4B,CAAA;;;gBAkB3C,oBAAoB,GAGtB;oBACF,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC;oBAC3C,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;iBAC9B,CAAC;gBAGuB,qBAAM,IAAA,mBAAU,EAAC;wBACxC,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,KAAK,EAAE,oBAAoB;wBAC3B,eAAe,EAAE,mBAAmB,CAAC,SAAS;wBAC9C,YAAY,EAAE,MAAM,CAAC,YAAY;wBACjC,MAAM,EAAE,MAAM,CAAC,MAAM;qBACtB,CAAC,EAAA;;gBANI,gBAAgB,GAAG,SAMvB;gBAEF,sBAAO;wBACL,eAAe,EAAE,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,eAAe,KAAI,IAAI;wBAC1D,YAAY,EAAE,gBAAgB,CAAC,YAAY;wBAC3C,OAAO,EAAE,gBAAgB,CAAC,OAAO;wBACjC,cAAc,EAAE,gBAAgB,CAAC,cAAc;wBAC/C,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;wBACnC,eAAe,EAAE,mBAAmB,CAAC,SAAS;wBAC9C,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;wBACnC,cAAc,EAAE,gBAAgB,CAAC,cAAc;wBAC/C,IAAI,EAAE,gBAAgB,CAAC,IAAI;qBAC5B,EAAC;;;KACH,CAAC;AAlEW,QAAA,aAAa,iBAkExB","sourcesContent":["import { IsolatedOrderParams, IsolatedOrderResult } from './types';\nimport {\n createAccount,\n transferMarginBetweenAccounts,\n} from '../margin-accounts';\nimport { matchOrder } from '../orders';\nimport { OwnerMetadataEntity } from '@reyaxyz/common';\n\nexport const isolatedOrder = async (\n params: IsolatedOrderParams,\n): Promise<IsolatedOrderResult> => {\n // todo: p2 consider performing all steps in api and only call one api function from here?\n\n // step 1: create new account\n\n // todo: p2: consider having a function that creates an account and auto-generates a name in one go, use it t&cs also\n // todo: p2: error handling & logging\n const createAccountResult = await createAccount({\n ownerAddress: params.owner.address,\n name: 'Isolated Trade Account',\n });\n\n if (!createAccountResult.accountId) {\n throw new Error('New Account Id not available to execute isolated trade');\n }\n\n // step 2: transfer margin from source to destination account\n\n for (const action of params.editCollateralActions) {\n // todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)\n await transferMarginBetweenAccounts({\n signer: params.signer,\n owner: params.owner,\n fromMarginAccountId: params.fromMarginAccountId,\n toMarginAccountId: createAccountResult.accountId,\n amount: Math.abs(action.collateralDelta),\n tokenAddress: action.collateralAddress,\n });\n }\n\n // step 3: execute trade\n\n /*\n * We need to bump the nonce since we've just executed a transfer transaction\n * */\n\n const ownerWithBumpedNonce: Pick<\n OwnerMetadataEntity,\n 'coreSigNonce' | 'address'\n > = {\n coreSigNonce: params.owner.coreSigNonce + 1,\n address: params.owner.address,\n };\n\n // todo: p1: need to increase the nonce for this tx as well\n const matchOrderResult = await matchOrder({\n signer: params.signer,\n owner: ownerWithBumpedNonce,\n marginAccountId: createAccountResult.accountId,\n amountInBase: params.amountInBase,\n market: params.market,\n });\n\n return {\n transactionHash: matchOrderResult?.transactionHash || null,\n coreSigNonce: matchOrderResult.coreSigNonce,\n xpBoost: matchOrderResult.xpBoost,\n lotteryXpBoost: matchOrderResult.lotteryXpBoost,\n isNftWon: matchOrderResult.isNftWon,\n marginAccountId: createAccountResult.accountId,\n xpEarned: matchOrderResult.xpEarned,\n executionPrice: matchOrderResult.executionPrice,\n base: matchOrderResult.base,\n };\n};\n"]}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["services/isolated-order/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer, JsonRpcSigner } from 'ethers';\nimport {\n EditCollateralAction,\n MarginAccountEntity,\n OwnerMetadataEntity,\n} from '@reyaxyz/common';\nimport { MarketParams } from '../orders';\n\nexport type IsolatedOrderParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce' | 'address'>;\n fromMarginAccountId: MarginAccountEntity['id'];\n editCollateralActions: EditCollateralAction[]; // todo: p2: consider abstracting this such that UI doesn't pass this\n amountInBase: number;\n market: MarketParams;\n};\n\nexport type IsolatedOrderResult = {\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"]}
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './isolatedOrder';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/isolated-order/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC"}
@@ -1,3 +0,0 @@
1
- import { IsolatedOrderParams, IsolatedOrderResult } from './types';
2
- export declare const isolatedOrder: (params: IsolatedOrderParams) => Promise<IsolatedOrderResult>;
3
- //# sourceMappingURL=isolatedOrder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isolatedOrder.d.ts","sourceRoot":"/","sources":["services/isolated-order/isolatedOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAQnE,eAAO,MAAM,aAAa,WAChB,mBAAmB,KAC1B,QAAQ,mBAAmB,CAgE7B,CAAC"}
@@ -1,23 +0,0 @@
1
- import { Signer, JsonRpcSigner } from 'ethers';
2
- import { EditCollateralAction, MarginAccountEntity, OwnerMetadataEntity } from '@reyaxyz/common';
3
- import { MarketParams } from '../orders';
4
- export type IsolatedOrderParams = {
5
- signer: Signer | JsonRpcSigner;
6
- owner: Pick<OwnerMetadataEntity, 'coreSigNonce' | 'address'>;
7
- fromMarginAccountId: MarginAccountEntity['id'];
8
- editCollateralActions: EditCollateralAction[];
9
- amountInBase: number;
10
- market: MarketParams;
11
- };
12
- export type IsolatedOrderResult = {
13
- transactionHash: string | null;
14
- coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;
15
- xpBoost: number;
16
- lotteryXpBoost: number;
17
- isNftWon: boolean;
18
- marginAccountId: MarginAccountEntity['id'];
19
- xpEarned: number;
20
- executionPrice: number;
21
- base: number;
22
- };
23
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/isolated-order/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC;IAC7D,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC/C,qBAAqB,EAAE,oBAAoB,EAAE,CAAC;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,YAAY,EAAE,mBAAmB,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,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"}
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './isolatedOrder';
@@ -1,75 +0,0 @@
1
- import { IsolatedOrderParams, IsolatedOrderResult } from './types';
2
- import {
3
- createAccount,
4
- transferMarginBetweenAccounts,
5
- } from '../margin-accounts';
6
- import { matchOrder } from '../orders';
7
- import { OwnerMetadataEntity } from '@reyaxyz/common';
8
-
9
- export const isolatedOrder = async (
10
- params: IsolatedOrderParams,
11
- ): Promise<IsolatedOrderResult> => {
12
- // todo: p2 consider performing all steps in api and only call one api function from here?
13
-
14
- // step 1: create new account
15
-
16
- // todo: p2: consider having a function that creates an account and auto-generates a name in one go, use it t&cs also
17
- // todo: p2: error handling & logging
18
- const createAccountResult = await createAccount({
19
- ownerAddress: params.owner.address,
20
- name: 'Isolated Trade Account',
21
- });
22
-
23
- if (!createAccountResult.accountId) {
24
- throw new Error('New Account Id not available to execute isolated trade');
25
- }
26
-
27
- // step 2: transfer margin from source to destination account
28
-
29
- for (const action of params.editCollateralActions) {
30
- // todo: p1: pack transfers into a single tx with multiple transfer commands (core sig issue)
31
- await transferMarginBetweenAccounts({
32
- signer: params.signer,
33
- owner: params.owner,
34
- fromMarginAccountId: params.fromMarginAccountId,
35
- toMarginAccountId: createAccountResult.accountId,
36
- amount: Math.abs(action.collateralDelta),
37
- tokenAddress: action.collateralAddress,
38
- });
39
- }
40
-
41
- // step 3: execute trade
42
-
43
- /*
44
- * We need to bump the nonce since we've just executed a transfer transaction
45
- * */
46
-
47
- const ownerWithBumpedNonce: Pick<
48
- OwnerMetadataEntity,
49
- 'coreSigNonce' | 'address'
50
- > = {
51
- coreSigNonce: params.owner.coreSigNonce + 1,
52
- address: params.owner.address,
53
- };
54
-
55
- // todo: p1: need to increase the nonce for this tx as well
56
- const matchOrderResult = await matchOrder({
57
- signer: params.signer,
58
- owner: ownerWithBumpedNonce,
59
- marginAccountId: createAccountResult.accountId,
60
- amountInBase: params.amountInBase,
61
- market: params.market,
62
- });
63
-
64
- return {
65
- transactionHash: matchOrderResult?.transactionHash || null,
66
- coreSigNonce: matchOrderResult.coreSigNonce,
67
- xpBoost: matchOrderResult.xpBoost,
68
- lotteryXpBoost: matchOrderResult.lotteryXpBoost,
69
- isNftWon: matchOrderResult.isNftWon,
70
- marginAccountId: createAccountResult.accountId,
71
- xpEarned: matchOrderResult.xpEarned,
72
- executionPrice: matchOrderResult.executionPrice,
73
- base: matchOrderResult.base,
74
- };
75
- };
@@ -1,28 +0,0 @@
1
- import { Signer, JsonRpcSigner } from 'ethers';
2
- import {
3
- EditCollateralAction,
4
- MarginAccountEntity,
5
- OwnerMetadataEntity,
6
- } from '@reyaxyz/common';
7
- import { MarketParams } from '../orders';
8
-
9
- export type IsolatedOrderParams = {
10
- signer: Signer | JsonRpcSigner;
11
- owner: Pick<OwnerMetadataEntity, 'coreSigNonce' | 'address'>;
12
- fromMarginAccountId: MarginAccountEntity['id'];
13
- editCollateralActions: EditCollateralAction[]; // todo: p2: consider abstracting this such that UI doesn't pass this
14
- amountInBase: number;
15
- market: MarketParams;
16
- };
17
-
18
- export type IsolatedOrderResult = {
19
- transactionHash: string | null;
20
- coreSigNonce: OwnerMetadataEntity['coreSigNonce'] | null;
21
- xpBoost: number;
22
- lotteryXpBoost: number;
23
- isNftWon: boolean;
24
- marginAccountId: MarginAccountEntity['id'];
25
- xpEarned: number;
26
- executionPrice: number;
27
- base: number;
28
- };