@instadapp/interop-x 0.0.0-dev.ee3d74b → 0.0.0-dev.ef7acff

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 (57) hide show
  1. package/dist/package.json +3 -1
  2. package/dist/src/abi/index.js +2 -0
  3. package/dist/src/abi/instList.json +232 -0
  4. package/dist/src/api/index.js +7 -0
  5. package/dist/src/constants/addresses.js +4 -2
  6. package/dist/src/db/models/transaction.js +15 -7
  7. package/dist/src/errors/index.js +17 -0
  8. package/dist/src/gnosis/actions/aaveV2/source.js +15 -4
  9. package/dist/src/gnosis/actions/aaveV2/target.js +78 -0
  10. package/dist/src/index.js +1 -1
  11. package/dist/src/tasks/InteropX/{ProcessSubmitSubmitEvents.js → ProcessSubmitEvents.js} +29 -5
  12. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +184 -0
  13. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +112 -0
  14. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +1 -0
  15. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +105 -0
  16. package/dist/src/tasks/index.js +13 -5
  17. package/dist/src/typechain/InstList.js +2 -0
  18. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  19. package/dist/src/typechain/factories/index.js +3 -1
  20. package/dist/src/typechain/index.js +3 -1
  21. package/dist/src/utils/async.js +18 -0
  22. package/dist/src/utils/dsa.js +24 -0
  23. package/dist/src/utils/formatting.js +17 -0
  24. package/dist/src/utils/gnosis.js +62 -0
  25. package/dist/src/utils/http.js +10 -0
  26. package/dist/src/utils/index.js +21 -219
  27. package/dist/src/utils/interop.js +16 -0
  28. package/dist/src/utils/validate.js +23 -0
  29. package/dist/src/utils/web3.js +92 -0
  30. package/package.json +3 -1
  31. package/src/abi/index.ts +2 -0
  32. package/src/abi/instList.json +232 -0
  33. package/src/api/index.ts +8 -0
  34. package/src/constants/addresses.ts +5 -3
  35. package/src/db/models/transaction.ts +134 -80
  36. package/src/errors/index.ts +13 -0
  37. package/src/gnosis/actions/aaveV2/source.ts +19 -5
  38. package/src/gnosis/actions/aaveV2/target.ts +130 -2
  39. package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +35 -7
  40. package/src/tasks/InteropX/ProcessValidateEvents.ts +272 -0
  41. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +160 -0
  42. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -4
  43. package/src/tasks/InteropX/SyncLogValidateEvents.ts +150 -0
  44. package/src/tasks/index.ts +16 -5
  45. package/src/typechain/InstList.ts +402 -0
  46. package/src/typechain/factories/InstList__factory.ts +253 -0
  47. package/src/typechain/factories/index.ts +1 -0
  48. package/src/typechain/index.ts +2 -0
  49. package/src/utils/async.ts +22 -0
  50. package/src/utils/dsa.ts +30 -0
  51. package/src/utils/formatting.ts +15 -0
  52. package/src/utils/gnosis.ts +123 -0
  53. package/src/utils/http.ts +6 -0
  54. package/src/utils/index.ts +8 -365
  55. package/src/utils/interop.ts +28 -0
  56. package/src/utils/validate.ts +24 -0
  57. package/src/utils/web3.ts +131 -0
@@ -0,0 +1,131 @@
1
+ import { ChainId } from "@/types";
2
+ import retry from "async-retry";
3
+ import { ethers } from "ethers";
4
+
5
+ export const getRpcProviderUrl = (chainId: ChainId) => {
6
+ switch (chainId) {
7
+ case 1:
8
+ return "https://rpc.ankr.com/eth";
9
+ case 137:
10
+ return "https://rpc.ankr.com/polygon";
11
+ case 43114:
12
+ return "https://rpc.ankr.com/avalanche";
13
+ default:
14
+ throw new Error(`Unknown chainId: ${chainId}`);
15
+ }
16
+ };
17
+
18
+
19
+ export class ContractError extends Error {
20
+ method: string;
21
+ address: string;
22
+ args: any[];
23
+ }
24
+
25
+ export function getContract<TContract extends ethers.Contract>(
26
+ address: string,
27
+ contractInterface: ethers.ContractInterface | any,
28
+ signerOrProvider?: ethers.Signer | ethers.providers.Provider
29
+ ) {
30
+ if (
31
+ !ethers.utils.getAddress(address) ||
32
+ address === ethers.constants.AddressZero
33
+ ) {
34
+ throw Error(`Invalid 'address' parameter '${address}'.`);
35
+ }
36
+
37
+ const contract = new ethers.Contract(
38
+ address,
39
+ contractInterface,
40
+ signerOrProvider
41
+ ) as TContract;
42
+
43
+ // Make sure the contract properties is writable
44
+ const desc = Object.getOwnPropertyDescriptor(contract, "functions");
45
+
46
+ if (!desc || desc.writable !== true) {
47
+ return contract;
48
+ }
49
+
50
+ return new Proxy(contract, {
51
+ get(target, prop, receiver) {
52
+ const value = Reflect.get(target, prop, receiver);
53
+
54
+ if (
55
+ typeof value === "function" &&
56
+ (contract.functions.hasOwnProperty(prop) ||
57
+ ["queryFilter"].includes(String(prop)))
58
+ ) {
59
+ let isConstant = false;
60
+
61
+ try {
62
+ isConstant = contract.interface.getFunction(String(prop)).constant;
63
+ } catch (error) { }
64
+
65
+ return async (...args: any[]) => {
66
+ try {
67
+ return await retry(
68
+ async () => await value.bind(contract)(...args),
69
+ { retries: isConstant ? 1 : 3 }
70
+ );
71
+ } catch (error) {
72
+ const err = new ContractError(
73
+ `Error calling "${String(prop)}" on "${address}": ${error.reason || error.message
74
+ }`
75
+ );
76
+
77
+ err.method = String(prop);
78
+ err.address = address;
79
+ err.args = [...args];
80
+
81
+ throw err;
82
+ }
83
+ };
84
+ }
85
+
86
+ if (
87
+ typeof value === "object" &&
88
+ [
89
+ "populateTransaction",
90
+ "estimateGas",
91
+ "functions",
92
+ "callStatic",
93
+ ].includes(String(prop))
94
+ ) {
95
+ const parentProp = String(prop);
96
+
97
+ return new Proxy(value, {
98
+ get(target, prop, receiver) {
99
+ const value = Reflect.get(target, prop, receiver);
100
+
101
+ if (typeof value === "function") {
102
+ return async (...args: any[]) => {
103
+ try {
104
+ return await retry(
105
+ async () => await value.bind(contract)(...args),
106
+ { retries: parentProp === "callStatic" ? 3 : 1 }
107
+ );
108
+ } catch (error) {
109
+ const err = new ContractError(
110
+ `Error calling "${String(
111
+ prop
112
+ )}" using "${parentProp}" on "${address}": ${error.reason || error.message
113
+ }`
114
+ );
115
+
116
+ err.method = String(prop);
117
+ err.address = address;
118
+ err.args = [...args];
119
+
120
+ throw err;
121
+ }
122
+ };
123
+ }
124
+ },
125
+ });
126
+ }
127
+
128
+ return value;
129
+ },
130
+ });
131
+ }