-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# Path to the .env file | ||
ENV_FILE="$(pwd)/.env" | ||
|
||
# Source the .env file | ||
source "$ENV_FILE" | ||
|
||
# Function to send out funds from an address | ||
drain_address() { | ||
local address=$1 | ||
local private_key=$2 | ||
|
||
# Get existing balance | ||
balance=$(cast balance --rpc-url "$L2_RPC_URL" "$address") | ||
echo "Existing balance: $balance" | ||
|
||
if [[ "$balance" == "0" ]]; then | ||
echo "Balance is 0, skipping..." | ||
return | ||
fi | ||
|
||
# Estimate gas | ||
gas_cost=$(cast estimate --rpc-url "$L2_RPC_URL" \ | ||
--from "$address" \ | ||
--value "$balance" \ | ||
"$L1_FUNDED_ADDRESS" | \ | ||
xargs cast --to-eth --pad 18) | ||
|
||
# Add 20% buffer | ||
gas_cost_with_buffer=$(echo "$gas_cost * 1.2" | bc) | ||
amount=$(echo "$balance - $gas_cost_with_buffer" | bc) | ||
|
||
# Send out funds if amount is greater than 0 | ||
if [[ "$amount" -gt 0 ]]; then | ||
echo "Sending out $amount to $L1_FUNDED_ADDRESS" | ||
cast send --private-key "$private_key" --rpc-url "$L2_RPC_URL" \ | ||
--value "$amount" "$L1_FUNDED_ADDRESS" | ||
else | ||
echo "Gas cost exceeds balance, skipping..." | ||
fi | ||
} | ||
|
||
# Fund the generated addresses | ||
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" ]]; then | ||
echo "Draining $role address: $address" | ||
drain_address "$address" "$private_key" | ||
echo | ||
else | ||
echo "Warning: $role address not found in .env file" | ||
echo | ||
fi | ||
done | ||
|
||
echo "Draining complete." |