{
  "$comment": "SPDX-License-Identifier: MIT",
  "$id": "https://spec.vaultfire.local/v3-open/1.0.0/bond-state.v1.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "bondId": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "definition": {
      "type": "object"
    },
    "definitionDigest": {
      "pattern": "^0x[0-9a-f]{64}$",
      "type": "string"
    },
    "exitAvailableAt": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "exitCallableWhilePaused": {
      "type": "boolean"
    },
    "invariants": {
      "additionalProperties": false,
      "properties": {
        "boundedPauseSafeExitRequired": {
          "const": true
        },
        "explicitConsentRequired": {
          "const": true
        },
        "flourishingCanSlashPrincipal": {
          "const": false
        },
        "rewardsCanConsumeCollateral": {
          "const": false
        },
        "surveillancePermittedForProtectedDecisions": {
          "const": false
        }
      },
      "required": [
        "flourishingCanSlashPrincipal",
        "rewardsCanConsumeCollateral",
        "surveillancePermittedForProtectedDecisions",
        "explicitConsentRequired",
        "boundedPauseSafeExitRequired"
      ],
      "type": "object"
    },
    "kind": {
      "enum": [
        "accountability",
        "partnership"
      ]
    },
    "lockedPrincipal": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "observedAt": {
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
      "type": "string"
    },
    "paused": {
      "type": "boolean"
    },
    "principalFunded": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "principalLiability": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "principalWithdrawn": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "protocolVersion": {
      "const": "3.0.0"
    },
    "pullCredits": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "amount": {
            "pattern": "^(0|[1-9][0-9]*)$",
            "type": "string"
          },
          "holder": {
            "pattern": "^0x[0-9a-f]{40}$",
            "type": "string"
          }
        },
        "required": [
          "holder",
          "amount"
        ],
        "type": "object"
      },
      "maxItems": 32,
      "minItems": 0,
      "type": "array",
      "uniqueItems": true
    },
    "refundablePrincipal": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "rewardBalance": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "rewardFunded": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "schema": {
      "const": "vaultfire.v3.open.bond-state.v1"
    },
    "schemaVersion": {
      "const": "1.0.0"
    },
    "slashedPrincipal": {
      "pattern": "^(0|[1-9][0-9]*)$",
      "type": "string"
    },
    "state": {
      "enum": [
        "Uninitialized",
        "Proposed",
        "Accepted",
        "Funded",
        "Active",
        "SettlementRequested",
        "Finalizable",
        "Challenged",
        "SettlementFrozen",
        "Settled",
        "Cancelled",
        "Expired",
        "ForceExited"
      ]
    },
    "timeoutResolution": {
      "additionalProperties": false,
      "properties": {
        "acceptedEvidenceAt": {
          "pattern": "^(0|[1-9][0-9]*)$",
          "type": "string"
        },
        "canonicalBreachStillExists": {
          "type": "boolean"
        },
        "canonicalRevalidatedAt": {
          "pattern": "^(0|[1-9][0-9]*)$",
          "type": "string"
        },
        "outcome": {
          "enum": [
            "settled-liability",
            "full-refund"
          ]
        },
        "sameTimestampRevalidation": {
          "const": true
        }
      },
      "required": [
        "acceptedEvidenceAt",
        "canonicalRevalidatedAt",
        "sameTimestampRevalidation",
        "canonicalBreachStillExists",
        "outcome"
      ],
      "type": [
        "object",
        "null"
      ]
    },
    "transitionHistory": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "at": {
            "pattern": "^(0|[1-9][0-9]*)$",
            "type": "string"
          },
          "eventDigest": {
            "pattern": "^0x[0-9a-f]{64}$",
            "type": "string"
          },
          "from": {
            "type": "string"
          },
          "mode": {
            "enum": [
              "ordinary",
              "accepted-liability-timeout",
              "timeout-refund"
            ]
          },
          "to": {
            "type": "string"
          }
        },
        "required": [
          "from",
          "to",
          "at",
          "eventDigest"
        ],
        "type": "object"
      },
      "maxItems": 64,
      "minItems": 1,
      "type": "array",
      "uniqueItems": false
    }
  },
  "required": [
    "schema",
    "schemaVersion",
    "protocolVersion",
    "kind",
    "bondId",
    "state",
    "definition",
    "definitionDigest",
    "transitionHistory",
    "principalFunded",
    "principalLiability",
    "lockedPrincipal",
    "principalWithdrawn",
    "rewardFunded",
    "rewardBalance",
    "refundablePrincipal",
    "slashedPrincipal",
    "paused",
    "exitAvailableAt",
    "exitCallableWhilePaused",
    "pullCredits",
    "observedAt",
    "invariants",
    "timeoutResolution"
  ],
  "type": "object"
}
