Skip to content

Commit

Permalink
fix: prevent overwrite existing l2 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
parketh committed Nov 20, 2024
1 parent 924422d commit 7c23541
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
16 changes: 8 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ BBN_FINALITY_GADGET_RPC=
## mnemonic "test test test test test test test test test test test junk"

# Admin address
GS_ADMIN_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
GS_ADMIN_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
GS_ADMIN_ADDRESS=
GS_ADMIN_PRIVATE_KEY=

# Batcher address
GS_BATCHER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
GS_BATCHER_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
GS_BATCHER_ADDRESS=
GS_BATCHER_PRIVATE_KEY=

# Proposer address
GS_PROPOSER_ADDRESS=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
GS_PROPOSER_PRIVATE_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
GS_PROPOSER_ADDRESS=
GS_PROPOSER_PRIVATE_KEY=

# Sequencer address
GS_SEQUENCER_ADDRESS=0x90F79bf6EB2c4f870365E785982E1f101E93b906
GS_SEQUENCER_PRIVATE_KEY=0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
GS_SEQUENCER_ADDRESS=
GS_SEQUENCER_PRIVATE_KEY=
64 changes: 46 additions & 18 deletions scripts/l2/l2-gen-addresses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,45 @@ output=$($WALLETS_SCRIPT)
# Path to the .env file
ENV_FILE="$(pwd)/.env"

# Process the output and update the .env file
echo "$output" | while IFS= read -r line; do
if [[ $line == export\ GS_* ]]; then
# Extract variable name and value
var_name=$(echo "$line" | cut -d'=' -f1 | cut -d' ' -f2)
var_value=$(echo "$line" | cut -d'=' -f2-)

# Update or add the variable in the .env file
if grep -q "^$var_name=" "$ENV_FILE"; then
sed -i.bak "s|^$var_name=.*|$var_name=$var_value|" "$ENV_FILE" && rm "${ENV_FILE}.bak"
else
echo "$var_name=$var_value" >> "$ENV_FILE"
fi
# Check if addresses already exist in the .env file
check_addresses_exist() {
for role in ADMIN BATCHER PROPOSER; do
if grep -q "^GS_${role}_ADDRESS=" "$ENV_FILE" || \
grep -q "^GS_${role}_PRIVATE_KEY=" "$ENV_FILE"; then
return 0
fi
done
done
return 1
}

if check_addresses_exist; then
echo "Error: Addresses or private keys already exist in .env file. Please remove them first."
exit 1
else
# If not, process the output and update the .env file
echo "$output" | while IFS= read -r line; do
if [[ $line == export\ GS_* ]]; then
# Extract variable name and value
var_name=$(echo "$line" | cut -d'=' -f1 | cut -d' ' -f2)
var_value=$(echo "$line" | cut -d'=' -f2-)

# Update or add the variable in the .env file
if grep -q "^$var_name=" "$ENV_FILE"; then
sed -i.bak "s|^$var_name=.*|$var_name=$var_value|" "$ENV_FILE" && rm "${ENV_FILE}.bak"
else
echo "$var_name=$var_value" >> "$ENV_FILE"
fi
fi
done
echo "Generated new addresses and updated .env file."
fi

echo "Generated new addresses and updated .env file."
# Function to check address balance
check_address_balance() {
local address=$1

cast balance "$address" --rpc-url "$L1_RPC_URL"
}

# Function to fund an address
fund_address() {
Expand All @@ -46,9 +68,15 @@ for role in ADMIN BATCHER PROPOSER; do
address="${!address_var}"

if [[ -n "$address" ]]; then
echo "Funding $role address: $address with amount $L1_FUND_AMOUNT"
fund_address "$address" "$L1_FUND_AMOUNT"
echo
local balance=$(check_address_balance "$address")
if [[ "$balance" == "0" ]]; then
echo "Funding $role address: $address with amount $L1_FUND_AMOUNT"
fund_address "$address" "$L1_FUND_AMOUNT"
echo
else
echo "$role address: $address already funded"
echo
fi
else
echo "Warning: $role address not found in .env file"
echo
Expand Down

0 comments on commit 7c23541

Please sign in to comment.