#!/bin/sh # Generate Go bindings from Foundry-built contract ABIs # This script runs INSIDE the go-dev container set -e echo "🔧 Generating Go bindings from Foundry contract ABIs" echo "====================================================" echo "" # Check if abigen is available if ! command -v abigen > /dev/null 2>&1; then echo "⚠️ abigen not found, installing..." go install github.com/ethereum/go-ethereum/cmd/abigen@v1.13.15 fi # Ensure contracts are built if [ ! -d "contracts/out" ]; then echo "❌ contracts/out directory not found" echo " Run: ./scripts/dev.sh forge-build" exit 1 fi # Function to generate binding from Foundry artifact generate_binding_from_artifact() { local artifact_path=$1 local pkg_name=$2 local type_name=$3 local output_file=$4 echo "📄 Generating $type_name from $artifact_path..." # Extract ABI from Foundry artifact JSON local temp_abi="/tmp/$(basename $artifact_path .json)_abi.json" jq '.abi' "$artifact_path" > "$temp_abi" # Generate binding abigen \ --abi="$temp_abi" \ --pkg="$pkg_name" \ --type="$type_name" \ --out="$output_file" rm "$temp_abi" echo " ✅ Generated: $output_file" } # Create bindings directories mkdir -p bindings/uniswap_v2 mkdir -p bindings/uniswap_v3 mkdir -p bindings/camelot mkdir -p bindings/balancer mkdir -p bindings/curve mkdir -p bindings/kyber echo "🦄 Uniswap V2 Bindings" echo "---------------------" # Find UniswapV2 artifacts in contracts/out UNISWAP_V2_ROUTER_ARTIFACT=$(find contracts/out -name "IUniswapV2Router02.json" -o -name "UniswapV2Router02.json" | head -1) UNISWAP_V2_PAIR_ARTIFACT=$(find contracts/out -name "IUniswapV2Pair.json" -o -name "UniswapV2Pair.json" | head -1) if [ -n "$UNISWAP_V2_ROUTER_ARTIFACT" ]; then generate_binding_from_artifact \ "$UNISWAP_V2_ROUTER_ARTIFACT" \ "uniswap_v2" \ "UniswapV2Router" \ "bindings/uniswap_v2/router.go" else echo " ⚠️ UniswapV2Router artifact not found, skipping" fi if [ -n "$UNISWAP_V2_PAIR_ARTIFACT" ]; then generate_binding_from_artifact \ "$UNISWAP_V2_PAIR_ARTIFACT" \ "uniswap_v2" \ "UniswapV2Pair" \ "bindings/uniswap_v2/pair.go" else echo " ⚠️ UniswapV2Pair artifact not found, skipping" fi echo "" echo "🦄 Uniswap V3 Bindings" echo "---------------------" # Find UniswapV3 artifacts UNISWAP_V3_ROUTER_ARTIFACT=$(find contracts/out -name "ISwapRouter.json" -o -name "SwapRouter.json" | head -1) UNISWAP_V3_POOL_ARTIFACT=$(find contracts/out -name "IUniswapV3Pool.json" -o -name "UniswapV3Pool.json" | head -1) if [ -n "$UNISWAP_V3_ROUTER_ARTIFACT" ]; then generate_binding_from_artifact \ "$UNISWAP_V3_ROUTER_ARTIFACT" \ "uniswap_v3" \ "SwapRouter" \ "bindings/uniswap_v3/router.go" else echo " ⚠️ SwapRouter artifact not found, skipping" fi if [ -n "$UNISWAP_V3_POOL_ARTIFACT" ]; then generate_binding_from_artifact \ "$UNISWAP_V3_POOL_ARTIFACT" \ "uniswap_v3" \ "UniswapV3Pool" \ "bindings/uniswap_v3/pool.go" else echo " ⚠️ UniswapV3Pool artifact not found, skipping" fi echo "" echo "✅ Binding generation complete!" echo "" echo "Generated bindings:" find bindings -name "*.go" -type f | sort echo "" echo "💡 Import in your Go code:" echo " import \"github.com/your-org/mev-bot/bindings/uniswap_v2\"" echo " import \"github.com/your-org/mev-bot/bindings/uniswap_v3\""