|
| 1 | +#!/bin/bash |
| 2 | +# Deploy EntryPoint contracts with deterministic addresses |
| 3 | +# Uses pre-compiled bytecode from the official deployment to ensure matching addresses |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +SCRIPT_DIR="$(dirname "$0")" |
| 8 | +cd "$SCRIPT_DIR/.." |
| 9 | + |
| 10 | +# Ensure soldeer dependencies are installed |
| 11 | +forge soldeer install |
| 12 | + |
| 13 | +RPC_URL="${RPC_URL:-http://localhost:5050}" |
| 14 | +PRIVATE_KEY="${PRIVATE_KEY:-0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80}" |
| 15 | + |
| 16 | +# CREATE2 factory addresses (from deterministic-deployment-proxy) |
| 17 | +# See: https://github.com/Arachnid/deterministic-deployment-proxy |
| 18 | +CREATE2_FACTORY="0x4e59b44847b379578588920cA78FbF26c0B4956C" |
| 19 | +FACTORY_DEPLOYER="0x3fAB184622Dc19b6109349B94811493BF2a45362" |
| 20 | + |
| 21 | +# Salt used for deterministic deployment (mined to produce 0x4337... address) |
| 22 | +SALT="0x0a59dbff790c23c976a548690c27297883cc66b4c67024f9117b0238995e35e9" |
| 23 | + |
| 24 | +# Known deterministic EntryPoint address (deployed via CREATE2 with specific salt) |
| 25 | +ENTRYPOINT_ADDRESS="0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108" |
| 26 | + |
| 27 | +# Pre-signed transaction to deploy the CREATE2 factory |
| 28 | +# This works on any chain - the deployer address has nonce 0 and this tx deploys the factory |
| 29 | +FACTORY_DEPLOY_TX="0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222" |
| 30 | + |
| 31 | +# Path to the official deployment JSON with pre-compiled bytecode |
| 32 | +ENTRYPOINT_DEPLOYMENT="dependencies/eth-infinitism-account-abstraction-0.8.0/deployments/ethereum/EntryPoint.json" |
| 33 | + |
| 34 | +# Check if EntryPoint is already deployed |
| 35 | +echo "Checking if EntryPoint is already deployed at $ENTRYPOINT_ADDRESS..." |
| 36 | +ENTRYPOINT_CODE=$(cast code $ENTRYPOINT_ADDRESS --rpc-url $RPC_URL 2>/dev/null || echo "0x") |
| 37 | + |
| 38 | +if [ "$ENTRYPOINT_CODE" != "0x" ] && [ -n "$ENTRYPOINT_CODE" ]; then |
| 39 | + echo "EntryPoint already deployed at $ENTRYPOINT_ADDRESS" |
| 40 | + exit 0 |
| 41 | +fi |
| 42 | + |
| 43 | +echo "EntryPoint not found, proceeding with deployment..." |
| 44 | + |
| 45 | +echo "Checking CREATE2 factory at $CREATE2_FACTORY..." |
| 46 | + |
| 47 | +# Check if CREATE2 factory exists |
| 48 | +FACTORY_CODE=$(cast code $CREATE2_FACTORY --rpc-url $RPC_URL 2>/dev/null || echo "0x") |
| 49 | + |
| 50 | +if [ "$FACTORY_CODE" = "0x" ] || [ -z "$FACTORY_CODE" ]; then |
| 51 | + echo "CREATE2 factory not found, deploying..." |
| 52 | + |
| 53 | + # Fund the factory deployer (needs ~0.1 ETH for gas) |
| 54 | + echo "Funding factory deployer at $FACTORY_DEPLOYER..." |
| 55 | + cast send $FACTORY_DEPLOYER --value 0.1ether --private-key $PRIVATE_KEY --rpc-url $RPC_URL |
| 56 | + |
| 57 | + # Send the pre-signed deployment transaction |
| 58 | + echo "Deploying CREATE2 factory..." |
| 59 | + cast publish $FACTORY_DEPLOY_TX --rpc-url $RPC_URL |
| 60 | + |
| 61 | + # Verify deployment |
| 62 | + sleep 2 |
| 63 | + FACTORY_CODE=$(cast code $CREATE2_FACTORY --rpc-url $RPC_URL) |
| 64 | + if [ "$FACTORY_CODE" = "0x" ] || [ -z "$FACTORY_CODE" ]; then |
| 65 | + echo "ERROR: CREATE2 factory deployment failed" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + echo "CREATE2 factory deployed successfully at $CREATE2_FACTORY" |
| 69 | +else |
| 70 | + echo "CREATE2 factory already deployed" |
| 71 | +fi |
| 72 | + |
| 73 | +# Extract pre-compiled bytecode from official deployment |
| 74 | +echo "Extracting pre-compiled EntryPoint bytecode..." |
| 75 | +if [ ! -f "$ENTRYPOINT_DEPLOYMENT" ]; then |
| 76 | + echo "ERROR: EntryPoint deployment file not found at $ENTRYPOINT_DEPLOYMENT" |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | + |
| 80 | +# Get bytecode and remove 0x prefix for concatenation |
| 81 | +BYTECODE=$(sed -nE 's/.*"bytecode" *: *"(0x)?([^"]*)".*/\2/p' "$ENTRYPOINT_DEPLOYMENT") |
| 82 | + |
| 83 | +# The CREATE2 factory expects: salt (32 bytes) ++ initCode |
| 84 | +# Salt without 0x prefix |
| 85 | +SALT_NO_PREFIX=$(echo $SALT | sed 's/^0x//') |
| 86 | + |
| 87 | +# Concatenate salt + bytecode |
| 88 | +PAYLOAD="0x${SALT_NO_PREFIX}${BYTECODE}" |
| 89 | + |
| 90 | +echo "Deploying EntryPoint via CREATE2 factory..." |
| 91 | +RESULT=$(cast send $CREATE2_FACTORY "$PAYLOAD" --private-key $PRIVATE_KEY --rpc-url $RPC_URL --json 2>&1) |
| 92 | + |
| 93 | +# Verify deployment |
| 94 | +sleep 2 |
| 95 | +DEPLOYED_CODE=$(cast code $ENTRYPOINT_ADDRESS --rpc-url $RPC_URL 2>/dev/null || echo "0x") |
| 96 | + |
| 97 | +if [ "$DEPLOYED_CODE" = "0x" ] || [ -z "$DEPLOYED_CODE" ]; then |
| 98 | + echo "ERROR: EntryPoint deployment failed" |
| 99 | + echo "Expected address: $ENTRYPOINT_ADDRESS" |
| 100 | + exit 1 |
| 101 | +fi |
| 102 | + |
| 103 | +echo "EntryPoint deployed successfully at $ENTRYPOINT_ADDRESS" |
0 commit comments