@jinn-network/client 0.1.1 → 0.1.2-canary.d6e72dfd

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 (317) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/CONTRIBUTING.md +123 -0
  3. package/README.md +210 -37
  4. package/deployments/deployment-claim-registry-baseSepolia.json +13 -0
  5. package/deployments/deployment-jinn-testnet-faucet-baseSepolia-fast.json +15 -0
  6. package/dist/adapters/claim-registry/abi.d.ts +127 -0
  7. package/dist/adapters/claim-registry/abi.js +93 -0
  8. package/dist/adapters/claim-registry/abi.js.map +1 -0
  9. package/dist/adapters/claim-registry/client.d.ts +89 -0
  10. package/dist/adapters/claim-registry/client.js +205 -0
  11. package/dist/adapters/claim-registry/client.js.map +1 -0
  12. package/dist/adapters/mech/adapter.d.ts +1 -0
  13. package/dist/adapters/mech/adapter.js +75 -41
  14. package/dist/adapters/mech/adapter.js.map +1 -1
  15. package/dist/adapters/mech/contracts.d.ts +2 -0
  16. package/dist/adapters/mech/contracts.js +57 -7
  17. package/dist/adapters/mech/contracts.js.map +1 -1
  18. package/dist/adapters/mech/ipfs.d.ts +8 -0
  19. package/dist/adapters/mech/ipfs.js +12 -0
  20. package/dist/adapters/mech/ipfs.js.map +1 -1
  21. package/dist/adapters/mech/types.d.ts +20 -46
  22. package/dist/adapters/mech/types.js +16 -35
  23. package/dist/adapters/mech/types.js.map +1 -1
  24. package/dist/api/gather-status.d.ts +1 -0
  25. package/dist/api/gather-status.js +33 -1
  26. package/dist/api/gather-status.js.map +1 -1
  27. package/dist/api/portfolio-v0-build.d.ts +81 -0
  28. package/dist/api/portfolio-v0-build.js +141 -0
  29. package/dist/api/portfolio-v0-build.js.map +1 -0
  30. package/dist/api/portfolio-v0-doctor.d.ts +37 -0
  31. package/dist/api/portfolio-v0-doctor.js +123 -0
  32. package/dist/api/portfolio-v0-doctor.js.map +1 -0
  33. package/dist/api/rewards-build.js +1 -1
  34. package/dist/api/rewards-build.js.map +1 -1
  35. package/dist/api/status-build.d.ts +7 -0
  36. package/dist/api/status-build.js +1 -0
  37. package/dist/api/status-build.js.map +1 -1
  38. package/dist/bin/jinn-mcp.d.ts +0 -12
  39. package/dist/bin/jinn-mcp.js +5 -14
  40. package/dist/bin/jinn-mcp.js.map +1 -1
  41. package/dist/build-meta.json +1 -1
  42. package/dist/cli/commands/auth.js +115 -25
  43. package/dist/cli/commands/auth.js.map +1 -1
  44. package/dist/cli/commands/bootstrap.js +1 -0
  45. package/dist/cli/commands/bootstrap.js.map +1 -1
  46. package/dist/cli/commands/doctor.js +130 -14
  47. package/dist/cli/commands/doctor.js.map +1 -1
  48. package/dist/cli/commands/fleet-scale.js +1 -0
  49. package/dist/cli/commands/fleet-scale.js.map +1 -1
  50. package/dist/cli/commands/fund-requirements.js +2 -0
  51. package/dist/cli/commands/fund-requirements.js.map +1 -1
  52. package/dist/cli/commands/intents.d.ts +17 -0
  53. package/dist/cli/commands/intents.js +489 -0
  54. package/dist/cli/commands/intents.js.map +1 -0
  55. package/dist/cli/commands/keys-backup.js +13 -11
  56. package/dist/cli/commands/keys-backup.js.map +1 -1
  57. package/dist/cli/commands/mcp.d.ts +3 -0
  58. package/dist/cli/commands/mcp.js +19 -0
  59. package/dist/cli/commands/mcp.js.map +1 -0
  60. package/dist/cli/commands/plugin-install.js +8 -4
  61. package/dist/cli/commands/plugin-install.js.map +1 -1
  62. package/dist/cli/commands/quickstart.js +60 -4
  63. package/dist/cli/commands/quickstart.js.map +1 -1
  64. package/dist/cli/commands/rewards.js +27 -1
  65. package/dist/cli/commands/rewards.js.map +1 -1
  66. package/dist/cli/commands/submit-intent.js +108 -5
  67. package/dist/cli/commands/submit-intent.js.map +1 -1
  68. package/dist/cli/commands/version.js +1 -0
  69. package/dist/cli/commands/version.js.map +1 -1
  70. package/dist/cli/deployment-digest.js +5 -0
  71. package/dist/cli/deployment-digest.js.map +1 -1
  72. package/dist/cli/execution-context.js +1 -0
  73. package/dist/cli/execution-context.js.map +1 -1
  74. package/dist/cli/index.js +4 -0
  75. package/dist/cli/index.js.map +1 -1
  76. package/dist/cli/intent-registry-access.d.ts +64 -0
  77. package/dist/cli/intent-registry-access.js +187 -0
  78. package/dist/cli/intent-registry-access.js.map +1 -0
  79. package/dist/cli/introspection-context.js +1 -0
  80. package/dist/cli/introspection-context.js.map +1 -1
  81. package/dist/cli/password.d.ts +21 -9
  82. package/dist/cli/password.js +45 -24
  83. package/dist/cli/password.js.map +1 -1
  84. package/dist/config.d.ts +110 -8
  85. package/dist/config.js +41 -12
  86. package/dist/config.js.map +1 -1
  87. package/dist/daemon/creator.d.ts +7 -1
  88. package/dist/daemon/creator.js +38 -3
  89. package/dist/daemon/creator.js.map +1 -1
  90. package/dist/daemon/daemon.d.ts +43 -0
  91. package/dist/daemon/daemon.js +87 -2
  92. package/dist/daemon/daemon.js.map +1 -1
  93. package/dist/earning/bootstrap.d.ts +2 -1
  94. package/dist/earning/bootstrap.js +72 -4
  95. package/dist/earning/bootstrap.js.map +1 -1
  96. package/dist/earning/contracts.d.ts +10 -0
  97. package/dist/earning/contracts.js +24 -0
  98. package/dist/earning/contracts.js.map +1 -1
  99. package/dist/earning/jinn-rewards.d.ts +9 -0
  100. package/dist/earning/jinn-rewards.js +7 -0
  101. package/dist/earning/jinn-rewards.js.map +1 -1
  102. package/dist/intents/prediction-apy-v0-auto.d.ts +11 -0
  103. package/dist/intents/prediction-apy-v0-auto.js +46 -0
  104. package/dist/intents/prediction-apy-v0-auto.js.map +1 -0
  105. package/dist/intents/prediction-apy-v0-template.d.ts +8 -0
  106. package/dist/intents/prediction-apy-v0-template.js +22 -0
  107. package/dist/intents/prediction-apy-v0-template.js.map +1 -0
  108. package/dist/intents/prediction-v0-auto.d.ts +53 -0
  109. package/dist/intents/prediction-v0-auto.js +84 -0
  110. package/dist/intents/prediction-v0-auto.js.map +1 -0
  111. package/dist/intents/prediction-v0-template.d.ts +65 -0
  112. package/dist/intents/prediction-v0-template.js +125 -0
  113. package/dist/intents/prediction-v0-template.js.map +1 -0
  114. package/dist/main.js +149 -1
  115. package/dist/main.js.map +1 -1
  116. package/dist/mcp/operator-server.d.ts +1 -1
  117. package/dist/mcp/operator-server.js +1 -1
  118. package/dist/preflight/claude-auth.d.ts +12 -1
  119. package/dist/preflight/claude-auth.js +21 -3
  120. package/dist/preflight/claude-auth.js.map +1 -1
  121. package/dist/restorer/engine/canonical-json.d.ts +18 -0
  122. package/dist/restorer/engine/canonical-json.js +59 -0
  123. package/dist/restorer/engine/canonical-json.js.map +1 -0
  124. package/dist/restorer/engine/claim.d.ts +69 -0
  125. package/dist/restorer/engine/claim.js +104 -0
  126. package/dist/restorer/engine/claim.js.map +1 -0
  127. package/dist/restorer/engine/delivery.d.ts +52 -0
  128. package/dist/restorer/engine/delivery.js +63 -0
  129. package/dist/restorer/engine/delivery.js.map +1 -0
  130. package/dist/restorer/engine/engine.d.ts +203 -0
  131. package/dist/restorer/engine/engine.js +753 -0
  132. package/dist/restorer/engine/engine.js.map +1 -0
  133. package/dist/restorer/engine/manifest-assembly.d.ts +67 -0
  134. package/dist/restorer/engine/manifest-assembly.js +79 -0
  135. package/dist/restorer/engine/manifest-assembly.js.map +1 -0
  136. package/dist/restorer/engine/packaging.d.ts +87 -0
  137. package/dist/restorer/engine/packaging.js +350 -0
  138. package/dist/restorer/engine/packaging.js.map +1 -0
  139. package/dist/restorer/engine/persistence.d.ts +170 -0
  140. package/dist/restorer/engine/persistence.js +381 -0
  141. package/dist/restorer/engine/persistence.js.map +1 -0
  142. package/dist/restorer/engine/recovery.d.ts +22 -0
  143. package/dist/restorer/engine/recovery.js +24 -0
  144. package/dist/restorer/engine/recovery.js.map +1 -0
  145. package/dist/restorer/engine/registry.d.ts +62 -0
  146. package/dist/restorer/engine/registry.js +73 -0
  147. package/dist/restorer/engine/registry.js.map +1 -0
  148. package/dist/restorer/engine/signing.d.ts +30 -0
  149. package/dist/restorer/engine/signing.js +39 -0
  150. package/dist/restorer/engine/signing.js.map +1 -0
  151. package/dist/restorer/engine/state.d.ts +42 -0
  152. package/dist/restorer/engine/state.js +87 -0
  153. package/dist/restorer/engine/state.js.map +1 -0
  154. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.d.ts +64 -0
  155. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.js +96 -0
  156. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.js.map +1 -0
  157. package/dist/restorer/impls/claude-mcp-hyperliquid/index.d.ts +101 -0
  158. package/dist/restorer/impls/claude-mcp-hyperliquid/index.js +710 -0
  159. package/dist/restorer/impls/claude-mcp-hyperliquid/index.js.map +1 -0
  160. package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.d.ts +137 -0
  161. package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.js +865 -0
  162. package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.js.map +1 -0
  163. package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.d.ts +74 -0
  164. package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.js +74 -0
  165. package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.js.map +1 -0
  166. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.d.ts +97 -0
  167. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js +226 -0
  168. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js.map +1 -0
  169. package/dist/restorer/impls/claude-mcp-prediction/index.d.ts +43 -0
  170. package/dist/restorer/impls/claude-mcp-prediction/index.js +230 -0
  171. package/dist/restorer/impls/claude-mcp-prediction/index.js.map +1 -0
  172. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.d.ts +38 -0
  173. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js +135 -0
  174. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js.map +1 -0
  175. package/dist/restorer/impls/claude-mcp-prediction/prompt.d.ts +8 -0
  176. package/dist/restorer/impls/claude-mcp-prediction/prompt.js +54 -0
  177. package/dist/restorer/impls/claude-mcp-prediction/prompt.js.map +1 -0
  178. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.d.ts +36 -0
  179. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js +137 -0
  180. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js.map +1 -0
  181. package/dist/restorer/impls/claude-mcp-prediction/types.d.ts +82 -0
  182. package/dist/restorer/impls/claude-mcp-prediction/types.js +6 -0
  183. package/dist/restorer/impls/claude-mcp-prediction/types.js.map +1 -0
  184. package/dist/restorer/impls/legacy-claude/index.d.ts +45 -0
  185. package/dist/restorer/impls/legacy-claude/index.js +71 -0
  186. package/dist/restorer/impls/legacy-claude/index.js.map +1 -0
  187. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.d.ts +68 -0
  188. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js +117 -0
  189. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js.map +1 -0
  190. package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.d.ts +49 -0
  191. package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.js +91 -0
  192. package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.js.map +1 -0
  193. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.d.ts +78 -0
  194. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js +274 -0
  195. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js.map +1 -0
  196. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.d.ts +23 -0
  197. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js +49 -0
  198. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js.map +1 -0
  199. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.d.ts +25 -0
  200. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js +44 -0
  201. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js.map +1 -0
  202. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.d.ts +17 -0
  203. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js +43 -0
  204. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js.map +1 -0
  205. package/dist/restorer/impls/portfolio-v0-evaluator/index.d.ts +43 -0
  206. package/dist/restorer/impls/portfolio-v0-evaluator/index.js +431 -0
  207. package/dist/restorer/impls/portfolio-v0-evaluator/index.js.map +1 -0
  208. package/dist/restorer/impls/portfolio-v0-evaluator/score.d.ts +21 -0
  209. package/dist/restorer/impls/portfolio-v0-evaluator/score.js +32 -0
  210. package/dist/restorer/impls/portfolio-v0-evaluator/score.js.map +1 -0
  211. package/dist/restorer/impls/portfolio-v0-evaluator/types.d.ts +32 -0
  212. package/dist/restorer/impls/portfolio-v0-evaluator/types.js +8 -0
  213. package/dist/restorer/impls/portfolio-v0-evaluator/types.js.map +1 -0
  214. package/dist/restorer/impls/prediction-apy-v0-baseline/index.d.ts +39 -0
  215. package/dist/restorer/impls/prediction-apy-v0-baseline/index.js +98 -0
  216. package/dist/restorer/impls/prediction-apy-v0-baseline/index.js.map +1 -0
  217. package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.d.ts +2 -0
  218. package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.js +7 -0
  219. package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.js.map +1 -0
  220. package/dist/restorer/impls/prediction-apy-v0-baseline/types.d.ts +4 -0
  221. package/dist/restorer/impls/prediction-apy-v0-baseline/types.js +2 -0
  222. package/dist/restorer/impls/prediction-apy-v0-baseline/types.js.map +1 -0
  223. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.d.ts +2 -0
  224. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js +7 -0
  225. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js.map +1 -0
  226. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.d.ts +39 -0
  227. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js +186 -0
  228. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js.map +1 -0
  229. package/dist/restorer/impls/prediction-apy-v0-evaluator/score.d.ts +9 -0
  230. package/dist/restorer/impls/prediction-apy-v0-evaluator/score.js +20 -0
  231. package/dist/restorer/impls/prediction-apy-v0-evaluator/score.js.map +1 -0
  232. package/dist/restorer/impls/prediction-apy-v0-evaluator/types.d.ts +7 -0
  233. package/dist/restorer/impls/prediction-apy-v0-evaluator/types.js +2 -0
  234. package/dist/restorer/impls/prediction-apy-v0-evaluator/types.js.map +1 -0
  235. package/dist/restorer/impls/prediction-v0-baseline/index.d.ts +29 -0
  236. package/dist/restorer/impls/prediction-v0-baseline/index.js +94 -0
  237. package/dist/restorer/impls/prediction-v0-baseline/index.js.map +1 -0
  238. package/dist/restorer/impls/prediction-v0-baseline/strategy.d.ts +8 -0
  239. package/dist/restorer/impls/prediction-v0-baseline/strategy.js +41 -0
  240. package/dist/restorer/impls/prediction-v0-baseline/strategy.js.map +1 -0
  241. package/dist/restorer/impls/prediction-v0-baseline/types.d.ts +7 -0
  242. package/dist/restorer/impls/prediction-v0-baseline/types.js +2 -0
  243. package/dist/restorer/impls/prediction-v0-baseline/types.js.map +1 -0
  244. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.d.ts +20 -0
  245. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.js +66 -0
  246. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.js.map +1 -0
  247. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.d.ts +9 -0
  248. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.js +23 -0
  249. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.js.map +1 -0
  250. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.d.ts +3 -0
  251. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.js +13 -0
  252. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.js.map +1 -0
  253. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.d.ts +7 -0
  254. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js +93 -0
  255. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js.map +1 -0
  256. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.d.ts +5 -0
  257. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.js +20 -0
  258. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.js.map +1 -0
  259. package/dist/restorer/impls/prediction-v0-evaluator/index.d.ts +33 -0
  260. package/dist/restorer/impls/prediction-v0-evaluator/index.js +208 -0
  261. package/dist/restorer/impls/prediction-v0-evaluator/index.js.map +1 -0
  262. package/dist/restorer/impls/prediction-v0-evaluator/score.d.ts +8 -0
  263. package/dist/restorer/impls/prediction-v0-evaluator/score.js +15 -0
  264. package/dist/restorer/impls/prediction-v0-evaluator/score.js.map +1 -0
  265. package/dist/restorer/impls/prediction-v0-evaluator/types.d.ts +7 -0
  266. package/dist/restorer/impls/prediction-v0-evaluator/types.js +2 -0
  267. package/dist/restorer/impls/prediction-v0-evaluator/types.js.map +1 -0
  268. package/dist/restorer/types.d.ts +177 -0
  269. package/dist/restorer/types.js +7 -0
  270. package/dist/restorer/types.js.map +1 -0
  271. package/dist/store/store.d.ts +3 -1
  272. package/dist/store/store.js +3 -0
  273. package/dist/store/store.js.map +1 -1
  274. package/dist/types/desired-state.d.ts +53 -0
  275. package/dist/types/desired-state.js +20 -0
  276. package/dist/types/desired-state.js.map +1 -1
  277. package/dist/types/index.d.ts +4 -1
  278. package/dist/types/index.js +4 -1
  279. package/dist/types/index.js.map +1 -1
  280. package/dist/types/portfolio.d.ts +1000 -0
  281. package/dist/types/portfolio.js +168 -0
  282. package/dist/types/portfolio.js.map +1 -0
  283. package/dist/types/prediction-apy.d.ts +919 -0
  284. package/dist/types/prediction-apy.js +121 -0
  285. package/dist/types/prediction-apy.js.map +1 -0
  286. package/dist/types/prediction.d.ts +925 -0
  287. package/dist/types/prediction.js +140 -0
  288. package/dist/types/prediction.js.map +1 -0
  289. package/dist/venues/aave-v3/addresses.d.ts +6 -0
  290. package/dist/venues/aave-v3/addresses.js +19 -0
  291. package/dist/venues/aave-v3/addresses.js.map +1 -0
  292. package/dist/venues/aave-v3/client.d.ts +81 -0
  293. package/dist/venues/aave-v3/client.js +97 -0
  294. package/dist/venues/aave-v3/client.js.map +1 -0
  295. package/dist/venues/chainlink/client.d.ts +99 -0
  296. package/dist/venues/chainlink/client.js +130 -0
  297. package/dist/venues/chainlink/client.js.map +1 -0
  298. package/dist/venues/chainlink/feeds.d.ts +8 -0
  299. package/dist/venues/chainlink/feeds.js +9 -0
  300. package/dist/venues/chainlink/feeds.js.map +1 -0
  301. package/dist/venues/hyperliquid/account-value.d.ts +30 -0
  302. package/dist/venues/hyperliquid/account-value.js +30 -0
  303. package/dist/venues/hyperliquid/account-value.js.map +1 -0
  304. package/dist/venues/hyperliquid/client.d.ts +63 -0
  305. package/dist/venues/hyperliquid/client.js +135 -0
  306. package/dist/venues/hyperliquid/client.js.map +1 -0
  307. package/dist/venues/hyperliquid/grid.d.ts +36 -0
  308. package/dist/venues/hyperliquid/grid.js +61 -0
  309. package/dist/venues/hyperliquid/grid.js.map +1 -0
  310. package/dist/venues/hyperliquid/types.d.ts +81 -0
  311. package/dist/venues/hyperliquid/types.js +8 -0
  312. package/dist/venues/hyperliquid/types.js.map +1 -0
  313. package/dist/withdraw/run-withdraw-plan.js +2 -0
  314. package/dist/withdraw/run-withdraw-plan.js.map +1 -1
  315. package/docker-compose.yml +44 -0
  316. package/package.json +12 -1
  317. package/skills/jinn-operator/SKILL.md +85 -0
@@ -0,0 +1,140 @@
1
+ /**
2
+ * prediction.v0 — typed intent spec, submission manifest, verdict manifest.
3
+ *
4
+ * §4 of spec/2026-04-20-prediction-v0-pis-phase-1-design.md
5
+ */
6
+ import { z } from 'zod';
7
+ import { WindowSchema } from './desired-state.js';
8
+ const HexStringSchema = z.string().regex(/^0x[0-9a-fA-F]*$/, 'must be a 0x-prefixed hex string');
9
+ const SignatureSchema = z.object({
10
+ algo: z.literal('secp256k1'),
11
+ signer: HexStringSchema,
12
+ hash: HexStringSchema,
13
+ sig: HexStringSchema,
14
+ });
15
+ const IntentProvenanceSchema = z.object({
16
+ cid: z.string().min(1),
17
+ onchainCreationTx: HexStringSchema,
18
+ onchainCreationBlock: z.number().int(),
19
+ requestId: HexStringSchema,
20
+ });
21
+ const ParticipantSchema = z.object({
22
+ safeAddress: HexStringSchema,
23
+ agentEoa: HexStringSchema,
24
+ });
25
+ // ── Question kinds ────────────────────────────────────────────────────────────
26
+ const ThresholdQuestionSchema = z.object({
27
+ kind: z.literal('threshold'),
28
+ operator: z.enum(['GT', 'GTE', 'LT', 'LTE']),
29
+ threshold: z.string(),
30
+ resolveTs: z.number().int(),
31
+ });
32
+ const RangeQuestionSchema = z.object({
33
+ kind: z.literal('range'),
34
+ lowerBound: z.string(),
35
+ upperBound: z.string(),
36
+ resolveTs: z.number().int(),
37
+ });
38
+ // ── Spec + eligibility + intent ────────────────────────────────────────────────
39
+ export const PredictionV0SpecSchema = z.object({
40
+ kind: z.literal('prediction.v0'),
41
+ oracle: z.object({
42
+ venue: z.enum(['chainlink-base-sepolia', 'chainlink-base']),
43
+ feed: HexStringSchema,
44
+ feedDescription: z.string(),
45
+ }),
46
+ question: z.discriminatedUnion('kind', [ThresholdQuestionSchema, RangeQuestionSchema]),
47
+ });
48
+ export const PredictionV0EligibilitySchema = z.object({
49
+ maxSubmissionDelayMs: z.number().int().default(60_000),
50
+ });
51
+ export const PredictionV0IntentSchema = z
52
+ .object({
53
+ id: z.string(),
54
+ description: z.string().min(1),
55
+ window: WindowSchema,
56
+ spec: PredictionV0SpecSchema,
57
+ eligibility: PredictionV0EligibilitySchema.default({}),
58
+ })
59
+ .refine(d => d.window.endTs > d.window.startTs, {
60
+ message: 'window.endTs must be > window.startTs',
61
+ path: ['window'],
62
+ })
63
+ .refine(d => d.window.endTs - d.window.startTs >= 60_000, {
64
+ message: 'window must be at least 1 minute',
65
+ path: ['window'],
66
+ })
67
+ .refine(d => d.window.endTs - d.window.startTs <= 86_400_000, {
68
+ message: 'window must be at most 24 hours',
69
+ path: ['window'],
70
+ })
71
+ .refine(d => d.spec.question.resolveTs >= d.window.endTs, {
72
+ message: 'resolveTs must be ≥ window.endTs',
73
+ path: ['spec', 'question', 'resolveTs'],
74
+ })
75
+ .refine(d => d.spec.question.resolveTs - d.window.endTs <= 3_600_000, {
76
+ message: 'resolve gap (resolveTs - endTs) must be ≤ 1 hour',
77
+ path: ['spec', 'question', 'resolveTs'],
78
+ });
79
+ // ── Submission manifest ───────────────────────────────────────────────────────
80
+ export const PredictionSubmissionManifestSchema = z.object({
81
+ schemaVersion: z.literal('prediction.v0.submission.v1'),
82
+ generatedAt: z.number().int(),
83
+ intent: IntentProvenanceSchema,
84
+ restorer: ParticipantSchema,
85
+ window: WindowSchema,
86
+ prediction: z.object({
87
+ probability: z.string().regex(/^(0(\.\d+)?|1(\.0+)?)$/, 'must be a decimal in [0,1]'),
88
+ submittedAt: z.number().int(),
89
+ modelId: z.string().min(1),
90
+ }),
91
+ oracleSnapshot: z
92
+ .object({
93
+ feed: HexStringSchema,
94
+ roundId: z.string(),
95
+ answer: z.string(),
96
+ updatedAt: z.number().int(),
97
+ })
98
+ .optional(),
99
+ rationale: z
100
+ .array(z.object({
101
+ ts: z.number().int(),
102
+ note: z.string(),
103
+ }))
104
+ .optional(),
105
+ signature: SignatureSchema,
106
+ });
107
+ // ── Verdict manifest ──────────────────────────────────────────────────────────
108
+ const CheckSchema = z.object({
109
+ name: z.string(),
110
+ status: z.enum(['PASS', 'FAIL', 'SKIP']),
111
+ detail: z.union([z.string(), z.record(z.unknown())]).optional(),
112
+ });
113
+ export const PredictionVerdictManifestSchema = z.object({
114
+ schemaVersion: z.literal('prediction.v0.verdict.v1'),
115
+ generatedAt: z.number().int(),
116
+ intent: IntentProvenanceSchema,
117
+ evaluator: ParticipantSchema,
118
+ window: WindowSchema,
119
+ verdict: z.enum(['PASS', 'FAIL', 'REJECTED', 'INDETERMINATE']),
120
+ score: z.string(),
121
+ scoreBasis: z.literal('brier.v1'),
122
+ scoreVersion: z.string(),
123
+ oracleReading: z.object({
124
+ feed: HexStringSchema,
125
+ roundId: z.string(),
126
+ answer: z.string(),
127
+ updatedAt: z.number().int(),
128
+ nextRoundUpdatedAt: z.number().int().optional(),
129
+ }),
130
+ claimed: z.object({
131
+ probability: z.string(),
132
+ submittedAt: z.number().int(),
133
+ modelId: z.string(),
134
+ submissionManifestCid: z.string(),
135
+ }),
136
+ groundTruth: z.enum(['YES', 'NO']),
137
+ checks: z.array(CheckSchema),
138
+ signature: SignatureSchema,
139
+ });
140
+ //# sourceMappingURL=prediction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prediction.js","sourceRoot":"","sources":["../../src/types/prediction.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,kBAAkB,EAAE,kCAAkC,CAAC,CAAC;AAEjG,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;IAC5B,MAAM,EAAE,eAAe;IACvB,IAAI,EAAE,eAAe;IACrB,GAAG,EAAE,eAAe;CACrB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,iBAAiB,EAAE,eAAe;IAClC,oBAAoB,EAAE,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,EAAE;QAC3B,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;KAChD,CAAC;IACF,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;QAC7B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE;KAClC,CAAC;IACF,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC;IAC5B,SAAS,EAAE,eAAe;CAC3B,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface AaveReserveAddressSet {
2
+ pool: `0x${string}`;
3
+ reserve: `0x${string}`;
4
+ symbol: string;
5
+ }
6
+ export declare const AAVE_V3_USDC: Record<'aave-v3-base-sepolia' | 'aave-v3-base' | 'aave-v3-mainnet', AaveReserveAddressSet>;
@@ -0,0 +1,19 @@
1
+ export const AAVE_V3_USDC = {
2
+ 'aave-v3-base-sepolia': {
3
+ // Base Sepolia pool proxy + USDC reserve (Aave v3 test deployment).
4
+ pool: '0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951',
5
+ reserve: '0x31d3A7711a10C45D72649D51E1c8D74282702572',
6
+ symbol: 'USDC',
7
+ },
8
+ 'aave-v3-base': {
9
+ pool: '0xA238Dd80C259a72e81d7e4664a9801593F98d1c5',
10
+ reserve: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
11
+ symbol: 'USDC',
12
+ },
13
+ 'aave-v3-mainnet': {
14
+ pool: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2',
15
+ reserve: '0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
16
+ symbol: 'USDC',
17
+ },
18
+ };
19
+ //# sourceMappingURL=addresses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../../src/venues/aave-v3/addresses.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,YAAY,GAA+F;IACtH,sBAAsB,EAAE;QACtB,oEAAoE;QACpE,IAAI,EAAE,4CAA4C;QAClD,OAAO,EAAE,4CAA4C;QACrD,MAAM,EAAE,MAAM;KACf;IACD,cAAc,EAAE;QACd,IAAI,EAAE,4CAA4C;QAClD,OAAO,EAAE,4CAA4C;QACrD,MAAM,EAAE,MAAM;KACf;IACD,iBAAiB,EAAE;QACjB,IAAI,EAAE,4CAA4C;QAClD,OAAO,EAAE,4CAA4C;QACrD,MAAM,EAAE,MAAM;KACf;CACF,CAAC"}
@@ -0,0 +1,81 @@
1
+ import type { PublicClient } from 'viem';
2
+ export declare const AAVE_POOL_ABI: readonly [{
3
+ readonly name: "getReserveData";
4
+ readonly type: "function";
5
+ readonly stateMutability: "view";
6
+ readonly inputs: readonly [{
7
+ readonly name: "asset";
8
+ readonly type: "address";
9
+ }];
10
+ readonly outputs: readonly [{
11
+ readonly name: "configuration";
12
+ readonly type: "uint256";
13
+ }, {
14
+ readonly name: "liquidityIndex";
15
+ readonly type: "uint128";
16
+ }, {
17
+ readonly name: "currentLiquidityRate";
18
+ readonly type: "uint128";
19
+ }, {
20
+ readonly name: "variableBorrowIndex";
21
+ readonly type: "uint128";
22
+ }, {
23
+ readonly name: "currentVariableBorrowRate";
24
+ readonly type: "uint128";
25
+ }, {
26
+ readonly name: "currentStableBorrowRate";
27
+ readonly type: "uint128";
28
+ }, {
29
+ readonly name: "lastUpdateTimestamp";
30
+ readonly type: "uint40";
31
+ }, {
32
+ readonly name: "id";
33
+ readonly type: "uint16";
34
+ }, {
35
+ readonly name: "aTokenAddress";
36
+ readonly type: "address";
37
+ }, {
38
+ readonly name: "stableDebtTokenAddress";
39
+ readonly type: "address";
40
+ }, {
41
+ readonly name: "variableDebtTokenAddress";
42
+ readonly type: "address";
43
+ }, {
44
+ readonly name: "interestRateStrategyAddress";
45
+ readonly type: "address";
46
+ }, {
47
+ readonly name: "accruedToTreasury";
48
+ readonly type: "uint128";
49
+ }, {
50
+ readonly name: "unbacked";
51
+ readonly type: "uint128";
52
+ }, {
53
+ readonly name: "isolationModeTotalDebt";
54
+ readonly type: "uint128";
55
+ }];
56
+ }];
57
+ export interface ReserveRateReading {
58
+ blockNumber: bigint;
59
+ blockTimestampMs: number;
60
+ currentLiquidityRateRay: bigint;
61
+ }
62
+ export interface TwaApyBpsResult {
63
+ twApyBps: number;
64
+ sampleCount: number;
65
+ sampleTimestampsMs: number[];
66
+ }
67
+ export declare function scheduleSampleTimestamps(windowEndTs: number, twaWindowSeconds: number, sampleCount: number): number[];
68
+ export declare function liquidityRateRayToApyBps(rateRay: bigint): number;
69
+ export declare function findBlockAtOrBeforeTimestamp(publicClient: PublicClient, targetTsMs: number): Promise<{
70
+ number: bigint;
71
+ timestampMs: number;
72
+ }>;
73
+ export declare function readReserveRateAtTimestamp(publicClient: PublicClient, pool: `0x${string}`, reserve: `0x${string}`, timestampMs: number): Promise<ReserveRateReading>;
74
+ export declare function twApyBpsOverWindow(params: {
75
+ publicClient: PublicClient;
76
+ pool: `0x${string}`;
77
+ reserve: `0x${string}`;
78
+ windowEndTs: number;
79
+ twaWindowSeconds: number;
80
+ sampleCount: number;
81
+ }): Promise<TwaApyBpsResult>;
@@ -0,0 +1,97 @@
1
+ export const AAVE_POOL_ABI = [
2
+ {
3
+ name: 'getReserveData',
4
+ type: 'function',
5
+ stateMutability: 'view',
6
+ inputs: [{ name: 'asset', type: 'address' }],
7
+ outputs: [
8
+ { name: 'configuration', type: 'uint256' },
9
+ { name: 'liquidityIndex', type: 'uint128' },
10
+ { name: 'currentLiquidityRate', type: 'uint128' },
11
+ { name: 'variableBorrowIndex', type: 'uint128' },
12
+ { name: 'currentVariableBorrowRate', type: 'uint128' },
13
+ { name: 'currentStableBorrowRate', type: 'uint128' },
14
+ { name: 'lastUpdateTimestamp', type: 'uint40' },
15
+ { name: 'id', type: 'uint16' },
16
+ { name: 'aTokenAddress', type: 'address' },
17
+ { name: 'stableDebtTokenAddress', type: 'address' },
18
+ { name: 'variableDebtTokenAddress', type: 'address' },
19
+ { name: 'interestRateStrategyAddress', type: 'address' },
20
+ { name: 'accruedToTreasury', type: 'uint128' },
21
+ { name: 'unbacked', type: 'uint128' },
22
+ { name: 'isolationModeTotalDebt', type: 'uint128' },
23
+ ],
24
+ },
25
+ ];
26
+ const RAY = 10n ** 27n;
27
+ const SECONDS_PER_YEAR = 31536000n;
28
+ export function scheduleSampleTimestamps(windowEndTs, twaWindowSeconds, sampleCount) {
29
+ if (sampleCount < 2)
30
+ throw new Error('sampleCount must be >= 2');
31
+ const windowMs = twaWindowSeconds * 1000;
32
+ const start = windowEndTs - windowMs;
33
+ if (start < 0)
34
+ throw new Error('twa window starts before unix epoch');
35
+ const step = Math.floor(windowMs / (sampleCount - 1));
36
+ if (step <= 0)
37
+ throw new Error('sample spacing must be positive');
38
+ const ts = [];
39
+ for (let i = 0; i < sampleCount; i++)
40
+ ts.push(start + i * step);
41
+ ts[ts.length - 1] = windowEndTs;
42
+ return ts;
43
+ }
44
+ export function liquidityRateRayToApyBps(rateRay) {
45
+ const apr = Number(rateRay) / Number(RAY);
46
+ const apy = Math.pow(1 + apr / Number(SECONDS_PER_YEAR), Number(SECONDS_PER_YEAR)) - 1;
47
+ return Math.round(apy * 10_000);
48
+ }
49
+ export async function findBlockAtOrBeforeTimestamp(publicClient, targetTsMs) {
50
+ const latest = await publicClient.getBlock({ blockTag: 'latest' });
51
+ let lo = 0n;
52
+ let hi = latest.number;
53
+ let best = 0n;
54
+ while (lo <= hi) {
55
+ const mid = (lo + hi) / 2n;
56
+ const block = await publicClient.getBlock({ blockNumber: mid });
57
+ const tsMs = Number(block.timestamp) * 1000;
58
+ if (tsMs <= targetTsMs) {
59
+ best = mid;
60
+ lo = mid + 1n;
61
+ }
62
+ else {
63
+ hi = mid - 1n;
64
+ }
65
+ }
66
+ const b = await publicClient.getBlock({ blockNumber: best });
67
+ return { number: b.number, timestampMs: Number(b.timestamp) * 1000 };
68
+ }
69
+ export async function readReserveRateAtTimestamp(publicClient, pool, reserve, timestampMs) {
70
+ const block = await findBlockAtOrBeforeTimestamp(publicClient, timestampMs);
71
+ const reserveData = await publicClient.readContract({
72
+ address: pool,
73
+ abi: AAVE_POOL_ABI,
74
+ functionName: 'getReserveData',
75
+ args: [reserve],
76
+ blockNumber: block.number,
77
+ });
78
+ return {
79
+ blockNumber: block.number,
80
+ blockTimestampMs: block.timestampMs,
81
+ currentLiquidityRateRay: reserveData[2],
82
+ };
83
+ }
84
+ export async function twApyBpsOverWindow(params) {
85
+ const sampleTs = scheduleSampleTimestamps(params.windowEndTs, params.twaWindowSeconds, params.sampleCount);
86
+ let sum = 0;
87
+ for (const ts of sampleTs) {
88
+ const r = await readReserveRateAtTimestamp(params.publicClient, params.pool, params.reserve, ts);
89
+ sum += liquidityRateRayToApyBps(r.currentLiquidityRateRay);
90
+ }
91
+ return {
92
+ twApyBps: Math.round(sum / sampleTs.length),
93
+ sampleCount: sampleTs.length,
94
+ sampleTimestampsMs: sampleTs,
95
+ };
96
+ }
97
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/venues/aave-v3/client.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B;QACE,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC5C,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE;YAC1C,EAAE,IAAI,EAAE,gBAAgB,EAAE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,kBAAkB,CAAC,MAOxC;IACC,MAAM,QAAQ,GAAG,wBAAwB,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC3G,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,CAAC,GAAG,MAAM,0BAA0B,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACjG,GAAG,IAAI,wBAAwB,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC3C,WAAW,EAAE,QAAQ,CAAC,MAAM;QAC5B,kBAAkB,EAAE,QAAQ;KAC7B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Chainlink AggregatorV3 read client.
3
+ *
4
+ * §7 of spec/2026-04-20-prediction-v0-pis-phase-1-design.md
5
+ */
6
+ import type { PublicClient } from 'viem';
7
+ export declare const AGGREGATOR_V3_ABI: readonly [{
8
+ readonly name: "latestRoundData";
9
+ readonly type: "function";
10
+ readonly stateMutability: "view";
11
+ readonly inputs: readonly [];
12
+ readonly outputs: readonly [{
13
+ readonly name: "roundId";
14
+ readonly type: "uint80";
15
+ }, {
16
+ readonly name: "answer";
17
+ readonly type: "int256";
18
+ }, {
19
+ readonly name: "startedAt";
20
+ readonly type: "uint256";
21
+ }, {
22
+ readonly name: "updatedAt";
23
+ readonly type: "uint256";
24
+ }, {
25
+ readonly name: "answeredInRound";
26
+ readonly type: "uint80";
27
+ }];
28
+ }, {
29
+ readonly name: "getRoundData";
30
+ readonly type: "function";
31
+ readonly stateMutability: "view";
32
+ readonly inputs: readonly [{
33
+ readonly name: "_roundId";
34
+ readonly type: "uint80";
35
+ }];
36
+ readonly outputs: readonly [{
37
+ readonly name: "roundId";
38
+ readonly type: "uint80";
39
+ }, {
40
+ readonly name: "answer";
41
+ readonly type: "int256";
42
+ }, {
43
+ readonly name: "startedAt";
44
+ readonly type: "uint256";
45
+ }, {
46
+ readonly name: "updatedAt";
47
+ readonly type: "uint256";
48
+ }, {
49
+ readonly name: "answeredInRound";
50
+ readonly type: "uint80";
51
+ }];
52
+ }, {
53
+ readonly name: "decimals";
54
+ readonly type: "function";
55
+ readonly stateMutability: "view";
56
+ readonly inputs: readonly [];
57
+ readonly outputs: readonly [{
58
+ readonly name: "";
59
+ readonly type: "uint8";
60
+ }];
61
+ }, {
62
+ readonly name: "description";
63
+ readonly type: "function";
64
+ readonly stateMutability: "view";
65
+ readonly inputs: readonly [];
66
+ readonly outputs: readonly [{
67
+ readonly name: "";
68
+ readonly type: "string";
69
+ }];
70
+ }];
71
+ export interface RoundReading {
72
+ roundId: bigint;
73
+ answer: bigint;
74
+ startedAt: number;
75
+ updatedAt: number;
76
+ answeredInRound: bigint;
77
+ decimals: number;
78
+ }
79
+ /** Scale a raw Chainlink int256 answer to a decimal string. */
80
+ export declare function scaleToDecimal(answer: bigint, decimals: number): string;
81
+ export declare function readChainlinkLatest(feed: `0x${string}`, publicClient: PublicClient): Promise<RoundReading>;
82
+ export declare function readChainlinkRound(feed: `0x${string}`, roundId: bigint, publicClient: PublicClient, decimals: number): Promise<RoundReading>;
83
+ export interface SpanningResult {
84
+ /** Round R with updatedAt ≤ resolveTs. */
85
+ round: RoundReading;
86
+ /** Round R+1 with updatedAt > resolveTs. null if no newer round exists yet. */
87
+ nextRound: RoundReading | null;
88
+ /** True iff nextRound exists — then the spanning property is satisfied. */
89
+ spanning: boolean;
90
+ }
91
+ /**
92
+ * Find the Chainlink round that "spans" resolveTs: round R where
93
+ * R.updatedAt ≤ resolveTs < (R+1).updatedAt.
94
+ *
95
+ * If the latest round's updatedAt ≤ resolveTs (i.e. no newer round yet),
96
+ * returns { round: latest, nextRound: null, spanning: false }. Caller should
97
+ * retry later (availability check will mark SKIP → INDETERMINATE verdict).
98
+ */
99
+ export declare function oraclePriceAtResolveTs(feed: `0x${string}`, resolveTs: number, publicClient: PublicClient): Promise<SpanningResult>;
@@ -0,0 +1,130 @@
1
+ export const AGGREGATOR_V3_ABI = [
2
+ {
3
+ name: 'latestRoundData',
4
+ type: 'function',
5
+ stateMutability: 'view',
6
+ inputs: [],
7
+ outputs: [
8
+ { name: 'roundId', type: 'uint80' },
9
+ { name: 'answer', type: 'int256' },
10
+ { name: 'startedAt', type: 'uint256' },
11
+ { name: 'updatedAt', type: 'uint256' },
12
+ { name: 'answeredInRound', type: 'uint80' },
13
+ ],
14
+ },
15
+ {
16
+ name: 'getRoundData',
17
+ type: 'function',
18
+ stateMutability: 'view',
19
+ inputs: [{ name: '_roundId', type: 'uint80' }],
20
+ outputs: [
21
+ { name: 'roundId', type: 'uint80' },
22
+ { name: 'answer', type: 'int256' },
23
+ { name: 'startedAt', type: 'uint256' },
24
+ { name: 'updatedAt', type: 'uint256' },
25
+ { name: 'answeredInRound', type: 'uint80' },
26
+ ],
27
+ },
28
+ {
29
+ name: 'decimals',
30
+ type: 'function',
31
+ stateMutability: 'view',
32
+ inputs: [],
33
+ outputs: [{ name: '', type: 'uint8' }],
34
+ },
35
+ {
36
+ name: 'description',
37
+ type: 'function',
38
+ stateMutability: 'view',
39
+ inputs: [],
40
+ outputs: [{ name: '', type: 'string' }],
41
+ },
42
+ ];
43
+ /** Scale a raw Chainlink int256 answer to a decimal string. */
44
+ export function scaleToDecimal(answer, decimals) {
45
+ if (answer < 0n) {
46
+ throw new Error(`scaleToDecimal: negative value not supported in v0 (got ${answer})`);
47
+ }
48
+ const s = answer.toString();
49
+ if (decimals === 0)
50
+ return s;
51
+ if (s.length <= decimals) {
52
+ const frac = s.padStart(decimals, '0').replace(/0+$/, '');
53
+ return frac.length > 0 ? `0.${frac}` : '0';
54
+ }
55
+ const intPart = s.slice(0, s.length - decimals);
56
+ const fracRaw = s.slice(s.length - decimals);
57
+ const frac = fracRaw.replace(/0+$/, '');
58
+ return frac.length > 0 ? `${intPart}.${frac}` : intPart;
59
+ }
60
+ export async function readChainlinkLatest(feed, publicClient) {
61
+ const [latest, decimals] = await Promise.all([
62
+ publicClient.readContract({
63
+ address: feed,
64
+ abi: AGGREGATOR_V3_ABI,
65
+ functionName: 'latestRoundData',
66
+ }),
67
+ publicClient.readContract({
68
+ address: feed,
69
+ abi: AGGREGATOR_V3_ABI,
70
+ functionName: 'decimals',
71
+ }),
72
+ ]);
73
+ const [roundId, answer, startedAt, updatedAt, answeredInRound] = latest;
74
+ return {
75
+ roundId,
76
+ answer,
77
+ // Chainlink timestamps are SECONDS → convert to ms for consistency with rest of codebase
78
+ startedAt: Number(startedAt) * 1000,
79
+ updatedAt: Number(updatedAt) * 1000,
80
+ answeredInRound,
81
+ decimals: decimals,
82
+ };
83
+ }
84
+ export async function readChainlinkRound(feed, roundId, publicClient, decimals) {
85
+ const round = await publicClient.readContract({
86
+ address: feed,
87
+ abi: AGGREGATOR_V3_ABI,
88
+ functionName: 'getRoundData',
89
+ args: [roundId],
90
+ });
91
+ const [rid, answer, startedAt, updatedAt, answeredInRound] = round;
92
+ return {
93
+ roundId: rid,
94
+ answer,
95
+ startedAt: Number(startedAt) * 1000,
96
+ updatedAt: Number(updatedAt) * 1000,
97
+ answeredInRound,
98
+ decimals,
99
+ };
100
+ }
101
+ /**
102
+ * Find the Chainlink round that "spans" resolveTs: round R where
103
+ * R.updatedAt ≤ resolveTs < (R+1).updatedAt.
104
+ *
105
+ * If the latest round's updatedAt ≤ resolveTs (i.e. no newer round yet),
106
+ * returns { round: latest, nextRound: null, spanning: false }. Caller should
107
+ * retry later (availability check will mark SKIP → INDETERMINATE verdict).
108
+ */
109
+ export async function oraclePriceAtResolveTs(feed, resolveTs, publicClient) {
110
+ const latest = await readChainlinkLatest(feed, publicClient);
111
+ // Case A: latest is at-or-before resolveTs → no newer round yet
112
+ if (latest.updatedAt <= resolveTs) {
113
+ return { round: latest, nextRound: null, spanning: false };
114
+ }
115
+ // Case B: latest is after resolveTs → walk back to find spanning round
116
+ let nextRound = latest;
117
+ let cursor = latest.roundId - 1n;
118
+ while (cursor > 0n) {
119
+ const r = await readChainlinkRound(feed, cursor, publicClient, latest.decimals);
120
+ if (r.updatedAt <= resolveTs) {
121
+ return { round: r, nextRound, spanning: true };
122
+ }
123
+ nextRound = r;
124
+ cursor -= 1n;
125
+ }
126
+ // Walked back to round 0 without finding a pre-resolveTs round — oracle is
127
+ // newer than the window. Surface as not-spanning so caller INDETERMINATE-s.
128
+ return { round: latest, nextRound: null, spanning: false };
129
+ }
130
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/venues/chainlink/client.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B;QACE,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,EAAE;QACV,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;YACnC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;YAClC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;YACtC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;YACtC,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC5C;KACF;IACD;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC9C,OAAO,EAAE;YACP,EAAE,IA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AS,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QACjD,CAAC;QACD,SAAS,GAAG,CAAC,CAAC;QACd,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;IACD,2EAA2E;IAC3E,4EAA4E;IAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Known Chainlink AggregatorV3 feeds on Base + Base Sepolia. */
2
+ export declare const BASE_SEPOLIA_FEEDS: {
3
+ readonly 'ETH / USD': "0x4aDC67696bA383F43DD60A9e78F2C97Fbbfc7cb1";
4
+ readonly 'BTC / USD': "0x0FB99723Aee6f420beAD13e6bBB79b7E6F034298";
5
+ };
6
+ export declare const BASE_FEEDS: {
7
+ readonly 'ETH / USD': "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70";
8
+ };
@@ -0,0 +1,9 @@
1
+ /** Known Chainlink AggregatorV3 feeds on Base + Base Sepolia. */
2
+ export const BASE_SEPOLIA_FEEDS = {
3
+ 'ETH / USD': '0x4aDC67696bA383F43DD60A9e78F2C97Fbbfc7cb1',
4
+ 'BTC / USD': '0x0FB99723Aee6f420beAD13e6bBB79b7E6F034298',
5
+ };
6
+ export const BASE_FEEDS = {
7
+ 'ETH / USD': '0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70',
8
+ };
9
+ //# sourceMappingURL=feeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/venues/chainlink/feeds.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,WAAW,EAAE,4CAAqD;IAClE,WAAW,EAAE,4CAAqD;CAC1D,CAAC;AAEX,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,WAAW,EAAE,4CAAqD;CAC1D,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Unified account-value helper.
3
+ *
4
+ * Returns a single equity figure that sums perps margin + spot USDC. This
5
+ * matches HL's `portfolio` endpoint `accountValueHistory` (which also
6
+ * reports the unified view), so restorer-claimed equity and evaluator-
7
+ * rederived grid points compare cleanly.
8
+ *
9
+ * Non-USDC spot tokens are NOT valued in v0 — their midprice lookup and
10
+ * safety semantics are out of scope for the first cut of portfolio.v0.
11
+ */
12
+ import type { HlClearinghouseState, HlSpotClearinghouseState } from './types.js';
13
+ export interface UnifiedAccountValue {
14
+ /** Sum of perps accountValue + spot USDC balance, as a decimal string. */
15
+ accountValue: string;
16
+ /** Perps-only accountValue (marginSummary.accountValue). */
17
+ perpsAccountValue: string;
18
+ /** Spot USDC balance (0 if absent). */
19
+ spotUsdc: string;
20
+ /** Raw perps payload from HL. */
21
+ clearinghouseState: HlClearinghouseState;
22
+ /** Raw spot payload from HL. */
23
+ spotClearinghouseState: HlSpotClearinghouseState;
24
+ }
25
+ interface HlClientLike {
26
+ clearinghouseState: (user: string) => Promise<HlClearinghouseState>;
27
+ spotClearinghouseState: (user: string) => Promise<HlSpotClearinghouseState>;
28
+ }
29
+ export declare function getUnifiedAccountValue(hlClient: HlClientLike, user: string): Promise<UnifiedAccountValue>;
30
+ export {};