|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Configuration |
| 5 | +RPC_URL="http://localhost:8545" |
| 6 | +ENTRYPOINT="0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108" |
| 7 | + |
| 8 | +# Get the directory where this script is located |
| 9 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | +WORKSPACE_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" |
| 11 | + |
| 12 | +# Read paymaster address from contracts-anvil.json |
| 13 | +CONTRACTS_FILE="$WORKSPACE_ROOT/examples/demo-app/contracts-anvil.json" |
| 14 | + |
| 15 | +if [ ! -f "$CONTRACTS_FILE" ]; then |
| 16 | + echo "❌ contracts-anvil.json not found at $CONTRACTS_FILE" |
| 17 | + echo "Please run deploy-msa-anvil.sh first" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +PAYMASTER=$(jq -r '.testPaymaster // .mockPaymaster' "$CONTRACTS_FILE") |
| 22 | + |
| 23 | +if [ -z "$PAYMASTER" ] || [ "$PAYMASTER" == "null" ]; then |
| 24 | + echo "❌ Paymaster address not found in contracts-anvil.json" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +echo "🔍 Checking paymaster deposit status..." |
| 29 | +echo "" |
| 30 | +echo "Paymaster address: $PAYMASTER" |
| 31 | +echo "EntryPoint address: $ENTRYPOINT" |
| 32 | +echo "" |
| 33 | + |
| 34 | +# Check paymaster's ETH balance |
| 35 | +echo "💰 Paymaster contract balance:" |
| 36 | +BALANCE=$(cast balance "$PAYMASTER" --rpc-url "$RPC_URL") |
| 37 | +echo " $BALANCE wei ($(cast --to-unit "$BALANCE" ether) ETH)" |
| 38 | +echo "" |
| 39 | + |
| 40 | +# Check deposit in EntryPoint using balanceOf(address) |
| 41 | +echo "💳 Deposit in EntryPoint:" |
| 42 | +DEPOSIT_RAW=$(cast call "$ENTRYPOINT" "balanceOf(address)(uint256)" "$PAYMASTER" --rpc-url "$RPC_URL") |
| 43 | +# Extract just the number without the scientific notation |
| 44 | +DEPOSIT=$(echo "$DEPOSIT_RAW" | awk '{print $1}') |
| 45 | +DEPOSIT_ETH=$(cast --to-unit "$DEPOSIT" ether 2>/dev/null || echo "0") |
| 46 | +echo " $DEPOSIT wei ($DEPOSIT_ETH ETH)" |
| 47 | +echo "" |
| 48 | + |
| 49 | +# Convert to decimal for comparison |
| 50 | +DEPOSIT_DEC="$DEPOSIT" |
| 51 | + |
| 52 | +if [ "$DEPOSIT_DEC" == "0" ]; then |
| 53 | + echo "❌ Paymaster has NO deposit in EntryPoint!" |
| 54 | + echo "" |
| 55 | + echo "To fix this, run:" |
| 56 | + echo " cast send '$PAYMASTER' 'deposit()' --value 10ether --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url '$RPC_URL'" |
| 57 | + exit 1 |
| 58 | +else |
| 59 | + echo "✅ Paymaster has deposit in EntryPoint" |
| 60 | +fi |
| 61 | + |
| 62 | +echo "✅ Deposit amount: $DEPOSIT_ETH ETH" |
| 63 | +echo "" |
| 64 | + |
| 65 | +# Check stake using getDepositInfo(address) |
| 66 | +echo "🔒 Checking stake status:" |
| 67 | +DEPOSIT_INFO=$(cast call "$ENTRYPOINT" "getDepositInfo(address)" "$PAYMASTER" --rpc-url "$RPC_URL") |
| 68 | + |
| 69 | +# Parse the returned tuple: (deposit, staked, stake, unstakeDelaySec, withdrawTime) |
| 70 | +# The output is a hex string with 5 values concatenated |
| 71 | +STAKED_HEX=$(echo "$DEPOSIT_INFO" | cut -c67-130) # Second 32 bytes (staked boolean) |
| 72 | +STAKE_HEX=$(echo "$DEPOSIT_INFO" | cut -c131-194) # Third 32 bytes (stake amount) |
| 73 | + |
| 74 | +# Convert hex to decimal (remove leading zeros) |
| 75 | +STAKED_VALUE="0x$STAKED_HEX" |
| 76 | +STAKE_VALUE="0x$STAKE_HEX" |
| 77 | + |
| 78 | +# Check if staked (any non-zero value means true) |
| 79 | +if [ "$STAKED_VALUE" != "0x0000000000000000000000000000000000000000000000000000000000000000" ]; then |
| 80 | + STAKE_ETH=$(cast --to-unit "$STAKE_VALUE" ether 2>/dev/null || echo "0") |
| 81 | + echo " ✅ Paymaster is staked" |
| 82 | + echo " ✅ Stake amount: $STAKE_ETH ETH" |
| 83 | +else |
| 84 | + echo " ❌ Paymaster is NOT staked!" |
| 85 | + echo "" |
| 86 | + echo " To fix this, run:" |
| 87 | + echo " cast send '$PAYMASTER' 'addStake(uint32)' 86400 --value 1ether --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url '$RPC_URL'" |
| 88 | + exit 1 |
| 89 | +fi |
0 commit comments