@reyaxyz/common 0.344.0 → 0.344.1-perpob.135

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 (85) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/exposure/command.js +8 -22
  3. package/dist/commands/exposure/command.js.map +1 -1
  4. package/dist/incentives-api-types.js.map +1 -1
  5. package/dist/rest/helpers/constants.js +12 -0
  6. package/dist/rest/helpers/constants.js.map +1 -1
  7. package/dist/trading-api-types.js.map +1 -1
  8. package/dist/transactions/abis/Errors.json +276 -1
  9. package/dist/transactions/abis/OrdersGateway.json +691 -119
  10. package/dist/transactions/abis/PassivePerpProxy.json +537 -0
  11. package/dist/transactions/buildMulticallTx.js.map +1 -1
  12. package/dist/transactions/contractAddresses.js +33 -4
  13. package/dist/transactions/contractAddresses.js.map +1 -1
  14. package/dist/transactions/executeTransaction.js +8 -123
  15. package/dist/transactions/executeTransaction.js.map +1 -1
  16. package/dist/transactions/sign.js +234 -1
  17. package/dist/transactions/sign.js.map +1 -1
  18. package/dist/types/commands/exposure/command.d.ts +8 -7
  19. package/dist/types/commands/exposure/command.d.ts.map +1 -1
  20. package/dist/types/incentives-api-types.d.ts +6 -2
  21. package/dist/types/incentives-api-types.d.ts.map +1 -1
  22. package/dist/types/rest/helpers/constants.d.ts +1 -1
  23. package/dist/types/rest/helpers/constants.d.ts.map +1 -1
  24. package/dist/types/trading-api-types.d.ts +123 -31
  25. package/dist/types/trading-api-types.d.ts.map +1 -1
  26. package/dist/types/transactions/buildMulticallTx.d.ts +1 -0
  27. package/dist/types/transactions/buildMulticallTx.d.ts.map +1 -1
  28. package/dist/types/transactions/contractAddresses.d.ts +1 -1
  29. package/dist/types/transactions/contractAddresses.d.ts.map +1 -1
  30. package/dist/types/transactions/executeTransaction.d.ts +2 -15
  31. package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
  32. package/dist/types/transactions/sign.d.ts +38 -1
  33. package/dist/types/transactions/sign.d.ts.map +1 -1
  34. package/dist/types/types.d.ts +44 -18
  35. package/dist/types/types.d.ts.map +1 -1
  36. package/dist/types/utils/calculate.d.ts +14 -2
  37. package/dist/types/utils/calculate.d.ts.map +1 -1
  38. package/dist/types/utils/layerzero.d.ts +22 -0
  39. package/dist/types/utils/layerzero.d.ts.map +1 -0
  40. package/dist/types/utils/token/batch-token-getters.d.ts +0 -5
  41. package/dist/types/utils/token/batch-token-getters.d.ts.map +1 -1
  42. package/dist/types/utils/token/token-getters.d.ts +0 -2
  43. package/dist/types/utils/token/token-getters.d.ts.map +1 -1
  44. package/dist/types.js +51 -7
  45. package/dist/types.js.map +1 -1
  46. package/dist/utils/calculate.js +137 -16
  47. package/dist/utils/calculate.js.map +1 -1
  48. package/dist/utils/layerzero.js +31 -0
  49. package/dist/utils/layerzero.js.map +1 -0
  50. package/dist/utils/token/batch-token-getters.js +13 -64
  51. package/dist/utils/token/batch-token-getters.js.map +1 -1
  52. package/dist/utils/token/token-getters.js +1 -42
  53. package/dist/utils/token/token-getters.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/commands/exposure/command.ts +8 -38
  56. package/src/incentives-api-types.ts +11 -5
  57. package/src/rest/helpers/constants.ts +22 -0
  58. package/src/trading-api-types.ts +128 -47
  59. package/src/transactions/abis/Errors.json +4148 -3873
  60. package/src/transactions/abis/OrdersGateway.json +692 -120
  61. package/src/transactions/abis/PassivePerpProxy.json +537 -0
  62. package/src/transactions/buildMulticallTx.ts +4 -0
  63. package/src/transactions/contractAddresses.ts +34 -4
  64. package/src/transactions/executeTransaction.ts +2 -130
  65. package/src/transactions/sign.ts +302 -0
  66. package/src/types.ts +70 -19
  67. package/src/utils/calculate.ts +181 -21
  68. package/src/utils/layerzero.ts +66 -0
  69. package/src/utils/token/batch-token-getters.ts +0 -28
  70. package/src/utils/token/token-getters.ts +0 -29
  71. package/dist/types/utils/layerzero/index.d.ts +0 -3
  72. package/dist/types/utils/layerzero/index.d.ts.map +0 -1
  73. package/dist/types/utils/layerzero/oft-config.d.ts +0 -4
  74. package/dist/types/utils/layerzero/oft-config.d.ts.map +0 -1
  75. package/dist/types/utils/layerzero/types.d.ts +0 -23
  76. package/dist/types/utils/layerzero/types.d.ts.map +0 -1
  77. package/dist/utils/layerzero/index.js +0 -19
  78. package/dist/utils/layerzero/index.js.map +0 -1
  79. package/dist/utils/layerzero/oft-config.js +0 -29
  80. package/dist/utils/layerzero/oft-config.js.map +0 -1
  81. package/dist/utils/layerzero/types.js +0 -3
  82. package/dist/utils/layerzero/types.js.map +0 -1
  83. package/src/utils/layerzero/index.ts +0 -2
  84. package/src/utils/layerzero/oft-config.ts +0 -32
  85. package/src/utils/layerzero/types.ts +0 -25
@@ -46,117 +46,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
- var _a;
50
49
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.decodeErrorBytes = exports.executeTransaction = exports.estimateGasFromTxAndChainId = exports.estimateGasGivenAddress = exports.estimateGas = void 0;
52
- var ethers_1 = require("ethers");
50
+ exports.executeTransaction = void 0;
53
51
  var types_1 = require("../types");
54
52
  var contractAddresses_1 = require("./contractAddresses");
55
53
  var Errors_json_1 = require("./abis/Errors.json");
56
54
  var ethers_decode_error_1 = require("ethers-decode-error");
57
55
  var txHelpers_1 = require("./txHelpers");
58
- var utils_1 = require("../utils");
59
- var ethers_2 = require("ethers");
60
- var reyaChainIdRPCMapper = (_a = {},
61
- _a[types_1.ReyaChainId.reyaNetwork] = 'https://rpc.reya.network/263e76b89da84d478fd2b6e8783a1cfe',
62
- _a[types_1.ReyaChainId.reyaCronos] = 'https://rpc.reya-cronos.gelato.digital/263e76b89da84d478fd2b6e8783a1cfe',
63
- _a);
64
56
  var errorDecoder = ethers_decode_error_1.ErrorDecoder.create([Errors_json_1.abi]);
65
- function estimateGas(signer, data, value, chainId, targetContract) {
66
- return __awaiter(this, void 0, void 0, function () {
67
- var accountAddress;
68
- return __generator(this, function (_a) {
69
- switch (_a.label) {
70
- case 0: return [4 /*yield*/, signer.getAddress()];
71
- case 1:
72
- accountAddress = _a.sent();
73
- return [2 /*return*/, estimateGasGivenAddress(accountAddress, data, value, chainId, targetContract)];
74
- }
75
- });
76
- });
77
- }
78
- exports.estimateGas = estimateGas;
79
- // TODO: deprecate this when /executeGelato is gone
80
- function estimateGasGivenAddress(accountAddress, data, value, chainId, targetContract) {
81
- return __awaiter(this, void 0, void 0, function () {
82
- var contractAddress, tx, gasLimit, network, provider, error_1, decodedError, reason, maxPriorityFeePerGas, maxFeePerGas;
83
- return __generator(this, function (_a) {
84
- switch (_a.label) {
85
- case 0:
86
- contractAddress = Object.values(contractAddresses_1.ContractType).includes(targetContract)
87
- ? (0, contractAddresses_1.getAddress)(chainId, targetContract)
88
- : targetContract;
89
- tx = __assign({ from: accountAddress, to: contractAddress, data: data }, (value && value !== '0' ? { value: value } : {}));
90
- gasLimit = BigInt('5000000');
91
- _a.label = 1;
92
- case 1:
93
- _a.trys.push([1, 3, , 5]);
94
- network = new ethers_1.Network('Reya', chainId);
95
- provider = new ethers_1.JsonRpcProvider(reyaChainIdRPCMapper[chainId], network, {
96
- staticNetwork: network,
97
- pollingInterval: 50,
98
- });
99
- return [4 /*yield*/, provider.call(tx)];
100
- case 2:
101
- _a.sent();
102
- return [3 /*break*/, 5];
103
- case 3:
104
- error_1 = _a.sent();
105
- return [4 /*yield*/, errorDecoder.decode(error_1)];
106
- case 4:
107
- decodedError = _a.sent();
108
- reason = customReasonMapper(decodedError);
109
- console.error("Error simulating transaction account address ".concat(accountAddress, " reason ").concat(decodedError === null || decodedError === void 0 ? void 0 : decodedError.name, " ").concat(decodedError, " ").concat(error_1));
110
- throw new Error(reason);
111
- case 5:
112
- if (Object.values(types_1.ReyaChainId).includes(chainId)) {
113
- maxPriorityFeePerGas = BigInt('0');
114
- maxFeePerGas = BigInt('100000000');
115
- return [2 /*return*/, __assign(__assign({}, tx), { gasLimit: gasLimit, maxPriorityFeePerGas: maxPriorityFeePerGas, maxFeePerGas: maxFeePerGas })];
116
- }
117
- return [2 /*return*/, __assign(__assign({}, tx), { gasLimit: gasLimit })];
118
- }
119
- });
120
- });
121
- }
122
- exports.estimateGasGivenAddress = estimateGasGivenAddress;
123
- function estimateGasFromTxAndChainId(chainId, tx) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- var rpcUrls, lastError, _i, rpcUrls_1, url, provider, estimation, error_2;
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0:
129
- rpcUrls = (0, utils_1.getPublicRpcUrlsOrThrow)(chainId);
130
- lastError = null;
131
- _i = 0, rpcUrls_1 = rpcUrls;
132
- _a.label = 1;
133
- case 1:
134
- if (!(_i < rpcUrls_1.length)) return [3 /*break*/, 6];
135
- url = rpcUrls_1[_i];
136
- _a.label = 2;
137
- case 2:
138
- _a.trys.push([2, 4, , 5]);
139
- provider = new ethers_1.ethers.JsonRpcProvider(url);
140
- return [4 /*yield*/, provider.estimateGas(tx)];
141
- case 3:
142
- estimation = _a.sent();
143
- return [2 /*return*/, addGasBuffer(estimation)];
144
- case 4:
145
- error_2 = _a.sent();
146
- lastError = error_2;
147
- return [3 /*break*/, 5];
148
- case 5:
149
- _i++;
150
- return [3 /*break*/, 1];
151
- case 6: throw new Error('All RPC URLs failed; last error: ' + lastError);
152
- }
153
- });
154
- });
155
- }
156
- exports.estimateGasFromTxAndChainId = estimateGasFromTxAndChainId;
157
57
  function estimateGasExternalChains(signer, data, value, chainId, targetContract) {
158
58
  return __awaiter(this, void 0, void 0, function () {
159
- var accountAddress, contractAddress, tx, gasLimit, gasEstimate, error_3, decodedError, reason, maxPriorityFeePerGas, maxFeePerGas;
59
+ var accountAddress, contractAddress, tx, gasLimit, gasEstimate, error_1, decodedError, reason, maxPriorityFeePerGas, maxFeePerGas;
160
60
  return __generator(this, function (_a) {
161
61
  switch (_a.label) {
162
62
  case 0: return [4 /*yield*/, signer.getAddress()];
@@ -176,12 +76,12 @@ function estimateGasExternalChains(signer, data, value, chainId, targetContract)
176
76
  gasLimit = (0, txHelpers_1.getGasBuffer)(gasEstimate);
177
77
  return [3 /*break*/, 6];
178
78
  case 4:
179
- error_3 = _a.sent();
180
- return [4 /*yield*/, errorDecoder.decode(error_3)];
79
+ error_1 = _a.sent();
80
+ return [4 /*yield*/, errorDecoder.decode(error_1)];
181
81
  case 5:
182
82
  decodedError = _a.sent();
183
83
  reason = customReasonMapper(decodedError);
184
- console.error("Error simulating external transaction with value ".concat(value, ", account address ").concat(accountAddress, ", reason ").concat(decodedError === null || decodedError === void 0 ? void 0 : decodedError.name, " ").concat(JSON.stringify(decodedError), " ").concat(error_3));
84
+ console.error("Error simulating external transaction with value ".concat(value, ", account address ").concat(accountAddress, ", reason ").concat(decodedError === null || decodedError === void 0 ? void 0 : decodedError.name, " ").concat(JSON.stringify(decodedError), " ").concat(error_1));
185
85
  throw new Error(reason);
186
86
  case 6:
187
87
  if (Object.values(types_1.ReyaChainId).includes(chainId)) {
@@ -196,7 +96,7 @@ function estimateGasExternalChains(signer, data, value, chainId, targetContract)
196
96
  }
197
97
  function executeTransaction(signer, data, value, chainId, targetContract) {
198
98
  return __awaiter(this, void 0, void 0, function () {
199
- var txData, txResponse, txReceipt, error_4;
99
+ var txData, txResponse, txReceipt, error_2;
200
100
  return __generator(this, function (_a) {
201
101
  switch (_a.label) {
202
102
  case 0: return [4 /*yield*/, estimateGasExternalChains(signer, data, value, chainId, targetContract)];
@@ -213,8 +113,8 @@ function executeTransaction(signer, data, value, chainId, targetContract) {
213
113
  txReceipt = _a.sent();
214
114
  return [2 /*return*/, txReceipt];
215
115
  case 5:
216
- error_4 = _a.sent();
217
- console.warn(error_4);
116
+ error_2 = _a.sent();
117
+ console.warn(error_2);
218
118
  throw new Error('Transaction Execution Error');
219
119
  case 6: return [2 /*return*/];
220
120
  }
@@ -240,19 +140,4 @@ var customReasonMapper = function (_a) {
240
140
  return reason !== null && reason !== void 0 ? reason : 'Error executing transaction';
241
141
  }
242
142
  };
243
- function addGasBuffer(estimation) {
244
- return (estimation * BigInt(120)) / BigInt(100);
245
- }
246
- function decodeErrorBytes(returnData) {
247
- return __awaiter(this, void 0, void 0, function () {
248
- var INTERFACE, decodedError;
249
- return __generator(this, function (_a) {
250
- INTERFACE = new ethers_2.Interface(Errors_json_1.abi);
251
- decodedError = INTERFACE.parseError(returnData);
252
- console.log(decodedError);
253
- return [2 /*return*/, "".concat(decodedError === null || decodedError === void 0 ? void 0 : decodedError.name, ": ").concat(decodedError === null || decodedError === void 0 ? void 0 : decodedError.args) || 'Error not found'];
254
- });
255
- });
256
- }
257
- exports.decodeErrorBytes = decodeErrorBytes;
258
143
  //# sourceMappingURL=executeTransaction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAMgB;AAChB,kCAA0D;AAC1D,yDAA+D;AAC/D,kDAAyC;AACzC,2DAAmD;AAEnD,yCAA2C;AAC3C,kCAAmD;AACnD,iCAAmC;AAEnC,IAAM,oBAAoB;IACxB,GAAC,mBAAW,CAAC,WAAW,IACtB,2DAA2D;IAC7D,GAAC,mBAAW,CAAC,UAAU,IACrB,yEAAyE;OAC5E,CAAC;AAQF,IAAM,YAAY,GAAG,kCAAY,CAAC,MAAM,CAAC,CAAC,iBAAG,CAAC,CAAC,CAAC;AAEhD,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC;;;;;wBAQd,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAEhD,sBAAO,uBAAuB,CAC5B,cAAc,EACd,IAAI,EACJ,KAAK,EACL,OAAO,EACP,cAAc,CACf,EAAC;;;;CACH;AAtBD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;YAC1B,sBAAO,UAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,eAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,CAAE,IAAI,iBAAiB,EAAC;;;CAC5E;AALD,4CAKC","sourcesContent":["import {\n ethers,\n JsonRpcProvider,\n JsonRpcSigner,\n Network,\n Signer,\n} from 'ethers';\nimport { MoneyInOutChainId, ReyaChainId } from '../types';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { abi } from './abis/Errors.json';\nimport { ErrorDecoder } from 'ethers-decode-error';\nimport type { DecodedError } from 'ethers-decode-error';\nimport { getGasBuffer } from './txHelpers';\nimport { getPublicRpcUrlsOrThrow } from '../utils';\nimport { Interface } from 'ethers';\n\nconst reyaChainIdRPCMapper: { [key: number]: string } = {\n [ReyaChainId.reyaNetwork]:\n 'https://rpc.reya.network/263e76b89da84d478fd2b6e8783a1cfe',\n [ReyaChainId.reyaCronos]:\n 'https://rpc.reya-cronos.gelato.digital/263e76b89da84d478fd2b6e8783a1cfe',\n};\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\nconst errorDecoder = ErrorDecoder.create([abi]);\n\nexport async function estimateGas(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n return estimateGasGivenAddress(\n accountAddress,\n data,\n value,\n chainId,\n targetContract,\n );\n}\n\n// TODO: deprecate this when /executeGelato is gone\nexport async function estimateGasGivenAddress(\n accountAddress: string,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n\n const tx = {\n from: accountAddress, // @todo Update with relayer address\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const network = new Network('Reya', chainId);\n const provider = new JsonRpcProvider(\n reyaChainIdRPCMapper[chainId],\n network,\n {\n staticNetwork: network,\n pollingInterval: 50,\n },\n );\n await provider.call(tx);\n } catch (error) {\n const decodedError = await errorDecoder.decode(error);\n const reason = customReasonMapper(decodedError);\n console.error(\n `Error simulating transaction account address ${accountAddress} reason ${decodedError?.name} ${decodedError} ${error}`,\n );\n throw new Error(reason);\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function estimateGasFromTxAndChainId(\n chainId: ReyaChainId | MoneyInOutChainId,\n tx: ethers.TransactionRequest,\n): Promise<bigint> {\n const rpcUrls = getPublicRpcUrlsOrThrow(chainId);\n let lastError = null;\n\n for (const url of rpcUrls) {\n try {\n const provider = new ethers.JsonRpcProvider(url);\n const estimation = await provider.estimateGas(tx);\n return addGasBuffer(estimation);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n}\n\nasync function estimateGasExternalChains(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress,\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n const decodedError = await errorDecoder.decode(error);\n const reason = customReasonMapper(decodedError);\n console.error(\n `Error simulating external transaction with value ${value}, account address ${accountAddress}, reason ${decodedError?.name} ${JSON.stringify(\n decodedError,\n )} ${error}`,\n );\n throw new Error(reason);\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n) {\n const txData = await estimateGasExternalChains(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\nconst customReasonMapper = ({ name, reason }: DecodedError): string => {\n switch (name) {\n case 'SignatureInvalid':\n return `Invalid signature. Please refresh page and try again`;\n case 'StalePriceDetected':\n return `Price not updated, please try again a bit later`;\n case 'SmallOrderSize':\n return `Order size below minimum`;\n case 'DustyOrderSize':\n return `Order amount is not divisible by trade size spacing`;\n case 'AccountBelowIM':\n return `Account below required margin`;\n default:\n // This handles the non-custom errors\n return reason ?? 'Error executing transaction';\n }\n};\n\nfunction addGasBuffer(estimation: bigint): bigint {\n return (estimation * BigInt(120)) / BigInt(100);\n}\n\nexport async function decodeErrorBytes(returnData: string): Promise<string> {\n const INTERFACE = new Interface(abi);\n const decodedError = INTERFACE.parseError(returnData);\n console.log(decodedError);\n return `${decodedError?.name}: ${decodedError?.args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AAsD,CAAC;QAChE,KAAK,oBAAoB;YACvB,OAAO,iDAAiD,CAAC;QAC3D,KAAK,gBAAgB;YACnB,OAAO,0BAA0B,CAAC;QACpC,KAAK,gBAAgB;YACnB,OAAO,qDAAqD,CAAC;QAC/D,KAAK,gBAAgB;YACnB,OAAO,+BAA+B,CAAC;QACzC;YACE,qCAAqC;YACrC,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,6BAA6B,CAAC;IACnD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ReyaChainId } from '../types';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { abi } from './abis/Errors.json';\nimport { ErrorDecoder } from 'ethers-decode-error';\nimport type { DecodedError } from 'ethers-decode-error';\nimport { getGasBuffer } from './txHelpers';\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\nconst errorDecoder = ErrorDecoder.create([abi]);\n\nasync function estimateGasExternalChains(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress,\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n const decodedError = await errorDecoder.decode(error);\n const reason = customReasonMapper(decodedError);\n console.error(\n `Error simulating external transaction with value ${value}, account address ${accountAddress}, reason ${decodedError?.name} ${JSON.stringify(\n decodedError,\n )} ${error}`,\n );\n throw new Error(reason);\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n) {\n const txData = await estimateGasExternalChains(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\nconst customReasonMapper = ({ name, reason }: DecodedError): string => {\n switch (name) {\n case 'SignatureInvalid':\n return `Invalid signature. Please refresh page and try again`;\n case 'StalePriceDetected':\n return `Price not updated, please try again a bit later`;\n case 'SmallOrderSize':\n return `Order size below minimum`;\n case 'DustyOrderSize':\n return `Order amount is not divisible by trade size spacing`;\n case 'AccountBelowIM':\n return `Account below required margin`;\n default:\n // This handles the non-custom errors\n return reason ?? 'Error executing transaction';\n }\n};\n"]}
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.signManagePermissionBySig = exports.signRevokePermission = exports.signVote = exports.signGrantPermission = exports.signCancelConditionalOrder = exports.isConditionalOrderSignatureValid = exports.signOrdersGatewayOrder = exports.createOrdersGatewayOrderNonce = exports.getReyaDomain = exports.signPoolRemoveLiquidity = exports.signCoreCommands = exports.convertEthersSignatureToEIP712Signature = void 0;
39
+ exports.signManagePermissionBySig = exports.signMEMassCancel = exports.signMEOrderCancel = exports.signRevokePermission = exports.signVote = exports.signGrantPermission = exports.isOrderSignatureValid = exports.signOrder = exports.signCancelConditionalOrder = exports.signMassCancel = exports.signOrderCancel = exports.isConditionalOrderSignatureValid = exports.signOrdersGatewayOrder = exports.createOrdersGatewayOrderNonce = exports.getReyaDomain = exports.signPoolRemoveLiquidity = exports.signCoreCommands = exports.convertEthersSignatureToEIP712Signature = void 0;
40
40
  var ethers_1 = require("ethers");
41
41
  var contractAddresses_1 = require("./contractAddresses");
42
42
  var types_1 = require("../types");
@@ -253,6 +253,86 @@ function isConditionalOrderSignatureValid(signerAddress, signature, reyaChainId,
253
253
  return recoveredAddress.toLowerCase() === signerAddress.toLowerCase();
254
254
  }
255
255
  exports.isConditionalOrderSignatureValid = isConditionalOrderSignatureValid;
256
+ var orderCancelTypes = {
257
+ OrderCancel: [
258
+ { name: 'verifyingChainId', type: 'uint64' },
259
+ { name: 'deadline', type: 'uint64' },
260
+ { name: 'cancel', type: 'OrderCancelDetails' },
261
+ ],
262
+ OrderCancelDetails: [
263
+ { name: 'accountId', type: 'uint64' },
264
+ { name: 'marketId', type: 'uint64' },
265
+ { name: 'orderId', type: 'uint64' },
266
+ { name: 'clOrdId', type: 'uint64' },
267
+ { name: 'nonce', type: 'uint64' },
268
+ ],
269
+ };
270
+ var massCancelTypes = {
271
+ MassCancel: [
272
+ { name: 'verifyingChainId', type: 'uint64' },
273
+ { name: 'deadline', type: 'uint64' },
274
+ { name: 'massCancel', type: 'MassCancelDetails' },
275
+ ],
276
+ MassCancelDetails: [
277
+ { name: 'accountId', type: 'uint64' },
278
+ { name: 'marketId', type: 'uint64' },
279
+ { name: 'nonce', type: 'uint64' },
280
+ ],
281
+ };
282
+ function signOrderCancel(signer, reyaChainId, accountId, marketId, orderId, clOrdId, nonce, deadline) {
283
+ return __awaiter(this, void 0, void 0, function () {
284
+ var signature;
285
+ return __generator(this, function (_a) {
286
+ switch (_a.label) {
287
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), orderCancelTypes, {
288
+ verifyingChainId: reyaChainId,
289
+ deadline: deadline,
290
+ cancel: {
291
+ accountId: accountId,
292
+ marketId: marketId,
293
+ orderId: orderId,
294
+ clOrdId: clOrdId,
295
+ nonce: nonce,
296
+ },
297
+ })];
298
+ case 1:
299
+ signature = _a.sent();
300
+ return [2 /*return*/, {
301
+ serializedSignature: signature.serialized,
302
+ nonce: nonce,
303
+ signature: convertEthersSignatureToEIP712Signature(signature, deadline),
304
+ }];
305
+ }
306
+ });
307
+ });
308
+ }
309
+ exports.signOrderCancel = signOrderCancel;
310
+ function signMassCancel(signer, reyaChainId, accountId, marketId, nonce, deadline) {
311
+ return __awaiter(this, void 0, void 0, function () {
312
+ var signature;
313
+ return __generator(this, function (_a) {
314
+ switch (_a.label) {
315
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), massCancelTypes, {
316
+ verifyingChainId: reyaChainId,
317
+ deadline: deadline,
318
+ massCancel: {
319
+ accountId: accountId,
320
+ marketId: marketId,
321
+ nonce: nonce,
322
+ },
323
+ })];
324
+ case 1:
325
+ signature = _a.sent();
326
+ return [2 /*return*/, {
327
+ serializedSignature: signature.serialized,
328
+ nonce: nonce,
329
+ signature: convertEthersSignatureToEIP712Signature(signature, deadline),
330
+ }];
331
+ }
332
+ });
333
+ });
334
+ }
335
+ exports.signMassCancel = signMassCancel;
256
336
  function signCancelConditionalOrder(signer, orderId) {
257
337
  return __awaiter(this, void 0, void 0, function () {
258
338
  var message;
@@ -271,6 +351,113 @@ function signCancelConditionalOrder(signer, orderId) {
271
351
  });
272
352
  }
273
353
  exports.signCancelConditionalOrder = signCancelConditionalOrder;
354
+ // -----------------------------------------------------------------------------
355
+ // perpOB: new EIP-712 typed data for the flat `Order` / `OrderDetails` struct
356
+ // -----------------------------------------------------------------------------
357
+ // These additions match the post-audit on-chain redesign in
358
+ // reya-network/feat/perpOB (orders-gateway/src/libraries/DataTypes.sol +
359
+ // ConditionalOrderHashing.sol). They ship alongside the legacy
360
+ // `conditionalOrderTypes` / `signOrdersGatewayOrder` / `isConditionalOrderSignatureValid`
361
+ // so downstream PRs (5/6) can migrate the 11 legacy call sites at routing-rewrite
362
+ // time without breaking signatures against the currently-deployed orders-gateway.
363
+ //
364
+ // Contract: Order envelope + flat OrderDetails inner struct. Two distinct time
365
+ // values are signed:
366
+ // - envelope `deadline` -> signature validity, enforced by API at entry
367
+ // - inner `expiresAfter` -> order lifetime, enforced on-chain at execution
368
+ // Convention: callers should set `deadline <= expiresAfter` when `expiresAfter > 0`.
369
+ // See reya-api-specs/docs/eip712.md for the canonical description.
370
+ var orderTypes = {
371
+ Order: [
372
+ { name: 'verifyingChainId', type: 'uint256' },
373
+ { name: 'deadline', type: 'uint256' },
374
+ { name: 'order', type: 'OrderDetails' },
375
+ ],
376
+ OrderDetails: [
377
+ { name: 'accountId', type: 'uint128' },
378
+ { name: 'marketId', type: 'uint128' },
379
+ { name: 'exchangeId', type: 'uint128' },
380
+ { name: 'orderType', type: 'uint8' },
381
+ { name: 'quantity', type: 'int256' },
382
+ { name: 'limitPrice', type: 'uint256' },
383
+ { name: 'triggerPrice', type: 'uint256' },
384
+ { name: 'timeInForce', type: 'uint8' },
385
+ { name: 'clientOrderId', type: 'uint64' },
386
+ { name: 'reduceOnly', type: 'bool' },
387
+ { name: 'expiresAfter', type: 'uint256' },
388
+ { name: 'signer', type: 'address' },
389
+ { name: 'nonce', type: 'uint256' },
390
+ ],
391
+ };
392
+ function signOrder(signer, reyaChainId, params) {
393
+ return __awaiter(this, void 0, void 0, function () {
394
+ var signature, _a, _b;
395
+ var _c, _d;
396
+ return __generator(this, function (_e) {
397
+ switch (_e.label) {
398
+ case 0:
399
+ _a = signReyaTypedData;
400
+ _b = [signer,
401
+ (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY),
402
+ orderTypes];
403
+ _c = {
404
+ verifyingChainId: reyaChainId,
405
+ deadline: BigInt(params.deadline)
406
+ };
407
+ _d = {
408
+ accountId: params.accountId,
409
+ marketId: params.marketId,
410
+ exchangeId: params.exchangeId,
411
+ orderType: params.orderType,
412
+ quantity: params.quantity,
413
+ limitPrice: params.limitPrice,
414
+ triggerPrice: params.triggerPrice,
415
+ timeInForce: params.timeInForce,
416
+ clientOrderId: params.clientOrderId,
417
+ reduceOnly: params.reduceOnly,
418
+ expiresAfter: params.expiresAfter
419
+ };
420
+ return [4 /*yield*/, signer.getAddress()];
421
+ case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([(_c.order = (_d.signer = _e.sent(),
422
+ _d.nonce = params.nonce,
423
+ _d),
424
+ _c)]))];
425
+ case 2:
426
+ signature = _e.sent();
427
+ return [2 /*return*/, {
428
+ serializedSignature: signature.serialized,
429
+ signature: convertEthersSignatureToEIP712Signature(signature, params.deadline),
430
+ }];
431
+ }
432
+ });
433
+ });
434
+ }
435
+ exports.signOrder = signOrder;
436
+ function isOrderSignatureValid(signerAddress, signature, reyaChainId, params) {
437
+ var domain = getReyaDomain((0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY));
438
+ var value = {
439
+ verifyingChainId: reyaChainId,
440
+ deadline: BigInt(params.deadline),
441
+ order: {
442
+ accountId: params.accountId,
443
+ marketId: params.marketId,
444
+ exchangeId: params.exchangeId,
445
+ orderType: params.orderType,
446
+ quantity: params.quantity,
447
+ limitPrice: params.limitPrice,
448
+ triggerPrice: params.triggerPrice,
449
+ timeInForce: params.timeInForce,
450
+ clientOrderId: params.clientOrderId,
451
+ reduceOnly: params.reduceOnly,
452
+ expiresAfter: params.expiresAfter,
453
+ signer: signerAddress,
454
+ nonce: params.nonce,
455
+ },
456
+ };
457
+ var recoveredAddress = (0, ethers_1.verifyTypedData)(domain, orderTypes, value, signature);
458
+ return recoveredAddress.toLowerCase() === signerAddress.toLowerCase();
459
+ }
460
+ exports.isOrderSignatureValid = isOrderSignatureValid;
274
461
  function signGrantPermission(signer, reyaChainId, accountId, permission, user, nonce, deadline) {
275
462
  return __awaiter(this, void 0, void 0, function () {
276
463
  var signature;
@@ -363,6 +550,52 @@ function signRevokePermission(signer, reyaChainId, accountId, permission, user,
363
550
  });
364
551
  }
365
552
  exports.signRevokePermission = signRevokePermission;
553
+ function signMEOrderCancel(signer, reyaChainId, accountId, marketId, orderId, clOrdId, nonce, deadline) {
554
+ return __awaiter(this, void 0, void 0, function () {
555
+ var signature;
556
+ return __generator(this, function (_a) {
557
+ switch (_a.label) {
558
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), orderCancelTypes, {
559
+ verifyingChainId: reyaChainId,
560
+ deadline: BigInt(deadline),
561
+ cancel: {
562
+ accountId: accountId,
563
+ marketId: marketId,
564
+ orderId: orderId,
565
+ clOrdId: clOrdId,
566
+ nonce: nonce,
567
+ },
568
+ })];
569
+ case 1:
570
+ signature = _a.sent();
571
+ return [2 /*return*/, signature.serialized];
572
+ }
573
+ });
574
+ });
575
+ }
576
+ exports.signMEOrderCancel = signMEOrderCancel;
577
+ function signMEMassCancel(signer, reyaChainId, accountId, marketId, nonce, deadline) {
578
+ return __awaiter(this, void 0, void 0, function () {
579
+ var signature;
580
+ return __generator(this, function (_a) {
581
+ switch (_a.label) {
582
+ case 0: return [4 /*yield*/, signReyaTypedData(signer, (0, contractAddresses_1.getAddress)(reyaChainId, contractAddresses_1.ContractType.ORDERS_GATEWAY_PROXY), massCancelTypes, {
583
+ verifyingChainId: reyaChainId,
584
+ deadline: BigInt(deadline),
585
+ massCancel: {
586
+ accountId: accountId,
587
+ marketId: marketId,
588
+ nonce: nonce,
589
+ },
590
+ })];
591
+ case 1:
592
+ signature = _a.sent();
593
+ return [2 /*return*/, signature.serialized];
594
+ }
595
+ });
596
+ });
597
+ }
598
+ exports.signMEMassCancel = signMEMassCancel;
366
599
  var signManagePermissionBySig = function (signer, signerAddress, reyaChainId, targetAddress, permissionState, deadline) { return __awaiter(void 0, void 0, void 0, function () {
367
600
  var signature;
368
601
  return __generator(this, function (_a) {
@@ -1 +1 @@
1
- {"version":3,"file":"sign.js","sourceRoot":"/","sources":["transactions/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAMgB;AAChB,yDAA+D;AAE/D,kCAMkB;AA0BlB,SAAgB,uCAAuC,CACrD,SAAoB,EACpB,QAAgB;IAEhB,OAAO;QACL,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,QAAQ,UAAA;KACT,CAAC;AACJ,CAAC;AAVD,0FAUC;AAED,SAAsB,gBAAgB,CACpC,MAA8B,EAC9B,WAAwB,EACxB,MAAe,EACf,SAAiB,EACjB,QAAmB,EACnB,KAAa,EACb,QAAgB,EAChB,kBAA0B;;;;;;oBAEpB,KAAK,GAAG;wBACZ,YAAY,EAAE;4BACZ,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;4BAC7C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;4BACnC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;4BACtC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE;4BACvC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;4BAClC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;4BACrC,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE;yBAC9C;wBACD,OAAO,EAAE;4BACP,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE;4BACtC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE;4BACjC,EAAE,IAAI,EAAE,UAA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IAAI;wBACV,KAAK,EAAE,KAAK;wBACZ,QAAQ,EAAE,QAAQ;qBACnB,CACF,EAAA;;oBArBK,SAAS,GAAG,SAqBjB;oBAED,sBAAO,uCAAuC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAC;;;;CACrE;AAjCD,oDAiCC;AAEM,IAAM,yBAAyB,GAAG,UACvC,MAA8B,EAC9B,aAAqB,EACrB,WAAwB,EACxB,aAAqB,EACrB,eAAwB,EACxB,QAAgB;;;;oBAEE,qBAAM,iBAAiB,CACvC,MAAM,EACN,IAAA,8BAAU,EAAC,WAAW,EAAE,gCAAY,CAAC,oBAAoB,CAAC,EAC1D;oBACE,qBAAqB,EAAE;wBACrB,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;wBAC7C,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;wBAClC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;wBACnC,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE;wBACzC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;qBACtC;iBACF,EACD;oBACE,gBAAgB,EAAE,WAAW;oBAC7B,KAAK,EAAE,aAAa;oBACpB,MAAM,EAAE,aAAa;oBACrB,eAAe,EAAE,eAAe;oBAChC,QAAQ,EAAE,QAAQ;iBACnB,CACF,EAAA;;gBAnBK,SAAS,GAAG,SAmBjB;gBAED,sBAAO,uCAAuC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAC;;;KACrE,CAAC;AA9BW,QAAA,yBAAyB,6BA8BpC","sourcesContent":["import {\n JsonRpcSigner,\n Signature,\n Signer,\n TypedDataField,\n verifyTypedData,\n} from 'ethers';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { Command } from './action';\nimport {\n Address,\n ConditionalOrderStatus,\n ConditionalOrderType,\n OrdersGatewayOrderType,\n ReyaChainId,\n} from '../types';\n\nexport type EIP712Signature = {\n v: number;\n r: string;\n s: string;\n deadline: number;\n};\n\nexport type CoreCommandsEIP712SignatureAndPayload = {\n signature: EIP712Signature;\n payload: {\n verifyingContract: string;\n types: Record<string, Array<TypedDataField>>;\n value: {\n verifyingChainId: number;\n caller: Address;\n accountId: number;\n commands: Command[];\n nonce: number;\n deadline: number;\n extraSignatureData: string;\n };\n };\n};\n\nexport function convertEthersSignatureToEIP712Signature(\n signature: Signature,\n deadline: number,\n): EIP712Signature {\n return {\n v: signature.v,\n r: signature.r,\n s: signature.s,\n deadline,\n };\n}\n\nexport async function signCoreCommands(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n accountId: number,\n commands: Command[],\n nonce: number,\n deadline: number,\n extraSignatureData: string,\n): Promise<CoreCommandsEIP712SignatureAndPayload> {\n const types = {\n ExecuteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'accountId', type: 'uint128' },\n { name: 'commands', type: 'Command[]' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n Command: [\n { name: 'commandType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n ],\n };\n\n const value = {\n verifyingChainId: reyaChainId,\n caller: caller,\n accountId: accountId,\n commands: commands,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n };\n\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n types,\n value,\n );\n\n const eip712Signature = convertEthersSignatureToEIP712Signature(\n signature,\n deadline,\n );\n\n return {\n signature: eip712Signature,\n payload: {\n verifyingContract: getAddress(reyaChainId, ContractType.CORE_PROXY),\n types: types,\n value: value,\n },\n };\n}\n\nexport async function signPoolRemoveLiquidity(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n owner: Address,\n poolId: number,\n sharesAmount: bigint,\n minOut: bigint,\n nonce: number,\n deadline: number,\n extraSignatureData: string,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.PASSIVE_POOL_PROXY),\n {\n RemoveLiquidityBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'owner', type: 'address' },\n { name: 'poolId', type: 'uint128' },\n { name: 'sharesAmount', type: 'uint256' },\n { name: 'minOut', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n caller: caller,\n owner: owner,\n poolId: poolId,\n sharesAmount: sharesAmount,\n minOut: minOut,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nasync function signReyaTypedData(\n signer: Signer | JsonRpcSigner,\n verifyingContract: string,\n types: Record<string, Array<TypedDataField>>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: Record<string, any>,\n): Promise<Signature> {\n const domain = getReyaDomain(verifyingContract);\n\n const signatureString = await signer.signTypedData(domain, types, value);\n\n return Signature.from(signatureString);\n}\n\nexport function getReyaDomain(verifyingContract: string) {\n return {\n name: 'Reya',\n version: '1',\n verifyingContract: verifyingContract,\n };\n}\n\nconst conditionalOrderTypes = {\n ConditionalOrder: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'order', type: 'ConditionalOrderDetails' },\n ],\n ConditionalOrderDetails: [\n { name: 'accountId', type: 'uint128' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n { name: 'counterpartyAccountIds', type: 'uint128[]' },\n { name: 'orderType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'signer', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n};\n\nexport function createOrdersGatewayOrderNonce(\n accountId: number,\n marketId: number,\n timestampMs: number,\n): bigint {\n // Validate the input ranges\n if (marketId < 0 || marketId >= 2 ** 32)\n throw new Error('marketId is out of range');\n if (accountId < 0 || accountId >= 2 ** 128)\n throw new Error('accountId is out of range');\n if (timestampMs < 0 || timestampMs >= 2 ** 64)\n throw new Error('timestamp is out of range');\n\n const hashUint256 =\n (BigInt(accountId) << BigInt(98)) |\n (BigInt(timestampMs) << BigInt(32)) |\n BigInt(marketId);\n\n return hashUint256;\n}\n\ntype SignOrdersGatewayOrderOutput = {\n serializedSignature: string;\n nonce: bigint;\n signature: EIP712Signature;\n};\n\nexport async function signOrdersGatewayOrder(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: ConditionalOrderType | OrdersGatewayOrderType,\n inputs: string,\n deadline: number,\n creationTimestampMs: number,\n customNonce?: bigint,\n): Promise<SignOrdersGatewayOrderOutput> {\n const nonce =\n customNonce ??\n createOrdersGatewayOrderNonce(accountId, marketId, creationTimestampMs);\n\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n conditionalOrderTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n order: {\n accountId: accountId,\n marketId: marketId,\n exchangeId: exchangeId,\n counterpartyAccountIds: counterpartyAccountIds,\n orderType: orderType,\n inputs: inputs,\n signer: await signer.getAddress(),\n nonce: nonce,\n },\n },\n );\n\n return {\n serializedSignature: signature.serialized,\n nonce,\n signature: convertEthersSignatureToEIP712Signature(signature, deadline),\n };\n}\n\nexport function isConditionalOrderSignatureValid(\n signerAddress: string,\n signature: string,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: number,\n inputs: string,\n nonce: bigint,\n deadline: number,\n): boolean {\n // Encode the data for recovering the address\n const domain = getReyaDomain(\n getAddress(reyaChainId, ContractType.CONDITIONAL_ORDERS_PROXY),\n );\n\n const value = {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n order: {\n accountId: accountId,\n marketId: marketId,\n exchangeId: exchangeId,\n counterpartyAccountIds: counterpartyAccountIds,\n orderType: orderType,\n inputs: inputs,\n signer: signerAddress,\n nonce: nonce,\n },\n };\n\n // Recover the address\n const recoveredAddress = verifyTypedData(\n domain,\n conditionalOrderTypes,\n value,\n signature,\n );\n\n return recoveredAddress.toLowerCase() === signerAddress.toLowerCase();\n}\n\nexport async function signCancelConditionalOrder(\n signer: Signer | JsonRpcSigner,\n orderId: string,\n): Promise<string> {\n const message = {\n orderId: orderId,\n status: ConditionalOrderStatus.CANCELLED,\n actionType: 'changeStatus',\n };\n return await signer.signMessage(JSON.stringify(message));\n}\n\nexport async function signGrantPermission(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n permission: string,\n user: string,\n nonce: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n GrantAccountPermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'accountId', type: 'uint128' },\n { name: 'permission', type: 'bytes32' },\n { name: 'user', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n accountId: accountId,\n permission: permission,\n user: user,\n nonce: nonce,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signVote(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n contractAddress: string,\n voter: string,\n isYesVote: boolean,\n deadline: number,\n): Promise<string> {\n const types = {\n CastVoteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'voter', type: 'address' },\n { name: 'yesVote', type: 'bool' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n };\n const values = {\n verifyingChainId: reyaChainId,\n voter: voter,\n yesVote: isYesVote,\n nonce: 1, // hardcoded because a user cannot vote more than once\n deadline: deadline,\n };\n\n const domain = getReyaDomain(contractAddress);\n\n const signatureString = await signer.signTypedData(domain, types, values);\n\n return signatureString;\n}\n\nexport async function signRevokePermission(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n permission: string,\n user: string,\n nonce: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n RevokeAccountPermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'accountId', type: 'uint128' },\n { name: 'permission', type: 'bytes32' },\n { name: 'user', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n accountId: accountId,\n permission: permission,\n user: user,\n nonce: nonce,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport const signManagePermissionBySig = async (\n signer: Signer | JsonRpcSigner,\n signerAddress: string,\n reyaChainId: ReyaChainId,\n targetAddress: string,\n permissionState: boolean,\n deadline: number,\n): Promise<EIP712Signature> => {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n {\n ManagePermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'owner', type: 'address' },\n { name: 'target', type: 'address' },\n { name: 'permissionState', type: 'bool' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n owner: signerAddress,\n target: targetAddress,\n permissionState: permissionState,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature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ACtC;iBACF,EACD;oBACE,gBAAgB,EAAE,WAAW;oBAC7B,KAAK,EAAE,aAAa;oBACpB,MAAM,EAAE,aAAa;oBACrB,eAAe,EAAE,eAAe;oBAChC,QAAQ,EAAE,QAAQ;iBACnB,CACF,EAAA;;gBAnBK,SAAS,GAAG,SAmBjB;gBAED,sBAAO,uCAAuC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAC;;;KACrE,CAAC;AA9BW,QAAA,yBAAyB,6BA8BpC","sourcesContent":["import {\n JsonRpcSigner,\n Signature,\n Signer,\n TypedDataField,\n verifyTypedData,\n} from 'ethers';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { Command } from './action';\nimport {\n Address,\n ConditionalOrderStatus,\n ConditionalOrderType,\n OrderType,\n OrdersGatewayOrderType,\n ReyaChainId,\n} from '../types';\n\nexport type EIP712Signature = {\n v: number;\n r: string;\n s: string;\n deadline: number;\n};\n\nexport type CoreCommandsEIP712SignatureAndPayload = {\n signature: EIP712Signature;\n payload: {\n verifyingContract: string;\n types: Record<string, Array<TypedDataField>>;\n value: {\n verifyingChainId: number;\n caller: Address;\n accountId: number;\n commands: Command[];\n nonce: number;\n deadline: number;\n extraSignatureData: string;\n };\n };\n};\n\nexport function convertEthersSignatureToEIP712Signature(\n signature: Signature,\n deadline: number,\n): EIP712Signature {\n return {\n v: signature.v,\n r: signature.r,\n s: signature.s,\n deadline,\n };\n}\n\nexport async function signCoreCommands(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n accountId: number,\n commands: Command[],\n nonce: number,\n deadline: number,\n extraSignatureData: string,\n): Promise<CoreCommandsEIP712SignatureAndPayload> {\n const types = {\n ExecuteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'accountId', type: 'uint128' },\n { name: 'commands', type: 'Command[]' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n Command: [\n { name: 'commandType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n ],\n };\n\n const value = {\n verifyingChainId: reyaChainId,\n caller: caller,\n accountId: accountId,\n commands: commands,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n };\n\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n types,\n value,\n );\n\n const eip712Signature = convertEthersSignatureToEIP712Signature(\n signature,\n deadline,\n );\n\n return {\n signature: eip712Signature,\n payload: {\n verifyingContract: getAddress(reyaChainId, ContractType.CORE_PROXY),\n types: types,\n value: value,\n },\n };\n}\n\nexport async function signPoolRemoveLiquidity(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n caller: Address,\n owner: Address,\n poolId: number,\n sharesAmount: bigint,\n minOut: bigint,\n nonce: number,\n deadline: number,\n extraSignatureData: string,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.PASSIVE_POOL_PROXY),\n {\n RemoveLiquidityBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'caller', type: 'address' },\n { name: 'owner', type: 'address' },\n { name: 'poolId', type: 'uint128' },\n { name: 'sharesAmount', type: 'uint256' },\n { name: 'minOut', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'extraSignatureData', type: 'bytes' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n caller: caller,\n owner: owner,\n poolId: poolId,\n sharesAmount: sharesAmount,\n minOut: minOut,\n nonce: nonce,\n deadline: deadline,\n extraSignatureData: extraSignatureData,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nasync function signReyaTypedData(\n signer: Signer | JsonRpcSigner,\n verifyingContract: string,\n types: Record<string, Array<TypedDataField>>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: Record<string, any>,\n): Promise<Signature> {\n const domain = getReyaDomain(verifyingContract);\n\n const signatureString = await signer.signTypedData(domain, types, value);\n\n return Signature.from(signatureString);\n}\n\nexport function getReyaDomain(verifyingContract: string) {\n return {\n name: 'Reya',\n version: '1',\n verifyingContract: verifyingContract,\n };\n}\n\nconst conditionalOrderTypes = {\n ConditionalOrder: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'order', type: 'ConditionalOrderDetails' },\n ],\n ConditionalOrderDetails: [\n { name: 'accountId', type: 'uint128' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n { name: 'counterpartyAccountIds', type: 'uint128[]' },\n { name: 'orderType', type: 'uint8' },\n { name: 'inputs', type: 'bytes' },\n { name: 'signer', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n};\n\nexport function createOrdersGatewayOrderNonce(\n accountId: number,\n marketId: number,\n timestampMs: number,\n): bigint {\n // Validate the input ranges\n if (marketId < 0 || marketId >= 2 ** 32)\n throw new Error('marketId is out of range');\n if (accountId < 0 || accountId >= 2 ** 128)\n throw new Error('accountId is out of range');\n if (timestampMs < 0 || timestampMs >= 2 ** 64)\n throw new Error('timestamp is out of range');\n\n const hashUint256 =\n (BigInt(accountId) << BigInt(98)) |\n (BigInt(timestampMs) << BigInt(32)) |\n BigInt(marketId);\n\n return hashUint256;\n}\n\ntype SignOrdersGatewayOrderOutput = {\n serializedSignature: string;\n nonce: bigint;\n signature: EIP712Signature;\n};\n\nexport async function signOrdersGatewayOrder(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: ConditionalOrderType | OrdersGatewayOrderType,\n inputs: string,\n deadline: number,\n creationTimestampMs: number,\n customNonce?: bigint,\n): Promise<SignOrdersGatewayOrderOutput> {\n const nonce =\n customNonce ??\n createOrdersGatewayOrderNonce(accountId, marketId, creationTimestampMs);\n\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n conditionalOrderTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n order: {\n accountId: accountId,\n marketId: marketId,\n exchangeId: exchangeId,\n counterpartyAccountIds: counterpartyAccountIds,\n orderType: orderType,\n inputs: inputs,\n signer: await signer.getAddress(),\n nonce: nonce,\n },\n },\n );\n\n return {\n serializedSignature: signature.serialized,\n nonce,\n signature: convertEthersSignatureToEIP712Signature(signature, deadline),\n };\n}\n\nexport function isConditionalOrderSignatureValid(\n signerAddress: string,\n signature: string,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n orderType: number,\n inputs: string,\n nonce: bigint,\n deadline: number,\n): boolean {\n // Encode the data for recovering the address\n const domain = getReyaDomain(\n getAddress(reyaChainId, ContractType.CONDITIONAL_ORDERS_PROXY),\n );\n\n const value = {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n order: {\n accountId: accountId,\n marketId: marketId,\n exchangeId: exchangeId,\n counterpartyAccountIds: counterpartyAccountIds,\n orderType: orderType,\n inputs: inputs,\n signer: signerAddress,\n nonce: nonce,\n },\n };\n\n // Recover the address\n const recoveredAddress = verifyTypedData(\n domain,\n conditionalOrderTypes,\n value,\n signature,\n );\n\n return recoveredAddress.toLowerCase() === signerAddress.toLowerCase();\n}\n\nconst orderCancelTypes = {\n OrderCancel: [\n { name: 'verifyingChainId', type: 'uint64' },\n { name: 'deadline', type: 'uint64' },\n { name: 'cancel', type: 'OrderCancelDetails' },\n ],\n OrderCancelDetails: [\n { name: 'accountId', type: 'uint64' },\n { name: 'marketId', type: 'uint64' },\n { name: 'orderId', type: 'uint64' },\n { name: 'clOrdId', type: 'uint64' },\n { name: 'nonce', type: 'uint64' },\n ],\n};\n\nconst massCancelTypes = {\n MassCancel: [\n { name: 'verifyingChainId', type: 'uint64' },\n { name: 'deadline', type: 'uint64' },\n { name: 'massCancel', type: 'MassCancelDetails' },\n ],\n MassCancelDetails: [\n { name: 'accountId', type: 'uint64' },\n { name: 'marketId', type: 'uint64' },\n { name: 'nonce', type: 'uint64' },\n ],\n};\n\ntype SignCancelOutput = {\n serializedSignature: string;\n nonce: bigint;\n signature: EIP712Signature;\n};\n\nexport async function signOrderCancel(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n orderId: bigint,\n clOrdId: bigint,\n nonce: bigint,\n deadline: number,\n): Promise<SignCancelOutput> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n orderCancelTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: deadline,\n cancel: {\n accountId: accountId,\n marketId: marketId,\n orderId: orderId,\n clOrdId: clOrdId,\n nonce: nonce,\n },\n },\n );\n\n return {\n serializedSignature: signature.serialized,\n nonce,\n signature: convertEthersSignatureToEIP712Signature(signature, deadline),\n };\n}\n\nexport async function signMassCancel(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n nonce: bigint,\n deadline: number,\n): Promise<SignCancelOutput> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n massCancelTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: deadline,\n massCancel: {\n accountId: accountId,\n marketId: marketId,\n nonce: nonce,\n },\n },\n );\n\n return {\n serializedSignature: signature.serialized,\n nonce,\n signature: convertEthersSignatureToEIP712Signature(signature, deadline),\n };\n}\n\nexport async function signCancelConditionalOrder(\n signer: Signer | JsonRpcSigner,\n orderId: string,\n): Promise<string> {\n const message = {\n orderId: orderId,\n status: ConditionalOrderStatus.CANCELLED,\n actionType: 'changeStatus',\n };\n return await signer.signMessage(JSON.stringify(message));\n}\n\n// -----------------------------------------------------------------------------\n// perpOB: new EIP-712 typed data for the flat `Order` / `OrderDetails` struct\n// -----------------------------------------------------------------------------\n// These additions match the post-audit on-chain redesign in\n// reya-network/feat/perpOB (orders-gateway/src/libraries/DataTypes.sol +\n// ConditionalOrderHashing.sol). They ship alongside the legacy\n// `conditionalOrderTypes` / `signOrdersGatewayOrder` / `isConditionalOrderSignatureValid`\n// so downstream PRs (5/6) can migrate the 11 legacy call sites at routing-rewrite\n// time without breaking signatures against the currently-deployed orders-gateway.\n//\n// Contract: Order envelope + flat OrderDetails inner struct. Two distinct time\n// values are signed:\n// - envelope `deadline` -> signature validity, enforced by API at entry\n// - inner `expiresAfter` -> order lifetime, enforced on-chain at execution\n// Convention: callers should set `deadline <= expiresAfter` when `expiresAfter > 0`.\n// See reya-api-specs/docs/eip712.md for the canonical description.\n\nconst orderTypes = {\n Order: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n { name: 'order', type: 'OrderDetails' },\n ],\n OrderDetails: [\n { name: 'accountId', type: 'uint128' },\n { name: 'marketId', type: 'uint128' },\n { name: 'exchangeId', type: 'uint128' },\n { name: 'orderType', type: 'uint8' },\n { name: 'quantity', type: 'int256' },\n { name: 'limitPrice', type: 'uint256' },\n { name: 'triggerPrice', type: 'uint256' },\n { name: 'timeInForce', type: 'uint8' },\n { name: 'clientOrderId', type: 'uint64' },\n { name: 'reduceOnly', type: 'bool' },\n { name: 'expiresAfter', type: 'uint256' },\n { name: 'signer', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n};\n\nexport type SignOrderParams = {\n /** Unified market id: core_id for perp, core_id + 1e10 for spot. */\n accountId: number;\n marketId: number;\n exchangeId: number;\n orderType: OrderType;\n /** Signed: positive = buy/long, negative = sell/short. */\n quantity: bigint;\n limitPrice: bigint;\n /** Must be 0n for Limit; must be non-zero for StopLoss / TakeProfit. */\n triggerPrice: bigint;\n /** 0 = GTC, 1 = IOC. Signed but not on-chain-enforced. */\n timeInForce: number;\n /** Signed but not on-chain-enforced. Off-chain correlation id. */\n clientOrderId: bigint;\n reduceOnly: boolean;\n /** 0n = good-until-cancelled. On-chain-enforced at execution. */\n expiresAfter: bigint;\n nonce: bigint;\n /** EIP-712 envelope signature deadline (unix seconds). API-enforced at entry. */\n deadline: number;\n};\n\nexport type SignOrderOutput = {\n serializedSignature: string;\n signature: EIP712Signature;\n};\n\nexport async function signOrder(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n params: SignOrderParams,\n): Promise<SignOrderOutput> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n orderTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(params.deadline),\n order: {\n accountId: params.accountId,\n marketId: params.marketId,\n exchangeId: params.exchangeId,\n orderType: params.orderType,\n quantity: params.quantity,\n limitPrice: params.limitPrice,\n triggerPrice: params.triggerPrice,\n timeInForce: params.timeInForce,\n clientOrderId: params.clientOrderId,\n reduceOnly: params.reduceOnly,\n expiresAfter: params.expiresAfter,\n signer: await signer.getAddress(),\n nonce: params.nonce,\n },\n },\n );\n\n return {\n serializedSignature: signature.serialized,\n signature: convertEthersSignatureToEIP712Signature(\n signature,\n params.deadline,\n ),\n };\n}\n\nexport function isOrderSignatureValid(\n signerAddress: string,\n signature: string,\n reyaChainId: ReyaChainId,\n params: SignOrderParams,\n): boolean {\n const domain = getReyaDomain(\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n );\n\n const value = {\n verifyingChainId: reyaChainId,\n deadline: BigInt(params.deadline),\n order: {\n accountId: params.accountId,\n marketId: params.marketId,\n exchangeId: params.exchangeId,\n orderType: params.orderType,\n quantity: params.quantity,\n limitPrice: params.limitPrice,\n triggerPrice: params.triggerPrice,\n timeInForce: params.timeInForce,\n clientOrderId: params.clientOrderId,\n reduceOnly: params.reduceOnly,\n expiresAfter: params.expiresAfter,\n signer: signerAddress,\n nonce: params.nonce,\n },\n };\n\n const recoveredAddress = verifyTypedData(\n domain,\n orderTypes,\n value,\n signature,\n );\n\n return recoveredAddress.toLowerCase() === signerAddress.toLowerCase();\n}\n\nexport async function signGrantPermission(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n permission: string,\n user: string,\n nonce: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n GrantAccountPermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'accountId', type: 'uint128' },\n { name: 'permission', type: 'bytes32' },\n { name: 'user', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n accountId: accountId,\n permission: permission,\n user: user,\n nonce: nonce,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signVote(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n contractAddress: string,\n voter: string,\n isYesVote: boolean,\n deadline: number,\n): Promise<string> {\n const types = {\n CastVoteBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'voter', type: 'address' },\n { name: 'yesVote', type: 'bool' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n };\n const values = {\n verifyingChainId: reyaChainId,\n voter: voter,\n yesVote: isYesVote,\n nonce: 1, // hardcoded because a user cannot vote more than once\n deadline: deadline,\n };\n\n const domain = getReyaDomain(contractAddress);\n\n const signatureString = await signer.signTypedData(domain, types, values);\n\n return signatureString;\n}\n\nexport async function signRevokePermission(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n permission: string,\n user: string,\n nonce: number,\n deadline: number,\n): Promise<EIP712Signature> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.CORE_PROXY),\n {\n RevokeAccountPermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'accountId', type: 'uint128' },\n { name: 'permission', type: 'bytes32' },\n { name: 'user', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n accountId: accountId,\n permission: permission,\n user: user,\n nonce: nonce,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n}\n\nexport async function signMEOrderCancel(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n orderId: bigint,\n clOrdId: bigint,\n nonce: bigint,\n deadline: number,\n): Promise<string> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n orderCancelTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n cancel: {\n accountId: accountId,\n marketId: marketId,\n orderId: orderId,\n clOrdId: clOrdId,\n nonce: nonce,\n },\n },\n );\n\n return signature.serialized;\n}\n\nexport async function signMEMassCancel(\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n marketId: number,\n nonce: bigint,\n deadline: number,\n): Promise<string> {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n massCancelTypes,\n {\n verifyingChainId: reyaChainId,\n deadline: BigInt(deadline),\n massCancel: {\n accountId: accountId,\n marketId: marketId,\n nonce: nonce,\n },\n },\n );\n\n return signature.serialized;\n}\n\nexport const signManagePermissionBySig = async (\n signer: Signer | JsonRpcSigner,\n signerAddress: string,\n reyaChainId: ReyaChainId,\n targetAddress: string,\n permissionState: boolean,\n deadline: number,\n): Promise<EIP712Signature> => {\n const signature = await signReyaTypedData(\n signer,\n getAddress(reyaChainId, ContractType.ORDERS_GATEWAY_PROXY),\n {\n ManagePermissionBySig: [\n { name: 'verifyingChainId', type: 'uint256' },\n { name: 'owner', type: 'address' },\n { name: 'target', type: 'address' },\n { name: 'permissionState', type: 'bool' },\n { name: 'deadline', type: 'uint256' },\n ],\n },\n {\n verifyingChainId: reyaChainId,\n owner: signerAddress,\n target: targetAddress,\n permissionState: permissionState,\n deadline: deadline,\n },\n );\n\n return convertEthersSignatureToEIP712Signature(signature, deadline);\n};\n"]}