{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "$ref": "#/$defs/d0_publicUnavailable"
    },
    {
      "$ref": "#/$defs/d3_publicPortfolioAvailable"
    }
  ],
  "$defs": {
    "d1_release": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{2,127}$"
        },
        "protocolRevision": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,63}$"
        },
        "rewardModelRevision": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,63}$"
        }
      },
      "required": [
        "id",
        "protocolRevision",
        "rewardModelRevision"
      ],
      "additionalProperties": false
    },
    "d2_unavailableReason": {
      "enum": [
        "indexer_disabled",
        "not_yet_safe",
        "indexer_unavailable",
        "indexer_mismatch",
        "unsupported_contract_version",
        "projection_rebuilding"
      ]
    },
    "d0_publicUnavailable": {
      "type": "object",
      "properties": {
        "schemaVersion": {
          "const": 2
        },
        "release": {
          "anyOf": [
            {
              "$ref": "#/$defs/d1_release"
            },
            {
              "type": "null"
            }
          ]
        },
        "installationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "status": {
          "const": "unavailable"
        },
        "reason": {
          "$ref": "#/$defs/d2_unavailableReason"
        }
      },
      "required": [
        "schemaVersion",
        "release",
        "installationId",
        "status",
        "reason"
      ],
      "additionalProperties": false
    },
    "d4_timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "d5_address": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{40}$"
    },
    "d7_decimal": {
      "type": "string",
      "format": "uint256-decimal"
    },
    "d8_bytes32": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{64}$"
    },
    "d6_chain": {
      "type": "object",
      "properties": {
        "target": {
          "enum": [
            "anvil",
            "sepolia",
            "mainnet"
          ]
        },
        "chainId": {
          "$ref": "#/$defs/d7_decimal"
        },
        "confirmations": {
          "const": "12"
        },
        "deploymentBlock": {
          "$ref": "#/$defs/d7_decimal"
        },
        "economyDeploymentBlock": {
          "$ref": "#/$defs/d7_decimal"
        },
        "indexedThroughBlock": {
          "$ref": "#/$defs/d7_decimal"
        },
        "safeThroughBlock": {
          "$ref": "#/$defs/d7_decimal"
        },
        "safeBlockHash": {
          "$ref": "#/$defs/d8_bytes32"
        },
        "safeBlockTimestamp": {
          "$ref": "#/$defs/d4_timestamp"
        }
      },
      "required": [
        "target",
        "chainId",
        "confirmations",
        "deploymentBlock",
        "economyDeploymentBlock",
        "indexedThroughBlock",
        "safeThroughBlock",
        "safeBlockHash",
        "safeBlockTimestamp"
      ],
      "additionalProperties": false
    },
    "d9_identities": {
      "type": "object",
      "properties": {
        "core": {
          "$ref": "#/$defs/d5_address"
        },
        "tokenFactory": {
          "$ref": "#/$defs/d5_address"
        },
        "mining": {
          "$ref": "#/$defs/d5_address"
        },
        "token": {
          "$ref": "#/$defs/d5_address"
        },
        "collection": {
          "$ref": "#/$defs/d5_address"
        },
        "miningImplementation": {
          "$ref": "#/$defs/d5_address"
        },
        "miningImplementationVersion": {
          "$ref": "#/$defs/d7_decimal"
        },
        "miningStorageLayoutDigest": {
          "$ref": "#/$defs/d8_bytes32"
        }
      },
      "required": [
        "core",
        "tokenFactory",
        "mining",
        "token",
        "collection",
        "miningImplementation",
        "miningImplementationVersion",
        "miningStorageLayoutDigest"
      ],
      "additionalProperties": false
    },
    "d11_positiveDecimal": {
      "type": "string",
      "pattern": "^[1-9][0-9]*$"
    },
    "d12_claimLimit": {
      "type": "string",
      "pattern": "^(?:[1-9]|[12][0-9]|3[0-2])$"
    },
    "d13_level": {
      "type": "object",
      "properties": {
        "level": {
          "type": "integer",
          "minimum": 1,
          "maximum": 14
        },
        "weight": {
          "$ref": "#/$defs/d7_decimal"
        },
        "cooldownBlocks": {
          "$ref": "#/$defs/d7_decimal"
        }
      },
      "required": [
        "level",
        "weight",
        "cooldownBlocks"
      ],
      "additionalProperties": false
    },
    "d10_configuration": {
      "type": "object",
      "properties": {
        "genesisTimestamp": {
          "$ref": "#/$defs/d7_decimal"
        },
        "roundDuration": {
          "$ref": "#/$defs/d11_positiveDecimal"
        },
        "maximumLevel": {
          "type": "integer",
          "minimum": 1,
          "maximum": 14
        },
        "claimLimit": {
          "$ref": "#/$defs/d12_claimLimit"
        },
        "tokenSymbol": {
          "const": "SQK"
        },
        "tokenDecimals": {
          "const": 18
        },
        "levels": {
          "type": "array",
          "minItems": 1,
          "maxItems": 14,
          "items": {
            "$ref": "#/$defs/d13_level"
          }
        }
      },
      "required": [
        "genesisTimestamp",
        "roundDuration",
        "maximumLevel",
        "claimLimit",
        "tokenSymbol",
        "tokenDecimals",
        "levels"
      ],
      "additionalProperties": false
    },
    "d14_miningState": {
      "type": "object",
      "properties": {
        "settledThroughRound": {
          "$ref": "#/$defs/d7_decimal"
        },
        "currentRound": {
          "$ref": "#/$defs/d7_decimal"
        },
        "completedBlockHeight": {
          "$ref": "#/$defs/d7_decimal"
        },
        "lastAppliedRound": {
          "$ref": "#/$defs/d7_decimal"
        },
        "totalWeight": {
          "$ref": "#/$defs/d7_decimal"
        }
      },
      "required": [
        "settledThroughRound",
        "currentRound",
        "completedBlockHeight",
        "lastAppliedRound",
        "totalWeight"
      ],
      "additionalProperties": false
    },
    "d15_portfolioSummary": {
      "type": "object",
      "properties": {
        "positionCount": {
          "$ref": "#/$defs/d7_decimal"
        },
        "activeWeight": {
          "$ref": "#/$defs/d7_decimal"
        },
        "targetWeight": {
          "$ref": "#/$defs/d7_decimal"
        },
        "claimableBaseUnits": {
          "$ref": "#/$defs/d7_decimal"
        },
        "earnedBaseUnits": {
          "$ref": "#/$defs/d7_decimal"
        },
        "earnedSevenDayBaseUnits": {
          "$ref": "#/$defs/d7_decimal"
        }
      },
      "required": [
        "positionCount",
        "activeWeight",
        "targetWeight",
        "claimableBaseUnits",
        "earnedBaseUnits",
        "earnedSevenDayBaseUnits"
      ],
      "additionalProperties": false
    },
    "d16_rewardDay": {
      "type": "object",
      "properties": {
        "date": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "earnedBaseUnits": {
          "$ref": "#/$defs/d7_decimal"
        }
      },
      "required": [
        "date",
        "earnedBaseUnits"
      ],
      "additionalProperties": false
    },
    "d17_position": {
      "type": "object",
      "properties": {
        "tokenId": {
          "$ref": "#/$defs/d7_decimal"
        },
        "level": {
          "type": "integer",
          "minimum": 1,
          "maximum": 14
        },
        "activeWeight": {
          "$ref": "#/$defs/d7_decimal"
        },
        "targetWeight": {
          "$ref": "#/$defs/d7_decimal"
        },
        "pendingRound": {
          "anyOf": [
            {
              "$ref": "#/$defs/d7_decimal"
            },
            {
              "type": "null"
            }
          ]
        },
        "pendingActivationSource": {
          "anyOf": [
            {
              "enum": [
                "mint",
                "merge"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "mergeState": {
          "enum": [
            "ready",
            "cooldown",
            "pending",
            "terminal"
          ]
        },
        "nextMergeBlock": {
          "$ref": "#/$defs/d7_decimal"
        },
        "blocksUntilMerge": {
          "$ref": "#/$defs/d7_decimal"
        },
        "claimableBaseUnits": {
          "$ref": "#/$defs/d7_decimal"
        },
        "earnedBaseUnits": {
          "$ref": "#/$defs/d7_decimal"
        },
        "earnedSevenDayBaseUnits": {
          "$ref": "#/$defs/d7_decimal"
        },
        "ownershipStartedAt": {
          "$ref": "#/$defs/d4_timestamp"
        },
        "metadataStatus": {
          "enum": [
            "available",
            "unavailable"
          ]
        }
      },
      "required": [
        "tokenId",
        "level",
        "activeWeight",
        "targetWeight",
        "pendingRound",
        "pendingActivationSource",
        "mergeState",
        "nextMergeBlock",
        "blocksUntilMerge",
        "claimableBaseUnits",
        "earnedBaseUnits",
        "earnedSevenDayBaseUnits",
        "ownershipStartedAt",
        "metadataStatus"
      ],
      "additionalProperties": false
    },
    "d18_cursor": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "pattern": "^[A-Za-z0-9_-]+$"
    },
    "d3_publicPortfolioAvailable": {
      "type": "object",
      "properties": {
        "schemaVersion": {
          "const": 2
        },
        "release": {
          "$ref": "#/$defs/d1_release"
        },
        "installationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "status": {
          "const": "available"
        },
        "generatedAt": {
          "$ref": "#/$defs/d4_timestamp"
        },
        "owner": {
          "$ref": "#/$defs/d5_address"
        },
        "chain": {
          "$ref": "#/$defs/d6_chain"
        },
        "identities": {
          "$ref": "#/$defs/d9_identities"
        },
        "configuration": {
          "$ref": "#/$defs/d10_configuration"
        },
        "mining": {
          "$ref": "#/$defs/d14_miningState"
        },
        "summary": {
          "$ref": "#/$defs/d15_portfolioSummary"
        },
        "earnings": {
          "type": "array",
          "minItems": 7,
          "maxItems": 7,
          "items": {
            "$ref": "#/$defs/d16_rewardDay"
          }
        },
        "positions": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "$ref": "#/$defs/d17_position"
          }
        },
        "nextCursor": {
          "anyOf": [
            {
              "$ref": "#/$defs/d18_cursor"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "schemaVersion",
        "release",
        "installationId",
        "status",
        "generatedAt",
        "owner",
        "chain",
        "identities",
        "configuration",
        "mining",
        "summary",
        "earnings",
        "positions",
        "nextCursor"
      ],
      "additionalProperties": false
    }
  },
  "$comment": "Public response structure from source snapshot 9e38b9313c9b4926ad15c7cd691d7f5789bdbc55. See endpoint notes for semantic constraints."
}
