@instadapp/interop-x 0.0.0-dev.75809ae → 0.0.0-dev.7adf1b5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) 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 +298 -0
  7. package/dist/src/abi/interopXGateway.json +184 -0
  8. package/dist/src/api/index.js +36 -0
  9. package/dist/src/config/index.js +31 -0
  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 +62 -0
  17. package/dist/{db → src/db}/sequelize.js +2 -1
  18. package/dist/src/gnosis/actions/deposit.js +48 -0
  19. package/dist/src/gnosis/actions/index.js +11 -0
  20. package/dist/src/gnosis/actions/withdraw.js +50 -0
  21. package/dist/src/gnosis/index.js +20 -0
  22. package/dist/src/index.js +130 -0
  23. package/dist/{logger → src/logger}/index.js +0 -0
  24. package/dist/{net → src/net}/index.js +0 -0
  25. package/dist/{net → src/net}/peer/index.js +13 -8
  26. package/dist/{net → src/net}/pool/index.js +34 -11
  27. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
  28. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +17 -14
  29. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
  30. package/dist/{net → src/net}/protocol/index.js +44 -4
  31. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  32. package/dist/{tasks → src/tasks}/BaseTask.js +14 -6
  33. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +162 -0
  34. package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +71 -0
  35. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  36. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +164 -0
  37. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +74 -0
  38. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  39. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
  40. package/dist/src/tasks/index.js +55 -0
  41. package/dist/src/typechain/Erc20.js +2 -0
  42. package/dist/src/typechain/GnosisSafe.js +2 -0
  43. package/dist/src/typechain/InteropBridgeToken.js +2 -0
  44. package/dist/src/typechain/InteropXGateway.js +2 -0
  45. package/dist/src/typechain/common.js +2 -0
  46. package/dist/src/typechain/factories/Erc20__factory.js +367 -0
  47. package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
  48. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +471 -0
  49. package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
  50. package/dist/src/typechain/factories/index.js +14 -0
  51. package/dist/src/typechain/index.js +35 -0
  52. package/dist/{types.js → src/types.js} +0 -0
  53. package/dist/src/utils/index.js +157 -0
  54. package/package.json +21 -7
  55. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  56. package/src/abi/erc20.json +350 -0
  57. package/src/abi/gnosisSafe.json +747 -0
  58. package/src/abi/index.ts +11 -0
  59. package/src/abi/interopBridgeToken.json +298 -0
  60. package/src/abi/interopXGateway.json +184 -0
  61. package/src/api/index.ts +36 -0
  62. package/src/config/index.ts +18 -2
  63. package/src/constants/addresses.ts +9 -2
  64. package/src/constants/index.ts +2 -0
  65. package/src/constants/itokens.ts +10 -0
  66. package/src/constants/tokens.ts +104 -0
  67. package/src/db/index.ts +1 -1
  68. package/src/db/models/index.ts +1 -1
  69. package/src/db/models/transaction.ts +106 -0
  70. package/src/db/sequelize.ts +2 -1
  71. package/src/gnosis/actions/deposit.ts +63 -0
  72. package/src/gnosis/actions/index.ts +7 -0
  73. package/src/gnosis/actions/withdraw.ts +67 -0
  74. package/src/gnosis/index.ts +19 -0
  75. package/src/index.ts +128 -6
  76. package/src/net/peer/index.ts +12 -10
  77. package/src/net/pool/index.ts +43 -13
  78. package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
  79. package/src/net/protocol/dial/SignatureDialProtocol.ts +20 -17
  80. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
  81. package/src/net/protocol/index.ts +60 -4
  82. package/src/tasks/AutoUpdateTask.ts +82 -0
  83. package/src/tasks/BaseTask.ts +16 -7
  84. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +249 -0
  85. package/src/tasks/InteropBridge/SyncBurnEvents.ts +119 -0
  86. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  87. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +260 -0
  88. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +124 -0
  89. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  90. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
  91. package/src/tasks/index.ts +45 -1
  92. package/src/typechain/Erc20.ts +491 -0
  93. package/src/typechain/GnosisSafe.ts +1728 -0
  94. package/src/typechain/InteropBridgeToken.ts +692 -0
  95. package/src/typechain/InteropXGateway.ts +407 -0
  96. package/src/typechain/common.ts +44 -0
  97. package/src/typechain/factories/Erc20__factory.ts +368 -0
  98. package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
  99. package/src/typechain/factories/InteropBridgeToken__factory.ts +478 -0
  100. package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
  101. package/src/typechain/factories/index.ts +7 -0
  102. package/src/typechain/index.ts +12 -0
  103. package/src/types.ts +2 -2
  104. package/src/utils/index.ts +87 -5
  105. package/tsconfig.json +3 -0
  106. package/dist/config/index.js +0 -17
  107. package/dist/constants/addresses.js +0 -13
  108. package/dist/db/models/execution.js +0 -38
  109. package/dist/index.js +0 -34
  110. package/dist/tasks/index.js +0 -19
  111. package/dist/utils/index.js +0 -89
  112. package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,272 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+
5
+ import { Contract, Signer, utils } from "ethers";
6
+ import type { Provider } from "@ethersproject/providers";
7
+ import type {
8
+ InteropXGateway,
9
+ InteropXGatewayInterface,
10
+ } from "../InteropXGateway";
11
+
12
+ const _abi = [
13
+ {
14
+ inputs: [
15
+ {
16
+ internalType: "address",
17
+ name: "__owner",
18
+ type: "address",
19
+ },
20
+ ],
21
+ stateMutability: "nonpayable",
22
+ type: "constructor",
23
+ },
24
+ {
25
+ anonymous: false,
26
+ inputs: [
27
+ {
28
+ indexed: false,
29
+ internalType: "address",
30
+ name: "user",
31
+ type: "address",
32
+ },
33
+ {
34
+ indexed: true,
35
+ internalType: "address",
36
+ name: "token",
37
+ type: "address",
38
+ },
39
+ {
40
+ indexed: false,
41
+ internalType: "uint256",
42
+ name: "amount",
43
+ type: "uint256",
44
+ },
45
+ {
46
+ indexed: true,
47
+ internalType: "uint256",
48
+ name: "vnonce",
49
+ type: "uint256",
50
+ },
51
+ {
52
+ indexed: false,
53
+ internalType: "uint32",
54
+ name: "sourceChainId",
55
+ type: "uint32",
56
+ },
57
+ {
58
+ indexed: true,
59
+ internalType: "uint32",
60
+ name: "targetChainId",
61
+ type: "uint32",
62
+ },
63
+ ],
64
+ name: "LogGatewayDeposit",
65
+ type: "event",
66
+ },
67
+ {
68
+ anonymous: false,
69
+ inputs: [
70
+ {
71
+ indexed: false,
72
+ internalType: "address",
73
+ name: "user",
74
+ type: "address",
75
+ },
76
+ {
77
+ indexed: true,
78
+ internalType: "address",
79
+ name: "token",
80
+ type: "address",
81
+ },
82
+ {
83
+ indexed: false,
84
+ internalType: "uint256",
85
+ name: "amount",
86
+ type: "uint256",
87
+ },
88
+ {
89
+ indexed: true,
90
+ internalType: "uint32",
91
+ name: "sourceChainId",
92
+ type: "uint32",
93
+ },
94
+ {
95
+ indexed: false,
96
+ internalType: "uint32",
97
+ name: "targetChainId",
98
+ type: "uint32",
99
+ },
100
+ {
101
+ indexed: true,
102
+ internalType: "bytes32",
103
+ name: "transactionHash",
104
+ type: "bytes32",
105
+ },
106
+ ],
107
+ name: "LogGatewayWithdraw",
108
+ type: "event",
109
+ },
110
+ {
111
+ anonymous: false,
112
+ inputs: [
113
+ {
114
+ indexed: true,
115
+ internalType: "address",
116
+ name: "previousOwner",
117
+ type: "address",
118
+ },
119
+ {
120
+ indexed: true,
121
+ internalType: "address",
122
+ name: "newOwner",
123
+ type: "address",
124
+ },
125
+ ],
126
+ name: "OwnershipTransferred",
127
+ type: "event",
128
+ },
129
+ {
130
+ inputs: [],
131
+ name: "_vnonce",
132
+ outputs: [
133
+ {
134
+ internalType: "uint256",
135
+ name: "",
136
+ type: "uint256",
137
+ },
138
+ ],
139
+ stateMutability: "view",
140
+ type: "function",
141
+ },
142
+ {
143
+ inputs: [
144
+ {
145
+ internalType: "address",
146
+ name: "token_",
147
+ type: "address",
148
+ },
149
+ {
150
+ internalType: "uint256",
151
+ name: "amount_",
152
+ type: "uint256",
153
+ },
154
+ {
155
+ internalType: "uint32",
156
+ name: "chainId_",
157
+ type: "uint32",
158
+ },
159
+ ],
160
+ name: "deposit",
161
+ outputs: [],
162
+ stateMutability: "nonpayable",
163
+ type: "function",
164
+ },
165
+ {
166
+ inputs: [
167
+ {
168
+ internalType: "address",
169
+ name: "to_",
170
+ type: "address",
171
+ },
172
+ {
173
+ internalType: "address",
174
+ name: "token_",
175
+ type: "address",
176
+ },
177
+ {
178
+ internalType: "uint256",
179
+ name: "amount_",
180
+ type: "uint256",
181
+ },
182
+ {
183
+ internalType: "uint32",
184
+ name: "chainId_",
185
+ type: "uint32",
186
+ },
187
+ ],
188
+ name: "depositFor",
189
+ outputs: [],
190
+ stateMutability: "nonpayable",
191
+ type: "function",
192
+ },
193
+ {
194
+ inputs: [],
195
+ name: "owner",
196
+ outputs: [
197
+ {
198
+ internalType: "address",
199
+ name: "",
200
+ type: "address",
201
+ },
202
+ ],
203
+ stateMutability: "view",
204
+ type: "function",
205
+ },
206
+ {
207
+ inputs: [],
208
+ name: "renounceOwnership",
209
+ outputs: [],
210
+ stateMutability: "nonpayable",
211
+ type: "function",
212
+ },
213
+ {
214
+ inputs: [
215
+ {
216
+ internalType: "uint256",
217
+ name: "amount_",
218
+ type: "uint256",
219
+ },
220
+ {
221
+ internalType: "address",
222
+ name: "user_",
223
+ type: "address",
224
+ },
225
+ {
226
+ internalType: "address",
227
+ name: "token_",
228
+ type: "address",
229
+ },
230
+ {
231
+ internalType: "uint32",
232
+ name: "chainId_",
233
+ type: "uint32",
234
+ },
235
+ {
236
+ internalType: "bytes32",
237
+ name: "transactionHash_",
238
+ type: "bytes32",
239
+ },
240
+ ],
241
+ name: "systemWithdraw",
242
+ outputs: [],
243
+ stateMutability: "nonpayable",
244
+ type: "function",
245
+ },
246
+ {
247
+ inputs: [
248
+ {
249
+ internalType: "address",
250
+ name: "newOwner",
251
+ type: "address",
252
+ },
253
+ ],
254
+ name: "transferOwnership",
255
+ outputs: [],
256
+ stateMutability: "nonpayable",
257
+ type: "function",
258
+ },
259
+ ];
260
+
261
+ export class InteropXGateway__factory {
262
+ static readonly abi = _abi;
263
+ static createInterface(): InteropXGatewayInterface {
264
+ return new utils.Interface(_abi) as InteropXGatewayInterface;
265
+ }
266
+ static connect(
267
+ address: string,
268
+ signerOrProvider: Signer | Provider
269
+ ): InteropXGateway {
270
+ return new Contract(address, _abi, signerOrProvider) as InteropXGateway;
271
+ }
272
+ }
@@ -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,14 +3,26 @@
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'
8
-
6
+ import { addresses } from '@/constants';
7
+ import { ChainId } from '@/types'
8
+ import { ethers } from 'ethers';
9
9
  export const http = axios.create();
10
10
 
11
11
  axiosRetry(http, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
12
12
 
13
13
 
14
+ export function shortenHash(hash: string, length: number = 4) {
15
+ if (!hash) return;
16
+
17
+ if (hash.length < 12) return hash;
18
+
19
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
20
+
21
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
22
+
23
+ return shortened;
24
+ }
25
+
14
26
  export function short(buffer: Buffer): string {
15
27
  return buffer.toString('hex').slice(0, 8) + '...'
16
28
  }
@@ -70,9 +82,11 @@ export const signGnosisSafeTx = async ({
70
82
  export const getRpcProviderUrl = (chainId: ChainId) => {
71
83
  switch (chainId) {
72
84
  case 1:
73
- return 'https://rpc.instadapp.io/mainnet';
85
+ return 'https://rpc.ankr.com/eth';
74
86
  case 137:
75
- return 'https://rpc.instadapp.io/polygon';
87
+ return 'https://rpc.ankr.com/polygon';
88
+ case 43114:
89
+ return 'https://rpc.ankr.com/avalanche';
76
90
  default:
77
91
  throw new Error(`Unknown chainId: ${chainId}`);
78
92
  }
@@ -113,4 +127,72 @@ export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout:
113
127
  clearTimeout(timeoutHandle);
114
128
  return result;
115
129
  }) as Promise<T>
130
+ }
131
+
132
+
133
+ export const generateInteropTransactionHash = (data: { action: string, submitTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
134
+ return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
135
+ String(data.action),
136
+ String(data.submitTransactionHash),
137
+ String(data.sourceChainId),
138
+ String(data.targetChainId),
139
+ ]);
140
+ }
141
+
142
+ export function getContract<TContract extends ethers.Contract>(address: string, contractInterface: ethers.ContractInterface | any, signerOrProvider?: ethers.Signer | ethers.providers.Provider) {
143
+ if (!ethers.utils.getAddress(address) || address === ethers.constants.AddressZero) {
144
+ throw Error(`Invalid 'address' parameter '${address}'.`)
145
+ }
146
+
147
+ const contract = new ethers.Contract(
148
+ address,
149
+ contractInterface,
150
+ signerOrProvider
151
+ ) as TContract
152
+
153
+ // Make sure the contract properties is writable
154
+ const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
155
+
156
+ if (!desc || desc.writable !== true) {
157
+ return contract
158
+ }
159
+
160
+ return new Proxy(contract, {
161
+ get(target, prop, receiver) {
162
+ const value = Reflect.get(target, prop, receiver);
163
+
164
+ if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
165
+ return async (...args: any[]) => {
166
+ try {
167
+ return await value.bind(contract)(...args);
168
+ } catch (error) {
169
+ throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`)
170
+ }
171
+ }
172
+ }
173
+
174
+
175
+ if (typeof value === 'object' && ['populateTransaction', 'estimateGas', 'functions', 'callStatic'].includes(String(prop))) {
176
+ const parentProp = String(prop);
177
+
178
+ return new Proxy(value, {
179
+ get(target, prop, receiver) {
180
+ const value = Reflect.get(target, prop, receiver);
181
+
182
+ if (typeof value === 'function') {
183
+ return async (...args: any[]) => {
184
+ try {
185
+ return await value.bind(contract)(...args);
186
+ } catch (error) {
187
+ throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`)
188
+ }
189
+ }
190
+ }
191
+ }
192
+ })
193
+ }
194
+
195
+ return value;
196
+ },
197
+ });
116
198
  }
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,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ethers_1 = require("ethers");
4
- const types_1 = require("types");
5
- class Config {
6
- constructor() {
7
- this.events = new types_1.EventBus();
8
- this.maxPeers = 10;
9
- this.privateKey = process.env.PRIVATE_KEY;
10
- this.wallet = new ethers_1.Wallet(this.privateKey);
11
- this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
12
- }
13
- isLeadNode() {
14
- return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
15
- }
16
- }
17
- exports.default = new Config();
@@ -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;