forked from ethereum/solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchains.sol
91 lines (82 loc) · 4.65 KB
/
chains.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// This is an adapted version of StdCheats by foundry:
// https://github.com/foundry-rs/forge-std/blob/master/src/StdCheats.sol
contract StdCheatsSafe {
struct Chain {
string name;
uint256 chainId;
string rpcUrl;
}
struct Chains {
Chain Anvil;
Chain Hardhat;
Chain Mainnet;
Chain Goerli;
Chain Sepolia;
Chain Optimism;
Chain OptimismGoerli;
Chain ArbitrumOne;
Chain ArbitrumOneGoerli;
Chain ArbitrumNova;
Chain Polygon;
Chain PolygonMumbai;
Chain Avalanche;
Chain AvalancheFuji;
Chain BnbSmartChain;
Chain BnbSmartChainTestnet;
Chain GnosisChain;
}
Chains stdChains;
function f(string[2][] memory rpcs) public returns (uint256) {
stdChains = Chains({
Anvil: Chain("Anvil", 31337, "http://127.0.0.1:8545"),
Hardhat: Chain("Hardhat", 31337, "http://127.0.0.1:8545"),
Mainnet: Chain("Mainnet", 1, "https://api.mycryptoapi.com/eth"),
Goerli: Chain("Goerli", 5, "https://goerli.infura.io/v3/84842078b09946638c03157f83405213"),
Sepolia: Chain("Sepolia", 11155111, "https://rpc.sepolia.dev"),
Optimism: Chain("Optimism", 10, "https://mainnet.optimism.io"),
OptimismGoerli: Chain("OptimismGoerli", 420, "https://goerli.optimism.io"),
ArbitrumOne: Chain("ArbitrumOne", 42161, "https://arb1.arbitrum.io/rpc"),
ArbitrumOneGoerli: Chain("ArbitrumOneGoerli", 421613, "https://goerli-rollup.arbitrum.io/rpc"),
ArbitrumNova: Chain("ArbitrumNova", 42170, "https://nova.arbitrum.io/rpc"),
Polygon: Chain("Polygon", 137, "https://polygon-rpc.com"),
PolygonMumbai: Chain("PolygonMumbai", 80001, "https://rpc-mumbai.matic.today"),
Avalanche: Chain("Avalanche", 43114, "https://api.avax.network/ext/bc/C/rpc"),
AvalancheFuji: Chain("AvalancheFuji", 43113, "https://api.avax-test.network/ext/bc/C/rpc"),
BnbSmartChain: Chain("BnbSmartChain", 56, "https://bsc-dataseed1.binance.org"),
BnbSmartChainTestnet: Chain("BnbSmartChainTestnet", 97, "https://data-seed-prebsc-1-s1.binance.org:8545"),
GnosisChain: Chain("GnosisChain", 100, "https://rpc.gnosischain.com")
});
for (uint256 i = 0; i < rpcs.length; i++) {
(string memory name, string memory rpcUrl) = (rpcs[i][0], rpcs[i][1]);
// forgefmt: disable-start
if (isEqual(name, "anvil")) stdChains.Anvil.rpcUrl = rpcUrl;
else if (isEqual(name, "hardhat")) stdChains.Hardhat.rpcUrl = rpcUrl;
else if (isEqual(name, "mainnet")) stdChains.Mainnet.rpcUrl = rpcUrl;
else if (isEqual(name, "goerli")) stdChains.Goerli.rpcUrl = rpcUrl;
else if (isEqual(name, "sepolia")) stdChains.Sepolia.rpcUrl = rpcUrl;
else if (isEqual(name, "optimism")) stdChains.Optimism.rpcUrl = rpcUrl;
else if (isEqual(name, "optimism_goerli", "optimism-goerli")) stdChains.OptimismGoerli.rpcUrl = rpcUrl;
else if (isEqual(name, "arbitrum_one", "arbitrum-one")) stdChains.ArbitrumOne.rpcUrl = rpcUrl;
else if (isEqual(name, "arbitrum_one_goerli", "arbitrum-one-goerli")) stdChains.ArbitrumOneGoerli.rpcUrl = rpcUrl;
else if (isEqual(name, "arbitrum_nova", "arbitrum-nova")) stdChains.ArbitrumNova.rpcUrl = rpcUrl;
else if (isEqual(name, "polygon")) stdChains.Polygon.rpcUrl = rpcUrl;
else if (isEqual(name, "polygon_mumbai", "polygon-mumbai")) stdChains.PolygonMumbai.rpcUrl = rpcUrl;
else if (isEqual(name, "avalanche")) stdChains.Avalanche.rpcUrl = rpcUrl;
else if (isEqual(name, "avalanche_fuji", "avalanche-fuji")) stdChains.AvalancheFuji.rpcUrl = rpcUrl;
else if (isEqual(name, "bnb_smart_chain", "bnb-smart-chain")) stdChains.BnbSmartChain.rpcUrl = rpcUrl;
else if (isEqual(name, "bnb_smart_chain_testnet", "bnb-smart-chain-testnet")) stdChains.BnbSmartChainTestnet.rpcUrl = rpcUrl;
else if (isEqual(name, "gnosis_chain", "gnosis-chain")) stdChains.GnosisChain.rpcUrl = rpcUrl;
// forgefmt: disable-end
}
return 0;
}
function isEqual(string memory a, string memory b) private pure returns (bool) {
return keccak256(abi.encode(a)) == keccak256(abi.encode(b));
}
function isEqual(string memory a, string memory b, string memory c) private pure returns (bool) {
return keccak256(abi.encode(a)) == keccak256(abi.encode(b))
|| keccak256(abi.encode(a)) == keccak256(abi.encode(c));
}
}