{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.northset.ai/artifacts/schemas/receipt-bundle-v1.schema.json",
  "title": "Northset public settlement receipt bundle",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "chain", "hub", "task", "transactions", "taskCompleted", "stats", "economics"],
  "properties": {
    "schema": { "const": "northset.receiptBundle.v1" },
    "chain": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "id"],
      "properties": {
        "name": { "const": "Arbitrum One" },
        "id": { "const": 42161 }
      }
    },
    "hub": { "$ref": "#/$defs/address" },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": ["taskId", "state", "stateCode", "specHash", "verifierId", "verifier", "inputHash", "outputHash"],
      "properties": {
        "taskId": { "$ref": "#/$defs/uint256String" },
        "state": { "const": "COMPLETED" },
        "stateCode": { "const": 3 },
        "specHash": { "$ref": "#/$defs/bytes32" },
        "verifierId": { "$ref": "#/$defs/bytes32" },
        "verifier": { "$ref": "#/$defs/address" },
        "inputHash": { "$ref": "#/$defs/bytes32" },
        "outputHash": { "$ref": "#/$defs/bytes32" }
      }
    },
    "transactions": {
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/transaction" },
      "required": ["created", "selected", "activated", "completed"]
    },
    "taskCompleted": {
      "type": "object",
      "additionalProperties": false,
      "required": ["transactionHash", "blockNumber", "blockTimestamp", "logIndex", "topic0", "indexedTaskId", "indexedDelegatee", "outputHash", "publicValues", "outputURI", "rawData"],
      "properties": {
        "transactionHash": { "$ref": "#/$defs/bytes32" },
        "blockNumber": { "$ref": "#/$defs/safeUnsignedInteger" },
        "blockTimestamp": { "type": "string", "format": "date-time" },
        "logIndex": { "$ref": "#/$defs/safeUnsignedInteger" },
        "topic0": { "$ref": "#/$defs/bytes32" },
        "indexedTaskId": { "$ref": "#/$defs/uint256String" },
        "indexedDelegatee": { "$ref": "#/$defs/address" },
        "outputHash": { "$ref": "#/$defs/bytes32" },
        "publicValues": { "type": "string", "pattern": "^0x[0-9a-fA-F]+$" },
        "outputURI": { "type": "string", "minLength": 1 },
        "rawData": { "type": "string", "pattern": "^0x[0-9a-fA-F]+$" }
      }
    },
    "stats": {
      "type": "object",
      "additionalProperties": false,
      "required": ["values", "n", "sum", "min", "max"],
      "properties": {
        "values": { "type": "array", "items": { "$ref": "#/$defs/uint64String" }, "maxItems": 4096 },
        "n": { "type": "integer", "minimum": 0, "maximum": 4096 },
        "sum": { "$ref": "#/$defs/uint256String" },
        "min": { "$ref": "#/$defs/uint64String" },
        "max": { "$ref": "#/$defs/uint64String" }
      }
    },
    "economics": {
      "type": "object",
      "additionalProperties": false,
      "required": ["creationEscrowUSDC", "selectionRefundUSDC", "selectedRewardUSDC", "activationBondUSDC", "feeUSDC", "netRewardUSDC", "completionPayoutUSDC"],
      "properties": {
        "creationEscrowUSDC": { "$ref": "#/$defs/uint256String" },
        "selectionRefundUSDC": { "$ref": "#/$defs/uint256String" },
        "selectedRewardUSDC": { "$ref": "#/$defs/uint256String" },
        "activationBondUSDC": { "$ref": "#/$defs/uint256String" },
        "feeUSDC": { "$ref": "#/$defs/uint256String" },
        "netRewardUSDC": { "$ref": "#/$defs/uint256String" },
        "completionPayoutUSDC": { "$ref": "#/$defs/uint256String" }
      }
    }
  },
  "$defs": {
    "address": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
    "bytes32": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
    "uint64String": { "type": "string", "pattern": "^(?:0|[1-9][0-9]{0,18}|1(?:[0-7][0-9]{18}|8(?:[0-3][0-9]{17}|4(?:[0-3][0-9]{16}|4(?:[0-5][0-9]{15}|6(?:[0-6][0-9]{14}|7(?:[0-3][0-9]{13}|4(?:[0-3][0-9]{12}|40(?:[0-6][0-9]{10}|7(?:[0-2][0-9]{9}|3(?:[0-6][0-9]{8}|70(?:[0-8][0-9]{6}|9(?:[0-4][0-9]{5}|5(?:[0-4][0-9]{4}|5(?:0[0-9]{3}|1(?:[0-5][0-9]{2}|6(?:0[0-9]{1}|1(?:[0-4]|5))))))))))))))))))$", "maxLength": 20 },
    "uint256String": { "type": "string", "pattern": "^(?:0|[1-9][0-9]{0,76}|1(?:0[0-9]{76}|1(?:[0-4][0-9]{75}|5(?:[0-6][0-9]{74}|7(?:[0-8][0-9]{73}|9(?:[0-1][0-9]{72}|20(?:[0-7][0-9]{70}|8(?:[0-8][0-9]{69}|9(?:[0-1][0-9]{68}|2(?:[0-2][0-9]{67}|3(?:[0-6][0-9]{66}|7(?:[0-2][0-9]{65}|3(?:0[0-9]{64}|1(?:[0-5][0-9]{63}|6(?:0[0-9]{62}|1(?:[0-8][0-9]{61}|9(?:[0-4][0-9]{60}|5(?:[0-3][0-9]{59}|4(?:[0-1][0-9]{58}|2(?:[0-2][0-9]{57}|3(?:[0-4][0-9]{56}|5(?:[0-6][0-9]{55}|70(?:[0-8][0-9]{53}|9(?:[0-7][0-9]{52}|8(?:[0-4][0-9]{51}|500(?:[0-7][0-9]{48}|8(?:[0-5][0-9]{47}|6(?:[0-7][0-9]{46}|8(?:[0-6][0-9]{45}|7(?:[0-8][0-9]{44}|90(?:[0-6][0-9]{42}|7(?:[0-7][0-9]{41}|8(?:[0-4][0-9]{40}|5(?:[0-2][0-9]{39}|3(?:[0-1][0-9]{38}|2(?:[0-5][0-9]{37}|6(?:[0-8][0-9]{36}|9(?:[0-8][0-9]{35}|9(?:[0-7][0-9]{34}|8(?:[0-3][0-9]{33}|4(?:[0-5][0-9]{32}|6(?:[0-5][0-9]{31}|6(?:[0-4][0-9]{30}|5(?:[0-5][0-9]{29}|6(?:[0-3][0-9]{28}|40(?:[0-4][0-9]{26}|5(?:[0-5][0-9]{25}|6(?:[0-3][0-9]{24}|40(?:[0-2][0-9]{22}|3(?:[0-8][0-9]{21}|9(?:[0-3][0-9]{20}|4(?:[0-4][0-9]{19}|5(?:[0-6][0-9]{18}|7(?:[0-4][0-9]{17}|5(?:[0-7][0-9]{16}|8(?:[0-3][0-9]{15}|400(?:[0-6][0-9]{12}|7(?:[0-8][0-9]{11}|9(?:0[0-9]{10}|1(?:[0-2][0-9]{9}|3(?:0[0-9]{8}|1(?:[0-1][0-9]{7}|2(?:[0-8][0-9]{6}|9(?:[0-5][0-9]{5}|6(?:[0-2][0-9]{4}|3(?:[0-8][0-9]{3}|9(?:[0-8][0-9]{2}|9(?:[0-2][0-9]{1}|3(?:[0-4]|5)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))$", "maxLength": 78 },
    "safeUnsignedInteger": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
    "transaction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["transactionHash", "blockNumber"],
      "properties": {
        "transactionHash": { "$ref": "#/$defs/bytes32" },
        "blockNumber": { "$ref": "#/$defs/safeUnsignedInteger" }
      }
    }
  }
}
