Skip to content

Commit 495eee5

Browse files
Filipp MakarovFilipp Makarov
authored andcommitted
chore: add rpc urls validation
1 parent ac46343 commit 495eee5

11 files changed

Lines changed: 100 additions & 44 deletions

File tree

foundry.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
optimism = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api", chain = "10"}
7878
optimism-sepolia = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api", chain = "11155420"}
7979

80-
# BSC
81-
bsc = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api", chain = "56"}
82-
bsc-testnet = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api", chain = "97"}
80+
# BNB
81+
bnb = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api", chain = "56"}
82+
bnb-testnet = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api", chain = "97"}
8383

8484
# SONIC
8585
sonic = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api", chain = "146"}
@@ -143,4 +143,4 @@
143143
# arc-testnet = { key = "", url = "", chain = "1244"}
144144

145145
# SOPHON
146-
# sophon-zk-testnet = { key = "", url = "", chain = "531050204"}
146+
sophon-zk-testnet = { key = "", url = "https://block-explorer-api.zksync-os-testnet-sophon.zksync.dev/api", chain = "531050204"}

script/deploy/DeployStxContracts.s.sol

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,21 @@ contract DeployStxContracts is Script, Config {
7676
* @param contractNames Array of contract names to deploy (empty array = all contracts)
7777
*/
7878
function run(uint256 chainId, string[] memory contractNames) external {
79-
// Load configuration and setup forks (enable write-back to save deployed addresses)
79+
8080
string memory fullConfigPath = string.concat(vm.projectRoot(), configPath);
8181
console.log("Loading config from:", fullConfigPath);
82-
_loadConfigAndForks(fullConfigPath, true);
82+
83+
// load config
84+
_loadConfig(fullConfigPath, false);
8385

84-
// Load configuration for each chain
85-
loadConfigurations(chainId, contractNames);
86-
87-
// Move above to the base contract
86+
// create fork
87+
console.log("Creating fork for chain:", chainId);
88+
uint256 forkId = vm.createFork(config.getRpcUrl(chainId));
89+
forkOf[chainId] = forkId;
90+
console.log("Fork successfully created");
8891

92+
// Load configuration for each chain
93+
loadConfiguration(chainId);
8994
deployContracts(chainId, contractNames);
9095
}
9196

@@ -170,11 +175,12 @@ contract DeployStxContracts is Script, Config {
170175
console.log("Chain ID:", chainId);
171176
console.log("=====================================\n");
172177

173-
// Use the RPC_{chainId} environment variable directly
174-
string memory rpcUrl = vm.envString(string.concat("RPC_", vm.toString(chainId)));
175178

179+
// Fallback flow of creating a fork not via config but from .env file
180+
// Use the RPC_{chainId} environment variable directly
181+
// string memory rpcUrl = vm.envString(string.concat("RPC_", vm.toString(chainId)));
176182
// Create and switch to fork for the chain
177-
vm.createSelectFork(rpcUrl);
183+
// vm.createSelectFork(rpcUrl);
178184

179185
// Verify chain ID
180186
require(block.chainid == chainId, "Chain ID mismatch");
@@ -310,9 +316,9 @@ contract DeployStxContracts is Script, Config {
310316
// ============
311317

312318
/**
313-
* @notice Load configurations for all target chains
319+
* @notice Load configurations for a given chain
314320
*/
315-
function loadConfigurations(uint256 chainId, string[] memory contractNames) internal {
321+
function loadConfiguration(uint256 chainId) internal {
316322
// Switch to the fork for this chain (already created by _loadConfigAndForks)
317323
vm.selectFork(forkOf[chainId]);
318324

script/deploy/artifacts/ComposableExecutionModule/ComposableExecutionModule.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

script/deploy/artifacts/K1MeeValidator/K1MeeValidator.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

script/deploy/artifacts/Nexus/Nexus.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

script/deploy/artifacts/NexusAccountFactory/NexusAccountFactory.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

script/deploy/artifacts/NexusBootstrap/NexusBootstrap.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

script/deploy/artifacts/NodePaymasterFactory/NodePaymasterFactory.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

script/deploy/config.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ chain_id = 11155420
179179
name = "Optimism Sepolia"
180180

181181
# ===============
182-
# BSC
182+
# BNB
183183
# ===============
184184

185-
### BSC Mainnet (56)
185+
### BNB Mainnet (56)
186186
[56]
187187
endpoint_url = "${RPC_56}"
188188

@@ -194,9 +194,9 @@ verify = true
194194
chain_id = 56
195195

196196
[56.string]
197-
name = "BSC Mainnet"
197+
name = "BNB Mainnet"
198198

199-
### BSC Testnet (97)
199+
### BNB Testnet (97)
200200
[97]
201201
endpoint_url = "${RPC_97}"
202202

@@ -208,7 +208,7 @@ verify = true
208208
chain_id = 97
209209

210210
[97.string]
211-
name = "BSC Testnet"
211+
name = "BNB Testnet"
212212

213213
# ===============
214214
# SONIC

script/deploy/deploy-stx.sh

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,6 @@ if [ -z "$TESTNET_PRIVATE_KEY" ]; then
110110
exit 1
111111
fi
112112

113-
# Check RPC URLs for requested chains
114-
for chain_id in "${REQUESTED_CHAINS[@]}"; do
115-
RPC_VAR="RPC_${chain_id}"
116-
if [ -z "${!RPC_VAR}" ]; then
117-
log_error "$RPC_VAR is not set in .env for chain $chain_id"
118-
log_info "Please set $RPC_VAR in your .env file"
119-
exit 1
120-
fi
121-
done
122113

123114
# Check if CREATEX_ADDRESS is set in .env
124115
if [ -z "$CREATEX_ADDRESS" ]; then
@@ -132,6 +123,40 @@ if [ -z "$EXPECTED_DISPERSE_ADDRESS" ]; then
132123
exit 1
133124
fi
134125

126+
127+
log_info "Checking RPC URLs for the requested chains..."
128+
# Check RPC URLs for requested chains
129+
for chain_id in "${REQUESTED_CHAINS[@]}"; do
130+
RPC_VAR="RPC_${chain_id}"
131+
if [ -z "${!RPC_VAR}" ]; then
132+
log_error "$RPC_VAR is not set in .env for chain $chain_id"
133+
log_info "Please set $RPC_VAR in your .env file"
134+
exit 1
135+
fi
136+
done
137+
138+
log_info "Trying to create forks for the requested chains..."
139+
# Build the chain array in the format Solidity expects: [1,10,137]
140+
CHAIN_ARRAY="["
141+
for i in "${!REQUESTED_CHAINS[@]}"; do
142+
if [ $i -gt 0 ]; then
143+
CHAIN_ARRAY="${CHAIN_ARRAY},"
144+
fi
145+
CHAIN_ARRAY="${CHAIN_ARRAY}${REQUESTED_CHAINS[$i]}"
146+
done
147+
CHAIN_ARRAY="${CHAIN_ARRAY}]"
148+
149+
# Try to create forks for the requested chains
150+
{
151+
forge script ./util/ValidateForks.s.sol:ValidateForks --sig "run(uint256[])" "$CHAIN_ARRAY" 1> ./deploy-logs/validate-forks.log 2> ./deploy-logs/validate-forks-errors.log
152+
} || {
153+
log_error "Failed to create forks for the requested chains, see logs for more details"
154+
log_error "The reason is most likely that some of the RPC URL for the chains you are about to deploy to is not valid"
155+
exit 1
156+
}
157+
158+
log_info "Forks successfully created, all RPC's from config are accessible"
159+
135160
# Check if we have to recompile the artifacts
136161
export FOUNDRY_PROFILE="via-ir"
137162
read -r -p "Do you want to rebuild Stx-contracts artifacts from your local sources? (y/n): " proceed
@@ -183,15 +208,6 @@ else
183208
log_info "Using precompiled artifacts"
184209
fi
185210

186-
CHAIN_ARRAY="["
187-
for i in "${!REQUESTED_CHAINS[@]}"; do
188-
if [ $i -gt 0 ]; then
189-
CHAIN_ARRAY="${CHAIN_ARRAY},"
190-
fi
191-
CHAIN_ARRAY="${CHAIN_ARRAY}${REQUESTED_CHAINS[$i]}"
192-
done
193-
CHAIN_ARRAY="${CHAIN_ARRAY}]"
194-
195211
# Check the expected addresses for the contracts and record the bytecode hashes
196212
log_info "Getting expected addresses for the contracts..."
197213
{

0 commit comments

Comments
 (0)