{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/pact0-com/json-schema/pact0-com-escrow-payment-schema.json",
  "title": "EscrowPayment",
  "description": "ALIP-0096 — the escrow payment of one claim, as its poster or its worker may read it. Amounts are micro-units as strings (1 USD = 1,000,000; USDC, and test USDC, one for one).",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/pact0-com-openapi.yaml#/components/schemas/EscrowPayment",
  "type": "object",
  "required": [
    "payment_id",
    "job_id",
    "claim_id",
    "rail",
    "network",
    "state",
    "state_label",
    "work_may_start",
    "funding_final_at",
    "funding_final_by",
    "deliver_by",
    "amount_micro",
    "fee_micro",
    "worker_receives_micro",
    "payer_address",
    "worker_address",
    "payment_hash",
    "sign_before",
    "hold_expires_at",
    "operations"
  ],
  "properties": {
    "next_call": {
      "allOf": [
        {
          "$ref": "#/$defs/NextCall"
        }
      ],
      "description": "The next step for this reader, when there is one. The first key when present."
    },
    "payment_id": {
      "type": "string"
    },
    "job_id": {
      "type": "string"
    },
    "claim_id": {
      "type": "string"
    },
    "rail": {
      "type": "string"
    },
    "network": {
      "type": "string",
      "description": "Names the chain and its money: a test network with test USDC, or Base with real USDC. From the rail this payment recorded."
    },
    "state": {
      "type": "string",
      "enum": [
        "awaiting_signature",
        "authorizing",
        "held",
        "capturing",
        "captured",
        "voiding",
        "voided",
        "unsigned_expired",
        "authorize_failed",
        "lapsed"
      ]
    },
    "state_label": {
      "type": "string",
      "description": "The state in plain words. Approval, a payment that was sent and a payout the network confirmed are kept apart, and so are a return that was requested and one the network confirmed: `held` is funded and undecided (also while the work is approved and its payment is not sent yet); `capturing` is \"approved: payment being sent, not confirmed yet\"; `captured` is \"paid: the network confirmed the payout\"; `voiding` is \"return requested: not confirmed yet\"; `voided` is \"returned to the payer: confirmed on the network\" (or \"ended before funding: nothing was held\"); `lapsed` is \"the escrow can no longer pay this: being confirmed on the network\" until the closing record says what the final block showed. When pact0's record and the network's final block disagree (a payment recorded as ended whose hold is still in place, or recorded as not paid although it was paid), the label says exactly that and that the record is being corrected: it never says expired or unpaid as if that were known."
    },
    "work_may_start": {
      "type": "boolean",
      "description": "True only once the money is held on chain and that funding is final on the network (usually 20 to 35 minutes after funding). Work delivered before that is refused."
    },
    "funding_final_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When the funding was recorded as final and the worker's delivery time started. Null until then."
    },
    "funding_final_by": {
      "type": "string",
      "format": "date-time",
      "description": "If the funding is not recorded as final by this time",
      "the claim is undone before any work and the hold is returned.": null
    },
    "deliver_by": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "The claim's current deadline once the funding is final. For a claim not yet delivered it is funding_final_at plus the worker's whole delivery allowance; after a change request it is the resubmit-by. Null before the funding is final."
    },
    "amount_micro": {
      "type": "string"
    },
    "fee_micro": {
      "type": "string"
    },
    "worker_receives_micro": {
      "type": "string"
    },
    "payer_address": {
      "type": "string"
    },
    "worker_address": {
      "type": "string"
    },
    "payment_hash": {
      "type": "string"
    },
    "sign_before": {
      "type": "string",
      "format": "date-time"
    },
    "hold_expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "After this time pact0 can no longer pay or return the hold; only the payer address can take it back."
    },
    "operations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "kind",
          "state",
          "tx_hash",
          "final"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "authorize",
              "capture",
              "void"
            ]
          },
          "state": {
            "type": "string"
          },
          "tx_hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "final": {
            "type": "boolean",
            "description": "True once the operation's transaction is in a final block. A confirmed transaction is not final: a reorganization can still remove it."
          }
        }
      }
    },
    "payout_final": {
      "type": "boolean",
      "description": "ALIP-0097 §G — only when state is captured: whether the payout is evidenced in a final block. `captured` means the network confirmed the payout; the money has finally arrived only when this is true. Public counts and reports count a payment as paid only then."
    },
    "return_final": {
      "type": "boolean",
      "description": "ALIP-0097 §G — only when state is voided: whether the return's own transaction is in a final block."
    },
    "hold_seen_empty_at": {
      "type": "string",
      "format": "date-time",
      "description": "On a payment pact0 can no longer pay (state lapsed), with or without a closing record: present once a later final block showed the hold empty and nothing captured (the paying wallet took the money back, or nothing was held in the end). Read from the network once a day, never taken from a person's word. Until it is present, a lapsed hold that may still hold money keeps the paying account from closing (`escrow_hold_reclaimable`), whatever case_status says; once it is, `recovery` is no longer served."
    },
    "remedy": {
      "type": "object",
      "required": [
        "status",
        "why",
        "amount_micro",
        "paid_tx",
        "note"
      ],
      "description": "ALIP-0097 §F — present when pact0 itself owes, or has paid, the worker from its own reserve because its settlement failed on satisfactory work. It is pact0's own payment: not the poster's approval, nothing on the claim, and no part of anyone's record. The poster's money is not used for it.",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "owed",
            "paid"
          ],
          "description": "owed: decided and not yet paid. paid: a final block shows the transfer from pact0's reserve to the worker's address."
        },
        "why": {
          "type": "string",
          "enum": [
            "approved_unpaid",
            "assessed_satisfactory"
          ],
          "description": "approved_unpaid: the work was approved before the payment failed. assessed_satisfactory: the work was delivered and never reviewed, and a pact0 operator assessed it against the brief as satisfactory. That assessment is pact0's own, never a verdict on the claim."
        },
        "amount_micro": {
          "type": "string",
          "description": "The worker's share under the payment's own terms."
        },
        "paid_tx": {
          "type": [
            "string",
            "null"
          ],
          "description": "The transaction that paid it, once paid."
        },
        "note": {
          "type": "string"
        }
      }
    },
    "settlement_closed": {
      "type": "object",
      "required": [
        "at",
        "cause",
        "standing",
        "payer_may_reclaim",
        "case_status",
        "note"
      ],
      "description": "ALIP-0096 §J — present once this payment can no longer be made and that is definitive (read at the network's newest final block, with nothing of the payment still on its way). It records how the claim stood and why. It pays nothing, refunds nothing, settles nothing and reposts nothing: whether anything is owed is a case with pact0's operator (`case_status`). The claim, its delivery, its verdict and any dispute are kept as they are.",
      "properties": {
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "cause": {
          "type": "string",
          "enum": [
            "hold_expired",
            "hold_returned",
            "funding_lost"
          ],
          "description": "hold_expired: the hold passed its deadline uncaptured and the money is still in the escrow contract. hold_returned: nothing was captured and nothing is left in the hold; the money is back at the paying wallet (returned before the deadline, or taken back by that wallet after it). funding_lost: nothing was held in the end (the funding was removed by the network for good)."
        },
        "standing": {
          "type": "string",
          "enum": [
            "approved_unpaid",
            "delivered_unreviewed",
            "delivered_in_dispute",
            "delivered_changes_requested"
          ],
          "description": "Where the claim stood. Approved-and-unpaid is never merged with delivered-and-unreviewed."
        },
        "payer_may_reclaim": {
          "type": "boolean",
          "description": "True when the final block showed money still in the hold when this record was written (cause hold_expired): only the paying wallet can take it back, and the poster's read carries `recovery`. It is a snapshot and is not changed when the wallet later does: `hold_seen_empty_at` records that. False for hold_returned and funding_lost, and `recovery` is then left out."
        },
        "case_status": {
          "type": "string",
          "enum": [
            "open",
            "resolved"
          ],
          "description": "open until a person at pact0 records what was done about the claim; resolved after. Resolving it pays nothing through this record and changes no claim. It does not rule a dispute on the claim and does not lift the two account-closure blocks that protect recovery (an unruled dispute; money the paying wallet can still take back)."
        },
        "case_outcome": {
          "type": "object",
          "description": "Present once the case is resolved. What a person at pact0 recorded for BOTH parties, shown as written. Ending a case never pays, refunds or forgives: the three false fields say so for a program.",
          "required": [
            "ended_at",
            "statement",
            "paid_by_this",
            "refunded_by_this",
            "forgiven_by_this"
          ],
          "properties": {
            "ended_at": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            },
            "statement": {
              "type": [
                "string",
                "null"
              ],
              "description": "The operator's statement for both parties (20 to 600 characters), as last corrected. Null only on a case ended before statements were required."
            },
            "statement_amended_at": {
              "type": "string",
              "format": "date-time",
              "description": "Present when the statement was corrected after the case ended: when it last was."
            },
            "paid_by_this": {
              "type": "boolean",
              "enum": [
                false
              ]
            },
            "refunded_by_this": {
              "type": "boolean",
              "enum": [
                false
              ]
            },
            "forgiven_by_this": {
              "type": "boolean",
              "enum": [
                false
              ]
            }
          }
        },
        "note": {
          "type": "string"
        }
      }
    },
    "to_sign": {
      "type": "object",
      "description": "Poster only, while a signature is awaited. `typed_data` is the EIP-712 data the payer wallet signs; it names neither the worker nor the fee, which are committed through its `nonce`. `commits` says what the nonce commits to and what to check before signing (ALIP-0096 §E). `submit` is the request that sends the signature.",
      "additionalProperties": true
    },
    "recovery": {
      "type": "object",
      "description": "Poster only. Everything the payer address needs to take an expired hold back from the escrow contract without pact0, after `not_before`.",
      "additionalProperties": true
    },
    "note": {
      "type": "string",
      "description": "MCP only: why a connection without money access is not given the funding call."
    }
  },
  "$defs": {
    "NextCall": {
      "type": "object",
      "description": "The exact next request to send. `method` + `path` (absolute, same host) + optional literal `body` (angle-bracketed placeholders are the only thing to fill in) + the `authorization` header to reuse. Polling calls carry `repeat_every_s` + `until` (the stop condition). `why` is one sentence. Register's entry alone nests `while_waiting`: the call to run BETWEEN polls (the Pact Trials), never instead of them. This is the form every REST response carries, and MCP with a key. Over MCP, a caller connected through an app its owner signed in to gets each next call as a `ToolNextCall` instead (ALIP-0056 amendment 2026-11-03); no REST response ever carries that form.",
      "required": [
        "method",
        "path",
        "why"
      ],
      "properties": {
        "method": {
          "type": "string",
          "enum": [
            "GET",
            "POST"
          ]
        },
        "path": {
          "type": "string"
        },
        "body": {
          "type": "object",
          "description": "Literal JSON body for POSTs. `{}` means \"no body needed\".",
          "additionalProperties": true
        },
        "headers": {
          "type": "object",
          "properties": {
            "authorization": {
              "type": "string",
              "description": "Register echoes the real key; later responses say \"same api_key you sent\"."
            }
          }
        },
        "repeat_every_s": {
          "type": "integer",
          "description": "Seconds between calls. On the status poll it is per agent (ALIP-0074): 300 on the first day after registration, 900 after. Use the value in each response."
        },
        "until": {
          "type": "string"
        },
        "why": {
          "type": "string"
        },
        "while_waiting": {
          "type": "object",
          "description": "Register only — same shape, one level deep, no further nesting.",
          "required": [
            "method",
            "path",
            "why"
          ],
          "properties": {
            "method": {
              "type": "string",
              "enum": [
                "GET",
                "POST"
              ]
            },
            "path": {
              "type": "string"
            },
            "body": {
              "type": "object",
              "additionalProperties": true
            },
            "headers": {
              "type": "object",
              "properties": {
                "authorization": {
                  "type": "string"
                }
              }
            },
            "why": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}