#!/usr/bin/env bash # Check whether Chain 138 deployed tokens (cUSDT, cUSDC) support ERC-2612 permit or ERC-3009. # Used to determine x402 compatibility: thirdweb x402 requires permit or ERC-3009. # # Usage: ./scripts/verify/check-chain138-token-permit-support.sh [RPC_URL] # RPC_URL: optional; default from RPC_URL_138 or CHAIN_138_RPC_URL or https://rpc-core.d-bis.org # --dry-run: print RPC and token addresses only (no RPC calls). # # Exit: 0 if script runs; output is human-readable. Use output to fill CHAIN138_X402_TOKEN_SUPPORT.md. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$PROJECT_ROOT" [[ -f "${SCRIPT_DIR}/../lib/load-project-env.sh" ]] && source "${SCRIPT_DIR}/../lib/load-project-env.sh" 2>/dev/null || true DRY_RUN="" RPC_ARG="" for a in "$@"; do if [[ "$a" == "--dry-run" ]]; then DRY_RUN=1; else [[ -z "$RPC_ARG" ]] && RPC_ARG="$a"; fi done RPC="${RPC_ARG:-${RPC_URL_138:-${CHAIN_138_RPC_URL:-https://rpc-core.d-bis.org}}}" # Token name, address (from CHAIN138_TOKEN_ADDRESSES.md) declare -A TOKENS TOKENS[cUSDT]="0x93E66202A11B1772E55407B32B44e5Cd8eda7f22" TOKENS[cUSDC]="0xf22258f57794CC8E06237084b353Ab30fFfa640b" # Test holder for nonces(address) call (any address is fine) HOLDER="0x0000000000000000000000000000000000000001" if [[ -n "$DRY_RUN" ]]; then echo "=== Chain 138 token permit support check (--dry-run) ===" echo "RPC: $RPC" for sym in cUSDT cUSDC; do echo " $sym: ${TOKENS[$sym]}"; done exit 0 fi echo "=== Chain 138 — ERC-2612 / ERC-3009 token support ===" echo "RPC: $RPC" echo "" if ! command -v cast &>/dev/null; then echo "WARN: 'cast' (foundry) not found. Install foundry or run from a env that has cast." echo "Checking via cast is required for on-chain verification." exit 1 fi for sym in cUSDT cUSDC; do addr="${TOKENS[$sym]}" echo "--- $sym ($addr) ---" # ERC-2612: nonces(address) selector 0x7ecebe00 if cast call "$addr" "nonces(address)(uint256)" "$HOLDER" --rpc-url "$RPC" 2>/dev/null; then echo " ERC-2612 (permit): supported" else echo " ERC-2612 (permit): not supported" fi # ERC-3009: authorizationState(address,bytes32) — try zero args; if call fails, likely not present # bytes32(0) as second arg: 0x0000000000000000000000000000000000000000000000000000000000000000 if cast call "$addr" "authorizationState(address,bytes32)(bool)" "$HOLDER" 0x0000000000000000000000000000000000000000000000000000000000000000 --rpc-url "$RPC" 2>/dev/null; then echo " ERC-3009 (transferWithAuthorization): supported" else echo " ERC-3009 (transferWithAuthorization): not supported" fi echo "" done echo "x402 compatibility: thirdweb x402 requires ERC-2612 or ERC-3009. Document results in docs/04-configuration/CHAIN138_X402_TOKEN_SUPPORT.md"