{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/farmdash/json-schema/farmdash-risk-sentinel-response-schema.json",
  "title": "RiskSentinelResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/farmdash-risk-api-openapi.yml#/components/schemas/RiskSentinelResponse",
  "type": "object",
  "properties": {
    "ok": {
      "type": "boolean"
    },
    "mode": {
      "type": "string",
      "enum": [
        "manual",
        "quoted"
      ]
    },
    "selectedProtocol": {
      "allOf": [
        {
          "$ref": "#/$defs/SupportedProtocol"
        }
      ],
      "nullable": true
    },
    "executionAlpha": {
      "allOf": [
        {
          "$ref": "#/$defs/ExecutionAlphaReport"
        }
      ],
      "nullable": true
    },
    "riskReport": {
      "allOf": [
        {
          "$ref": "#/$defs/SwapRiskReport"
        }
      ],
      "nullable": true
    },
    "quotePreview": {
      "allOf": [
        {
          "$ref": "#/$defs/SwapResult"
        }
      ],
      "nullable": true
    },
    "health": {
      "allOf": [
        {
          "$ref": "#/$defs/HealthCheck"
        }
      ],
      "nullable": true
    },
    "netEdge": {
      "allOf": [
        {
          "$ref": "#/$defs/NetEdgeAnalysis"
        }
      ],
      "nullable": true
    },
    "flags": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/RiskFlag"
      }
    },
    "shouldHalt": {
      "type": "boolean"
    }
  },
  "$defs": {
    "AllowanceStatus": {
      "type": "object",
      "properties": {
        "spender": {
          "type": [
            "string",
            "null"
          ]
        },
        "allowance": {
          "type": [
            "string",
            "null"
          ]
        },
        "requiredAmount": {
          "type": "string"
        },
        "approvalNeeded": {
          "type": "boolean"
        },
        "overApproved": {
          "type": "boolean"
        },
        "source": {
          "type": "string",
          "enum": [
            "onchain",
            "quote_fallback",
            "unavailable"
          ]
        }
      }
    },
    "ExecutionAlphaReport": {
      "type": "object",
      "properties": {
        "selectedProtocol": {
          "$ref": "#/$defs/SupportedProtocol"
        },
        "routeReason": {
          "type": "string"
        },
        "mevProtection": {
          "type": "object",
          "properties": {
            "safetyMode": {
              "$ref": "#/$defs/SwapSafetyMode"
            },
            "actualSlippageBps": {
              "type": "integer"
            },
            "maxRecommendedSlippageBps": {
              "type": "integer"
            }
          }
        },
        "candidates": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/RouteCandidate"
          }
        },
        "quoteDecay": {
          "$ref": "#/$defs/QuoteDecayMetrics"
        },
        "netEdge": {
          "$ref": "#/$defs/NetEdgeAnalysis"
        }
      }
    },
    "HealthCheck": {
      "type": "object",
      "properties": {
        "healthFactor": {
          "type": [
            "number",
            "null"
          ]
        },
        "liquidationBufferPct": {
          "type": [
            "number",
            "null"
          ]
        },
        "alertLevel": {
          "type": "string",
          "enum": [
            "none",
            "warning",
            "critical"
          ]
        },
        "shouldHalt": {
          "type": "boolean"
        }
      }
    },
    "NetEdgeAnalysis": {
      "type": "object",
      "properties": {
        "expectedUpsideUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "protocolFeeUsd": {
          "type": "number"
        },
        "gasUsd": {
          "type": "number"
        },
        "bridgeFeeUsd": {
          "type": "number"
        },
        "riskBufferUsd": {
          "type": "number"
        },
        "totalCostUsd": {
          "type": "number"
        },
        "netEdgeUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "positive": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "enforced": {
          "type": "boolean"
        }
      }
    },
    "PegCheck": {
      "type": "object",
      "properties": {
        "tokenAddress": {
          "type": "string"
        },
        "symbol": {
          "type": "string"
        },
        "reference": {
          "type": "string",
          "enum": [
            "USD",
            "ETH"
          ]
        },
        "priceUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "referencePriceUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "deviationPct": {
          "type": [
            "number",
            "null"
          ]
        },
        "alert": {
          "type": "boolean"
        }
      }
    },
    "QuoteDecayMetrics": {
      "type": "object",
      "properties": {
        "previousObservedAt": {
          "type": [
            "integer",
            "null"
          ]
        },
        "quoteAgeMs": {
          "type": [
            "integer",
            "null"
          ]
        },
        "outputDecayBps": {
          "type": "number"
        },
        "gasIncreaseBps": {
          "type": "number"
        },
        "severity": {
          "$ref": "#/$defs/QuoteDecaySeverity"
        }
      }
    },
    "QuoteDecaySeverity": {
      "type": "string",
      "enum": [
        "none",
        "low",
        "medium",
        "high"
      ]
    },
    "RiskFlag": {
      "type": "object",
      "required": [
        "code",
        "category",
        "severity",
        "title",
        "message"
      ],
      "properties": {
        "code": {
          "type": "string"
        },
        "category": {
          "type": "string",
          "enum": [
            "approval",
            "bridge",
            "contract",
            "token",
            "health",
            "execution"
          ]
        },
        "severity": {
          "$ref": "#/$defs/RiskSeverity"
        },
        "title": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "metadata": {
          "type": "object",
          "additionalProperties": true
        }
      }
    },
    "RiskSeverity": {
      "type": "string",
      "enum": [
        "low",
        "medium",
        "high",
        "critical"
      ]
    },
    "RouteCandidate": {
      "type": "object",
      "properties": {
        "protocol": {
          "$ref": "#/$defs/SupportedProtocol"
        },
        "estimatedOutput": {
          "type": "string"
        },
        "feeAmountUsd": {
          "type": "number"
        },
        "gasEstimateUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "bridgeFeeUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "routeRiskScore": {
          "type": "number"
        },
        "selected": {
          "type": "boolean"
        }
      }
    },
    "SupportedProtocol": {
      "type": "string",
      "enum": [
        "lifi",
        "relay"
      ],
      "description": "Swap quote provider. Automatic routing compares all healthy compatible providers (LI.FI, Relay; 0x paused until reinstated); force one with ?protocol= (deterministic, never silent fallback)."
    },
    "SwapResult": {
      "type": "object",
      "required": [
        "protocol",
        "estimatedOutput",
        "feeBps",
        "feeAmountUSD",
        "gasEstimate",
        "txData",
        "expiresAt"
      ],
      "properties": {
        "protocol": {
          "$ref": "#/$defs/SupportedProtocol"
        },
        "estimatedOutput": {
          "type": "string"
        },
        "feeBps": {
          "type": "integer"
        },
        "feeAmountUSD": {
          "type": "string"
        },
        "feeEventId": {
          "type": "string",
          "format": "uuid",
          "description": "Use with /agents/confirm to confirm settlement"
        },
        "gasEstimate": {
          "type": "string"
        },
        "txData": {
          "$ref": "#/$defs/SwapTxData"
        },
        "expiresAt": {
          "type": "integer"
        },
        "allowanceTarget": {
          "type": [
            "string",
            "null"
          ]
        },
        "gasEstimateUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "bridgeFeeUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "simulation": {
          "type": "object",
          "additionalProperties": true
        },
        "executionAlpha": {
          "$ref": "#/$defs/ExecutionAlphaReport"
        },
        "riskReport": {
          "$ref": "#/$defs/SwapRiskReport"
        },
        "confirmUrl": {
          "type": "string"
        }
      }
    },
    "SwapRiskReport": {
      "type": "object",
      "properties": {
        "flags": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/RiskFlag"
          }
        },
        "approval": {
          "allOf": [
            {
              "$ref": "#/$defs/AllowanceStatus"
            }
          ],
          "nullable": true
        },
        "pegChecks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/PegCheck"
          }
        },
        "health": {
          "allOf": [
            {
              "$ref": "#/$defs/HealthCheck"
            }
          ],
          "nullable": true
        },
        "shouldHalt": {
          "type": "boolean"
        },
        "haltReasons": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "SwapSafetyMode": {
      "type": "string",
      "enum": [
        "strict",
        "balanced"
      ]
    },
    "SwapTxData": {
      "type": "object",
      "required": [
        "to",
        "data",
        "value",
        "chainId"
      ],
      "properties": {
        "to": {
          "type": "string",
          "description": "Protocol contract address (NOT FarmDash)"
        },
        "data": {
          "type": "string",
          "description": "Encoded calldata"
        },
        "value": {
          "type": "string",
          "description": "Native token value in wei"
        },
        "chainId": {
          "type": "integer"
        }
      }
    }
  }
}