{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://402rates.com/schemas/rwa-instrument-v1.json",
  "title": "402rates.com RWA instrument state",
  "description": "Frozen-contract response for compass.rwa.instrument under public schema version 0.5.0.",
  "oneOf": [
    { "$ref": "#/$defs/instrument_response" },
    { "$ref": "#/$defs/ticker_list_response" }
  ],
  "$defs": {
    "status": {
      "type": "string",
      "enum": ["known", "conditional", "conflicting", "unknown"]
    },
    "date_or_null": {
      "type": ["string", "null"],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "term_cell": {
      "type": "object",
      "required": ["status", "issuer_stated", "source_url"],
      "properties": {
        "status": { "$ref": "#/$defs/status" },
        "issuer_stated": { "type": ["string", "null"] },
        "source_url": { "type": ["string", "null"], "format": "uri" }
      },
      "additionalProperties": true
    },
    "meta": {
      "type": "object",
      "required": ["capability", "schema_version", "generated_at", "schema", "contract", "disclaimer"],
      "properties": {
        "capability": { "const": "compass.rwa.instrument" },
        "schema_version": { "const": "0.5.0" },
        "generated_at": { "type": "string", "format": "date-time" },
        "schema": { "const": "https://402rates.com/schemas/rwa-instrument-v1.json" },
        "contract": {
          "type": "object",
          "required": ["stability", "change_policy"],
          "properties": {
            "stability": { "const": "frozen" },
            "change_policy": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        "disclaimer": { "const": "Informational data and calculation service only. Not investment, legal, tax or accounting advice; not an offer, solicitation, recommendation, or determination of eligibility or suitability. Source and onchain data may be inaccurate, incomplete, delayed, stale or conflicting. Verify independently. The caller remains responsible for every decision and action; 402rates.com does not execute investment transactions or hold financial assets on the caller's behalf." }
      },
      "additionalProperties": false
    },
    "terms": {
      "type": "object",
      "required": [
        "schema_version", "minimum_subscription", "minimum_redemption", "subscription_fee_bps",
        "redemption_fee_bps", "redemption", "access_requirements",
        "token_chains", "subscription_chains", "redemption_chains"
      ],
      "properties": {
        "schema_version": { "type": "string" },
        "minimum_subscription": { "$ref": "#/$defs/term_cell" },
        "minimum_redemption": { "$ref": "#/$defs/term_cell" },
        "subscription_fee_bps": { "$ref": "#/$defs/term_cell" },
        "redemption_fee_bps": { "$ref": "#/$defs/term_cell" },
        "redemption": { "$ref": "#/$defs/term_cell" },
        "access_requirements": { "$ref": "#/$defs/term_cell" },
        "token_chains": { "$ref": "#/$defs/term_cell" },
        "subscription_chains": { "$ref": "#/$defs/term_cell" },
        "redemption_chains": { "$ref": "#/$defs/term_cell" }
      },
      "additionalProperties": false
    },
    "yield": {
      "type": "object",
      "required": [
        "basis_name", "basis_version", "instrument", "ticker", "issuer",
        "family", "currency", "yield_basis", "yield_pct", "issuer_figure",
        "unavailable_reason", "deployments"
      ],
      "properties": {
        "basis_name": { "const": "Open Treasury Yield Basis" },
        "basis_version": { "const": "1.1.0" },
        "instrument": { "type": "string", "minLength": 1 },
        "ticker": { "type": "string", "minLength": 1 },
        "issuer": { "type": ["string", "null"] },
        "family": { "enum": ["price_accrual", "supply_accrual"] },
        "currency": { "type": ["string", "null"] },
        "yield_basis": { "enum": ["measured", "quoted", "unavailable"] },
        "yield_pct": { "type": ["number", "null"] },
        "issuer_figure": { "type": "object" },
        "unavailable_reason": { "type": ["string", "null"] },
        "deployments": { "type": "array" }
      },
      "additionalProperties": true
    },
    "deployment": {
      "type": "object",
      "required": ["chain_key", "chain", "address", "decimals", "verification", "verified_on"],
      "properties": {
        "chain_key": { "type": "string", "minLength": 1 },
        "chain": { "type": "string", "minLength": 1 },
        "address": { "type": "string", "minLength": 1 },
        "decimals": { "type": "integer", "minimum": 0 },
        "verification": { "enum": ["self_onchain", "issuer_list"] },
        "verified_on": { "$ref": "#/$defs/date_or_null" }
      },
      "additionalProperties": false
    },
    "size_supply": {
      "type": "object",
      "required": ["chain_key", "address", "total_supply", "raw_value", "decimals", "block", "read_at", "as_of", "age_days", "source_id"],
      "properties": {
        "chain_key": { "type": "string", "minLength": 1 },
        "address": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
        "total_supply": { "type": "string", "pattern": "^\\d+(?:\\.\\d+)?$" },
        "raw_value": { "type": "string", "pattern": "^\\d+$" },
        "decimals": { "type": "integer", "minimum": 0 },
        "block": { "type": ["integer", "null"], "minimum": 0 },
        "read_at": { "type": "string", "format": "date-time" },
        "as_of": { "type": "string", "minLength": 1 },
        "age_days": { "type": "integer", "minimum": 0 },
        "source_id": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "size": {
      "type": "object",
      "required": ["status", "value_atomic", "value_decimals", "value", "currency", "computed_from", "scope", "deployments_read", "deployments_known", "note"],
      "properties": {
        "status": { "enum": ["measured", "supply_only", "unavailable"] },
        "value_atomic": { "type": ["string", "null"], "pattern": "^\\d+$" },
        "value_decimals": { "type": ["integer", "null"], "minimum": 0 },
        "value": { "type": ["string", "null"], "pattern": "^\\d+(?:\\.\\d+)?$" },
        "currency": { "type": ["string", "null"] },
        "computed_from": {
          "type": "object",
          "required": ["nav_per_share", "supply"],
          "properties": {
            "nav_per_share": {
              "oneOf": [
                { "type": "null" },
                {
                  "type": "object",
                  "required": ["source_id", "as_of", "value", "raw_value", "decimals", "read_at"],
                  "properties": {
                    "source_id": { "type": "string", "minLength": 1 },
                    "as_of": { "$ref": "#/$defs/date_or_null" },
                    "value": { "type": "string", "minLength": 1 },
                    "raw_value": { "type": "string", "pattern": "^\\d+$" },
                    "decimals": { "type": "integer", "minimum": 0 },
                    "read_at": { "type": "string", "format": "date-time" }
                  },
                  "additionalProperties": false
                }
              ]
            },
            "supply": { "type": "array", "items": { "$ref": "#/$defs/size_supply" } }
          },
          "additionalProperties": false
        },
        "scope": { "const": "deployments_read" },
        "deployments_read": { "type": "integer", "minimum": 0 },
        "deployments_known": { "type": "integer", "minimum": 1 },
        "note": { "const": "total across the deployments we read, not the fund's total" },
        "reason": { "type": "string", "minLength": 1 },
        "age_days": { "type": ["integer", "null"], "minimum": 0 },
        "max_age_days": { "type": ["integer", "null"], "minimum": 0 }
      },
      "additionalProperties": false
    },
    "instrument_response": {
      "type": "object",
      "required": ["instrument", "yield", "size", "terms", "deployments", "evidence", "meta"],
      "properties": {
        "instrument": {
          "type": "object",
          "required": ["ticker", "issuer", "family", "currency"],
          "properties": {
            "ticker": { "type": "string", "minLength": 1 },
            "issuer": { "type": ["string", "null"] },
            "family": { "enum": ["price_accrual", "supply_accrual"] },
            "currency": { "type": ["string", "null"] }
          },
          "additionalProperties": false
        },
        "yield": { "$ref": "#/$defs/yield" },
        "size": { "$ref": "#/$defs/size" },
        "terms": { "$ref": "#/$defs/terms" },
        "deployments": { "type": "array", "items": { "$ref": "#/$defs/deployment" } },
        "evidence": {
          "type": "object",
          "required": ["terms_retrieved_at", "yield_computed_at", "size_computed_at", "last_verified"],
          "properties": {
            "terms_retrieved_at": { "$ref": "#/$defs/date_or_null" },
            "yield_computed_at": { "type": "string", "format": "date-time" },
            "size_computed_at": { "type": "string", "format": "date-time" },
            "last_verified": { "$ref": "#/$defs/date_or_null" }
          },
          "additionalProperties": false
        },
        "meta": { "$ref": "#/$defs/meta" }
      },
      "additionalProperties": false
    },
    "ticker_list_response": {
      "type": "object",
      "required": ["known_tickers", "meta"],
      "properties": {
        "known_tickers": {
          "type": "array",
          "minItems": 13,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "meta": { "$ref": "#/$defs/meta" }
      },
      "additionalProperties": false
    }
  }
}
