Skip to content

Commit 3e63fa5

Browse files
Merge pull request #105 from engineeredsoftware/v36/gate-6-exchange-settlement-reconciliation
V36 Gate 6: Exchange Settlement Ledger Database Reconciliation
2 parents 40f6ae8 + 8ea69e5 commit 3e63fa5

19 files changed

Lines changed: 2637 additions & 4 deletions

.bitcode/v36-exchange-settlement-reconciliation.json

Lines changed: 1490 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/bitcode-canon-quality.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ jobs:
8585
if [ -f scripts/check-v36-gate5-exchange-pricing-quote.mjs ]; then
8686
node scripts/check-v36-gate5-exchange-pricing-quote.mjs --skip-branch-check
8787
fi
88+
if [ -f scripts/check-v36-gate6-exchange-settlement-reconciliation.mjs ]; then
89+
node scripts/check-v36-gate6-exchange-settlement-reconciliation.mjs --skip-branch-check
90+
fi
8891
fi
8992
else
9093
echo "Unexpected BITCODE_SPEC.txt pointer: $POINTER" >&2

.github/workflows/bitcode-gate-quality.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ jobs:
213213
if [ -f scripts/check-v36-gate5-exchange-pricing-quote.mjs ]; then
214214
node scripts/check-v36-gate5-exchange-pricing-quote.mjs --skip-branch-check
215215
fi
216+
if [ -f scripts/check-v36-gate6-exchange-settlement-reconciliation.mjs ]; then
217+
node scripts/check-v36-gate6-exchange-settlement-reconciliation.mjs --skip-branch-check
218+
fi
216219
fi
217220
else
218221
echo "Unexpected BITCODE_SPEC.txt pointer: $POINTER" >&2
@@ -272,6 +275,7 @@ jobs:
272275
pnpm --dir packages/protocol exec node --test --test-force-exit test/v36-exchange-intent-order-contracts.test.js
273276
pnpm --dir packages/protocol exec node --test --test-force-exit test/v36-exchange-rights-transfer-review.test.js
274277
pnpm --dir packages/protocol exec node --test --test-force-exit test/v36-exchange-pricing-quote.test.js
278+
pnpm --dir packages/protocol exec node --test --test-force-exit test/v36-exchange-settlement-reconciliation.test.js
275279
pnpm --filter @bitcode/api exec jest --config jest.config.cjs --runTestsByPath src/routes/__tests__/btd-crypto.test.ts --runInBand
276280
pnpm --filter @bitcode/api exec jest --config jest.config.cjs --runTestsByPath src/routes/__tests__/auxillaries-contract.test.ts --runInBand
277281
pnpm --dir packages/executions-mcp/src/mcp-server run test:mcp -- --runTestsByPath src/__tests__/unit/auth.test.ts --runInBand

BITCODE_SPEC_V36.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ Ledger journal state remains stronger than database projection state for quote
149149
roots, settlement admission, payment matching, route allocation, and network
150150
posture.
151151

152+
## V36 Gate 6 ExchangeSettlementReceipt canon
153+
154+
Gate 6 implements `ExchangeSettlementReceipt` as the package-owned settlement
155+
and reconciliation contract for Exchange completion.
156+
`ExchangeSettlementReceipt` binds payment observation, finality state, rights
157+
transfer receipt, ledger root, database projection root, object storage root,
158+
delivery state, repair id, observer jobs, reconciliation decision, proof roots,
159+
and event ids before source-bearing delivery can be trusted.
160+
161+
Gate 6 emits `.bitcode/v36-exchange-settlement-reconciliation.json` with
162+
`source-safe-exchange-settlement-reconciliation-metadata`.
163+
The settlement binding is payment observation, finality state, rights transfer receipt, ledger root, database projection root, object storage root, delivery state, and repair id.
164+
The source-safe receipt may expose settlement identity, payment observation,
165+
finality state, rights-transfer receipt identity, ledger root, database
166+
projection root, object storage root, delivery state, repair id, observer jobs,
167+
proof roots, and event ids; it must not expose protected source, unpaid
168+
AssetPack source, wallet private material, provider tokens, protected prompts,
169+
protected model responses, private payment credentials, private buyer
170+
repository payloads, object-storage private bytes, or secret values.
171+
172+
observers and repair jobs reconcile database projections to ledger truth.
173+
The ledger journal remains stronger than database and object-storage
174+
projections; repair jobs may rewrite projections toward ledger truth but cannot
175+
rewrite ledger truth toward projection convenience.
176+
settlement finality and delivery are auditable.
177+
Delivery stays blocked while finality, rights-transfer receipt, database
178+
projection, or object-storage projection is missing, stale, or drifted.
179+
152180
## Canonical Bitcode executive summary
153181

154182
Bitcode measures technical knowledge, finds deposits that fit reviewed Reads, synthesizes source-bearing AssetPacks, and settles read rights in BTC with BTD range and rights receipts.

BITCODE_SPEC_V36_DELTA.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ Closure acceptance:
126126

127127
- `ExchangeSettlementReceipt` binds payment observation, finality state, rights transfer receipt, ledger root, database projection root, object storage root, delivery state, and repair id;
128128
- observers and repair jobs reconcile database projections to ledger truth;
129-
- settlement finality and delivery are auditable.
129+
- settlement finality and delivery are auditable;
130+
- `.bitcode/v36-exchange-settlement-reconciliation.json` is generated from the package-owned builder with `source-safe-exchange-settlement-reconciliation-metadata`;
131+
- `pnpm run check:v36-gate6` validates package source, artifact freshness, package tests, docs, workflow wiring, payment observation, finality state, rights transfer receipt, ledger root, database projection root, object storage root, delivery state, repair id, observer jobs, repair jobs, projection reconciliation to ledger truth, delivery auditability, source-safety, proof roots, and event ids.
130132

131133
### Gate 7: Dispute Repair Revenue Route Operations
132134

BITCODE_SPEC_V36_NOTES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ the BTD range ledger journal remains the ownership and range identity record.
126126
underpayment, overpayment, stale quote, or unsupported network posture fails closed so settlement cannot continue with mismatched payment, expired price,
127127
or unsupported network state.
128128

129+
## Gate 6 closure notes
130+
131+
Gate 6 closes when `ExchangeSettlementReceipt` is package-owned and generated
132+
through `.bitcode/v36-exchange-settlement-reconciliation.json`.
133+
The generated artifact carries
134+
`source-safe-exchange-settlement-reconciliation-metadata` and binds payment observation, finality state, rights transfer receipt, ledger root, database projection root, object storage root, delivery state, and repair id.
135+
observers and repair jobs reconcile database projections to ledger truth.
136+
settlement finality and delivery are auditable.
137+
Delivery remains blocked until paid finality, rights-transfer receipt,
138+
projection synchronization, object-storage projection, and delivery state are
139+
all source-safe and proof-rooted.
140+
129141
## Accepted boundaries
130142

131143
- V36 owns deeper Exchange.

BITCODE_SPEC_V36_PARITY_MATRIX.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ No `_legacy/` source is active source truth.
5858
| Exchange intent and order contracts | Gate 3 | `ExchangeIntent`, `ExchangeOrder`, `.bitcode/v36-exchange-intent-order-contracts.json`, package source, tests, and `check:v36-gate3` | closed | Buy, sell, bid, ask, cancel, accept, settle, and history transitions are typed, authorized, idempotent, policy-gated, source-safe, and replayable. |
5959
| Rights-transfer review | Gate 4 | `ExchangeRightsTransferPreview`, `.bitcode/v36-exchange-rights-transfer-review.json`, package source, tests, and `check:v36-gate4` | closed | BTD range identity, ownership, buyer, rights scope, disclosure boundary, settlement unlock, owner-read, licensed-read, and blocked transfer states are source-safe. |
6060
| Pricing quote | Gate 5 | `ExchangePricingQuote`, `.bitcode/v36-pricing-liquidity-fee-quote.json`, package source, tests, and `check:v36-gate5` | closed | BTC price, measurement weight, measurement volume, liquidity band, wrapper analysis, treasury/depositor/reader routes, quote roots, and fail-closed payment/network posture are deterministic. |
61-
| Settlement reconciliation | Gate 6 | `ExchangeSettlementReceipt`, `.bitcode/v36-exchange-settlement-reconciliation.json`, observers, repair tests, and `check:v36-gate6` | draft-required | Ledger, database, object storage, finality, delivery, and rights-transfer roots reconcile. |
61+
| Settlement reconciliation | Gate 6 | `ExchangeSettlementReceipt`, `.bitcode/v36-exchange-settlement-reconciliation.json`, observers, repair tests, and `check:v36-gate6` | closed | Payment observation, finality state, rights-transfer receipt, ledger root, database projection root, object storage root, delivery state, repair id, observer jobs, and repair jobs reconcile. |
6262
| Dispute repair revenue routes | Gate 7 | `ExchangeDisputeRepairCase`, `ExchangeRevenueRoute`, `.bitcode/v36-exchange-dispute-repair-revenue-route.json`, tests, and `check:v36-gate7` | draft-required | Disputes, repairs, revenue routes, conservation proofs, runbooks, and escalation paths exist. |
6363
| Exchange UX and Terminal integration | Gate 8 | `/exchange`, Terminal handoff, public docs, telemetry dashboards, `.bitcode/v36-exchange-ux-proof.json`, and `check:v36-gate8` | draft-required | Master-detail UX, source-safe expanded detail, order history, and Terminal navigation are validated. |
6464
| Local staging rehearsal | Gate 9 | `.bitcode/v36-exchange-rehearsal.json`, local/staging logs, proof roots, and `check:v36-gate9` | draft-required | Local and staging-testnet list/bid/ask/cancel/accept/settle/repair/history flows are rehearsed. |
@@ -147,6 +147,18 @@ No `_legacy/` source is active source truth.
147147
| Ledger/database projection posture is explicit | ledger journal refs outrank database projection refs for quote roots, settlement admission, route allocation, and network posture | closed |
148148
| Workflow and package tests are wired | `packages/protocol/test/v36-exchange-pricing-quote.test.js`, `scripts/check-v36-gate5-exchange-pricing-quote.mjs`, `.github/workflows/bitcode-gate-quality.yml` | closed |
149149

150+
## Gate 6 Parity
151+
152+
| Requirement | Source evidence | Current V36 judgment |
153+
| --- | --- | --- |
154+
| `ExchangeSettlementReceipt` is package-owned | `packages/protocol/src/canonical/exchange-settlement-reconciliation.js`, `packages/protocol/src/index.js`, `packages/protocol/src/index.d.ts` | closed |
155+
| Generated settlement artifact exists | `.bitcode/v36-exchange-settlement-reconciliation.json`, `scripts/generate-v36-exchange-settlement-reconciliation.mjs`, `pnpm run check:v36-exchange-settlement-reconciliation` | closed |
156+
| Required settlement fields are covered | payment observation, finality state, rights transfer receipt, ledger root, database projection root, object storage root, delivery state, and repair id | closed |
157+
| Projection reconciliation is explicit | observers and repair jobs reconcile database projections to ledger truth | closed |
158+
| Finality and delivery are auditable | settlement finality and delivery are auditable | closed |
159+
| Settlement payloads are source-safe | `source-safe-exchange-settlement-reconciliation-metadata`; protected source, unpaid AssetPack source, private wallet material, provider tokens, protected prompts, protected model responses, private payment credentials, object-storage private bytes, private buyer payloads, and secret values are forbidden | closed |
160+
| Workflow and package tests are wired | `packages/protocol/test/v36-exchange-settlement-reconciliation.test.js`, `scripts/check-v36-gate6-exchange-settlement-reconciliation.mjs`, `.github/workflows/bitcode-gate-quality.yml` | closed |
161+
150162
## V36 accepted boundaries
151163

152164
- V36 owns deeper Exchange.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ source-safe generated artifact `.bitcode/v36-pricing-liquidity-fee-quote.json`.
4242
The quote covers BTC amount, measurement weight, measurement volume, liquidity band, wrapper analysis, treasury route, depositor route, reader route, and
4343
quote root. The source-safe verdict is
4444
`source-safe-exchange-pricing-quote-metadata`; wrapper analysis cannot make BTD range cells fungible chain-of-record assets, and underpayment, overpayment, stale quote, or unsupported network posture fails closed.
45+
V36 Gate 6 anchors settlement through package-owned `ExchangeSettlementReceipt`
46+
and the source-safe generated artifact
47+
`.bitcode/v36-exchange-settlement-reconciliation.json`.
48+
The receipt binds payment observation, finality state, rights transfer receipt, ledger root, database projection root, object storage root, delivery state, and repair id.
49+
The source-safe verdict is
50+
`source-safe-exchange-settlement-reconciliation-metadata`; observers and repair jobs reconcile database projections to ledger truth, and settlement finality and delivery are auditable.
4551
Promoted V35 closure owns telemetry and documentation depth over promoted V34:
4652
internal codebase docs, public `/docs`, telemetry taxonomy, dashboards, alert
4753
runbooks, incident response, operator escalation, documentation QA, developer

SPECIFICATIONS_ROADMAP.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- Current active canonical pointer: `BITCODE_SPEC.txt` -> `V35`
66
- Current active canon: `BITCODE_SPEC_V35.md`
77
- Current draft target: `BITCODE_SPEC_V36.md`
8-
- Current working gate: V36 Gate 6 Exchange Settlement Ledger Database Reconciliation, following V36 Gate 5 Exchange pricing/liquidity quote closure.
8+
- Current working gate: V36 Gate 7 Dispute Repair Revenue Route Operations, following V36 Gate 6 Exchange settlement reconciliation closure.
99
- Latest closed version: V35 Telemetry And Documentation Depth, which promoted documentation surfaces, telemetry taxonomy, public docs, dashboards, alert runbooks, incident response, operator escalation, documentation QA, onboarding, local/staging telemetry rehearsal, and V35 promotion readiness.
1010
- Recent V35 closure anchor: V35 Gate 10 Promotion Readiness generated V35 proof support, promoted `BITCODE_SPEC.txt` to `V35`, prepared V35 active / V36 draft runtime posture, and closed telemetry/documentation-depth canon.
1111
- V34 Gate 2 closure anchor: deployment-depth now owns package-backed `DeploymentHostCapabilityCatalog` and `EnvironmentLaneContract` source, deterministic `.bitcode/v34-deployment-host-capability-catalog.json` and `.bitcode/v34-environment-lane-contracts.json`, and visible `value-bearing-mainnet` blocking through `blocked_future_canon_required`.
@@ -32,6 +32,7 @@
3232
- V36 Gate 3 closure anchor: Exchange depth now owns package-backed `ExchangeIntent` and `ExchangeOrder` source, deterministic `.bitcode/v36-exchange-intent-order-contracts.json`, `source-safe-exchange-intent-order-contract-metadata`, buy, sell, bid, ask, cancel, accept, settle, and history transition rows, actor principals, organization roles, wallet posture, authority proofs, idempotency keys, policy decisions, fail-closed results, proof roots, event ids, ledger journal refs, database projection refs, package tests, workflow wiring, and `check:v36-gate3`; order history is replayable without private wallet material or secrets.
3333
- V36 Gate 4 closure anchor: Exchange depth now owns package-backed `ExchangeRightsTransferPreview` source, deterministic `.bitcode/v36-exchange-rights-transfer-review.json`, `source-safe-exchange-rights-transfer-review-metadata`, BTD range identity, current owner, requested buyer, rights scope, settlement unlock condition, disclosure limit, owner-read, licensed-read, and blocked transfer preview states, proof roots, event ids, ledger/database projection refs, package tests, workflow wiring, and `check:v36-gate4`; AssetPack source is hidden until paid settlement and rights transfer are complete.
3434
- V36 Gate 5 closure anchor: Exchange depth now owns package-backed `ExchangePricingQuote` source, deterministic `.bitcode/v36-pricing-liquidity-fee-quote.json`, `source-safe-exchange-pricing-quote-metadata`, BTC amount, measurement weight, measurement volume, liquidity band, wrapper analysis, treasury route, depositor route, reader route, quote root, proof roots, event ids, ledger/database projection refs, package tests, workflow wiring, and `check:v36-gate5`; wrapper analysis cannot make BTD range cells fungible chain-of-record assets, and underpayment, overpayment, stale quote, or unsupported network posture fails closed.
35+
- V36 Gate 6 closure anchor: Exchange depth now owns package-backed `ExchangeSettlementReceipt` source, deterministic `.bitcode/v36-exchange-settlement-reconciliation.json`, `source-safe-exchange-settlement-reconciliation-metadata`, payment observation, finality state, rights transfer receipt, ledger root, database projection root, object storage root, delivery state, repair id, observer jobs, repair jobs, proof roots, event ids, package tests, workflow wiring, and `check:v36-gate6`; observers and repair jobs reconcile database projections to ledger truth, and settlement finality and delivery are auditable.
3536
- Purpose: concise running index of Bitcode/ENGI specification history, current work, and planned work.
3637

3738
This roadmap is not an active system specification.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@
197197
"generate:v36-exchange-pricing-quote": "node scripts/generate-v36-exchange-pricing-quote.mjs",
198198
"check:v36-exchange-pricing-quote": "node scripts/generate-v36-exchange-pricing-quote.mjs --check",
199199
"check:v36-gate5": "node scripts/check-v36-gate5-exchange-pricing-quote.mjs",
200+
"generate:v36-exchange-settlement-reconciliation": "node scripts/generate-v36-exchange-settlement-reconciliation.mjs",
201+
"check:v36-exchange-settlement-reconciliation": "node scripts/generate-v36-exchange-settlement-reconciliation.mjs --check",
202+
"check:v36-gate6": "node scripts/check-v36-gate6-exchange-settlement-reconciliation.mjs",
200203
"check:spec-quality": "node scripts/run-bitcode-spec-quality.mjs --mode basic",
201204
"check:spec-quality:title": "node scripts/run-bitcode-spec-quality.mjs --mode strict-from-title",
202205
"check:spec-quality:v24": "node scripts/run-bitcode-spec-quality.mjs --mode strict-version --version V24",

0 commit comments

Comments
 (0)