Skip to content
Merged
28 changes: 20 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,32 @@ 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
# OP Admin contract address + private key
# e.g. GS_ADMIN_ADDRESS=0x9126fC851f5BeDFFa8f3E1a5B0aaA3dc21f1616E
# e.g. GS_ADMIN_PRIVATE_KEY=0x0486cf424dbf0e0de275410d5f332a4e4ae44eb2c0d0d49bf83d2ce49d8b3771
GS_ADMIN_ADDRESS=
GS_ADMIN_PRIVATE_KEY=

# Batcher address
GS_BATCHER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
GS_BATCHER_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
# OP Batcher contract address + private key, e.g.
# e.g. GS_BATCHER_ADDRESS=0x19B5eBDE3176db8C5103133F10eEC15E108Edbc6
# e.g. GS_BATCHER_PRIVATE_KEY=0xccb6d44b2720e89fd1ee93b58141c22089ee11698aef38e9c9d404d0db263b81
GS_BATCHER_ADDRESS=
GS_BATCHER_PRIVATE_KEY=

# Proposer address
GS_PROPOSER_ADDRESS=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
GS_PROPOSER_PRIVATE_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
# OP Proposer contract address + private key, e.g.
# e.g. GS_PROPOSER_ADDRESS=0x70bEE4FCaA7321cDE64cb85Cbf7029C373ad3996
# e.g. GS_PROPOSER_PRIVATE_KEY=0xc12305ce88f34ef747dab0907bde98ad1b8079e3f95ff047a641e0d43a57b17b
GS_PROPOSER_ADDRESS=
GS_PROPOSER_PRIVATE_KEY=

# Sequencer address
GS_SEQUENCER_ADDRESS=0x90F79bf6EB2c4f870365E785982E1f101E93b906
GS_SEQUENCER_PRIVATE_KEY=0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
# OP Sequencer contract address + private key, e.g.
# e.g. GS_SEQUENCER_ADDRESS=0xDA8425BBD1B33720B1AfbC0c3cfE9Aac82CB9A50
# e.g. GS_SEQUENCER_PRIVATE_KEY=0xbb9f1f4090e83213061b62c4ff9c666952caf75b2f8d0234a765160088db3afa
GS_SEQUENCER_ADDRESS=
GS_SEQUENCER_PRIVATE_KEY=

# DNS Configuration
L2_SYSTEM_SERVER_IP=11.22.33.44
Expand Down
50 changes: 45 additions & 5 deletions scripts/l2/l2-gen-addresses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,41 @@ set -euo pipefail

# Set the path to the wallets.sh script
WALLETS_SCRIPT="$(pwd)/optimism/packages/contracts-bedrock/scripts/getting-started/wallets.sh"
TEARDOWN_SCRIPT="$(pwd)/scripts/l2/l2-teardown.sh"

# Run the wallets.sh script and capture its output
output=$($WALLETS_SCRIPT)

# Path to the .env file
ENV_FILE="$(pwd)/.env"

# Source the .env file
source "$ENV_FILE"

# Check if any addresses already exist in the .env file
check_addresses_exist() {
for role in ADMIN BATCHER PROPOSER; do
address_var="GS_${role}_ADDRESS"
private_key_var="GS_${role}_PRIVATE_KEY"
address="${!address_var}"
private_key="${!private_key_var}"

if [[ -n "$address" ]] || [[ -n "$private_key" ]]; then
return 0
fi
done
return 1
}

# If addresses already exist, first backup the .env file and run teardown
if check_addresses_exist; then
echo "Addresses already exist in .env file. Backing up and running teardown."
timestamp=$(date +%s)
cp "$ENV_FILE" "$ENV_FILE.bak-$timestamp"
"$TEARDOWN_SCRIPT"
echo "Teardown complete."
fi

# Process the output and update the .env file
echo "$output" | while IFS= read -r line; do
if [[ $line == export\ GS_* ]]; then
Expand All @@ -25,9 +53,15 @@ echo "$output" | while IFS= read -r line; do
fi
fi
done

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() {
local address=$1
Expand All @@ -37,7 +71,7 @@ fund_address() {
--value "$amount" "$address"
}

# Source the .env file
# Update the .env file with the new addresses
source "$ENV_FILE"

# Fund the generated addresses
Expand All @@ -46,9 +80,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
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 "Error: $role address already funded: $address"
exit 1
fi
else
echo "Warning: $role address not found in .env file"
echo
Expand Down