Files
proxmox/scripts/deployment/pmm-soak-mint-mirror-usdc-deployer-shortfall.sh
defiQUG dc8abb06e2 PMM soak grid: fund-grid progress/ERR trap, complete-grid START_LEG and timing, tranche RPC override, grid funding doc
- pmm-soak-operator-fund-grid: PMM_SOAK_FUND_PROGRESS_EVERY, ERR trap, help text comments only
- pmm-soak-complete-grid-funding-operator: PMM_SOAK_START_LEG resume, per-leg and total wall time
- pmm-soak-operator-fund-full-grid-tranches: PMM_SOAK_RPC_URL_OVERRIDE, bash --noprofile --norc, manual hint
- pmm-soak-mint-mirror-usdc-deployer-shortfall: ASCII-only operator messages
- CHAIN138_GRID_6534_WALLET_FUNDING_PLAN: full-grid orchestrator, env vars, log markers

Made-with: Cursor
2026-04-11 20:56:40 -07:00

91 lines
3.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Mint Official USDC mirror (Chain 138) to deployer so PMM soak grid funding can transfer out.
# OfficialStableMirrorToken: onlyOwner mint(address,uint256). Deployer is owner.
#
# Waits until deployer latest nonce == pending (no in-flight txs from this EOA), then mints shortfall:
# (PMM_SOAK_SEED_MIRROR_USDC_RAW × (6534 wallets)) deployer balance
#
# Usage:
# bash scripts/deployment/pmm-soak-mint-mirror-usdc-deployer-shortfall.sh --dry-run
# bash scripts/deployment/pmm-soak-mint-mirror-usdc-deployer-shortfall.sh --apply
#
# Env: RPC_URL_138, PMM_SOAK_RPC_URL_OVERRIDE, PRIVATE_KEY / DEPLOYER_PRIVATE_KEY, PMM_SOAK_GRID_JSON, PMM_SOAK_SEED_MIRROR_USDC_RAW,
# PMM_SOAK_WAIT_NONCE_CLEAR_SEC, CHAIN138_DEPLOY_GAS_PRICE_WEI
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
cd "$PROJECT_ROOT"
# shellcheck source=/dev/null
source "${PROJECT_ROOT}/scripts/lib/pmm-soak-dotenv-override.sh"
pmm_soak_snapshot_pool_env_for_restore
# shellcheck source=/dev/null
[[ -f "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" ]] && source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh"
pmm_soak_restore_pool_env_after_dotenv
if [[ -n "${PMM_SOAK_RPC_URL_OVERRIDE:-}" ]]; then
export RPC_URL_138="$PMM_SOAK_RPC_URL_OVERRIDE"
export CHAIN138_RPC_URL="$RPC_URL_138"
export CHAIN138_RPC="$RPC_URL_138"
export ETH_RPC_URL="$RPC_URL_138"
fi
USDC_M=0x71D6687F38b93CCad569Fa6352c876eea967201b
D=0x4A666F96fC8764181194447A7dFdb7d471b301C8
RPC="${RPC_URL_138:-http://192.168.11.211:8545}"
PK="${DEPLOYER_PRIVATE_KEY:-${PRIVATE_KEY:-}}"
SEED_USDC="${PMM_SOAK_SEED_MIRROR_USDC_RAW:-100000000}"
MAX_LI=6533
GAS_WEI="${CHAIN138_DEPLOY_GAS_PRICE_WEI:-1000}"
MAX_WAIT="${PMM_SOAK_WAIT_NONCE_CLEAR_SEC:-7200}"
APPLY=0
while [[ $# -gt 0 ]]; do
case "$1" in
--apply) APPLY=1 ;;
--dry-run) APPLY=0 ;;
*) echo "unknown: $1" >&2; exit 2 ;;
esac
shift
done
if [[ "$APPLY" -eq 1 && -z "$PK" ]]; then
echo "[mint-usdc] FATAL: --apply needs PRIVATE_KEY" >&2
exit 1
fi
USDC_NEEDED="$(python3 -c "print(int('$SEED_USDC') * (int('$MAX_LI') + 1))")"
USDC_BAL="$(cast call "$USDC_M" 'balanceOf(address)(uint256)' "$D" --rpc-url "$RPC" | awk '{print $1}')"
if (( USDC_BAL >= USDC_NEEDED )); then
echo "[mint-usdc] deployer already has $USDC_BAL >= need $USDC_NEEDED - nothing to do"
exit 0
fi
SHORTFALL="$(python3 -c "print(int('$USDC_NEEDED') - int('$USDC_BAL'))")"
echo "[mint-usdc] need=$USDC_NEEDED bal=$USDC_BAL shortfall=$SHORTFALL"
if [[ "$APPLY" -eq 0 ]]; then
echo "[mint-usdc] dry-run: after mempool clear, would run:"
echo " cast send $USDC_M 'mint(address,uint256)' $D $SHORTFALL --rpc-url \"\$RPC_URL_138\" --private-key \"\$PRIVATE_KEY\" --legacy --gas-price $GAS_WEI"
exit 0
fi
start="$SECONDS"
while true; do
nl="$(cast nonce "$D" --rpc-url "$RPC" -B latest)"
np="$(cast nonce "$D" --rpc-url "$RPC" -B pending)"
if [[ "$nl" == "$np" ]]; then
echo "[mint-usdc] nonce clear (latest=pending=$nl)"
break
fi
if (( SECONDS - start > MAX_WAIT )); then
echo "[mint-usdc] FATAL: pending nonce (latest=$nl pending=$np) after ${MAX_WAIT}s" >&2
exit 1
fi
echo "[mint-usdc] waiting mempool latest=$nl pending=$np ..."
sleep 3
done
cast send "$USDC_M" 'mint(address,uint256)' "$D" "$SHORTFALL" \
--rpc-url "$RPC" --private-key "$PK" --legacy --gas-price "$GAS_WEI"
USDC_BAL="$(cast call "$USDC_M" 'balanceOf(address)(uint256)' "$D" --rpc-url "$RPC" | awk '{print $1}')"
echo "[mint-usdc] done deployer mirror USDC balance=$USDC_BAL"