@oakagentkit/core 0.3.4 → 0.3.5

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 (247) hide show
  1. package/build/dist/api/history.js +1 -1
  2. package/build/dist/api/modules/borro/index.js +1 -1
  3. package/build/dist/api/modules/borro/positions.js +1 -1
  4. package/build/dist/api/modules/borro/reader.js +1 -1
  5. package/build/dist/api/modules/chop/actions.d.ts +13 -1
  6. package/build/dist/api/modules/chop/actions.js +1 -1
  7. package/build/dist/api/modules/chop/checks.js +1 -1
  8. package/build/dist/api/modules/chop/copy.d.ts +1 -0
  9. package/build/dist/api/modules/chop/copy.js +1 -1
  10. package/build/dist/api/modules/chop/display.d.ts +36 -0
  11. package/build/dist/api/modules/chop/display.js +1 -0
  12. package/build/dist/api/modules/chop/guard.js +1 -1
  13. package/build/dist/api/modules/chop/index.js +1 -1
  14. package/build/dist/api/modules/chop/pins.d.ts +1 -0
  15. package/build/dist/api/modules/chop/pins.js +1 -1
  16. package/build/dist/api/modules/chop/positions.js +1 -1
  17. package/build/dist/api/modules/chop/reader.d.ts +6 -1
  18. package/build/dist/api/modules/chop/reader.js +1 -1
  19. package/build/dist/api/modules/chop/types.d.ts +7 -0
  20. package/build/dist/api/modules/chop/unfarm.d.ts +16 -0
  21. package/build/dist/api/modules/chop/unfarm.js +1 -0
  22. package/build/dist/api/modules/clanker/index.js +1 -1
  23. package/build/dist/api/modules/earn/index.js +1 -1
  24. package/build/dist/api/modules/erc8004/index.js +1 -1
  25. package/build/dist/api/modules/factor/actions.js +1 -1
  26. package/build/dist/api/modules/factor/api.js +1 -1
  27. package/build/dist/api/modules/factor/checks.js +1 -1
  28. package/build/dist/api/modules/factor/copy.d.ts +11 -11
  29. package/build/dist/api/modules/factor/copy.js +1 -1
  30. package/build/dist/api/modules/factor/guard.js +1 -1
  31. package/build/dist/api/modules/factor/index.js +1 -1
  32. package/build/dist/api/modules/factor/reader.js +1 -1
  33. package/build/dist/api/modules/fobo/client.js +1 -1
  34. package/build/dist/api/modules/fobo/index.js +1 -1
  35. package/build/dist/api/modules/gloam/index.js +1 -1
  36. package/build/dist/api/modules/grove/index.js +1 -1
  37. package/build/dist/api/modules/heyresearch/builder-feed.js +1 -1
  38. package/build/dist/api/modules/heyresearch/index.js +1 -1
  39. package/build/dist/api/modules/heyresearch/public-reads.js +1 -1
  40. package/build/dist/api/modules/heyresearch/scan.js +1 -1
  41. package/build/dist/api/modules/heyresearch/token-facts.js +1 -1
  42. package/build/dist/api/modules/hoodlock/airdrop.js +1 -1
  43. package/build/dist/api/modules/hoodlock/fee.js +1 -1
  44. package/build/dist/api/modules/hoodlock/guard.js +1 -1
  45. package/build/dist/api/modules/hoodlock/index.js +1 -1
  46. package/build/dist/api/modules/hoodlock/lifecycle.js +1 -1
  47. package/build/dist/api/modules/hoodlock/locks-burn.js +1 -1
  48. package/build/dist/api/modules/hoodlock/public.js +1 -1
  49. package/build/dist/api/modules/hookr/actions.js +1 -1
  50. package/build/dist/api/modules/hookr/create-cancel.js +1 -1
  51. package/build/dist/api/modules/hookr/discovery.js +1 -1
  52. package/build/dist/api/modules/hookr/fill-bounty.js +1 -1
  53. package/build/dist/api/modules/hookr/index.js +1 -1
  54. package/build/dist/api/modules/hookr/launch-receipt.js +1 -1
  55. package/build/dist/api/modules/hookr/launch.js +1 -1
  56. package/build/dist/api/modules/hookr/liquidity.js +1 -1
  57. package/build/dist/api/modules/hookr/lp-positions.js +1 -1
  58. package/build/dist/api/modules/hookr/lp-reads.js +1 -1
  59. package/build/dist/api/modules/hookr/lp-receipt.js +1 -1
  60. package/build/dist/api/modules/hookr/lp-state.js +1 -1
  61. package/build/dist/api/modules/hookr/public-reads.js +1 -1
  62. package/build/dist/api/modules/hookr/relay.js +1 -1
  63. package/build/dist/api/modules/layerbank/actions.js +1 -1
  64. package/build/dist/api/modules/layerbank/index.js +1 -1
  65. package/build/dist/api/modules/layerbank/reader.js +1 -1
  66. package/build/dist/api/modules/longbow/administration.js +1 -1
  67. package/build/dist/api/modules/longbow/fixed.js +1 -1
  68. package/build/dist/api/modules/longbow/index.js +1 -1
  69. package/build/dist/api/modules/meridian/index.js +1 -1
  70. package/build/dist/api/modules/merkl/discovery.js +1 -1
  71. package/build/dist/api/modules/merkl/index.js +1 -1
  72. package/build/dist/api/modules/merkl/manage.js +1 -1
  73. package/build/dist/api/modules/morpho/bundles.js +1 -1
  74. package/build/dist/api/modules/morpho/in-kind.js +1 -1
  75. package/build/dist/api/modules/morpho/index.js +1 -1
  76. package/build/dist/api/modules/morpho/local-guard.js +1 -1
  77. package/build/dist/api/modules/morpho/midnight.js +1 -1
  78. package/build/dist/api/modules/morpho/protocol.js +1 -1
  79. package/build/dist/api/modules/morpho/vault-tools.js +1 -1
  80. package/build/dist/api/modules/netnet/card-plan.js +1 -1
  81. package/build/dist/api/modules/netnet/card-read.js +1 -1
  82. package/build/dist/api/modules/netnet/card-recovery.js +1 -1
  83. package/build/dist/api/modules/netnet/desk-action.js +1 -1
  84. package/build/dist/api/modules/netnet/financial.js +1 -1
  85. package/build/dist/api/modules/netnet/index.js +1 -1
  86. package/build/dist/api/modules/pendle/index.js +1 -1
  87. package/build/dist/api/modules/pendle/reader.js +1 -1
  88. package/build/dist/api/modules/pendle/trade.js +1 -1
  89. package/build/dist/api/modules/pons/index.js +1 -1
  90. package/build/dist/api/modules/priors/coverage.js +1 -1
  91. package/build/dist/api/modules/priors/discovery.js +1 -1
  92. package/build/dist/api/modules/priors/index.js +1 -1
  93. package/build/dist/api/modules/priors/integration.js +1 -1
  94. package/build/dist/api/modules/priors/stock-swap.js +1 -1
  95. package/build/dist/api/modules/raeto/index.js +1 -1
  96. package/build/dist/api/modules/relay/index.js +1 -1
  97. package/build/dist/api/modules/relay/outbound-status.js +1 -1
  98. package/build/dist/api/modules/spark/index.js +1 -1
  99. package/build/dist/api/modules/steakhouse/index.js +1 -1
  100. package/build/dist/api/modules/steakhouse/local-guard.js +1 -1
  101. package/build/dist/api/modules/steakhouse/management.js +1 -1
  102. package/build/dist/api/modules/steakhouse/v2-exit.js +1 -1
  103. package/build/dist/api/modules/tickerspring/basket-routes.js +1 -1
  104. package/build/dist/api/modules/tickerspring/contract-reads.js +1 -1
  105. package/build/dist/api/modules/tickerspring/exit-preview.js +1 -1
  106. package/build/dist/api/modules/tickerspring/guards.js +1 -1
  107. package/build/dist/api/modules/tickerspring/index.js +1 -1
  108. package/build/dist/api/modules/tickerspring/journeys.js +1 -1
  109. package/build/dist/api/modules/tickerspring/ladder.js +1 -1
  110. package/build/dist/api/modules/tickerspring/maker.js +1 -1
  111. package/build/dist/api/modules/tickerspring/order-accounting.js +1 -1
  112. package/build/dist/api/modules/tickerspring/research.js +1 -1
  113. package/build/dist/api/modules/tickerspring/strategies.js +1 -1
  114. package/build/dist/api/modules/uniswap/auction-create.js +1 -1
  115. package/build/dist/api/modules/uniswap/auction.js +1 -1
  116. package/build/dist/api/modules/uniswap/batch.js +1 -1
  117. package/build/dist/api/modules/uniswap/common.js +1 -1
  118. package/build/dist/api/modules/uniswap/fees.js +1 -1
  119. package/build/dist/api/modules/uniswap/index.js +1 -1
  120. package/build/dist/api/modules/uniswap/local-guard.js +1 -1
  121. package/build/dist/api/modules/uniswap/oracle.js +1 -1
  122. package/build/dist/api/modules/uniswap/pool-math.js +1 -1
  123. package/build/dist/api/modules/uniswap/pools.js +1 -1
  124. package/build/dist/api/modules/uniswap/position.js +1 -1
  125. package/build/dist/api/modules/uniswap/protocol.js +1 -1
  126. package/build/dist/api/modules/uniswap/quote-guard.js +1 -1
  127. package/build/dist/api/modules/uniswap/token-jar.js +1 -1
  128. package/build/dist/api/modules/uniswap/trade-batch.js +1 -1
  129. package/build/dist/api/modules/uniswap/trade.js +1 -1
  130. package/build/dist/api/modules/uniswap/v2.js +1 -1
  131. package/build/dist/api/modules/uniswap/v3.js +1 -1
  132. package/build/dist/api/modules/uniswap/v4.js +1 -1
  133. package/build/dist/api/modules/uniswap/wrap.js +1 -1
  134. package/build/dist/api/modules/upoch/index.js +1 -1
  135. package/build/dist/api/modules/upoch/reads.js +1 -1
  136. package/build/dist/api/modules/wormhole/index.js +1 -1
  137. package/build/dist/api/prices.d.ts +5 -0
  138. package/build/dist/api/prices.js +1 -1
  139. package/build/dist/api/send.js +1 -1
  140. package/build/dist/api/signing-registry.js +1 -1
  141. package/build/dist/api/tokens.d.ts +1 -0
  142. package/build/dist/api/tokens.js +1 -1
  143. package/build/dist/api/usd-estimate.d.ts +2 -0
  144. package/build/dist/api/usd-estimate.js +1 -1
  145. package/build/dist/chunks/{UBVE2U6X.js → 2FOI2625.js} +1 -1
  146. package/build/dist/chunks/{5OTQCE2E.js → 2I7XHRTI.js} +1 -1
  147. package/build/dist/chunks/{SGHSCK22.js → 2PS4GCOZ.js} +1 -1
  148. package/build/dist/chunks/3BQ5XHDJ.js +1 -0
  149. package/build/dist/chunks/{PRBIC3UK.js → 3YH5B5NQ.js} +1 -1
  150. package/build/dist/chunks/{RUSXMQSJ.js → 4HQEJHCD.js} +1 -1
  151. package/build/dist/chunks/{ZFRTBBIW.js → 4IOHSX3Z.js} +1 -1
  152. package/build/dist/chunks/5H7NVE6O.js +1 -0
  153. package/build/dist/chunks/{JJGZ7W3V.js → 6AS3TGOX.js} +1 -1
  154. package/build/dist/chunks/{RK3PPFRX.js → 6CKCZJ3F.js} +1 -1
  155. package/build/dist/chunks/{HU2JXDLH.js → 6LVHN33V.js} +1 -1
  156. package/build/dist/chunks/7OOCAZBE.js +1 -0
  157. package/build/dist/chunks/{O3XWE4FO.js → 7TRO6MBQ.js} +1 -1
  158. package/build/dist/chunks/{WX7OYCNS.js → A4FLWHLP.js} +1 -1
  159. package/build/dist/chunks/{FP7DHVK2.js → A4K5GXVO.js} +1 -1
  160. package/build/dist/chunks/{AOX6DKYU.js → AL6UXNGH.js} +1 -1
  161. package/build/dist/chunks/{FQTO7VJG.js → C57DITTF.js} +1 -1
  162. package/build/dist/chunks/{ZTX4WT62.js → CFPJDLTZ.js} +1 -1
  163. package/build/dist/chunks/{SRHVSNPX.js → CNDIAF3P.js} +1 -1
  164. package/build/dist/chunks/{LEHBRAZX.js → CW37EGPL.js} +1 -1
  165. package/build/dist/chunks/{PQG3ULRT.js → DBOGRUPS.js} +1 -1
  166. package/build/dist/chunks/{T3QEN3S6.js → E47UYYK4.js} +1 -1
  167. package/build/dist/chunks/EPOIAXCV.js +3 -0
  168. package/build/dist/chunks/{DWQJ7NSX.js → FCVH4FYH.js} +1 -1
  169. package/build/dist/chunks/{V6EVQWAL.js → FHB7QYJO.js} +1 -1
  170. package/build/dist/chunks/FRT6AC6M.js +1 -0
  171. package/build/dist/chunks/{Z5YI6KLN.js → FRVCSDKU.js} +1 -1
  172. package/build/dist/chunks/{EIE2U4OX.js → G5AMH4IP.js} +1 -1
  173. package/build/dist/chunks/{EQEMI54U.js → GDUKZYE2.js} +1 -1
  174. package/build/dist/chunks/{GNOHIL4Q.js → GKUPC4DO.js} +1 -1
  175. package/build/dist/chunks/{K7HTDKAT.js → GMMTHTCP.js} +1 -1
  176. package/build/dist/chunks/{XHFAF5PZ.js → HDBZZOHJ.js} +1 -1
  177. package/build/dist/chunks/{Q4HSQL65.js → HPS4KOU4.js} +1 -1
  178. package/build/dist/chunks/IZP3EKKS.js +1 -0
  179. package/build/dist/chunks/{P6MPKIU2.js → J7OZLXSG.js} +1 -1
  180. package/build/dist/chunks/{PXUML7HJ.js → JDHPMS7X.js} +1 -1
  181. package/build/dist/chunks/{MOZBDCVV.js → JJSCDDQO.js} +1 -1
  182. package/build/dist/chunks/{EFESPGA2.js → KCZUJ57H.js} +1 -1
  183. package/build/dist/chunks/{2ILYVUFA.js → KKTOBXIT.js} +1 -1
  184. package/build/dist/chunks/{L6CVMDWQ.js → KO7ANIKY.js} +1 -1
  185. package/build/dist/chunks/{2T6O77QZ.js → LKUZAJPZ.js} +1 -1
  186. package/build/dist/chunks/{5GQJVKVY.js → LZM3DO5Q.js} +1 -1
  187. package/build/dist/chunks/M6JNGU4E.js +1 -0
  188. package/build/dist/chunks/{MEB727X5.js → M7OVMIIE.js} +1 -1
  189. package/build/dist/chunks/{RKM62HC5.js → MJGEGNDU.js} +1 -1
  190. package/build/dist/chunks/{SYERFEJ4.js → MQXSCNUL.js} +1 -1
  191. package/build/dist/chunks/N624NR7Y.js +1 -0
  192. package/build/dist/chunks/{X3YEDVRN.js → N65J3L2H.js} +1 -1
  193. package/build/dist/chunks/{2TX7HP6M.js → N742W5KX.js} +1 -1
  194. package/build/dist/chunks/{365B4YEV.js → NIWAVMDR.js} +1 -1
  195. package/build/dist/chunks/O2QBSINK.js +1 -0
  196. package/build/dist/chunks/{FA3GBXQP.js → O4P5IQCP.js} +1 -1
  197. package/build/dist/chunks/{HUKDISRE.js → OB3YMTDI.js} +1 -1
  198. package/build/dist/chunks/{WXZ4LAKO.js → PV7FEVBD.js} +1 -1
  199. package/build/dist/chunks/{4M6XBG6X.js → Q3Q3YHEX.js} +1 -1
  200. package/build/dist/chunks/QA6Z2CYP.js +2 -0
  201. package/build/dist/chunks/{BDLV42SD.js → QBNASL3T.js} +1 -1
  202. package/build/dist/chunks/{AHUCYDBC.js → QKIQ7ZKD.js} +1 -1
  203. package/build/dist/chunks/{7FYM7FJA.js → QMIH6HXH.js} +1 -1
  204. package/build/dist/chunks/{2QP6WGKZ.js → QQD4PV64.js} +1 -1
  205. package/build/dist/chunks/{KNBNKG7P.js → R66NSNNQ.js} +1 -1
  206. package/build/dist/chunks/{VQJXQLFW.js → RP5VCG54.js} +1 -1
  207. package/build/dist/chunks/{OKXKDDBX.js → RUHNLNVX.js} +1 -1
  208. package/build/dist/chunks/{VKNKVUAA.js → S37D7HOK.js} +1 -1
  209. package/build/dist/chunks/S47M3IPR.js +1 -0
  210. package/build/dist/chunks/S65KXMZ7.js +3 -0
  211. package/build/dist/chunks/{NYHKIXJR.js → SX5YNFHG.js} +1 -1
  212. package/build/dist/chunks/{MHONMLF6.js → TGXEKBLV.js} +1 -1
  213. package/build/dist/chunks/{VHK5AYC2.js → TJU644I7.js} +1 -1
  214. package/build/dist/chunks/{O56EZB5Y.js → TOIKOIY6.js} +1 -1
  215. package/build/dist/chunks/{YR44GQG4.js → TZ7S5KRB.js} +1 -1
  216. package/build/dist/chunks/UEOS6SHR.js +1 -0
  217. package/build/dist/chunks/{USZCTSPI.js → USGMGKAG.js} +1 -1
  218. package/build/dist/chunks/{W5FM2OVB.js → UUF4Z6K6.js} +1 -1
  219. package/build/dist/chunks/{PMFR47H3.js → VREGY7E6.js} +1 -1
  220. package/build/dist/chunks/{2YYKQGJZ.js → W7BFM6CK.js} +1 -1
  221. package/build/dist/chunks/{3D7FXI6G.js → WQ2XTDHO.js} +1 -1
  222. package/build/dist/chunks/WRA3ZC6W.js +1 -0
  223. package/build/dist/chunks/{K3TZYPSV.js → XADHV2DT.js} +1 -1
  224. package/build/dist/chunks/{LVFI74ST.js → XNJ6NDQQ.js} +1 -1
  225. package/build/dist/chunks/{DD47RZFU.js → XTXXWRN2.js} +1 -1
  226. package/build/dist/chunks/{CZ66MYKR.js → XWC6IC5E.js} +1 -1
  227. package/build/dist/chunks/{DMB64UIN.js → YWVPK3DV.js} +1 -1
  228. package/build/dist/chunks/{WNWRF4HE.js → YZHJ4BAP.js} +1 -1
  229. package/build/dist/chunks/{4PB6MSGZ.js → ZKBOPZH5.js} +1 -1
  230. package/build/dist/chunks/{5ZVIAGLX.js → ZQPC54J5.js} +1 -1
  231. package/build/dist/chunks/{HDBDBKEA.js → ZVY7GGSP.js} +1 -1
  232. package/build/dist/chunks/{LQSPWRHN.js → ZX43P4BK.js} +1 -1
  233. package/build/dist/chunks/{PQOWIRKQ.js → ZXFJKW6H.js} +1 -1
  234. package/build/dist/chunks/{N6PHSHBE.js → ZXRIJG6H.js} +1 -1
  235. package/package.json +1 -1
  236. package/build/dist/chunks/3AOTYJPX.js +0 -1
  237. package/build/dist/chunks/4E7FJQLL.js +0 -1
  238. package/build/dist/chunks/4J245N3F.js +0 -1
  239. package/build/dist/chunks/BA66J5YQ.js +0 -1
  240. package/build/dist/chunks/BIY2F6MO.js +0 -1
  241. package/build/dist/chunks/DGCJZ3HO.js +0 -1
  242. package/build/dist/chunks/DHX3Q5RV.js +0 -2
  243. package/build/dist/chunks/EFUACKDK.js +0 -1
  244. package/build/dist/chunks/JW7GLNLB.js +0 -3
  245. package/build/dist/chunks/MIKQWF6Q.js +0 -3
  246. package/build/dist/chunks/P7C3TYI4.js +0 -1
  247. package/build/dist/chunks/ZNX3YVF2.js +0 -1
@@ -1 +1 @@
1
- import{l as Y}from"./BA66J5YQ.js";import{b as V,c as W,d as G}from"./4J245N3F.js";import{d as de,e as L}from"./GYPMUYB5.js";import{a as B}from"./Z7FGEWO2.js";import{a as N}from"./43LI5NKJ.js";import{b as H,c as se,d as ae,e as j}from"./IX3GZMTM.js";import{b as x,j as D}from"./TI727O2H.js";import{a as o}from"./XSD5NL7J.js";import{a as S}from"./JXOEJPJ4.js";import{decodeEventLog as $e,encodeAbiParameters as pe,encodeFunctionData as ye,erc20Abi as Z,getAddress as l,isAddress as E,keccak256 as Ee,parseAbi as _e,parseAbiParameters as we,toEventSelector as ge}from"viem";var A=l(D[4663].hookr.HookrLimitOrders.address),ve=l(D[4663].hookr.HookrRoot.address),Ne=l(D[4663].hookr.HookrRouter.address),It=l(D[4663].hookr.HookrRegistry.address),Be=l(D[4663].hookr.HookrForwarder.address),Fe=l(D[4663].hookr.PoolManager.address),At=l(D[4663].hookr.HOOKR_Token.address),Me=l("0x000000000000000000000000000000000000dEaD"),ze=8388608,qe=200,ce=60n,Xe=604800n,ue=31536000n,ht=10,St=100,xt="500000000000000",Ct="10000000000000000",me=4096n,Q=32n,Ke=1e4,Ue=(1n<<127n)-1n,le=(1n<<128n)-1n,je=(1n<<160n)-1n,Ve=(1n<<40n)-1n,We=16777215,Ge=8388607,fe=1n<<192n,ee=0,M=1,Ye=2,Qe=3,Ze=ge("OrderCreated(uint256,address,bytes32,bool,uint128,uint128,uint128,uint40,address)"),Dt=ge("OrderCancelled(uint256,address,address,uint256,uint256)"),P=_e(["function bountyBounds((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, uint128 amountIn, uint128 minAmountOut) view returns (uint128 minBounty, uint128 defaultBounty, uint128 maxBounty)","function createOrder(((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, uint128 amountIn, uint128 minAmountOut, uint160 sqrtPriceLimitX96, address recipient, uint40 expiry, uint128 bounty) params) payable returns (uint256 orderId)","function cancel(uint256 orderId, address to)","function getOrder(uint256 orderId) view returns (((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, address owner, uint40 createdAt, uint40 expiry, bool zeroForOne, uint8 status, address recipient, uint128 amountIn, uint128 minAmountOut, uint128 bounty, uint160 sqrtPriceLimitX96))","function quoteFill(uint256 orderId) view returns (bool fillable, uint256 amountOut)","function lastOrderId() view returns (uint256)","function liabilities(address currency) view returns (uint256)","function router() view returns (address)","function registry() view returns (address)","function poolManager() view returns (address)","function forwarder() view returns (address)","event OrderCreated(uint256 indexed orderId, address indexed owner, bytes32 indexed poolId, bool zeroForOne, uint128 amountIn, uint128 minAmountOut, uint128 bounty, uint40 expiry, address recipient)","event OrderCancelled(uint256 indexed orderId, address indexed owner, address indexed to, uint256 amountIn, uint256 bounty)"]);function F(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ke(e){let t=e.toLowerCase();return t===L.toLowerCase()||t===B.toLowerCase()||t===de.toLowerCase()}function $(e,t){if(typeof e!="string"||!e.trim())throw new o(`Provide a valid contract address for ${t}. Identify tokens by chain and address, never by symbol.`);let n=e.trim();if(!E(n,{strict:!1}))throw new o(`Invalid token address "${n}" for ${t}. Identify tokens by chain and address, never by symbol.`);return ke(n)?L:l(n)}function be(e){let t=e===void 0?x:Number(e);if(!Number.isSafeInteger(t)||t!==x)throw new o(`Hookr limit orders are only supported on Robinhood Chain (${x}).`);return x}function Je(e){switch(e){case ee:return"None";case M:return"Open";case Ye:return"Filled";case Qe:return"Cancelled";default:return"Unknown"}}function et(e,t,n=ae){if(typeof e!="string"||!/^-?\d+$/.test(e.trim()))throw new o("Signed amount must be an integer string in base units.");let r=e.trim();if(r.startsWith("-")){let i=r.slice(1),u=n(i,t);return u==="0"?"0":`-${u}`}return n(r,t)}function Pt(e,t,n="floor"){return se(e,t,n)}function Oe(e){return Ee(pe(we("address, address, uint24, int24, address"),[l(e.currency0),l(e.currency1),e.fee,e.tickSpacing,l(e.hooks)]))}function Ie(e,t){let n=e.toLowerCase();if(new Set([L.toLowerCase(),Me.toLowerCase(),A.toLowerCase(),Ne.toLowerCase(),Be.toLowerCase(),Fe.toLowerCase(),t.toLowerCase()]).has(n))throw new o(`Recipient ${e} is a reserved address and cannot receive Hookr limit order funds.`)}async function J(e,t,n,r){if(ke(e))return{address:B,symbol:V.symbol,decimals:V.decimals,chainId:t};let i=l(e),u=i.toLowerCase();if(F(r)){let s=typeof r.decimals=="number"&&Number.isInteger(r.decimals)&&r.decimals>=0&&r.decimals<=255?r.decimals:void 0,a=typeof r.symbol=="string"&&r.symbol.trim()?r.symbol.trim():void 0;if(s!==void 0&&a!==void 0)return{address:i,symbol:a,decimals:s,chainId:t}}if(u===W.address.toLowerCase())return{...W,chainId:t};if(u===G.address.toLowerCase())return{...G,chainId:t};try{let[s,a]=await Promise.all([n.readContract({address:i,abi:Z,functionName:"symbol"}),n.readContract({address:i,abi:Z,functionName:"decimals"})]);if(typeof s!="string"||!s.trim()||typeof a!="number"||!Number.isInteger(a)||a<0||a>255)throw new o(`Invalid token metadata for ${i}.`);return{address:i,symbol:s.trim(),decimals:a,chainId:t}}catch{throw new o(`Could not read valid token metadata for ${i}. Refusing to guess token decimals.`)}}function tt(e){let t=F(e.key)?e.key:F(e.poolKey)?e.poolKey:void 0,n=t?.fee??e.fee??ze,r=(typeof n=="string"&&/^\d+$/.test(n),Number(n));if(!Number.isInteger(r)||r<0||r>We)throw new o("Pool fee must be a valid uint24 integer (default 8388608 for Hookr dynamic fee pools).");let i=t?.tickSpacing??e.tickSpacing??qe,u=(typeof i=="string"&&/^-?\d+$/.test(i),Number(i));if(!Number.isInteger(u)||u<=0||u>Ge)throw new o("Pool tickSpacing must be a positive int24 integer.");let s=t?.hooks??e.hooks??ve;if(typeof s!="string"||!E(s,{strict:!1}))throw new o("Provide a valid Hookr root contract address for hooks.");let a=l(s);if(t?.currency0!==void 0&&t?.currency1!==void 0||e.currency0!==void 0&&e.currency1!==void 0){let m=$(t?.currency0??e.currency0,"currency0"),I=$(t?.currency1??e.currency1,"currency1");if(m.toLowerCase()===I.toLowerCase())throw new o("Pool currency0 and currency1 must be distinct token addresses.");if(BigInt(m)>=BigInt(I))throw new o("Pool currency0 must sort strictly before currency1 by address.");let b;if(typeof e.zeroForOne=="boolean")b=e.zeroForOne;else if(e.tokenIn!==void 0||e.from!==void 0){let C=$(e.tokenIn??e.from,"tokenIn");if(C.toLowerCase()===m.toLowerCase())b=!0;else if(C.toLowerCase()===I.toLowerCase())b=!1;else throw new o("tokenIn does not match currency0 or currency1 of the pool key.")}else throw new o("Provide zeroForOne (boolean) or tokenIn when specifying a pool key.");return{key:{currency0:m,currency1:I,fee:r,tickSpacing:u,hooks:a},zeroForOne:b}}let w=e.tokenIn??e.from,f=e.tokenOut??e.to;if(w===void 0||f===void 0)throw new o("Provide either key ({ currency0, currency1, fee, tickSpacing, hooks }) with zeroForOne or tokenIn and tokenOut addresses.");let g=$(w,"tokenIn"),k=$(f,"tokenOut");if(g.toLowerCase()===k.toLowerCase())throw new o("Input and output tokens must have distinct addresses.");let p=BigInt(g)<BigInt(k),y=p?g:k,d=p?k:g;if(typeof e.zeroForOne=="boolean"&&e.zeroForOne!==p)throw new o("zeroForOne conflicts with the canonical sorting of tokenIn and tokenOut.");return{key:{currency0:y,currency1:d,fee:r,tickSpacing:u,hooks:a},zeroForOne:p}}function nt(e,t,n){let r=Y(t),i=r*r;if(n){let s=j(e.toString(),i.toString(),fe.toString(),"ceil");return BigInt(s)}let u=j(e.toString(),fe.toString(),i.toString(),"ceil");return BigInt(u)}function R(e,t){if(typeof e=="bigint"){if(e<0n)throw new o(`${t} must be a non-negative integer.`);return e}if(typeof e=="number"){if(!Number.isSafeInteger(e)||e<0)throw new o(`${t} must be a non-negative safe integer.`);return BigInt(e)}if(typeof e=="string")return H(e.trim());throw new o(`Provide ${t} as a decimal base-unit string.`)}async function ot(e,t){if(t!==void 0)return R(t,"now");if(typeof e.getBlock=="function"){let n=await e.getBlock().catch(()=>{throw new o("Could not read the chain timestamp for Hookr order expiry.")});return BigInt(n.timestamp)}throw new o("Could not read the chain timestamp for Hookr order expiry.")}function Ae(e,t){return!e.changes||e.changes.length===0?"no net ERC-20 transfer deltas":e.changes.map(n=>`${et(n.amount,n.token.decimals,t.formatAmount)} ${S(n.token.symbol)}`).join(", ")}function rt(e,t,n,r){if(!e||!Array.isArray(e.logs))throw new o("Provide a transaction receipt with a logs array.");for(let i of e.logs){if(!i||typeof i.address!="string"||!E(i.address,{strict:!1})||!Array.isArray(i.topics)||typeof i.data!="string"||i.topics.some(u=>typeof u!="string"||!/^0x[0-9a-fA-F]{64}$/.test(u)))throw new o(`Malformed Hookr ${t} receipt log.`);if(i.address.toLowerCase()===A.toLowerCase()&&i.topics[0]?.toLowerCase()===n.toLowerCase()){if(i.topics.length!==4||!/^0x0{24}/i.test(i.topics[2])||t==="OrderCancelled"&&!/^0x0{24}/i.test(i.topics[3])||!/^0x[0-9a-fA-F]*$/.test(i.data)||i.data.length!==2+r*64)throw new o(`Malformed Hookr ${t} receipt log.`);return{topics:i.topics,data:i.data}}}throw new o(`Could not find Hookr ${t} event in transaction receipt logs.`)}function he(e){if(e.receipt!==void 0){if(!F(e.receipt)||!Array.isArray(e.receipt.logs))throw new o("Provide a transaction receipt with a logs array.");return st({logs:e.receipt.logs})}if(e.logs!==void 0){if(!Array.isArray(e.logs))throw new o("Provide receipt logs as an array.");return it(e.logs)}}function Se(e){let t=rt(e,"OrderCreated",Ze,6);try{let n=$e({abi:P,eventName:"OrderCreated",...t,strict:!0});if(pe(we("bool, uint128, uint128, uint128, uint40, address"),[n.args.zeroForOne,n.args.amountIn,n.args.minAmountOut,n.args.bounty,n.args.expiry,n.args.recipient]).toLowerCase()!==t.data.toLowerCase())throw new o("Noncanonical Hookr OrderCreated event data.");return{orderId:n.args.orderId.toString(),owner:l(n.args.owner),poolId:n.args.poolId,zeroForOne:n.args.zeroForOne,amountIn:n.args.amountIn.toString(),minAmountOut:n.args.minAmountOut.toString(),bounty:n.args.bounty.toString(),expiry:n.args.expiry.toString(),recipient:l(n.args.recipient)}}catch{throw new o("Malformed Hookr OrderCreated receipt log.")}}function it(e){return Se({logs:e}).orderId}function st(e){return Se(e).orderId}function xe(e){if(Array.isArray(e)){let[n,r,i,u,s,a,c,w,f,g,k]=e;return{key:Array.isArray(n)?{currency0:n[0],currency1:n[1],fee:Number(n[2]),tickSpacing:Number(n[3]),hooks:n[4]}:n,owner:r,createdAt:i,expiry:u,zeroForOne:s,status:a,recipient:c,amountIn:BigInt(w),minAmountOut:BigInt(f),bounty:BigInt(g),sqrtPriceLimitX96:BigInt(k)}}let t=e;return{key:{currency0:t.key.currency0,currency1:t.key.currency1,fee:Number(t.key.fee),tickSpacing:Number(t.key.tickSpacing),hooks:t.key.hooks},owner:t.owner,createdAt:t.createdAt,expiry:t.expiry,zeroForOne:!!t.zeroForOne,status:Number(t.status),recipient:t.recipient,amountIn:BigInt(t.amountIn),minAmountOut:BigInt(t.minAmountOut),bounty:BigInt(t.bounty),sqrtPriceLimitX96:BigInt(t.sqrtPriceLimitX96)}}async function Ce(e,t,n){let r=R(t,"orderId");if(r<=0n)throw new o("Order ID must be a positive integer.");let i=e.clientFor(x),u=n?.order??await i.readContract({address:A,abi:P,functionName:"getOrder",args:[r]}).catch(()=>{throw new o(`Could not read Hookr order #${r}. Order coverage is incomplete.`)}),s=xe(u),a=Number(s.status);if(s.owner.toLowerCase()===L.toLowerCase()||a===ee)throw new o(`Hookr order #${r} does not exist.`);let c={currency0:l(s.key.currency0),currency1:l(s.key.currency1),fee:Number(s.key.fee),tickSpacing:Number(s.key.tickSpacing),hooks:l(s.key.hooks)},w=s.zeroForOne?c.currency0:c.currency1,f=s.zeroForOne?c.currency1:c.currency0,g=m=>{let I=m.toLowerCase(),b=n?.tokens.get(I);if(b)return b;let C=J(m,x,i);return n?.tokens.set(I,C),C},[k,p]=await Promise.all([g(w),g(f)]),y=!1,d=0n;if(a===M)try{let m=await i.readContract({address:A,abi:P,functionName:"quoteFill",args:[r]});if(typeof m[0]!="boolean"||typeof m[1]!="bigint"||m[1]<0n)throw new o(`Invalid quote for Hookr order #${r}.`);y=m[0],d=m[1]}catch{throw new o(`Could not quote Hookr order #${r}. Fillability and output amount are unknown.`)}return{orderId:r.toString(),poolId:Oe(c),key:c,owner:l(s.owner),recipient:l(s.recipient),createdAt:BigInt(s.createdAt).toString(),expiry:BigInt(s.expiry).toString(),zeroForOne:s.zeroForOne,status:a,statusLabel:Je(a),amountIn:s.amountIn.toString(),minAmountOut:s.minAmountOut.toString(),bounty:s.bounty.toString(),sqrtPriceLimitX96:s.sqrtPriceLimitX96.toString(),tokenIn:k,tokenOut:p,fillable:y,quotedAmountOut:d.toString()}}function at(e){return{name:"hookr_create",inputSchema:{type:"object",properties:{key:{type:"object",description:"Uniswap v4 PoolKey of the pool to place the order in; omitted fee, tickSpacing and hooks use Hookr defaults. tokenIn or zeroForOne picks the direction.",properties:{currency0:{type:"string",description:"Lower-sorted pool token address (0x followed by 40 hex digits)."},currency1:{type:"string",description:"Higher-sorted pool token address (0x followed by 40 hex digits)."},fee:{type:"number",description:"Pool fee in pips, hundredths of a basis point (3000 = 0.3%); default 8388608, the v4 dynamic-fee flag of Hookr pools."},tickSpacing:{type:"number",description:"Pool tick spacing, a positive integer; defaults to the Hookr pool spacing."},hooks:{type:"string",description:"Address of the pool hook contract; defaults to the Hookr root hook."}}},tokenIn:{type:"string",description:"Input token address on chain 4663."},tokenOut:{type:"string",description:"Output token address on chain 4663."},zeroForOne:{type:"boolean",description:"True when selling currency0 for currency1."},amountIn:{type:"string",description:"Input amount in base units (uint128)."},minAmountOut:{type:"string",description:"Minimum net output amount in base units (uint128)."},tick:{type:"number",description:"Optional limit tick in [-887272, 887272]."},expiry:{type:"string",description:"Order expiry unix timestamp in seconds (uint40)."},deadline:{type:"string",description:"Alias for expiry unix timestamp in seconds."},bounty:{type:"string",description:"Keeper bounty in native ETH wei (uint128)."},recipient:{type:"string",description:"Order output recipient address (must be the signing wallet)."},sqrtPriceLimitX96:{type:"string",description:"Optional sqrtPriceLimitX96 (defaults to 0)."},chainId:{type:"number",description:"Must be 4663 (Robinhood Chain)."}},required:["amountIn"]},async execute(t,n){N(n);let r=l(n),i=be(t.chainId),u=e.clientFor(i),s=he(t),{key:a,zeroForOne:c}=tt(t),w=c?a.currency0:a.currency1,f=c?a.currency1:a.currency0,[g,k]=await Promise.all([J(w,i,u,t.tokenInMeta),J(f,i,u,t.tokenOutMeta)]),p=t.recipient??r;if(typeof p!="string"||!E(p,{strict:!1}))throw new o("Provide a valid recipient address for the Hookr limit order.");let y=l(p);if(Ie(y,a.hooks),y!==r)throw new o("Hookr recipient must be the signing wallet.");if(typeof t.amountIn!="string")throw new o("Provide amountIn as an integer string in base units.");let d=H(t.amountIn);if(d<=0n||d>Ue)throw new o("amountIn must be between 1 and int128.max base units.");if(t.tick!==void 0){let T=Number(t.tick);Y(T)}let m;if(t.minAmountOut!==void 0){if(typeof t.minAmountOut!="string")throw new o("Provide minAmountOut as an integer string in base units.");m=H(t.minAmountOut)}else if(t.tick!==void 0)m=nt(d,Number(t.tick),c);else throw new o("Provide minAmountOut in base units (or tick to derive minAmountOut).");if(m<=0n||m>le)throw new o("minAmountOut must be between 1 and uint128.max base units.");let I=t.sqrtPriceLimitX96!==void 0?R(t.sqrtPriceLimitX96,"sqrtPriceLimitX96"):0n;if(I>je)throw new o("sqrtPriceLimitX96 exceeds uint160 bounds.");let b=await ot(u,t.now),C=t.expiry??t.deadline,O;if(C!==void 0)O=R(C,"expiry");else if(t.lifetime!==void 0||t.ttlSeconds!==void 0){let T=R(t.lifetime??t.ttlSeconds,"lifetime");O=b+T}else O=b+Xe;if(O<b+ce)throw new o(`Order expiry (${O}) is expired or below the minimum lifetime of ${ce} seconds from block timestamp ${b}.`);if(O>b+ue||O>Ve)throw new o(`Order expiry (${O}) exceeds the maximum lifetime of ${ue} seconds (365 days).`);let z=await u.readContract({address:A,abi:P,functionName:"bountyBounds",args:[a,c,d,m]}).catch(()=>{throw new o("Could not read Hookr bounty bounds.")}),_=BigInt(z[0]),q=BigInt(z[1]),X=BigInt(z[2]);if(t.bounty!==void 0&&typeof t.bounty!="string")throw new o("Provide bounty as an integer string in base units.");let h=t.bounty!==void 0?H(t.bounty):q,K=_>0n?_:q;if(h<_||K>0n&&h<K)throw new o(`Order keeper bounty (${h} wei) is underbounty: must be at least ${K} wei (default keeper bounty floor).`);if(h>X||h>le)throw new o(`Order keeper bounty (${h} wei) exceeds the maximum allowed bounty of ${X} wei.`);let te=w.toLowerCase()===L.toLowerCase(),v=[];if(!te){let T;try{let U=await u.readContract({address:w,abi:Z,functionName:"allowance",args:[r,A]});if(typeof U!="bigint"||U<0n)throw new o("Invalid token allowance.");T=U}catch{throw new o(`Could not read token allowance for ${w}. No approval was prepared.`)}T<d&&v.push(e.approval(w,A,d.toString(),i))}let Pe=te?d+h:h,Le=ye({abi:P,functionName:"createOrder",args:[{key:a,zeroForOne:c,amountIn:d,minAmountOut:m,sqrtPriceLimitX96:I,recipient:y,expiry:Number(O),bounty:h}]}),ne=e.formatAmount(d.toString(),g.decimals),oe=e.formatAmount(m.toString(),k.decimals),re=e.formatAmount(h.toString(),18),Te=e.unsignedTx({to:A,data:Le,value:Pe.toString(),chainId:i,description:`Create Hookr limit order on ${A}: sell ${ne} ${S(g.symbol)} (${g.address}) for at least ${oe} ${S(k.symbol)} (${k.address}) with ${re} ETH keeper bounty (fee=${a.fee}, tickSpacing=${a.tickSpacing}, expiry=${O}).`});v.push(Te);let ie=await e.preview(v,r),Re=Ae(ie,e),He=Oe(a);return{txs:v,summary:`Hookr limit order prepared: sell ${ne} ${S(g.symbol)} for at least ${oe} ${S(k.symbol)} (bounty ${re} ETH, expiry ${O}; preview deltas: ${Re}).`,preview:ie,poolId:He,key:a,zeroForOne:c,amountIn:d.toString(),minAmountOut:m.toString(),bounty:h.toString(),bountyBounds:{minBounty:_.toString(),defaultBounty:q.toString(),maxBounty:X.toString()},expiry:O.toString(),recipient:y,sqrtPriceLimitX96:I.toString(),tokenIn:g,tokenOut:k,...s!==void 0?{orderId:s}:{}}}}}function dt(e){return{name:"hookr_cancel",inputSchema:{type:"object",properties:{orderId:{type:"string",description:"Hookr order ID to cancel (uint256 decimal string)."},to:{type:"string",description:"Recipient address for the refunded principal and bounty (must be the signing wallet)."},chainId:{type:"number",description:"Must be 4663 (Robinhood Chain)."}},required:["orderId"]},async execute(t,n){N(n);let r=l(n),i=be(t.chainId),u=he(t),s=t.orderId??t.id??u;if(s===void 0)throw new o("Provide orderId to cancel a Hookr limit order.");let a=R(s,"orderId");if(a<=0n)throw new o("orderId must be a positive integer.");let c=await Ce(e,a);if(c.owner.toLowerCase()!==r.toLowerCase())throw new o(`Unauthorized cancellation: only the order owner (${c.owner}) can cancel Hookr order #${a} (caller is ${r}).`);if(c.status!==M)throw new o(`Hookr order #${a} is not open (current status: ${c.statusLabel}).`);let w=t.to??r;if(typeof w!="string"||!E(w,{strict:!1}))throw new o("Provide a valid refund recipient address for cancel.");let f=l(w);if(Ie(f,c.key.hooks),f!==r)throw new o("Hookr refund recipient must be the signing wallet.");let g=ye({abi:P,functionName:"cancel",args:[a,f]}),k=e.formatAmount(c.amountIn,c.tokenIn.decimals),p=e.formatAmount(c.bounty,18),y=e.unsignedTx({to:A,data:g,value:"0",chainId:i,description:`Cancel Hookr limit order #${a} on ${A} and refund ${k} ${S(c.tokenIn.symbol)} plus ${p} ETH bounty to ${f}.`}),d=await e.preview([y],r),m=Ae(d,e);return{txs:[y],summary:`Cancel Hookr limit order #${a}: refund ${k} ${S(c.tokenIn.symbol)} and ${p} ETH bounty to ${f} (preview deltas: ${m}).`,preview:d,orderId:a.toString(),to:f,refundedAmountIn:c.amountIn,refundedBounty:c.bounty,tokenIn:c.tokenIn,tokenOut:c.tokenOut}}}}function ct(e){let t=performance.now()+Ke;return new Proxy(e,{get(n,r,i){return r!=="readContract"?Reflect.get(n,r,i):async(...u)=>{let s=t-performance.now(),a=()=>new o("Hookr scan deadline exceeded. Order coverage is incomplete; retry later.");if(s<=0)throw a();let c;try{return await Promise.race([n.readContract(...u),new Promise((w,f)=>{c=setTimeout(()=>f(a()),s)})])}finally{c!==void 0&&clearTimeout(c)}}}})}function ut(e){return async t=>{N(t);let n=l(t),r=ct(e.clientFor(x)),i={...e,clientFor:()=>r},u=await r.readContract({address:A,abi:P,functionName:"lastOrderId"}).catch(()=>{throw new o("Could not read the last Hookr order ID. Order coverage is incomplete.")});if(typeof u!="bigint"||u<0n)throw new o("Could not read a valid last Hookr order ID. Order coverage is incomplete.");let s=u,a=s>me?s-me+1n:1n;if(s<=0n)return[];let c=[],w=new Map;for(let f=a;f<=s;f+=Q){let g=Array.from({length:Number(s-f+1n<Q?s-f+1n:Q)},(p,y)=>f+BigInt(y)),k=await Promise.all(g.map(async p=>{let y=await r.readContract({address:A,abi:P,functionName:"getOrder",args:[p]}).catch(()=>{throw new o(`Could not read Hookr order #${p}. Order coverage is incomplete.`)}),d=xe(y);if(d.owner.toLowerCase()===L||Number(d.status)===ee)throw new o(`Hookr order #${p} does not exist. Order coverage is incomplete.`);return{id:p,order:d}}));for(let{id:p,order:y}of k){if(y.owner.toLowerCase()!==n.toLowerCase()||Number(y.status)!==M)continue;let d=await Ce(i,p,{order:y,tokens:w}),m=[{token:d.tokenIn,amount:d.amountIn}];BigInt(d.bounty)>0n&&m.push({token:{address:B,symbol:"ETH",decimals:18,chainId:x},amount:d.bounty});let I=e.formatAmount(d.amountIn,d.tokenIn.decimals),b=e.formatAmount(d.minAmountOut,d.tokenOut.decimals),C=e.formatAmount(d.bounty,18),O=e.formatAmount(d.quotedAmountOut,d.tokenOut.decimals);c.push({module:"hookr",id:d.orderId,chainId:x,assets:m,description:`Hookr open limit order #${d.orderId}: sell ${I} ${S(d.tokenIn.symbol)} (${d.tokenIn.address}) for at least ${b} ${S(d.tokenOut.symbol)} (${d.tokenOut.address}), bounty ${C} ETH, expiry ${d.expiry}, fillable=${d.fillable} (quoted output ${O} ${S(d.tokenOut.symbol)}).`})}}return a>1n&&c.push({module:"hookr",id:"coverage",chainId:x,assets:[],description:`Hookr order coverage is incomplete: scanned IDs ${a}-${s}. Older orders require an explicit order ID.`}),c}}var De=e=>{let t=[at(e),dt(e)],n=ut(e);return{tools:t,positions:n}},Lt=De,Tt=De;export{A as a,ve as b,Ne as c,It as d,Be as e,Fe as f,At as g,Me as h,ze as i,qe as j,ce as k,Xe as l,ue as m,ht as n,St as o,xt as p,Ct as q,me as r,Ke as s,ee as t,M as u,Ye as v,Qe as w,Ze as x,Dt as y,P as z,et as A,Pt as B,Oe as C,rt as D,Se as E,it as F,st as G,xe as H,Ce as I,at as J,dt as K,ct as L,ut as M,De as N,Lt as O,Tt as P};
1
+ import{m as Y}from"./7OOCAZBE.js";import{b as V,c as W,d as G}from"./N624NR7Y.js";import{d as de,e as L}from"./GYPMUYB5.js";import{a as B}from"./Z7FGEWO2.js";import{a as N}from"./43LI5NKJ.js";import{b as H,c as se,d as ae,e as j}from"./IX3GZMTM.js";import{b as x,j as D}from"./TI727O2H.js";import{a as o}from"./XSD5NL7J.js";import{a as S}from"./JXOEJPJ4.js";import{decodeEventLog as $e,encodeAbiParameters as pe,encodeFunctionData as ye,erc20Abi as Z,getAddress as l,isAddress as E,keccak256 as Ee,parseAbi as _e,parseAbiParameters as we,toEventSelector as ge}from"viem";var A=l(D[4663].hookr.HookrLimitOrders.address),ve=l(D[4663].hookr.HookrRoot.address),Ne=l(D[4663].hookr.HookrRouter.address),It=l(D[4663].hookr.HookrRegistry.address),Be=l(D[4663].hookr.HookrForwarder.address),Fe=l(D[4663].hookr.PoolManager.address),At=l(D[4663].hookr.HOOKR_Token.address),Me=l("0x000000000000000000000000000000000000dEaD"),ze=8388608,qe=200,ce=60n,Xe=604800n,ue=31536000n,ht=10,St=100,xt="500000000000000",Ct="10000000000000000",me=4096n,Q=32n,Ke=1e4,Ue=(1n<<127n)-1n,le=(1n<<128n)-1n,je=(1n<<160n)-1n,Ve=(1n<<40n)-1n,We=16777215,Ge=8388607,fe=1n<<192n,ee=0,M=1,Ye=2,Qe=3,Ze=ge("OrderCreated(uint256,address,bytes32,bool,uint128,uint128,uint128,uint40,address)"),Dt=ge("OrderCancelled(uint256,address,address,uint256,uint256)"),P=_e(["function bountyBounds((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, uint128 amountIn, uint128 minAmountOut) view returns (uint128 minBounty, uint128 defaultBounty, uint128 maxBounty)","function createOrder(((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, uint128 amountIn, uint128 minAmountOut, uint160 sqrtPriceLimitX96, address recipient, uint40 expiry, uint128 bounty) params) payable returns (uint256 orderId)","function cancel(uint256 orderId, address to)","function getOrder(uint256 orderId) view returns (((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, address owner, uint40 createdAt, uint40 expiry, bool zeroForOne, uint8 status, address recipient, uint128 amountIn, uint128 minAmountOut, uint128 bounty, uint160 sqrtPriceLimitX96))","function quoteFill(uint256 orderId) view returns (bool fillable, uint256 amountOut)","function lastOrderId() view returns (uint256)","function liabilities(address currency) view returns (uint256)","function router() view returns (address)","function registry() view returns (address)","function poolManager() view returns (address)","function forwarder() view returns (address)","event OrderCreated(uint256 indexed orderId, address indexed owner, bytes32 indexed poolId, bool zeroForOne, uint128 amountIn, uint128 minAmountOut, uint128 bounty, uint40 expiry, address recipient)","event OrderCancelled(uint256 indexed orderId, address indexed owner, address indexed to, uint256 amountIn, uint256 bounty)"]);function F(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ke(e){let t=e.toLowerCase();return t===L.toLowerCase()||t===B.toLowerCase()||t===de.toLowerCase()}function $(e,t){if(typeof e!="string"||!e.trim())throw new o(`Provide a valid contract address for ${t}. Identify tokens by chain and address, never by symbol.`);let n=e.trim();if(!E(n,{strict:!1}))throw new o(`Invalid token address "${n}" for ${t}. Identify tokens by chain and address, never by symbol.`);return ke(n)?L:l(n)}function be(e){let t=e===void 0?x:Number(e);if(!Number.isSafeInteger(t)||t!==x)throw new o(`Hookr limit orders are only supported on Robinhood Chain (${x}).`);return x}function Je(e){switch(e){case ee:return"None";case M:return"Open";case Ye:return"Filled";case Qe:return"Cancelled";default:return"Unknown"}}function et(e,t,n=ae){if(typeof e!="string"||!/^-?\d+$/.test(e.trim()))throw new o("Signed amount must be an integer string in base units.");let r=e.trim();if(r.startsWith("-")){let i=r.slice(1),u=n(i,t);return u==="0"?"0":`-${u}`}return n(r,t)}function Pt(e,t,n="floor"){return se(e,t,n)}function Oe(e){return Ee(pe(we("address, address, uint24, int24, address"),[l(e.currency0),l(e.currency1),e.fee,e.tickSpacing,l(e.hooks)]))}function Ie(e,t){let n=e.toLowerCase();if(new Set([L.toLowerCase(),Me.toLowerCase(),A.toLowerCase(),Ne.toLowerCase(),Be.toLowerCase(),Fe.toLowerCase(),t.toLowerCase()]).has(n))throw new o(`Recipient ${e} is a reserved address and cannot receive Hookr limit order funds.`)}async function J(e,t,n,r){if(ke(e))return{address:B,symbol:V.symbol,decimals:V.decimals,chainId:t};let i=l(e),u=i.toLowerCase();if(F(r)){let s=typeof r.decimals=="number"&&Number.isInteger(r.decimals)&&r.decimals>=0&&r.decimals<=255?r.decimals:void 0,a=typeof r.symbol=="string"&&r.symbol.trim()?r.symbol.trim():void 0;if(s!==void 0&&a!==void 0)return{address:i,symbol:a,decimals:s,chainId:t}}if(u===W.address.toLowerCase())return{...W,chainId:t};if(u===G.address.toLowerCase())return{...G,chainId:t};try{let[s,a]=await Promise.all([n.readContract({address:i,abi:Z,functionName:"symbol"}),n.readContract({address:i,abi:Z,functionName:"decimals"})]);if(typeof s!="string"||!s.trim()||typeof a!="number"||!Number.isInteger(a)||a<0||a>255)throw new o(`Invalid token metadata for ${i}.`);return{address:i,symbol:s.trim(),decimals:a,chainId:t}}catch{throw new o(`Could not read valid token metadata for ${i}. Refusing to guess token decimals.`)}}function tt(e){let t=F(e.key)?e.key:F(e.poolKey)?e.poolKey:void 0,n=t?.fee??e.fee??ze,r=(typeof n=="string"&&/^\d+$/.test(n),Number(n));if(!Number.isInteger(r)||r<0||r>We)throw new o("Pool fee must be a valid uint24 integer (default 8388608 for Hookr dynamic fee pools).");let i=t?.tickSpacing??e.tickSpacing??qe,u=(typeof i=="string"&&/^-?\d+$/.test(i),Number(i));if(!Number.isInteger(u)||u<=0||u>Ge)throw new o("Pool tickSpacing must be a positive int24 integer.");let s=t?.hooks??e.hooks??ve;if(typeof s!="string"||!E(s,{strict:!1}))throw new o("Provide a valid Hookr root contract address for hooks.");let a=l(s);if(t?.currency0!==void 0&&t?.currency1!==void 0||e.currency0!==void 0&&e.currency1!==void 0){let m=$(t?.currency0??e.currency0,"currency0"),I=$(t?.currency1??e.currency1,"currency1");if(m.toLowerCase()===I.toLowerCase())throw new o("Pool currency0 and currency1 must be distinct token addresses.");if(BigInt(m)>=BigInt(I))throw new o("Pool currency0 must sort strictly before currency1 by address.");let b;if(typeof e.zeroForOne=="boolean")b=e.zeroForOne;else if(e.tokenIn!==void 0||e.from!==void 0){let C=$(e.tokenIn??e.from,"tokenIn");if(C.toLowerCase()===m.toLowerCase())b=!0;else if(C.toLowerCase()===I.toLowerCase())b=!1;else throw new o("tokenIn does not match currency0 or currency1 of the pool key.")}else throw new o("Provide zeroForOne (boolean) or tokenIn when specifying a pool key.");return{key:{currency0:m,currency1:I,fee:r,tickSpacing:u,hooks:a},zeroForOne:b}}let w=e.tokenIn??e.from,f=e.tokenOut??e.to;if(w===void 0||f===void 0)throw new o("Provide either key ({ currency0, currency1, fee, tickSpacing, hooks }) with zeroForOne or tokenIn and tokenOut addresses.");let g=$(w,"tokenIn"),k=$(f,"tokenOut");if(g.toLowerCase()===k.toLowerCase())throw new o("Input and output tokens must have distinct addresses.");let p=BigInt(g)<BigInt(k),y=p?g:k,d=p?k:g;if(typeof e.zeroForOne=="boolean"&&e.zeroForOne!==p)throw new o("zeroForOne conflicts with the canonical sorting of tokenIn and tokenOut.");return{key:{currency0:y,currency1:d,fee:r,tickSpacing:u,hooks:a},zeroForOne:p}}function nt(e,t,n){let r=Y(t),i=r*r;if(n){let s=j(e.toString(),i.toString(),fe.toString(),"ceil");return BigInt(s)}let u=j(e.toString(),fe.toString(),i.toString(),"ceil");return BigInt(u)}function R(e,t){if(typeof e=="bigint"){if(e<0n)throw new o(`${t} must be a non-negative integer.`);return e}if(typeof e=="number"){if(!Number.isSafeInteger(e)||e<0)throw new o(`${t} must be a non-negative safe integer.`);return BigInt(e)}if(typeof e=="string")return H(e.trim());throw new o(`Provide ${t} as a decimal base-unit string.`)}async function ot(e,t){if(t!==void 0)return R(t,"now");if(typeof e.getBlock=="function"){let n=await e.getBlock().catch(()=>{throw new o("Could not read the chain timestamp for Hookr order expiry.")});return BigInt(n.timestamp)}throw new o("Could not read the chain timestamp for Hookr order expiry.")}function Ae(e,t){return!e.changes||e.changes.length===0?"no net ERC-20 transfer deltas":e.changes.map(n=>`${et(n.amount,n.token.decimals,t.formatAmount)} ${S(n.token.symbol)}`).join(", ")}function rt(e,t,n,r){if(!e||!Array.isArray(e.logs))throw new o("Provide a transaction receipt with a logs array.");for(let i of e.logs){if(!i||typeof i.address!="string"||!E(i.address,{strict:!1})||!Array.isArray(i.topics)||typeof i.data!="string"||i.topics.some(u=>typeof u!="string"||!/^0x[0-9a-fA-F]{64}$/.test(u)))throw new o(`Malformed Hookr ${t} receipt log.`);if(i.address.toLowerCase()===A.toLowerCase()&&i.topics[0]?.toLowerCase()===n.toLowerCase()){if(i.topics.length!==4||!/^0x0{24}/i.test(i.topics[2])||t==="OrderCancelled"&&!/^0x0{24}/i.test(i.topics[3])||!/^0x[0-9a-fA-F]*$/.test(i.data)||i.data.length!==2+r*64)throw new o(`Malformed Hookr ${t} receipt log.`);return{topics:i.topics,data:i.data}}}throw new o(`Could not find Hookr ${t} event in transaction receipt logs.`)}function he(e){if(e.receipt!==void 0){if(!F(e.receipt)||!Array.isArray(e.receipt.logs))throw new o("Provide a transaction receipt with a logs array.");return st({logs:e.receipt.logs})}if(e.logs!==void 0){if(!Array.isArray(e.logs))throw new o("Provide receipt logs as an array.");return it(e.logs)}}function Se(e){let t=rt(e,"OrderCreated",Ze,6);try{let n=$e({abi:P,eventName:"OrderCreated",...t,strict:!0});if(pe(we("bool, uint128, uint128, uint128, uint40, address"),[n.args.zeroForOne,n.args.amountIn,n.args.minAmountOut,n.args.bounty,n.args.expiry,n.args.recipient]).toLowerCase()!==t.data.toLowerCase())throw new o("Noncanonical Hookr OrderCreated event data.");return{orderId:n.args.orderId.toString(),owner:l(n.args.owner),poolId:n.args.poolId,zeroForOne:n.args.zeroForOne,amountIn:n.args.amountIn.toString(),minAmountOut:n.args.minAmountOut.toString(),bounty:n.args.bounty.toString(),expiry:n.args.expiry.toString(),recipient:l(n.args.recipient)}}catch{throw new o("Malformed Hookr OrderCreated receipt log.")}}function it(e){return Se({logs:e}).orderId}function st(e){return Se(e).orderId}function xe(e){if(Array.isArray(e)){let[n,r,i,u,s,a,c,w,f,g,k]=e;return{key:Array.isArray(n)?{currency0:n[0],currency1:n[1],fee:Number(n[2]),tickSpacing:Number(n[3]),hooks:n[4]}:n,owner:r,createdAt:i,expiry:u,zeroForOne:s,status:a,recipient:c,amountIn:BigInt(w),minAmountOut:BigInt(f),bounty:BigInt(g),sqrtPriceLimitX96:BigInt(k)}}let t=e;return{key:{currency0:t.key.currency0,currency1:t.key.currency1,fee:Number(t.key.fee),tickSpacing:Number(t.key.tickSpacing),hooks:t.key.hooks},owner:t.owner,createdAt:t.createdAt,expiry:t.expiry,zeroForOne:!!t.zeroForOne,status:Number(t.status),recipient:t.recipient,amountIn:BigInt(t.amountIn),minAmountOut:BigInt(t.minAmountOut),bounty:BigInt(t.bounty),sqrtPriceLimitX96:BigInt(t.sqrtPriceLimitX96)}}async function Ce(e,t,n){let r=R(t,"orderId");if(r<=0n)throw new o("Order ID must be a positive integer.");let i=e.clientFor(x),u=n?.order??await i.readContract({address:A,abi:P,functionName:"getOrder",args:[r]}).catch(()=>{throw new o(`Could not read Hookr order #${r}. Order coverage is incomplete.`)}),s=xe(u),a=Number(s.status);if(s.owner.toLowerCase()===L.toLowerCase()||a===ee)throw new o(`Hookr order #${r} does not exist.`);let c={currency0:l(s.key.currency0),currency1:l(s.key.currency1),fee:Number(s.key.fee),tickSpacing:Number(s.key.tickSpacing),hooks:l(s.key.hooks)},w=s.zeroForOne?c.currency0:c.currency1,f=s.zeroForOne?c.currency1:c.currency0,g=m=>{let I=m.toLowerCase(),b=n?.tokens.get(I);if(b)return b;let C=J(m,x,i);return n?.tokens.set(I,C),C},[k,p]=await Promise.all([g(w),g(f)]),y=!1,d=0n;if(a===M)try{let m=await i.readContract({address:A,abi:P,functionName:"quoteFill",args:[r]});if(typeof m[0]!="boolean"||typeof m[1]!="bigint"||m[1]<0n)throw new o(`Invalid quote for Hookr order #${r}.`);y=m[0],d=m[1]}catch{throw new o(`Could not quote Hookr order #${r}. Fillability and output amount are unknown.`)}return{orderId:r.toString(),poolId:Oe(c),key:c,owner:l(s.owner),recipient:l(s.recipient),createdAt:BigInt(s.createdAt).toString(),expiry:BigInt(s.expiry).toString(),zeroForOne:s.zeroForOne,status:a,statusLabel:Je(a),amountIn:s.amountIn.toString(),minAmountOut:s.minAmountOut.toString(),bounty:s.bounty.toString(),sqrtPriceLimitX96:s.sqrtPriceLimitX96.toString(),tokenIn:k,tokenOut:p,fillable:y,quotedAmountOut:d.toString()}}function at(e){return{name:"hookr_create",inputSchema:{type:"object",properties:{key:{type:"object",description:"Uniswap v4 PoolKey of the pool to place the order in; omitted fee, tickSpacing and hooks use Hookr defaults. tokenIn or zeroForOne picks the direction.",properties:{currency0:{type:"string",description:"Lower-sorted pool token address (0x followed by 40 hex digits)."},currency1:{type:"string",description:"Higher-sorted pool token address (0x followed by 40 hex digits)."},fee:{type:"number",description:"Pool fee in pips, hundredths of a basis point (3000 = 0.3%); default 8388608, the v4 dynamic-fee flag of Hookr pools."},tickSpacing:{type:"number",description:"Pool tick spacing, a positive integer; defaults to the Hookr pool spacing."},hooks:{type:"string",description:"Address of the pool hook contract; defaults to the Hookr root hook."}}},tokenIn:{type:"string",description:"Input token address on chain 4663."},tokenOut:{type:"string",description:"Output token address on chain 4663."},zeroForOne:{type:"boolean",description:"True when selling currency0 for currency1."},amountIn:{type:"string",description:"Input amount in base units (uint128)."},minAmountOut:{type:"string",description:"Minimum net output amount in base units (uint128)."},tick:{type:"number",description:"Optional limit tick in [-887272, 887272]."},expiry:{type:"string",description:"Order expiry unix timestamp in seconds (uint40)."},deadline:{type:"string",description:"Alias for expiry unix timestamp in seconds."},bounty:{type:"string",description:"Keeper bounty in native ETH wei (uint128)."},recipient:{type:"string",description:"Order output recipient address (must be the signing wallet)."},sqrtPriceLimitX96:{type:"string",description:"Optional sqrtPriceLimitX96 (defaults to 0)."},chainId:{type:"number",description:"Must be 4663 (Robinhood Chain)."}},required:["amountIn"]},async execute(t,n){N(n);let r=l(n),i=be(t.chainId),u=e.clientFor(i),s=he(t),{key:a,zeroForOne:c}=tt(t),w=c?a.currency0:a.currency1,f=c?a.currency1:a.currency0,[g,k]=await Promise.all([J(w,i,u,t.tokenInMeta),J(f,i,u,t.tokenOutMeta)]),p=t.recipient??r;if(typeof p!="string"||!E(p,{strict:!1}))throw new o("Provide a valid recipient address for the Hookr limit order.");let y=l(p);if(Ie(y,a.hooks),y!==r)throw new o("Hookr recipient must be the signing wallet.");if(typeof t.amountIn!="string")throw new o("Provide amountIn as an integer string in base units.");let d=H(t.amountIn);if(d<=0n||d>Ue)throw new o("amountIn must be between 1 and int128.max base units.");if(t.tick!==void 0){let T=Number(t.tick);Y(T)}let m;if(t.minAmountOut!==void 0){if(typeof t.minAmountOut!="string")throw new o("Provide minAmountOut as an integer string in base units.");m=H(t.minAmountOut)}else if(t.tick!==void 0)m=nt(d,Number(t.tick),c);else throw new o("Provide minAmountOut in base units (or tick to derive minAmountOut).");if(m<=0n||m>le)throw new o("minAmountOut must be between 1 and uint128.max base units.");let I=t.sqrtPriceLimitX96!==void 0?R(t.sqrtPriceLimitX96,"sqrtPriceLimitX96"):0n;if(I>je)throw new o("sqrtPriceLimitX96 exceeds uint160 bounds.");let b=await ot(u,t.now),C=t.expiry??t.deadline,O;if(C!==void 0)O=R(C,"expiry");else if(t.lifetime!==void 0||t.ttlSeconds!==void 0){let T=R(t.lifetime??t.ttlSeconds,"lifetime");O=b+T}else O=b+Xe;if(O<b+ce)throw new o(`Order expiry (${O}) is expired or below the minimum lifetime of ${ce} seconds from block timestamp ${b}.`);if(O>b+ue||O>Ve)throw new o(`Order expiry (${O}) exceeds the maximum lifetime of ${ue} seconds (365 days).`);let z=await u.readContract({address:A,abi:P,functionName:"bountyBounds",args:[a,c,d,m]}).catch(()=>{throw new o("Could not read Hookr bounty bounds.")}),_=BigInt(z[0]),q=BigInt(z[1]),X=BigInt(z[2]);if(t.bounty!==void 0&&typeof t.bounty!="string")throw new o("Provide bounty as an integer string in base units.");let h=t.bounty!==void 0?H(t.bounty):q,K=_>0n?_:q;if(h<_||K>0n&&h<K)throw new o(`Order keeper bounty (${h} wei) is underbounty: must be at least ${K} wei (default keeper bounty floor).`);if(h>X||h>le)throw new o(`Order keeper bounty (${h} wei) exceeds the maximum allowed bounty of ${X} wei.`);let te=w.toLowerCase()===L.toLowerCase(),v=[];if(!te){let T;try{let U=await u.readContract({address:w,abi:Z,functionName:"allowance",args:[r,A]});if(typeof U!="bigint"||U<0n)throw new o("Invalid token allowance.");T=U}catch{throw new o(`Could not read token allowance for ${w}. No approval was prepared.`)}T<d&&v.push(e.approval(w,A,d.toString(),i))}let Pe=te?d+h:h,Le=ye({abi:P,functionName:"createOrder",args:[{key:a,zeroForOne:c,amountIn:d,minAmountOut:m,sqrtPriceLimitX96:I,recipient:y,expiry:Number(O),bounty:h}]}),ne=e.formatAmount(d.toString(),g.decimals),oe=e.formatAmount(m.toString(),k.decimals),re=e.formatAmount(h.toString(),18),Te=e.unsignedTx({to:A,data:Le,value:Pe.toString(),chainId:i,description:`Create Hookr limit order on ${A}: sell ${ne} ${S(g.symbol)} (${g.address}) for at least ${oe} ${S(k.symbol)} (${k.address}) with ${re} ETH keeper bounty (fee=${a.fee}, tickSpacing=${a.tickSpacing}, expiry=${O}).`});v.push(Te);let ie=await e.preview(v,r),Re=Ae(ie,e),He=Oe(a);return{txs:v,summary:`Hookr limit order prepared: sell ${ne} ${S(g.symbol)} for at least ${oe} ${S(k.symbol)} (bounty ${re} ETH, expiry ${O}; preview deltas: ${Re}).`,preview:ie,poolId:He,key:a,zeroForOne:c,amountIn:d.toString(),minAmountOut:m.toString(),bounty:h.toString(),bountyBounds:{minBounty:_.toString(),defaultBounty:q.toString(),maxBounty:X.toString()},expiry:O.toString(),recipient:y,sqrtPriceLimitX96:I.toString(),tokenIn:g,tokenOut:k,...s!==void 0?{orderId:s}:{}}}}}function dt(e){return{name:"hookr_cancel",inputSchema:{type:"object",properties:{orderId:{type:"string",description:"Hookr order ID to cancel (uint256 decimal string)."},to:{type:"string",description:"Recipient address for the refunded principal and bounty (must be the signing wallet)."},chainId:{type:"number",description:"Must be 4663 (Robinhood Chain)."}},required:["orderId"]},async execute(t,n){N(n);let r=l(n),i=be(t.chainId),u=he(t),s=t.orderId??t.id??u;if(s===void 0)throw new o("Provide orderId to cancel a Hookr limit order.");let a=R(s,"orderId");if(a<=0n)throw new o("orderId must be a positive integer.");let c=await Ce(e,a);if(c.owner.toLowerCase()!==r.toLowerCase())throw new o(`Unauthorized cancellation: only the order owner (${c.owner}) can cancel Hookr order #${a} (caller is ${r}).`);if(c.status!==M)throw new o(`Hookr order #${a} is not open (current status: ${c.statusLabel}).`);let w=t.to??r;if(typeof w!="string"||!E(w,{strict:!1}))throw new o("Provide a valid refund recipient address for cancel.");let f=l(w);if(Ie(f,c.key.hooks),f!==r)throw new o("Hookr refund recipient must be the signing wallet.");let g=ye({abi:P,functionName:"cancel",args:[a,f]}),k=e.formatAmount(c.amountIn,c.tokenIn.decimals),p=e.formatAmount(c.bounty,18),y=e.unsignedTx({to:A,data:g,value:"0",chainId:i,description:`Cancel Hookr limit order #${a} on ${A} and refund ${k} ${S(c.tokenIn.symbol)} plus ${p} ETH bounty to ${f}.`}),d=await e.preview([y],r),m=Ae(d,e);return{txs:[y],summary:`Cancel Hookr limit order #${a}: refund ${k} ${S(c.tokenIn.symbol)} and ${p} ETH bounty to ${f} (preview deltas: ${m}).`,preview:d,orderId:a.toString(),to:f,refundedAmountIn:c.amountIn,refundedBounty:c.bounty,tokenIn:c.tokenIn,tokenOut:c.tokenOut}}}}function ct(e){let t=performance.now()+Ke;return new Proxy(e,{get(n,r,i){return r!=="readContract"?Reflect.get(n,r,i):async(...u)=>{let s=t-performance.now(),a=()=>new o("Hookr scan deadline exceeded. Order coverage is incomplete; retry later.");if(s<=0)throw a();let c;try{return await Promise.race([n.readContract(...u),new Promise((w,f)=>{c=setTimeout(()=>f(a()),s)})])}finally{c!==void 0&&clearTimeout(c)}}}})}function ut(e){return async t=>{N(t);let n=l(t),r=ct(e.clientFor(x)),i={...e,clientFor:()=>r},u=await r.readContract({address:A,abi:P,functionName:"lastOrderId"}).catch(()=>{throw new o("Could not read the last Hookr order ID. Order coverage is incomplete.")});if(typeof u!="bigint"||u<0n)throw new o("Could not read a valid last Hookr order ID. Order coverage is incomplete.");let s=u,a=s>me?s-me+1n:1n;if(s<=0n)return[];let c=[],w=new Map;for(let f=a;f<=s;f+=Q){let g=Array.from({length:Number(s-f+1n<Q?s-f+1n:Q)},(p,y)=>f+BigInt(y)),k=await Promise.all(g.map(async p=>{let y=await r.readContract({address:A,abi:P,functionName:"getOrder",args:[p]}).catch(()=>{throw new o(`Could not read Hookr order #${p}. Order coverage is incomplete.`)}),d=xe(y);if(d.owner.toLowerCase()===L||Number(d.status)===ee)throw new o(`Hookr order #${p} does not exist. Order coverage is incomplete.`);return{id:p,order:d}}));for(let{id:p,order:y}of k){if(y.owner.toLowerCase()!==n.toLowerCase()||Number(y.status)!==M)continue;let d=await Ce(i,p,{order:y,tokens:w}),m=[{token:d.tokenIn,amount:d.amountIn}];BigInt(d.bounty)>0n&&m.push({token:{address:B,symbol:"ETH",decimals:18,chainId:x},amount:d.bounty});let I=e.formatAmount(d.amountIn,d.tokenIn.decimals),b=e.formatAmount(d.minAmountOut,d.tokenOut.decimals),C=e.formatAmount(d.bounty,18),O=e.formatAmount(d.quotedAmountOut,d.tokenOut.decimals);c.push({module:"hookr",id:d.orderId,chainId:x,assets:m,description:`Hookr open limit order #${d.orderId}: sell ${I} ${S(d.tokenIn.symbol)} (${d.tokenIn.address}) for at least ${b} ${S(d.tokenOut.symbol)} (${d.tokenOut.address}), bounty ${C} ETH, expiry ${d.expiry}, fillable=${d.fillable} (quoted output ${O} ${S(d.tokenOut.symbol)}).`})}}return a>1n&&c.push({module:"hookr",id:"coverage",chainId:x,assets:[],description:`Hookr order coverage is incomplete: scanned IDs ${a}-${s}. Older orders require an explicit order ID.`}),c}}var De=e=>{let t=[at(e),dt(e)],n=ut(e);return{tools:t,positions:n}},Lt=De,Tt=De;export{A as a,ve as b,Ne as c,It as d,Be as e,Fe as f,At as g,Me as h,ze as i,qe as j,ce as k,Xe as l,ue as m,ht as n,St as o,xt as p,Ct as q,me as r,Ke as s,ee as t,M as u,Ye as v,Qe as w,Ze as x,Dt as y,P as z,et as A,Pt as B,Oe as C,rt as D,Se as E,it as F,st as G,xe as H,Ce as I,at as J,dt as K,ct as L,ut as M,De as N,Lt as O,Tt as P};
@@ -0,0 +1 @@
1
+ import{d as J,e as Q,f as X,i as Y,n as Z,o as ee}from"./7OOCAZBE.js";import{a as v,d as j}from"./JFC2QCMW.js";import{a as z}from"./Y2QADJOB.js";import{a as G,b as V,c as R}from"./CFPJDLTZ.js";import{b as L,j as W}from"./TI727O2H.js";import{formatUnits as de,getAddress as le,parseAbi as ne}from"viem";var b=10n**18n,F=1n<<192n,te=ne(["function slot0() view returns (uint160,int24,uint16,uint16,uint16,uint8,bool)","function liquidity() view returns (uint128)","function getSlot0(bytes32) view returns (uint160,int24,uint24,uint24)","function getLiquidity(bytes32) view returns (uint128)"]),me=ne(["function getLaunchedToken(address) view returns ((address token,address curve,address deployer,address creatorFeeRecipient,address pairToken,uint256 graduationThreshold,uint24 poolFee,int24 tickSpacing,uint16 creatorTaxBps,bool buybackEnabled,uint8 phase,uint256 sweptQuote,uint256 sweptTokens,uint256 sweptAt,bool exists))"]),a=m=>({usdEstimate:null,estimateLabel:"price unavailable",estimateReason:m}),k=m=>`${m.chainId}:${m.address.toLowerCase()}`;async function we(m,P,w={}){let C=Number.isFinite(w.budgetMs)?Math.min(3e3,Math.max(0,w.budgetMs)):3e3,A=`Oak stopped pricing after ${C===3e3?"3 seconds":`${C} milliseconds`}`,E=new Map,O=[...new Map(P.map(e=>[k(e.token),e.token])).values()],h=!1,T=0,S=[];async function I(e){if(h)throw new Error(A);if(T>=6?await new Promise(t=>S.push(t)):T++,h)throw new Error(A);try{return await e()}finally{let t=S.shift();t?t():T--}}let B=new Map,N=new Map,q=new Map,H;function g(e){let t=B.get(e);if(!t){let n=m.clientFor(e);t=new Proxy(n,{get(r,o,c){let p=Reflect.get(r,o,c);return["readContract","getCode","multicall"].includes(String(o))?(...u)=>I(async()=>Reflect.apply(p,r,u)):p}}),B.set(e,t)}return t}function y(e){let t=N.get(e);return t||(t=I(()=>g(e).getBlockNumber({cacheTime:0})),N.set(e,t)),t}function U(e,t){return H??=Z(e,void 0,t).then(n=>{let r=BigInt(n);if(r<=0n)throw new Error("ETH average unavailable");return r}),H}function ie(e,t){let n=`${e}:${t}`,r=q.get(n);return r||(r=I(()=>g(e).getBlock({blockNumber:t})).then(o=>{if(!(o.number!==t||typeof o.timestamp!="bigint"||o.timestamp<=0n))return o.timestamp.toString()}).catch(()=>{}),q.set(n,r)),r}async function re(e,t){let n=g(e.chainId),r=await y(e.chainId),o=await j(e,n,r);if(!o)return a("Oak has no pinned pool with sufficient in-range depth for this token");let c=BigInt(e.address)<BigInt(v.usdg);return{numerator:c?o.sqrt**2n:F,denominator:(c?F:o.sqrt**2n)*10n**6n,source:`current price in the Uniswap USDG/${t.symbol} pool; on-chain trading can differ from the stock market`,block:r}}async function oe(e){let t=g(e.chainId),n=await y(e.chainId),{assets:r,isLog:o}=await Q(e,t,n,w.chopShareFacts),c=10n**BigInt(e.decimals),p=await Promise.all(r.map(d=>M(d.token,!1))),u=0n,s=1n;for(let d=0;d<r.length;d++){let l=p[d];if(!("numerator"in l))return l;u=u*l.denominator+BigInt(r[d].amount)*l.numerator*s,s*=l.denominator}return{numerator:u,denominator:s*c,block:n,source:`Chop ${o?"log":"LP reserves and log"} net backing estimate; default-caller fees may differ; locks and gas excluded`}}async function M(e,t=!0){if(X(e))return{numerator:1n,denominator:10n**6n,source:"USDG counted at $1.00"};if(e.chainId!==L)return a("Oak has no source for this token");let n=[G.oakLog.address,V].some(i=>i.toLowerCase()===e.address.toLowerCase()),r=w.chopShareFacts?.some(i=>[i.log.address,i.staking.address].some(f=>f.toLowerCase()===e.address.toLowerCase())),o=n||r;if(!o&&w.chopShareTokens?.some(i=>i.toLowerCase()===e.address.toLowerCase()))return a("chop_logs shows this log's backing");if(t&&o){if(P.filter(i=>k(i.token)===k(e)).every(i=>i.amount==="0"))return{numerator:0n,denominator:1n,source:"zero Chop share balance"};try{return await oe(e)}catch{return a("chop_logs shows this log's backing")}}let c=e.symbol;if(c.startsWith("untrusted "))try{let i=JSON.parse(c.slice(10));typeof i=="string"&&(c=i)}catch{}if(J(e))try{let i=g(e.chainId),f=await y(e.chainId),_=le(R.stateView),D=R.poolId,[ce,ue]=await Promise.all([i.readContract({address:_,abi:te,functionName:"getSlot0",args:[D],blockNumber:f}),i.readContract({address:_,abi:te,functionName:"getLiquidity",args:[D],blockNumber:f})]),K=ce[0];return K<=0n||ue<=0n?a("The pinned Uniswap v4 WETH/CHOP pool has no active liquidity, and the only other route is a near-empty pool. A quote is a sale for this amount only; Oak never uses it to value a balance."):{numerator:await U(i,f)*F,denominator:b*K**2n*10n**BigInt(e.decimals),source:"current price in the Uniswap v4 WETH/CHOP pool",block:f}}catch{return a("Oak could not verify the pinned Uniswap v4 WETH/CHOP pool for CHOP. A quote is a sale for this amount only; Oak never uses it to value a balance.")}if(c==="CHOP")return a("Oak has no pinned market for CHOP. A quote is a sale for this amount only; Oak never uses it to value a balance.");let p=v.tokens.find(i=>i.token.toLowerCase()===e.address.toLowerCase());if(p)return re(e,p);if(Object.hasOwn(v.notOffered,c))return a("Oak has no pinned market for this token");let u=g(e.chainId),s=await y(e.chainId);if(Y(e))return{numerator:await U(u,s),denominator:b*b,source:"30-minute average of the Uniswap ETH/USDG pool",block:s};let d=(m.oakTokenAddress??process.env.OAK_TOKEN_ADDRESS)?.toLowerCase()===e.address.toLowerCase();if(d)try{let i=m.resolvePrice?await m.resolvePrice(e,s):await ee(e,{client:u,blockNumber:s,oakTokenAddress:e.address,officialStockTokens:[]}),f=BigInt(i.usdE18);if(f<=0n)throw new Error("OAK price unavailable");return{numerator:f,denominator:b*10n**BigInt(e.decimals),source:"OAK price",block:s}}catch{}if(d&&(await u.readContract({address:W[L].pons.factory.address,abi:me,functionName:"getLaunchedToken",args:[e.address],blockNumber:s})).phase!==2)return a("Oak has no graduated Pons pool price for OAK");let l=await z(e,u,s);return l.numerator<=0n||l.denominator<=0n?a("Oak has no source for this token"):{numerator:await U(u,s)*l.numerator,denominator:b*l.denominator*10n**BigInt(e.decimals),source:d?"OAK's current Pons pool price; fewer than enough trades in 30 minutes for a price":"current Pons pool price",block:s}}let x=0;async function se(){for(;!h&&x<O.length;){let e=O[x++],t;try{if(!Number.isInteger(e.decimals)||e.decimals<0||e.decimals>255)throw new Error("Invalid decimals");if(t=await M(e),h||E.set(k(e),t),"numerator"in t&&t.block!==void 0){let n=await ie(e.chainId,t.block);h||(t.observedAt=n)}}catch{t=a("Oak has no source for this token")}h||E.set(k(e),t)}}let $,ae=new Promise(e=>{$=setTimeout(()=>{h=!0;for(let t of S.splice(0))t();e()},C)});try{await Promise.race([Promise.all(Array.from({length:Math.min(6,O.length)},se)),ae])}finally{clearTimeout($),h=!0}return P.map(e=>{let t;try{if(!/^\d+$/.test(e.amount)||!Number.isInteger(e.token.decimals)||e.token.decimals<0||e.token.decimals>255)throw new Error("Invalid amount");t="humanAmount"in e&&typeof e.humanAmount=="string"?e.humanAmount:de(BigInt(e.amount),e.token.decimals);let n=E.get(k(e.token));if(n&&"numerator"in n){let o=(BigInt(e.amount)*n.numerator*100n*2n+n.denominator)/(n.denominator*2n);return{...e,humanAmount:t,usdEstimate:`${o/100n}.${(o%100n).toString().padStart(2,"0")}`,estimateLabel:"estimate, not a quote",estimateSource:n.source,unitUsdE18:(n.numerator*10n**BigInt(e.token.decimals)*b/n.denominator).toString(),...n.observedAt===void 0?{}:{observedAt:n.observedAt},...n.block===void 0?{}:{estimateAsOf:n.block.toString()}}}return{...e,humanAmount:t,...n??a(A)}}catch{return{...e,...t===void 0?{}:{humanAmount:t},...a("Oak cannot format this token amount")}}})}export{we as a};
@@ -1 +1 @@
1
- import{a as f,b as a}from"./CZL6T2ZQ.js";import{a as s,b as c}from"./ZQ6AF3VX.js";import{a as w}from"./DGCJZ3HO.js";import{a as r}from"./XSD5NL7J.js";import{getAddress as d,isAddressEqual as n,keccak256 as b}from"viem";function u(e){if(!/^[0-9]+$/.test(String(e)))throw new r("Provide a Factor job ID as a non-negative integer.");let t=BigInt(e);if(t>=2n**256n)throw new r("The Factor job ID exceeds uint256.");return t}function y(e,t){if(e.codeHash.toLowerCase()!==a.desk.codeHash)throw new r("Factor desk code hash does not match the pin.");if(!n(e.burnPot,a.burnPot.address))throw new r("Factor desk burn pot does not match the pin.");if(!n(e.gateway,a.gateway.address))throw new r("Factor desk gateway does not match the pin.");if(e.stateDesk==="unreachable"){if(t)throw new r(w.stateUnavailable)}else if(!n(e.stateDesk,a.desk.address))throw new r(w.stateMismatch)}async function P(e){if(await e.getChainId()!==f.chainId)throw new r("Factor requires Robinhood Chain 4663.");let[t,o,i,C]=await Promise.all([e.getCode({address:a.desk.address}),e.readContract({address:a.desk.address,abi:s,functionName:"burnPot"}),e.readContract({address:a.desk.address,abi:s,functionName:"gateway"}),e.readContract({address:a.line.address,abi:c,functionName:"desk"})]);if(!n(C,a.desk.address))throw new r("Factor line desk does not match the pin.");return{codeHash:b(t??"0x"),burnPot:d(o),gateway:d(i)}}async function A(e,t){return e.readContract({address:a.desk.address,abi:s,functionName:"job",args:[u(t)]})}async function D(e,t){let[o,i]=await e.readContract({address:a.desk.address,abi:s,functionName:"canDrawOn",args:[u(t)]});return{early:o.toString(),pool:i.toString()}}async function F(e,t){let o=await e.readContract({address:a.line.address,abi:c,functionName:"keyOf",args:[d(t)]});return d(o)}async function I(e,t){let o=await e.getCode({address:d(t)});return o!==void 0&&o!=="0x"}export{y as a,P as b,A as c,D as d,F as e,I as f};
1
+ import{a as f,b as a}from"./CZL6T2ZQ.js";import{a as s,b as c}from"./ZQ6AF3VX.js";import{a as w}from"./UEOS6SHR.js";import{a as r}from"./XSD5NL7J.js";import{getAddress as d,isAddressEqual as n,keccak256 as b}from"viem";function u(e){if(!/^[0-9]+$/.test(String(e)))throw new r("Provide a Factor job ID as a non-negative integer.");let t=BigInt(e);if(t>=2n**256n)throw new r("The Factor job ID exceeds uint256.");return t}function y(e,t){if(e.codeHash.toLowerCase()!==a.desk.codeHash)throw new r("Factor desk code hash does not match the pin.");if(!n(e.burnPot,a.burnPot.address))throw new r("Factor desk burn pot does not match the pin.");if(!n(e.gateway,a.gateway.address))throw new r("Factor desk gateway does not match the pin.");if(e.stateDesk==="unreachable"){if(t)throw new r(w.stateUnavailable)}else if(!n(e.stateDesk,a.desk.address))throw new r(w.stateMismatch)}async function P(e){if(await e.getChainId()!==f.chainId)throw new r("Factor requires Robinhood Chain 4663.");let[t,o,i,C]=await Promise.all([e.getCode({address:a.desk.address}),e.readContract({address:a.desk.address,abi:s,functionName:"burnPot"}),e.readContract({address:a.desk.address,abi:s,functionName:"gateway"}),e.readContract({address:a.line.address,abi:c,functionName:"desk"})]);if(!n(C,a.desk.address))throw new r("Factor line desk does not match the pin.");return{codeHash:b(t??"0x"),burnPot:d(o),gateway:d(i)}}async function A(e,t){return e.readContract({address:a.desk.address,abi:s,functionName:"job",args:[u(t)]})}async function D(e,t){let[o,i]=await e.readContract({address:a.desk.address,abi:s,functionName:"canDrawOn",args:[u(t)]});return{early:o.toString(),pool:i.toString()}}async function F(e,t){let o=await e.readContract({address:a.line.address,abi:c,functionName:"keyOf",args:[d(t)]});return d(o)}async function I(e,t){let o=await e.getCode({address:d(t)});return o!==void 0&&o!=="0x"}export{y as a,P as b,A as c,D as d,F as e,I as f};
@@ -1 +1 @@
1
- import{b as Z,c as z,d as J,e as K}from"./RKM62HC5.js";import{a as W}from"./6F527FLN.js";import{a as H}from"./ZNX3YVF2.js";import{a as V}from"./IPU656WB.js";import{a as L}from"./A3PN3PK3.js";import{c as j}from"./X24YTJST.js";import{b as T,o as q}from"./GYPMUYB5.js";import{b as _}from"./SPJCSEKP.js";import{a as A,d as I,e as B}from"./43LI5NKJ.js";import{a as $}from"./66F5ZH34.js";import{g as x,m as E,n as R}from"./NWNYJ26T.js";import{b as h,e as F,j as N,k as S}from"./TI727O2H.js";import{a as o}from"./XSD5NL7J.js";import{getAddress as O,parseAbi as te}from"viem";var n=O(N[4663].vaults.groveAlm.address),ne="0x29626c2d8ca49a51e4deceec5499e52983c42bd5",m=te(["function asset() view returns (address)","function decimals() view returns (uint8)","function totalAssets() view returns (uint256)","function totalSupply() view returns (uint256)","function balanceOf(address) view returns (uint256)","function maxDeposit(address) view returns (uint256)","function maxWithdraw(address) view returns (uint256)","function previewDeposit(uint256) view returns (uint256)","function previewRedeem(uint256) view returns (uint256)","function performanceFee() view returns (uint256)","function managementFee() view returns (uint256)"]),C=$("Positive integer in token base units."),U={type:"string",description:`Public Grove vault only: ${n}. Defaults to this vault.`},Q={type:"integer",minimum:0,maximum:9999,default:T,description:`Allowed slippage in basis points (50 = 0.5%), 0 to 9999. Sets the minimum output unless you pass it explicitly. Defaults to ${T}.`};function D(t){return R(t,"Amount must be positive and within the uint256 range.",{notString:"Amount must be a positive integer string in base units.",positive:!0})}function v(t){return E(t,"Grove returned an invalid integer read.")}function M(t,d,l){if(A(d),Object.keys(t).some(u=>!["vault",...l].includes(u)))throw new o("Unsupported Grove argument.");if(t.vault!==void 0){if(typeof t.vault!="string")throw new o("Provide the public Grove vault address.");if(t.vault.toLowerCase()===ne)throw new o("The Grove ALM proxy is allocator infrastructure, not the public ERC-4626 vault.");if(A(t.vault),!x(t.vault,n))throw new o("Only the public Grove ERC-4626 vault is supported.")}}function X(t,d,l){let u=l===void 0?T:l;if(typeof u!="number")throw new o("Slippage must be an integer from 0 to 9999 bps.");let e=BigInt(q(t.toString(),u)),a=d===void 0?e:D(d);if(a<=0n||a>t)throw new o("The minimum output must be positive and no greater than the quoted output.");return a}function Y(t,d){let l=0n;for(let u of t.changes)if(!(u.token.chainId!==d.chainId||!x(u.token.address,d.address))){if(u.token.decimals!==d.decimals||typeof u.amount!="string"||!/^-?\d+$/.test(u.amount))throw new o("Grove preview returned invalid token metadata or amounts.");l+=BigInt(u.amount)}return l}var ae=t=>{async function d(e){try{return await e()}catch(a){throw new o(t.plainError(a))}}async function l(){let e=t.clientFor(h);if(await e.getChainId()!==h)throw new o("Grove requires an RPC endpoint on chain 4663.");let a=await e.readContract({address:n,abi:m,functionName:"asset"});if(typeof a!="string"||!x(a,S))throw new o("The public Grove vault must use canonical USDG on chain 4663.");let[i,r,s]=await Promise.all([e.readContract({address:O(S),abi:m,functionName:"decimals"}),e.readContract({address:n,abi:m,functionName:"decimals"}),L(e,n)]);if(i!==F||r!==18)throw new o("Grove token decimals differ from the evidenced USDG/share interface.");let p={address:O(S),chainId:h,decimals:i,symbol:"USDG"};return{client:e,asset:p,shareToken:{address:n,chainId:h,decimals:r,symbol:s}}}async function u(e,a,i,r,s,p){let f=await t.preview(e,a);if(Y(f,i)!==-r)throw new o("Grove simulation did not show the exact requested token outflow.");if(Y(f,s)<p)throw new o("Grove simulated output is below the minimum.");let g=f.changes.map(({token:w,amount:b})=>{let y=b.startsWith("-");return`${y?"-":"+"}${t.formatAmount(y?b.slice(1):b,w.decimals)} ${w.symbol} (${w.address}, chain ${w.chainId})`}).join("; ");return{txs:e,summary:`${f.summary} ${g}. Minimum ${p} base units of ${s.address} is a preview check, not enforced on-chain by standard ERC-4626. Re-preview before signing; execution output can change.`}}return{tools:[z(t,"grove_details",n),V(t,"grove_analytics",n),H(t,"grove_manage",n),...W(t,"grove",n),{name:"grove_list",inputSchema:{type:"object",properties:{vault:U},additionalProperties:!1},execute:(e,a)=>d(async()=>{M(e,a,[]);let{client:i,asset:r,shareToken:s}=await l(),[p,f,c,g,w,b]=await Promise.all([i.readContract({address:n,abi:m,functionName:"totalAssets"}),i.readContract({address:n,abi:m,functionName:"totalSupply"}),i.readContract({address:n,abi:m,functionName:"maxDeposit",args:[a]}),i.readContract({address:n,abi:m,functionName:"maxWithdraw",args:[a]}),i.readContract({address:n,abi:m,functionName:"performanceFee"}),i.readContract({address:n,abi:m,functionName:"managementFee"})]);return[{vault:n,chainId:h,name:"Grove x Steakhouse USDG",asset:r,shareToken:s,totalAssets:{token:r,amount:v(p).toString()},totalSupply:{token:s,amount:v(f).toString()},maxDeposit:v(c)===0n?null:c.toString(),maxWithdraw:v(g)===0n?null:g.toString(),maxViewCaveat:"Zero Morpho V2 maximum views mean unknown capacity. Simulate the requested action; full exits use the fresh share balance.",fees:{performanceFeeRaw:v(w).toString(),managementFeeRaw:v(b).toString(),scale:"1000000000000000000",managementFeeTimeUnit:"second",performanceFeeBasis:"accrued interest"}}]})},{name:"grove_deposit",inputSchema:{type:"object",description:"Deposit USDG in base units (1 USDG = 1000000) for 18-decimal vault shares. Exit with grove_withdraw; check positions after confirmation.",properties:{vault:U,amount:C,minSharesOut:C,slippageBps:Q},required:["amount"],additionalProperties:!1},execute:(e,a)=>d(async()=>{M(e,a,["amount","minSharesOut","slippageBps"]);let i=D(e.amount),{client:r,asset:s,shareToken:p}=await l(),f=v(await r.readContract({address:n,abi:m,functionName:"previewDeposit",args:[i]})),c=X(f,e.minSharesOut,e.slippageBps),g=I(n,s.address,i.toString(),a,h),w=[t.approval(s.address,n,i.toString(),h),t.unsignedTx(g.txs[1])];return u(w,a,s,i,p,c)})},{name:"grove_withdraw",inputSchema:{type:"object",description:"Redeem shares in 18-decimal base units, or shares all for a full exit to USDG. Check positions after confirmation.",properties:{vault:U,shares:{oneOf:[C,{const:"all",description:"Redeem the fresh full share balance."}],description:'Vault shares to redeem, in base units (shares have 18 decimals; "1000000000000000000" = 1 share), or "all" for the full balance.'},minAmountOut:C,slippageBps:Q,force:{type:"boolean",description:'True plans a full Morpho V2 force exit with penalty disclosure. Needs shares "all", minAmountOut and maxPenaltyAssets.'},maxPenaltyAssets:$('Force exit only: most USDG, in base units (6 decimals), you accept losing to the exit penalty. Example: "1000000" = 1 USDG.')},required:["shares"],additionalProperties:!1},execute:(e,a)=>d(async()=>{M(e,a,["shares","minAmountOut","slippageBps","force","maxPenaltyAssets"]);let i=e.shares==="all"?void 0:D(e.shares),{client:r,asset:s,shareToken:p}=await l(),f=v(await r.readContract({address:n,abi:m,functionName:"balanceOf",args:[a]})),c=i??f;if(c===0n||c>f)throw new o("The Grove share balance is insufficient for this withdrawal.");if(e.force!==void 0&&typeof e.force!="boolean")throw new o("force must be a boolean.");if(e.force===!0){if(e.shares!=="all"||e.slippageBps!==void 0)throw new o("Force exit requires shares all and an explicit minAmountOut; omit slippageBps.");let G=j(e.maxPenaltyAssets),ee=D(e.minAmountOut),k=await Z(t,r,n,a,c,G),P=await t.preview([k.tx],a);return K(P.changes,n,c,ee),{txs:[k.tx],preview:P,summary:`${J(k.plan)} ${P.summary}`}}if(e.maxPenaltyAssets!==void 0)throw new o("maxPenaltyAssets requires force true.");let g=v(await r.readContract({address:n,abi:m,functionName:"previewRedeem",args:[c]})),w=X(g,e.minAmountOut,e.slippageBps),y=B(n,c.toString(),a,h).txs.map(G=>t.unsignedTx({...G,description:`Redeem ${c} Grove share base units to the wallet.`}));return u(y,a,p,c,s,w)})}],positions:e=>d(async()=>{A(e);let{client:a,asset:i,shareToken:r}=await l(),s=v(await a.readContract({address:n,abi:m,functionName:"balanceOf",args:[e]}));if(s===0n)return[];let p=v(await a.readContract({address:n,abi:m,functionName:"previewRedeem",args:[s]}));return[{module:"grove",id:`${h}:${n.toLowerCase()}`,chainId:h,assets:[{token:i,amount:p.toString()}],description:`${t.formatAmount(s.toString(),r.decimals)} Grove shares (${s} base units, ${r.decimals} decimals, ${n}); estimated USDG redemption, subject to simulation.`}]})}},we=t=>_("grove",[ae(t)]);export{ae as a,we as b};
1
+ import{a as H}from"./M6JNGU4E.js";import{b as Z,c as z,d as J,e as K}from"./MJGEGNDU.js";import{a as W}from"./6F527FLN.js";import{a as V}from"./IPU656WB.js";import{a as L}from"./A3PN3PK3.js";import{c as j}from"./X24YTJST.js";import{b as T,o as q}from"./GYPMUYB5.js";import{b as _}from"./SPJCSEKP.js";import{a as A,d as I,e as B}from"./43LI5NKJ.js";import{a as $}from"./66F5ZH34.js";import{g as x,m as E,n as R}from"./NWNYJ26T.js";import{b as h,e as F,j as N,k as S}from"./TI727O2H.js";import{a as o}from"./XSD5NL7J.js";import{getAddress as O,parseAbi as te}from"viem";var n=O(N[4663].vaults.groveAlm.address),ne="0x29626c2d8ca49a51e4deceec5499e52983c42bd5",m=te(["function asset() view returns (address)","function decimals() view returns (uint8)","function totalAssets() view returns (uint256)","function totalSupply() view returns (uint256)","function balanceOf(address) view returns (uint256)","function maxDeposit(address) view returns (uint256)","function maxWithdraw(address) view returns (uint256)","function previewDeposit(uint256) view returns (uint256)","function previewRedeem(uint256) view returns (uint256)","function performanceFee() view returns (uint256)","function managementFee() view returns (uint256)"]),C=$("Positive integer in token base units."),U={type:"string",description:`Public Grove vault only: ${n}. Defaults to this vault.`},Q={type:"integer",minimum:0,maximum:9999,default:T,description:`Allowed slippage in basis points (50 = 0.5%), 0 to 9999. Sets the minimum output unless you pass it explicitly. Defaults to ${T}.`};function D(t){return R(t,"Amount must be positive and within the uint256 range.",{notString:"Amount must be a positive integer string in base units.",positive:!0})}function v(t){return E(t,"Grove returned an invalid integer read.")}function M(t,d,l){if(A(d),Object.keys(t).some(u=>!["vault",...l].includes(u)))throw new o("Unsupported Grove argument.");if(t.vault!==void 0){if(typeof t.vault!="string")throw new o("Provide the public Grove vault address.");if(t.vault.toLowerCase()===ne)throw new o("The Grove ALM proxy is allocator infrastructure, not the public ERC-4626 vault.");if(A(t.vault),!x(t.vault,n))throw new o("Only the public Grove ERC-4626 vault is supported.")}}function X(t,d,l){let u=l===void 0?T:l;if(typeof u!="number")throw new o("Slippage must be an integer from 0 to 9999 bps.");let e=BigInt(q(t.toString(),u)),a=d===void 0?e:D(d);if(a<=0n||a>t)throw new o("The minimum output must be positive and no greater than the quoted output.");return a}function Y(t,d){let l=0n;for(let u of t.changes)if(!(u.token.chainId!==d.chainId||!x(u.token.address,d.address))){if(u.token.decimals!==d.decimals||typeof u.amount!="string"||!/^-?\d+$/.test(u.amount))throw new o("Grove preview returned invalid token metadata or amounts.");l+=BigInt(u.amount)}return l}var ae=t=>{async function d(e){try{return await e()}catch(a){throw new o(t.plainError(a))}}async function l(){let e=t.clientFor(h);if(await e.getChainId()!==h)throw new o("Grove requires an RPC endpoint on chain 4663.");let a=await e.readContract({address:n,abi:m,functionName:"asset"});if(typeof a!="string"||!x(a,S))throw new o("The public Grove vault must use canonical USDG on chain 4663.");let[i,r,s]=await Promise.all([e.readContract({address:O(S),abi:m,functionName:"decimals"}),e.readContract({address:n,abi:m,functionName:"decimals"}),L(e,n)]);if(i!==F||r!==18)throw new o("Grove token decimals differ from the evidenced USDG/share interface.");let p={address:O(S),chainId:h,decimals:i,symbol:"USDG"};return{client:e,asset:p,shareToken:{address:n,chainId:h,decimals:r,symbol:s}}}async function u(e,a,i,r,s,p){let f=await t.preview(e,a);if(Y(f,i)!==-r)throw new o("Grove simulation did not show the exact requested token outflow.");if(Y(f,s)<p)throw new o("Grove simulated output is below the minimum.");let g=f.changes.map(({token:w,amount:b})=>{let y=b.startsWith("-");return`${y?"-":"+"}${t.formatAmount(y?b.slice(1):b,w.decimals)} ${w.symbol} (${w.address}, chain ${w.chainId})`}).join("; ");return{txs:e,summary:`${f.summary} ${g}. Minimum ${p} base units of ${s.address} is a preview check, not enforced on-chain by standard ERC-4626. Re-preview before signing; execution output can change.`}}return{tools:[z(t,"grove_details",n),V(t,"grove_analytics",n),H(t,"grove_manage",n),...W(t,"grove",n),{name:"grove_list",inputSchema:{type:"object",properties:{vault:U},additionalProperties:!1},execute:(e,a)=>d(async()=>{M(e,a,[]);let{client:i,asset:r,shareToken:s}=await l(),[p,f,c,g,w,b]=await Promise.all([i.readContract({address:n,abi:m,functionName:"totalAssets"}),i.readContract({address:n,abi:m,functionName:"totalSupply"}),i.readContract({address:n,abi:m,functionName:"maxDeposit",args:[a]}),i.readContract({address:n,abi:m,functionName:"maxWithdraw",args:[a]}),i.readContract({address:n,abi:m,functionName:"performanceFee"}),i.readContract({address:n,abi:m,functionName:"managementFee"})]);return[{vault:n,chainId:h,name:"Grove x Steakhouse USDG",asset:r,shareToken:s,totalAssets:{token:r,amount:v(p).toString()},totalSupply:{token:s,amount:v(f).toString()},maxDeposit:v(c)===0n?null:c.toString(),maxWithdraw:v(g)===0n?null:g.toString(),maxViewCaveat:"Zero Morpho V2 maximum views mean unknown capacity. Simulate the requested action; full exits use the fresh share balance.",fees:{performanceFeeRaw:v(w).toString(),managementFeeRaw:v(b).toString(),scale:"1000000000000000000",managementFeeTimeUnit:"second",performanceFeeBasis:"accrued interest"}}]})},{name:"grove_deposit",inputSchema:{type:"object",description:"Deposit USDG in base units (1 USDG = 1000000) for 18-decimal vault shares. Exit with grove_withdraw; check positions after confirmation.",properties:{vault:U,amount:C,minSharesOut:C,slippageBps:Q},required:["amount"],additionalProperties:!1},execute:(e,a)=>d(async()=>{M(e,a,["amount","minSharesOut","slippageBps"]);let i=D(e.amount),{client:r,asset:s,shareToken:p}=await l(),f=v(await r.readContract({address:n,abi:m,functionName:"previewDeposit",args:[i]})),c=X(f,e.minSharesOut,e.slippageBps),g=I(n,s.address,i.toString(),a,h),w=[t.approval(s.address,n,i.toString(),h),t.unsignedTx(g.txs[1])];return u(w,a,s,i,p,c)})},{name:"grove_withdraw",inputSchema:{type:"object",description:"Redeem shares in 18-decimal base units, or shares all for a full exit to USDG. Check positions after confirmation.",properties:{vault:U,shares:{oneOf:[C,{const:"all",description:"Redeem the fresh full share balance."}],description:'Vault shares to redeem, in base units (shares have 18 decimals; "1000000000000000000" = 1 share), or "all" for the full balance.'},minAmountOut:C,slippageBps:Q,force:{type:"boolean",description:'True plans a full Morpho V2 force exit with penalty disclosure. Needs shares "all", minAmountOut and maxPenaltyAssets.'},maxPenaltyAssets:$('Force exit only: most USDG, in base units (6 decimals), you accept losing to the exit penalty. Example: "1000000" = 1 USDG.')},required:["shares"],additionalProperties:!1},execute:(e,a)=>d(async()=>{M(e,a,["shares","minAmountOut","slippageBps","force","maxPenaltyAssets"]);let i=e.shares==="all"?void 0:D(e.shares),{client:r,asset:s,shareToken:p}=await l(),f=v(await r.readContract({address:n,abi:m,functionName:"balanceOf",args:[a]})),c=i??f;if(c===0n||c>f)throw new o("The Grove share balance is insufficient for this withdrawal.");if(e.force!==void 0&&typeof e.force!="boolean")throw new o("force must be a boolean.");if(e.force===!0){if(e.shares!=="all"||e.slippageBps!==void 0)throw new o("Force exit requires shares all and an explicit minAmountOut; omit slippageBps.");let G=j(e.maxPenaltyAssets),ee=D(e.minAmountOut),k=await Z(t,r,n,a,c,G),P=await t.preview([k.tx],a);return K(P.changes,n,c,ee),{txs:[k.tx],preview:P,summary:`${J(k.plan)} ${P.summary}`}}if(e.maxPenaltyAssets!==void 0)throw new o("maxPenaltyAssets requires force true.");let g=v(await r.readContract({address:n,abi:m,functionName:"previewRedeem",args:[c]})),w=X(g,e.minAmountOut,e.slippageBps),y=B(n,c.toString(),a,h).txs.map(G=>t.unsignedTx({...G,description:`Redeem ${c} Grove share base units to the wallet.`}));return u(y,a,p,c,s,w)})}],positions:e=>d(async()=>{A(e);let{client:a,asset:i,shareToken:r}=await l(),s=v(await a.readContract({address:n,abi:m,functionName:"balanceOf",args:[e]}));if(s===0n)return[];let p=v(await a.readContract({address:n,abi:m,functionName:"previewRedeem",args:[s]}));return[{module:"grove",id:`${h}:${n.toLowerCase()}`,chainId:h,assets:[{token:i,amount:p.toString()}],description:`${t.formatAmount(s.toString(),r.decimals)} Grove shares (${s} base units, ${r.decimals} decimals, ${n}); estimated USDG redemption, subject to simulation.`}]})}},we=t=>_("grove",[ae(t)]);export{ae as a,we as b};
@@ -1 +1 @@
1
- import{b as ne}from"./Z5YI6KLN.js";import{b as ee,e as te}from"./T3QEN3S6.js";import{a as D,b as W,c as _,d as J,e as z,f as Y,g as Z}from"./N6PHSHBE.js";import{d as V,e as $,w as U}from"./4E7FJQLL.js";import{a as H}from"./IOYRL6AY.js";import{a as E}from"./66F5ZH34.js";import{c as b,g as G}from"./NWNYJ26T.js";import{b as S,j as N}from"./TI727O2H.js";import{a as o}from"./XSD5NL7J.js";import{encodeAbiParameters as w,encodeFunctionData as oe,encodePacked as he,erc20Abi as be,getAddress as ce,parseAbi as T,parseAbiParameters as g,zeroAddress as v}from"viem";var ie=ce("0x33e885ed0ec9bf04ecfb19341582aadcb4c8a9e7"),re=ce(N[4663].ponsTrade.quoter.address),xe=T(["function execute(bytes commands,bytes[] inputs,uint256 deadline) payable"]),we=T(["function approve(address token,address spender,uint160 amount,uint48 expiration)"]),se=T(["function factory() view returns (address)","function quoteExactInput(bytes path,uint256 amountIn) returns (uint256,uint160[],uint32[],uint256)","function quoteExactOutput(bytes path,uint256 amountOut) returns (uint256,uint160[],uint32[],uint256)"]),F="(address intermediateCurrency,uint24 fee,int24 tickSpacing,address hooks,bytes hookData)",M="(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)",ae=T([`function quoteExactInput((address exactCurrency,${F}[] path,uint128 exactAmount) params) returns (uint256,uint256)`,`function quoteExactOutput((address exactCurrency,${F}[] path,uint128 exactAmount) params) returns (uint256,uint256)`,`function quoteExactInputSingle((${M} poolKey,bool zeroForOne,uint128 exactAmount,bytes hookData) params) returns (uint256,uint256)`,`function quoteExactOutputSingle((${M} poolKey,bool zeroForOne,uint128 exactAmount,bytes hookData) params) returns (uint256,uint256)`]),ke=g(`(address exactCurrency,${F}[] path,uint256[] minHopPriceX36,uint128 amount,uint128 limit)`);function ve(u,t,r,l){let s=[],e=l?r:t,i=new Set([e]);for(let n of l?[...u].reverse():u){let c=n.currency0===e?n.currency1:n.currency1===e?n.currency0:void 0;if(!c||i.has(c))throw new o("V4 poolKeys must form a continuous route without repeated currencies.");s.push({intermediateCurrency:c,fee:n.fee,tickSpacing:n.tickSpacing,hooks:n.hooks,hookData:"0x"}),e=c,i.add(e)}if(e!==(l?t:r))throw new o("V4 route does not end at the requested currency.");return s}var ge=g(`(${M} poolKey,bool zeroForOne,uint128 amount,uint128 limit,uint256 minHopPriceX36,bytes hookData)`),Ae=g("address recipient,uint256 amount,uint256 limit,bytes path,bool payerIsUser,uint256[] minHopPriceX36"),Pe=g("address recipient,uint256 amount,uint256 limit,address[] path,bool payerIsUser,uint256[] minHopPriceX36"),ue=g("address,uint256"),Ie=g("bytes,bytes[]");function Se(u,t,r){let l=r?[...u].reverse():u,s=r?[...t].reverse():t,e=l[0];return s.forEach((i,n)=>{e=`${e}${he(["uint24","address"],[i,l[n+1]]).slice(2)}`}),e}var de={version:{description:'Uniswap version: "v2" for pairs, "v3" for concentrated liquidity or "v4" for PoolManager.',type:"string",enum:["v2","v3","v4"]},tokenIn:{...b,description:"Input token address; the zero address means native ETH for v4."},tokenOut:{...b,description:"Output token address; the zero address means native ETH for v4."},path:{description:"Two to six distinct ERC-20 token addresses in input-to-output order for v2 or v3.",type:"array",minItems:2,maxItems:6,items:b},fees:{type:"array",description:"One v3 pool fee per path hop, in pips, hundredths of a basis point (3000 = 0.3%; 950000 = 95%).",items:{type:"integer",minimum:0,maximum:1e6}},poolKeys:{description:"One to five v4 pool keys in input-to-output route order, without repeated currencies.",type:"array",minItems:1,maxItems:5,items:{type:"object",required:["currency0","currency1","fee","tickSpacing","hooks"],properties:{currency0:{...b,description:"Lower sorted currency address; the zero address means native ETH."},currency1:{...b,description:"Higher sorted currency address."},fee:{type:"integer",description:"Pool fee in pips, hundredths of a basis point (3000 = 0.3%; 950000 = 95%)."},tickSpacing:{description:"Spacing between usable pool ticks, as an integer.",type:"integer"},hooks:{...b,description:"Hook contract address; the zero address means no hook."}},additionalProperties:!1}},poolKey:{description:"V4 pool key: sorted currencies, fee in pips, tick spacing and hook address.",type:"object",properties:{currency0:{...b,description:"Lower sorted currency address; the zero address means native ETH."},currency1:{...b,description:"Higher sorted currency address."},fee:{type:"integer",description:"Pool fee in pips, hundredths of a basis point (3000 = 0.3%; 950000 = 95%)."},tickSpacing:{description:"Spacing between usable pool ticks, as an integer.",type:"integer"},hooks:{...b,description:"Hook contract address; the zero address means no hook."}},required:["currency0","currency1","fee","tickSpacing","hooks"],additionalProperties:!1},allowHighFeePools:{description:"Allow pools above Oak's usual fee threshold; review the fee warning before confirming.",type:"boolean"},acceptValueLoss:{description:"Acknowledge the quoted value-loss warning; review the measured loss before confirming.",type:"boolean"},amountIn:E('Amount of input token in base units; use input token decimals. Example: "1000000" = 1 input token at 6 decimals.'),amountOut:E('Amount of output token in base units; use output token decimals. Example: "1000000" = 1 output token at 6 decimals.'),minAmountOut:E('Minimum amount of output token in base units; use output token decimals. Example: "1000000" = 1 output token at 6 decimals.'),maxAmountIn:E('Maximum amount of input token in base units; use input token decimals. Example: "1000000" = 1 input token at 6 decimals.'),slippageBps:{description:"Slippage tolerance in basis points (50 = 0.5%).",type:"integer",minimum:0,maximum:9999}};async function Ee(u,t,r,l=!1){Z(t,Object.keys(de));let s=t.version;if(!["v2","v3","v4"].includes(String(s)))throw new o("Provide version v2, v3 or v4.");let e=t.amountOut!==void 0;if(t.amountIn!==void 0===e)throw new o("Provide exactly one of amountIn or amountOut.");if(e&&t.minAmountOut!==void 0||!e&&t.maxAmountIn!==void 0)throw new o("Use maxAmountIn for exact output, minAmountOut for exact input.");let i=D(e?t.amountOut:t.amountIn,e?"amountOut":"amountIn",s==="v4"?128:160),n=_(t.tokenIn),c=_(t.tokenOut);if(n===c)throw new o("Swap requires different input and output currencies.");let x=u.clientFor(S),p=await x.getBlock(),L=J(t.slippageBps),j,I,m,O,A,f,d,C;if(s==="v4"){if(t.path!==void 0||t.fees!==void 0)throw new o("V4 uses poolKey or poolKeys; omit path and fees.");if(t.poolKey===void 0==(t.poolKeys===void 0))throw new o("Provide poolKey or poolKeys, not both.");if(t.poolKeys!==void 0){if(!Array.isArray(t.poolKeys)||t.poolKeys.length<1||t.poolKeys.length>5)throw new o("Provide 1 to 5 v4 poolKeys.");let a=t.poolKeys.map(P=>U(P));j=a,I=ve(a,n,c,e),m=(await x.simulateContract({address:re,abi:ae,functionName:e?"quoteExactOutput":"quoteExactInput",args:[{exactCurrency:e?c:n,path:I,exactAmount:i}],account:r,gas:H,blockNumber:p.number})).result[0]}else{if(f=U(t.poolKey),![f.currency0,f.currency1].includes(n)||![f.currency0,f.currency1].includes(c))throw new o("PoolKey currencies differ from the requested swap.");m=(await x.simulateContract({address:re,abi:ae,functionName:e?"quoteExactOutputSingle":"quoteExactInputSingle",args:[{poolKey:f,zeroForOne:n===f.currency0,exactAmount:i,hookData:"0x"}],account:r,gas:H,blockNumber:p.number})).result[0]}A="0x10"}else{if(t.poolKey!==void 0||t.poolKeys!==void 0||n===v||c===v)throw new o("V2/v3 routes use ERC-20 tokens; wrap ETH to WETH first.");if(d=Array.isArray(t.path)?t.path.map(W):[n,c],d.length<2||d.length>6||d[0]!==n||d.at(-1)!==c||new Set(d).size!==d.length||d.includes(v))throw new o("Path must contain 2 to 6 distinct ERC-20 tokens in input-to-output order.");if(s==="v2"){if(t.fees!==void 0)throw new o("V2 fees are fixed by the pair; omit fees.");let a=await x.readContract({address:ee,abi:te,functionName:e?"getAmountsIn":"getAmountsOut",args:[i,d],blockNumber:p.number});m=e?a[0]:a.at(-1),A=e?"0x09":"0x08"}else{let a=t.fees;if(!Array.isArray(a)||a.length!==d.length-1||a.some(P=>typeof P!="number"||!Number.isInteger(P)||P<0||P>1e6))throw new o("Provide one integer pool fee in hundredths of a basis point (3000 = 0.3%) per v3 path hop.");if(!G(await x.readContract({address:ie,abi:se,functionName:"factory",blockNumber:p.number}),N[4663].uniswap.v3_factory.address))throw new o("V3 quoter is not configured for the pinned factory.");C=Se(d,a,e),m=(await x.simulateContract({address:ie,abi:se,functionName:e?"quoteExactOutput":"quoteExactInput",args:[C,i],account:r,gas:H,blockNumber:p.number})).result[0],A=e?"0x01":"0x00"}}if(m<=0n)throw new o("No positive Uniswap quote is available.");let k=await ne(x,{version:s,input:n,path:d,fees:t.fees,poolKeys:f?[f]:j,exactOutput:e,amount:i,quoted:m,blockNumber:p.number,allowHighFeePools:t.allowHighFeePools===!0,acceptValueLoss:t.acceptValueLoss===!0}),{confirmationWarnings:pe,...me}=k,R=e?t.maxAmountIn:t.minAmountOut;if(!l&&R===void 0)throw new o(`Provide ${e?"maxAmountIn":"minAmountOut"} from uniswap_quote to confirm the trade bound.`);let y=R===void 0?e?(m*BigInt(1e4+L)+9999n)/10000n:m*BigInt(1e4-L)/10000n:D(R,e?"maxAmountIn":"minAmountOut",s==="v4"?128:160);if(y<=0n||(e?y<m:y>m))throw new o("The fresh quote does not satisfy the confirmed swap bound.");let h=e?y:i;if(h>=1n<<160n||s==="v4"&&(h>=1n<<128n||y>=1n<<128n))throw new o("Swap bounds exceed the router amount range.");let[le,fe]=await Promise.all([z(u,n,p.number),z(u,c,p.number)]),X={...me,version:s,input:{token:le,amount:(e?m:i).toString()},output:{token:fe,amount:(e?i:m).toString()},[e?"maxAmountIn":"minAmountOut"]:y.toString(),blockNumber:p.number.toString(),expiresAt:(p.timestamp+60n).toString()};if(l)return{quote:X,...k.warnings?{warnings:k.warnings}:{},summary:"Read-only on-chain quote. Repeat the same route with the returned bound in uniswap_swap; execution gets a fresh quote and preview."};let q=p.timestamp+300n,K=[],B="Native ETH input; no token approvals.";if(n!==v){let a=await x.readContract({address:n,abi:be,functionName:"allowance",args:[r,V],blockNumber:p.number});a!==h&&K.push(u.approval(n,V,h.toString(),S)),B=`${a===h?"Reuse existing exact ERC-20 allowance of":"Set ERC-20 allowance to exactly"} ${h} input base units to Permit2; exact router permit.`,K.push(u.unsignedTx({to:V,data:oe({abi:we,functionName:"approve",args:[n,$,h,Number(q)]}),value:"0",chainId:S,description:`Permit exactly ${h} input base units to Universal Router until ${q}.`}))}if(s==="v4"){let a=I?w(ke,[{exactCurrency:e?c:n,path:I,minHopPriceX36:[],amount:i,limit:y}]):w(ge,[{poolKey:f,zeroForOne:n===f.currency0,amount:i,limit:y,minHopPriceX36:0n,hookData:"0x"}]);O=w(Ie,[I?e?"0x090c0f":"0x070c0f":e?"0x080c0f":"0x060c0f",[a,w(ue,[n,h]),w(ue,[c,e?i:y])]])}else s==="v2"?O=w(Pe,[r,i,y,d,!0,[]]):O=w(Ae,[r,i,y,C,!0,[]]);let Q=[O];return n===v&&e&&(A=`${A}04`,Q.push(w(g("address,address,uint256"),[v,r,0n]))),K.push(u.unsignedTx({to:$,data:oe({abi:xe,functionName:"execute",args:[A,Q,q]}),value:n===v?h.toString():"0",chainId:S,description:`Uniswap ${s} ${e?"exact output":"exact input"} swap; recipient ${r}; deadline ${q}.`})),{...k.warnings?{warnings:k.warnings}:{},confirmationWarnings:pe,...await Y(u,K,r,`${(k.warnings??[]).join(" ")}${k.warnings?.length?" ":""}Swap through Universal Router 2.1.2. ${B} Fixed output/input bound and five-minute on-chain deadline. Venue fees included; gas excluded.`),quote:X}}function Ue(u){return{tools:[!0,!1].map(t=>({name:t?"uniswap_quote":"uniswap_swap",inputSchema:{type:"object",additionalProperties:!1,required:["version","tokenIn","tokenOut"],properties:de},execute:(r,l)=>Ee(u,r,l,t)}))}}export{ie as a,re as b,xe as c,we as d,se as e,ae as f,ke as g,ve as h,ge as i,Ae as j,Pe as k,Se as l,Ee as m,Ue as n};
1
+ import{b as ne}from"./FRVCSDKU.js";import{b as ee,e as te}from"./E47UYYK4.js";import{a as D,b as W,c as _,d as J,e as z,f as Y,g as Z}from"./ZXRIJG6H.js";import{d as V,e as $,w as U}from"./FRT6AC6M.js";import{a as H}from"./IOYRL6AY.js";import{a as E}from"./66F5ZH34.js";import{c as b,g as G}from"./NWNYJ26T.js";import{b as S,j as N}from"./TI727O2H.js";import{a as o}from"./XSD5NL7J.js";import{encodeAbiParameters as w,encodeFunctionData as oe,encodePacked as he,erc20Abi as be,getAddress as ce,parseAbi as T,parseAbiParameters as g,zeroAddress as v}from"viem";var ie=ce("0x33e885ed0ec9bf04ecfb19341582aadcb4c8a9e7"),re=ce(N[4663].ponsTrade.quoter.address),xe=T(["function execute(bytes commands,bytes[] inputs,uint256 deadline) payable"]),we=T(["function approve(address token,address spender,uint160 amount,uint48 expiration)"]),se=T(["function factory() view returns (address)","function quoteExactInput(bytes path,uint256 amountIn) returns (uint256,uint160[],uint32[],uint256)","function quoteExactOutput(bytes path,uint256 amountOut) returns (uint256,uint160[],uint32[],uint256)"]),F="(address intermediateCurrency,uint24 fee,int24 tickSpacing,address hooks,bytes hookData)",M="(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)",ae=T([`function quoteExactInput((address exactCurrency,${F}[] path,uint128 exactAmount) params) returns (uint256,uint256)`,`function quoteExactOutput((address exactCurrency,${F}[] path,uint128 exactAmount) params) returns (uint256,uint256)`,`function quoteExactInputSingle((${M} poolKey,bool zeroForOne,uint128 exactAmount,bytes hookData) params) returns (uint256,uint256)`,`function quoteExactOutputSingle((${M} poolKey,bool zeroForOne,uint128 exactAmount,bytes hookData) params) returns (uint256,uint256)`]),ke=g(`(address exactCurrency,${F}[] path,uint256[] minHopPriceX36,uint128 amount,uint128 limit)`);function ve(u,t,r,l){let s=[],e=l?r:t,i=new Set([e]);for(let n of l?[...u].reverse():u){let c=n.currency0===e?n.currency1:n.currency1===e?n.currency0:void 0;if(!c||i.has(c))throw new o("V4 poolKeys must form a continuous route without repeated currencies.");s.push({intermediateCurrency:c,fee:n.fee,tickSpacing:n.tickSpacing,hooks:n.hooks,hookData:"0x"}),e=c,i.add(e)}if(e!==(l?t:r))throw new o("V4 route does not end at the requested currency.");return s}var ge=g(`(${M} poolKey,bool zeroForOne,uint128 amount,uint128 limit,uint256 minHopPriceX36,bytes hookData)`),Ae=g("address recipient,uint256 amount,uint256 limit,bytes path,bool payerIsUser,uint256[] minHopPriceX36"),Pe=g("address recipient,uint256 amount,uint256 limit,address[] path,bool payerIsUser,uint256[] minHopPriceX36"),ue=g("address,uint256"),Ie=g("bytes,bytes[]");function Se(u,t,r){let l=r?[...u].reverse():u,s=r?[...t].reverse():t,e=l[0];return s.forEach((i,n)=>{e=`${e}${he(["uint24","address"],[i,l[n+1]]).slice(2)}`}),e}var de={version:{description:'Uniswap version: "v2" for pairs, "v3" for concentrated liquidity or "v4" for PoolManager.',type:"string",enum:["v2","v3","v4"]},tokenIn:{...b,description:"Input token address; the zero address means native ETH for v4."},tokenOut:{...b,description:"Output token address; the zero address means native ETH for v4."},path:{description:"Two to six distinct ERC-20 token addresses in input-to-output order for v2 or v3.",type:"array",minItems:2,maxItems:6,items:b},fees:{type:"array",description:"One v3 pool fee per path hop, in pips, hundredths of a basis point (3000 = 0.3%; 950000 = 95%).",items:{type:"integer",minimum:0,maximum:1e6}},poolKeys:{description:"One to five v4 pool keys in input-to-output route order, without repeated currencies.",type:"array",minItems:1,maxItems:5,items:{type:"object",required:["currency0","currency1","fee","tickSpacing","hooks"],properties:{currency0:{...b,description:"Lower sorted currency address; the zero address means native ETH."},currency1:{...b,description:"Higher sorted currency address."},fee:{type:"integer",description:"Pool fee in pips, hundredths of a basis point (3000 = 0.3%; 950000 = 95%)."},tickSpacing:{description:"Spacing between usable pool ticks, as an integer.",type:"integer"},hooks:{...b,description:"Hook contract address; the zero address means no hook."}},additionalProperties:!1}},poolKey:{description:"V4 pool key: sorted currencies, fee in pips, tick spacing and hook address.",type:"object",properties:{currency0:{...b,description:"Lower sorted currency address; the zero address means native ETH."},currency1:{...b,description:"Higher sorted currency address."},fee:{type:"integer",description:"Pool fee in pips, hundredths of a basis point (3000 = 0.3%; 950000 = 95%)."},tickSpacing:{description:"Spacing between usable pool ticks, as an integer.",type:"integer"},hooks:{...b,description:"Hook contract address; the zero address means no hook."}},required:["currency0","currency1","fee","tickSpacing","hooks"],additionalProperties:!1},allowHighFeePools:{description:"Allow pools above Oak's usual fee threshold; review the fee warning before confirming.",type:"boolean"},acceptValueLoss:{description:"Acknowledge the quoted value-loss warning; review the measured loss before confirming.",type:"boolean"},amountIn:E('Amount of input token in base units; use input token decimals. Example: "1000000" = 1 input token at 6 decimals.'),amountOut:E('Amount of output token in base units; use output token decimals. Example: "1000000" = 1 output token at 6 decimals.'),minAmountOut:E('Minimum amount of output token in base units; use output token decimals. Example: "1000000" = 1 output token at 6 decimals.'),maxAmountIn:E('Maximum amount of input token in base units; use input token decimals. Example: "1000000" = 1 input token at 6 decimals.'),slippageBps:{description:"Slippage tolerance in basis points (50 = 0.5%).",type:"integer",minimum:0,maximum:9999}};async function Ee(u,t,r,l=!1){Z(t,Object.keys(de));let s=t.version;if(!["v2","v3","v4"].includes(String(s)))throw new o("Provide version v2, v3 or v4.");let e=t.amountOut!==void 0;if(t.amountIn!==void 0===e)throw new o("Provide exactly one of amountIn or amountOut.");if(e&&t.minAmountOut!==void 0||!e&&t.maxAmountIn!==void 0)throw new o("Use maxAmountIn for exact output, minAmountOut for exact input.");let i=D(e?t.amountOut:t.amountIn,e?"amountOut":"amountIn",s==="v4"?128:160),n=_(t.tokenIn),c=_(t.tokenOut);if(n===c)throw new o("Swap requires different input and output currencies.");let x=u.clientFor(S),p=await x.getBlock(),L=J(t.slippageBps),j,I,m,O,A,f,d,C;if(s==="v4"){if(t.path!==void 0||t.fees!==void 0)throw new o("V4 uses poolKey or poolKeys; omit path and fees.");if(t.poolKey===void 0==(t.poolKeys===void 0))throw new o("Provide poolKey or poolKeys, not both.");if(t.poolKeys!==void 0){if(!Array.isArray(t.poolKeys)||t.poolKeys.length<1||t.poolKeys.length>5)throw new o("Provide 1 to 5 v4 poolKeys.");let a=t.poolKeys.map(P=>U(P));j=a,I=ve(a,n,c,e),m=(await x.simulateContract({address:re,abi:ae,functionName:e?"quoteExactOutput":"quoteExactInput",args:[{exactCurrency:e?c:n,path:I,exactAmount:i}],account:r,gas:H,blockNumber:p.number})).result[0]}else{if(f=U(t.poolKey),![f.currency0,f.currency1].includes(n)||![f.currency0,f.currency1].includes(c))throw new o("PoolKey currencies differ from the requested swap.");m=(await x.simulateContract({address:re,abi:ae,functionName:e?"quoteExactOutputSingle":"quoteExactInputSingle",args:[{poolKey:f,zeroForOne:n===f.currency0,exactAmount:i,hookData:"0x"}],account:r,gas:H,blockNumber:p.number})).result[0]}A="0x10"}else{if(t.poolKey!==void 0||t.poolKeys!==void 0||n===v||c===v)throw new o("V2/v3 routes use ERC-20 tokens; wrap ETH to WETH first.");if(d=Array.isArray(t.path)?t.path.map(W):[n,c],d.length<2||d.length>6||d[0]!==n||d.at(-1)!==c||new Set(d).size!==d.length||d.includes(v))throw new o("Path must contain 2 to 6 distinct ERC-20 tokens in input-to-output order.");if(s==="v2"){if(t.fees!==void 0)throw new o("V2 fees are fixed by the pair; omit fees.");let a=await x.readContract({address:ee,abi:te,functionName:e?"getAmountsIn":"getAmountsOut",args:[i,d],blockNumber:p.number});m=e?a[0]:a.at(-1),A=e?"0x09":"0x08"}else{let a=t.fees;if(!Array.isArray(a)||a.length!==d.length-1||a.some(P=>typeof P!="number"||!Number.isInteger(P)||P<0||P>1e6))throw new o("Provide one integer pool fee in hundredths of a basis point (3000 = 0.3%) per v3 path hop.");if(!G(await x.readContract({address:ie,abi:se,functionName:"factory",blockNumber:p.number}),N[4663].uniswap.v3_factory.address))throw new o("V3 quoter is not configured for the pinned factory.");C=Se(d,a,e),m=(await x.simulateContract({address:ie,abi:se,functionName:e?"quoteExactOutput":"quoteExactInput",args:[C,i],account:r,gas:H,blockNumber:p.number})).result[0],A=e?"0x01":"0x00"}}if(m<=0n)throw new o("No positive Uniswap quote is available.");let k=await ne(x,{version:s,input:n,path:d,fees:t.fees,poolKeys:f?[f]:j,exactOutput:e,amount:i,quoted:m,blockNumber:p.number,allowHighFeePools:t.allowHighFeePools===!0,acceptValueLoss:t.acceptValueLoss===!0}),{confirmationWarnings:pe,...me}=k,R=e?t.maxAmountIn:t.minAmountOut;if(!l&&R===void 0)throw new o(`Provide ${e?"maxAmountIn":"minAmountOut"} from uniswap_quote to confirm the trade bound.`);let y=R===void 0?e?(m*BigInt(1e4+L)+9999n)/10000n:m*BigInt(1e4-L)/10000n:D(R,e?"maxAmountIn":"minAmountOut",s==="v4"?128:160);if(y<=0n||(e?y<m:y>m))throw new o("The fresh quote does not satisfy the confirmed swap bound.");let h=e?y:i;if(h>=1n<<160n||s==="v4"&&(h>=1n<<128n||y>=1n<<128n))throw new o("Swap bounds exceed the router amount range.");let[le,fe]=await Promise.all([z(u,n,p.number),z(u,c,p.number)]),X={...me,version:s,input:{token:le,amount:(e?m:i).toString()},output:{token:fe,amount:(e?i:m).toString()},[e?"maxAmountIn":"minAmountOut"]:y.toString(),blockNumber:p.number.toString(),expiresAt:(p.timestamp+60n).toString()};if(l)return{quote:X,...k.warnings?{warnings:k.warnings}:{},summary:"Read-only on-chain quote. Repeat the same route with the returned bound in uniswap_swap; execution gets a fresh quote and preview."};let q=p.timestamp+300n,K=[],B="Native ETH input; no token approvals.";if(n!==v){let a=await x.readContract({address:n,abi:be,functionName:"allowance",args:[r,V],blockNumber:p.number});a!==h&&K.push(u.approval(n,V,h.toString(),S)),B=`${a===h?"Reuse existing exact ERC-20 allowance of":"Set ERC-20 allowance to exactly"} ${h} input base units to Permit2; exact router permit.`,K.push(u.unsignedTx({to:V,data:oe({abi:we,functionName:"approve",args:[n,$,h,Number(q)]}),value:"0",chainId:S,description:`Permit exactly ${h} input base units to Universal Router until ${q}.`}))}if(s==="v4"){let a=I?w(ke,[{exactCurrency:e?c:n,path:I,minHopPriceX36:[],amount:i,limit:y}]):w(ge,[{poolKey:f,zeroForOne:n===f.currency0,amount:i,limit:y,minHopPriceX36:0n,hookData:"0x"}]);O=w(Ie,[I?e?"0x090c0f":"0x070c0f":e?"0x080c0f":"0x060c0f",[a,w(ue,[n,h]),w(ue,[c,e?i:y])]])}else s==="v2"?O=w(Pe,[r,i,y,d,!0,[]]):O=w(Ae,[r,i,y,C,!0,[]]);let Q=[O];return n===v&&e&&(A=`${A}04`,Q.push(w(g("address,address,uint256"),[v,r,0n]))),K.push(u.unsignedTx({to:$,data:oe({abi:xe,functionName:"execute",args:[A,Q,q]}),value:n===v?h.toString():"0",chainId:S,description:`Uniswap ${s} ${e?"exact output":"exact input"} swap; recipient ${r}; deadline ${q}.`})),{...k.warnings?{warnings:k.warnings}:{},confirmationWarnings:pe,...await Y(u,K,r,`${(k.warnings??[]).join(" ")}${k.warnings?.length?" ":""}Swap through Universal Router 2.1.2. ${B} Fixed output/input bound and five-minute on-chain deadline. Venue fees included; gas excluded.`),quote:X}}function Ue(u){return{tools:[!0,!1].map(t=>({name:t?"uniswap_quote":"uniswap_swap",inputSchema:{type:"object",additionalProperties:!1,required:["version","tokenIn","tokenOut"],properties:de},execute:(r,l)=>Ee(u,r,l,t)}))}}export{ie as a,re as b,xe as c,we as d,se as e,ae as f,ke as g,ve as h,ge as i,Ae as j,Pe as k,Se as l,Ee as m,Ue as n};
@@ -0,0 +1 @@
1
+ import{m as J}from"./WSILNJS2.js";import{a as U,e as Z,h as ee,i as te,k as ne}from"./KHOUBQJK.js";import{c as N,e as Q}from"./JFC2QCMW.js";import{a as Y}from"./Y2QADJOB.js";import{b as re,e as O,q as ie}from"./N624NR7Y.js";import{a as g,b as C}from"./Z7FGEWO2.js";import{a as P}from"./LIUXNOLP.js";import{e as z,f as j}from"./S65KXMZ7.js";import{f as $,l as V}from"./CW37EGPL.js";import{a as X,c as A}from"./CFPJDLTZ.js";import{a as v}from"./VVAM3EAK.js";import{a as K}from"./SPJCSEKP.js";import{b as F}from"./SCG5HWMN.js";import{b as E}from"./IX3GZMTM.js";import{t as T}from"./MQ5F2VOK.js";import{b as m,c as l,d as G,e as k,j as h,k as q,l as W,q as B}from"./TI727O2H.js";import{a as c}from"./XSD5NL7J.js";import{a as D,b as R}from"./JXOEJPJ4.js";import{getAddress as p,isAddress as se,parseAbi as me,zeroAddress as oe}from"viem";var ae=[{inputs:[],name:"available",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"ethUsdE18",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"liquidityUsdgE6",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"phase",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"priceSigner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"signer",type:"address"}],name:"setPriceSigner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"spotOakPerEthE18",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"supplyNet",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"syncPhase",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"wallet",type:"address"},{internalType:"uint256",name:"oakPerEthE18",type:"uint256"},{internalType:"uint64",name:"timestamp",type:"uint64"},{internalType:"bytes32",name:"nonce",type:"bytes32"}],internalType:"struct PriceNote",name:"n",type:"tuple"},{internalType:"bytes",name:"sig",type:"bytes"},{internalType:"address",name:"boundWallet",type:"address"}],name:"verifyNote",outputs:[{internalType:"uint256",name:"oakPerEthE18",type:"uint256"}],stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"signer",type:"address"}],name:"PriceSignerSet",type:"event"},{inputs:[],name:"NotReady",type:"error"},{inputs:[],name:"NoteBadSignature",type:"error"},{inputs:[],name:"NoteExpired",type:"error"},{inputs:[],name:"NoteNotYetValid",type:"error"},{inputs:[{internalType:"uint256",name:"spot",type:"uint256"},{internalType:"uint256",name:"note",type:"uint256"}],name:"NoteOutsideGuard",type:"error"},{inputs:[],name:"NoteWrongWallet",type:"error"},{inputs:[{internalType:"address",name:"source",type:"address"}],name:"OracleUnreadable",type:"error"}];function Qe(n){return"source"in n&&n.source==="pool-spot-estimate"?void 0:n}var M=300,Te="1000000000000000000",le=p(h[m].tokens.USDG.address),fe=p(h[l].deployments.test_USDG.address),_=p(h[m].tokens.WETH.address),L=p(h[l].deployments.test_WETH.address),I=p(X.chop);function pe(n){return n.chainId===m&&n.address.toLowerCase()===I.toLowerCase()}async function Ye(n,e,t,o){let s=o?.find(b=>b.measuredAtBlock===t.toString()&&[b.log.address,b.staking.address].some(y=>y.toLowerCase()===n.address.toLowerCase())),i=n.address;try{s||(i=p(await $(e,n.address,"INDEX_FUND",[],t)))}catch{}let a=s??await V(e,i,"read",t);if(a.drift.length)throw new c("Chop code changed; share backing cannot be estimated.");let r=10n**BigInt(n.decimals),d=n.address.toLowerCase()===a.log.address.toLowerCase(),u=n.address.toLowerCase()===a.staking.address.toLowerCase();if(!d&&!u||n.chainId!==m||n.decimals!==(d?a.log.decimals:a.staking.decimals))throw new c("Chop share identity does not match the verified log.");let f=d?[(await z(e,a,oe,r,t)).net]:(await j(e,a,oe,r,t)).assets;if(!f.length)throw new c("Chop LP reserves or net log backing could not be verified.");return{assets:f,isLog:d}}function be(n){let e=n.address.toLowerCase();return n.chainId===m?e===le.toLowerCase():n.chainId===l?e===fe.toLowerCase():!1}function ye(n){return n.chainId!==m&&n.chainId!==l?!1:C(n.address)===g}function we(n){let e=n.address.toLowerCase();return n.chainId===m?e===_.toLowerCase():n.chainId===l?e===L.toLowerCase():!1}function Se(n){return ye(n)||we(n)}var ge=-887272,he=887272,Pe=(1n<<256n)-1n,Ce=me(["function observe(uint32[] secondsAgos) view returns (int56[] tickCumulatives, uint160[] secondsPerLiquidityCumulativeX128s)","function slot0() view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)"]),de=me(["function getSlot0(bytes32 poolId) view returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)","function getLiquidity(bytes32 poolId) view returns (uint128 liquidity)"]),xe=1n<<192n;async function De(n,e){let t=p(A.stateView),o=A.poolId,[s,i]=await Promise.all([n.readContract({address:t,abi:de,functionName:"getSlot0",args:[o],blockNumber:e}),n.readContract({address:t,abi:de,functionName:"getLiquidity",args:[o],blockNumber:e})]),a=s[0],r=Number(s[1]);if(a<=0n||i<=0n||!Number.isInteger(r)||r<ge||r>he)throw new c("The pinned Uniswap v4 WETH/CHOP pool has no active liquidity, and the only other route is a near-empty pool.");return{numerator:xe,denominator:a*a}}function H(n,e){if(typeof n=="bigint")return n;if(typeof n=="number"){if(!Number.isSafeInteger(n))throw new c(`Invalid ${e} timestamp.`);return BigInt(n)}if(typeof n=="string"&&/^-?\d+$/.test(n.trim()))return BigInt(n.trim());throw new c(`Invalid ${e} timestamp.`)}function Je(n,e=BigInt(Math.floor(Date.now()/1e3)),t=M){try{return w(n,e,t),!0}catch{return!1}}function w(n,e=BigInt(Math.floor(Date.now()/1e3)),t=M){if(!Number.isInteger(t)||t<0)throw new c("Maximum price age must be a non-negative integer.");let o=H(n,"price"),s=H(e,"current");if(o<=0n)throw new c("Price timestamp must be positive.");if(o>s)throw new c("Price timestamp is in the future.");let i=s-o;if(i>BigInt(t))throw new c(`Price is stale: age ${i}s exceeds ${t}s.`);return o.toString()}function ke(n){if(!Number.isInteger(n)||n<ge||n>he)throw new c(`Tick ${n} is outside valid Uniswap bounds.`);let e=BigInt(n<0?-n:n),t=(e&0x1n)!==0n?0xfffcb933bd6fad37aa2d162d1a594001n:0x100000000000000000000000000000000n;return(e&0x2n)!==0n&&(t=t*0xfff97272373d413259a46990580e213an>>128n),(e&0x4n)!==0n&&(t=t*0xfff2e50f5f656932ef12357cf3c7fdccn>>128n),(e&0x8n)!==0n&&(t=t*0xffe5caca7e10e4e61c3624eaa0941cd0n>>128n),(e&0x10n)!==0n&&(t=t*0xffcb9843d60f6159c9db58835c926644n>>128n),(e&0x20n)!==0n&&(t=t*0xff973b41fa98c081472e6896dfb254c0n>>128n),(e&0x40n)!==0n&&(t=t*0xff2ea16466c96a3843ec78b326b52861n>>128n),(e&0x80n)!==0n&&(t=t*0xfe5dee046a99a2a811c461f1969c3053n>>128n),(e&0x100n)!==0n&&(t=t*0xfcbe86c7900a88aedcffc83b479aa3a4n>>128n),(e&0x200n)!==0n&&(t=t*0xf987a7253ac413176f2b074cf7815e54n>>128n),(e&0x400n)!==0n&&(t=t*0xf3392b0822b70005940c7a398e4b70f3n>>128n),(e&0x800n)!==0n&&(t=t*0xe7159475a2c29b7443b29c7fa6e889d9n>>128n),(e&0x1000n)!==0n&&(t=t*0xd097f3bdfd2022b8845ad8f792aa5825n>>128n),(e&0x2000n)!==0n&&(t=t*0xa9f746462d870fdf8a65dc1f90e061e5n>>128n),(e&0x4000n)!==0n&&(t=t*0x70d869a156d2a1b890bb3df62baf32f7n>>128n),(e&0x8000n)!==0n&&(t=t*0x31be135f97d08fd981231505542fcfa6n>>128n),(e&0x10000n)!==0n&&(t=t*0x9aa508b5b7a84e1c677de54f3e99bc9n>>128n),(e&0x20000n)!==0n&&(t=t*0x5d6af8dedb81196699c329225ee604n>>128n),(e&0x40000n)!==0n&&(t=t*0x2216e584f5fa1ea926041bedfe98n>>128n),(e&0x80000n)!==0n&&(t=t*0x48a170391f7dc42444e8fa2n>>128n),n>0&&(t=Pe/t),(t>>32n)+(t%(1n<<32n)===0n?0n:1n)}async function ce(n,e,t,o){let s=async()=>{throw new c("Price identity resolution is read-only.")},i=K({network:e===l?"testnet":"mainnet",clientFor:r=>t.client??T(t.rpcUrl,r),http:t.http??F(),preview:s,quoteSwap:s,buildSwap:s}),a=await ie(n,{context:i,oakTokenAddress:t.oakTokenAddress??process.env.OAK_TOKEN_ADDRESS,officialStockTokens:t.officialStockTokens,tokenMetadata:o,blockNumber:t.blockNumber,readMetadata:async r=>{let d=t.client??T(t.rpcUrl,e),[u,f]=await Promise.all([v(d,e,r,"symbol",t.blockNumber),v(d,e,r,"decimals",t.blockNumber)]);return{address:r,symbol:u,decimals:f,chainId:e}}});return{address:a.address,symbol:a.kind==="erc20"&&o?o.symbol:a.symbol,decimals:a.decimals,chainId:a.chainId}}async function ve(n,e,t){if(typeof n=="object"&&n!==null){let r=n.chainId??e,d=C(n.address)===g?g:p(n.address),u={address:d,symbol:n.symbol,decimals:n.decimals,chainId:r};return be(u)?{address:d,symbol:"USDG",decimals:k,chainId:r}:ye(u)?{address:g,symbol:"ETH",decimals:18,chainId:r}:we(u)?{address:d,symbol:"WETH",decimals:18,chainId:r}:pe(u)?{address:d,symbol:"CHOP",decimals:18,chainId:r}:ce(u.address,r,t,u)}let o=n.trim(),s=o.toUpperCase(),i=o.toLowerCase();if(s==="ETH"||se(o,{strict:!1})&&C(o)===g)return{...re,chainId:e};if(s==="WETH"||e===m&&i===_.toLowerCase()||e===l&&i===L.toLowerCase()){if(e!==m&&e!==l)throw new c(`No canonical WETH address configured for chain ${e}.`);return{address:e===l?L:_,symbol:"WETH",decimals:18,chainId:e}}if(s==="USDG"||e===m&&i===q.toLowerCase()||e===l&&i===W.toLowerCase()){if(e!==m&&e!==l)throw new c(`No canonical USDG address configured for chain ${e}.`);return{address:e===l?fe:le,symbol:"USDG",decimals:k,chainId:e}}if(e===m&&(s==="USDE"||i===O.address.toLowerCase()))return{...O,chainId:e};if(e===m&&(s==="CHOP"||i===I.toLowerCase()))return{address:I,symbol:"CHOP",decimals:18,chainId:e};let a=t.oakTokenAddress??process.env.OAK_TOKEN_ADDRESS;if(s==="OAK"||a&&o.toLowerCase()===a.toLowerCase()){if(!a&&!se(o,{strict:!1}))throw new c("OAK token address is required to price OAK.");return{address:p(a??o),symbol:"OAK",decimals:G,chainId:e}}return ce(n,e,t)}async function x(n,e,t){if(e)return(await n.readContract({address:e,abi:ae,functionName:"ethUsdE18",blockNumber:t})).toString();let s=(await n.readContract({address:p(B),abi:Ce,functionName:"observe",args:[[U,0]],blockNumber:t}))[0];if(!s||s.length<2)throw new c("ETH/USDG pool observation returned insufficient tick cumulatives.");let i=ee(s[0],s[1],U),a=ke(i);return te(a)}async function S(n,e,t,o){if(n.timestamp!==void 0)return w(n.timestamp,t(),o);if(e&&typeof e.getBlock=="function"){let i=await P(e,n.blockNumber);return w(i.timestamp,t(),o)}let s=t();return w(s,s,o)}function ue(n){if(n.startsWith("untrusted "))try{let e=JSON.parse(n.slice(10));if(typeof e=="string"&&D(e)===n)return n}catch{}return D(n)}async function Ze(n,e={}){let t=e.chainId??m,o=e.maxAgeSeconds??M,s=()=>e.now!==void 0?H(e.now,"current"):BigInt(Math.floor(Date.now()/1e3)),i=await ve(n,t,e);if((R(i.symbol)||i.symbol.length>256)&&(i.symbol=ue(i.symbol)),e.trades){let r=await S(e,e.client,s,o),d=ne(e.trades,{now:s(),windowStart:e.windowStart,windowEnd:e.windowEnd});if(e.spotOakPerEthE18!==void 0&&!J(d,e.spotOakPerEthE18))throw new c("30-minute average is outside the 50% spot guard band.");let u=e.ethUsdE18!==void 0?e.ethUsdE18.toString():await x(e.client??T(e.rpcUrl,t),e.oracleAddress);return{token:i,usdE18:Z(u,d),timestamp:r}}if(e.usdE18!==void 0){let r=await S(e,e.client,s,o),d=E(e.usdE18.toString());if(d<=0n)throw new c("USD price must be positive.");return{token:i,usdE18:d.toString(),timestamp:r}}if(e.resolver){let r=await e.resolver(i),d=w(r.timestamp,s(),o),u=E(r.usdE18);if(u<=0n)throw new c("USD price must be positive.");return{token:i,usdE18:u.toString(),timestamp:d,...r.source==="pool-spot-estimate"?{source:r.source,sourceLabel:N}:{}}}let a=e.client??T(e.rpcUrl,t);if(be(i)){let r=await S(e,a,s,o);return{token:i,usdE18:Te,timestamp:r}}if(Se(i)){let r=await S(e,a,s,o),d=await x(a,e.oracleAddress,e.blockNumber);return{token:i,usdE18:d,timestamp:r}}if(pe(i)){let r=e.timestamp===void 0&&a&&typeof a.getBlock=="function"?await P(a,e.blockNumber):void 0,d=r?w(r.timestamp,s(),o):await S(e,a,s,o);if(r&&r.number===null)throw new c("CHOP reference requires a mined block.");let u=r?.number??e.blockNumber,[f,b]=await Promise.all([De(a,u),e.ethUsdE18!==void 0?Promise.resolve(e.ethUsdE18.toString()):x(a,e.oracleAddress,u)]),y=E(b)*f.numerator/f.denominator;if(y<=0n)throw new c("CHOP USD reference price must be positive.");return{token:i,usdE18:y.toString(),timestamp:d}}if(i.chainId===m)try{let r=await P(a,e.blockNumber),d=w(r.timestamp,s(),o);if(r.number===null)throw new c("Pons reference requires a mined block.");let u=await Q(i,a,r.number);if(u!==void 0&&u>0n)return{token:i,usdE18:u.toString(),timestamp:d,source:"pool-spot-estimate",sourceLabel:N};let[f,b]=await Promise.all([Y(i,a,r.number),x(a,e.oracleAddress,r.number)]),y=E(b)*f.numerator/f.denominator;if(y<=0n)throw new c("Pons USD reference price must be positive.");return{token:i,usdE18:y.toString(),timestamp:d}}catch{}throw new c(`Oak has no fresh on-chain trade price for ${ue(i.symbol)}, so it shows no price. balances and positions show a labeled estimate where one exists; an estimate is not a quote.`)}export{Qe as a,M as b,Te as c,pe as d,Ye as e,be as f,ye as g,we as h,Se as i,De as j,Je as k,w as l,ke as m,x as n,Ze as o};
@@ -1 +1 @@
1
- import{b as Z}from"./OB7BFDOV.js";import{i as ee}from"./ANIF3JMV.js";import{a as Y}from"./E76Z2TT4.js";import{b as z}from"./GBIBRYOV.js";import{c as Q}from"./SUNTJ6IU.js";import{b as X}from"./ADIPEGNN.js";import{a as D,b as k,c as R,d as N,g as V,h as I,k as _,l as x,n as B,p as W,r as $,s as U,t as q,v as E,x as J,y as G}from"./3A2IKFTV.js";import{a as y}from"./X5V2Z2NM.js";import{b as K}from"./SPJCSEKP.js";import{a as O}from"./43LI5NKJ.js";import{c as L,e as T,g as w}from"./NWNYJ26T.js";import{a as g,d as j}from"./XSD5NL7J.js";import{a as A}from"./JXOEJPJ4.js";import{Buffer as te}from"node:buffer";import{decodeEventLog as re,encodeFunctionData as H,getAddress as se,hexToString as de,parseAbiItem as ce,toEventSelector as ie}from"viem";var Ke={register:"erc8004_register"},ge="Oak now always adds the public oak.registrar marker when it registers an agent, so tag: false and --no-tag are no longer available. Remove the option and register again. To use an agent ID you already own without the marker, link it with oak setup link <agentId>.",fe="The registration went through, but Oak could not find its oak.registrar marker on Robinhood Chain. Nothing else was sent. Ask me to check the agent with erc8004_identity.",le="One transaction registers your agent and writes the public marker oak.registrar = oak. Anyone can see on Robinhood Chain that this agent was registered through Oak. The marker is self-reported, not proof of anything, and the transaction stays in the public history even if the marker is changed later. It needs gas.",F="https://eips.ethereum.org/EIPS/eip-8004#registration-v1",ue={type:"object",required:["type","name","description","image","services","x402Support","active","registrations"],properties:{type:{const:F,description:"ERC-8004 registration-v1 profile type URI."},name:{type:"string",minLength:1,description:"Short public name for the agent."},description:{type:"string",description:"Public text describing what the agent does; may be empty."},image:{type:"string",description:"Public HTTPS or IPFS image URI without credentials."},services:{type:"array",items:{type:"object",required:["name","endpoint"]},description:"Service endpoint objects with name and endpoint; use an empty list for none."},x402Support:{type:"boolean",description:"Whether the agent supports x402 payments."},active:{type:"boolean",description:"Whether this agent is active."},registrations:{type:"array",description:"Registry references with agentRegistry and agentId; leave empty before first registration."},tags:{type:"array",items:{type:"string"},description:"Optional public text labels for the agent."},supportedTrust:{type:"array",items:{type:"string"},description:"Optional trust mechanism labels supported by the agent."}}};function pe(e){if(typeof e!="string"||!e.trim())return!1;try{let t=new URL(e);return["https:","ipfs:"].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password}catch{return!1}}var me=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&t.trim()),he=e=>e.replace(/\.$/,"");function ye(e,t,a,n){let{registryId:d}=I(e);if(!T(t))throw new g("Provide a registration-v1 profile object.");if(a!==void 0&&typeof a!="boolean")throw new g("The tag option must be a boolean.");let o=[],r=(i,c)=>o.push(`${i}: ${c}`);t.type!==F&&r("type",`use "${F}"`),(typeof t.name!="string"||!t.name.trim())&&r("name",'a short name for your agent, such as "Oak Agent 1"'),typeof t.description!="string"&&r("description","a sentence about what your agent does (it may be empty text)"),pe(t.image)||r("image","an HTTPS or IPFS link to a picture, with no username or password in it"),typeof t.active!="boolean"&&r("active","true or false"),typeof t.x402Support!="boolean"&&r("x402Support","true or false"),Array.isArray(t.services)?t.services.forEach((i,c)=>{try{Z(i)}catch(p){if(!(p instanceof g))throw p;r(`services item ${c+1}`,he(p.message))}}):r("services","a list of endpoints, or [] for none");for(let i of["tags","supportedTrust"])t[i]!==void 0&&!me(t[i])&&r(i,"a list of nonempty text labels, or leave it out");if(Array.isArray(t.registrations)?t.registrations.forEach((i,c)=>{let p=`registrations item ${c+1}`;if(!T(i)||typeof i.agentRegistry!="string"||!/^eip155:[1-9][0-9]*:0x[0-9a-fA-F]{40}$/.test(i.agentRegistry))return r(p,"an agentRegistry such as eip155:4663:0x\u2026 and its agentId");let f=typeof i.agentId=="number"&&Number.isSafeInteger(i.agentId)?String(i.agentId):i.agentId,b;try{b=x(f)}catch{return r(p,'an agentId as a whole number, such as "1"')}w(i.agentRegistry,d)&&(n===void 0?r(p,"remove the entry for this registry; its ID comes from the mined Registered receipt, and erc8004_update adds it afterwards"):b!==n&&r(p,`the agentId does not match the agent being updated; use "${n}" or remove the entry`))}):r("registrations","a list, or [] before the first registration"),o.length)throw new g(`This profile needs: ${o.join("; ")}. Fix all of these and try again.`);let u=t.registrations.map(i=>({...i}));n!==void 0&&!u.some(i=>w(i.agentRegistry,d))&&u.push({agentId:n.toString(),agentRegistry:d});let s=[...new Set((t.tags??[]).filter(i=>i!==k))];a!==!1&&s.push(k);let m={...t,registrations:u,...s.length?{tags:s}:{}};s.length||delete m.tags;let l;try{if(l=JSON.stringify(m),te.byteLength(l)>65536)throw new Error;JSON.parse(l)}catch{throw new g("Profile must be JSON data no larger than 64 KiB.")}return`data:application/json;base64,${te.from(l,"utf8").toString("base64")}`}async function M(e,t){try{let{chainId:a,registry:n}=I(e),d=x(t),o=e.clientFor(a),r=await o.readContract({address:n,abi:y,functionName:"ownerOf",args:[d]}).catch(l=>{throw j(l)?new g(`Agent ${d} does not exist in this ERC-8004 registry: the owner lookup reverted. Check the agent ID.`):l});O(r);let[u,s,m]=await Promise.all([o.readContract({address:n,abi:y,functionName:"tokenURI",args:[d]}),o.readContract({address:n,abi:y,functionName:"getAgentWallet",args:[d]}),o.readContract({address:n,abi:y,functionName:"getMetadata",args:[d,k]})]);if(O(s),typeof u!="string"||typeof m!="string"||!/^0x([0-9a-fA-F]{2})*$/.test(m))throw new g("The registry returned invalid identity data.");return{agentId:d.toString(),chainId:a,registry:n,owner:r,uri:u,agentWallet:s,registrarMetadata:m,registryValidated:!1,summary:D}}catch(a){throw new g(e.plainError(a))}}async function De(e,t){let a=await M(e,t);return{...a,uri:A(a.uri)}}async function we(e,t,a,n,d,o){let{registry:r}=I(e),u=await E(e,t,a,d),s=o===void 0?"Registered":"URIUpdated",m=ie(o===void 0?"Registered(uint256,string,address)":"URIUpdated(uint256,string,address)"),l=u.logs.filter(v=>w(v.address,r)&&v.topics[0]===m&&!v.removed);if(l.length!==1)throw new g(`The receipt must contain one matching ${s} event.`);let i=l[0],c=re({abi:y,eventName:s,topics:i.topics,data:i.data,strict:!0}),p=c.args.agentId,f=c.eventName==="Registered"?c.args.agentURI:c.args.newURI,b=c.eventName==="Registered"?c.args.owner:c.args.updatedBy;if(o!==void 0&&p!==o||f!==n||!w(b,a))throw new g("The registry event does not match the expected agent, URI and wallet.");let h=await M(e,p.toString());if(h.uri!==n||o===void 0&&!w(h.owner,a))throw new g("The current agent owner or URI does not match the confirmed operation.");return h}function be(e,t){let{chainId:a,registry:n}=I(e);return e.unsignedTx({to:n,chainId:a,value:"0",data:H({abi:y,functionName:"setMetadata",args:[t,k,R]}),description:`Set mutable oak.registrar metadata to oak for agent ${t}.`})}async function ae(e,t,a,n){let{registry:d}=I(e),o=x(n.agentId),r=await E(e,t,a,H({abi:y,functionName:"setMetadata",args:[o,k,R]})),u=ie("MetadataSet(uint256,string,string,bytes)"),s=r.logs.filter(c=>w(c.address,d)&&c.topics[0]===u&&!c.removed);if(s.length!==1)throw new g("The receipt must contain one matching MetadataSet event.");let m=s[0],{args:l}=re({abi:y,eventName:"MetadataSet",topics:m.topics,data:m.data,strict:!0});if(l.agentId!==o||l.metadataKey!==k||l.metadataValue!==R)throw new g("The metadata event does not match this agent and registrar marker.");let i=await M(e,n.agentId);if(i.registrarMetadata!==R||i.uri!==n.uri||!w(i.owner,n.owner))throw new g("The current agent metadata, owner or URI does not match the confirmed operation.");return i}async function ke(e,t){let{chainId:a,registry:n}=I(e),d=e.clientFor(a),o=await d.readContract({address:n,abi:y,functionName:"balanceOf",args:[t]});if(o===0n)return;if(typeof o!="bigint"||o<0n)throw new g("Registry balance is unavailable; registration was not built.");let r=await d.getBlockNumber({cacheTime:0}),u=new Set;for(;;){let s=r>9999999n?r-9999999n:0n,m=await d.getLogs({address:n,event:ce("event Transfer(address indexed from,address indexed to,uint256 indexed tokenId)"),args:{to:t},fromBlock:s,toBlock:r,strict:!0});for(let l of m){let i=l.args.tokenId.toString();if(l.removed||u.has(i))continue;u.add(i);let c=await M(e,i);if(w(c.owner,t))return c}if(s===0n)throw new g("Owned identity could not be located; registration was not built. Run oak setup link <agentId>.");r=s-1n}}function Ie(e){if(e===void 0)return[];if(!Array.isArray(e)||e.length>15)throw new g("Provide at most 15 user metadata entries as { key, value } with value as 0x hex or text.");let t=new Set;return e.map(a=>{if(!T(a))throw new g("Provide each metadata entry as { key, value } or { key, text }.");let n=J(a.key);if(n===k)throw new g("The key oak.registrar is reserved for the registration marker. Remove that metadata entry.");if(t.has(n))throw new g(`Metadata key ${A(n)} is repeated.`);return t.add(n),{metadataKey:n,metadataValue:G(a)}})}function oe(e,t,a){let n=$(t);if(!n)return;let{registryId:d}=I(e);return Array.isArray(n.registrations)&&n.registrations.some(o=>T(o)&&typeof o.agentRegistry=="string"&&w(o.agentRegistry,d)&&String(o.agentId)===a.toString())}function ve(e,t,a){let n=oe(e,t.uri,BigInt(t.agentId));return n===!0?{...t,profileComplete:!0}:{...t,profileComplete:n===void 0?null:!1,nextStep:{tool:"erc8004_update",arguments:{agentId:t.agentId,profile:a??"a registration-v1 profile object"},why:"The minted profile does not list its own registry and agent ID yet (registrations is empty). erc8004_update appends it automatically. It is a normal action: it needs a verified identity link and an active subscription, so link with oak_setup first."}}}async function ne(e,t,a,n){let{chainId:d,registry:o}=I(e);O(n),B(e,a.chainId);let r=t?x(a.agentId):void 0;if(!t&&(a.tag===!1||a.noTag!==void 0||a["--no-tag"]!==void 0))throw new g(ge);if(a.tag!==void 0&&typeof a.tag!="boolean")throw new g("The tag option must be a boolean.");let s=!t&&a.profile===void 0?"":ye(e,a.profile,a.tag,r),m=t?[]:Ie(a.metadata),l=a.tag!==!1;if(t&&a.metadataTransactionHash!==void 0&&(!l||a.transactionHash===void 0))throw new g("A metadata transaction hash requires tagging and the profile transaction hash.");let i=r!==void 0?H({abi:y,functionName:"setAgentURI",args:[r,s]}):H({abi:y,functionName:"register",args:[s,[...m,{metadataKey:k,metadataValue:R}]]}),c=f=>r===void 0?ve(e,f,a.profile):f;if(a.transactionHash!==void 0){let f=await we(e,a.transactionHash,n,s,i,r);if(!t){if(!w(f.registrarMetadata,R))throw new g(fe);if(a.metadataTransactionHash!==void 0)throw new g("Registration already writes oak.registrar in one transaction. Omit metadataTransactionHash.");return c(f)}return l&&a.metadataTransactionHash!==void 0?c(await ae(e,a.metadataTransactionHash,n,f)):c(f)}if(!t){let f=await ke(e,n);if(f){let b={...f,registrationResumed:!0},h=$(f.uri),v=Array.isArray(h?.tags)&&h.tags.includes(k);if(a.metadataTransactionHash!==void 0){if(!v)throw new g("Only a legacy Oak profile can resume its registrar metadata. Link this agent with oak setup link <agentId>.");return c({...await ae(e,a.metadataTransactionHash,n,f),registrationResumed:!0})}if(!v||f.registrarMetadata!=="0x")return c(b);let S=await U(e,[be(e,x(f.agentId))],n,`Resume registrar metadata for legacy Oak agent ${f.agentId}; no new identity will be minted. Submit locally, then repeat these arguments with metadataTransactionHash to verify the marker receipt.`);return{...b,...S}}if(a.metadataTransactionHash!==void 0)throw new g("No owned legacy Oak identity was found; no metadata transaction was built.")}r!==void 0&&await q(e,r,n);let p=[e.unsignedTx({to:o,data:i,value:"0",chainId:d,description:r===void 0?"Register an ERC-8004 agent profile.":`Update ERC-8004 agent ${r} profile.`})];return t?U(e,p,n,"Submit locally, then repeat the original arguments with transactionHash to verify the profile receipt and URI. The tag option changes the profile tag only; existing onchain metadata is unchanged."):U(e,p,n,`${le} Submit locally, then repeat the original arguments with transactionHash to verify the registration receipt, URI and marker. Update the profile registrations with the mined ID afterward.`)}async function Re(e,t){let a=await M(e,t.agentId),{chainId:n,registry:d}=I(e),o=e.clientFor(n),r=BigInt(a.agentId),u=t.metadataKeys===void 0?[]:(()=>{if(!Array.isArray(t.metadataKeys)||t.metadataKeys.length>16)throw new g("Provide at most 16 metadata keys.");return t.metadataKeys.map(h=>W(h,"metadata key",128,!1))})(),s=t.operator===void 0?void 0:se(String(t.operator)),[m,l,...i]=await Promise.allSettled([o.readContract({address:d,abi:y,functionName:"getApproved",args:[r]}),s?o.readContract({address:d,abi:y,functionName:"isApprovedForAll",args:[a.owner,s]}):Promise.resolve(void 0),...u.map(h=>o.readContract({address:d,abi:y,functionName:"getMetadata",args:[r,h]}))]),c=h=>h.status==="fulfilled"?h.value:void 0,p=c(m),f=_(a.agentWallet)?"unset":w(a.agentWallet,a.owner)?"owner":"verified-other",b=oe(e,a.uri,r);return{...a,approved:typeof p=="string"&&_(p)?null:p??"unavailable",...s?{operator:s,operatorApproved:c(l)??"unavailable"}:{},walletState:f,walletNote:f==="unset"?"No verified payment wallet: it starts as the minting owner, and any NFT transfer or erc8004_unset_wallet clears it. Re-verify with erc8004_wallet_proof then erc8004_set_wallet.":f==="owner"?"The payment wallet is the current owner.":"The payment wallet was proven by a signature from that wallet and is not the owner.",profile:{selfRegistered:b??null,fetched:!1,note:b===void 0?"The URI is external or not decodable; Oak does not fetch it.":void 0},...u.length?{metadata:Object.fromEntries(u.map((h,v)=>{let S=c(i[v]),P=typeof S=="string"&&/^0x([0-9a-fA-F]{2})*$/.test(S)?S:void 0,C;if(P&&P!=="0x")try{C=A(de(P))}catch{C=void 0}return[A(h),{hex:P??"unavailable",...C?{text:C}:{}}]}))}:{}}}var Ae={type:"object",additionalProperties:!1,required:["key"],properties:{key:{type:"string",minLength:1,maxLength:128,description:"Metadata key; agentWallet and oak.registrar are reserved during registration."},value:{...V,description:"Metadata bytes as 0x-prefixed hex; provide value or text."},text:{type:"string",description:"Metadata as UTF-8 text; provide text or value."}}},Te=e=>{let t=(n,d,o)=>({name:n,inputSchema:d,execute:async(r,u)=>{try{let s=await o(r,u);return T(s)&&typeof s.uri=="string"?{...s,uri:A(s.uri)}:s}catch(s){throw new g(e.plainError(s))}}}),a=n=>({type:"object",additionalProperties:!1,required:n?["agentId","profile"]:[],properties:{profile:{...ue,description:n?"Registration-v1 profile object to publish for this agent.":"Omit for an empty URI; register(uri, metadata[]) still writes the public oak.registrar marker. Attach a profile later with erc8004_update."},tag:{type:"boolean",default:!0,description:n?"Set false to remove the profile tag. Profile updates leave existing onchain metadata unchanged.":"Accepted only as true. Oak always adds the oak.registrar marker when it registers."},transactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$",description:n?"Verify the exact profile transaction, event and URI.":"After local submission, verify exact registration calldata, event, URI and oak.registrar marker."},metadataTransactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$",description:n?"Optional legacy metadata transaction hash, supplied with transactionHash to verify a previously sent two-transaction update.":"Only for a resumed legacy Oak profile: verify its separate metadata transaction without transactionHash."},...n?{agentId:N}:{noTag:{type:"boolean",description:"Removed option: omit it and register again."},"--no-tag":{type:"boolean",description:"Removed option: omit it and register again."},metadata:{type:"array",maxItems:15,items:Ae,description:"Up to 15 user entries plus the mandatory oak.registrar marker. The keys agentWallet and oak.registrar are reserved."}}}});return{tools:[t("erc8004_register",a(!1),(n,d)=>ne(e,!1,n,d)),t("erc8004_update",a(!0),(n,d)=>ne(e,!0,n,d)),t("erc8004_identity",{type:"object",additionalProperties:!1,required:["agentId"],properties:{agentId:N,metadataKeys:{type:"array",maxItems:16,items:{type:"string",minLength:1,maxLength:128},description:"Also read these onchain metadata keys."},operator:{...L,description:"Also report whether this address is approved for all of the owner's agents."}}},n=>Re(e,n))]}},Ve=e=>K("erc8004",[Te(e),Q(e),X(e),Y(e),z(e),ee(e)]);export{Ke as a,De as b,oe as c,Te as d,Ve as e};
1
+ import{c as Q}from"./SUNTJ6IU.js";import{b as X}from"./ADIPEGNN.js";import{b as Z}from"./OB7BFDOV.js";import{i as ee}from"./ANIF3JMV.js";import{a as Y}from"./E76Z2TT4.js";import{b as z}from"./GBIBRYOV.js";import{a as D,b as k,c as R,d as N,g as V,h as I,k as _,l as x,n as B,p as W,r as $,s as U,t as q,v as E,x as J,y as G}from"./3A2IKFTV.js";import{a as y}from"./X5V2Z2NM.js";import{b as K}from"./SPJCSEKP.js";import{a as O}from"./43LI5NKJ.js";import{c as L,e as T,g as w}from"./NWNYJ26T.js";import{a as g,d as j}from"./XSD5NL7J.js";import{a as A}from"./JXOEJPJ4.js";import{Buffer as te}from"node:buffer";import{decodeEventLog as re,encodeFunctionData as H,getAddress as se,hexToString as de,parseAbiItem as ce,toEventSelector as ie}from"viem";var Ke={register:"erc8004_register"},ge="Oak now always adds the public oak.registrar marker when it registers an agent, so tag: false and --no-tag are no longer available. Remove the option and register again. To use an agent ID you already own without the marker, link it with oak setup link <agentId>.",fe="The registration went through, but Oak could not find its oak.registrar marker on Robinhood Chain. Nothing else was sent. Ask me to check the agent with erc8004_identity.",le="One transaction registers your agent and writes the public marker oak.registrar = oak. Anyone can see on Robinhood Chain that this agent was registered through Oak. The marker is self-reported, not proof of anything, and the transaction stays in the public history even if the marker is changed later. It needs gas.",F="https://eips.ethereum.org/EIPS/eip-8004#registration-v1",ue={type:"object",required:["type","name","description","image","services","x402Support","active","registrations"],properties:{type:{const:F,description:"ERC-8004 registration-v1 profile type URI."},name:{type:"string",minLength:1,description:"Short public name for the agent."},description:{type:"string",description:"Public text describing what the agent does; may be empty."},image:{type:"string",description:"Public HTTPS or IPFS image URI without credentials."},services:{type:"array",items:{type:"object",required:["name","endpoint"]},description:"Service endpoint objects with name and endpoint; use an empty list for none."},x402Support:{type:"boolean",description:"Whether the agent supports x402 payments."},active:{type:"boolean",description:"Whether this agent is active."},registrations:{type:"array",description:"Registry references with agentRegistry and agentId; leave empty before first registration."},tags:{type:"array",items:{type:"string"},description:"Optional public text labels for the agent."},supportedTrust:{type:"array",items:{type:"string"},description:"Optional trust mechanism labels supported by the agent."}}};function pe(e){if(typeof e!="string"||!e.trim())return!1;try{let t=new URL(e);return["https:","ipfs:"].includes(t.protocol)&&!!t.hostname&&!t.username&&!t.password}catch{return!1}}var me=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&t.trim()),he=e=>e.replace(/\.$/,"");function ye(e,t,a,n){let{registryId:d}=I(e);if(!T(t))throw new g("Provide a registration-v1 profile object.");if(a!==void 0&&typeof a!="boolean")throw new g("The tag option must be a boolean.");let o=[],r=(i,c)=>o.push(`${i}: ${c}`);t.type!==F&&r("type",`use "${F}"`),(typeof t.name!="string"||!t.name.trim())&&r("name",'a short name for your agent, such as "Oak Agent 1"'),typeof t.description!="string"&&r("description","a sentence about what your agent does (it may be empty text)"),pe(t.image)||r("image","an HTTPS or IPFS link to a picture, with no username or password in it"),typeof t.active!="boolean"&&r("active","true or false"),typeof t.x402Support!="boolean"&&r("x402Support","true or false"),Array.isArray(t.services)?t.services.forEach((i,c)=>{try{Z(i)}catch(p){if(!(p instanceof g))throw p;r(`services item ${c+1}`,he(p.message))}}):r("services","a list of endpoints, or [] for none");for(let i of["tags","supportedTrust"])t[i]!==void 0&&!me(t[i])&&r(i,"a list of nonempty text labels, or leave it out");if(Array.isArray(t.registrations)?t.registrations.forEach((i,c)=>{let p=`registrations item ${c+1}`;if(!T(i)||typeof i.agentRegistry!="string"||!/^eip155:[1-9][0-9]*:0x[0-9a-fA-F]{40}$/.test(i.agentRegistry))return r(p,"an agentRegistry such as eip155:4663:0x\u2026 and its agentId");let f=typeof i.agentId=="number"&&Number.isSafeInteger(i.agentId)?String(i.agentId):i.agentId,b;try{b=x(f)}catch{return r(p,'an agentId as a whole number, such as "1"')}w(i.agentRegistry,d)&&(n===void 0?r(p,"remove the entry for this registry; its ID comes from the mined Registered receipt, and erc8004_update adds it afterwards"):b!==n&&r(p,`the agentId does not match the agent being updated; use "${n}" or remove the entry`))}):r("registrations","a list, or [] before the first registration"),o.length)throw new g(`This profile needs: ${o.join("; ")}. Fix all of these and try again.`);let u=t.registrations.map(i=>({...i}));n!==void 0&&!u.some(i=>w(i.agentRegistry,d))&&u.push({agentId:n.toString(),agentRegistry:d});let s=[...new Set((t.tags??[]).filter(i=>i!==k))];a!==!1&&s.push(k);let m={...t,registrations:u,...s.length?{tags:s}:{}};s.length||delete m.tags;let l;try{if(l=JSON.stringify(m),te.byteLength(l)>65536)throw new Error;JSON.parse(l)}catch{throw new g("Profile must be JSON data no larger than 64 KiB.")}return`data:application/json;base64,${te.from(l,"utf8").toString("base64")}`}async function M(e,t){try{let{chainId:a,registry:n}=I(e),d=x(t),o=e.clientFor(a),r=await o.readContract({address:n,abi:y,functionName:"ownerOf",args:[d]}).catch(l=>{throw j(l)?new g(`Agent ${d} does not exist in this ERC-8004 registry: the owner lookup reverted. Check the agent ID.`):l});O(r);let[u,s,m]=await Promise.all([o.readContract({address:n,abi:y,functionName:"tokenURI",args:[d]}),o.readContract({address:n,abi:y,functionName:"getAgentWallet",args:[d]}),o.readContract({address:n,abi:y,functionName:"getMetadata",args:[d,k]})]);if(O(s),typeof u!="string"||typeof m!="string"||!/^0x([0-9a-fA-F]{2})*$/.test(m))throw new g("The registry returned invalid identity data.");return{agentId:d.toString(),chainId:a,registry:n,owner:r,uri:u,agentWallet:s,registrarMetadata:m,registryValidated:!1,summary:D}}catch(a){throw new g(e.plainError(a))}}async function De(e,t){let a=await M(e,t);return{...a,uri:A(a.uri)}}async function we(e,t,a,n,d,o){let{registry:r}=I(e),u=await E(e,t,a,d),s=o===void 0?"Registered":"URIUpdated",m=ie(o===void 0?"Registered(uint256,string,address)":"URIUpdated(uint256,string,address)"),l=u.logs.filter(v=>w(v.address,r)&&v.topics[0]===m&&!v.removed);if(l.length!==1)throw new g(`The receipt must contain one matching ${s} event.`);let i=l[0],c=re({abi:y,eventName:s,topics:i.topics,data:i.data,strict:!0}),p=c.args.agentId,f=c.eventName==="Registered"?c.args.agentURI:c.args.newURI,b=c.eventName==="Registered"?c.args.owner:c.args.updatedBy;if(o!==void 0&&p!==o||f!==n||!w(b,a))throw new g("The registry event does not match the expected agent, URI and wallet.");let h=await M(e,p.toString());if(h.uri!==n||o===void 0&&!w(h.owner,a))throw new g("The current agent owner or URI does not match the confirmed operation.");return h}function be(e,t){let{chainId:a,registry:n}=I(e);return e.unsignedTx({to:n,chainId:a,value:"0",data:H({abi:y,functionName:"setMetadata",args:[t,k,R]}),description:`Set mutable oak.registrar metadata to oak for agent ${t}.`})}async function ae(e,t,a,n){let{registry:d}=I(e),o=x(n.agentId),r=await E(e,t,a,H({abi:y,functionName:"setMetadata",args:[o,k,R]})),u=ie("MetadataSet(uint256,string,string,bytes)"),s=r.logs.filter(c=>w(c.address,d)&&c.topics[0]===u&&!c.removed);if(s.length!==1)throw new g("The receipt must contain one matching MetadataSet event.");let m=s[0],{args:l}=re({abi:y,eventName:"MetadataSet",topics:m.topics,data:m.data,strict:!0});if(l.agentId!==o||l.metadataKey!==k||l.metadataValue!==R)throw new g("The metadata event does not match this agent and registrar marker.");let i=await M(e,n.agentId);if(i.registrarMetadata!==R||i.uri!==n.uri||!w(i.owner,n.owner))throw new g("The current agent metadata, owner or URI does not match the confirmed operation.");return i}async function ke(e,t){let{chainId:a,registry:n}=I(e),d=e.clientFor(a),o=await d.readContract({address:n,abi:y,functionName:"balanceOf",args:[t]});if(o===0n)return;if(typeof o!="bigint"||o<0n)throw new g("Registry balance is unavailable; registration was not built.");let r=await d.getBlockNumber({cacheTime:0}),u=new Set;for(;;){let s=r>9999999n?r-9999999n:0n,m=await d.getLogs({address:n,event:ce("event Transfer(address indexed from,address indexed to,uint256 indexed tokenId)"),args:{to:t},fromBlock:s,toBlock:r,strict:!0});for(let l of m){let i=l.args.tokenId.toString();if(l.removed||u.has(i))continue;u.add(i);let c=await M(e,i);if(w(c.owner,t))return c}if(s===0n)throw new g("Owned identity could not be located; registration was not built. Run oak setup link <agentId>.");r=s-1n}}function Ie(e){if(e===void 0)return[];if(!Array.isArray(e)||e.length>15)throw new g("Provide at most 15 user metadata entries as { key, value } with value as 0x hex or text.");let t=new Set;return e.map(a=>{if(!T(a))throw new g("Provide each metadata entry as { key, value } or { key, text }.");let n=J(a.key);if(n===k)throw new g("The key oak.registrar is reserved for the registration marker. Remove that metadata entry.");if(t.has(n))throw new g(`Metadata key ${A(n)} is repeated.`);return t.add(n),{metadataKey:n,metadataValue:G(a)}})}function oe(e,t,a){let n=$(t);if(!n)return;let{registryId:d}=I(e);return Array.isArray(n.registrations)&&n.registrations.some(o=>T(o)&&typeof o.agentRegistry=="string"&&w(o.agentRegistry,d)&&String(o.agentId)===a.toString())}function ve(e,t,a){let n=oe(e,t.uri,BigInt(t.agentId));return n===!0?{...t,profileComplete:!0}:{...t,profileComplete:n===void 0?null:!1,nextStep:{tool:"erc8004_update",arguments:{agentId:t.agentId,profile:a??"a registration-v1 profile object"},why:"The minted profile does not list its own registry and agent ID yet (registrations is empty). erc8004_update appends it automatically. It is a normal action: it needs a verified identity link and an active subscription, so link with oak_setup first."}}}async function ne(e,t,a,n){let{chainId:d,registry:o}=I(e);O(n),B(e,a.chainId);let r=t?x(a.agentId):void 0;if(!t&&(a.tag===!1||a.noTag!==void 0||a["--no-tag"]!==void 0))throw new g(ge);if(a.tag!==void 0&&typeof a.tag!="boolean")throw new g("The tag option must be a boolean.");let s=!t&&a.profile===void 0?"":ye(e,a.profile,a.tag,r),m=t?[]:Ie(a.metadata),l=a.tag!==!1;if(t&&a.metadataTransactionHash!==void 0&&(!l||a.transactionHash===void 0))throw new g("A metadata transaction hash requires tagging and the profile transaction hash.");let i=r!==void 0?H({abi:y,functionName:"setAgentURI",args:[r,s]}):H({abi:y,functionName:"register",args:[s,[...m,{metadataKey:k,metadataValue:R}]]}),c=f=>r===void 0?ve(e,f,a.profile):f;if(a.transactionHash!==void 0){let f=await we(e,a.transactionHash,n,s,i,r);if(!t){if(!w(f.registrarMetadata,R))throw new g(fe);if(a.metadataTransactionHash!==void 0)throw new g("Registration already writes oak.registrar in one transaction. Omit metadataTransactionHash.");return c(f)}return l&&a.metadataTransactionHash!==void 0?c(await ae(e,a.metadataTransactionHash,n,f)):c(f)}if(!t){let f=await ke(e,n);if(f){let b={...f,registrationResumed:!0},h=$(f.uri),v=Array.isArray(h?.tags)&&h.tags.includes(k);if(a.metadataTransactionHash!==void 0){if(!v)throw new g("Only a legacy Oak profile can resume its registrar metadata. Link this agent with oak setup link <agentId>.");return c({...await ae(e,a.metadataTransactionHash,n,f),registrationResumed:!0})}if(!v||f.registrarMetadata!=="0x")return c(b);let S=await U(e,[be(e,x(f.agentId))],n,`Resume registrar metadata for legacy Oak agent ${f.agentId}; no new identity will be minted. Submit locally, then repeat these arguments with metadataTransactionHash to verify the marker receipt.`);return{...b,...S}}if(a.metadataTransactionHash!==void 0)throw new g("No owned legacy Oak identity was found; no metadata transaction was built.")}r!==void 0&&await q(e,r,n);let p=[e.unsignedTx({to:o,data:i,value:"0",chainId:d,description:r===void 0?"Register an ERC-8004 agent profile.":`Update ERC-8004 agent ${r} profile.`})];return t?U(e,p,n,"Submit locally, then repeat the original arguments with transactionHash to verify the profile receipt and URI. The tag option changes the profile tag only; existing onchain metadata is unchanged."):U(e,p,n,`${le} Submit locally, then repeat the original arguments with transactionHash to verify the registration receipt, URI and marker. Update the profile registrations with the mined ID afterward.`)}async function Re(e,t){let a=await M(e,t.agentId),{chainId:n,registry:d}=I(e),o=e.clientFor(n),r=BigInt(a.agentId),u=t.metadataKeys===void 0?[]:(()=>{if(!Array.isArray(t.metadataKeys)||t.metadataKeys.length>16)throw new g("Provide at most 16 metadata keys.");return t.metadataKeys.map(h=>W(h,"metadata key",128,!1))})(),s=t.operator===void 0?void 0:se(String(t.operator)),[m,l,...i]=await Promise.allSettled([o.readContract({address:d,abi:y,functionName:"getApproved",args:[r]}),s?o.readContract({address:d,abi:y,functionName:"isApprovedForAll",args:[a.owner,s]}):Promise.resolve(void 0),...u.map(h=>o.readContract({address:d,abi:y,functionName:"getMetadata",args:[r,h]}))]),c=h=>h.status==="fulfilled"?h.value:void 0,p=c(m),f=_(a.agentWallet)?"unset":w(a.agentWallet,a.owner)?"owner":"verified-other",b=oe(e,a.uri,r);return{...a,approved:typeof p=="string"&&_(p)?null:p??"unavailable",...s?{operator:s,operatorApproved:c(l)??"unavailable"}:{},walletState:f,walletNote:f==="unset"?"No verified payment wallet: it starts as the minting owner, and any NFT transfer or erc8004_unset_wallet clears it. Re-verify with erc8004_wallet_proof then erc8004_set_wallet.":f==="owner"?"The payment wallet is the current owner.":"The payment wallet was proven by a signature from that wallet and is not the owner.",profile:{selfRegistered:b??null,fetched:!1,note:b===void 0?"The URI is external or not decodable; Oak does not fetch it.":void 0},...u.length?{metadata:Object.fromEntries(u.map((h,v)=>{let S=c(i[v]),P=typeof S=="string"&&/^0x([0-9a-fA-F]{2})*$/.test(S)?S:void 0,C;if(P&&P!=="0x")try{C=A(de(P))}catch{C=void 0}return[A(h),{hex:P??"unavailable",...C?{text:C}:{}}]}))}:{}}}var Ae={type:"object",additionalProperties:!1,required:["key"],properties:{key:{type:"string",minLength:1,maxLength:128,description:"Metadata key; agentWallet and oak.registrar are reserved during registration."},value:{...V,description:"Metadata bytes as 0x-prefixed hex; provide value or text."},text:{type:"string",description:"Metadata as UTF-8 text; provide text or value."}}},Te=e=>{let t=(n,d,o)=>({name:n,inputSchema:d,execute:async(r,u)=>{try{let s=await o(r,u);return T(s)&&typeof s.uri=="string"?{...s,uri:A(s.uri)}:s}catch(s){throw new g(e.plainError(s))}}}),a=n=>({type:"object",additionalProperties:!1,required:n?["agentId","profile"]:[],properties:{profile:{...ue,description:n?"Registration-v1 profile object to publish for this agent.":"Omit for an empty URI; register(uri, metadata[]) still writes the public oak.registrar marker. Attach a profile later with erc8004_update."},tag:{type:"boolean",default:!0,description:n?"Set false to remove the profile tag. Profile updates leave existing onchain metadata unchanged.":"Accepted only as true. Oak always adds the oak.registrar marker when it registers."},transactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$",description:n?"Verify the exact profile transaction, event and URI.":"After local submission, verify exact registration calldata, event, URI and oak.registrar marker."},metadataTransactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$",description:n?"Optional legacy metadata transaction hash, supplied with transactionHash to verify a previously sent two-transaction update.":"Only for a resumed legacy Oak profile: verify its separate metadata transaction without transactionHash."},...n?{agentId:N}:{noTag:{type:"boolean",description:"Removed option: omit it and register again."},"--no-tag":{type:"boolean",description:"Removed option: omit it and register again."},metadata:{type:"array",maxItems:15,items:Ae,description:"Up to 15 user entries plus the mandatory oak.registrar marker. The keys agentWallet and oak.registrar are reserved."}}}});return{tools:[t("erc8004_register",a(!1),(n,d)=>ne(e,!1,n,d)),t("erc8004_update",a(!0),(n,d)=>ne(e,!0,n,d)),t("erc8004_identity",{type:"object",additionalProperties:!1,required:["agentId"],properties:{agentId:N,metadataKeys:{type:"array",maxItems:16,items:{type:"string",minLength:1,maxLength:128},description:"Also read these onchain metadata keys."},operator:{...L,description:"Also report whether this address is approved for all of the owner's agents."}}},n=>Re(e,n))]}},Ve=e=>K("erc8004",[Te(e),Q(e),X(e),Y(e),z(e),ee(e)]);export{Ke as a,De as b,oe as c,Te as d,Ve as e};