@instadapp/avocado-base 0.0.0-dev.0d3d1e2

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.
@@ -0,0 +1,319 @@
1
+ import { ethers } from "ethers";
2
+
3
+ export const bridgeDisabledNetworks = [1101];
4
+
5
+ export const networks: Network[] = [
6
+ {
7
+ name: "Mainnet",
8
+ debankName: "eth",
9
+ ankrName: "eth",
10
+ zerionName: "ethereum",
11
+ chainId: 1,
12
+ explorerUrl: "https://etherscan.io",
13
+ get serverRpcUrl() {
14
+ return process.env?.MAINNET_RPC_URL || this.params.rpcUrls[0];
15
+ },
16
+ balanceResolverAddress: "0x5b7D61b389D12e1f5873d0cCEe7E675915AB5F43",
17
+ usdcAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
18
+ params: {
19
+ rpcUrls: ["https://rpc.ankr.com/eth"],
20
+ nativeCurrency: {
21
+ name: "Ethereum",
22
+ symbol: "ETH",
23
+ decimals: 18,
24
+ },
25
+ },
26
+ },
27
+ {
28
+ name: "Polygon",
29
+ debankName: "matic",
30
+ ankrName: "polygon",
31
+ zerionName: "polygon",
32
+ chainId: 137,
33
+ balanceResolverAddress: "0x58632D23120b20650262b8A629a14e4F4043E0D9",
34
+ usdcAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
35
+ explorerUrl: "https://polygonscan.com",
36
+ get serverRpcUrl() {
37
+ return process.env?.POLYGON_RPC_URL || this.params.rpcUrls[0];
38
+ },
39
+ params: {
40
+ chainName: "Matic(Polygon) Mainnet",
41
+ nativeCurrency: {
42
+ name: "Matic",
43
+ symbol: "MATIC",
44
+ decimals: 18,
45
+ },
46
+ rpcUrls: ["https://polygon-rpc.com"],
47
+ },
48
+ },
49
+ {
50
+ name: "Arbitrum",
51
+ debankName: "arb",
52
+ ankrName: "arbitrum",
53
+ zerionName: "arbitrum",
54
+ chainId: 42161,
55
+ usdcAddress: "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",
56
+ balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
57
+ explorerUrl: "https://arbiscan.io",
58
+ get serverRpcUrl() {
59
+ return process.env?.ARBITRUM_RPC_URL || this.params.rpcUrls[0];
60
+ },
61
+ params: {
62
+ chainName: "Arbitrum One",
63
+ nativeCurrency: {
64
+ name: "Ethereum",
65
+ symbol: "ETH",
66
+ decimals: 18,
67
+ },
68
+ rpcUrls: ["https://arb1.arbitrum.io/rpc"],
69
+ },
70
+ },
71
+ {
72
+ name: "Optimism",
73
+ debankName: "op",
74
+ ankrName: "optimism",
75
+ zerionName: "optimism",
76
+ chainId: 10,
77
+ usdcAddress: "0x7f5c764cbc14f9669b88837ca1490cca17c31607",
78
+ balanceResolverAddress: "0xca5f37e6D8bB24c5A7958d5eccE7Bd9Aacc944f2",
79
+ explorerUrl: "https://optimistic.etherscan.io",
80
+ get serverRpcUrl() {
81
+ return process.env?.OPTIMISM_RPC_URL || this.params.rpcUrls[0];
82
+ },
83
+ params: {
84
+ chainName: "Optimistic Ethereum",
85
+ nativeCurrency: {
86
+ name: "Ethereum",
87
+ symbol: "ETH",
88
+ decimals: 18,
89
+ },
90
+ rpcUrls: ["https://rpc.ankr.com/optimism"],
91
+ },
92
+ },
93
+ {
94
+ name: "Avalanche",
95
+ debankName: "avax",
96
+ ankrName: "avalanche",
97
+ zerionName: "avalanche",
98
+ chainId: 43114,
99
+ usdcAddress: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
100
+ balanceResolverAddress: "0x63009f31D054E0ac9F321Cf0D642375236A4Bf1E",
101
+ explorerUrl: "https://snowtrace.io",
102
+ get serverRpcUrl() {
103
+ return process.env?.AVALANCHE_RPC_URL || this.params.rpcUrls[0];
104
+ },
105
+ params: {
106
+ chainName: "Avalanche Network",
107
+ nativeCurrency: {
108
+ name: "Avalanche",
109
+ symbol: "AVAX",
110
+ decimals: 18,
111
+ },
112
+ rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
113
+ },
114
+ },
115
+ {
116
+ name: "BSC",
117
+ debankName: "bsc",
118
+ ankrName: "bsc",
119
+ zerionName: "binance-smart-chain",
120
+ chainId: 56,
121
+ explorerUrl: "https://bscscan.com",
122
+ usdcAddress: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
123
+ balanceResolverAddress: "0xb808cff38706e267067b0af427726aa099f69f89",
124
+ get serverRpcUrl() {
125
+ return process.env?.BSC_RPC_URL || this.params.rpcUrls[0];
126
+ },
127
+ params: {
128
+ chainName: "Binance Smart Chain",
129
+ rpcUrls: ["https://rpc.ankr.com/bsc"],
130
+ nativeCurrency: {
131
+ name: "Binance Coin",
132
+ symbol: "BNB",
133
+ decimals: 18,
134
+ },
135
+ },
136
+ },
137
+ {
138
+ name: "Gnosis",
139
+ debankName: "xdai",
140
+ zerionName: "xdai",
141
+ chainId: 100,
142
+ balanceResolverAddress: "0xfaa244e276b1597f663975ed007ee4ff70d27849",
143
+ explorerUrl: "https://gnosisscan.io",
144
+ usdcAddress: "0xddafbb505ad214d7b80b1f830fccc89b60fb7a83",
145
+ get serverRpcUrl() {
146
+ return process.env?.GNOSIS_RPC_URL || this.params.rpcUrls[0];
147
+ },
148
+ params: {
149
+ chainName: "Gnosis Safe",
150
+ rpcUrls: ["https://rpc.ankr.com/gnosis"],
151
+ nativeCurrency: {
152
+ name: "xdaistable",
153
+ symbol: "xDAI",
154
+ decimals: 18,
155
+ },
156
+ },
157
+ },
158
+ {
159
+ name: "Polygon zkEVM",
160
+ chainId: 1101,
161
+ explorerUrl: "https://zkevm.polygonscan.com",
162
+ balanceResolverAddress: "0x48D1Fa5Ee6691a1E0B45d2B515650997BEA27a01",
163
+ usdcAddress: "0xa8ce8aee21bc2a48a5ef670afcc9274c7bbbc035",
164
+ get serverRpcUrl() {
165
+ return process.env?.POLYGON_ZKEVM_RPC_URL || this.params.rpcUrls[0];
166
+ },
167
+ params: {
168
+ chainName: "polygon zkEVM",
169
+ rpcUrls: ["https://rpc.ankr.com/polygon_zkevm"],
170
+
171
+ nativeCurrency: {
172
+ name: "Ethereum",
173
+ symbol: "ETH",
174
+ decimals: 18,
175
+ },
176
+ },
177
+ },
178
+ // {
179
+ // name: "Aurora",
180
+ // chainId: 1313161554,
181
+ // zerionName: "aurora",
182
+ // explorerUrl: "https://explorer.mainnet.aurora.dev",
183
+ // get serverRpcUrl() {
184
+ // return process.env?.AURORA_RPC_URL || this.params.rpcUrls[0];
185
+ // },
186
+ // usdcAddress: "0xB12BFcA5A55806AaF64E99521918A4bf0fC40802",
187
+ // balanceResolverAddress: "0xdF19Da523DA64bBE82eE0E4DFf00d676A8386474",
188
+ // params: {
189
+ // rpcUrls: ["https://mainnet.aurora.dev"],
190
+ // chainName: "Aurora",
191
+ // nativeCurrency: {
192
+ // decimals: 18,
193
+ // name: "Aurora ETH",
194
+ // symbol: "AETH",
195
+ // },
196
+ // },
197
+ // },
198
+ {
199
+ name: "Fantom",
200
+ chainId: 250,
201
+ zerionName: "fantom",
202
+ explorerUrl: "https://ftmscan.com",
203
+ ankrName: "fantom",
204
+ get serverRpcUrl() {
205
+ return process.env?.FANTOM_RPC_URL || this.params.rpcUrls[0];
206
+ },
207
+ usdcAddress: "0x04068da6c83afcfa0e13ba15a6696662335d5b75",
208
+ balanceResolverAddress: "0x929376c77a2fb8152375a089a4fccf84ff481479",
209
+ params: {
210
+ rpcUrls: ["https://rpc.ankr.com/fantom"],
211
+ chainName: "Fantom",
212
+ nativeCurrency: {
213
+ name: "Fantom",
214
+ symbol: "FTM",
215
+ decimals: 18,
216
+ },
217
+ },
218
+ },
219
+ {
220
+ name: AVO_PROD_CHAIN_NAME,
221
+ chainId: AVO_PROD_CHAIN_ID,
222
+ isAvocado: true,
223
+ balanceResolverAddress: "",
224
+ usdcAddress: "",
225
+ serverRpcUrl: AVO_PROD_RPC_URL,
226
+ explorerUrl: AVO_PROD_EXPLORER_URL,
227
+ params: {
228
+ chainName: AVO_PROD_CHAIN_NAME,
229
+ nativeCurrency: {
230
+ name: "Avocado",
231
+ symbol: "USDC",
232
+ decimals: 18,
233
+ },
234
+ iconUrls: ["https://avocado.instadapp.io/logo.svg"],
235
+ rpcUrls: [AVO_PROD_RPC_URL],
236
+ },
237
+ },
238
+ {
239
+ name: AVO_STAGING_CHAIN_NAME,
240
+ chainId: AVO_STAGING_CHAIN_ID,
241
+ serverRpcUrl: AVO_STAGING_RPC_URL,
242
+ explorerUrl: AVO_STAGING_EXPLORER_URL,
243
+ isAvocado: true,
244
+ balanceResolverAddress: "",
245
+ usdcAddress: "",
246
+ params: {
247
+ chainName: AVO_STAGING_CHAIN_NAME,
248
+ nativeCurrency: {
249
+ name: "Avocado",
250
+ symbol: "USDC",
251
+ decimals: 18,
252
+ },
253
+ iconUrls: ["https://avocado.instadapp.io/logo.svg"],
254
+ rpcUrls: [AVO_STAGING_RPC_URL],
255
+ },
256
+ },
257
+ ];
258
+
259
+ export const getNetworkByChainId = (
260
+ chainId: ChainId | number | string
261
+ ): Network => {
262
+ return networks.find((i) => i.chainId == chainId)!;
263
+ };
264
+
265
+ export const availableNetworks = networks.filter(
266
+ (network) => !network.isAvocado
267
+ );
268
+
269
+ export const chainIdToName = (chainId: ChainId | number | string) => {
270
+ const network = getNetworkByChainId(chainId);
271
+ return network.name;
272
+ };
273
+
274
+ export const getRpcURLByChainId = (chainId: ChainId | number | string) => {
275
+ const network = getNetworkByChainId(chainId);
276
+ return network.params.rpcUrls[0];
277
+ };
278
+
279
+ export const RPCMap = networks.reduce((acc, network) => {
280
+ acc[network.chainId] = network.params.rpcUrls[0];
281
+ return acc;
282
+ }, {} as Record<number, string>);
283
+
284
+ export const networkIds = networks.map((network) => network.chainId);
285
+
286
+ const rpcInstances: Record<string, ethers.providers.StaticJsonRpcProvider> = {};
287
+ const serverRpcInstances: Record<
288
+ string,
289
+ ethers.providers.StaticJsonRpcProvider
290
+ > = {};
291
+
292
+ export const getServerRpcProvider = (chainId: number | string) => {
293
+ if (!rpcInstances[chainId]) {
294
+ const network = networks.find((n) => n.chainId == chainId);
295
+ serverRpcInstances[chainId] = new ethers.providers.StaticJsonRpcProvider(
296
+ network?.serverRpcUrl
297
+ );
298
+ }
299
+
300
+ return serverRpcInstances[chainId];
301
+ };
302
+
303
+ export const getRpcProvider = (chainId: number | string) => {
304
+ if (!rpcInstances[chainId]) {
305
+ rpcInstances[chainId] = new ethers.providers.StaticJsonRpcProvider(
306
+ getRpcURLByChainId(Number(chainId))
307
+ );
308
+ }
309
+
310
+ return rpcInstances[chainId];
311
+ };
312
+
313
+ export const getExplorerUrl = (
314
+ chainId: ChainId | number | string,
315
+ suffix: `/${string}` = "/"
316
+ ) => {
317
+ const network = getNetworkByChainId(chainId);
318
+ return `${network.explorerUrl}${suffix}`;
319
+ };
@@ -0,0 +1,110 @@
1
+ type ChainId =
2
+ | 1
3
+ | 137
4
+ | 42161
5
+ | 10
6
+ | 56
7
+ | 43114
8
+ | 100
9
+ | 1101
10
+ | 250
11
+ | 634
12
+ | 1313161554
13
+ | 63400;
14
+
15
+ type ISlackMessageType = "danger" | "error" | "success" | "banner";
16
+
17
+ interface Network {
18
+ name: string;
19
+ debankName?: string;
20
+ ankrName?: string;
21
+ zerionName?: string;
22
+ chainId: ChainId;
23
+ isAvocado?: boolean;
24
+ serverRpcUrl: string | undefined;
25
+ balanceResolverAddress?: string;
26
+ usdcAddress: string;
27
+ explorerUrl: string;
28
+ params: {
29
+ chainName?: string;
30
+ iconUrls?: string[];
31
+ rpcUrls: string[];
32
+ nativeCurrency?: {
33
+ name: string;
34
+ symbol: string;
35
+ decimals: number;
36
+ };
37
+ };
38
+ }
39
+
40
+ type SignMetadataProps = {
41
+ token: string;
42
+ spender: string;
43
+ amount: string;
44
+ expiration: string;
45
+ };
46
+
47
+ type DappMetadataProps = {
48
+ name: string;
49
+ url: string;
50
+ };
51
+
52
+ type SendMetadataProps = {
53
+ token: string;
54
+ amount: string;
55
+ receiver: string;
56
+ };
57
+
58
+ type CrossSendMetadatProps = {
59
+ fromToken: string;
60
+ toToken: string;
61
+ toChainId: string;
62
+ amount: string;
63
+ receiver: string;
64
+ };
65
+
66
+ type UpgradeMetadataProps = {
67
+ version: string;
68
+ walletImpl: string;
69
+ };
70
+
71
+ type TopupMetadataProps = {
72
+ amount: string;
73
+ token: string;
74
+ onBehalf: string;
75
+ };
76
+
77
+ type BridgeMetadataProps = {
78
+ amount: string;
79
+ receiver: string;
80
+ fromToken: string;
81
+ toToken: string;
82
+ toChainId: string;
83
+ bridgeFee: string;
84
+ nativeToken: string;
85
+ };
86
+
87
+ type SwapMetadataProps = {
88
+ sellToken: string;
89
+ buyToken: string;
90
+ sellAmount: string;
91
+ buyAmount: string;
92
+ receiver: string;
93
+ protocol?: string;
94
+ };
95
+
96
+ type MetadataProps = {
97
+ type:
98
+ | "transfer"
99
+ | "bridge"
100
+ | "swap"
101
+ | "multi"
102
+ | "gas-topup"
103
+ | "upgrade"
104
+ | "dapp"
105
+ | "deploy"
106
+ | "permit2"
107
+ | "cross-transfer";
108
+ encodedData: string;
109
+ version?: string;
110
+ };