@instadapp/interop-x 0.0.0-dev.c696e38 → 0.0.0-dev.cb34b2e

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 (92) hide show
  1. package/dist/package.json +9 -2
  2. package/dist/src/abi/aaveV2Resolver.json +832 -0
  3. package/dist/src/abi/balanceResolver.json +211 -0
  4. package/dist/src/abi/index.js +6 -0
  5. package/dist/src/abi/instList.json +232 -0
  6. package/dist/src/api/index.js +7 -0
  7. package/dist/src/constants/addresses.js +7 -1
  8. package/dist/src/constants/capPerChain.js +8 -0
  9. package/dist/src/constants/index.js +2 -0
  10. package/dist/src/constants/tokens.js +44 -44
  11. package/dist/src/constants/wrappedNativeToken.js +8 -0
  12. package/dist/src/crons/index.js +3 -0
  13. package/dist/src/crons/prices.js +16 -0
  14. package/dist/src/db/models/transaction.js +4 -0
  15. package/dist/src/errors/index.js +30 -0
  16. package/dist/src/gnosis/actions/aaveV2/source.js +2 -1
  17. package/dist/src/gnosis/actions/aaveV2/target.js +5 -3
  18. package/dist/src/index.js +2 -1
  19. package/dist/src/providers/index.js +17 -0
  20. package/dist/src/providers/retry-provider.js +45 -0
  21. package/dist/src/services/Prices.js +74 -0
  22. package/dist/src/services/index.js +8 -0
  23. package/dist/src/tasks/InteropX/{ProcessSubmitSubmitEvents.js → ProcessSubmitEvents.js} +106 -14
  24. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +30 -10
  25. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +113 -0
  26. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
  27. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +5 -4
  28. package/dist/src/tasks/index.js +7 -5
  29. package/dist/src/typechain/AaveV2Resolver.js +2 -0
  30. package/dist/src/typechain/BalanceResolver.js +2 -0
  31. package/dist/src/typechain/InstList.js +2 -0
  32. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  33. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  34. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  35. package/dist/src/typechain/factories/index.js +7 -1
  36. package/dist/src/typechain/index.js +7 -1
  37. package/dist/src/utils/async.js +18 -0
  38. package/dist/src/utils/dsa.js +24 -0
  39. package/dist/src/utils/formatting.js +67 -0
  40. package/dist/src/utils/gnosis.js +87 -0
  41. package/dist/src/utils/http.js +10 -0
  42. package/dist/src/utils/index.js +22 -220
  43. package/dist/src/utils/interop.js +16 -0
  44. package/dist/src/utils/tokens.js +22 -0
  45. package/dist/src/utils/validate.js +111 -0
  46. package/dist/src/utils/web3.js +93 -0
  47. package/package.json +9 -2
  48. package/src/abi/aaveV2Resolver.json +832 -0
  49. package/src/abi/balanceResolver.json +211 -0
  50. package/src/abi/index.ts +6 -0
  51. package/src/abi/instList.json +232 -0
  52. package/src/api/index.ts +8 -0
  53. package/src/constants/addresses.ts +18 -2
  54. package/src/constants/capPerChain.ts +5 -0
  55. package/src/constants/index.ts +2 -0
  56. package/src/constants/tokens.ts +44 -44
  57. package/src/constants/wrappedNativeToken.ts +5 -0
  58. package/src/crons/index.ts +1 -0
  59. package/src/crons/prices.ts +12 -0
  60. package/src/db/models/transaction.ts +21 -0
  61. package/src/errors/index.ts +26 -0
  62. package/src/gnosis/actions/aaveV2/source.ts +2 -1
  63. package/src/gnosis/actions/aaveV2/target.ts +13 -3
  64. package/src/index.ts +1 -0
  65. package/src/providers/index.ts +1 -0
  66. package/src/providers/retry-provider.ts +51 -0
  67. package/src/services/Prices.ts +89 -0
  68. package/src/services/index.ts +1 -0
  69. package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +133 -20
  70. package/src/tasks/InteropX/ProcessValidateEvents.ts +42 -19
  71. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +161 -0
  72. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +5 -6
  73. package/src/tasks/InteropX/SyncLogValidateEvents.ts +8 -9
  74. package/src/tasks/index.ts +8 -5
  75. package/src/typechain/AaveV2Resolver.ts +1017 -0
  76. package/src/typechain/BalanceResolver.ts +266 -0
  77. package/src/typechain/InstList.ts +402 -0
  78. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  79. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  80. package/src/typechain/factories/InstList__factory.ts +253 -0
  81. package/src/typechain/factories/index.ts +3 -0
  82. package/src/typechain/index.ts +6 -0
  83. package/src/utils/async.ts +22 -0
  84. package/src/utils/dsa.ts +30 -0
  85. package/src/utils/formatting.ts +68 -0
  86. package/src/utils/gnosis.ts +166 -0
  87. package/src/utils/http.ts +6 -0
  88. package/src/utils/index.ts +9 -365
  89. package/src/utils/interop.ts +28 -0
  90. package/src/utils/tokens.ts +21 -0
  91. package/src/utils/validate.ts +174 -0
  92. package/src/utils/web3.ts +132 -0
@@ -0,0 +1,235 @@
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
+ BalanceResolver,
9
+ BalanceResolverInterface,
10
+ } from "../BalanceResolver";
11
+
12
+ const _abi = [
13
+ {
14
+ inputs: [
15
+ {
16
+ internalType: "address",
17
+ name: "_wnativeToken",
18
+ type: "address",
19
+ },
20
+ ],
21
+ stateMutability: "nonpayable",
22
+ type: "constructor",
23
+ },
24
+ {
25
+ inputs: [
26
+ {
27
+ components: [
28
+ {
29
+ components: [
30
+ {
31
+ internalType: "address",
32
+ name: "sourceToken",
33
+ type: "address",
34
+ },
35
+ {
36
+ internalType: "address",
37
+ name: "targetToken",
38
+ type: "address",
39
+ },
40
+ {
41
+ internalType: "uint256",
42
+ name: "amount",
43
+ type: "uint256",
44
+ },
45
+ ],
46
+ internalType: "struct Variables.TokenInfo[]",
47
+ name: "supply",
48
+ type: "tuple[]",
49
+ },
50
+ {
51
+ components: [
52
+ {
53
+ internalType: "address",
54
+ name: "sourceToken",
55
+ type: "address",
56
+ },
57
+ {
58
+ internalType: "address",
59
+ name: "targetToken",
60
+ type: "address",
61
+ },
62
+ {
63
+ internalType: "uint256",
64
+ name: "amount",
65
+ type: "uint256",
66
+ },
67
+ ],
68
+ internalType: "struct Variables.TokenInfo[]",
69
+ name: "withdraw",
70
+ type: "tuple[]",
71
+ },
72
+ ],
73
+ internalType: "struct Variables.Position",
74
+ name: "position",
75
+ type: "tuple",
76
+ },
77
+ {
78
+ internalType: "address",
79
+ name: "liquidityContract",
80
+ type: "address",
81
+ },
82
+ {
83
+ internalType: "bool",
84
+ name: "isSupply",
85
+ type: "bool",
86
+ },
87
+ {
88
+ internalType: "bool",
89
+ name: "isTargetToken",
90
+ type: "bool",
91
+ },
92
+ ],
93
+ name: "checkLiquidity",
94
+ outputs: [
95
+ {
96
+ components: [
97
+ {
98
+ internalType: "bool",
99
+ name: "isOk",
100
+ type: "bool",
101
+ },
102
+ {
103
+ components: [
104
+ {
105
+ internalType: "address",
106
+ name: "token",
107
+ type: "address",
108
+ },
109
+ {
110
+ internalType: "uint256",
111
+ name: "liquidityAvailable",
112
+ type: "uint256",
113
+ },
114
+ {
115
+ internalType: "uint256",
116
+ name: "liquidityShort",
117
+ type: "uint256",
118
+ },
119
+ ],
120
+ internalType: "struct Helpers.LiquidityData[]",
121
+ name: "supply",
122
+ type: "tuple[]",
123
+ },
124
+ {
125
+ components: [
126
+ {
127
+ internalType: "address",
128
+ name: "token",
129
+ type: "address",
130
+ },
131
+ {
132
+ internalType: "uint256",
133
+ name: "liquidityAvailable",
134
+ type: "uint256",
135
+ },
136
+ {
137
+ internalType: "uint256",
138
+ name: "liquidityShort",
139
+ type: "uint256",
140
+ },
141
+ ],
142
+ internalType: "struct Helpers.LiquidityData[]",
143
+ name: "withdraw",
144
+ type: "tuple[]",
145
+ },
146
+ ],
147
+ internalType: "struct Helpers.PositionData",
148
+ name: "p",
149
+ type: "tuple",
150
+ },
151
+ ],
152
+ stateMutability: "view",
153
+ type: "function",
154
+ },
155
+ {
156
+ inputs: [
157
+ {
158
+ internalType: "address[]",
159
+ name: "tokens",
160
+ type: "address[]",
161
+ },
162
+ {
163
+ internalType: "address",
164
+ name: "liquidityContract",
165
+ type: "address",
166
+ },
167
+ ],
168
+ name: "getLiquidity",
169
+ outputs: [
170
+ {
171
+ components: [
172
+ {
173
+ internalType: "address",
174
+ name: "token",
175
+ type: "address",
176
+ },
177
+ {
178
+ internalType: "uint256",
179
+ name: "liquidityAvailable",
180
+ type: "uint256",
181
+ },
182
+ {
183
+ internalType: "uint256",
184
+ name: "liquidityShort",
185
+ type: "uint256",
186
+ },
187
+ ],
188
+ internalType: "struct Helpers.LiquidityData[]",
189
+ name: "l",
190
+ type: "tuple[]",
191
+ },
192
+ ],
193
+ stateMutability: "view",
194
+ type: "function",
195
+ },
196
+ {
197
+ inputs: [],
198
+ name: "nativeToken",
199
+ outputs: [
200
+ {
201
+ internalType: "address",
202
+ name: "",
203
+ type: "address",
204
+ },
205
+ ],
206
+ stateMutability: "view",
207
+ type: "function",
208
+ },
209
+ {
210
+ inputs: [],
211
+ name: "wnativeToken",
212
+ outputs: [
213
+ {
214
+ internalType: "address",
215
+ name: "",
216
+ type: "address",
217
+ },
218
+ ],
219
+ stateMutability: "view",
220
+ type: "function",
221
+ },
222
+ ];
223
+
224
+ export class BalanceResolver__factory {
225
+ static readonly abi = _abi;
226
+ static createInterface(): BalanceResolverInterface {
227
+ return new utils.Interface(_abi) as BalanceResolverInterface;
228
+ }
229
+ static connect(
230
+ address: string,
231
+ signerOrProvider: Signer | Provider
232
+ ): BalanceResolver {
233
+ return new Contract(address, _abi, signerOrProvider) as BalanceResolver;
234
+ }
235
+ }
@@ -0,0 +1,253 @@
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 { InstList, InstListInterface } from "../InstList";
8
+
9
+ const _abi = [
10
+ {
11
+ inputs: [
12
+ {
13
+ internalType: "address",
14
+ name: "_instaIndex",
15
+ type: "address",
16
+ },
17
+ ],
18
+ stateMutability: "nonpayable",
19
+ type: "constructor",
20
+ },
21
+ {
22
+ inputs: [
23
+ {
24
+ internalType: "uint64",
25
+ name: "",
26
+ type: "uint64",
27
+ },
28
+ ],
29
+ name: "accountAddr",
30
+ outputs: [
31
+ {
32
+ internalType: "address",
33
+ name: "",
34
+ type: "address",
35
+ },
36
+ ],
37
+ stateMutability: "view",
38
+ type: "function",
39
+ },
40
+ {
41
+ inputs: [
42
+ {
43
+ internalType: "address",
44
+ name: "",
45
+ type: "address",
46
+ },
47
+ ],
48
+ name: "accountID",
49
+ outputs: [
50
+ {
51
+ internalType: "uint64",
52
+ name: "",
53
+ type: "uint64",
54
+ },
55
+ ],
56
+ stateMutability: "view",
57
+ type: "function",
58
+ },
59
+ {
60
+ inputs: [
61
+ {
62
+ internalType: "uint64",
63
+ name: "",
64
+ type: "uint64",
65
+ },
66
+ ],
67
+ name: "accountLink",
68
+ outputs: [
69
+ {
70
+ internalType: "address",
71
+ name: "first",
72
+ type: "address",
73
+ },
74
+ {
75
+ internalType: "address",
76
+ name: "last",
77
+ type: "address",
78
+ },
79
+ {
80
+ internalType: "uint64",
81
+ name: "count",
82
+ type: "uint64",
83
+ },
84
+ ],
85
+ stateMutability: "view",
86
+ type: "function",
87
+ },
88
+ {
89
+ inputs: [
90
+ {
91
+ internalType: "uint64",
92
+ name: "",
93
+ type: "uint64",
94
+ },
95
+ {
96
+ internalType: "address",
97
+ name: "",
98
+ type: "address",
99
+ },
100
+ ],
101
+ name: "accountList",
102
+ outputs: [
103
+ {
104
+ internalType: "address",
105
+ name: "prev",
106
+ type: "address",
107
+ },
108
+ {
109
+ internalType: "address",
110
+ name: "next",
111
+ type: "address",
112
+ },
113
+ ],
114
+ stateMutability: "view",
115
+ type: "function",
116
+ },
117
+ {
118
+ inputs: [],
119
+ name: "accounts",
120
+ outputs: [
121
+ {
122
+ internalType: "uint64",
123
+ name: "",
124
+ type: "uint64",
125
+ },
126
+ ],
127
+ stateMutability: "view",
128
+ type: "function",
129
+ },
130
+ {
131
+ inputs: [
132
+ {
133
+ internalType: "address",
134
+ name: "_owner",
135
+ type: "address",
136
+ },
137
+ ],
138
+ name: "addAuth",
139
+ outputs: [],
140
+ stateMutability: "nonpayable",
141
+ type: "function",
142
+ },
143
+ {
144
+ inputs: [
145
+ {
146
+ internalType: "address",
147
+ name: "_account",
148
+ type: "address",
149
+ },
150
+ ],
151
+ name: "init",
152
+ outputs: [],
153
+ stateMutability: "nonpayable",
154
+ type: "function",
155
+ },
156
+ {
157
+ inputs: [],
158
+ name: "instaIndex",
159
+ outputs: [
160
+ {
161
+ internalType: "address",
162
+ name: "",
163
+ type: "address",
164
+ },
165
+ ],
166
+ stateMutability: "view",
167
+ type: "function",
168
+ },
169
+ {
170
+ inputs: [
171
+ {
172
+ internalType: "address",
173
+ name: "_owner",
174
+ type: "address",
175
+ },
176
+ ],
177
+ name: "removeAuth",
178
+ outputs: [],
179
+ stateMutability: "nonpayable",
180
+ type: "function",
181
+ },
182
+ {
183
+ inputs: [
184
+ {
185
+ internalType: "address",
186
+ name: "",
187
+ type: "address",
188
+ },
189
+ ],
190
+ name: "userLink",
191
+ outputs: [
192
+ {
193
+ internalType: "uint64",
194
+ name: "first",
195
+ type: "uint64",
196
+ },
197
+ {
198
+ internalType: "uint64",
199
+ name: "last",
200
+ type: "uint64",
201
+ },
202
+ {
203
+ internalType: "uint64",
204
+ name: "count",
205
+ type: "uint64",
206
+ },
207
+ ],
208
+ stateMutability: "view",
209
+ type: "function",
210
+ },
211
+ {
212
+ inputs: [
213
+ {
214
+ internalType: "address",
215
+ name: "",
216
+ type: "address",
217
+ },
218
+ {
219
+ internalType: "uint64",
220
+ name: "",
221
+ type: "uint64",
222
+ },
223
+ ],
224
+ name: "userList",
225
+ outputs: [
226
+ {
227
+ internalType: "uint64",
228
+ name: "prev",
229
+ type: "uint64",
230
+ },
231
+ {
232
+ internalType: "uint64",
233
+ name: "next",
234
+ type: "uint64",
235
+ },
236
+ ],
237
+ stateMutability: "view",
238
+ type: "function",
239
+ },
240
+ ];
241
+
242
+ export class InstList__factory {
243
+ static readonly abi = _abi;
244
+ static createInterface(): InstListInterface {
245
+ return new utils.Interface(_abi) as InstListInterface;
246
+ }
247
+ static connect(
248
+ address: string,
249
+ signerOrProvider: Signer | Provider
250
+ ): InstList {
251
+ return new Contract(address, _abi, signerOrProvider) as InstList;
252
+ }
253
+ }
@@ -1,6 +1,9 @@
1
1
  /* Autogenerated file. Do not edit manually. */
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
+ export { AaveV2Resolver__factory } from "./AaveV2Resolver__factory";
5
+ export { BalanceResolver__factory } from "./BalanceResolver__factory";
4
6
  export { Erc20__factory } from "./Erc20__factory";
5
7
  export { GnosisSafe__factory } from "./GnosisSafe__factory";
8
+ export { InstList__factory } from "./InstList__factory";
6
9
  export { InteropX__factory } from "./InteropX__factory";
@@ -1,10 +1,16 @@
1
1
  /* Autogenerated file. Do not edit manually. */
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
+ export type { AaveV2Resolver } from "./AaveV2Resolver";
5
+ export type { BalanceResolver } from "./BalanceResolver";
4
6
  export type { Erc20 } from "./Erc20";
5
7
  export type { GnosisSafe } from "./GnosisSafe";
8
+ export type { InstList } from "./InstList";
6
9
  export type { InteropX } from "./InteropX";
7
10
  export * as factories from "./factories";
11
+ export { AaveV2Resolver__factory } from "./factories/AaveV2Resolver__factory";
12
+ export { BalanceResolver__factory } from "./factories/BalanceResolver__factory";
8
13
  export { Erc20__factory } from "./factories/Erc20__factory";
9
14
  export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
15
+ export { InstList__factory } from "./factories/InstList__factory";
10
16
  export { InteropX__factory } from "./factories/InteropX__factory";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Call an async function with a maximum time limit (in milliseconds) for the timeout
3
+ * Resolved promise for async function call, or an error if time limit reached
4
+ */
5
+ export const asyncCallWithTimeout = async <T>(
6
+ asyncPromise: Promise<T>,
7
+ timeout: number
8
+ ) => {
9
+ let timeoutHandle;
10
+
11
+ const timeoutPromise = new Promise((_resolve, reject) => {
12
+ timeoutHandle = setTimeout(
13
+ () => reject(new Error("Async call timeout limit reached")),
14
+ timeout
15
+ );
16
+ });
17
+
18
+ return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
19
+ clearTimeout(timeoutHandle);
20
+ return result;
21
+ }) as Promise<T>;
22
+ };
@@ -0,0 +1,30 @@
1
+ import Web3EthAbi from "web3-eth-abi";
2
+ import { connectors } from "@/abi/connectors";
3
+
4
+ export const encodeConnectorMethod = (params: {
5
+ connector: string;
6
+ method: string;
7
+ args: string[];
8
+ }) => {
9
+ const connectorInterface = getInterface(
10
+ connectors.versions[2][params.connector],
11
+ params.method
12
+ );
13
+
14
+ if (!connectorInterface)
15
+ throw new Error(`ConnectorInterface '${params.method}' not found`);
16
+
17
+ //@ts-ignore
18
+ return Web3EthAbi.encodeFunctionCall(connectorInterface, params.args);
19
+ };
20
+
21
+ const getInterface = (abiItems: any[], method: string) => {
22
+ const abiItem = abiItems.find((abiItem) => abiItem.name === method);
23
+
24
+ if (!abiItem) {
25
+ console.error(`${method} is an invalid method.`);
26
+ return;
27
+ }
28
+
29
+ return abiItem;
30
+ };
@@ -0,0 +1,68 @@
1
+ const locale = "en-US";
2
+
3
+ export function formatUsd(value: any, fractionDigits = 0) {
4
+ const formatter = new Intl.NumberFormat(locale, {
5
+ style: "currency",
6
+ currency: "USD",
7
+ minimumFractionDigits: fractionDigits,
8
+ maximumFractionDigits: fractionDigits
9
+ });
10
+
11
+ return formatter.format(value);
12
+ }
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
+
26
+ export function short(buffer: Buffer): string {
27
+ return buffer.toString("hex").slice(0, 8) + "...";
28
+ }
29
+
30
+ export const chainIdToName = (chainId: string | number) => {
31
+ switch (String(chainId)) {
32
+ case "1":
33
+ return "Mainnet";
34
+ case "137":
35
+ return "Polygon";
36
+ case "43114":
37
+ return "Avalanche";
38
+ default:
39
+ return "Mainnet";
40
+ }
41
+ };
42
+
43
+ export const getChainIdNativeSymbol = (chainId: string | number) => {
44
+ switch (String(chainId)) {
45
+ case "137":
46
+ return "MATIC";
47
+ case "43114":
48
+ return "AVAX";
49
+ case "1":
50
+ return "ETH";
51
+ default:
52
+ return "ETH";
53
+ }
54
+ };
55
+
56
+
57
+ export const getExplorerUrl = (chainId: string | number, suffix = '/') => {
58
+ switch (String(chainId)) {
59
+ case "1":
60
+ return `https://etherscan.io${suffix}`;
61
+ case "137":
62
+ return `https://polygonscan.com${suffix}`;
63
+ case "43114":
64
+ return `https://snowtrace.io${suffix}`;
65
+ default:
66
+ return `https://etherscan.io${suffix}`;
67
+ }
68
+ }