#!/usr/bin/env bash
# Update Blockscout with bridge addresses and routes information
# This script creates documentation and provides instructions for manual Blockscout updates
# Usage: ./update-blockscout-bridge-info.sh

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }

log_info "========================================="
log_info "Update Blockscout with Bridge Information"
log_info "========================================="
log_info ""

# Bridge addresses
WETH9_BRIDGE_138="0x89dd12025bfCD38A168455A44B400e913ED33BE2"
WETH10_BRIDGE_138="0xe0E93247376aa097dB308B92e6Ba36bA015535D0"
WETH9_BRIDGE_MAINNET="0x2A0840e5117683b11682ac46f5CF5621E67269E3"
WETH10_BRIDGE_MAINNET="0xb7721dD53A8c629d9f1Ba31a5819AFe250002b03"

BLOCKSCOUT_URL="https://explorer.d-bis.org"

log_info "Chain 138 Bridge Contracts:"
log_info "  CCIPWETH9Bridge:  $WETH9_BRIDGE_138"
log_info "  CCIPWETH10Bridge: $WETH10_BRIDGE_138"
log_info ""

log_info "Ethereum Mainnet Bridge Contracts:"
log_info "  CCIPWETH9Bridge:  $WETH9_BRIDGE_MAINNET"
log_info "  CCIPWETH10Bridge: $WETH10_BRIDGE_MAINNET"
log_info ""

log_info "Blockscout Links:"
log_info "  CCIPWETH9Bridge (138):  $BLOCKSCOUT_URL/address/$WETH9_BRIDGE_138"
log_info "  CCIPWETH10Bridge (138): $BLOCKSCOUT_URL/address/$WETH10_BRIDGE_138"
log_info ""

log_info "========================================="
log_info "Bridge Routes Summary"
log_info "========================================="
log_info ""

log_info "From Chain 138 - CCIPWETH9Bridge sends to:"
log_info "  - BSC: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Polygon: 0xa780ef19a041745d353c9432f2a7f5a241335ffe"
log_info "  - Avalanche: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Base: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Arbitrum: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Optimism: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Ethereum Mainnet: $WETH9_BRIDGE_MAINNET"
log_info ""

log_info "From Chain 138 - CCIPWETH10Bridge sends to:"
log_info "  - BSC: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Polygon: 0xdab0591e5e89295ffad75a71dcfc30c5625c4fa2"
log_info "  - Avalanche: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Base: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Arbitrum: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Optimism: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Ethereum Mainnet: $WETH10_BRIDGE_MAINNET"
log_info ""

log_info "From Ethereum Mainnet - CCIPWETH9Bridge sends to:"
log_info "  - BSC: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Polygon: 0xa780ef19a041745d353c9432f2a7f5a241335ffe"
log_info "  - Avalanche: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Base: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Arbitrum: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Optimism: 0x8078a09637e47fa5ed34f626046ea2094a5cde5e"
log_info "  - Chain 138: $WETH9_BRIDGE_138"
log_info ""

log_info "From Ethereum Mainnet - CCIPWETH10Bridge sends to:"
log_info "  - BSC: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Polygon: 0xdab0591e5e89295ffad75a71dcfc30c5625c4fa2"
log_info "  - Avalanche: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Base: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Arbitrum: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Optimism: 0x105f8a15b819948a89153505762444ee9f324684"
log_info "  - Chain 138: $WETH10_BRIDGE_138"
log_info ""

log_success "========================================="
log_success "Blockscout Update Information Ready"
log_success "========================================="
log_info ""
log_info "📄 Documentation created:"
log_info "  - docs/BLOCKSCOUT_BRIDGE_ADDRESSES_UPDATE.md"
log_info "  - docs/ALL_BRIDGE_ADDRESSES_AND_ROUTES.md"
log_info ""
log_info "🔍 Next Steps:"
log_info "  1. Verify contracts on Blockscout UI (manual verification)"
log_info "  2. Update Blockscout with bridge route information"
log_info "  3. Monitor bridge transactions on Blockscout"
log_info ""

