{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "./settlement-schema.json",
  "title": "Lineage multi-asset reward settlement manifest",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "policyVersion", "epoch", "priceObservations", "totals", "leaves", "root"],
  "properties": {
    "version": { "const": 2 },
    "policyVersion": { "const": "lineage-rewards-v1" },
    "epoch": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "opensAt", "closesAt"],
      "properties": {
        "id": { "type": "integer", "minimum": 0 },
        "opensAt": { "type": "string", "format": "date-time" },
        "closesAt": { "type": "string", "format": "date-time" }
      }
    },
    "priceObservations": {
      "type": "array",
      "minItems": 4,
      "maxItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["symbol", "mint", "usdPrice", "blockId", "observedAt"],
        "properties": {
          "symbol": { "enum": ["NVDAx", "AMDx", "INTCx", "AAPLx"] },
          "mint": { "enum": ["Xsc9qvGR1efVDFGLrVsmkzv3qi45LTBjeUKSPmx9qEh", "XsXcJ6GZ9kVnjqGsjBnktRcuwMBmvKWh8S93RefZ1rF", "XshPgPdXFRWB8tP1j82rebb2Q9rPgGX37RuqzohmArM", "XsbEhLAtcf6HdfpFZ5xEMdqW8nfAvcsP5bdudRLJzJp"] },
          "usdPrice": { "type": "number", "exclusiveMinimum": 0 },
          "blockId": { "type": "integer", "minimum": 0 },
          "observedAt": { "type": "string", "format": "date-time" }
        }
      }
    },
    "totals": {
      "type": "object",
      "additionalProperties": false,
      "required": ["verifiedRuns", "wallets", "rawUnitsByAsset"],
      "properties": {
        "verifiedRuns": { "type": "integer", "minimum": 0 },
        "wallets": { "type": "integer", "minimum": 0 },
        "rawUnitsByAsset": {
          "type": "object",
          "additionalProperties": false,
          "required": ["NVDAx", "AMDx", "INTCx", "AAPLx"],
          "properties": {
            "NVDAx": { "type": "string", "pattern": "^[0-9]+$" },
            "AMDx": { "type": "string", "pattern": "^[0-9]+$" },
            "INTCx": { "type": "string", "pattern": "^[0-9]+$" },
            "AAPLx": { "type": "string", "pattern": "^[0-9]+$" }
          }
        }
      }
    },
    "leaves": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["index", "wallet", "symbol", "mint", "rawUnits", "runDigest", "leafHash"],
        "properties": {
          "index": { "type": "integer", "minimum": 0 },
          "wallet": { "type": "string", "pattern": "^[1-9A-HJ-NP-Za-km-z]{32,44}$" },
          "symbol": { "enum": ["NVDAx", "AMDx", "INTCx", "AAPLx"] },
          "mint": { "type": "string", "pattern": "^[1-9A-HJ-NP-Za-km-z]{32,44}$" },
          "rawUnits": { "type": "string", "pattern": "^[0-9]+$" },
          "runDigest": { "type": "string" },
          "leafHash": { "type": "string" }
        }
      }
    },
    "root": { "type": "string" },
    "manifestDigest": { "type": "string" },
    "onchainSignature": { "type": ["string", "null"] },
    "generatedAt": { "type": "string", "format": "date-time" }
  }
}
