--- name: aegisquant-defi-execution description: Zero-custody quantitative DeFi safety screening, MEV-protected routing, verified swap construction, and post-trade shortfall auditing via AegisQuant MCP (aegis-swap-mcp). --- # AegisQuant Pre-Trade Safety & Execution Protocol Follow this exact 4-step quantitative execution workflow whenever evaluating, sizing, or executing an on-chain swap or arbitrage trade on Base, Ethereum, Arbitrum, Polygon, Optimism, or Solana: ## 1. Safety & Fractional Kelly Sizing (`scan_alpha_safety` or `batch_portfolio_shield`) - Always run `scan_alpha_safety` (or `batch_portfolio_shield` for up to 10 tokens) **before** quoting or executing a trade on an unfamiliar token. - If `risk_assessment.verdict` is `CRITICAL_AVOID` or `hard_override_triggered === true`, **abort immediately** — do not build a swap. - If `risk_assessment.verdict === "UNVERIFIED_CAUTION"`, warn the user that upstream security APIs did not return complete telemetry and treat `max_recommended_position_usd` as `0`. - Cap position size at `risk_assessment.max_recommended_position_usd` (0.25x Fractional Kelly, hard-capped at 2% of pool liquidity). ## 2. Opportunity & Optimal Execution (`find_arb_and_yield_spreads` -> `compute_optimal_execution`) - For cross-DEX spread discovery, call `find_arb_and_yield_spreads`. Only proceed when `strictly_profitable_count > 0` and `net_profit_usd > 0`. - For any swap, call `compute_optimal_execution` to obtain: - `kkt_split_routing`: convex split allocations across active DEX pools. - `mev_protection`: `optimal_slippage_bps` ceiling where sandwich profit <= 0 and `recommended_venue` (`COW_MEV_PROTECTED` vs `KYBER_AGGREGATOR`). - `almgren_chriss_tranching`: `optimal_tranches` and `tranche_interval_seconds`. ## 3. Unsigned Calldata + Local Firewall (`build_verified_swap`) - Call `build_verified_swap` with `max_slippage_bps <= optimal_slippage_bps` and the user's explicit `sender_address` and `recipient_address`. - **Never** ignore a `FIREWALL_BLOCKED` response from `aegis-swap-mcp`. Only present `unsigned_tx` or `unsigned_order_intent` to the user's wallet when `local_firewall.status === "VERIFIED"`. ## 4. Post-Trade Shortfall Feedback (`audit_execution_shortfall`) - After the user signs and broadcasts the transaction, call `audit_execution_shortfall` with the `tx_hash`, `pool_address`, `quoted_price`, `expected_net_price`, and `realized_price`. - Apply `next_trade_adjustments` (switching to `COW_MEV_PROTECTED` or splitting into more tranches) on subsequent executions.