DeFi Slippage, MEV & Liquidation Math Guard
ingravity_computeDefiSlippageAndLiquidationComputes deterministic 18-decimal BigInt AMM swap outputs (amm: exact amount out, price impact, and 48-step MEV sandwich bounds) and/or perp liquidation limits (leverage: liquidation price and health factor). Runs pure off-chain math with zero RPC calls or on-chain side effects; pass amm, leverage, or both (omitting both returns -32602). Set tier to FULL ($0.10 USDC, default) for full metrics or ESSENTIAL ($0.04 USDC) for PROCEED/ABORT signal only; unpaid calls return isError: true with an x402 challenge (0.15%/5%-10% rescue fees apply only when settling exposed live-capital rescues). Use for swap or leverage math; use ingravity_inspectEvmTransactionFirewall for raw calldata.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amm | No | Optional constant-product AMM swap parameters (reserveIn, reserveOut, amountIn required when included; evaluated independently of leverage; supply amm, leverage, or both). | |
| tier | No | Billing & output depth: FULL ($0.10 USDC) returns exact amm and leverage structures; ESSENTIAL ($0.04 USDC) returns top-level action, signal, and savedCapitalEstimateUsd only. | FULL |
| leverage | No | Optional perpetual/margin position parameters for exact liquidation price and initial health factor (entryPrice required when included; evaluated independently of amm). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amm | No | Exact BigInt swap metrics and optimal MEV sandwich profitability bounds (FULL tier only, when amm supplied). | |
| action | Yes | Trade or margin risk gate decision. | |
| signal | Yes | Traffic-light execution signal. | |
| settled | Yes | Whether x402 USDC payment settled cleanly. | |
| leverage | No | Exact liquidation price, distance-to-liquidation %, and health factor (FULL tier only, when leverage supplied). | |
| savedCapitalEstimateUsd | Yes | Estimated MEV or liquidation loss avoided. | |
| proportionalRescueCommissionPolicy | No | 0.15% Pre-Flight swap and 5%-10% Safe-Harbor terms (FULL tier only). |