@instadapp/interop-x 0.0.0-dev.75809ae → 0.0.0-dev.79c1ae5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. package/.env.example +2 -1
  2. package/dist/package.json +73 -0
  3. package/dist/src/abi/erc20.json +350 -0
  4. package/dist/src/abi/gnosisSafe.json +747 -0
  5. package/dist/src/abi/index.js +15 -0
  6. package/dist/src/abi/interopBridgeToken.json +286 -0
  7. package/dist/src/abi/interopXGateway.json +184 -0
  8. package/dist/src/api/index.js +33 -0
  9. package/dist/{config → src/config}/index.js +6 -1
  10. package/dist/src/constants/addresses.js +20 -0
  11. package/dist/{constants → src/constants}/index.js +2 -0
  12. package/dist/src/constants/itokens.js +13 -0
  13. package/dist/src/constants/tokens.js +107 -0
  14. package/dist/{db → src/db}/index.js +0 -0
  15. package/dist/{db → src/db}/models/index.js +1 -1
  16. package/dist/src/db/models/transaction.js +54 -0
  17. package/dist/{db → src/db}/sequelize.js +2 -1
  18. package/dist/src/index.js +103 -0
  19. package/dist/{logger → src/logger}/index.js +0 -0
  20. package/dist/{net → src/net}/index.js +0 -0
  21. package/dist/{net → src/net}/peer/index.js +11 -7
  22. package/dist/{net → src/net}/pool/index.js +29 -11
  23. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
  24. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +22 -14
  25. package/dist/{net → src/net}/protocol/index.js +33 -4
  26. package/dist/src/tasks/AutoUpdateTask.js +43 -0
  27. package/dist/{tasks → src/tasks}/BaseTask.js +3 -3
  28. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +147 -0
  29. package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +70 -0
  30. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +150 -0
  31. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +75 -0
  32. package/dist/src/tasks/index.js +42 -0
  33. package/dist/src/typechain/Erc20.js +2 -0
  34. package/dist/src/typechain/GnosisSafe.js +2 -0
  35. package/dist/src/typechain/InteropBridgeToken.js +2 -0
  36. package/dist/src/typechain/InteropXGateway.js +2 -0
  37. package/dist/src/typechain/common.js +2 -0
  38. package/dist/src/typechain/factories/Erc20__factory.js +367 -0
  39. package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
  40. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +459 -0
  41. package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
  42. package/dist/src/typechain/factories/index.js +14 -0
  43. package/dist/src/typechain/index.js +35 -0
  44. package/dist/{types.js → src/types.js} +0 -0
  45. package/dist/src/utils/index.js +228 -0
  46. package/package.json +20 -6
  47. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  48. package/src/abi/erc20.json +350 -0
  49. package/src/abi/gnosisSafe.json +747 -0
  50. package/src/abi/index.ts +11 -0
  51. package/src/abi/interopBridgeToken.json +286 -0
  52. package/src/abi/interopXGateway.json +184 -0
  53. package/src/api/index.ts +33 -0
  54. package/src/config/index.ts +9 -1
  55. package/src/constants/addresses.ts +9 -2
  56. package/src/constants/index.ts +2 -0
  57. package/src/constants/itokens.ts +10 -0
  58. package/src/constants/tokens.ts +104 -0
  59. package/src/db/index.ts +1 -1
  60. package/src/db/models/index.ts +1 -1
  61. package/src/db/models/transaction.ts +96 -0
  62. package/src/db/sequelize.ts +2 -1
  63. package/src/index.ts +90 -6
  64. package/src/net/peer/index.ts +10 -9
  65. package/src/net/pool/index.ts +39 -13
  66. package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
  67. package/src/net/protocol/dial/SignatureDialProtocol.ts +26 -17
  68. package/src/net/protocol/index.ts +48 -4
  69. package/src/tasks/AutoUpdateTask.ts +55 -0
  70. package/src/tasks/BaseTask.ts +3 -4
  71. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +233 -0
  72. package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +121 -0
  73. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +245 -0
  74. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +126 -0
  75. package/src/tasks/index.ts +24 -1
  76. package/src/typechain/Erc20.ts +491 -0
  77. package/src/typechain/GnosisSafe.ts +1728 -0
  78. package/src/typechain/InteropBridgeToken.ts +686 -0
  79. package/src/typechain/InteropXGateway.ts +407 -0
  80. package/src/typechain/common.ts +44 -0
  81. package/src/typechain/factories/Erc20__factory.ts +368 -0
  82. package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
  83. package/src/typechain/factories/InteropBridgeToken__factory.ts +466 -0
  84. package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
  85. package/src/typechain/factories/index.ts +7 -0
  86. package/src/typechain/index.ts +12 -0
  87. package/src/types.ts +2 -2
  88. package/src/utils/index.ts +193 -2
  89. package/tsconfig.json +3 -0
  90. package/dist/constants/addresses.js +0 -13
  91. package/dist/db/models/execution.js +0 -38
  92. package/dist/index.js +0 -34
  93. package/dist/tasks/index.js +0 -19
  94. package/dist/utils/index.js +0 -89
  95. package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,7 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export { Erc20__factory } from "./Erc20__factory";
5
+ export { GnosisSafe__factory } from "./GnosisSafe__factory";
6
+ export { InteropBridgeToken__factory } from "./InteropBridgeToken__factory";
7
+ export { InteropXGateway__factory } from "./InteropXGateway__factory";
@@ -0,0 +1,12 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export type { Erc20 } from "./Erc20";
5
+ export type { GnosisSafe } from "./GnosisSafe";
6
+ export type { InteropBridgeToken } from "./InteropBridgeToken";
7
+ export type { InteropXGateway } from "./InteropXGateway";
8
+ export * as factories from "./factories";
9
+ export { Erc20__factory } from "./factories/Erc20__factory";
10
+ export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
11
+ export { InteropBridgeToken__factory } from "./factories/InteropBridgeToken__factory";
12
+ export { InteropXGateway__factory } from "./factories/InteropXGateway__factory";
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events'
2
- import { IPeerInfo } from './net'
2
+ import { IPeerInfo } from '@/net'
3
3
 
4
4
  /**
5
5
  * Types for the central event bus, emitted
@@ -36,4 +36,4 @@ export type EventBusType = EventBus<Event.PEER_CONNECTED> &
36
36
  EventBus<Event.POOL_PEER_BANNED>
37
37
 
38
38
 
39
- export type ChainId = 1 | 137;
39
+ export type ChainId = 1 | 137 | 43114;
@@ -3,8 +3,14 @@
3
3
  */
4
4
  import axios from 'axios'
5
5
  import axiosRetry from "axios-retry";
6
- import { addresses } from '../constants';
7
- import { ChainId } from '../types'
6
+ import { addresses, itokens, tokens } from '@/constants';
7
+ import { ChainId } from '@/types'
8
+ import { ethers } from 'ethers';
9
+ import { encodeMulti, MetaTransaction, OperationType } from 'ethers-multisend';
10
+ import { Transaction } from '@/db';
11
+ import config from '@/config';
12
+ import abi from '@/abi';
13
+ import { InteropBridgeToken, InteropXGateway } from '@/typechain';
8
14
 
9
15
  export const http = axios.create();
10
16
 
@@ -73,6 +79,8 @@ export const getRpcProviderUrl = (chainId: ChainId) => {
73
79
  return 'https://rpc.instadapp.io/mainnet';
74
80
  case 137:
75
81
  return 'https://rpc.instadapp.io/polygon';
82
+ case 43114:
83
+ return 'https://rpc.instadapp.io/avalanche';
76
84
  default:
77
85
  throw new Error(`Unknown chainId: ${chainId}`);
78
86
  }
@@ -113,4 +121,187 @@ export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout:
113
121
  clearTimeout(timeoutHandle);
114
122
  return result;
115
123
  }) as Promise<T>
124
+ }
125
+
126
+
127
+ export const generateInteropTransactionHash = (data: { action: string, submitTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
128
+ return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
129
+ String(data.action),
130
+ String(data.submitTransactionHash),
131
+ String(data.sourceChainId),
132
+ String(data.targetChainId),
133
+ ]);
134
+ }
135
+
136
+ export const buildDataForTransaction = async (transaction: Transaction, type?: 'source' | 'target') => {
137
+ type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
138
+
139
+ switch (transaction.action) {
140
+ case "deposit":
141
+ return await buildDepositDataForTransaction(transaction, type);
142
+ case "withdraw":
143
+ return await buildWithdrawDataForTransaction(transaction, type);
144
+ default:
145
+ throw new Error(`Unknown action: ${transaction.action}`);
146
+ }
147
+ }
148
+
149
+ export const buildDepositDataForTransaction = async (transaction: Transaction, type: 'source' | 'target') => {
150
+ const transactions: MetaTransaction[] = [];
151
+
152
+ if (transaction.action !== 'deposit') {
153
+ throw new Error(`Invalid action: ${transaction.action}`)
154
+ }
155
+
156
+ if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
157
+ throw Error('Cannot build data for pending deposit transaction');
158
+ }
159
+
160
+ if (!transaction.submitEvent) {
161
+ throw Error('Cannot build data for transaction without submitEvent');
162
+ }
163
+
164
+
165
+ const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
166
+
167
+ if (!token) {
168
+ throw Error('Cannot build data for transaction without token');
169
+ }
170
+
171
+ const itoken = itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
172
+
173
+ if (!itoken) {
174
+ throw Error('Cannot build data for transaction without itoken');
175
+ }
176
+
177
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
178
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
179
+ const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
180
+
181
+ const { data } = await interopBridgeContract.populateTransaction.mint(
182
+ transaction.submitEvent.user,
183
+ ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
184
+ ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
185
+ transaction.submitTransactionHash,
186
+ );
187
+
188
+ transactions.push({
189
+ to: itoken.address,
190
+ data: data!,
191
+ value: '0',
192
+ operation: OperationType.Call,
193
+ });
194
+
195
+ return encodeMulti(transactions).data
196
+ }
197
+
198
+ export const buildWithdrawDataForTransaction = async (transaction: Transaction, type: 'source' | 'target') => {
199
+ const transactions: MetaTransaction[] = [];
200
+
201
+ if (transaction.action !== 'withdraw') {
202
+ throw new Error(`Invalid action: ${transaction.action}`)
203
+ }
204
+
205
+ if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
206
+ throw Error('Cannot build data for pending withdraw transaction');
207
+ }
208
+
209
+ if (!transaction.submitEvent) {
210
+ throw Error('Cannot build data for transaction without submitEvent');
211
+ }
212
+
213
+ const { to, amount, chainId, itoken: itokenAddress } = transaction.submitEvent;
214
+
215
+ const itoken = itokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
216
+
217
+ if (!itoken) {
218
+ throw Error('Cannot build data for transaction without itoken');
219
+ }
220
+
221
+ const token = tokens[chainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
222
+
223
+ if (!token) {
224
+ throw Error('Cannot build data for transaction without token');
225
+ }
226
+
227
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
228
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
229
+ const gatewayAddress = addresses[chainId].interopXGateway;
230
+ const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
231
+
232
+ const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
233
+ ethers.BigNumber.from(amount.toString()),
234
+ to,
235
+ token.address,
236
+ ethers.BigNumber.from(transaction.sourceChainId.toString()),
237
+ transaction.submitTransactionHash,
238
+ );
239
+
240
+ transactions.push({
241
+ to: gatewayAddress,
242
+ data: data!,
243
+ value: '0',
244
+ operation: OperationType.Call,
245
+ });
246
+
247
+ return encodeMulti(transactions).data
248
+ }
249
+
250
+
251
+ export function getContract<TContract extends ethers.Contract>(address: string, contractInterface: ethers.ContractInterface | any, signerOrProvider?: ethers.Signer | ethers.providers.Provider) {
252
+ if (!ethers.utils.getAddress(address) || address === ethers.constants.AddressZero) {
253
+ throw Error(`Invalid 'address' parameter '${address}'.`)
254
+ }
255
+
256
+ const contract = new ethers.Contract(
257
+ address,
258
+ contractInterface,
259
+ signerOrProvider
260
+ ) as TContract
261
+
262
+ // Make sure the contract properties is writable
263
+ const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
264
+
265
+ if (!desc || desc.writable !== true) {
266
+ return contract
267
+ }
268
+
269
+ return new Proxy(contract, {
270
+ get(target, prop, receiver) {
271
+ const value = Reflect.get(target, prop, receiver);
272
+
273
+ if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
274
+ return async (...args: any[]) => {
275
+ try {
276
+ return await value.bind(contract)(...args);
277
+ } catch (error) {
278
+ throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`)
279
+ }
280
+ }
281
+ }
282
+
283
+
284
+ if (typeof value === 'object' && ['populateTransaction', 'estimateGas', 'functions', 'callStatic'].includes(String(prop))) {
285
+ const parentProp = String(prop);
286
+
287
+ return new Proxy(value, {
288
+ get(target, prop, receiver) {
289
+ const value = Reflect.get(target, prop, receiver);
290
+
291
+ if (typeof value === 'function') {
292
+ return async (...args: any[]) => {
293
+ try {
294
+ return await value.bind(contract)(...args);
295
+ } catch (error) {
296
+ throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`)
297
+ }
298
+ }
299
+ }
300
+ }
301
+ })
302
+ }
303
+
304
+ return value;
305
+ },
306
+ });
116
307
  }
package/tsconfig.json CHANGED
@@ -16,6 +16,9 @@
16
16
  "noEmit": false,
17
17
  "outDir": "dist",
18
18
  "baseUrl": "src",
19
+ "paths": {
20
+ "@/*" : ["./*" ]
21
+ },
19
22
  "typeRoots": [
20
23
  "./node_modules/@types",
21
24
  "./@types"
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addresses = void 0;
4
- exports.addresses = {
5
- 1: {
6
- gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
7
- multisend: "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
8
- },
9
- 137: {
10
- gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
11
- multisend: "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
12
- },
13
- };
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Execution = void 0;
4
- const sequelize_1 = require("../sequelize");
5
- const sequelize_2 = require("sequelize");
6
- class Execution extends sequelize_2.Model {
7
- }
8
- exports.Execution = Execution;
9
- Execution.init({
10
- id: {
11
- type: sequelize_2.DataTypes.INTEGER,
12
- autoIncrement: true,
13
- primaryKey: true
14
- },
15
- transactionHash: sequelize_2.DataTypes.STRING,
16
- from: sequelize_2.DataTypes.STRING,
17
- executions: sequelize_2.DataTypes.JSON,
18
- chainId: sequelize_2.DataTypes.NUMBER,
19
- gas: sequelize_2.DataTypes.STRING,
20
- maxGasPrice: sequelize_2.DataTypes.STRING,
21
- assets: sequelize_2.DataTypes.JSON,
22
- metadata: sequelize_2.DataTypes.STRING,
23
- vnonce: sequelize_2.DataTypes.STRING,
24
- txHash: sequelize_2.DataTypes.STRING,
25
- blockNumber: sequelize_2.DataTypes.STRING,
26
- status: {
27
- type: sequelize_2.DataTypes.STRING,
28
- defaultValue: 'pending'
29
- },
30
- delayUntil: sequelize_2.DataTypes.DATE,
31
- delayedCount: {
32
- type: sequelize_2.DataTypes.INTEGER,
33
- defaultValue: 0
34
- },
35
- error: sequelize_2.DataTypes.STRING,
36
- createdAt: sequelize_2.DataTypes.DATE,
37
- updatedAt: sequelize_2.DataTypes.DATE,
38
- }, { sequelize: sequelize_1.sequelize, tableName: 'executions' });
package/dist/index.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const console_1 = require("console");
7
- const dotenv_1 = __importDefault(require("dotenv"));
8
- const tasks_1 = require("tasks");
9
- const logger_1 = __importDefault(require("./logger"));
10
- const net_1 = require("./net");
11
- dotenv_1.default.config();
12
- (0, console_1.assert)(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
13
- const logger = new logger_1.default('Process');
14
- async function main() {
15
- (0, net_1.startPeer)({});
16
- const tasks = new tasks_1.Tasks();
17
- tasks.start();
18
- }
19
- main()
20
- .then(() => {
21
- }).catch(err => {
22
- console.error(err);
23
- });
24
- process.on('SIGINT', () => {
25
- logger.debug('received SIGINT signal. exiting.');
26
- process.exit(0);
27
- });
28
- process.on('SIGTERM', () => {
29
- logger.debug('received SIGTERM signal. exiting.');
30
- process.exit(0);
31
- });
32
- process.on('unhandledRejection', (reason, p) => {
33
- logger.error('unhandled rejection: promise:', p, 'reason:', reason);
34
- });
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tasks = void 0;
4
- class Tasks {
5
- constructor() {
6
- this.tasks = [];
7
- }
8
- async start() {
9
- for (const task of this.tasks) {
10
- try {
11
- task.start();
12
- }
13
- catch (error) {
14
- console.error(`Error starting task: ${task.constructor.name}`);
15
- }
16
- }
17
- }
18
- }
19
- exports.Tasks = Tasks;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.http = void 0;
7
- /**
8
- * @module util
9
- */
10
- const axios_1 = __importDefault(require("axios"));
11
- const axios_retry_1 = __importDefault(require("axios-retry"));
12
- const constants_1 = require("../constants");
13
- exports.http = axios_1.default.create();
14
- (0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
15
- function short(buffer) {
16
- return buffer.toString('hex').slice(0, 8) + '...';
17
- }
18
- exports.short = short;
19
- const signGnosisSafeTx = async ({ to, data = null, value = '0', operation = '1', baseGas = '0', gasPrice = "0", gasToken = "0x0000000000000000000000000000000000000000", refundReceiver = "0x0000000000000000000000000000000000000000", safeTxGas = "79668", nonce = "0", chainId = 137, }, { signer }) => {
20
- const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
21
- const domain = {
22
- verifyingContract: gnosisSafe,
23
- chainId,
24
- };
25
- const types = {
26
- SafeTx: [
27
- { type: 'address', name: 'to' },
28
- { type: 'uint256', name: 'value' },
29
- { type: 'bytes', name: 'data' },
30
- { type: 'uint8', name: 'operation' },
31
- { type: 'uint256', name: 'safeTxGas' },
32
- { type: 'uint256', name: 'baseGas' },
33
- { type: 'uint256', name: 'gasPrice' },
34
- { type: 'address', name: 'gasToken' },
35
- { type: 'address', name: 'refundReceiver' },
36
- { type: 'uint256', name: 'nonce' },
37
- ],
38
- };
39
- const message = {
40
- baseGas,
41
- data,
42
- gasPrice,
43
- gasToken,
44
- nonce: Number(nonce),
45
- operation,
46
- refundReceiver,
47
- safeAddress: gnosisSafe,
48
- safeTxGas: String(safeTxGas),
49
- to,
50
- value,
51
- };
52
- return await signer._signTypedData(domain, types, message);
53
- };
54
- exports.signGnosisSafeTx = signGnosisSafeTx;
55
- const getRpcProviderUrl = (chainId) => {
56
- switch (chainId) {
57
- case 1:
58
- return 'https://rpc.instadapp.io/mainnet';
59
- case 137:
60
- return 'https://rpc.instadapp.io/polygon';
61
- default:
62
- throw new Error(`Unknown chainId: ${chainId}`);
63
- }
64
- };
65
- exports.getRpcProviderUrl = getRpcProviderUrl;
66
- const buildSignatureBytes = (signatures) => {
67
- signatures.sort((left, right) => left.signer.toLowerCase().localeCompare(right.signer.toLowerCase()));
68
- let signatureBytes = "0x";
69
- for (const sig of signatures) {
70
- signatureBytes += sig.data.slice(2);
71
- }
72
- return signatureBytes;
73
- };
74
- exports.buildSignatureBytes = buildSignatureBytes;
75
- /**
76
- * Call an async function with a maximum time limit (in milliseconds) for the timeout
77
- * Resolved promise for async function call, or an error if time limit reached
78
- */
79
- const asyncCallWithTimeout = async (asyncPromise, timeout) => {
80
- let timeoutHandle;
81
- const timeoutPromise = new Promise((_resolve, reject) => {
82
- timeoutHandle = setTimeout(() => reject(new Error('Async call timeout limit reached')), timeout);
83
- });
84
- return Promise.race([asyncPromise, timeoutPromise]).then(result => {
85
- clearTimeout(timeoutHandle);
86
- return result;
87
- });
88
- };
89
- exports.asyncCallWithTimeout = asyncCallWithTimeout;
@@ -1,57 +0,0 @@
1
- import { sequelize } from '../sequelize'
2
- import { CreationOptional, InferAttributes, InferCreationAttributes, Model, DataTypes } from 'sequelize';
3
-
4
- export class Execution extends Model<InferAttributes<Execution>, InferCreationAttributes<Execution>> {
5
- declare id: CreationOptional<number>;
6
-
7
- declare transactionHash: string;
8
- declare from: string;
9
- declare executions: any[];
10
- declare chainId: number;
11
- declare gas: string;
12
- declare maxGasPrice: string;
13
- declare assets: any[];
14
- declare metadata: string;
15
- declare vnonce: string;
16
- declare txHash: string;
17
-
18
- declare blockNumber: string;
19
- declare status: CreationOptional<string>;
20
- declare delayUntil: CreationOptional<Date>;
21
- declare delayedCount: CreationOptional<number>;
22
-
23
- declare error: CreationOptional<string>;
24
- declare createdAt: CreationOptional<Date>;
25
- declare updatedAt: CreationOptional<Date>;
26
- }
27
-
28
- Execution.init({
29
- id: {
30
- type: DataTypes.INTEGER,
31
- autoIncrement: true,
32
- primaryKey: true
33
- },
34
- transactionHash: DataTypes.STRING,
35
- from: DataTypes.STRING,
36
- executions: DataTypes.JSON,
37
- chainId: DataTypes.NUMBER,
38
- gas: DataTypes.STRING,
39
- maxGasPrice: DataTypes.STRING,
40
- assets: DataTypes.JSON,
41
- metadata: DataTypes.STRING,
42
- vnonce: DataTypes.STRING,
43
- txHash: DataTypes.STRING,
44
- blockNumber: DataTypes.STRING,
45
- status: {
46
- type: DataTypes.STRING,
47
- defaultValue: 'pending'
48
- },
49
- delayUntil: DataTypes.DATE,
50
- delayedCount: {
51
- type: DataTypes.INTEGER,
52
- defaultValue: 0
53
- },
54
- error: DataTypes.STRING,
55
- createdAt: DataTypes.DATE,
56
- updatedAt: DataTypes.DATE,
57
- }, { sequelize, tableName: 'executions' });