{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.hoodbuybutton.com/loop/receipt.schema.json",
  "title": "The Buy Button Loop Collection Receipt",
  "description": "An immutable, machine-readable receipt for a completed BUY fee collection and its cumulative dead-address observation.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "schemaVersion",
    "recordType",
    "recordVersion",
    "canonicalUri",
    "chain",
    "observation",
    "assets",
    "cumulativeDeadAddress",
    "latestCollection",
    "recipientLabelRegistry",
    "evidenceBoundary"
  ],
  "properties": {
    "$schema": { "const": "https://www.hoodbuybutton.com/loop/receipt.schema.json" },
    "schemaVersion": { "const": "1.0.0" },
    "recordType": { "const": "buy-button-loop-collection-receipt" },
    "recordVersion": { "const": 1 },
    "canonicalUri": { "type": "string", "format": "uri" },
    "chain": { "$ref": "#/$defs/chain" },
    "observation": { "$ref": "#/$defs/observation" },
    "assets": {
      "type": "object",
      "additionalProperties": false,
      "required": ["buy", "weth"],
      "properties": {
        "buy": { "$ref": "#/$defs/token" },
        "weth": { "$ref": "#/$defs/token" }
      }
    },
    "cumulativeDeadAddress": { "$ref": "#/$defs/cumulativeDeadAddress" },
    "latestCollection": { "$ref": "#/$defs/latestCollection" },
    "recipientLabelRegistry": { "$ref": "#/$defs/recipientLabelRegistry" },
    "evidenceBoundary": { "$ref": "#/$defs/evidenceBoundary" }
  },
  "$defs": {
    "address": {
      "type": "string",
      "pattern": "^0x[0-9A-Fa-f]{40}$"
    },
    "hash": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{64}$"
    },
    "baseUnits": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)$"
    },
    "decimalAmount": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]+)?$"
    },
    "explorerUrl": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://robinhoodchain\\.blockscout\\.com/"
    },
    "chain": {
      "type": "object",
      "additionalProperties": false,
      "required": ["namespace", "name", "chainId", "explorer"],
      "properties": {
        "namespace": { "const": "eip155" },
        "name": { "const": "Robinhood Chain" },
        "chainId": { "const": 4663 },
        "explorer": { "const": "https://robinhoodchain.blockscout.com" }
      }
    },
    "observation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["blockNumber", "blockHash", "blockTimestamp", "observedAt"],
      "properties": {
        "blockNumber": { "type": "integer", "minimum": 1 },
        "blockHash": { "$ref": "#/$defs/hash" },
        "blockTimestamp": { "type": "string", "format": "date-time" },
        "observedAt": { "type": "string", "format": "date-time" }
      }
    },
    "token": {
      "type": "object",
      "additionalProperties": false,
      "required": ["symbol", "name", "contract", "decimals", "explorerUrl"],
      "properties": {
        "symbol": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 },
        "contract": { "$ref": "#/$defs/address" },
        "decimals": { "type": "integer", "minimum": 0, "maximum": 255 },
        "explorerUrl": { "$ref": "#/$defs/explorerUrl" }
      }
    },
    "cumulativeDeadAddress": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "address",
        "explorerUrl",
        "balanceBaseUnits",
        "balance",
        "originalSupplyBaseUnits",
        "originalSupply",
        "shareOfOriginalSupplyPercent",
        "erc20TotalSupplyBaseUnits",
        "erc20TotalSupply",
        "definition"
      ],
      "properties": {
        "address": { "$ref": "#/$defs/address" },
        "explorerUrl": { "$ref": "#/$defs/explorerUrl" },
        "balanceBaseUnits": { "$ref": "#/$defs/baseUnits" },
        "balance": { "$ref": "#/$defs/decimalAmount" },
        "originalSupplyBaseUnits": { "$ref": "#/$defs/baseUnits" },
        "originalSupply": { "$ref": "#/$defs/decimalAmount" },
        "shareOfOriginalSupplyPercent": { "$ref": "#/$defs/decimalAmount" },
        "erc20TotalSupplyBaseUnits": { "$ref": "#/$defs/baseUnits" },
        "erc20TotalSupply": { "$ref": "#/$defs/decimalAmount" },
        "definition": { "type": "string", "minLength": 1 }
      }
    },
    "actor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["address", "explorerUrl"],
      "properties": {
        "address": { "$ref": "#/$defs/address" },
        "explorerUrl": { "$ref": "#/$defs/explorerUrl" }
      }
    },
    "buyToDead": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "from",
        "to",
        "assetContract",
        "amountBaseUnits",
        "amount",
        "transferLogIndex"
      ],
      "properties": {
        "from": { "$ref": "#/$defs/address" },
        "to": { "$ref": "#/$defs/address" },
        "assetContract": { "$ref": "#/$defs/address" },
        "amountBaseUnits": { "$ref": "#/$defs/baseUnits" },
        "amount": { "$ref": "#/$defs/decimalAmount" },
        "transferLogIndex": { "type": "integer", "minimum": 0 }
      }
    },
    "route": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "recipient",
        "sharePercent",
        "amountBaseUnits",
        "amount",
        "transferLogIndex",
        "distributionLogIndex",
        "explorerUrl"
      ],
      "properties": {
        "recipient": { "$ref": "#/$defs/address" },
        "sharePercent": { "type": "integer", "minimum": 1, "maximum": 100 },
        "amountBaseUnits": { "$ref": "#/$defs/baseUnits" },
        "amount": { "$ref": "#/$defs/decimalAmount" },
        "transferLogIndex": { "type": "integer", "minimum": 0 },
        "distributionLogIndex": { "type": "integer", "minimum": 0 },
        "explorerUrl": { "$ref": "#/$defs/explorerUrl" }
      }
    },
    "wethDistribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assetContract", "totalAmountBaseUnits", "totalAmount", "routes"],
      "properties": {
        "assetContract": { "$ref": "#/$defs/address" },
        "totalAmountBaseUnits": { "$ref": "#/$defs/baseUnits" },
        "totalAmount": { "$ref": "#/$defs/decimalAmount" },
        "routes": {
          "type": "array",
          "minItems": 5,
          "maxItems": 5,
          "items": { "$ref": "#/$defs/route" }
        }
      }
    },
    "latestCollection": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transactionHash",
        "transactionUrl",
        "blockNumber",
        "blockHash",
        "blockUrl",
        "timestamp",
        "transactionStatus",
        "receiptStatus",
        "caller",
        "collector",
        "buyToDead",
        "wethDistribution"
      ],
      "properties": {
        "transactionHash": { "$ref": "#/$defs/hash" },
        "transactionUrl": { "$ref": "#/$defs/explorerUrl" },
        "blockNumber": { "type": "integer", "minimum": 1 },
        "blockHash": { "$ref": "#/$defs/hash" },
        "blockUrl": { "$ref": "#/$defs/explorerUrl" },
        "timestamp": { "type": "string", "format": "date-time" },
        "transactionStatus": { "const": "success" },
        "receiptStatus": { "const": 1 },
        "caller": { "$ref": "#/$defs/actor" },
        "collector": { "$ref": "#/$defs/actor" },
        "buyToDead": { "$ref": "#/$defs/buyToDead" },
        "wethDistribution": { "$ref": "#/$defs/wethDistribution" }
      }
    },
    "recipientLabelRegistry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["scope", "registryUri", "signatureUri"],
      "properties": {
        "scope": { "type": "string", "minLength": 1 },
        "registryUri": { "type": "string", "format": "uri" },
        "signatureUri": { "type": "string", "format": "uri" }
      }
    },
    "evidenceBoundary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["onchainFacts", "humanLabels", "notClaimed"],
      "properties": {
        "onchainFacts": { "type": "string", "minLength": 1 },
        "humanLabels": { "type": "string", "minLength": 1 },
        "notClaimed": { "type": "string", "minLength": 1 }
      }
    }
  }
}
