@oracle-agent/oracle 0.10.0 → 0.12.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 (424) hide show
  1. package/LICENSE +115 -201
  2. package/README.md +82 -91
  3. package/SECURITY.md +37 -12
  4. package/SETUP.md +207 -272
  5. package/dist/action-receipts.mjs +1 -0
  6. package/dist/action-semantics.mjs +1 -0
  7. package/dist/address-book.mjs +2 -0
  8. package/dist/bin/desk-server.mjs +14 -0
  9. package/dist/bin/oracle-data-mcp.mjs +8 -0
  10. package/dist/bin/oracle-init.mjs +24 -0
  11. package/dist/bin/oracle-public-server.mjs +5 -0
  12. package/dist/bin/oracle-route.mjs +22 -0
  13. package/dist/bin/oracle-scan.mjs +18 -0
  14. package/dist/bin/oracle-upgrade.mjs +21 -0
  15. package/dist/bin/oracle.mjs +68 -0
  16. package/dist/chains.mjs +1 -0
  17. package/dist/cli/commands/auth.mjs +16 -0
  18. package/dist/cli/commands/bootstrap.mjs +18 -0
  19. package/dist/cli/commands/chain.mjs +21 -0
  20. package/dist/cli/commands/chat.mjs +35 -0
  21. package/dist/cli/commands/credential.mjs +1 -0
  22. package/dist/cli/commands/data-mcp.mjs +2 -0
  23. package/dist/cli/commands/data.mjs +12 -0
  24. package/dist/cli/commands/doctor.mjs +5 -0
  25. package/dist/cli/commands/gate.mjs +13 -0
  26. package/dist/cli/commands/help.mjs +1 -0
  27. package/dist/cli/commands/init.mjs +3 -0
  28. package/dist/cli/commands/mcp.mjs +33 -0
  29. package/dist/cli/commands/model.mjs +44 -0
  30. package/dist/cli/commands/prepare.mjs +2 -0
  31. package/dist/cli/commands/public.mjs +3 -0
  32. package/dist/cli/commands/route.mjs +2 -0
  33. package/dist/cli/commands/runner.mjs +1 -0
  34. package/dist/cli/commands/scan.mjs +2 -0
  35. package/dist/cli/commands/setup.mjs +34 -0
  36. package/dist/cli/commands/sign.mjs +4 -0
  37. package/dist/cli/commands/signer.mjs +1 -0
  38. package/dist/cli/commands/upgrade.mjs +2 -0
  39. package/dist/cli/commands/vault.mjs +1 -0
  40. package/dist/cli/commands/version.mjs +2 -0
  41. package/dist/data/desk-data.mjs +12 -0
  42. package/dist/index.mjs +17 -0
  43. package/dist/nft-gas-war-guard.mjs +1 -0
  44. package/dist/onboarding/harness-configs.mjs +4 -0
  45. package/dist/portfolio-risk.mjs +1 -0
  46. package/dist/prepare-envelope.mjs +1 -0
  47. package/dist/public-control/policy-schema.mjs +1 -0
  48. package/dist/router/index.mjs +2 -0
  49. package/dist/scanner/index.mjs +4 -0
  50. package/dist/signals/index.mjs +1 -0
  51. package/dist/watch-preferences.mjs +1 -0
  52. package/package.json +27 -65
  53. package/public/oracle-splash/assets/cli-chain-hyperliquid.jpg +0 -0
  54. package/public/oracle-splash/brand/aave.webp +0 -0
  55. package/public/oracle-splash/brand/aavev2.webp +0 -0
  56. package/public/oracle-splash/brand/aborean.webp +0 -0
  57. package/public/oracle-splash/brand/across.webp +0 -0
  58. package/public/oracle-splash/brand/aerodrome.webp +0 -0
  59. package/public/oracle-splash/brand/afi.webp +0 -0
  60. package/public/oracle-splash/brand/arcus.webp +0 -0
  61. package/public/oracle-splash/brand/aster.webp +0 -0
  62. package/public/oracle-splash/brand/avant.webp +0 -0
  63. package/public/oracle-splash/brand/balancer.webp +0 -0
  64. package/public/oracle-splash/brand/beefy.webp +0 -0
  65. package/public/oracle-splash/brand/benqi.webp +0 -0
  66. package/public/oracle-splash/brand/bestinslot.ico +0 -0
  67. package/public/oracle-splash/brand/bitfi.webp +0 -0
  68. package/public/oracle-splash/brand/bonkswap.webp +0 -0
  69. package/public/oracle-splash/brand/bouncebit.webp +0 -0
  70. package/public/oracle-splash/brand/camelot.webp +0 -0
  71. package/public/oracle-splash/brand/compound.webp +0 -0
  72. package/public/oracle-splash/brand/concrete.webp +0 -0
  73. package/public/oracle-splash/brand/cow.webp +0 -0
  74. package/public/oracle-splash/brand/curve.webp +0 -0
  75. package/public/oracle-splash/brand/derive.webp +0 -0
  76. package/public/oracle-splash/brand/dolomite.webp +0 -0
  77. package/public/oracle-splash/brand/eigenlayer.webp +0 -0
  78. package/public/oracle-splash/brand/ekubo.webp +0 -0
  79. package/public/oracle-splash/brand/ethena.webp +0 -0
  80. package/public/oracle-splash/brand/etherfi.webp +0 -0
  81. package/public/oracle-splash/brand/etherfiborrow.webp +0 -0
  82. package/public/oracle-splash/brand/felix.webp +0 -0
  83. package/public/oracle-splash/brand/fluid.webp +0 -0
  84. package/public/oracle-splash/brand/fluxbeam.webp +0 -0
  85. package/public/oracle-splash/brand/folks.webp +0 -0
  86. package/public/oracle-splash/brand/fortyacres.webp +0 -0
  87. package/public/oracle-splash/brand/gainsnetwork.webp +0 -0
  88. package/public/oracle-splash/brand/gassss.webp +0 -0
  89. package/public/oracle-splash/brand/gmx.webp +0 -0
  90. package/public/oracle-splash/brand/harmonix.webp +0 -0
  91. package/public/oracle-splash/brand/hlorderbook.webp +0 -0
  92. package/public/oracle-splash/brand/hlp.webp +0 -0
  93. package/public/oracle-splash/brand/hop.webp +0 -0
  94. package/public/oracle-splash/brand/hyperbeat.webp +0 -0
  95. package/public/oracle-splash/brand/hyperlend.webp +0 -0
  96. package/public/oracle-splash/brand/hyperliquid.webp +0 -0
  97. package/public/oracle-splash/brand/hyperliquidhpl.webp +0 -0
  98. package/public/oracle-splash/brand/hyperliquidspot.webp +0 -0
  99. package/public/oracle-splash/brand/hyperswap.webp +0 -0
  100. package/public/oracle-splash/brand/hypha.webp +0 -0
  101. package/public/oracle-splash/brand/joedex.webp +0 -0
  102. package/public/oracle-splash/brand/jupiter.webp +0 -0
  103. package/public/oracle-splash/brand/kelp.webp +0 -0
  104. package/public/oracle-splash/brand/kinetiq.webp +0 -0
  105. package/public/oracle-splash/brand/kmhype.webp +0 -0
  106. package/public/oracle-splash/brand/kona.webp +0 -0
  107. package/public/oracle-splash/brand/konalend.webp +0 -0
  108. package/public/oracle-splash/brand/lfj.webp +0 -0
  109. package/public/oracle-splash/brand/lido.webp +0 -0
  110. package/public/oracle-splash/brand/lifi.webp +0 -0
  111. package/public/oracle-splash/brand/lighter.webp +0 -0
  112. package/public/oracle-splash/brand/lista.webp +0 -0
  113. package/public/oracle-splash/brand/loopedhype.webp +0 -0
  114. package/public/oracle-splash/brand/lorenzo.webp +0 -0
  115. package/public/oracle-splash/brand/magic-eden.webp +0 -0
  116. package/public/oracle-splash/brand/magiceden.webp +0 -0
  117. package/public/oracle-splash/brand/mempool.png +0 -0
  118. package/public/oracle-splash/brand/meteora.webp +0 -0
  119. package/public/oracle-splash/brand/morpho.webp +0 -0
  120. package/public/oracle-splash/brand/myriad.webp +0 -0
  121. package/public/oracle-splash/brand/noxa.webp +0 -0
  122. package/public/oracle-splash/brand/odos.webp +0 -0
  123. package/public/oracle-splash/brand/oneinch.webp +0 -0
  124. package/public/oracle-splash/brand/openbook.webp +0 -0
  125. package/public/oracle-splash/brand/opensea.webp +0 -0
  126. package/public/oracle-splash/brand/orca.webp +0 -0
  127. package/public/oracle-splash/brand/ordinals.png +0 -0
  128. package/public/oracle-splash/brand/ostium.webp +0 -0
  129. package/public/oracle-splash/brand/pancakeswap.webp +0 -0
  130. package/public/oracle-splash/brand/pendle.webp +0 -0
  131. package/public/oracle-splash/brand/perena.webp +0 -0
  132. package/public/oracle-splash/brand/pharaoh.webp +0 -0
  133. package/public/oracle-splash/brand/phoenix.webp +0 -0
  134. package/public/oracle-splash/brand/polymarket.webp +0 -0
  135. package/public/oracle-splash/brand/polynomial.webp +0 -0
  136. package/public/oracle-splash/brand/projectx.webp +0 -0
  137. package/public/oracle-splash/brand/pumpfun.webp +0 -0
  138. package/public/oracle-splash/brand/quickswap.webp +0 -0
  139. package/public/oracle-splash/brand/rain.webp +0 -0
  140. package/public/oracle-splash/brand/raydium.webp +0 -0
  141. package/public/oracle-splash/brand/relay.webp +0 -0
  142. package/public/oracle-splash/brand/rocketpool.webp +0 -0
  143. package/public/oracle-splash/brand/saber.webp +0 -0
  144. package/public/oracle-splash/brand/sakuraswap.webp +0 -0
  145. package/public/oracle-splash/brand/sanctum.webp +0 -0
  146. package/public/oracle-splash/brand/satflow.png +0 -0
  147. package/public/oracle-splash/brand/sierra.webp +0 -0
  148. package/public/oracle-splash/brand/sky.webp +0 -0
  149. package/public/oracle-splash/brand/solv.webp +0 -0
  150. package/public/oracle-splash/brand/spark.webp +0 -0
  151. package/public/oracle-splash/brand/sparksavings.webp +0 -0
  152. package/public/oracle-splash/brand/sphere.webp +0 -0
  153. package/public/oracle-splash/brand/ssv.webp +0 -0
  154. package/public/oracle-splash/brand/stabble.webp +0 -0
  155. package/public/oracle-splash/brand/stableswap.webp +0 -0
  156. package/public/oracle-splash/brand/stakewise.webp +0 -0
  157. package/public/oracle-splash/brand/stargate.webp +0 -0
  158. package/public/oracle-splash/brand/sthype.webp +0 -0
  159. package/public/oracle-splash/brand/sushiswap.webp +0 -0
  160. package/public/oracle-splash/brand/unisat.png +0 -0
  161. package/public/oracle-splash/brand/uniswap.webp +0 -0
  162. package/public/oracle-splash/brand/uniswapv2.webp +0 -0
  163. package/public/oracle-splash/brand/uniswapv4.webp +0 -0
  164. package/public/oracle-splash/brand/unit.webp +0 -0
  165. package/public/oracle-splash/brand/velodrome.webp +0 -0
  166. package/public/oracle-splash/brand/velora.webp +0 -0
  167. package/public/oracle-splash/brand/venus.webp +0 -0
  168. package/public/oracle-splash/brand/wbeth.webp +0 -0
  169. package/public/oracle-splash/brand/xsy.webp +0 -0
  170. package/public/oracle-splash/brand/yieldyak.webp +0 -0
  171. package/public/oracle-splash/brand/zerobase.webp +0 -0
  172. package/public/oracle-splash/brand/zerox.webp +0 -0
  173. package/public/oracle-splash/index.html +246 -169
  174. package/CONTRIBUTING.md +0 -98
  175. package/bin/desk-server.mjs +0 -440
  176. package/bin/oracle-data-mcp.mjs +0 -1010
  177. package/bin/oracle-init.mjs +0 -496
  178. package/bin/oracle-public-server.mjs +0 -36
  179. package/bin/oracle-route.mjs +0 -254
  180. package/bin/oracle-scan.mjs +0 -192
  181. package/bin/oracle-upgrade.mjs +0 -42
  182. package/bin/oracle.mjs +0 -33
  183. package/docs/adding-a-chain.md +0 -229
  184. package/docs/architecture.md +0 -136
  185. package/docs/cli.md +0 -47
  186. package/docs/connectors.md +0 -13
  187. package/docs/oracle-pack-standard.md +0 -29
  188. package/docs/profiles.md +0 -154
  189. package/examples/add-a-chain.mjs +0 -65
  190. package/examples/oracle-pack-template.mjs +0 -38
  191. package/examples/research-a-token.mjs +0 -70
  192. package/plugins/oracle-owner-gate/__init__.py +0 -227
  193. package/plugins/oracle-owner-gate/plugin.yaml +0 -9
  194. package/profiles/_template/SOUL.md +0 -54
  195. package/profiles/_template/profile.json +0 -22
  196. package/profiles/bitcoin-agent/SOUL.md +0 -31
  197. package/profiles/bitcoin-agent/profile.json +0 -32
  198. package/profiles/hyperliquid-agent/SOUL.md +0 -34
  199. package/profiles/hyperliquid-agent/profile.json +0 -37
  200. package/profiles/oracle/SOUL.md +0 -107
  201. package/profiles/oracle/profile.json +0 -39
  202. package/profiles/polymarket-agent/SOUL.md +0 -35
  203. package/profiles/polymarket-agent/profile.json +0 -34
  204. package/profiles/profile.schema.json +0 -90
  205. package/profiles/protocol-builder/SOUL.md +0 -57
  206. package/profiles/protocol-builder/profile.json +0 -39
  207. package/profiles/robinhood-agent/SOUL.md +0 -53
  208. package/profiles/robinhood-agent/profile.json +0 -40
  209. package/profiles/solana-agent/SOUL.md +0 -37
  210. package/profiles/solana-agent/profile.json +0 -37
  211. package/profiles/stable-agent/SOUL.md +0 -43
  212. package/profiles/stable-agent/profile.json +0 -37
  213. package/protocols/templates/safe-erc20/SECURITY.md +0 -16
  214. package/protocols/templates/safe-erc20/foundry.toml +0 -12
  215. package/protocols/templates/safe-erc20/remappings.txt +0 -2
  216. package/protocols/templates/safe-erc20/src/SafeERC20.sol +0 -53
  217. package/protocols/templates/safe-erc20/test/SafeERC20.t.sol +0 -72
  218. package/scripts/adversarial-bench.mjs +0 -114
  219. package/scripts/build-inscription.py +0 -230
  220. package/scripts/check-doc-drift.mjs +0 -112
  221. package/scripts/check-test-count.mjs +0 -105
  222. package/scripts/e2e-hl-markets.mjs +0 -21
  223. package/scripts/e2e-hl-perps.mjs +0 -48
  224. package/scripts/e2e-hypercore-staking.mjs +0 -128
  225. package/scripts/e2e-solana-bitcoin.mjs +0 -183
  226. package/scripts/protocol-template-gate.mjs +0 -15
  227. package/scripts/public-api-scan.mjs +0 -23
  228. package/scripts/secret-scan.mjs +0 -181
  229. package/scripts/verify-v3-venues.mjs +0 -192
  230. package/skills/balance/SKILL.md +0 -176
  231. package/skills/oracle-action-semantics/SKILL.md +0 -40
  232. package/skills/oracle-best-execution/SKILL.md +0 -127
  233. package/skills/oracle-bitcoin/SKILL.md +0 -53
  234. package/skills/oracle-chain-graphs-telegram-cards/SKILL.md +0 -59
  235. package/skills/oracle-chat/SKILL.md +0 -61
  236. package/skills/oracle-chat/chain.SKILL.md +0 -31
  237. package/skills/oracle-chat/setup.SKILL.md +0 -37
  238. package/skills/oracle-circuit-breaker/SKILL.md +0 -51
  239. package/skills/oracle-contract-research/SKILL.md +0 -55
  240. package/skills/oracle-desk/SKILL.md +0 -58
  241. package/skills/oracle-dex-launch/SKILL.md +0 -38
  242. package/skills/oracle-grants/SKILL.md +0 -69
  243. package/skills/oracle-hypercore-staking/SKILL.md +0 -57
  244. package/skills/oracle-hyperliquid/SKILL.md +0 -56
  245. package/skills/oracle-meme-token-sniper/SKILL.md +0 -73
  246. package/skills/oracle-multichain-nft-launch/SKILL.md +0 -338
  247. package/skills/oracle-multichain-token-launch/SKILL.md +0 -300
  248. package/skills/oracle-nft-gacha-launch/SKILL.md +0 -48
  249. package/skills/oracle-nft-mint-gas-war/SKILL.md +0 -63
  250. package/skills/oracle-polymarket/SKILL.md +0 -60
  251. package/skills/oracle-protocol-builder/SKILL.md +0 -59
  252. package/skills/oracle-protocol-security/SKILL.md +0 -60
  253. package/skills/oracle-public-product/SKILL.md +0 -44
  254. package/skills/oracle-receipts/SKILL.md +0 -52
  255. package/skills/oracle-rfq-tokenized-assets/SKILL.md +0 -69
  256. package/skills/oracle-smart-wallet-scanner/SKILL.md +0 -49
  257. package/skills/oracle-solana/SKILL.md +0 -65
  258. package/skills/oracle-solana-nft/SKILL.md +0 -54
  259. package/skills/oracle-token-research/SKILL.md +0 -67
  260. package/skins/oracle.yaml +0 -56
  261. package/src/action-receipts.mjs +0 -168
  262. package/src/action-semantics.mjs +0 -62
  263. package/src/address-book.mjs +0 -208
  264. package/src/agent-auth.mjs +0 -206
  265. package/src/approval-guard.mjs +0 -282
  266. package/src/attestation-secret.mjs +0 -88
  267. package/src/audit-log.mjs +0 -196
  268. package/src/auth/oauth.mjs +0 -672
  269. package/src/auto-slippage.mjs +0 -378
  270. package/src/capability-posture.mjs +0 -125
  271. package/src/chains.mjs +0 -62
  272. package/src/cli/chain-catalog.mjs +0 -215
  273. package/src/cli/chain-state.mjs +0 -74
  274. package/src/cli/commands/auth.mjs +0 -193
  275. package/src/cli/commands/bootstrap.mjs +0 -87
  276. package/src/cli/commands/chain.mjs +0 -143
  277. package/src/cli/commands/chat.mjs +0 -434
  278. package/src/cli/commands/credential.mjs +0 -9
  279. package/src/cli/commands/data-mcp.mjs +0 -18
  280. package/src/cli/commands/data.mjs +0 -73
  281. package/src/cli/commands/doctor.mjs +0 -126
  282. package/src/cli/commands/help.mjs +0 -7
  283. package/src/cli/commands/init.mjs +0 -27
  284. package/src/cli/commands/mcp.mjs +0 -142
  285. package/src/cli/commands/model.mjs +0 -99
  286. package/src/cli/commands/prepare.mjs +0 -12
  287. package/src/cli/commands/public.mjs +0 -20
  288. package/src/cli/commands/route.mjs +0 -12
  289. package/src/cli/commands/runner.mjs +0 -9
  290. package/src/cli/commands/scan.mjs +0 -12
  291. package/src/cli/commands/setup.mjs +0 -275
  292. package/src/cli/commands/sign.mjs +0 -21
  293. package/src/cli/commands/signer.mjs +0 -9
  294. package/src/cli/commands/upgrade.mjs +0 -12
  295. package/src/cli/commands/vault.mjs +0 -9
  296. package/src/cli/commands/version.mjs +0 -22
  297. package/src/cli/first-run.mjs +0 -23
  298. package/src/cli/kernel.mjs +0 -239
  299. package/src/cli/mcp-targets/chatgpt.mjs +0 -51
  300. package/src/cli/mcp-targets/claude-code.mjs +0 -39
  301. package/src/cli/mcp-targets/claude-desktop.mjs +0 -24
  302. package/src/cli/mcp-targets/codex.mjs +0 -41
  303. package/src/cli/mcp-targets/shared.mjs +0 -61
  304. package/src/cli/messaging-platforms.mjs +0 -209
  305. package/src/cli/model-config.mjs +0 -70
  306. package/src/cli/operator-dispatch.mjs +0 -258
  307. package/src/cli/oracle-harness.py +0 -415
  308. package/src/cli/paths.mjs +0 -83
  309. package/src/cli/runtime.mjs +0 -351
  310. package/src/cli/setup-state.mjs +0 -168
  311. package/src/cli/spawn-child.mjs +0 -43
  312. package/src/data/catalog.mjs +0 -554
  313. package/src/data/desk-data.mjs +0 -683
  314. package/src/data/http.mjs +0 -253
  315. package/src/data/provider-endpoint.mjs +0 -94
  316. package/src/data/providers/aerodrome.mjs +0 -245
  317. package/src/data/providers/balancer.mjs +0 -209
  318. package/src/data/providers/bitcoin-esplora.mjs +0 -216
  319. package/src/data/providers/bitcoin-meta.mjs +0 -378
  320. package/src/data/providers/blockscout.mjs +0 -14
  321. package/src/data/providers/bridges.mjs +0 -242
  322. package/src/data/providers/cowswap.mjs +0 -415
  323. package/src/data/providers/curve.mjs +0 -201
  324. package/src/data/providers/defillama.mjs +0 -88
  325. package/src/data/providers/dexscreener.mjs +0 -43
  326. package/src/data/providers/evm-rpc.mjs +0 -222
  327. package/src/data/providers/geckoterminal.mjs +0 -34
  328. package/src/data/providers/gmx.mjs +0 -496
  329. package/src/data/providers/hl-assets.mjs +0 -165
  330. package/src/data/providers/hl-info.mjs +0 -108
  331. package/src/data/providers/hl-markets.mjs +0 -210
  332. package/src/data/providers/hl-outcome.mjs +0 -61
  333. package/src/data/providers/hl-perps.mjs +0 -387
  334. package/src/data/providers/hl-staking.mjs +0 -353
  335. package/src/data/providers/hl-ws.mjs +0 -119
  336. package/src/data/providers/hyperevm-dex.mjs +0 -49
  337. package/src/data/providers/jupiter.mjs +0 -183
  338. package/src/data/providers/lifi.mjs +0 -151
  339. package/src/data/providers/magiceden-sol.mjs +0 -393
  340. package/src/data/providers/morpho.mjs +0 -173
  341. package/src/data/providers/nft-gallery.mjs +0 -163
  342. package/src/data/providers/nft-portfolio.mjs +0 -494
  343. package/src/data/providers/odos.mjs +0 -156
  344. package/src/data/providers/oneinch.mjs +0 -174
  345. package/src/data/providers/opensea-multichain.mjs +0 -136
  346. package/src/data/providers/opensea-nft.mjs +0 -371
  347. package/src/data/providers/paraswap.mjs +0 -118
  348. package/src/data/providers/pendle.mjs +0 -187
  349. package/src/data/providers/poly-clob.mjs +0 -283
  350. package/src/data/providers/poly-public.mjs +0 -96
  351. package/src/data/providers/poly-ws.mjs +0 -103
  352. package/src/data/providers/portfolio-history.mjs +0 -394
  353. package/src/data/providers/portfolio.mjs +0 -594
  354. package/src/data/providers/rfq.mjs +0 -15
  355. package/src/data/providers/rh-agent.mjs +0 -59
  356. package/src/data/providers/satflow.mjs +0 -338
  357. package/src/data/providers/solana-rpc.mjs +0 -197
  358. package/src/data/providers/uniswap-v3.mjs +0 -320
  359. package/src/data/providers/zerox.mjs +0 -167
  360. package/src/data/public-api-scan.mjs +0 -61
  361. package/src/data/quote-placeholder.mjs +0 -31
  362. package/src/exact-integer.mjs +0 -72
  363. package/src/exec-policy.mjs +0 -455
  364. package/src/flags.mjs +0 -15
  365. package/src/fresh-window.mjs +0 -76
  366. package/src/gmx-attestation.mjs +0 -176
  367. package/src/index.mjs +0 -100
  368. package/src/nft-gas-war-guard.mjs +0 -139
  369. package/src/onboarding/agent-keys.mjs +0 -161
  370. package/src/onboarding/harness-configs.mjs +0 -102
  371. package/src/onboarding/index.mjs +0 -18
  372. package/src/onboarding/tiers.mjs +0 -139
  373. package/src/oracle-env.mjs +0 -47
  374. package/src/portfolio-risk.mjs +0 -170
  375. package/src/prepare-envelope.mjs +0 -186
  376. package/src/profile-upgrade.mjs +0 -277
  377. package/src/protocol-execution.mjs +0 -84
  378. package/src/protocol-templates/gate.mjs +0 -179
  379. package/src/protocol-templates/prepare-deploy.mjs +0 -81
  380. package/src/public-api/buzz-integration.mjs +0 -256
  381. package/src/public-api/connect-agent.mjs +0 -416
  382. package/src/public-api/grants.mjs +0 -142
  383. package/src/public-api/http.mjs +0 -389
  384. package/src/public-control/aa-adapter.mjs +0 -402
  385. package/src/public-control/build-registry.mjs +0 -227
  386. package/src/public-control/bundler-client.mjs +0 -357
  387. package/src/public-control/grant-indexer.mjs +0 -296
  388. package/src/public-control/policy-render.mjs +0 -69
  389. package/src/public-control/policy-schema.mjs +0 -318
  390. package/src/public-control/runtime-config.mjs +0 -275
  391. package/src/public-control/session-key-model.mjs +0 -374
  392. package/src/public-control/session-orchestrator.mjs +0 -412
  393. package/src/rfq/intent.mjs +0 -180
  394. package/src/rfq/sources.mjs +0 -181
  395. package/src/route-attestation.mjs +0 -132
  396. package/src/router/best-execution.mjs +0 -326
  397. package/src/router/index.mjs +0 -226
  398. package/src/router/prepare-bridge.mjs +0 -289
  399. package/src/router/prepare-route.mjs +0 -381
  400. package/src/router/proposal.mjs +0 -311
  401. package/src/router/risk-classifier.mjs +0 -119
  402. package/src/router/route-sources.mjs +0 -329
  403. package/src/scanner/chains.config.mjs +0 -430
  404. package/src/scanner/contract.mjs +0 -270
  405. package/src/scanner/evm-scanner.mjs +0 -394
  406. package/src/scanner/index.mjs +0 -9
  407. package/src/scanner/v2-venue.mjs +0 -335
  408. package/src/scanner/v3-venue.mjs +0 -290
  409. package/src/scopes.mjs +0 -44
  410. package/src/sell-simulation.mjs +0 -167
  411. package/src/signals/engine.mjs +0 -146
  412. package/src/signals/index.mjs +0 -1
  413. package/src/token-transfer-guard.mjs +0 -188
  414. package/src/tui/app.mjs +0 -438
  415. package/src/tui/backend.mjs +0 -145
  416. package/src/tui/format.mjs +0 -272
  417. package/src/tui/gateway-client.mjs +0 -177
  418. package/src/tui/input.mjs +0 -501
  419. package/src/tui/renderer.mjs +0 -443
  420. package/src/tui/standalone-client.mjs +0 -666
  421. package/src/tui/theme.mjs +0 -81
  422. package/src/vault-attestation.mjs +0 -146
  423. package/src/venues.mjs +0 -206
  424. package/src/watch-preferences.mjs +0 -85
@@ -1,381 +0,0 @@
1
- // Prepare the winning route.
2
- //
3
- // The gap this closes: the router says "paraswap wins" and the user then has to
4
- // rebuild that transaction through a completely different path, by hand, hoping they
5
- // pick the same venue and parameters. That handoff is where the value of a
6
- // comparison leaks away.
7
- //
8
- // Three things make this more than a thin wrapper:
9
- //
10
- // 1. QUOTES DECAY. The comparison ran at a past block. Preparing against that
11
- // number would carry a stale minOut into a signature -- the exact failure the
12
- // guard exists to prevent. So we RE-QUOTE, and if the fresh number is materially
13
- // worse we say so rather than quietly preparing a worse trade than the one the
14
- // user agreed to.
15
- //
16
- // 2. NOT EVERY WINNER IS A TRANSACTION. CoW returns EIP-712 typed data for an
17
- // off-chain order; LI.FI/ParaSwap/0x return an unsigned EVM transaction. These
18
- // are different artifacts requiring different wallet actions, and collapsing
19
- // them into one "prepared" shape would hand someone typed data where they
20
- // expected a tx. The artifact kind is explicit and always stated.
21
- //
22
- // 3. THE DESTINATION IS THE ATTACK SURFACE. A prepared transaction is a `to` plus
23
- // opaque calldata. If that address is wrong, nothing downstream saves you. It is
24
- // echoed prominently and checked against the quoting venue.
25
- //
26
- // Custody is unchanged: this returns artifacts to sign. It cannot sign or broadcast.
27
-
28
- import { bestSwapRoute } from "./index.mjs";
29
- import { stampPrepared } from "../prepare-envelope.mjs";
30
-
31
- export const ARTIFACT = Object.freeze({
32
- /** Unsigned EVM transaction: wallet signs and broadcasts it. */
33
- TRANSACTION: "unsigned-transaction",
34
- /** EIP-712 payload: wallet signs data; a solver settles on-chain. No broadcast. */
35
- TYPED_DATA_ORDER: "typed-data-order",
36
- });
37
-
38
- /**
39
- * How much the re-quote may fall below the comparison before we refuse.
40
- *
41
- * Not zero: prices move between blocks and a hard-zero tolerance would make prepare
42
- * fail constantly for no safety benefit. But bounded, because "the route you picked
43
- * is now 4% worse" is a decision the user should get to make again.
44
- */
45
- const DEFAULT_DRIFT_TOLERANCE_BPS = 100;
46
-
47
- const PREPARERS = {
48
- // On-chain Uniswap V3. Unlike the aggregators below, this builds calldata from the
49
- // chain's own router rather than an API's transaction payload — which is what makes
50
- // chains no aggregator indexes (e.g. Robinhood 4663) preparable at all.
51
- //
52
- // The provider stamps requiresUserSignature:true / signingReady:false /
53
- // broadcastReady:false. Preparing is NOT permission to execute: the wallet is still
54
- // the only thing that can authorize this, and the unattended daemon surface list
55
- // (hl, poly) is deliberately unchanged by adding this.
56
- "uniswap-v3": async ({ chainId, tokenIn, tokenOut, amountIn, taker }, opts) => {
57
- const { uniV3PrepareExactIn } = await import("../data/providers/uniswap-v3.mjs");
58
- const p = await uniV3PrepareExactIn(
59
- { chainId, tokenIn, tokenOut, amountIn, recipient: taker },
60
- opts,
61
- );
62
- return {
63
- artifactKind: ARTIFACT.TRANSACTION,
64
- transaction: p.transaction,
65
- requiresApproval: p.requiresApproval ?? null,
66
- amountOut: p.quote?.amountOut ?? null,
67
- minOut: p.quote?.amountOutMinimum ?? null,
68
- };
69
- },
70
-
71
- lifi: async ({ chainId, tokenIn, tokenOut, amountIn, taker }, opts) => {
72
- const { lifiPrepare } = await import("../data/providers/lifi.mjs");
73
- const p = await lifiPrepare(
74
- { fromChain: chainId, toChain: chainId, fromToken: tokenIn, toToken: tokenOut, fromAmount: amountIn, fromAddress: taker },
75
- opts,
76
- );
77
- return {
78
- artifactKind: ARTIFACT.TRANSACTION,
79
- transaction: p.transaction,
80
- requiresApproval: p.requiresApproval ?? null,
81
- amountOut: p.quote?.estimate?.toAmount ?? null,
82
- minOut: p.quote?.estimate?.toAmountMin ?? null,
83
- };
84
- },
85
-
86
- paraswap: async ({ chainId, tokenIn, tokenOut, amountIn, taker, decimalsIn, decimalsOut }, opts) => {
87
- const { paraswapPrepare } = await import("../data/providers/paraswap.mjs");
88
- const p = await paraswapPrepare(
89
- { chainId, srcToken: tokenIn, destToken: tokenOut, amount: amountIn, srcDecimals: decimalsIn, destDecimals: decimalsOut, userAddress: taker, side: "SELL" },
90
- opts,
91
- );
92
- return {
93
- artifactKind: ARTIFACT.TRANSACTION,
94
- transaction: p.transaction,
95
- requiresApproval: p.requiresApproval ?? null,
96
- amountOut: p.quote?.priceRoute?.destAmount ?? null,
97
- minOut: p.quote?.amountOutMinimum ?? null,
98
- };
99
- },
100
-
101
- "0x": async ({ chainId, tokenIn, tokenOut, amountIn, taker }, opts) => {
102
- const { zeroxPrepare } = await import("../data/providers/zerox.mjs");
103
- const p = await zeroxPrepare(
104
- { chainId, sellToken: tokenIn, buyToken: tokenOut, sellAmount: amountIn, taker },
105
- opts,
106
- );
107
- return {
108
- artifactKind: ARTIFACT.TRANSACTION,
109
- transaction: p.transaction,
110
- requiresApproval: p.requiresApproval ?? null,
111
- amountOut: p.quote?.buyAmount ?? null,
112
- minOut: p.quote?.minBuyAmount ?? null,
113
- };
114
- },
115
-
116
- cow: async ({ chainId, tokenIn, tokenOut, amountIn, taker }, opts) => {
117
- const { cowPrepareOrder } = await import("../data/providers/cowswap.mjs");
118
- const p = await cowPrepareOrder(
119
- { chainId, sellToken: tokenIn, buyToken: tokenOut, sellAmountBeforeFee: String(amountIn), from: taker },
120
- opts,
121
- );
122
- return {
123
- // Deliberately NOT a transaction. The wallet signs typed data and a solver
124
- // settles it; there is nothing to broadcast, and treating this as a tx would
125
- // produce a confusing failure at signing time.
126
- artifactKind: ARTIFACT.TYPED_DATA_ORDER,
127
- typedData: p.typedData,
128
- // The relayer is what needs the ERC-20 allowance for CoW, NOT the settlement
129
- // contract. Approving the wrong one produces an order that can never fill.
130
- requiresApproval: {
131
- token: tokenIn,
132
- spender: p.vaultRelayer,
133
- amount: String(amountIn),
134
- note: "CoW pulls funds via the vault relayer, not the settlement contract",
135
- },
136
- settlement: p.settlement,
137
- amountOut: p.quote?.quote?.buyAmount ?? null,
138
- minOut: null,
139
- submission: "sign the typed data, then submit the order to the CoW API",
140
- };
141
- },
142
- };
143
-
144
- export function supportedPreparers() {
145
- return Object.keys(PREPARERS);
146
- }
147
-
148
- /**
149
- * Addresses that are fine for QUOTING but must never reach a prepare call.
150
- *
151
- * The quote placeholder exists so aggregators that demand a `from` will price a route
152
- * for an anonymous caller. Passing it to prepare is a category error: you would be
153
- * building a transaction for the burn address.
154
- *
155
- * Some venues catch this and some do not, which is the dangerous part. ParaSwap
156
- * rejects it with "userAddress must be a valid address" (verified live), while other
157
- * venues will happily build a transaction addressed to nobody. Relying on the venue
158
- * to notice is relying on the least careful one.
159
- */
160
- const NON_TAKER_ADDRESSES = new Set(
161
- [
162
- "0x0000000000000000000000000000000000000000",
163
- "0x000000000000000000000000000000000000dead",
164
- "0x0000000000000000000000000000000000000001",
165
- "0x00000000000000000000000000000000000a1ce5",
166
- ].map((a) => a.toLowerCase()),
167
- );
168
-
169
- const ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
170
-
171
- /**
172
- * Compare routes, then prepare the winner.
173
- *
174
- * @param {object} p same shape as bestSwapRoute, plus:
175
- * @param {string} [p.source] force a specific source instead of the winner
176
- * @param {number} [p.driftToleranceBps]
177
- */
178
- export async function prepareBestRoute(p, opts = {}) {
179
- const { taker } = p;
180
- if (!taker) {
181
- throw new Error(
182
- "prepareBestRoute requires taker: a prepared transaction is built FOR an " +
183
- "address, and the quote-only placeholder must never end up in one",
184
- );
185
- }
186
- if (!ADDRESS_RE.test(taker)) {
187
- throw new Error(`taker must be a valid 20-byte address, got "${taker}"`);
188
- }
189
- if (NON_TAKER_ADDRESSES.has(taker.toLowerCase())) {
190
- throw new Error(
191
- `taker "${taker}" is a placeholder/burn address. It is valid for quoting but ` +
192
- "not for preparing -- that would build a transaction for an address nobody " +
193
- "controls. Pass the real wallet that will sign.",
194
- );
195
- }
196
-
197
- const comparison = await bestSwapRoute(p, opts);
198
- if (!comparison.best) {
199
- // A liquidity rejection is a DIFFERENT failure from "nobody answered", and
200
- // conflating them hides the reason a live venue was refused.
201
- const blocked = comparison.impactRejected ?? [];
202
- return {
203
- ok: false,
204
- reason: blocked.length
205
- ? blocked[0].reason
206
- : "no source returned a usable route",
207
- priceImpactBlocked: blocked.length > 0,
208
- impactRejected: blocked,
209
- comparison,
210
- };
211
- }
212
-
213
- // Honour an explicit override, but never silently: picking a non-winner is a
214
- // legitimate choice (a user may distrust a venue) and it should be visible.
215
- const chosenSource = p.source || comparison.best.source;
216
- const chosen = comparison.routes.find((r) => r.source === chosenSource);
217
- if (!chosen) {
218
- return {
219
- ok: false,
220
- reason: `source "${chosenSource}" did not return a usable route`,
221
- comparison,
222
- };
223
- }
224
-
225
- const prepare = PREPARERS[chosenSource];
226
- if (!prepare) {
227
- // Honest failure beats a fabricated transaction. Name the fallback.
228
- const alt = comparison.routes.find((r) => PREPARERS[r.source] && r.source !== chosenSource);
229
- return {
230
- ok: false,
231
- reason:
232
- `${chosenSource} won the comparison but has no prepare path in this build. ` +
233
- (alt
234
- ? `Next preparable route is ${alt.source}; pass source:"${alt.source}" to use it.`
235
- : "No route in this comparison can be prepared."),
236
- comparison,
237
- winner: chosenSource,
238
- };
239
- }
240
-
241
- let prepared;
242
- try {
243
- prepared = await prepare(p, opts);
244
- } catch (err) {
245
- // Read the API's actual complaint, not just the HTTP status line.
246
- //
247
- // httpJson throws `HTTP 400 POST <url>` and attaches the parsed response to
248
- // err.body. Matching only err.message would classify every venue rejection as a
249
- // generic "provider-error", which is how a fixable user-side problem ("you have
250
- // not approved yet") gets reported as an opaque failure.
251
- const detail =
252
- typeof err?.body === "string"
253
- ? err.body
254
- : err?.body
255
- ? JSON.stringify(err.body)
256
- : "";
257
- const msg = [String(err?.message || err), detail].filter(Boolean).join(" :: ");
258
-
259
- // Translate the two failures that will confuse people most.
260
- //
261
- // Several venues validate on-chain state before building calldata:
262
- // * "Not enough WETH balance" -- the taker does not hold the input token
263
- // * "Not enough WETH allowance" -- the approval does not exist YET
264
- //
265
- // The allowance case is the important one, and it is a genuine ordering
266
- // constraint rather than a bug: ParaSwap will not build swap calldata until the
267
- // TokenTransferProxy is already approved. So the honest flow is approve first,
268
- // then prepare -- which is exactly why requiresApproval is a separate step in
269
- // this API instead of being bundled into one "just sign this" blob.
270
- //
271
- // Reporting the raw HTTP 400 would read as "the router is broken" when the user
272
- // simply has not approved yet.
273
- const allowanceIssue = /allowance/i.test(msg);
274
- const balanceIssue = !allowanceIssue && /not enough|insufficient|balance/i.test(msg);
275
-
276
- let reason;
277
- let failureKind;
278
- if (allowanceIssue) {
279
- failureKind = "approval-required-first";
280
- reason =
281
- `${chosenSource} will not build swap calldata until the token approval ` +
282
- `exists on-chain. Approve the spender first, then prepare again. ` +
283
- `Underlying: ${msg}`;
284
- } else if (balanceIssue) {
285
- failureKind = "taker-not-funded";
286
- reason =
287
- `${chosenSource} refused to build the transaction: ${msg}. This venue ` +
288
- `verifies the taker holds the input token. Quoting works for any address; ` +
289
- `preparing needs the real funded wallet.`;
290
- } else {
291
- failureKind = "provider-error";
292
- reason = `${chosenSource} prepare failed: ${msg}`;
293
- }
294
-
295
- // Name a preparable alternative so a blocked winner is not a dead end.
296
- const alt = comparison.routes.find(
297
- (r) => PREPARERS[r.source] && r.source !== chosenSource,
298
- );
299
-
300
- return {
301
- ok: false,
302
- reason,
303
- failureKind,
304
- ...(alt ? { alternative: alt.source } : {}),
305
- comparison,
306
- };
307
- }
308
-
309
- // Drift check. The comparison is already stale; this is the number that will
310
- // actually be signed against.
311
- const tolerance = p.driftToleranceBps ?? DEFAULT_DRIFT_TOLERANCE_BPS;
312
- let driftBps = null;
313
- let driftWarning = null;
314
- if (prepared.amountOut != null && chosen.grossOut != null) {
315
- try {
316
- const then = BigInt(chosen.grossOut);
317
- const now = BigInt(prepared.amountOut);
318
- if (then > 0n) {
319
- driftBps = Number(((now - then) * 10_000n) / then);
320
- if (driftBps < -tolerance) {
321
- driftWarning =
322
- `route moved ${(driftBps / 100).toFixed(2)}% against you between the ` +
323
- `comparison and this prepare (tolerance ${(tolerance / 100).toFixed(2)}%). ` +
324
- "The ranking may no longer hold -- re-run the comparison before signing.";
325
- }
326
- }
327
- } catch {
328
- /* leave null rather than invent a drift figure */
329
- }
330
- }
331
-
332
- const runnersUp = comparison.routes
333
- .filter((r) => r.source !== chosenSource)
334
- .map((r) => ({ source: r.source, netOut: r.netOut, gasUsd: r.gasUsd }));
335
-
336
- return stampPrepared({
337
- ok: true,
338
- chosen: {
339
- source: chosenSource,
340
- wasWinner: chosenSource === comparison.best.source,
341
- netOut: chosen.netOut,
342
- grossOut: chosen.grossOut,
343
- gasUsd: chosen.gasUsd,
344
- },
345
- // Carry the liquidity measurement through to the caller. Without this the
346
- // guard runs but its result is invisible, so a consumer cannot tell a route
347
- // that PASSED the ceiling from one that was never measured at all.
348
- priceImpact: comparison.priceImpact ?? null,
349
- impactUnmeasured: comparison.impactUnmeasured ?? [],
350
- ...prepared,
351
- unsigned: true,
352
- signedBy: "user-wallet",
353
- // The single most security-relevant field: where value goes.
354
- destination:
355
- prepared.artifactKind === ARTIFACT.TRANSACTION
356
- ? prepared.transaction?.to ?? null
357
- : prepared.settlement ?? null,
358
- driftBps,
359
- warnings: [
360
- ...(driftWarning ? [driftWarning] : []),
361
- ...(comparison.warnings || []),
362
- ...(prepared.artifactKind === ARTIFACT.TYPED_DATA_ORDER
363
- ? [
364
- "This is an ORDER to sign, not a transaction to broadcast. Signing it " +
365
- "authorizes a solver to settle on your behalf.",
366
- ]
367
- : []),
368
- ],
369
- runnersUp,
370
- comparison: {
371
- rankedOn: comparison.rankedOn,
372
- sourcesAnswered: comparison.sourcesAnswered,
373
- sourcesTried: comparison.sourcesTried,
374
- improvementBps: comparison.improvementBps,
375
- },
376
- note:
377
- "UNSIGNED. Verify the destination address and minOut against a fresh quote " +
378
- "immediately before signing -- a quote-time minimum is not a minimum at " +
379
- "broadcast time.",
380
- }, { provider: "router", kind: "best-route" });
381
- }
@@ -1,311 +0,0 @@
1
- // Oracle Router proposal model.
2
- //
3
- // Pure, dependency-free. A "proposal" is an advisory object: a labeled
4
- // suggestion for what Oracle Control *could* do, carrying no authority of its
5
- // own. This module MUST NEVER be able to produce an object that authorizes,
6
- // signs, or broadcasts anything, and MUST NEVER accept or echo back secrets
7
- // (bearer tokens, private/session keys, passphrases, keystore paths, etc.).
8
- //
9
- // Enforcement is defense-in-depth, in this order:
10
- // 1. Reject: any dangerous field anywhere in the input throws immediately.
11
- // 2. Strip: the emitted proposal is built from an explicit field allowlist
12
- // only (nothing "extra" from the input can leak through even if step 1
13
- // had a gap).
14
- // 3. Pin: every proposal carries fixed, non-overridable advisory markers
15
- // (mode: "proposal", authorized: false, signed: false, broadcast: false)
16
- // that the caller cannot set to anything else.
17
- // 4. Freeze: the returned proposal (and its nested plain objects/arrays)
18
- // is deep-frozen so downstream code cannot mutate it into something
19
- // that looks authorized.
20
-
21
- import { classifyRisk } from "./risk-classifier.mjs";
22
-
23
- // Case-insensitive key patterns that must never appear anywhere in a
24
- // proposal request or its emitted output. Deliberately broad: it is safer to
25
- // over-reject an oddly named benign field than to under-reject a secret.
26
- export const DANGEROUS_FIELD_PATTERNS = Object.freeze([
27
- /priv(ate)?[-_ ]?key/i,
28
- /seed[-_ ]?phrase/i,
29
- /mnemonic/i,
30
- /api[-_ ]?key/i,
31
- /api[-_ ]?secret/i,
32
- /bearer/i,
33
- /session[-_ ]?key/i,
34
- /session[-_ ]?secret/i,
35
- /session[-_ ]?token/i,
36
- /keystore/i,
37
- /passphrase/i,
38
- /^password$/i,
39
- /secret/i,
40
- /signature/i,
41
- /signed[-_ ]?tx/i,
42
- /raw[-_ ]?tx/i,
43
- /broadcast/i,
44
- /authoriz/i,
45
- /^grant$/i,
46
- /grant[-_ ]?token/i,
47
- /credential/i,
48
- /house[-_ ]?wallet/i,
49
- /executor[-_ ]?token/i,
50
- /access[-_ ]?token/i,
51
- /^token$/i,
52
- /^sig$/i,
53
- /wallet[-_ ]?key/i,
54
- ]);
55
-
56
- // Exact key names the router itself emits as PINNED, hardcoded-false/fixed
57
- // advisory markers (see createProposal below). These key names happen to
58
- // match the dangerous-field patterns above (e.g. "authorized" contains
59
- // "authoriz", "canAccessSecrets" contains "secret") precisely BECAUSE they
60
- // exist to make the proposal's non-authority explicit and readable. They are
61
- // only ever assigned literal constants by this module, never taken from
62
- // caller input, so allowing them past the OUTPUT-side scan is safe. This
63
- // allowlist is NEVER applied when scanning untrusted caller input.
64
- const PINNED_SAFE_OUTPUT_KEYS = new Set([
65
- "mode",
66
- "advisoryOnly",
67
- "authorized",
68
- "signed",
69
- "broadcast",
70
- "requiresHumanConfirmation",
71
- "grantsPermissions",
72
- "capabilities",
73
- "canClassifyRisk",
74
- "canExplain",
75
- "canSimulate",
76
- "canSign",
77
- "canBroadcast",
78
- "canAuthorize",
79
- "canMintCapability",
80
- "canAccessSecrets",
81
- ]);
82
-
83
- function isDangerousKey(key, { allowPinnedSafe = false } = {}) {
84
- const k = String(key);
85
- if (allowPinnedSafe && PINNED_SAFE_OUTPUT_KEYS.has(k)) return false;
86
- return DANGEROUS_FIELD_PATTERNS.some((re) => re.test(k));
87
- }
88
-
89
- /**
90
- * Recursively scan a value for keys matching DANGEROUS_FIELD_PATTERNS.
91
- * Returns a list of dotted paths where a dangerous key was found. Pure,
92
- * read-only -- never mutates the input.
93
- *
94
- * @param {*} value
95
- * @param {string} [pathPrefix]
96
- * @param {object} [opts]
97
- * @param {boolean} [opts.allowPinnedSafe] when true, exempts this module's own
98
- * fixed advisory-marker key names (see PINNED_SAFE_OUTPUT_KEYS). Only ever
99
- * pass this when scanning output THIS module constructed itself -- never
100
- * when scanning caller-supplied input.
101
- */
102
- export function findDangerousFields(value, pathPrefix = "", opts = {}) {
103
- const hits = [];
104
- if (Array.isArray(value)) {
105
- value.forEach((item, i) => {
106
- hits.push(...findDangerousFields(item, `${pathPrefix}[${i}]`, opts));
107
- });
108
- return hits;
109
- }
110
- if (value && typeof value === "object") {
111
- for (const [key, val] of Object.entries(value)) {
112
- const path = pathPrefix ? `${pathPrefix}.${key}` : key;
113
- if (isDangerousKey(key, opts)) hits.push(path);
114
- hits.push(...findDangerousFields(val, path, opts));
115
- }
116
- return hits;
117
- }
118
- return hits;
119
- }
120
-
121
- /** Throws if `value` contains any dangerous field anywhere, at any depth.
122
- * Pass { allowPinnedSafe: true } ONLY for output this module itself built. */
123
- export function assertNoDangerousFields(value, label = "proposal input", opts = {}) {
124
- const hits = findDangerousFields(value, "", opts);
125
- if (hits.length) {
126
- throw new Error(
127
- `${label} contains disallowed secret/signing/broadcast field(s): ${hits.join(", ")}`
128
- );
129
- }
130
- }
131
-
132
- /** Deep-clones plain objects/arrays with any dangerous keys removed. Defense
133
- * in depth only -- createProposal() rejects rather than relying on this to
134
- * silently clean up the input. */
135
- export function stripDangerousFields(value) {
136
- if (Array.isArray(value)) return value.map(stripDangerousFields);
137
- if (value && typeof value === "object") {
138
- const out = {};
139
- for (const [key, val] of Object.entries(value)) {
140
- if (isDangerousKey(key)) continue;
141
- out[key] = stripDangerousFields(val);
142
- }
143
- return out;
144
- }
145
- return value;
146
- }
147
-
148
- function deepFreeze(value) {
149
- if (Array.isArray(value)) {
150
- value.forEach(deepFreeze);
151
- return Object.freeze(value);
152
- }
153
- if (value && typeof value === "object") {
154
- for (const v of Object.values(value)) deepFreeze(v);
155
- return Object.freeze(value);
156
- }
157
- return value;
158
- }
159
-
160
- // Fields the router is allowed to read off a proposal request. Anything not
161
- // in this list is dropped when the proposal is built, regardless of what the
162
- // caller sent -- this is what makes step 2 (Strip) effective even if a
163
- // dangerous field used a name the regex list hasn't seen yet.
164
- const ALLOWED_INPUT_FIELDS = Object.freeze([
165
- "kind",
166
- "target",
167
- "notionalUsd",
168
- "chainId",
169
- "venue",
170
- "destinationKnown",
171
- "unlimitedApproval",
172
- "crossChain",
173
- "note",
174
- ]);
175
-
176
- function pickAllowed(input) {
177
- const out = {};
178
- for (const key of ALLOWED_INPUT_FIELDS) {
179
- if (input && Object.prototype.hasOwnProperty.call(input, key) && input[key] !== undefined) {
180
- out[key] = input[key];
181
- }
182
- }
183
- return out;
184
- }
185
-
186
- let proposalCounter = 0;
187
- function nextProposalId(nowMs) {
188
- proposalCounter += 1;
189
- return `proposal-${nowMs}-${proposalCounter}`;
190
- }
191
-
192
- /**
193
- * Build an advisory-only proposal object. Never authorizes, signs, or
194
- * broadcasts anything; the returned object cannot be mistaken for one that
195
- * does because its authority markers are pinned to false/"proposal" and it is
196
- * deep-frozen.
197
- *
198
- * @param {object} input
199
- * @param {string} input.kind see risk-classifier.mjs for recognized kinds
200
- * @param {string} [input.target] human-readable description of the target (e.g. "HL BTC-PERP")
201
- * @param {number} [input.notionalUsd]
202
- * @param {number} [input.chainId]
203
- * @param {string} [input.venue]
204
- * @param {boolean} [input.destinationKnown]
205
- * @param {boolean} [input.unlimitedApproval]
206
- * @param {boolean} [input.crossChain]
207
- * @param {string} [input.note] free-text rationale; itself scanned for dangerous fields if an object is passed by mistake
208
- * @param {number} [nowMs] injectable clock for deterministic tests
209
- * @returns {object} frozen proposal
210
- */
211
- export function createProposal(input = {}, nowMs = Date.now()) {
212
- if (input === null || typeof input !== "object" || Array.isArray(input)) {
213
- throw new Error("proposal input must be a plain object");
214
- }
215
-
216
- // Step 1: reject. Scan the FULL raw input (not just the allowlisted
217
- // subset) so a caller cannot smuggle a secret in under an allowed key name
218
- // collision, nor bury one in an unlisted field and have it silently
219
- // dropped without anyone noticing the attempt.
220
- assertNoDangerousFields(input, "proposal input");
221
-
222
- const kind = String(input.kind || "").trim().toLowerCase();
223
- if (!kind) throw new Error("proposal input: kind is required");
224
-
225
- // Step 2: strip / allowlist. Only known-safe fields are read from input.
226
- const safeInput = pickAllowed(input);
227
- safeInput.kind = kind;
228
-
229
- const risk = classifyRisk({
230
- kind,
231
- notionalUsd: safeInput.notionalUsd,
232
- destinationKnown: safeInput.destinationKnown,
233
- unlimitedApproval: safeInput.unlimitedApproval,
234
- crossChain: safeInput.crossChain,
235
- });
236
-
237
- const proposal = {
238
- id: nextProposalId(Number(nowMs) || Date.now()),
239
- createdAt: new Date(Number(nowMs) || Date.now()).toISOString(),
240
-
241
- kind: safeInput.kind,
242
- target: safeInput.target != null ? String(safeInput.target) : null,
243
- notionalUsd: safeInput.notionalUsd != null ? Number(safeInput.notionalUsd) : null,
244
- chainId: safeInput.chainId != null ? Number(safeInput.chainId) : null,
245
- venue: safeInput.venue != null ? String(safeInput.venue) : null,
246
- note: safeInput.note != null ? String(safeInput.note) : null,
247
-
248
- risk: {
249
- tier: risk.tier,
250
- score: risk.score,
251
- reasons: risk.reasons,
252
- },
253
-
254
- // Step 3: pinned advisory markers. These are NOT derived from input and
255
- // cannot be overridden by any input field -- they are literal constants.
256
- mode: "proposal",
257
- advisoryOnly: true,
258
- authorized: false,
259
- signed: false,
260
- broadcast: false,
261
- requiresHumanConfirmation: true,
262
- grantsPermissions: false,
263
- capabilities: Object.freeze({
264
- canClassifyRisk: true,
265
- canExplain: true,
266
- canSimulate: kind === "simulate",
267
- canSign: false,
268
- canBroadcast: false,
269
- canAuthorize: false,
270
- canMintCapability: false,
271
- canAccessSecrets: false,
272
- }),
273
- };
274
-
275
- // Belt-and-suspenders: re-verify the object we are about to hand out
276
- // contains no dangerous keys before freezing, in case a future edit to
277
- // ALLOWED_INPUT_FIELDS accidentally lets one through. allowPinnedSafe is
278
- // required here because this module's own fixed advisory markers (e.g.
279
- // "authorized", "broadcast", "canAccessSecrets") intentionally reuse
280
- // wording from the dangerous-pattern list to stay self-documenting; they
281
- // are hardcoded constants above, never derived from input.
282
- assertNoDangerousFields(proposal, "proposal output", { allowPinnedSafe: true });
283
-
284
- return deepFreeze(proposal);
285
- }
286
-
287
- /**
288
- * Defense-in-depth guard for anything downstream that receives a proposal
289
- * object from the router and wants to double check, before acting on it in
290
- * any way, that it really is advisory-only. Throws if the object does not
291
- * look like a well-formed, unauthorized proposal.
292
- */
293
- export function assertAdvisoryProposal(proposal) {
294
- if (!proposal || typeof proposal !== "object") {
295
- throw new Error("proposal required");
296
- }
297
- if (proposal.mode !== "proposal") throw new Error("proposal: mode must be \"proposal\"");
298
- if (proposal.authorized !== false) throw new Error("proposal: authorized must be false");
299
- if (proposal.signed !== false) throw new Error("proposal: signed must be false");
300
- if (proposal.broadcast !== false) throw new Error("proposal: broadcast must be false");
301
- if (proposal.advisoryOnly !== true) throw new Error("proposal: advisoryOnly must be true");
302
- if (proposal.grantsPermissions !== false) {
303
- throw new Error("proposal: grantsPermissions must be false");
304
- }
305
- const caps = proposal.capabilities || {};
306
- if (caps.canSign || caps.canBroadcast || caps.canAuthorize || caps.canMintCapability || caps.canAccessSecrets) {
307
- throw new Error("proposal: capabilities must not grant sign/broadcast/authorize/mint/secret access");
308
- }
309
- assertNoDangerousFields(proposal, "proposal", { allowPinnedSafe: true });
310
- return true;
311
- }