{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.hoodbuybutton.com/receipts/ledger.schema.json",
  "title": "Buy Button public fee ledger",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "recordType",
    "canonicalUri",
    "updatedAt",
    "chain",
    "assets",
    "activation",
    "labelRegistry",
    "summary",
    "snapshot",
    "routes",
    "venueSnapshot",
    "claims",
    "usesAndOutcomes",
    "evidenceBoundary"
  ],
  "properties": {
    "$schema": {"type": "string", "format": "uri"},
    "schemaVersion": {"const": "1.0.0"},
    "recordType": {"const": "buy-button-public-fee-ledger"},
    "canonicalUri": {"type": "string", "format": "uri"},
    "updatedAt": {"type": "string", "format": "date-time"},
    "chain": {
      "type": "object",
      "required": ["namespace", "name", "chainId", "explorer"],
      "properties": {
        "namespace": {"const": "eip155"},
        "name": {"type": "string"},
        "chainId": {"const": 4663},
        "explorer": {"type": "string", "format": "uri"}
      },
      "additionalProperties": false
    },
    "assets": {"type": "object"},
    "activation": {"type": "object"},
    "labelRegistry": {"type": "object"},
    "summary": {
      "type": "object",
      "required": ["confirmedCollectionCount", "routedWeth", "buySentToDeadDuringIncludedCollections", "verifiedReserveAcquisitionCount", "verifiedReserveWethInput", "verifiedReserveBuyReceived", "unclassifiedOutflowCount", "correctionCount"],
      "properties": {
        "confirmedCollectionCount": {"type": "integer", "minimum": 0},
        "routedWeth": {"$ref": "#/$defs/decimal"},
        "buySentToDeadDuringIncludedCollections": {"$ref": "#/$defs/decimal"},
        "verifiedReserveAcquisitionCount": {"type": "integer", "minimum": 0},
        "verifiedReserveWethInput": {"$ref": "#/$defs/decimal"},
        "verifiedReserveBuyReceived": {"$ref": "#/$defs/decimal"},
        "unclassifiedOutflowCount": {"type": "integer", "minimum": 0},
        "correctionCount": {"type": "integer", "minimum": 0}
      },
      "additionalProperties": false
    },
    "snapshot": {"$ref": "#/$defs/snapshot"},
    "routes": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "items": {"$ref": "#/$defs/route"}
    },
    "venueSnapshot": {"type": "object"},
    "claims": {
      "type": "array",
      "items": {"$ref": "#/$defs/claim"}
    },
    "usesAndOutcomes": {
      "type": "array",
      "items": {"$ref": "#/$defs/useOutcome"}
    },
    "evidenceBoundary": {"type": "object"}
  },
  "$defs": {
    "decimal": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.[0-9]+$"
    },
    "address": {
      "type": "string",
      "pattern": "^0x[0-9a-fA-F]{40}$"
    },
    "hash": {
      "type": "string",
      "pattern": "^0x[0-9a-fA-F]{64}$"
    },
    "snapshot": {
      "type": "object",
      "required": ["blockNumber", "blockHash", "blockTimestamp", "observedAt", "rpc", "deadAddress"],
      "properties": {
        "blockNumber": {"type": "integer", "minimum": 1},
        "blockHash": {"$ref": "#/$defs/hash"},
        "blockTimestamp": {"type": "string", "format": "date-time"},
        "observedAt": {"type": "string", "format": "date-time"},
        "rpc": {"type": "string", "format": "uri"},
        "deadAddress": {"$ref": "#/$defs/deadAddress"}
      },
      "additionalProperties": false
    },
    "deadAddress": {
      "type": "object",
      "required": ["address", "buyBalance", "shareOfOriginalSupplyPercent", "erc20TotalSupply", "explorerUrl", "marketValueEstimate"],
      "properties": {
        "address": {"$ref": "#/$defs/address"},
        "buyBalance": {"$ref": "#/$defs/decimal"},
        "shareOfOriginalSupplyPercent": {"$ref": "#/$defs/decimal"},
        "erc20TotalSupply": {"$ref": "#/$defs/decimal"},
        "explorerUrl": {"type": "string", "format": "uri"},
        "marketValueEstimate": {"$ref": "#/$defs/marketValueEstimate"}
      },
      "additionalProperties": false
    },
    "marketValueEstimate": {
      "type": "object",
      "required": ["classification", "quoteCurrency", "estimatedAmount", "unitPriceUsd", "priceObservedAt", "balanceConfirmedAtBlock", "balanceConfirmedAt", "source", "method", "limitation"],
      "properties": {
        "classification": {"const": "NOTIONAL_SPOT_ESTIMATE"},
        "quoteCurrency": {"const": "USD"},
        "estimatedAmount": {"$ref": "#/$defs/decimal"},
        "unitPriceUsd": {"$ref": "#/$defs/decimal"},
        "priceObservedAt": {"type": "string", "format": "date-time"},
        "balanceConfirmedAtBlock": {"type": "integer", "minimum": 1},
        "balanceConfirmedAt": {"type": "string", "format": "date-time"},
        "source": {"$ref": "#/$defs/marketValueSource"},
        "method": {"type": "string", "minLength": 1},
        "limitation": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "marketValueSource": {
      "type": "object",
      "required": ["provider", "poolAddress", "marketUrl", "apiUrl"],
      "properties": {
        "provider": {"const": "GeckoTerminal"},
        "poolAddress": {"$ref": "#/$defs/address"},
        "marketUrl": {"type": "string", "format": "uri"},
        "apiUrl": {"type": "string", "format": "uri"}
      },
      "additionalProperties": false
    },
    "route": {
      "type": "object",
      "required": ["routeId", "label", "sharePercent", "recipient", "receivedSinceActivation", "observedBalances", "openingOrOtherNetWeth", "receiptedUse", "verifiedOutcome", "reconciliationStatus", "reconciliationNote"],
      "properties": {
        "routeId": {"type": "string"},
        "label": {"type": "string"},
        "sharePercent": {"type": "integer", "minimum": 0, "maximum": 100},
        "recipient": {"$ref": "#/$defs/address"},
        "receivedSinceActivation": {"type": "object"},
        "observedBalances": {"type": "array"},
        "openingOrOtherNetWeth": {"anyOf": [{"$ref": "#/$defs/decimal"}, {"type": "null"}]},
        "receiptedUse": {"type": ["object", "null"]},
        "verifiedOutcome": {"type": ["object", "null"]},
        "reconciliationStatus": {"enum": ["RECONCILED", "PARTIAL", "UNAVAILABLE"]},
        "reconciliationNote": {"type": "string"}
      },
      "additionalProperties": false
    },
    "claim": {
      "type": "object",
      "required": ["eventType", "transactionHash", "blockNumber", "timestamp", "wethRouted", "buySentToDead", "routeAmounts"],
      "properties": {
        "eventType": {"const": "CLAIM"},
        "transactionHash": {"$ref": "#/$defs/hash"},
        "blockNumber": {"type": "integer", "minimum": 1},
        "timestamp": {"type": "string", "format": "date-time"},
        "wethRouted": {"$ref": "#/$defs/decimal"},
        "buySentToDead": {"$ref": "#/$defs/decimal"},
        "routeAmounts": {"type": "object", "minProperties": 5, "maxProperties": 5}
      },
      "additionalProperties": false
    },
    "useOutcome": {
      "type": "object",
      "required": ["eventType", "classification", "routeId", "transactionHash", "blockNumber", "timestamp", "input", "output"],
      "properties": {
        "eventType": {"enum": ["USE", "OUTCOME", "UNCLASSIFIED", "CORRECTION"]},
        "classification": {"type": "string"},
        "routeId": {"type": "string"},
        "transactionHash": {"$ref": "#/$defs/hash"},
        "linkedTransactionHashes": {"type": "array", "items": {"$ref": "#/$defs/hash"}},
        "blockNumber": {"type": "integer", "minimum": 1},
        "timestamp": {"type": "string", "format": "date-time"},
        "input": {"type": "object"},
        "output": {"type": ["object", "null"]},
        "claimTransactionHash": {"anyOf": [{"$ref": "#/$defs/hash"}, {"type": "null"}]},
        "destination": {"$ref": "#/$defs/address"},
        "note": {"type": "string"}
      },
      "additionalProperties": false
    }
  }
}
