@instadapp/interop-x 0.0.0-dev.80722d6 → 0.0.0-dev.8965b57

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. package/bin/interop-x +1 -1
  2. package/dist/package.json +73 -0
  3. package/dist/{abi → src/abi}/erc20.json +0 -0
  4. package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
  5. package/dist/{abi → src/abi}/index.js +2 -4
  6. package/dist/src/abi/interopXContract.json +391 -0
  7. package/dist/src/alias.js +10 -0
  8. package/dist/src/api/index.js +36 -0
  9. package/dist/{config → src/config}/index.js +11 -1
  10. package/dist/{constants → src/constants}/addresses.js +3 -11
  11. package/dist/{constants → src/constants}/index.js +0 -0
  12. package/dist/{constants → src/constants}/tokens.js +31 -1
  13. package/dist/{db → src/db}/index.js +0 -0
  14. package/dist/{db → src/db}/models/index.js +0 -0
  15. package/dist/{db → src/db}/models/transaction.js +27 -9
  16. package/dist/{db → src/db}/sequelize.js +0 -0
  17. package/dist/src/gnosis/actions/index.js +9 -0
  18. package/dist/src/gnosis/actions/withdraw/index.js +55 -0
  19. package/dist/src/gnosis/index.js +20 -0
  20. package/dist/src/index.js +119 -0
  21. package/dist/{logger → src/logger}/index.js +0 -0
  22. package/dist/{net → src/net}/index.js +0 -0
  23. package/dist/{net → src/net}/peer/index.js +8 -3
  24. package/dist/{net → src/net}/pool/index.js +32 -9
  25. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
  26. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +21 -12
  27. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  28. package/dist/{net → src/net}/protocol/index.js +51 -1
  29. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  30. package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
  31. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +152 -0
  32. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +77 -0
  33. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
  34. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  35. package/dist/src/tasks/index.js +38 -0
  36. package/dist/{typechain → src/typechain}/Erc20.js +0 -0
  37. package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
  38. package/dist/{typechain/InteropBridgeToken.js → src/typechain/InteropXContract.js} +0 -0
  39. package/dist/{typechain → src/typechain}/common.js +0 -0
  40. package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
  41. package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
  42. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  43. package/dist/src/typechain/factories/index.js +12 -0
  44. package/dist/{typechain → src/typechain}/index.js +3 -5
  45. package/dist/{types.js → src/types.js} +0 -0
  46. package/dist/src/utils/index.js +168 -0
  47. package/package.json +13 -6
  48. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  49. package/src/abi/index.ts +2 -4
  50. package/src/abi/interopXContract.json +391 -0
  51. package/src/alias.ts +6 -0
  52. package/src/api/index.ts +36 -0
  53. package/src/config/index.ts +11 -1
  54. package/src/constants/addresses.ts +3 -11
  55. package/src/constants/tokens.ts +32 -2
  56. package/src/db/models/transaction.ts +68 -25
  57. package/src/gnosis/actions/index.ts +5 -0
  58. package/src/gnosis/actions/withdraw/index.ts +76 -0
  59. package/src/gnosis/index.ts +19 -0
  60. package/src/index.ts +101 -24
  61. package/src/net/peer/index.ts +9 -7
  62. package/src/net/pool/index.ts +41 -11
  63. package/src/net/protocol/dial/SignatureDialProtocol.ts +23 -13
  64. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  65. package/src/net/protocol/index.ts +67 -1
  66. package/src/tasks/AutoUpdateTask.ts +82 -0
  67. package/src/tasks/BaseTask.ts +14 -4
  68. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +216 -0
  69. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +114 -0
  70. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
  71. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  72. package/src/tasks/index.ts +24 -5
  73. package/src/typechain/InteropXContract.ts +524 -0
  74. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  75. package/src/typechain/factories/index.ts +1 -2
  76. package/src/typechain/index.ts +2 -4
  77. package/src/utils/index.ts +119 -8
  78. package/tsconfig.json +7 -2
  79. package/dist/abi/interopBridgeToken.json +0 -286
  80. package/dist/abi/interopXGateway.json +0 -184
  81. package/dist/index.js +0 -63
  82. package/dist/tasks/InteropXGateway/SyncDepositEvents.js +0 -79
  83. package/dist/tasks/index.js +0 -27
  84. package/dist/typechain/InteropXGateway.js +0 -2
  85. package/dist/typechain/factories/InteropBridgeToken__factory.js +0 -459
  86. package/dist/typechain/factories/InteropXGateway__factory.js +0 -265
  87. package/dist/typechain/factories/index.js +0 -14
  88. package/dist/utils/index.js +0 -101
  89. package/src/abi/interopBridgeToken.json +0 -286
  90. package/src/abi/interopXGateway.json +0 -184
  91. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -114
  92. package/src/typechain/InteropBridgeToken.ts +0 -686
  93. package/src/typechain/InteropXGateway.ts +0 -407
  94. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  95. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -0,0 +1,533 @@
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
+ InteropXContract,
9
+ InteropXContractInterface,
10
+ } from "../InteropXContract";
11
+
12
+ const _abi = [
13
+ {
14
+ anonymous: false,
15
+ inputs: [
16
+ {
17
+ indexed: true,
18
+ internalType: "address",
19
+ name: "bridger",
20
+ type: "address",
21
+ },
22
+ {
23
+ components: [
24
+ {
25
+ components: [
26
+ {
27
+ internalType: "address",
28
+ name: "sourceToken",
29
+ type: "address",
30
+ },
31
+ {
32
+ internalType: "address",
33
+ name: "targetToken",
34
+ type: "address",
35
+ },
36
+ {
37
+ internalType: "uint256",
38
+ name: "amount",
39
+ type: "uint256",
40
+ },
41
+ ],
42
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
43
+ name: "supply",
44
+ type: "tuple[]",
45
+ },
46
+ {
47
+ components: [
48
+ {
49
+ internalType: "address",
50
+ name: "sourceToken",
51
+ type: "address",
52
+ },
53
+ {
54
+ internalType: "address",
55
+ name: "targetToken",
56
+ type: "address",
57
+ },
58
+ {
59
+ internalType: "uint256",
60
+ name: "amount",
61
+ type: "uint256",
62
+ },
63
+ ],
64
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
65
+ name: "withdraw",
66
+ type: "tuple[]",
67
+ },
68
+ ],
69
+ indexed: false,
70
+ internalType: "struct InteropXContractBeta.Position",
71
+ name: "position",
72
+ type: "tuple",
73
+ },
74
+ {
75
+ indexed: true,
76
+ internalType: "uint32",
77
+ name: "sourceChainId",
78
+ type: "uint32",
79
+ },
80
+ {
81
+ indexed: false,
82
+ internalType: "uint32",
83
+ name: "targetChainId",
84
+ type: "uint32",
85
+ },
86
+ {
87
+ indexed: true,
88
+ internalType: "bytes32",
89
+ name: "requestTransactionHash",
90
+ type: "bytes32",
91
+ },
92
+ {
93
+ indexed: false,
94
+ internalType: "bytes",
95
+ name: "metadata",
96
+ type: "bytes",
97
+ },
98
+ ],
99
+ name: "LogBridgeCommitted",
100
+ type: "event",
101
+ },
102
+ {
103
+ anonymous: false,
104
+ inputs: [
105
+ {
106
+ indexed: true,
107
+ internalType: "address",
108
+ name: "bridger",
109
+ type: "address",
110
+ },
111
+ {
112
+ components: [
113
+ {
114
+ components: [
115
+ {
116
+ internalType: "address",
117
+ name: "sourceToken",
118
+ type: "address",
119
+ },
120
+ {
121
+ internalType: "address",
122
+ name: "targetToken",
123
+ type: "address",
124
+ },
125
+ {
126
+ internalType: "uint256",
127
+ name: "amount",
128
+ type: "uint256",
129
+ },
130
+ ],
131
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
132
+ name: "supply",
133
+ type: "tuple[]",
134
+ },
135
+ {
136
+ components: [
137
+ {
138
+ internalType: "address",
139
+ name: "sourceToken",
140
+ type: "address",
141
+ },
142
+ {
143
+ internalType: "address",
144
+ name: "targetToken",
145
+ type: "address",
146
+ },
147
+ {
148
+ internalType: "uint256",
149
+ name: "amount",
150
+ type: "uint256",
151
+ },
152
+ ],
153
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
154
+ name: "withdraw",
155
+ type: "tuple[]",
156
+ },
157
+ ],
158
+ indexed: false,
159
+ internalType: "struct InteropXContractBeta.Position",
160
+ name: "position",
161
+ type: "tuple",
162
+ },
163
+ {
164
+ indexed: false,
165
+ internalType: "uint256",
166
+ name: "sourceChainId",
167
+ type: "uint256",
168
+ },
169
+ {
170
+ indexed: true,
171
+ internalType: "uint256",
172
+ name: "targetChainId",
173
+ type: "uint256",
174
+ },
175
+ {
176
+ indexed: true,
177
+ internalType: "bytes32",
178
+ name: "requestTransactionHash",
179
+ type: "bytes32",
180
+ },
181
+ {
182
+ indexed: false,
183
+ internalType: "bytes32",
184
+ name: "targetCommittedTransactionHash",
185
+ type: "bytes32",
186
+ },
187
+ {
188
+ indexed: false,
189
+ internalType: "bytes",
190
+ name: "metadata",
191
+ type: "bytes",
192
+ },
193
+ ],
194
+ name: "LogBridgeCompleted",
195
+ type: "event",
196
+ },
197
+ {
198
+ anonymous: false,
199
+ inputs: [
200
+ {
201
+ indexed: true,
202
+ internalType: "address",
203
+ name: "bridger",
204
+ type: "address",
205
+ },
206
+ {
207
+ components: [
208
+ {
209
+ components: [
210
+ {
211
+ internalType: "address",
212
+ name: "sourceToken",
213
+ type: "address",
214
+ },
215
+ {
216
+ internalType: "address",
217
+ name: "targetToken",
218
+ type: "address",
219
+ },
220
+ {
221
+ internalType: "uint256",
222
+ name: "amount",
223
+ type: "uint256",
224
+ },
225
+ ],
226
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
227
+ name: "supply",
228
+ type: "tuple[]",
229
+ },
230
+ {
231
+ components: [
232
+ {
233
+ internalType: "address",
234
+ name: "sourceToken",
235
+ type: "address",
236
+ },
237
+ {
238
+ internalType: "address",
239
+ name: "targetToken",
240
+ type: "address",
241
+ },
242
+ {
243
+ internalType: "uint256",
244
+ name: "amount",
245
+ type: "uint256",
246
+ },
247
+ ],
248
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
249
+ name: "withdraw",
250
+ type: "tuple[]",
251
+ },
252
+ ],
253
+ indexed: false,
254
+ internalType: "struct InteropXContractBeta.Position",
255
+ name: "position",
256
+ type: "tuple",
257
+ },
258
+ {
259
+ indexed: false,
260
+ internalType: "uint256",
261
+ name: "sourceChainId",
262
+ type: "uint256",
263
+ },
264
+ {
265
+ indexed: true,
266
+ internalType: "uint256",
267
+ name: "targetChainId",
268
+ type: "uint256",
269
+ },
270
+ {
271
+ indexed: false,
272
+ internalType: "bytes",
273
+ name: "metadata",
274
+ type: "bytes",
275
+ },
276
+ ],
277
+ name: "LogBridgeRequest",
278
+ type: "event",
279
+ },
280
+ {
281
+ anonymous: false,
282
+ inputs: [
283
+ {
284
+ indexed: true,
285
+ internalType: "address",
286
+ name: "bridger",
287
+ type: "address",
288
+ },
289
+ {
290
+ components: [
291
+ {
292
+ components: [
293
+ {
294
+ internalType: "address",
295
+ name: "sourceToken",
296
+ type: "address",
297
+ },
298
+ {
299
+ internalType: "address",
300
+ name: "targetToken",
301
+ type: "address",
302
+ },
303
+ {
304
+ internalType: "uint256",
305
+ name: "amount",
306
+ type: "uint256",
307
+ },
308
+ ],
309
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
310
+ name: "supply",
311
+ type: "tuple[]",
312
+ },
313
+ {
314
+ components: [
315
+ {
316
+ internalType: "address",
317
+ name: "sourceToken",
318
+ type: "address",
319
+ },
320
+ {
321
+ internalType: "address",
322
+ name: "targetToken",
323
+ type: "address",
324
+ },
325
+ {
326
+ internalType: "uint256",
327
+ name: "amount",
328
+ type: "uint256",
329
+ },
330
+ ],
331
+ internalType: "struct InteropXContractBeta.TokenInfo[]",
332
+ name: "withdraw",
333
+ type: "tuple[]",
334
+ },
335
+ ],
336
+ indexed: false,
337
+ internalType: "struct InteropXContractBeta.Position",
338
+ name: "position",
339
+ type: "tuple",
340
+ },
341
+ {
342
+ indexed: false,
343
+ internalType: "uint32",
344
+ name: "sourceChainId",
345
+ type: "uint32",
346
+ },
347
+ {
348
+ indexed: true,
349
+ internalType: "uint32",
350
+ name: "targetChainId",
351
+ type: "uint32",
352
+ },
353
+ {
354
+ indexed: true,
355
+ internalType: "bytes32",
356
+ name: "requestTransactionHash",
357
+ type: "bytes32",
358
+ },
359
+ {
360
+ indexed: false,
361
+ internalType: "bytes",
362
+ name: "metadata",
363
+ type: "bytes",
364
+ },
365
+ ],
366
+ name: "LogBridgeRequestSent",
367
+ type: "event",
368
+ },
369
+ {
370
+ inputs: [],
371
+ name: "_vnonce",
372
+ outputs: [
373
+ {
374
+ internalType: "uint256",
375
+ name: "",
376
+ type: "uint256",
377
+ },
378
+ ],
379
+ stateMutability: "view",
380
+ type: "function",
381
+ },
382
+ {
383
+ inputs: [
384
+ {
385
+ internalType: "address",
386
+ name: "to_",
387
+ type: "address",
388
+ },
389
+ {
390
+ internalType: "address",
391
+ name: "sourceToken_",
392
+ type: "address",
393
+ },
394
+ {
395
+ internalType: "address",
396
+ name: "targetToken_",
397
+ type: "address",
398
+ },
399
+ {
400
+ internalType: "uint256",
401
+ name: "amount_",
402
+ type: "uint256",
403
+ },
404
+ {
405
+ internalType: "uint32",
406
+ name: "targetChainId_",
407
+ type: "uint32",
408
+ },
409
+ {
410
+ internalType: "bytes32",
411
+ name: "transactionHash_",
412
+ type: "bytes32",
413
+ },
414
+ {
415
+ internalType: "bytes",
416
+ name: "metadata_",
417
+ type: "bytes",
418
+ },
419
+ ],
420
+ name: "completeBridge",
421
+ outputs: [],
422
+ stateMutability: "nonpayable",
423
+ type: "function",
424
+ },
425
+ {
426
+ inputs: [
427
+ {
428
+ internalType: "address",
429
+ name: "sourceToken_",
430
+ type: "address",
431
+ },
432
+ {
433
+ internalType: "address",
434
+ name: "targetToken_",
435
+ type: "address",
436
+ },
437
+ {
438
+ internalType: "uint256",
439
+ name: "amount_",
440
+ type: "uint256",
441
+ },
442
+ {
443
+ internalType: "uint32",
444
+ name: "targetChainId_",
445
+ type: "uint32",
446
+ },
447
+ {
448
+ internalType: "bytes",
449
+ name: "metadata_",
450
+ type: "bytes",
451
+ },
452
+ ],
453
+ name: "requestWithdraw",
454
+ outputs: [],
455
+ stateMutability: "nonpayable",
456
+ type: "function",
457
+ },
458
+ {
459
+ inputs: [
460
+ {
461
+ internalType: "address",
462
+ name: "",
463
+ type: "address",
464
+ },
465
+ ],
466
+ name: "whitelistedMapping",
467
+ outputs: [
468
+ {
469
+ internalType: "uint256",
470
+ name: "",
471
+ type: "uint256",
472
+ },
473
+ ],
474
+ stateMutability: "view",
475
+ type: "function",
476
+ },
477
+ {
478
+ inputs: [
479
+ {
480
+ internalType: "address",
481
+ name: "user_",
482
+ type: "address",
483
+ },
484
+ {
485
+ internalType: "address",
486
+ name: "sourceToken_",
487
+ type: "address",
488
+ },
489
+ {
490
+ internalType: "address",
491
+ name: "targetToken_",
492
+ type: "address",
493
+ },
494
+ {
495
+ internalType: "uint256",
496
+ name: "amount_",
497
+ type: "uint256",
498
+ },
499
+ {
500
+ internalType: "uint32",
501
+ name: "chainId_",
502
+ type: "uint32",
503
+ },
504
+ {
505
+ internalType: "bytes32",
506
+ name: "transactionHash_",
507
+ type: "bytes32",
508
+ },
509
+ {
510
+ internalType: "bytes",
511
+ name: "metadata_",
512
+ type: "bytes",
513
+ },
514
+ ],
515
+ name: "withdrawRequested",
516
+ outputs: [],
517
+ stateMutability: "nonpayable",
518
+ type: "function",
519
+ },
520
+ ];
521
+
522
+ export class InteropXContract__factory {
523
+ static readonly abi = _abi;
524
+ static createInterface(): InteropXContractInterface {
525
+ return new utils.Interface(_abi) as InteropXContractInterface;
526
+ }
527
+ static connect(
528
+ address: string,
529
+ signerOrProvider: Signer | Provider
530
+ ): InteropXContract {
531
+ return new Contract(address, _abi, signerOrProvider) as InteropXContract;
532
+ }
533
+ }
@@ -3,5 +3,4 @@
3
3
  /* eslint-disable */
4
4
  export { Erc20__factory } from "./Erc20__factory";
5
5
  export { GnosisSafe__factory } from "./GnosisSafe__factory";
6
- export { InteropBridgeToken__factory } from "./InteropBridgeToken__factory";
7
- export { InteropXGateway__factory } from "./InteropXGateway__factory";
6
+ export { InteropXContract__factory } from "./InteropXContract__factory";
@@ -3,10 +3,8 @@
3
3
  /* eslint-disable */
4
4
  export type { Erc20 } from "./Erc20";
5
5
  export type { GnosisSafe } from "./GnosisSafe";
6
- export type { InteropBridgeToken } from "./InteropBridgeToken";
7
- export type { InteropXGateway } from "./InteropXGateway";
6
+ export type { InteropXContract } from "./InteropXContract";
8
7
  export * as factories from "./factories";
9
8
  export { Erc20__factory } from "./factories/Erc20__factory";
10
9
  export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
11
- export { InteropBridgeToken__factory } from "./factories/InteropBridgeToken__factory";
12
- export { InteropXGateway__factory } from "./factories/InteropXGateway__factory";
10
+ export { InteropXContract__factory } from "./factories/InteropXContract__factory";
@@ -6,12 +6,24 @@ import axiosRetry from "axios-retry";
6
6
  import { addresses } from '@/constants';
7
7
  import { ChainId } from '@/types'
8
8
  import { ethers } from 'ethers';
9
-
9
+ import { GnosisSafe } from '@/typechain';
10
10
  export const http = axios.create();
11
11
 
12
12
  axiosRetry(http, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
13
13
 
14
14
 
15
+ export function shortenHash(hash: string, length: number = 4) {
16
+ if (!hash) return;
17
+
18
+ if (hash.length < 12) return hash;
19
+
20
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
21
+
22
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
23
+
24
+ return shortened;
25
+ }
26
+
15
27
  export function short(buffer: Buffer): string {
16
28
  return buffer.toString('hex').slice(0, 8) + '...'
17
29
  }
@@ -71,11 +83,11 @@ export const signGnosisSafeTx = async ({
71
83
  export const getRpcProviderUrl = (chainId: ChainId) => {
72
84
  switch (chainId) {
73
85
  case 1:
74
- return 'https://rpc.instadapp.io/mainnet';
86
+ return 'https://rpc.ankr.com/eth';
75
87
  case 137:
76
- return 'https://rpc.instadapp.io/polygon';
88
+ return 'https://rpc.ankr.com/polygon';
77
89
  case 43114:
78
- return 'https://rpc.instadapp.io/avalanche';
90
+ return 'https://rpc.ankr.com/avalanche';
79
91
  default:
80
92
  throw new Error(`Unknown chainId: ${chainId}`);
81
93
  }
@@ -119,11 +131,110 @@ export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout:
119
131
  }
120
132
 
121
133
 
122
- export const generateInteropTransactionHash = (data: { type: string, sourceTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
123
- return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
124
- String(data.type),
125
- String(data.sourceTransactionHash),
134
+ export const generateInteropTransactionHash = (data: { action: string, bridger: string, requestTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
135
+ return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string', 'string'], [
136
+ String(data.action),
137
+ String(data.bridger),
138
+ String(data.requestTransactionHash),
126
139
  String(data.sourceChainId),
127
140
  String(data.targetChainId),
128
141
  ]);
142
+ }
143
+
144
+ export function getContract<TContract extends ethers.Contract>(address: string, contractInterface: ethers.ContractInterface | any, signerOrProvider?: ethers.Signer | ethers.providers.Provider) {
145
+ if (!ethers.utils.getAddress(address) || address === ethers.constants.AddressZero) {
146
+ throw Error(`Invalid 'address' parameter '${address}'.`)
147
+ }
148
+
149
+ const contract = new ethers.Contract(
150
+ address,
151
+ contractInterface,
152
+ signerOrProvider
153
+ ) as TContract
154
+
155
+ // Make sure the contract properties is writable
156
+ const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
157
+
158
+ if (!desc || desc.writable !== true) {
159
+ return contract
160
+ }
161
+
162
+ return new Proxy(contract, {
163
+ get(target, prop, receiver) {
164
+ const value = Reflect.get(target, prop, receiver);
165
+
166
+ if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
167
+ return async (...args: any[]) => {
168
+ try {
169
+ return await value.bind(contract)(...args);
170
+ } catch (error) {
171
+ throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`)
172
+ }
173
+ }
174
+ }
175
+
176
+
177
+ if (typeof value === 'object' && ['populateTransaction', 'estimateGas', 'functions', 'callStatic'].includes(String(prop))) {
178
+ const parentProp = String(prop);
179
+
180
+ return new Proxy(value, {
181
+ get(target, prop, receiver) {
182
+ const value = Reflect.get(target, prop, receiver);
183
+
184
+ if (typeof value === 'function') {
185
+ return async (...args: any[]) => {
186
+ try {
187
+ return await value.bind(contract)(...args);
188
+ } catch (error) {
189
+ throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`)
190
+ }
191
+ }
192
+ }
193
+ }
194
+ })
195
+ }
196
+
197
+ return value;
198
+ },
199
+ });
200
+ }
201
+
202
+ export const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
203
+ console.log(transactionData);
204
+
205
+ let isExecuted = await safeContract.dataHashes(
206
+ await safeContract.getTransactionHash(
207
+ transactionData.to,
208
+ transactionData.value,
209
+ transactionData.data,
210
+ transactionData.operation,
211
+ transactionData.safeTxGas,
212
+ transactionData.baseGas,
213
+ transactionData.gasPrice,
214
+ transactionData.gasToken,
215
+ transactionData.refundReceiver,
216
+ transactionData.nonce
217
+ )
218
+ )
219
+
220
+ while (isExecuted == 1) {
221
+ transactionData.safeTxGas = ethers.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
222
+
223
+ isExecuted = await safeContract.dataHashes(
224
+ await safeContract.getTransactionHash(
225
+ transactionData.to,
226
+ transactionData.value,
227
+ transactionData.data,
228
+ transactionData.operation,
229
+ transactionData.safeTxGas,
230
+ transactionData.baseGas,
231
+ transactionData.gasPrice,
232
+ transactionData.gasToken,
233
+ transactionData.refundReceiver,
234
+ transactionData.nonce
235
+ )
236
+ )
237
+ }
238
+
239
+ return transactionData
129
240
  }