Files
proxmox/scripts/deployment/recycle-mainnet-aave-quote-push-surplus.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

156 lines
5.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Sweep retained quote surplus from the receiver to the deployer and, when the
# deployer gas reserve is healthy, immediately recycle that quote into the
# wallet-funded cWUSDC/USDC peg tranche helper.
#
# Default: simulation only. Use --apply to broadcast / execute.
#
# Env:
# ETHEREUM_MAINNET_RPC required
# PRIVATE_KEY required
# AAVE_QUOTE_PUSH_RECEIVER_MAINNET required
# QUOTE_PUSH_SURPLUS_TOKEN_MAINNET optional; defaults to mainnet USDC
# QUOTE_PUSH_RECEIVER_RESERVE_RAW optional; amount to keep on receiver after sweep
# QUOTE_PUSH_DEPLOYER_GAS_FLOOR_ETH optional; default 0.003
# QUOTE_PUSH_OPERATION_BUFFER_ETH optional; default 0.0005
# QUOTE_PUSH_NATIVE_TOKEN_PRICE optional; default 3200
#
# Usage:
# source scripts/lib/load-project-env.sh
# bash scripts/deployment/recycle-mainnet-aave-quote-push-surplus.sh --dry-run
# bash scripts/deployment/recycle-mainnet-aave-quote-push-surplus.sh --apply
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROXMOX_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
SMOM="${PROXMOX_ROOT}/smom-dbis-138"
DEFAULT_USDC_MAINNET="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
# shellcheck disable=SC1091
source "${PROXMOX_ROOT}/scripts/lib/load-project-env.sh" 2>/dev/null || true
# shellcheck disable=SC1091
source "${SMOM}/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_env() {
local name="$1"
if [[ -z "${!name:-}" ]]; then
echo "[fail] missing required env: $name" >&2
exit 1
fi
}
pick_latest_receiver() {
local latest_json="${SMOM}/broadcast/DeployAaveQuotePushFlashReceiver.s.sol/1/run-latest.json"
if [[ ! -f "$latest_json" ]] || ! command -v jq >/dev/null 2>&1; then
return 1
fi
jq -r '.transactions[]? | select(.transactionType == "CREATE" and .contractName == "AaveQuotePushFlashReceiver") | .contractAddress' \
"$latest_json" | tail -n1
}
require_cmd cast
require_cmd python3
MODE="dry-run"
for arg in "$@"; do
case "$arg" in
--dry-run) MODE="dry-run" ;;
--apply) MODE="apply" ;;
*)
echo "[fail] unknown arg: $arg (use --dry-run or --apply)" >&2
exit 2
;;
esac
done
require_env ETHEREUM_MAINNET_RPC
require_env PRIVATE_KEY
if [[ -z "${AAVE_QUOTE_PUSH_RECEIVER_MAINNET:-}" ]]; then
inferred_receiver="$(pick_latest_receiver || true)"
if [[ -n "$inferred_receiver" && "$inferred_receiver" != "null" ]]; then
export AAVE_QUOTE_PUSH_RECEIVER_MAINNET="$inferred_receiver"
fi
fi
require_env AAVE_QUOTE_PUSH_RECEIVER_MAINNET
DEPLOYER="$(cast wallet address --private-key "$PRIVATE_KEY")"
TOKEN="${QUOTE_PUSH_SURPLUS_TOKEN_MAINNET:-$DEFAULT_USDC_MAINNET}"
RECEIVER_RESERVE_RAW="${QUOTE_PUSH_RECEIVER_RESERVE_RAW:-0}"
GAS_FLOOR_ETH="${QUOTE_PUSH_DEPLOYER_GAS_FLOOR_ETH:-0.003}"
OP_BUFFER_ETH="${QUOTE_PUSH_OPERATION_BUFFER_ETH:-0.0005}"
NATIVE_TOKEN_PRICE="${QUOTE_PUSH_NATIVE_TOKEN_PRICE:-3200}"
deployer_eth="$(cast balance "$DEPLOYER" --ether --rpc-url "$ETHEREUM_MAINNET_RPC")"
receiver_quote_raw="$(cast call "$TOKEN" 'balanceOf(address)(uint256)' "$AAVE_QUOTE_PUSH_RECEIVER_MAINNET" --rpc-url "$ETHEREUM_MAINNET_RPC" | awk '{print $1}')"
read -r sweepable_raw gas_shortfall_eth <<EOF
$(python3 - "$deployer_eth" "$receiver_quote_raw" "$RECEIVER_RESERVE_RAW" "$GAS_FLOOR_ETH" "$OP_BUFFER_ETH" <<'PY'
import sys
deployer_eth = float(sys.argv[1])
receiver_quote_raw = int(sys.argv[2])
receiver_reserve_raw = int(sys.argv[3])
gas_floor_eth = float(sys.argv[4])
op_buffer_eth = float(sys.argv[5])
sweepable_raw = max(0, receiver_quote_raw - receiver_reserve_raw)
gas_shortfall_eth = max(0.0, gas_floor_eth + op_buffer_eth - deployer_eth)
print(sweepable_raw, gas_shortfall_eth)
PY
)
EOF
gas_floor_breached="$(
python3 - "$gas_shortfall_eth" <<'PY'
import sys
print("yes" if float(sys.argv[1]) > 0 else "no")
PY
)"
echo "=== recycle-mainnet-aave-quote-push-surplus ($MODE) ==="
echo "deployer=$DEPLOYER"
echo "receiver=$AAVE_QUOTE_PUSH_RECEIVER_MAINNET"
echo "token=$TOKEN"
echo "receiver_quote_raw=$receiver_quote_raw"
echo "receiver_reserve_raw=$RECEIVER_RESERVE_RAW"
echo "sweepable_raw=$sweepable_raw"
echo "deployer_eth=$deployer_eth"
echo "gas_floor_eth=$GAS_FLOOR_ETH"
echo "operation_buffer_eth=$OP_BUFFER_ETH"
echo "native_token_price=$NATIVE_TOKEN_PRICE"
bash "${PROXMOX_ROOT}/scripts/verify/report-mainnet-aave-quote-push-surplus-accounting.sh"
if (( sweepable_raw == 0 )); then
echo "[stop] no sweepable receiver surplus is available" >&2
exit 3
fi
if [[ "$MODE" == "dry-run" ]]; then
bash "${PROXMOX_ROOT}/scripts/deployment/sweep-mainnet-aave-quote-push-receiver-surplus.sh" --dry-run
if [[ "$gas_floor_breached" == "yes" ]]; then
echo "[stop] deployer gas reserve is below recycle floor; sweep can proceed, but pool recycle is intentionally skipped"
exit 0
fi
bash "${PROXMOX_ROOT}/scripts/deployment/apply-mainnet-cwusdc-usdc-peg-tranche-from-wallet.sh" --dry-run
exit 0
fi
bash "${PROXMOX_ROOT}/scripts/deployment/sweep-mainnet-aave-quote-push-receiver-surplus.sh" --apply
if [[ "$gas_floor_breached" == "yes" ]]; then
echo "[stop] swept surplus to deployer, but deployer ETH is still below recycle floor; skipping pool-growth tranche"
exit 0
fi
bash "${PROXMOX_ROOT}/scripts/deployment/apply-mainnet-cwusdc-usdc-peg-tranche-from-wallet.sh" --apply