Skip to content

Commit 30abb6d

Browse files
authored
Update run.zsh (#106)
depends on wealdtech/ethereal#65 Signed-off-by: Barnabas Busa <busa.barnabas@gmail.com>
1 parent e004b36 commit 30abb6d

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

scripts/run.zsh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ print_usage() {
4343
echo " fork_choice Get the fork choice of the network"
4444
echo " send_blob n Send "n" number of blob(s) to the network [default 1]"
4545
echo " deposit s e [type] Deposit to the network from validator index start to end - optional withdrawal type (0x00, 0x01, 0x02)"
46+
echo " topup validator_index eth_amount Top-up an existing validator with additional ETH (Pectra upgrade feature)"
4647
echo " exit s e Exit from the network from validator index start to end - mandatory argument"
4748
echo " set_withdrawal_addr s e address Set the withdrawal credentials for validator index start (mandatory) to end (optional) and Ethereum address"
4849
echo " full_withdrawal s e Withdraw from the network from validator index start to end - mandatory argument"
@@ -482,6 +483,78 @@ for arg in "${command[@]}"; do
482483
fi
483484
fi
484485
;;
486+
"topup")
487+
# Top-up an existing validator with additional ETH (Pectra upgrade feature)
488+
if [[ $# -ne 3 ]]; then
489+
echo "Top-up calls for exactly 2 arguments!"
490+
echo " Usage: ${0} topup validator_index eth_amount"
491+
echo " Example: ${0} topup 5 35"
492+
exit;
493+
else
494+
# Check if cast is installed
495+
if ! command -v cast &> /dev/null; then
496+
echo "Error: 'cast' command not found. Please install Foundry."
497+
echo "Install with: curl -L https://foundry.paradigm.xyz | bash && foundryup"
498+
exit 1
499+
fi
500+
validator_index=${command[2]}
501+
eth_amount=${command[3]}
502+
503+
# Validate inputs
504+
if ! [[ "$validator_index" =~ ^[0-9]+$ ]]; then
505+
echo "Error: Validator index must be a positive integer."
506+
exit 1
507+
fi
508+
if ! [[ "$eth_amount" =~ ^[0-9]+(\.[0-9]+)?$ ]] || (( $(echo "$eth_amount < 1" | bc -l) )); then
509+
echo "Error: ETH amount must be >= 1."
510+
exit 1
511+
fi
512+
513+
# Get validator info
514+
validator_info=$(curl -s "$bn_endpoint/eth/v1/beacon/states/head/validators/$validator_index")
515+
if [[ $(echo "$validator_info" | jq -r '.data') == "null" ]]; then
516+
echo "Error: Validator $validator_index not found."
517+
exit 1
518+
fi
519+
520+
validator_pubkey=$(echo "$validator_info" | jq -r '.data.validator.pubkey')
521+
withdrawal_credentials=$(echo "$validator_info" | jq -r '.data.validator.withdrawal_credentials')
522+
deposit_contract_address=$(curl -s $bn_endpoint/eth/v1/config/spec | jq -r '.data.DEPOSIT_CONTRACT_ADDRESS')
523+
524+
# Convert ETH to wei for the transaction
525+
deposit_amount_wei=$(echo "$eth_amount * 1000000000000000000" | bc)
526+
527+
# Prepare transaction arguments
528+
deposit_path="m/44'/60'/0'/0/7"
529+
privatekey=$(ethereal hd keys --path="$deposit_path" --seed="$sops_mnemonic" | awk '/Private key/{print $NF}')
530+
publickey=$(ethereal hd keys --path="$deposit_path" --seed="$sops_mnemonic" | awk '/Ethereum address/{print $NF}')
531+
532+
echo "Top-up Summary:"
533+
echo " Validator: $validator_index ($validator_pubkey)"
534+
echo " Amount: $eth_amount ETH"
535+
echo " Deposit Contract: $deposit_contract_address"
536+
echo ""
537+
echo "Continue? (y/n)"
538+
read -r response
539+
540+
541+
# Simple topup using ethereal's dedicated command with no safety checks
542+
ethereal validator topup \
543+
--from="$publickey" \
544+
--validator="$validator_pubkey" \
545+
--topup-amount="${eth_amount}eth" \
546+
--privatekey="$privatekey" \
547+
--connection="$rpc_endpoint" \
548+
--consensus-connection="$bn_endpoint" \
549+
--no-safety-checks \
550+
--timeout=60s
551+
else
552+
echo "Top-up cancelled."
553+
fi
554+
555+
exit;
556+
fi
557+
;;
485558
"exit")
486559
# if I have 1 argument, then use that as the validator index, else use second and third in a loop
487560
# if there are less than 2 arguments, then exit

0 commit comments

Comments
 (0)