|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Send L1 messages |
| 4 | +# Usage: ./send-l1-messages.sh [count] |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +# Source common functions |
| 9 | +source "$(dirname "$0")/common-functions.sh" |
| 10 | + |
| 11 | +# Check for required arguments |
| 12 | +if [ $# -lt 1 ]; then |
| 13 | + log_info "usage: send-l1-messages.sh [count]" |
| 14 | + log_info "example: send-l1-messages.sh 10" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +check_script_env_vars() { |
| 19 | + # Check the L1 private key is provided |
| 20 | + if [[ -z "${L1_DEPLOYER_PRIVATE_KEY:-}" ]]; then |
| 21 | + log_error "L1_DEPLOYER_PRIVATE_KEY environment variable is required" |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + |
| 25 | + # Check the L1 RPC URL is provided |
| 26 | + if [[ -z "${SCROLL_L1_DEPLOYMENT_RPC:-}" ]]; then |
| 27 | + log_error "SCROLL_L1_DEPLOYMENT_RPC environment variable is required" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | + |
| 31 | + # Check the L1 message queue proxy address is provided |
| 32 | + if [[ -z "${L1_MESSAGE_QUEUE_V2_PROXY_ADDR:-}" ]]; then |
| 33 | + log_error "L1_MESSAGE_QUEUE_V2_PROXY_ADDR environment variable is required" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + |
| 37 | + # Check the L1 enforced tx gateway proxy address is provided |
| 38 | + if [[ -z "${L1_ENFORCED_TX_GATEWAY_PROXY_ADDR:-}" ]]; then |
| 39 | + log_error "L1_ENFORCED_TX_GATEWAY_PROXY_ADDR environment variable is required" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + |
| 43 | + # Check the L1 scroll messenger proxy address is provided |
| 44 | + if [[ -z "${L1_SCROLL_MESSENGER_PROXY_ADDR:-}" ]]; then |
| 45 | + log_error "L1_SCROLL_MESSENGER_PROXY_ADDR environment variable is required" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +} |
| 49 | + |
| 50 | +main() { |
| 51 | + log_info "=== SENDING L1 MESSAGES ===" |
| 52 | + |
| 53 | + check_script_env_vars |
| 54 | + |
| 55 | + address=$(cast wallet address "$L1_DEPLOYER_PRIVATE_KEY") |
| 56 | + start_nonce=$(cast nonce --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" "$address") |
| 57 | + end_nonce=$(($start_nonce + $1)) |
| 58 | + |
| 59 | + log_info "Address: $address" |
| 60 | + log_info "Start nonce: $start_nonce" |
| 61 | + log_info "End nonce: $end_nonce" |
| 62 | + |
| 63 | + for (( ii = $start_nonce; ii < $end_nonce; ii += 2 )); do |
| 64 | + log_info "" |
| 65 | + log_info "Sending deposit tx with nonce #$ii" |
| 66 | + cast send --async --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" --private-key "$L1_DEPLOYER_PRIVATE_KEY" --legacy --gas-price 0.1gwei --nonce "$ii" --gas-limit 200000 --value 0.001ether "$L1_SCROLL_MESSENGER_PROXY_ADDR" "sendMessage(address _to, uint256 _value, bytes memory _message, uint256 _gasLimit)" 0x0000000000000000000000000000000000000002 0x1 0x 200000 |
| 67 | + |
| 68 | + log_info "" |
| 69 | + next_queue_index=$(cast call --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" "$L1_MESSAGE_QUEUE_V2_PROXY_ADDR" "nextCrossDomainMessageIndex()(uint256)") |
| 70 | + log_info "Next queue index: $next_queue_index " |
| 71 | + |
| 72 | + log_info "" |
| 73 | + log_info "Sending enforced tx with nonce #$(( $ii + 1 ))" |
| 74 | + cast send --async --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" --private-key "$L1_DEPLOYER_PRIVATE_KEY" --legacy --gas-price 0.1gwei --nonce "$(( $ii + 1 ))" --gas-limit 200000 --value 0.001ether "$L1_ENFORCED_TX_GATEWAY_PROXY_ADDR" "sendTransaction(address _target, uint256 _value, uint256 _gasLimit, bytes calldata _data)" 0x0000000000000000000000000000000000000001 1 200000 0x |
| 75 | + |
| 76 | + log_info "" |
| 77 | + next_queue_index=$(cast call --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" "$L1_MESSAGE_QUEUE_V2_PROXY_ADDR" "nextCrossDomainMessageIndex()(uint256)") |
| 78 | + log_info "Next queue index: $next_queue_index " |
| 79 | + done |
| 80 | + |
| 81 | + echo "Done" |
| 82 | +} |
0 commit comments