@jinn-network/client 0.1.6-canary.fb9c8196 → 0.1.7-canary.d4e4e183

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 (259) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/deployments/deployment-jinn-mvi-l1-sepolia-fast.json +23 -4
  3. package/deployments/deployment-jinn-mvi-l1-sepolia.json +23 -4
  4. package/deployments/deployment-jinn-mvi-l2-baseSepolia.json +5 -4
  5. package/dist/adapters/mech/adapter.d.ts +38 -1
  6. package/dist/adapters/mech/adapter.js +241 -54
  7. package/dist/adapters/mech/adapter.js.map +1 -1
  8. package/dist/adapters/mech/contracts.d.ts +17 -4
  9. package/dist/adapters/mech/contracts.js +8 -2
  10. package/dist/adapters/mech/contracts.js.map +1 -1
  11. package/dist/adapters/mech/safe-revert.d.ts +20 -0
  12. package/dist/adapters/mech/safe-revert.js +12 -4
  13. package/dist/adapters/mech/safe-revert.js.map +1 -1
  14. package/dist/adapters/mech/safe.d.ts +5 -1
  15. package/dist/adapters/mech/safe.js +27 -8
  16. package/dist/adapters/mech/safe.js.map +1 -1
  17. package/dist/adapters/mech/verdict-code.d.ts +1 -0
  18. package/dist/adapters/mech/verdict-code.js +18 -0
  19. package/dist/adapters/mech/verdict-code.js.map +1 -1
  20. package/dist/api/admin-endpoint.d.ts +15 -3
  21. package/dist/api/admin-endpoint.js +24 -2
  22. package/dist/api/admin-endpoint.js.map +1 -1
  23. package/dist/api/bootstrap-endpoint.js +9 -5
  24. package/dist/api/bootstrap-endpoint.js.map +1 -1
  25. package/dist/api/codex-doctor-endpoint.d.ts +73 -0
  26. package/dist/api/codex-doctor-endpoint.js +177 -0
  27. package/dist/api/codex-doctor-endpoint.js.map +1 -0
  28. package/dist/api/discovery-endpoint.d.ts +1 -0
  29. package/dist/api/discovery-endpoint.js +26 -0
  30. package/dist/api/discovery-endpoint.js.map +1 -1
  31. package/dist/api/gather-status.d.ts +11 -0
  32. package/dist/api/gather-status.js +332 -3
  33. package/dist/api/gather-status.js.map +1 -1
  34. package/dist/api/hermes-doctor-endpoint.d.ts +107 -0
  35. package/dist/api/hermes-doctor-endpoint.js +204 -5
  36. package/dist/api/hermes-doctor-endpoint.js.map +1 -1
  37. package/dist/api/launcher-status.d.ts +21 -16
  38. package/dist/api/launcher-status.js +2 -1
  39. package/dist/api/launcher-status.js.map +1 -1
  40. package/dist/api/portfolio-v0-build.d.ts +10 -0
  41. package/dist/api/portfolio-v0-build.js +24 -5
  42. package/dist/api/portfolio-v0-build.js.map +1 -1
  43. package/dist/api/prediction-v1-build.d.ts +10 -0
  44. package/dist/api/prediction-v1-build.js +7 -1
  45. package/dist/api/prediction-v1-build.js.map +1 -1
  46. package/dist/api/server.d.ts +31 -1
  47. package/dist/api/server.js +68 -1
  48. package/dist/api/server.js.map +1 -1
  49. package/dist/api/setup-endpoints.js +50 -4
  50. package/dist/api/setup-endpoints.js.map +1 -1
  51. package/dist/api/solvernets-endpoints.d.ts +8 -0
  52. package/dist/api/solvernets-endpoints.js +71 -43
  53. package/dist/api/solvernets-endpoints.js.map +1 -1
  54. package/dist/api/status-build.d.ts +58 -0
  55. package/dist/api/status-build.js +50 -0
  56. package/dist/api/status-build.js.map +1 -1
  57. package/dist/api/task-run-routing.d.ts +7 -0
  58. package/dist/api/task-run-routing.js +12 -0
  59. package/dist/api/task-run-routing.js.map +1 -0
  60. package/dist/api/task-runs-build.d.ts +21 -0
  61. package/dist/api/task-runs-build.js +14 -1
  62. package/dist/api/task-runs-build.js.map +1 -1
  63. package/dist/build-info.json +4 -4
  64. package/dist/build-meta.json +1 -1
  65. package/dist/chain-read-errors.d.ts +10 -0
  66. package/dist/chain-read-errors.js +15 -0
  67. package/dist/chain-read-errors.js.map +1 -1
  68. package/dist/cli/commands/auth.js +1 -1
  69. package/dist/cli/commands/auth.js.map +1 -1
  70. package/dist/cli/commands/create.js +3 -2
  71. package/dist/cli/commands/create.js.map +1 -1
  72. package/dist/cli/commands/doctor.d.ts +2 -0
  73. package/dist/cli/commands/doctor.js +2 -0
  74. package/dist/cli/commands/doctor.js.map +1 -1
  75. package/dist/cli/commands/rewards.js +11 -7
  76. package/dist/cli/commands/rewards.js.map +1 -1
  77. package/dist/cli/commands/status.js +1 -1
  78. package/dist/cli/commands/status.js.map +1 -1
  79. package/dist/cli/commands/tasks.js +86 -9
  80. package/dist/cli/commands/tasks.js.map +1 -1
  81. package/dist/cli/commands/update.d.ts +10 -0
  82. package/dist/cli/commands/update.js +36 -0
  83. package/dist/cli/commands/update.js.map +1 -1
  84. package/dist/cli/introspection-context.js +5 -0
  85. package/dist/cli/introspection-context.js.map +1 -1
  86. package/dist/cli/task-native-readiness.d.ts +3 -1
  87. package/dist/cli/task-native-readiness.js +28 -6
  88. package/dist/cli/task-native-readiness.js.map +1 -1
  89. package/dist/config.d.ts +97 -5
  90. package/dist/config.js +90 -18
  91. package/dist/config.js.map +1 -1
  92. package/dist/daemon/checkpoint-loop.d.ts +48 -0
  93. package/dist/daemon/checkpoint-loop.js +76 -0
  94. package/dist/daemon/checkpoint-loop.js.map +1 -0
  95. package/dist/daemon/creator.d.ts +1 -1
  96. package/dist/daemon/creator.js +7 -3
  97. package/dist/daemon/creator.js.map +1 -1
  98. package/dist/daemon/daemon.d.ts +11 -0
  99. package/dist/daemon/daemon.js +51 -1
  100. package/dist/daemon/daemon.js.map +1 -1
  101. package/dist/daemon/jinn-claim-loop-wiring.d.ts +33 -0
  102. package/dist/daemon/jinn-claim-loop-wiring.js +40 -0
  103. package/dist/daemon/jinn-claim-loop-wiring.js.map +1 -0
  104. package/dist/daemon/jinn-claim-loop.d.ts +24 -17
  105. package/dist/daemon/jinn-claim-loop.js +77 -23
  106. package/dist/daemon/jinn-claim-loop.js.map +1 -1
  107. package/dist/daemon/skip-log-dedup.d.ts +69 -0
  108. package/dist/daemon/skip-log-dedup.js +106 -0
  109. package/dist/daemon/skip-log-dedup.js.map +1 -0
  110. package/dist/dashboard/assets/index-BUlE8F3Y.js +330 -0
  111. package/dist/dashboard/assets/index-blqc7eqq.css +32 -0
  112. package/dist/dashboard/index.html +2 -2
  113. package/dist/discovery/factory.d.ts +17 -5
  114. package/dist/discovery/factory.js +46 -18
  115. package/dist/discovery/factory.js.map +1 -1
  116. package/dist/discovery/http.js +142 -3
  117. package/dist/discovery/http.js.map +1 -1
  118. package/dist/discovery/onchain.d.ts +5 -0
  119. package/dist/discovery/onchain.js +407 -15
  120. package/dist/discovery/onchain.js.map +1 -1
  121. package/dist/discovery/types.d.ts +45 -1
  122. package/dist/discovery/types.js +8 -10
  123. package/dist/discovery/types.js.map +1 -1
  124. package/dist/discovery/with-fallback.d.ts +7 -0
  125. package/dist/discovery/with-fallback.js +10 -0
  126. package/dist/discovery/with-fallback.js.map +1 -1
  127. package/dist/earning/bootstrap.d.ts +44 -12
  128. package/dist/earning/bootstrap.js +88 -46
  129. package/dist/earning/bootstrap.js.map +1 -1
  130. package/dist/earning/contracts.d.ts +5 -3
  131. package/dist/earning/contracts.js +12 -7
  132. package/dist/earning/contracts.js.map +1 -1
  133. package/dist/earning/funding-plan.js +27 -18
  134. package/dist/earning/funding-plan.js.map +1 -1
  135. package/dist/earning/safe-adapter.d.ts +2 -0
  136. package/dist/earning/safe-adapter.js +26 -12
  137. package/dist/earning/safe-adapter.js.map +1 -1
  138. package/dist/earning/store.d.ts +8 -0
  139. package/dist/earning/store.js.map +1 -1
  140. package/dist/earning/testnet-setup-migration.js +10 -0
  141. package/dist/earning/testnet-setup-migration.js.map +1 -1
  142. package/dist/erc8004/reputation.d.ts +8 -0
  143. package/dist/erc8004/reputation.js +22 -3
  144. package/dist/erc8004/reputation.js.map +1 -1
  145. package/dist/harnesses/engine/engine.d.ts +72 -0
  146. package/dist/harnesses/engine/engine.js +105 -8
  147. package/dist/harnesses/engine/engine.js.map +1 -1
  148. package/dist/harnesses/engine/persistence.d.ts +51 -1
  149. package/dist/harnesses/engine/persistence.js +118 -5
  150. package/dist/harnesses/engine/persistence.js.map +1 -1
  151. package/dist/harnesses/engine/work-dir-reaper.d.ts +65 -0
  152. package/dist/harnesses/engine/work-dir-reaper.js +100 -0
  153. package/dist/harnesses/engine/work-dir-reaper.js.map +1 -0
  154. package/dist/harnesses/impls/hermes-agent/adapter.js +40 -0
  155. package/dist/harnesses/impls/hermes-agent/adapter.js.map +1 -1
  156. package/dist/harnesses/impls/hermes-agent/bootstrap.d.ts +20 -0
  157. package/dist/harnesses/impls/hermes-agent/bootstrap.js +40 -6
  158. package/dist/harnesses/impls/hermes-agent/bootstrap.js.map +1 -1
  159. package/dist/harnesses/impls/hermes-agent/harness.d.ts +37 -1
  160. package/dist/harnesses/impls/hermes-agent/harness.js +59 -4
  161. package/dist/harnesses/impls/hermes-agent/harness.js.map +1 -1
  162. package/dist/harnesses/impls/index.d.ts +5 -0
  163. package/dist/harnesses/impls/index.js +11 -0
  164. package/dist/harnesses/impls/index.js.map +1 -1
  165. package/dist/harnesses/impls/learner/harness.d.ts +38 -4
  166. package/dist/harnesses/impls/learner/harness.js +96 -2
  167. package/dist/harnesses/impls/learner/harness.js.map +1 -1
  168. package/dist/harnesses/impls/learner/plugin-path.d.ts +0 -13
  169. package/dist/harnesses/impls/learner/plugin-path.js +35 -15
  170. package/dist/harnesses/impls/learner/plugin-path.js.map +1 -1
  171. package/dist/harnesses/impls/learner/types.d.ts +11 -0
  172. package/dist/harnesses/impls/stub.d.ts +58 -0
  173. package/dist/harnesses/impls/stub.js +89 -0
  174. package/dist/harnesses/impls/stub.js.map +1 -0
  175. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.d.ts +69 -50
  176. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js +178 -93
  177. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js.map +1 -1
  178. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.d.ts +12 -1
  179. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js +121 -7
  180. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js.map +1 -1
  181. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.d.ts +15 -0
  182. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js +54 -4
  183. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js.map +1 -1
  184. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.d.ts +6 -0
  185. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js +1 -1
  186. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js.map +1 -1
  187. package/dist/harnesses/readiness-registry.js +9 -1
  188. package/dist/harnesses/readiness-registry.js.map +1 -1
  189. package/dist/main.js +168 -53
  190. package/dist/main.js.map +1 -1
  191. package/dist/observability/emit-event.d.ts +1 -1
  192. package/dist/observability/emit-event.js.map +1 -1
  193. package/dist/plugins/learner/.claude-plugin/plugin.json +9 -0
  194. package/dist/plugins/learner/.codex-plugin/plugin.json +39 -0
  195. package/dist/plugins/learner/AGENTS.md +40 -0
  196. package/dist/plugins/learner/CLAUDE.md +33 -0
  197. package/dist/plugins/learner/README.md +59 -0
  198. package/dist/plugins/learner/hooks/hooks.json +16 -0
  199. package/dist/plugins/learner/hooks/session-start +38 -0
  200. package/dist/plugins/learner/skills/learn/SKILL.md +412 -0
  201. package/dist/plugins/learner/skills/learn/analyst-prompt.md +68 -0
  202. package/dist/plugins/learner/skills/learn/consolidator-prompt.md +94 -0
  203. package/dist/plugins/learner/skills/learn/explorer-prompt.md +53 -0
  204. package/dist/plugins/learner/skills/learn/planner-prompt.md +87 -0
  205. package/dist/plugins/learner/skills/learn/promoter-prompt.md +113 -0
  206. package/dist/plugins/learner/skills/learn/step-worker-prompt.md +47 -0
  207. package/dist/plugins/learner/skills/learn/strategist-prompt.md +85 -0
  208. package/dist/restart-daemon.d.ts +29 -10
  209. package/dist/restart-daemon.js +27 -14
  210. package/dist/restart-daemon.js.map +1 -1
  211. package/dist/solver-nets/prediction-operator-ux.js +31 -12
  212. package/dist/solver-nets/prediction-operator-ux.js.map +1 -1
  213. package/dist/solver-types/_swe-rebench-v2-pool-cache.d.ts +58 -0
  214. package/dist/solver-types/_swe-rebench-v2-pool-cache.js +87 -0
  215. package/dist/solver-types/_swe-rebench-v2-pool-cache.js.map +1 -0
  216. package/dist/solver-types/_swe-rebench-v2-substrate.d.ts +1 -0
  217. package/dist/solver-types/_swe-rebench-v2-substrate.js +10 -0
  218. package/dist/solver-types/_swe-rebench-v2-substrate.js.map +1 -1
  219. package/dist/solver-types/_swe-rebench-v2-validated-pool.d.ts +65 -0
  220. package/dist/solver-types/_swe-rebench-v2-validated-pool.js +243 -26
  221. package/dist/solver-types/_swe-rebench-v2-validated-pool.js.map +1 -1
  222. package/dist/solver-types/swe-rebench-v2-auto.d.ts +22 -7
  223. package/dist/solver-types/swe-rebench-v2-auto.js +45 -20
  224. package/dist/solver-types/swe-rebench-v2-auto.js.map +1 -1
  225. package/dist/solver-types/swe-rebench-v2.d.ts +13 -2
  226. package/dist/solver-types/swe-rebench-v2.js +233 -94
  227. package/dist/solver-types/swe-rebench-v2.js.map +1 -1
  228. package/dist/solvernets/daemon-init.d.ts +10 -2
  229. package/dist/solvernets/daemon-init.js +22 -2
  230. package/dist/solvernets/daemon-init.js.map +1 -1
  231. package/dist/solvernets/launched-record-dispatcher.js +35 -7
  232. package/dist/solvernets/launched-record-dispatcher.js.map +1 -1
  233. package/dist/solvernets/store.d.ts +5 -0
  234. package/dist/solvernets/store.js +1 -0
  235. package/dist/solvernets/store.js.map +1 -1
  236. package/dist/store/store.d.ts +15 -0
  237. package/dist/store/store.js +118 -3
  238. package/dist/store/store.js.map +1 -1
  239. package/dist/tasks/sources.d.ts +18 -1
  240. package/dist/tasks/sources.js +33 -5
  241. package/dist/tasks/sources.js.map +1 -1
  242. package/dist/tx-retry.d.ts +151 -19
  243. package/dist/tx-retry.js +286 -32
  244. package/dist/tx-retry.js.map +1 -1
  245. package/dist/types/payloads/prediction-apy-v0.d.ts +5 -5
  246. package/dist/types/payloads/prediction-v0.d.ts +5 -5
  247. package/dist/types/task-document.d.ts +392 -0
  248. package/dist/types/task-document.js +10 -0
  249. package/dist/types/task-document.js.map +1 -1
  250. package/dist/types/task.d.ts +28 -0
  251. package/dist/util/extract-tx-hash.d.ts +14 -0
  252. package/dist/util/extract-tx-hash.js +19 -0
  253. package/dist/util/extract-tx-hash.js.map +1 -0
  254. package/dist/vendor/@jinn-network/sdk/dist/contracts.js +1 -1
  255. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.d.ts +3 -0
  256. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.js +1 -0
  257. package/package.json +29 -12
  258. package/dist/dashboard/assets/index-C_QnE4YV.js +0 -140
  259. package/dist/dashboard/assets/index-CarzUepP.css +0 -32
@@ -145,6 +145,36 @@ export interface DiscoveryAPI {
145
145
  * `undefined` if no lifecycle events have been recorded for it yet.
146
146
  */
147
147
  getLifecycleStatus(manifestCid: string): Promise<SolverNetLifecycleStatus | undefined>;
148
+ /**
149
+ * Returns the number of distinct operators that have *ever* claimed a task
150
+ * on the SolverNet identified by `manifestCid` — i.e. the count of unique
151
+ * `attempt.operator` Safe addresses across every task whose
152
+ * `manifestDigest === keccak256(manifestCid)`, **including tasks that are
153
+ * now finalized or refunded**.
154
+ *
155
+ * This is an *ever-participated* signal, not a "currently active" one. The
156
+ * count never filters on task lifecycle state: the on-chain backing reads
157
+ * raw `TaskAttemptCreated` logs, which carry no finalized/refunded flag, so
158
+ * the only count consistent across all three backings (HTTP / embedded /
159
+ * on-chain) is the all-time distinct-operator total. Treat it as "operators
160
+ * who have participated at least once", not "operators participating today".
161
+ *
162
+ * It is the protocol-observable participation signal: a "join" in the
163
+ * operator app is purely a local config write (`joinedSolverNets[<cid>]`,
164
+ * see `spec/2026-05-05-solvernet-creation-and-launch.md` §12) and leaves no
165
+ * on-chain footprint. An operator only becomes visible to the network once
166
+ * they claim a task — `TaskAttemptCreated` is the first on-chain event tied
167
+ * to (operator, SolverNet). This method therefore counts *participating*
168
+ * operators (operators who have claimed at least one task), which is the
169
+ * only honest cross-operator count derivable from the indexer / chain.
170
+ *
171
+ * Task pagination is hard-capped (`MAX_OPERATOR_COUNT_TASK_PAGES` in each
172
+ * backing) so a pathological task volume cannot turn this into an unbounded
173
+ * scan; on a SolverNet beyond the cap the count is a lower bound.
174
+ *
175
+ * Returns `0` when no operator has attempted a task on the SolverNet yet.
176
+ */
177
+ getSolverNetOperatorCount(manifestCid: string): Promise<number>;
148
178
  /**
149
179
  * Returns envelope refs matching the query. Refs only — byte retrieval is
150
180
  * done by the corpus library on demand.
@@ -200,7 +230,21 @@ export interface DiscoveryAPI {
200
230
  * The `withFallback` wrapper catches this class (plus network-shaped errors)
201
231
  * and routes to the floor implementation for the duration of the outage.
202
232
  */
233
+ /**
234
+ * Machine-readable reason a discovery read failed. `rpc_rate_limited` is the
235
+ * one branch callers act on distinctly: it means the configured RPC endpoint
236
+ * returned a 429 (or otherwise rate-limited the daemon), which — on the shared
237
+ * default RPC — is an operator-actionable condition ("add your own key"), not
238
+ * an indexer outage. Any other transport failure is left untyped (`undefined`).
239
+ */
240
+ export type DiscoveryUnavailableCode = 'rpc_rate_limited';
203
241
  export declare class DiscoveryUnavailableError extends Error {
204
242
  readonly cause?: unknown;
205
- constructor(message: string, cause?: unknown);
243
+ /**
244
+ * Typed reason, when one can be classified — currently only
245
+ * `rpc_rate_limited`, surfaced end-to-end so the operator UI can render a
246
+ * distinct "your RPC is throttled" message instead of a generic failure.
247
+ */
248
+ readonly code?: DiscoveryUnavailableCode;
249
+ constructor(message: string, cause?: unknown, code?: DiscoveryUnavailableCode);
206
250
  }
@@ -9,21 +9,19 @@
9
9
  *
10
10
  * Spec: spec/2026-05-11-discovery-api-and-shared-indexer.md §5.
11
11
  */
12
- // ── Error ────────────────────────────────────────────────────────────────────
13
- /**
14
- * Thrown by a DiscoveryAPI implementation when it is temporarily unable to
15
- * serve a request — e.g. indexer unreachable, embedded Ponder still syncing,
16
- * hosted subgraph 5xx.
17
- *
18
- * The `withFallback` wrapper catches this class (plus network-shaped errors)
19
- * and routes to the floor implementation for the duration of the outage.
20
- */
21
12
  export class DiscoveryUnavailableError extends Error {
22
13
  cause;
23
- constructor(message, cause) {
14
+ /**
15
+ * Typed reason, when one can be classified — currently only
16
+ * `rpc_rate_limited`, surfaced end-to-end so the operator UI can render a
17
+ * distinct "your RPC is throttled" message instead of a generic failure.
18
+ */
19
+ code;
20
+ constructor(message, cause, code) {
24
21
  super(message);
25
22
  this.name = 'DiscoveryUnavailableError';
26
23
  this.cause = cause;
24
+ this.code = code;
27
25
  }
28
26
  }
29
27
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/discovery/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgOH,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAChC,KAAK,CAAW;IAElC,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/discovery/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAkRH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAChC,KAAK,CAAW;IAClC;;;;OAIG;IACM,IAAI,CAA4B;IAEzC,YAAY,OAAe,EAAE,KAAe,EAAE,IAA+B;QAC3E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -12,6 +12,13 @@
12
12
  * operators can see why their daemon is running slowly. After the window
13
13
  * elapses the wrapper probes the primary again on the next call.
14
14
  *
15
+ * NOTE (2026-05-23): this wrapper is no longer engaged by default. The
16
+ * factory installs it only when `discovery.fallbackToOnchain === true` (an
17
+ * explicit opt-in). Without the opt-in, indexer outages propagate as
18
+ * DiscoveryUnavailableError so the operator-app surfaces them rather than the
19
+ * daemon silently storming shared RPC. The wrapper itself is unchanged for
20
+ * operators who still want it.
21
+ *
15
22
  * Spec: spec/2026-05-11-discovery-api-and-shared-indexer.md §9.3.
16
23
  */
17
24
  import type { DiscoveryAPI } from './types.js';
@@ -12,6 +12,13 @@
12
12
  * operators can see why their daemon is running slowly. After the window
13
13
  * elapses the wrapper probes the primary again on the next call.
14
14
  *
15
+ * NOTE (2026-05-23): this wrapper is no longer engaged by default. The
16
+ * factory installs it only when `discovery.fallbackToOnchain === true` (an
17
+ * explicit opt-in). Without the opt-in, indexer outages propagate as
18
+ * DiscoveryUnavailableError so the operator-app surfaces them rather than the
19
+ * daemon silently storming shared RPC. The wrapper itself is unchanged for
20
+ * operators who still want it.
21
+ *
15
22
  * Spec: spec/2026-05-11-discovery-api-and-shared-indexer.md §9.3.
16
23
  */
17
24
  import { DiscoveryUnavailableError } from './types.js';
@@ -145,6 +152,9 @@ export function withFallback(primary, floor, opts = {}) {
145
152
  getLifecycleStatus(manifestCid) {
146
153
  return dispatch(() => primary.getLifecycleStatus(manifestCid), () => floor.getLifecycleStatus(manifestCid));
147
154
  },
155
+ getSolverNetOperatorCount(manifestCid) {
156
+ return dispatch(() => primary.getSolverNetOperatorCount(manifestCid), () => floor.getSolverNetOperatorCount(manifestCid));
157
+ },
148
158
  queryEnvelopes(query) {
149
159
  return dispatch(() => primary.queryEnvelopes(query), () => floor.queryEnvelopes(query));
150
160
  },
@@ -1 +1 @@
1
- {"version":3,"file":"with-fallback.js","sourceRoot":"","sources":["../../src/discovery/with-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GA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C,IAAI,CAAC,CACvC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * Phase 1 (master): generate mnemonic → fund master EOA
5
5
  * Phase 2 (per-service): derive agent → stake → deploy mech
6
6
  */
7
- import type { FleetState, FleetBootstrapResult } from './types.js';
7
+ import type { FleetState, FleetBootstrapResult, StakingMode } from './types.js';
8
8
  import { requestTestnetFunding } from './faucet.js';
9
9
  import { type JinnOnchainNetwork } from './viem-clients.js';
10
10
  /**
@@ -16,33 +16,65 @@ import { type JinnOnchainNetwork } from './viem-clients.js';
16
16
  * ≈ 0.0046 ETH minimum; 2× gives ≈ 0.009–0.010 ETH — the bootstrap
17
17
  * `minEoaGasEth` default.
18
18
  *
19
- * The multiplier only applies when no service has a persisted `service_id`
20
- * on-chain (i.e. the fleet is truly cold — OR migration-wiped, where
21
- * services exist in shape but lost their on-chain anchor). Once any service
22
- * has committed a `service_id`, the fleet is past the cold-start cliff and
23
- * 1× suffices.
19
+ * Used by {@link stage1MinMasterEth} to size the Stage 1 master gas budget.
24
20
  *
25
21
  * Single source of truth: imported by funding-plan.ts.
26
22
  */
27
23
  export declare const STANDARD_MASTER_BOOTSTRAP_MULTIPLIER = 2n;
28
24
  /**
29
- * Compute the required master ETH gate for the standard staking mode.
25
+ * Self-bond mode needs much more ETH per service than standard mode because
26
+ * the master funds the agent which then pays for: Safe deploy, 5 service
27
+ * registry txs (create, activate, register, deploy, stake), and mech deploy.
28
+ * Roughly 15 txs at varying gas costs. 0.03 ETH per service is a safe
29
+ * estimate. Single source of truth: imported by funding-plan.ts.
30
+ */
31
+ export declare const SELF_BOND_ETH_PER_SERVICE = 30000000000000000n;
32
+ /**
33
+ * Single source of truth for the master-ETH cold-start funding gate.
34
+ *
35
+ * Both the mutating bootstrapper ({@link FleetBootstrapper.ensureStage1And2})
36
+ * and the read-only funding plan (`planFleetFunding` in funding-plan.ts) route
37
+ * through this helper, so a migration-wiped fleet computes an identical
38
+ * required-ETH gate in both views. Re-implementing the gate inline at either
39
+ * call site is the u34i cross-module invariant-drift hazard — do not do it.
40
+ *
41
+ * Standard-mode gate has three branches:
42
+ * 1. `standardFleetAlreadyComplete` — fleet already has its full target of
43
+ * operational services and no deprecated-setup migration is pending →
44
+ * `0n` (nothing to fund).
45
+ * 2. `preStage1` — no fleet identity yet (`fleet_stage === 'none'` or no
46
+ * fleet state at all) → the Stage 1 gate from {@link stage1MinMasterEth},
47
+ * which covers the master → agent transfer plus the master's own gas
48
+ * reserve. See jinn-mono-u34i.
49
+ * 3. otherwise — the Stage 2 master gas budget: `minEoaGasEth` (stake gas)
50
+ * plus a per-extra-service top-up transfer for services 2..N.
51
+ *
52
+ * Self-bond mode is a flat `SELF_BOND_ETH_PER_SERVICE × targetServices`
53
+ * regardless of stage.
30
54
  *
31
55
  * @param services Persisted service states
32
56
  * @param minEoaGasEth Configured minimum EOA gas target (wei)
33
- * @param standardMultiplier Cold-start multiplier (defaults to {@link STANDARD_MASTER_BOOTSTRAP_MULTIPLIER})
34
- * @param pendingSetupMigration True when deprecated testnet setup detected
57
+ * @param pendingSetupMigration True when a deprecated testnet setup is
58
+ * detected — suppresses the `standardFleetAlreadyComplete` short-circuit so a
59
+ * migration-wiped fleet is correctly treated as needing funding. Both call
60
+ * sites MUST pass this so the bootstrapper gate and the funding-plan view
61
+ * agree for migration-wiped fleets.
35
62
  * @param targetServices How many services the fleet is aiming for
63
+ * @param stakingMode `'standard'` (default) or `'self-bond'`
64
+ * @param preStage1 True when fleet identity is not yet provisioned —
65
+ * selects the Stage 1 gate. The bootstrapper passes `false` here because it
66
+ * only computes this gate *after* `ensureStage1` succeeds.
36
67
  */
37
- export declare function computeRequiredMasterEth({ services, minEoaGasEth, standardMultiplier, pendingSetupMigration, targetServices, }: {
68
+ export declare function computeRequiredMasterEth({ services, minEoaGasEth, pendingSetupMigration, targetServices, stakingMode, preStage1, }: {
38
69
  services: Array<{
39
- service_id: number | null | undefined;
70
+ service_id?: number | null | undefined;
40
71
  step?: string;
41
72
  }>;
42
73
  minEoaGasEth: bigint;
43
- standardMultiplier?: bigint;
44
74
  pendingSetupMigration?: boolean;
45
75
  targetServices?: number;
76
+ stakingMode?: StakingMode;
77
+ preStage1?: boolean;
46
78
  }): bigint;
47
79
  /** Master ETH required to FINISH the whole bootstrap from a fresh start (not
48
80
  * just to enter Stage 1). Centralized so the daemon's ensureStage1 gate,
@@ -34,36 +34,80 @@ const SAFE_TOKEN_BOOTSTRAP_MULTIPLIER = 2n;
34
34
  * ≈ 0.0046 ETH minimum; 2× gives ≈ 0.009–0.010 ETH — the bootstrap
35
35
  * `minEoaGasEth` default.
36
36
  *
37
- * The multiplier only applies when no service has a persisted `service_id`
38
- * on-chain (i.e. the fleet is truly cold — OR migration-wiped, where
39
- * services exist in shape but lost their on-chain anchor). Once any service
40
- * has committed a `service_id`, the fleet is past the cold-start cliff and
41
- * 1× suffices.
37
+ * Used by {@link stage1MinMasterEth} to size the Stage 1 master gas budget.
42
38
  *
43
39
  * Single source of truth: imported by funding-plan.ts.
44
40
  */
45
41
  export const STANDARD_MASTER_BOOTSTRAP_MULTIPLIER = 2n;
46
42
  /**
47
- * Compute the required master ETH gate for the standard staking mode.
43
+ * Self-bond mode needs much more ETH per service than standard mode because
44
+ * the master funds the agent which then pays for: Safe deploy, 5 service
45
+ * registry txs (create, activate, register, deploy, stake), and mech deploy.
46
+ * Roughly 15 txs at varying gas costs. 0.03 ETH per service is a safe
47
+ * estimate. Single source of truth: imported by funding-plan.ts.
48
+ */
49
+ export const SELF_BOND_ETH_PER_SERVICE = 30000000000000000n; // 0.03 ETH
50
+ /**
51
+ * Single source of truth for the master-ETH cold-start funding gate.
52
+ *
53
+ * Both the mutating bootstrapper ({@link FleetBootstrapper.ensureStage1And2})
54
+ * and the read-only funding plan (`planFleetFunding` in funding-plan.ts) route
55
+ * through this helper, so a migration-wiped fleet computes an identical
56
+ * required-ETH gate in both views. Re-implementing the gate inline at either
57
+ * call site is the u34i cross-module invariant-drift hazard — do not do it.
58
+ *
59
+ * Standard-mode gate has three branches:
60
+ * 1. `standardFleetAlreadyComplete` — fleet already has its full target of
61
+ * operational services and no deprecated-setup migration is pending →
62
+ * `0n` (nothing to fund).
63
+ * 2. `preStage1` — no fleet identity yet (`fleet_stage === 'none'` or no
64
+ * fleet state at all) → the Stage 1 gate from {@link stage1MinMasterEth},
65
+ * which covers the master → agent transfer plus the master's own gas
66
+ * reserve. See jinn-mono-u34i.
67
+ * 3. otherwise — the Stage 2 master gas budget: `minEoaGasEth` (stake gas)
68
+ * plus a per-extra-service top-up transfer for services 2..N.
69
+ *
70
+ * Self-bond mode is a flat `SELF_BOND_ETH_PER_SERVICE × targetServices`
71
+ * regardless of stage.
48
72
  *
49
73
  * @param services Persisted service states
50
74
  * @param minEoaGasEth Configured minimum EOA gas target (wei)
51
- * @param standardMultiplier Cold-start multiplier (defaults to {@link STANDARD_MASTER_BOOTSTRAP_MULTIPLIER})
52
- * @param pendingSetupMigration True when deprecated testnet setup detected
75
+ * @param pendingSetupMigration True when a deprecated testnet setup is
76
+ * detected — suppresses the `standardFleetAlreadyComplete` short-circuit so a
77
+ * migration-wiped fleet is correctly treated as needing funding. Both call
78
+ * sites MUST pass this so the bootstrapper gate and the funding-plan view
79
+ * agree for migration-wiped fleets.
53
80
  * @param targetServices How many services the fleet is aiming for
81
+ * @param stakingMode `'standard'` (default) or `'self-bond'`
82
+ * @param preStage1 True when fleet identity is not yet provisioned —
83
+ * selects the Stage 1 gate. The bootstrapper passes `false` here because it
84
+ * only computes this gate *after* `ensureStage1` succeeds.
54
85
  */
55
- export function computeRequiredMasterEth({ services, minEoaGasEth, standardMultiplier = STANDARD_MASTER_BOOTSTRAP_MULTIPLIER, pendingSetupMigration = false, targetServices = 1, }) {
56
- const completedCount = services.filter(s => s.step !== undefined && isOperationalServiceStep(s.step)).length;
57
- const standardFleetAlreadyComplete = !pendingSetupMigration && completedCount >= targetServices;
86
+ export function computeRequiredMasterEth({ services, minEoaGasEth, pendingSetupMigration = false, targetServices = 1, stakingMode = 'standard', preStage1 = false, }) {
87
+ if (stakingMode !== 'standard') {
88
+ return SELF_BOND_ETH_PER_SERVICE * BigInt(targetServices);
89
+ }
90
+ // Reconciled `standardFleetAlreadyComplete` — a single definition replacing
91
+ // the three historic inline variants. Adopts the strictest of them (the
92
+ // FleetBootstrapper variant): the fleet must have at least `targetServices`
93
+ // rows AND every row must be operational AND no deprecated-setup migration
94
+ // may be pending. A migration-wiped fleet (which sets
95
+ // `pendingSetupMigration`) is therefore never short-circuited to `0n`.
96
+ const standardFleetAlreadyComplete = services.length >= targetServices &&
97
+ services.every(s => s.step !== undefined && isOperationalServiceStep(s.step)) &&
98
+ !pendingSetupMigration;
58
99
  if (standardFleetAlreadyComplete)
59
100
  return 0n;
60
- // "Cold in liability" = no service has an on-chain anchor yet.
61
- // This includes:
62
- // 1. Fresh fleet (services array is empty)
63
- // 2. Migration-wiped fleet (services exist in shape but service_id === null)
64
- // Apply the 2× headroom multiplier in both cases.
65
- const hasPersistedOnChain = services.some(s => s.service_id != null);
66
- return minEoaGasEth * (hasPersistedOnChain ? 1n : standardMultiplier);
101
+ if (preStage1) {
102
+ // Stage 1 gate: master → agent transfer (STAGE1_AGENT_ETH) + the master's
103
+ // own gas reserve, plus per-extra-service transfers. See jinn-mono-u34i.
104
+ return stage1MinMasterEth({ minEoaGasEth }, targetServices);
105
+ }
106
+ // Stage 2 master gas budget — covers distributor.stake() (~0.003 ETH at
107
+ // typical 6 gwei Base Sepolia) plus per-extra-service top-up transfers.
108
+ // Service 1 piggybacks on HD-1's Stage 1 funding, so the base term is a
109
+ // single `minEoaGasEth` (not `× 2`). See jinn-mono-u34i.
110
+ return minEoaGasEth + minEoaGasEth * BigInt(Math.max(0, targetServices - 1));
67
111
  }
68
112
  /** Master ETH required to FINISH the whole bootstrap from a fresh start (not
69
113
  * just to enter Stage 1). Centralized so the daemon's ensureStage1 gate,
@@ -429,12 +473,8 @@ export class FleetBootstrapper {
429
473
  // Phase 1b: Check master funding for the full operator path.
430
474
  const masterAddress = state.master_address;
431
475
  let masterBalance = await this.publicClient.getBalance({ address: masterAddress });
432
- // Self-bond mode needs much more ETH than standard mode because the master
433
- // funds the agent which then pays for: Safe deploy, 5 service registry txs
434
- // (create, activate, register, deploy, stake), and mech deploy. Roughly
435
- // 15 txs at varying gas costs. 0.03 ETH per service is a safe estimate.
436
- // On re-runs, include ETH already held by funded agents/safes in the total.
437
- const SELF_BOND_ETH_PER_SERVICE = 30000000000000000n; // 0.03 ETH
476
+ // On re-runs, include ETH already held by funded agents/safes in the
477
+ // total for self-bond mode.
438
478
  let systemEth = masterBalance;
439
479
  if (this.stakingMode === 'self-bond') {
440
480
  for (const svc of state.services) {
@@ -456,25 +496,20 @@ export class FleetBootstrapper {
456
496
  stakingMode: this.stakingMode,
457
497
  currentStakingContract: this.config.stakingContract,
458
498
  }).services.length > 0;
459
- const standardFleetAlreadyComplete = this.stakingMode === 'standard' &&
460
- state.services.length >= this.targetServices &&
461
- state.services.every(svc => svc.step !== undefined && isOperationalServiceStep(svc.step)) &&
462
- !pendingSetupMigration;
463
- const requiredMasterEth = this.stakingMode === 'standard'
464
- ? (standardFleetAlreadyComplete
465
- ? 0n
466
- // Stage 2 master gas budget — covers distributor.stake() (~0.003
467
- // ETH at typical 6 gwei Base Sepolia) plus per-extra-service
468
- // top-up transfers. Previously this was `× 2` for fresh fleets,
469
- // which double-counted a service-1 transfer that doesn't actually
470
- // fire (HD-1 carries Stage 1 leftover, gets a conditional top-up
471
- // only if needed). See jinn-mono-u34i: the `× 2` figure also
472
- // exceeded the post-Stage-1 master balance at the operator-facing
473
- // 0.020 ETH budget by ~127k gwei of Stage 1 gas burn, causing a
474
- // second funding prompt.
475
- : this.config.minEoaGasEth +
476
- this.config.minEoaGasEth * BigInt(Math.max(0, this.targetServices - 1)))
477
- : SELF_BOND_ETH_PER_SERVICE * BigInt(this.targetServices);
499
+ // Single source of truth: the master-ETH gate is computed by
500
+ // `computeRequiredMasterEth` (defined above), the same helper the
501
+ // read-only `planFleetFunding` view routes through. Re-deriving it inline
502
+ // here is the u34i cross-module invariant-drift hazard. `ensureStage1And2`
503
+ // only reaches this point AFTER `ensureStage1` has succeeded, so the
504
+ // fleet is always past Stage 1 — `preStage1` is `false`.
505
+ const requiredMasterEth = computeRequiredMasterEth({
506
+ services: state.services,
507
+ minEoaGasEth: this.config.minEoaGasEth,
508
+ pendingSetupMigration,
509
+ targetServices: this.targetServices,
510
+ stakingMode: this.stakingMode,
511
+ preStage1: false,
512
+ });
478
513
  const autoFaucetEnabled = this.autoTestnetFaucet;
479
514
  // Re-sum system ETH (master + agent/safe balances for self-bond mode).
480
515
  // Hoisted so the drip loop below can refresh cheaply.
@@ -1098,16 +1133,23 @@ export class FleetBootstrapper {
1098
1133
  // calling stake() again would revert with AgentInstanceRegistered (selector 0x631695bd)
1099
1134
  // and there is nothing useful the operator can do without rotating the agent EOA.
1100
1135
  // Fail fast with a typed error instead of letting the contract revert.
1136
+ //
1137
+ // ServiceRegistryL2 exposes the `mapAgentInstanceOperators(address) → address` mapping:
1138
+ // it returns the operator address that registered the given agent instance, or the
1139
+ // zero address when no operator has bound that instance. A non-zero return means the
1140
+ // EOA is already bound. (There is no `mapAgentInstances(address) → uint256` getter on
1141
+ // the deployed registry — an earlier draft of this guard referenced one and was a
1142
+ // permanent no-op.)
1101
1143
  if (svc.agent_address && svc.service_id === null && this.config.serviceRegistry) {
1102
1144
  let alreadyBound = false;
1103
1145
  try {
1104
- const boundServiceId = (await this.publicClient.readContract({
1146
+ const boundOperator = (await this.publicClient.readContract({
1105
1147
  address: getAddress(this.config.serviceRegistry),
1106
1148
  abi: SERVICE_REGISTRY_L2_ABI,
1107
- functionName: 'mapAgentInstances',
1149
+ functionName: 'mapAgentInstanceOperators',
1108
1150
  args: [getAddress(svc.agent_address)],
1109
1151
  }));
1110
- alreadyBound = boundServiceId > 0n;
1152
+ alreadyBound = boundOperator !== '0x0000000000000000000000000000000000000000';
1111
1153
  }
1112
1154
  catch {
1113
1155
  // Registry read failure is non-fatal — proceed and let stake() surface