Files
proxmox/scripts/deployment/run-mainnet-cwusdc-flash-quote-push-model-sweep.sh
defiQUG 0d29343941 chore: update .env.master.example with new deployment scripts and treasury manager parameters; enhance AGENTS.md with GRU reference primacy details
- Added new deployment script references for Aave quote-push and treasury manager in .env.master.example.
- Updated AGENTS.md to include information on GRU reference primacy versus public PMM mesh execution model.
- Minor updates to various documentation files to reflect changes in policy and operational guidelines.

Made-with: Cursor
2026-04-12 18:20:41 -07:00

106 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Read-only: loop **modeling** runs (no chain txs) for flash quote-push against live
# Mainnet cWUSDC/USDC reserves. Use when wallet USDC is zero but you want sized tranches.
#
# Env:
# ETHEREUM_MAINNET_RPC (required)
# FLASH_MODEL_SCAN_SIZES — comma-separated gross flash quote sizes in raw units (default 5e6,1e7,2e7)
# PMM_FLASH_EXIT_PRICE_CMD — passed to node --external-exit-price-cmd (default: printf 1.02)
# GAS_GWEI, NATIVE_PRICE — optional overrides for the economics model
# If GAS_GWEI is unset, the script reads the live mainnet gas price and converts it to gwei.
# FLASH_MODEL_GAS_TX_COUNT, FLASH_MODEL_GAS_PER_TX — gas row (defaults 3 / 250000)
# FLASH_MODEL_MAX_POST_TRADE_DEV_BPS — deviation guard (default 500; raise only for stress math, not production)
#
# Usage:
# source scripts/lib/load-project-env.sh
# bash scripts/deployment/run-mainnet-cwusdc-flash-quote-push-model-sweep.sh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROXMOX_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
# shellcheck disable=SC1091
source "${PROXMOX_ROOT}/scripts/lib/load-project-env.sh" 2>/dev/null || true
# shellcheck disable=SC1091
source "${PROXMOX_ROOT}/smom-dbis-138/scripts/load-env.sh" >/dev/null 2>&1 || true
require_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "[fail] missing required command: $1" >&2
exit 1
}
}
require_cmd cast
require_cmd node
RPC_URL="${ETHEREUM_MAINNET_RPC:-}"
CWUSDC="${CWUSDC_MAINNET:-0x2de5F116bFcE3d0f922d9C8351e0c5Fc24b9284a}"
USDC="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
INTEGRATION="${DODO_PMM_INTEGRATION_MAINNET:-}"
POOL="${POOL_CWUSDC_USDC_MAINNET:-0x69776fc607e9edA8042e320e7e43f54d06c68f0E}"
SCAN="${FLASH_MODEL_SCAN_SIZES:-5000000,10000000,25000000}"
EXIT_CMD="${PMM_FLASH_EXIT_PRICE_CMD:-printf 1.02}"
GAS_GWEI="${GAS_GWEI:-}"
NATIVE_PRICE="${NATIVE_PRICE:-3200}"
GAS_TXN="${FLASH_MODEL_GAS_TX_COUNT:-3}"
GAS_PER="${FLASH_MODEL_GAS_PER_TX:-250000}"
DEV_BPS="${FLASH_MODEL_MAX_POST_TRADE_DEV_BPS:-500}"
if [[ -z "$RPC_URL" ]]; then
echo "[fail] ETHEREUM_MAINNET_RPC is required" >&2
exit 1
fi
if [[ -n "$INTEGRATION" ]]; then
mapped_pool="$(cast call "$INTEGRATION" 'pools(address,address)(address)' "$CWUSDC" "$USDC" --rpc-url "$RPC_URL" 2>/dev/null | awk '{print $1}' || true)"
if [[ -n "$mapped_pool" && "$mapped_pool" != "0x0000000000000000000000000000000000000000" && "${mapped_pool,,}" != "${POOL,,}" ]]; then
POOL="$mapped_pool"
fi
fi
out="$(cast call "$POOL" 'getVaultReserve()(uint256,uint256)' --rpc-url "$RPC_URL")"
B="$(printf '%s\n' "$out" | sed -n '1p' | awk '{print $1}')"
Q="$(printf '%s\n' "$out" | sed -n '2p' | awk '{print $1}')"
if [[ -z "$GAS_GWEI" ]]; then
gas_price_wei="$(cast gas-price --rpc-url "$RPC_URL" | awk '{print $1}')"
GAS_GWEI="$(python3 - "$gas_price_wei" <<'PY'
import sys
print(f"{int(sys.argv[1]) / 1_000_000_000:.9f}")
PY
)"
fi
PMM_JS="${PROXMOX_ROOT}/scripts/analytics/pmm-flash-push-break-even.mjs"
echo "=== Flash quote-push model sweep (dry-run only) ==="
echo "pool=$POOL B=$B Q=$Q scan=$SCAN gas_tx=$GAS_TXN gas_per=$GAS_PER max_fee_gwei=$GAS_GWEI dev_bps=$DEV_BPS"
echo
# --full-loop-dry-run requires explicit -x; run one node invocation per scan size.
IFS=',' read -r -a sizes <<< "${SCAN// /}"
for x in "${sizes[@]}"; do
[[ -z "$x" ]] && continue
echo "----- model trade_raw=$x -----"
node "$PMM_JS" \
-B "$B" -Q "$Q" \
--full-loop-dry-run \
--loop-strategy quote-push \
-x "$x" \
--base-asset cWUSDC --base-decimals 6 \
--quote-asset USDC --quote-decimals 6 \
--external-exit-price-cmd "$EXIT_CMD" \
--flash-fee-bps 5 --lp-fee-bps 3 \
--flash-provider-cap 1000000000000 \
--flash-provider-name 'Aave mainnet (cap placeholder)' \
--gas-tx-count "$GAS_TXN" --gas-per-tx "$GAS_PER" \
--max-fee-gwei "$GAS_GWEI" \
--native-token-price "$NATIVE_PRICE" \
--max-post-trade-deviation-bps "$DEV_BPS"
echo
done
echo "Live execution: deploy-mainnet-aave-quote-push-stack.sh then run-mainnet-aave-cwusdc-quote-push-once.sh (see plan-mainnet-cwusdc-flash-quote-push-rebalance.sh)"
echo "Receiver surplus accounting: bash scripts/verify/report-mainnet-aave-quote-push-surplus-accounting.sh"