@ottochain/sdk 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/dist/cjs/apps/compute/index.js +33 -0
  2. package/dist/cjs/apps/compute/state-machines/compute-rule110.js +164 -0
  3. package/dist/cjs/apps/compute/state-machines/index.js +9 -0
  4. package/dist/cjs/apps/contracts/index.js +1 -1
  5. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +126 -148
  6. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +153 -174
  7. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
  8. package/dist/cjs/apps/corporate/state-machines/corp-board.js +415 -481
  9. package/dist/cjs/apps/corporate/state-machines/corp-entity.js +368 -440
  10. package/dist/cjs/apps/corporate/state-machines/corp-securities.js +532 -647
  11. package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +499 -603
  12. package/dist/cjs/apps/governance/index.js +7 -7
  13. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +170 -209
  14. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +161 -214
  15. package/dist/cjs/apps/governance/state-machines/dao-single.js +92 -92
  16. package/dist/cjs/apps/governance/state-machines/dao-token.js +169 -223
  17. package/dist/cjs/apps/governance/state-machines/governance-simple.js +185 -217
  18. package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
  19. package/dist/cjs/apps/identity/constants.js +16 -24
  20. package/dist/cjs/apps/identity/index.js +1 -1
  21. package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
  22. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +151 -169
  23. package/dist/cjs/apps/identity/state-machines/identity-registry.js +89 -115
  24. package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
  25. package/dist/cjs/apps/index.js +4 -1
  26. package/dist/cjs/apps/lending/assets.js +41 -17
  27. package/dist/cjs/apps/lending/credit-scoring.js +4 -4
  28. package/dist/cjs/apps/lending/eligibility.js +9 -25
  29. package/dist/cjs/apps/lending/index.js +1 -1
  30. package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +177 -156
  31. package/dist/cjs/apps/markets/index.js +1 -1
  32. package/dist/cjs/apps/markets/state-machines/market-auction.js +115 -134
  33. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +122 -137
  34. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +158 -177
  35. package/dist/cjs/apps/markets/state-machines/market-prediction.js +193 -227
  36. package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
  37. package/dist/cjs/apps/oracles/index.js +1 -1
  38. package/dist/cjs/apps/privacy/index.js +67 -0
  39. package/dist/cjs/apps/privacy/state-machines/index.js +17 -0
  40. package/dist/cjs/apps/privacy/state-machines/mixer-ddhRing.js +286 -0
  41. package/dist/cjs/apps/privacy/state-machines/note-pool.js +476 -0
  42. package/dist/cjs/apps/staked-pool/assets.js +103 -0
  43. package/dist/cjs/apps/staked-pool/base.js +498 -0
  44. package/dist/cjs/apps/staked-pool/consumer.js +55 -0
  45. package/dist/cjs/apps/staked-pool/index.js +83 -0
  46. package/dist/cjs/apps/staked-pool/state-machines/index.js +12 -0
  47. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-base.js +49 -0
  48. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-oracle.js +131 -0
  49. package/dist/cjs/generated/google/protobuf/struct.js +1 -1
  50. package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
  51. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +1 -1
  52. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  53. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +1 -1
  54. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  55. package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +1 -1
  56. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +1 -1
  57. package/dist/cjs/generated/ottochain/v1/common.js +1 -1
  58. package/dist/cjs/generated/ottochain/v1/fiber.js +40 -2
  59. package/dist/cjs/generated/ottochain/v1/messages.js +1 -1
  60. package/dist/cjs/generated/ottochain/v1/records.js +1 -1
  61. package/dist/cjs/index.js +20 -3
  62. package/dist/cjs/ottochain/genesis-manifest.js +6 -0
  63. package/dist/cjs/ottochain/metagraph-client.js +16 -8
  64. package/dist/cjs/ottochain/snapshot.js +2 -4
  65. package/dist/cjs/ottochain/transaction.js +10 -0
  66. package/dist/cjs/privacy/sealed-bid.js +85 -82
  67. package/dist/cjs/privacy/shield-app.js +32 -32
  68. package/dist/cjs/schema/effects.js +117 -1
  69. package/dist/cjs/schema/fiber-app.js +132 -3
  70. package/dist/cjs/schema/guard-lint.js +3 -12
  71. package/dist/cjs/schema/guards.js +38 -38
  72. package/dist/cjs/templates/asset-policy.js +190 -0
  73. package/dist/cjs/templates/index.js +86 -0
  74. package/dist/cjs/templates/machine.js +130 -0
  75. package/dist/cjs/templates/migration.js +39 -0
  76. package/dist/cjs/templates/state-shape.js +38 -0
  77. package/dist/cjs/validation.js +1 -3
  78. package/dist/esm/apps/compute/index.js +29 -0
  79. package/dist/esm/apps/compute/state-machines/compute-rule110.js +161 -0
  80. package/dist/esm/apps/compute/state-machines/index.js +5 -0
  81. package/dist/esm/apps/contracts/index.js +4 -4
  82. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +128 -150
  83. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +155 -176
  84. package/dist/esm/apps/contracts/state-machines/contract-universal.js +47 -59
  85. package/dist/esm/apps/corporate/index.js +2 -2
  86. package/dist/esm/apps/corporate/state-machines/corp-board.js +418 -484
  87. package/dist/esm/apps/corporate/state-machines/corp-entity.js +371 -443
  88. package/dist/esm/apps/corporate/state-machines/corp-securities.js +535 -650
  89. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +502 -606
  90. package/dist/esm/apps/governance/index.js +10 -10
  91. package/dist/esm/apps/governance/state-machines/dao-multisig.js +172 -211
  92. package/dist/esm/apps/governance/state-machines/dao-reputation.js +163 -216
  93. package/dist/esm/apps/governance/state-machines/dao-single.js +94 -94
  94. package/dist/esm/apps/governance/state-machines/dao-token.js +171 -225
  95. package/dist/esm/apps/governance/state-machines/governance-simple.js +187 -219
  96. package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
  97. package/dist/esm/apps/identity/constants.js +18 -26
  98. package/dist/esm/apps/identity/index.js +8 -8
  99. package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
  100. package/dist/esm/apps/identity/state-machines/identity-oracle.js +153 -171
  101. package/dist/esm/apps/identity/state-machines/identity-registry.js +91 -117
  102. package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
  103. package/dist/esm/apps/index.js +9 -6
  104. package/dist/esm/apps/lending/assets.js +41 -17
  105. package/dist/esm/apps/lending/credit-scoring.js +6 -6
  106. package/dist/esm/apps/lending/eligibility.js +10 -26
  107. package/dist/esm/apps/lending/index.js +5 -5
  108. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +178 -157
  109. package/dist/esm/apps/markets/index.js +5 -5
  110. package/dist/esm/apps/markets/state-machines/market-auction.js +117 -136
  111. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +124 -139
  112. package/dist/esm/apps/markets/state-machines/market-group-buy.js +160 -179
  113. package/dist/esm/apps/markets/state-machines/market-prediction.js +195 -229
  114. package/dist/esm/apps/markets/state-machines/market-universal.js +66 -81
  115. package/dist/esm/apps/oracles/index.js +3 -3
  116. package/dist/esm/apps/privacy/index.js +56 -0
  117. package/dist/esm/apps/privacy/state-machines/index.js +6 -0
  118. package/dist/esm/apps/privacy/state-machines/mixer-ddhRing.js +282 -0
  119. package/dist/esm/apps/privacy/state-machines/note-pool.js +470 -0
  120. package/dist/esm/apps/staked-pool/assets.js +91 -0
  121. package/dist/esm/apps/staked-pool/base.js +493 -0
  122. package/dist/esm/apps/staked-pool/consumer.js +49 -0
  123. package/dist/esm/apps/staked-pool/index.js +60 -0
  124. package/dist/esm/apps/staked-pool/state-machines/index.js +6 -0
  125. package/dist/esm/apps/staked-pool/state-machines/staked-pool-base.js +46 -0
  126. package/dist/esm/apps/staked-pool/state-machines/staked-pool-oracle.js +127 -0
  127. package/dist/esm/generated/google/protobuf/struct.js +1 -1
  128. package/dist/esm/generated/google/protobuf/timestamp.js +1 -1
  129. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +1 -1
  130. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  131. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +1 -1
  132. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  133. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +1 -1
  134. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +1 -1
  135. package/dist/esm/generated/ottochain/v1/common.js +1 -1
  136. package/dist/esm/generated/ottochain/v1/fiber.js +40 -2
  137. package/dist/esm/generated/ottochain/v1/messages.js +1 -1
  138. package/dist/esm/generated/ottochain/v1/records.js +1 -1
  139. package/dist/esm/index.js +10 -4
  140. package/dist/esm/ottochain/genesis-manifest.js +6 -0
  141. package/dist/esm/ottochain/metagraph-client.js +16 -8
  142. package/dist/esm/ottochain/snapshot.js +2 -4
  143. package/dist/esm/ottochain/transaction.js +8 -0
  144. package/dist/esm/privacy/index.js +2 -2
  145. package/dist/esm/privacy/sealed-bid.js +87 -84
  146. package/dist/esm/privacy/shield-app.js +33 -33
  147. package/dist/esm/schema/effects.js +110 -0
  148. package/dist/esm/schema/fiber-app.js +127 -3
  149. package/dist/esm/schema/guard-lint.js +3 -12
  150. package/dist/esm/schema/guards.js +36 -37
  151. package/dist/esm/templates/asset-policy.js +182 -0
  152. package/dist/esm/templates/index.js +41 -0
  153. package/dist/esm/templates/machine.js +125 -0
  154. package/dist/esm/templates/migration.js +34 -0
  155. package/dist/esm/templates/state-shape.js +34 -0
  156. package/dist/esm/validation.js +1 -3
  157. package/dist/esm/zk/index.js +4 -4
  158. package/dist/types/apps/compute/index.d.ts +176 -0
  159. package/dist/types/apps/compute/state-machines/compute-rule110.d.ts +157 -0
  160. package/dist/types/apps/compute/state-machines/index.d.ts +5 -0
  161. package/dist/types/apps/contracts/index.d.ts +14 -14
  162. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +3 -3
  163. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +3 -3
  164. package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
  165. package/dist/types/apps/corporate/index.d.ts +162 -162
  166. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +88 -88
  167. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +14 -14
  168. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +18 -18
  169. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +43 -43
  170. package/dist/types/apps/governance/index.d.ts +81 -81
  171. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +16 -16
  172. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +22 -22
  173. package/dist/types/apps/governance/state-machines/dao-token.d.ts +21 -21
  174. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +11 -11
  175. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +4 -4
  176. package/dist/types/apps/identity/constants.d.ts +2 -2
  177. package/dist/types/apps/identity/index.d.ts +70 -70
  178. package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
  179. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +11 -11
  180. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +27 -27
  181. package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
  182. package/dist/types/apps/index.d.ts +9 -6
  183. package/dist/types/apps/lending/assets.d.ts +2 -2
  184. package/dist/types/apps/lending/credit-scoring.d.ts +5 -5
  185. package/dist/types/apps/lending/eligibility.d.ts +2 -2
  186. package/dist/types/apps/lending/index.d.ts +20 -12
  187. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +15 -7
  188. package/dist/types/apps/markets/index.d.ts +76 -76
  189. package/dist/types/apps/markets/state-machines/market-auction.d.ts +12 -12
  190. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +19 -19
  191. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +18 -18
  192. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +15 -15
  193. package/dist/types/apps/markets/state-machines/market-universal.d.ts +7 -7
  194. package/dist/types/apps/oracles/index.d.ts +1 -1
  195. package/dist/types/apps/privacy/index.d.ts +328 -0
  196. package/dist/types/apps/privacy/state-machines/index.d.ts +6 -0
  197. package/dist/types/apps/privacy/state-machines/mixer-ddhRing.d.ts +337 -0
  198. package/dist/types/apps/privacy/state-machines/note-pool.d.ts +196 -0
  199. package/dist/types/apps/staked-pool/assets.d.ts +53 -0
  200. package/dist/types/apps/staked-pool/base.d.ts +80 -0
  201. package/dist/types/apps/staked-pool/consumer.d.ts +29 -0
  202. package/dist/types/apps/staked-pool/index.d.ts +51 -0
  203. package/dist/types/apps/staked-pool/state-machines/index.d.ts +6 -0
  204. package/dist/types/apps/staked-pool/state-machines/staked-pool-base.d.ts +8 -0
  205. package/dist/types/apps/staked-pool/state-machines/staked-pool-oracle.d.ts +34 -0
  206. package/dist/types/generated/openapi.d.ts +13 -0
  207. package/dist/types/generated/ottochain/v1/fiber.d.ts +7 -0
  208. package/dist/types/index.d.ts +3 -3
  209. package/dist/types/openapi.d.ts +4 -2
  210. package/dist/types/ottochain/genesis-manifest.d.ts +6 -0
  211. package/dist/types/ottochain/transaction.d.ts +9 -1
  212. package/dist/types/ottochain/types.d.ts +1 -1
  213. package/dist/types/privacy/index.d.ts +2 -2
  214. package/dist/types/privacy/sealed-bid.d.ts +9 -9
  215. package/dist/types/privacy/shield-app.d.ts +1 -1
  216. package/dist/types/schema/effects.d.ts +107 -0
  217. package/dist/types/schema/fiber-app.d.ts +281 -0
  218. package/dist/types/schema/guards.d.ts +12 -0
  219. package/dist/types/templates/asset-policy.d.ts +119 -0
  220. package/dist/types/templates/index.d.ts +26 -0
  221. package/dist/types/templates/machine.d.ts +139 -0
  222. package/dist/types/templates/migration.d.ts +34 -0
  223. package/dist/types/templates/state-shape.d.ts +30 -0
  224. package/dist/types/zk/index.d.ts +4 -4
  225. package/package.json +31 -13
@@ -0,0 +1,196 @@
1
+ /**
2
+ * shielded-note-pool — a Tornado-style fixed-denomination UTXO-private asset pool.
3
+ *
4
+ * One fiber instance is one shielded pool. The pool's PUBLIC state is the privacy
5
+ * scaffolding only — a Poseidon-Merkle commitment ROOT window, a spent-NULLIFIER set,
6
+ * an append-only output-COMMITMENT log, and the asset-record UUIDs the pool custodies.
7
+ * The real value model is a UTXO note layer that lives OFF-chain in notes committed to
8
+ * the tree; each spend is attested by a single Groth16 proof of the `zk-shielded` circuit.
9
+ *
10
+ * Division of labour (the Kachina/Midnight split — a general verifier in the VM, the
11
+ * shielded pool as ordinary state + transitions on top of it; see
12
+ * docs/design/ergo-patterns-as-fiber-primitives.md §"shielded-note-pool" and
13
+ * docs/design/shielded-transfer-app-sketch.md):
14
+ * - the CIRCUIT proves membership (Poseidon-Merkle inclusion) ∧ authorization
15
+ * (`owner == Poseidon([nsk])`) ∧ nullifier derivation (`nf == Poseidon([rho, nsk])`)
16
+ * ∧ intra-transfer nullifier uniqueness ∧ per-asset conservation ∧ u64 range;
17
+ * - this GUARD (combine) verifies the proof against the pinned `vkey`, binds the
18
+ * public inputs by slicing them from the VERIFIED `publicValues` bytes, rejects an
19
+ * already-spent nullifier (`none`), checks the spend's anchor is still honored
20
+ * (`in [anchor, knownRoots]`), and pins the fee word to a configured value;
21
+ * - the EFFECT (combine) spends the nullifier, logs the output commitment, advances
22
+ * the rolling anchor window, and (on `unshield`) releases exactly one whole
23
+ * `denom`-valued asset record to a clear recipient.
24
+ *
25
+ * It uses NO new metakit opcode. `groth16_verify` verifies the proof; the public-input
26
+ * words are extracted from the verified `publicValues` string with fixed-offset `substr`
27
+ * and re-prefixed `0x` (`{cat:['0x', {substr:[pv,off,64]}]}`) — slicing the verified
28
+ * bytes IS the binding, so no field can be mauled independently of the proof.
29
+ *
30
+ * ──────────────────────────────────────────────────────────────────────────────────────
31
+ * ⚠ UNAUDITED — TEST ASSETS ONLY. The `zk-shielded` circuit and its Groth16 verifier are
32
+ * UNAUDITED; BN254 is ~100-bit security. This MVP is test-assets-only and pins
33
+ * N=1 input / M=1 output / zero fee, with a SINGLE TRUSTED RELAYER for root advancement.
34
+ * Do NOT deploy with value-bearing assets until the circuit + verifier are audited and the
35
+ * in-circuit `newRoot` (which removes the trusted relayer) has landed. See §"Scope" / the
36
+ * Risks list in the design doc.
37
+ * ──────────────────────────────────────────────────────────────────────────────────────
38
+ *
39
+ * MVP constraints (CONFIRMED DEFAULTS):
40
+ * - test assets only;
41
+ * - single trusted relayer gates root advancement (`event.newRoot` is NOT in the proven
42
+ * public values, so a non-relayer could otherwise flood `knownRoots` and evict honest
43
+ * in-flight anchors — a real DoS). LATER: prove `newRoot` in-circuit and drop the relayer.
44
+ * - fixed denomination; the deposit mint is transparent (Tornado-style), the amount is
45
+ * hidden among same-`denom` notes (anonymity set = all live `denom` notes).
46
+ *
47
+ * On-chain primitive facts this builder relies on (re-verified against
48
+ * `@constellation-network/metagraph-sdk-jlvm@1.8.0-rc.5`, see tests/note-pool.test.ts):
49
+ * - array APPEND is `merge([arr,[item]])` (flatten one level); `cat` on arrays ERRORS
50
+ * ("Unexpected input for `cat`") — never use `cat` for array append on-chain;
51
+ * - every crypto/compare value is `0x`-prefixed; an extracted word MUST be re-prefixed
52
+ * `{cat:['0x', {substr:[pv,off,64]}]}` before comparing with a stored `0x` hash;
53
+ * - `none [arr, {===:[{var:""}, x]}]` fires correctly (fresh→true, spent→false);
54
+ * - `groth16_verify` on a garbage bundle returns `false` (graceful deny, never throws);
55
+ * - `pmt_verify([root, leaf, index, [siblings]])` is Poseidon-Merkle inclusion with
56
+ * ROOT-FIRST siblings and a leaf-position `index` (depth range-checked) — exported as
57
+ * {@link pmtMembership} for off-chain witness building / a membership-gated variant.
58
+ */
59
+ import { type FiberAppDefinition, type JsonLogicRule, type SchemaField } from '../../../schema/fiber-app.js';
60
+ /**
61
+ * The EXACT `publicValues` layout the guard slices, for the N=1 input / M=1 output MVP.
62
+ *
63
+ * `publicValues` is the abi-encoded `ShieldedTransferPublicValues` carried as a single
64
+ * `0x`-prefixed lowercase-hex string. Each 32-byte ABI word is 64 hex chars; word `w`
65
+ * begins at hex offset `2 + 64*w` (the leading `2` skips `0x`).
66
+ *
67
+ * `ShieldedTransferPublicValues { bytes32 anchor; bytes32[] nullifiers; bytes32[] outputCms;
68
+ * uint64 fee; bytes32 feeAsset; }`. The circuit commits this via `alloy_sol_types::abi_encode`,
69
+ * which — the struct being a DYNAMIC tuple (it holds the two dynamic arrays) — emits a single leading
70
+ * `0x20` tuple-offset HEAD WORD before the struct body, then the body's own head of array offsets +
71
+ * a tail of (len, elems). For FIXED N=1/M=1 the tail is static and `substr`-addressable.
72
+ *
73
+ * ┌── field ─────────────┬── hex offset ─┬── width ─┬── notes ─────────────────────────────────┐
74
+ * │ tuple head (0x20) │ 2 │ 64 │ abi_encode dynamic-tuple offset; NOT a field│
75
+ * │ anchor │ 66 │ 64 │ Poseidon-Merkle root the inputs prove under │
76
+ * │ nullifiers off (0xa0)│ 130 │ 64 │ body-relative offset of the nullifiers array│
77
+ * │ outputCms off (0xe0)│ 194 │ 64 │ body-relative offset of the outputCms array │
78
+ * │ fee (uint64 word) │ 258 │ 64 │ transparent fee, right-aligned in the word │
79
+ * │ feeAsset │ 322 │ 64 │ asset-as-Fr the fee is denominated in │
80
+ * │ nullifiers.len │ 386 │ 64 │ == 1 for the N=1 MVP │
81
+ * │ nullifiers[0] │ 450 │ 64 │ the revealed input nullifier │
82
+ * │ outputCms.len │ 514 │ 64 │ == 1 for the M=1 MVP │
83
+ * │ outputCms[0] │ 578 │ 64 │ the revealed output commitment │
84
+ * └──────────────────────┴───────────────┴──────────┴─────────────────────────────────────────────┘
85
+ *
86
+ * The word ORDER and ENCODING a matching SP1 fixture MUST produce (so the placeholder can be
87
+ * swapped for a real proof): the `0x`-string is
88
+ * 0x ‖ 0x20 ‖ anchor ‖ nullifiers.off ‖ outputCms.off ‖ fee ‖ feeAsset ‖
89
+ * nullifiers.len ‖ nullifiers[0] ‖ outputCms.len ‖ outputCms[0]
90
+ * laid out by the circuit's `commit_slice(abi_encode(ShieldedTransferPublicValues{..}))`, such that
91
+ * the five field offsets below land on the words above. Every word is a lowercase 32-byte hex with
92
+ * NO `0x` per-word prefix (the single `0x` is on the whole string).
93
+ *
94
+ * RECONCILED 2026-06 against the REAL `zk-shielded` circuit (~/repos/metakit-sdk/rust/zk-shielded):
95
+ * an earlier version of this layout omitted the leading `0x20` dynamic-tuple head word, so every
96
+ * offset was one 32-byte word (64 hex) too low and the guard sliced the WRONG words. The circuit is
97
+ * the source of truth; the offsets above were corrected (+64 each) to match a real SP1 Groth16 proof
98
+ * whose `publicValues` is `0x ‖ 0x20 ‖ anchor ‖ 0xa0 ‖ 0xe0 ‖ fee ‖ feeAsset ‖ 1 ‖ nf ‖ 1 ‖ cm`.
99
+ *
100
+ * cm / nf preimages (the circuit's, fixed and byte-for-byte across Scala/Rust/TS):
101
+ * - `cm = Poseidon([value_as_fr, owner, asset, rho])` (4-input, MAX poseidon arity);
102
+ * - `owner = Poseidon([nsk])`;
103
+ * - `nf = Poseidon([rho, nsk])` (FIELD ORDER rho, nsk).
104
+ */
105
+ export declare const PV_LAYOUT: {
106
+ /** anchor — word 1 (word 0 is the dynamic-tuple `0x20` head word; see the table). */
107
+ readonly anchor: 66;
108
+ /** fee — word 4 (uint64 right-aligned). MVP pins this whole word to {@link NotePoolOptions.feeWord}. */
109
+ readonly fee: 258;
110
+ /** feeAsset — word 5. */
111
+ readonly feeAsset: 322;
112
+ /** nullifiers[0] — after the nullifiers length word @386. */
113
+ readonly nullifier: 450;
114
+ /** outputCms[0] — after the outputCms length word @514. */
115
+ readonly outputCm: 578;
116
+ };
117
+ /**
118
+ * Lift `publicValues` word at hex `offset` back to a `0x`-hex value comparable with a stored
119
+ * `bytes32`/`hash`. `cat` of two STRINGS is valid on-chain; `cat` of arrays ERRORS — this is
120
+ * strings only. The slice is taken from the SAME bytes `groth16_verify` consumed, so a changed
121
+ * field invalidates the proof: re-prefixing the verified slice IS the public-input binding.
122
+ */
123
+ export declare const pvField: (offset: number) => JsonLogicRule;
124
+ /**
125
+ * `pmt_verify([root, leaf, index, [siblings]])` Poseidon-Merkle inclusion (root-first siblings,
126
+ * leaf-position `index`, depth = `siblings.length`, range-checked). Exported for off-chain witness
127
+ * building and for a membership-gated pool variant. NOTE: the MVP `transfer`/`unshield` guards do
128
+ * NOT call `pmt_verify` — membership is proven INSIDE the circuit (`verify_inclusion`) and bound to
129
+ * the verified `anchor`; the chain only checks `anchor ∈ knownRoots`. This helper exists so a
130
+ * downstream pool that wants an additional ON-CHAIN inclusion check (e.g. for a transparent leaf)
131
+ * can express it with the verified operand format.
132
+ */
133
+ export declare const pmtMembership: (rootVar: JsonLogicRule, leafVar: JsonLogicRule, indexVar: JsonLogicRule, siblingsVar: JsonLogicRule) => JsonLogicRule;
134
+ export interface NotePoolOptions {
135
+ /** zk-shielded program vkey (32B, `0x`-hex). Pinned ONCE at creation; the guard reads it from state. */
136
+ vkey: string;
137
+ /** Merkle depth of the commitment tree, pinned at creation. */
138
+ depth: number;
139
+ /** Fixed note denomination (asset units). Each live note ⇔ one `denom`-valued asset record. */
140
+ denom: number;
141
+ /** Asset policy ref the pool mints/burns note-records under (the deposit authorization surface). */
142
+ poolPolicyRef: string;
143
+ /** `0x` Fr label fees are charged in (== asset-as-Fr). Must equal the proof's `feeAsset` word. */
144
+ feeAsset: string;
145
+ /**
146
+ * The EXACT `0x` 32-byte word `fee` must equal. MVP: the all-zero word (forces fee=0, rejects any
147
+ * value-siphoning fee). LATER, to allow a fixed nonzero fee, compare only the right 16 hex.
148
+ */
149
+ feeWord?: string;
150
+ /** DAG address authorized to advance the root (MVP single trusted relayer; anti-grief). */
151
+ relayer: string;
152
+ /** How many recent anchors stay spendable (rolling window). Default 64. */
153
+ rootWindow?: number;
154
+ }
155
+ /** The all-zero 32-byte word — the MVP `feeWord` (pins fee=0). */
156
+ export declare const ZERO_WORD: string;
157
+ /** Public state every shielded note-pool carries (the note value model itself is private/off-chain). */
158
+ export declare const NOTE_POOL_STATE: Record<string, SchemaField>;
159
+ /** `transfer` / `unshield` carry a Groth16 bundle; `unshield` also carries the record to release. */
160
+ export interface ShieldedSpendPayload {
161
+ /** Groth16 proof bytes (0x hex). */
162
+ proof: string;
163
+ /** abi-encoded `ShieldedTransferPublicValues` (0x hex); see {@link PV_LAYOUT}. */
164
+ publicValues: string;
165
+ }
166
+ /** `transfer` advances the tree; `newRoot` is wallet/relayer-computed (NOT in the proven PV). */
167
+ export interface TransferPayload extends ShieldedSpendPayload {
168
+ /** wallet/relayer-computed root after appending `outputCms[0]`. Authorized by the relayer signer gate. */
169
+ newRoot: string;
170
+ }
171
+ /** `unshield` releases one whole `denom`-valued record the pool holds to a clear recipient. */
172
+ export interface UnshieldPayload extends ShieldedSpendPayload {
173
+ /** assetId UUID of the note-record to release; MUST be `in state.noteRecords`. */
174
+ recordId: string;
175
+ /** clear DAG address (→ `AssetHolder.Wallet`) that receives the released note-record. */
176
+ recipient: string;
177
+ }
178
+ /** `noteMinted` records a deposit's commitment + the freshly-minted record's UUID. */
179
+ export interface NoteMintedPayload {
180
+ /** client-computed `cm = Poseidon([denom, owner, feeAsset, rho])` (0x). */
181
+ commitment: string;
182
+ /** assetId UUID of the `denom`-valued record the deposit minted into `Fiber(poolId)`. */
183
+ recordId: string;
184
+ }
185
+ /**
186
+ * Build the shielded-note-pool fiber app.
187
+ *
188
+ * Single state `ACTIVE → ACTIVE` with three transitions:
189
+ * - `transfer` — note-to-note spend (no public asset move); advances the tree. Relayer-gated.
190
+ * - `noteMinted`— witness transition recording a deposit's commitment + record UUID (the deposit
191
+ * itself is an asset-model `MintAsset` into `Fiber(poolId)`, gated by the
192
+ * `poolPolicyRef` mintPolicy — NOT a fiber transition).
193
+ * - `unshield` — burn a note (nullify), release one whole `denom` note-record to a clear recipient.
194
+ * Self-sufficient because it is CASCADE-REACHABLE (asset transfers fire from cascades).
195
+ */
196
+ export declare function notePoolDef(opts: NotePoolOptions): FiberAppDefinition;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Asset-subsystem integration for the staked-pool family.
3
+ *
4
+ * Two asset roles:
5
+ * - STAKE token: a governed fungible. Joining is a custody `Transfer` of the whole stake instance into
6
+ * `AssetHolder.Fiber(poolId)` (the loan family's "lock = Transfer into Fiber holder" pattern); the
7
+ * pool's `stake_and_join` guard verifies the custody via `heldAssets` (H5). Withdraw/slash move it back
8
+ * out via the fiber's `_transferAsset` directive.
9
+ * - REWARD token: a shared fungible the pool pre-holds. `claim_reward` moves ONE whole reward instance to
10
+ * a verified in-consensus claimant (per-claim model — the whole-asset transfer has no amount field).
11
+ *
12
+ * Reuses the lending family's asset payload builders (`createAssetPolicyPayload`, `createMintAssetPayload`,
13
+ * `createApplyMorphismPayload`, `fiberHolder`, `walletHolder`) — re-exported here so a staked-pool caller
14
+ * has a single import surface.
15
+ */
16
+ import { createAssetPolicyPayload, createMintAssetPayload, createApplyMorphismPayload, fiberHolder, walletHolder, TokenBehaviors, type CreateAssetPolicyParams, type MintAssetMessage, type ApplyMorphismMessage, type PolicyRef, type JsonLogicRule } from '../lending/assets.js';
17
+ export { createAssetPolicyPayload, createMintAssetPayload, createApplyMorphismPayload, fiberHolder, walletHolder, TokenBehaviors, };
18
+ export type { CreateAssetPolicyParams, MintAssetMessage, ApplyMorphismMessage, PolicyRef, JsonLogicRule };
19
+ /**
20
+ * Stake-token policy: a governed fungible. `Transfer` is the custody move into/out of the pool fiber.
21
+ * Transferable so withdraw/slash can return it (a soulbound stake would fail the R1 transferable check
22
+ * on withdraw — see design §11; not the default here).
23
+ */
24
+ export declare function stakePolicy(name?: string, version?: string): CreateAssetPolicyParams;
25
+ /**
26
+ * Reward-pot policy: a shared fungible the pool pre-holds and pays out one whole instance per claim.
27
+ * `mintGuard` (optional) gates who may mint reward instances into the pool (e.g. the pool authority);
28
+ * omit for an open mint pinned operationally.
29
+ */
30
+ export declare function rewardPotPolicy(mintGuard?: JsonLogicRule | null, name?: string, version?: string): CreateAssetPolicyParams;
31
+ /**
32
+ * stake_and_join driver: the participant Transfers their whole stake instance into the pool fiber BEFORE
33
+ * the `stake_and_join` event (custody = Transfer to `AssetHolder.Fiber`). Mirrors `lockCollateralOp`.
34
+ */
35
+ export declare function stakeJoinOp(args: {
36
+ stakeAssetId: string;
37
+ poolFiberId: string;
38
+ targetSequenceNumber: number;
39
+ }): ApplyMorphismMessage;
40
+ /**
41
+ * Pre-mint reward instances into the pool fiber (sized to expected claimants for the epoch). Mirrors
42
+ * `mintPrincipalOp` but mints to `Fiber(poolId)` so `claim_reward` can later transfer one whole instance.
43
+ */
44
+ export declare function mintRewardInstancesOp(args: {
45
+ rewardAssetId: string;
46
+ rewardPolicyRef: PolicyRef;
47
+ poolFiberId: string;
48
+ amount: number | string;
49
+ witness?: {
50
+ publicValues: string;
51
+ proof: string;
52
+ };
53
+ }): MintAssetMessage;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Staked-pool BASE factory — a reusable staked-epoch-pool lifecycle skeleton.
3
+ *
4
+ * Lifecycle: FORMING → COLLECTING → SETTLED → COLLECTING (reset) … → CLOSED.
5
+ * FORMING (initial) — accepting stake/join; registry bound; not yet running epochs.
6
+ * COLLECTING — epoch open; participants submit datapoints/votes.
7
+ * SETTLED — result published; entitlement ledger credited; result readable cross-fiber.
8
+ * CLOSED (final) — wound down; stakes + unclaimed rewards still withdrawable/claimable.
9
+ *
10
+ * The base composes EXISTING SDK primitives only:
11
+ * - `signerIsParty` (authority gate), `actorIsSigner`/`actorHasEntry` (effect-key↔signer coupling),
12
+ * `signerHasReputationVia` (the #24 dynamic-dep reputation-gated join), `actorNotInArray` (array dedup),
13
+ * `depInState` (cross-fiber consumer read — used by the consumer, not the pool itself) — `src/schema/guards.ts`.
14
+ * - `addDependency` (#24 bind), `transferAsset` (whole-instance custody move) — `src/schema/effects.ts`.
15
+ *
16
+ * Value model (design §2.1, §4 — resolved):
17
+ * - Submissions are an APPEND-ONLY ARRAY of `{ addr, value }` records (no map-keyed-by-address, because
18
+ * there is no `(array,int)` element-index op). Append is `merge[state.submissions, [record]]` — verified.
19
+ * - finalize emits ZERO asset transfers: it publishes `result` and records the in-consensus address set
20
+ * into `inConsensus` (the entitlement ledger). No reward map-fold (a map-valued `reduce` accumulator is
21
+ * rejected by the VM — `isPrimitive` guard in `opReduce`); entitlement is membership in `inConsensus`.
22
+ * - reward = PER-CLAIM on a shared fungible: `claim_reward` moves ONE whole reward instance the pool holds
23
+ * to a verified, in-consensus, not-yet-claimed signer, and marks `claimed[addr] = true`. ≤1 transfer.
24
+ * - withdraw_stake / hard-slash each emit exactly ONE whole `_transferAsset` ⇒ never the 32-cap.
25
+ *
26
+ * Multi-`from` arms are SPLIT into one transition per source state (chain `from` is a single string):
27
+ * stake_and_join ×2, claim_reward ×2, withdraw_stake ×2, close ×3.
28
+ */
29
+ import type { FiberAppDefinition, Transition } from '../../schema/fiber-app.js';
30
+ /**
31
+ * submit COLLECTING→COLLECTING — append one `{addr,value}` datapoint. OVERRIDABLE per specialization.
32
+ * Guard = joined participant (signer-pinned) AND within window AND not-yet-submitted-this-epoch (array dedup).
33
+ */
34
+ export declare function defaultSubmitArm(): Transition;
35
+ /**
36
+ * Genesis state — EVERY map init'd to `{}` and EVERY array to `[]` so reads stay total (M1: `has`/`get`
37
+ * on null hard-error). `epoch`/`epochStartedAt` are 0 until `open_first_epoch`.
38
+ */
39
+ export declare const baseInitialStateData: {
40
+ readonly status: "FORMING";
41
+ readonly epoch: 0;
42
+ readonly epochStartedAt: 0;
43
+ readonly participants: {};
44
+ readonly stakes: {};
45
+ readonly stakeAssetIds: {};
46
+ readonly submissions: readonly [];
47
+ readonly inConsensus: readonly [];
48
+ readonly claimed: {};
49
+ readonly result: null;
50
+ };
51
+ export interface StakedPoolOverrides {
52
+ /** Metadata identity for the specialization. */
53
+ metadata: {
54
+ name: string;
55
+ type: string;
56
+ description: string;
57
+ version?: string;
58
+ };
59
+ /** Override the COLLECTING→COLLECTING `submit` arm (e.g. oracle datapoint append). Defaults to {@link defaultSubmitArm}. */
60
+ submit?: Transition;
61
+ /** The finalize arm (COLLECTING→SETTLED) — REQUIRED; supplied by the specialization (e.g. trimmed-mean). */
62
+ finalize: Transition;
63
+ /** Extra arms (e.g. governance propose/vote/resolve/challenge/slash) appended after the base arms. */
64
+ extraTransitions?: readonly Transition[];
65
+ /** Extra states (e.g. governance VOTING). */
66
+ extraStates?: Record<string, {
67
+ id: string;
68
+ isFinal: boolean;
69
+ metadata?: unknown;
70
+ }>;
71
+ /** Extra create-schema properties merged onto the base. */
72
+ extraCreateProperties?: Record<string, unknown>;
73
+ /** Extra state-schema properties merged onto the base. */
74
+ extraStateProperties?: Record<string, unknown>;
75
+ }
76
+ /**
77
+ * Build a staked-pool definition from the shared base + a specialization's `submit`/`finalize` (+ extras).
78
+ * Emits all SPLIT multi-`from` arms; no two emitted entries share both `from` and `eventName`.
79
+ */
80
+ export declare function makeStakedPoolDef(overrides: StakedPoolOverrides): FiberAppDefinition;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Cross-fiber consumer-read helpers for a SETTLED staked/oracle pool ("pull the answer").
3
+ *
4
+ * Two-phase (#24): a consumer first BINDS the pool dependency and PINS the epoch it intends to consume
5
+ * (transition N), then GATES on lifecycle + epoch and READS `result` (transition N+1). The epoch pin
6
+ * (M4) makes the read epoch-EXACT: between bind and read the pool can cycle SETTLED→COLLECTING→SETTLED,
7
+ * so a bare `depInState(SETTLED)` could read a DIFFERENT epoch's answer.
8
+ *
9
+ * Verified against the VM: `machines.<poolId>.state.{epoch,result}` reads resolve, and
10
+ * `depInState`/the epoch-`===` gate evaluate true only for the pinned, settled epoch.
11
+ */
12
+ import type { JsonLogicRule } from '../../schema/fiber-app.js';
13
+ /**
14
+ * PHASE 1 effect fragment — bind the pool dependency AND pin its current epoch into `epochField`
15
+ * (default `"expectedPoolEpoch"`). Spread into the consumer's `merge` effect on the bind transition.
16
+ * NOTE: `machines.<poolId>` is only readable AFTER a prior `_addDependency`, so the epoch pin records the
17
+ * value the consumer observes at bind time; on the first bind the pool dep may be unbound and the pin
18
+ * resolves null — bind in one transition, pin in the next if the registry/pool was not yet a dependency.
19
+ */
20
+ export declare function bindAndPinPoolEpoch(poolIdVar?: string, epochField?: string): Record<string, unknown>;
21
+ /**
22
+ * PHASE 2 guard — the pool is SETTLED for the EXACT epoch the consumer pinned. Compose into the read
23
+ * transition's guard alongside the consumer's own auth.
24
+ */
25
+ export declare function poolSettledForPinnedEpoch(poolIdVar?: string, epochField?: string): JsonLogicRule;
26
+ /** PHASE 2 value read — the published `result` object (use `.value` for the scalar answer). */
27
+ export declare function readPoolResult(poolIdVar?: string): JsonLogicRule;
28
+ /** PHASE 2 value read — the scalar `result.value`. */
29
+ export declare function readPoolResultValue(poolIdVar?: string): JsonLogicRule;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Staked-pool Application — a reusable staked-epoch-pool std-lib BASE plus an oracle-pool specialization.
3
+ *
4
+ * The base is a long-lived account-layer fiber proving the chain can carry real economic coordination:
5
+ * registry-gated, stake-backed membership; an append-only submission array; a state-resident claim
6
+ * entitlement ledger (zero finalize-time transfers); and one-whole-asset claim/withdraw custody moves.
7
+ * The oracle specialization adds an outlier-bounded (trimmed-mean) consensus aggregation whose published
8
+ * answer a consumer reads cross-fiber via an epoch-pinned `depInState(SETTLED)` gate.
9
+ *
10
+ * Composes EXISTING SDK primitives only (+ two helpers added this workstream — `transferAsset`,
11
+ * `actorNotInArray`): `signerIsParty` / `actorIsSigner` / `signerHasReputationVia` / `depInState`
12
+ * (`src/schema/guards.ts`), `addDependency` / `transferAsset` (`src/schema/effects.ts`), and the lending
13
+ * family's asset payload builders (`src/apps/lending/assets.ts`).
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import {
18
+ * getStakedPoolDefinition,
19
+ * makeOraclePoolDef,
20
+ * stakePolicy,
21
+ * rewardPotPolicy,
22
+ * bindAndPinPoolEpoch,
23
+ * poolSettledForPinnedEpoch,
24
+ * readPoolResultValue,
25
+ * } from '@ottochain/sdk/apps/staked-pool';
26
+ *
27
+ * const oracle = getStakedPoolDefinition('oraclePool');
28
+ * const plainMean = makeOraclePoolDef({ aggregation: 'mean' });
29
+ * const stake = stakePolicy();
30
+ * ```
31
+ *
32
+ * @packageDocumentation
33
+ */
34
+ import { stakedPoolBaseDef, stakedPoolOracleDef } from './state-machines/index.js';
35
+ import type { FiberAppDefinition } from '../../schema/fiber-app.js';
36
+ export { stakedPoolBaseDef, stakedPoolOracleDef };
37
+ /** All staked-pool state machine definitions. */
38
+ export declare const STAKED_POOL_DEFINITIONS: {
39
+ readonly base: FiberAppDefinition<string, string>;
40
+ readonly oraclePool: FiberAppDefinition<string, string>;
41
+ };
42
+ export type StakedPoolType = keyof typeof STAKED_POOL_DEFINITIONS;
43
+ /**
44
+ * Get a staked-pool state machine definition by type.
45
+ * @param type - 'base' | 'oraclePool' (default: 'oraclePool')
46
+ */
47
+ export declare function getStakedPoolDefinition(type?: StakedPoolType): FiberAppDefinition;
48
+ export { makeStakedPoolDef, defaultSubmitArm, baseInitialStateData, type StakedPoolOverrides } from './base.js';
49
+ export { makeOraclePoolDef, type OracleAggregation, type OraclePoolOptions } from './state-machines/index.js';
50
+ export { stakePolicy, rewardPotPolicy, stakeJoinOp, mintRewardInstancesOp, createAssetPolicyPayload, createMintAssetPayload, createApplyMorphismPayload, fiberHolder, walletHolder, TokenBehaviors, type CreateAssetPolicyParams, type MintAssetMessage, type ApplyMorphismMessage, type PolicyRef, } from './assets.js';
51
+ export { bindAndPinPoolEpoch, poolSettledForPinnedEpoch, readPoolResult, readPoolResultValue } from './consumer.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Staked-pool state machine definitions.
3
+ * Re-exports from TypeScript definition files.
4
+ */
5
+ export { stakedPoolBaseDef } from './staked-pool-base.js';
6
+ export { stakedPoolOracleDef, makeOraclePoolDef, type OracleAggregation, type OraclePoolOptions, } from './staked-pool-oracle.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The generic staked-pool BASE definition (`StakedPool`) — the reusable epoch-pool skeleton with a
3
+ * minimal pass-through `finalize` (authority settles; publishes a trivial result and an EMPTY in-consensus
4
+ * set, zero transfers). It is the lowest-common-denominator def; downstream apps should prefer a
5
+ * specialization (e.g. the oracle pool) that supplies real aggregation. Exposed for definition-validity
6
+ * round-tripping and as the explicit "base, unspecialized" instance.
7
+ */
8
+ export declare const stakedPoolBaseDef: import("../../../schema/fiber-app.js").FiberAppDefinition<string, string>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Oracle-pool specialization of the staked-pool base (`StakedPoolOracle`).
3
+ *
4
+ * `submit` appends a numeric datapoint `{ addr, value }` (the base default arm).
5
+ * `finalize` (COLLECTING→SETTLED) aggregates the array with an outlier-bounded mean and publishes the
6
+ * answer + the in-consensus address set — emitting ZERO asset transfers (the entitlement ledger is
7
+ * `inConsensus`; rewards are pulled per-claim via the base `claim_reward` arm).
8
+ *
9
+ * Aggregation (default `trimmedMean`):
10
+ * 1. vals = map(submissions, .value)
11
+ * 2. trimmed = filter(submissions, value != min(vals) && value != max(vals)) — drop single min + single max
12
+ * 3. center = sum(trimmed.value) / count(trimmed) — EXACT rational (no truncation)
13
+ * 4. kept = filter(submissions, abs(value - center) <= outlierBound) — the in-consensus set
14
+ * 5. answer = sum(kept.value) / count(kept)
15
+ *
16
+ * CRITICAL JLVM SCOPING (verified against @constellation-network/metagraph-sdk-jlvm@1.8.0-rc.5):
17
+ * - Inside a `map`/`filter` callback the data scope is the BARE element, BUT the outer `state.*` is
18
+ * still readable (verified: `{cat:[addr,"|",{var:"state.epoch"}]}` reads epoch correctly).
19
+ * - A `let`-bound name does NOT cross into a `map`/`filter` callback. So `center` is INLINED into the
20
+ * `kept` predicate (it reads `state.submissions`, which IS visible) rather than `let`-hoisted — a
21
+ * `let`-bound `center` resolves to null inside `filter`, evicting every submission (div-by-zero).
22
+ * - A `reduce` with a MAP initial accumulator is rejected (`opReduce` requires `isPrimitive(init)`),
23
+ * so the reward ledger is NOT a folded `{addr:int}` map — it is the `inConsensus` array (membership =
24
+ * entitlement), consumed by `claim_reward` + a `claimed` dedup map.
25
+ */
26
+ export type OracleAggregation = 'mean' | 'trimmedMean';
27
+ export interface OraclePoolOptions {
28
+ /** Aggregation strategy. Default `trimmedMean` (drop single min + single max — the robustness ceiling). */
29
+ aggregation?: OracleAggregation;
30
+ }
31
+ /** Build the oracle-pool definition. `outlierPenalty` is soft-only (no-credit for outliers); hard slash is v2. */
32
+ export declare function makeOraclePoolDef(options?: OraclePoolOptions): import("../../../schema/fiber-app.js").FiberAppDefinition<string, string>;
33
+ /** Default oracle-pool definition (trimmed-mean). */
34
+ export declare const stakedPoolOracleDef: import("../../../schema/fiber-app.js").FiberAppDefinition<string, string>;
@@ -428,11 +428,23 @@ export interface components {
428
428
  ordinal: number;
429
429
  state: components["schemas"]["CalculatedState"];
430
430
  };
431
+ /** DynamicDependency */
432
+ DynamicDependency: {
433
+ /** Format: uuid */
434
+ fiberId: string;
435
+ active: boolean;
436
+ /** Format: int64 */
437
+ addedAt: number;
438
+ };
431
439
  /** EmittedEvent */
432
440
  EmittedEvent: {
433
441
  name: string;
434
442
  data: unknown;
435
443
  destination?: string;
444
+ /** Format: uuid */
445
+ emitterFiberId: string;
446
+ /** Format: int32 */
447
+ emissionIndex: number;
436
448
  };
437
449
  /** EventReceipt */
438
450
  EventReceipt: {
@@ -562,6 +574,7 @@ export interface components {
562
574
  childFiberIds?: string[];
563
575
  schemaBinding?: components["schemas"]["SchemaBinding"];
564
576
  authorizedSigners?: string[];
577
+ dynamicDependencies?: components["schemas"]["DynamicDependency"][];
565
578
  };
566
579
  /** StateProofResponse */
567
580
  StateProofResponse: {
@@ -53,6 +53,13 @@ export interface EmittedEvent {
53
53
  name: string;
54
54
  data?: any | undefined;
55
55
  destination?: string | undefined;
56
+ /**
57
+ * Engine-stamped at extraction (EffectExtractor), never user-supplied — make every
58
+ * emitted event attributable to the fiber that produced it (engine-default-fixes Fix 1).
59
+ */
60
+ emitterFiberId: string;
61
+ /** Sparse position within the raw `_emit` array at authoring time. */
62
+ emissionIndex: number;
56
63
  }
57
64
  /** Event receipt - log entry for state machine transition */
58
65
  export interface EventReceipt {
@@ -31,8 +31,8 @@ export { OttoChainError, NetworkError, ValidationError, SigningError, Transactio
31
31
  export { DagAddressSchema, PrivateKeySchema, PublicKeySchema, KeyPairSchema, SignatureProofSchema, SignedSchema, TransactionReferenceSchema, CurrencyTransactionValueSchema, CurrencyTransactionSchema, TransferParamsSchema, AgentIdentityRegistrationSchema, PlatformLinkSchema, ContractTermsSchema, ProposeContractRequestSchema, AcceptContractRequestSchema, CompleteContractRequestSchema, validate, validatePrivateKey, validatePublicKey, validateAddress, validateKeyPair, safeParse, assert, type ValidatedKeyPair, type ValidatedSignatureProof, type ValidatedCurrencyTransaction, type ValidatedTransferParams, type ValidatedAgentIdentityRegistration, type ValidatedPlatformLink, type ValidatedProposeContractRequest, type ValidatedAcceptContractRequest, type ValidatedCompleteContractRequest, } from './validation.js';
32
32
  export { MetagraphClient as OttoMetagraphClient } from './ottochain/metagraph-client.js';
33
33
  export type { MetagraphClientConfig, Checkpoint, SubscribeOptions, FiberStateCallback, Unsubscribe, } from './ottochain/metagraph-client.js';
34
- export { toProtoDefinition, defineFiberApp, type ProtoStateMachineDefinition, type FiberAppDefinition, type FiberAppMetadata, type StateDefinition, type StdStateMetadata, type StateCategory, type Transition, } from './schema/fiber-app.js';
35
- export { type GuardRule, signerIsParty, signerIsAnyParty, signerInSet, signerIsNotParty, signerHasEntry, assetSignerIs, actorIsSigner, actorInSet, actorHasEntry, signerHasReputation, signerHasRole, signerHasReputationVia, signerHasRoleVia, depInState, } from './schema/guards.js';
36
- export { addDependency, setDependencyActive } from './schema/effects.js';
34
+ export { toProtoDefinition, defineFiberApp, constrained, unconstrained, immutable, IMMUTABLE_POLICY, projectFiberPolicy, type ProtoStateMachineDefinition, type FiberAppDefinition, type FiberAppMetadata, type FiberPolicy, type FiberPolicyDials, type ImmutablePolicy, type EffectKind, type SpawnOwnerPolicy, type DependencyMode, type TransferPolicy, type DependencyPolicy, type MigrationAuthority, type UpgradePolicy, type VersionRange, type StateDefinition, type StdStateMetadata, type StateCategory, type Transition, } from './schema/fiber-app.js';
35
+ export { type GuardRule, signerIsParty, signerIsAnyParty, signerInSet, signerIsNotParty, signerHasEntry, assetSignerIs, actorIsSigner, actorInSet, actorHasEntry, signerHasReputation, signerHasRole, signerHasReputationVia, signerHasRoleVia, depInState, actorNotInArray, } from './schema/guards.js';
36
+ export { addDependency, setDependencyActive, transferAsset, triggers, spawn, emit, toFiber, toWallet, RESERVED_EFFECT_KEYS, } from './schema/effects.js';
37
37
  export { shieldApp, SHIELDED_POOL_STATE, type ShieldOptions } from './privacy/shield-app.js';
38
38
  export type { paths as ApiPaths, operations as ApiOperations, components as ApiComponents, VersionInfo, TransitionFeeEstimate, ScriptFeeEstimate, SubscribeRequest, SubscribeResponse, Subscriber, SubscriberList, } from './openapi.js';
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * Typed OttoChain HTTP API surface.
3
3
  *
4
- * These types are generated from the metagraph's OpenAPI contract
5
- * (`openapi/ottochain-openapi.json`, emitted by ottochain's tapir `ApiEndpoints`) — so the SDK and the
4
+ * These types are generated from the metagraph's ML0 OpenAPI contract
5
+ * (`openapi/ottochain-openapi-ml0.json`, emitted by ottochain's tapir `ApiEndpoints`) — so the SDK and the
6
6
  * chain share ONE source of truth for request/response shapes, instead of reverse-engineering them inline.
7
+ * The vendored contract is pulled from ottochain's published RELEASE artifacts (see `openapi/README.md` +
8
+ * `openapi/source.json`); refresh it with `pnpm fetch:openapi`.
7
9
  *
8
10
  * Regenerate after the contract changes with `pnpm gen:openapi`. The raw generated module is
9
11
  * `src/generated/openapi.ts`; this file gives consumers stable, named aliases for the precise response
@@ -90,6 +90,12 @@ export interface StateMachineDefinition {
90
90
  dependencies: unknown[];
91
91
  }>;
92
92
  metadata: unknown | null;
93
+ /**
94
+ * Fiber constitution. PRESENT for `Constrained` (a bare object of the SET dials) and for
95
+ * `Immutable` (the bare JSON string `"Immutable"`); ABSENT for `Unconstrained` (the chain
96
+ * emits no `policy` key for it).
97
+ */
98
+ policy?: Record<string, unknown> | string;
93
99
  }
94
100
  /**
95
101
  * One package to pre-register at genesis. This is the genesis INPUT, not the
@@ -5,7 +5,7 @@
5
5
  * self-signed mode, where clients sign their own transactions.
6
6
  */
7
7
  import type { Signed } from '@constellation-network/metagraph-sdk';
8
- import type { CreateAssetPolicy, MintAsset, ApplyMorphism, AuthorizeCompose } from './types.js';
8
+ import type { CreateAssetPolicy, MintAsset, ApplyMorphism, AuthorizeCompose, PublishMachineVersion, UpgradeFiber } from './types.js';
9
9
  /**
10
10
  * Parameters for creating a new state machine fiber
11
11
  */
@@ -202,6 +202,14 @@ export declare function createApplyMorphismPayload(params: ApplyMorphism): {
202
202
  export declare function createAuthorizeComposePayload(params: AuthorizeCompose): {
203
203
  AuthorizeCompose: AuthorizeCompose;
204
204
  };
205
+ /** Wrap a {@link PublishMachineVersion} (create-or-append a STATE-MACHINE registry version). */
206
+ export declare function createPublishMachineVersionPayload(params: PublishMachineVersion): {
207
+ PublishMachineVersion: PublishMachineVersion;
208
+ };
209
+ /** Wrap an {@link UpgradeFiber} (re-pin a fiber to another registered version of the SAME package). */
210
+ export declare function createUpgradeFiberPayload(params: UpgradeFiber): {
211
+ UpgradeFiber: UpgradeFiber;
212
+ };
205
213
  /**
206
214
  * Sign a transaction payload for self-signed mode.
207
215
  *
@@ -7,7 +7,7 @@
7
7
  * @see modules/models/src/main/scala/xyz/kd5ujc/schema/
8
8
  * @packageDocumentation
9
9
  */
10
- export type { Address, FiberId, StateId, HashValue, FiberOrdinal, SnapshotOrdinal, Timestamp, } from '../types.js';
10
+ export type { Address, FiberId, StateId, HashValue, FiberOrdinal, SnapshotOrdinal, Timestamp } from '../types.js';
11
11
  /**
12
12
  * JSON logic value - arbitrary JSON data used for state data and payloads.
13
13
  */
@@ -2,5 +2,5 @@
2
2
  * Privacy: shield any fiber app into a zk-jlvm-shielded private-state pool.
3
3
  * See docs/design/zk-private-contract-state-rfc.md.
4
4
  */
5
- export { shieldApp, SHIELDED_POOL_STATE, type ShieldOptions } from "./shield-app.js";
6
- export { sealedBidAccountDef, shieldedSealedBidDef, vickreyAuctionDef } from "./sealed-bid.js";
5
+ export { shieldApp, SHIELDED_POOL_STATE, type ShieldOptions } from './shield-app.js';
6
+ export { sealedBidAccountDef, shieldedSealedBidDef, vickreyAuctionDef } from './sealed-bid.js';