@oakagentkit/core 0.2.3 → 0.2.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 (576) hide show
  1. package/build/dist/api/addresses.d.ts +112 -0
  2. package/build/dist/api/addresses.js +1 -1
  3. package/build/dist/api/amounts.d.ts +2 -0
  4. package/build/dist/api/amounts.js +1 -1
  5. package/build/dist/api/args.js +1 -1
  6. package/build/dist/api/cache.js +1 -1
  7. package/build/dist/api/canonical.js +1 -1
  8. package/build/dist/api/chain.js +1 -1
  9. package/build/dist/api/deployments.js +1 -1
  10. package/build/dist/api/errors.d.ts +1 -0
  11. package/build/dist/api/errors.js +1 -1
  12. package/build/dist/api/gas.js +1 -1
  13. package/build/dist/api/grandfather.js +1 -1
  14. package/build/dist/api/guards.js +1 -1
  15. package/build/dist/api/history.js +1 -1
  16. package/build/dist/api/http.js +1 -1
  17. package/build/dist/api/identity-link.d.ts +1 -0
  18. package/build/dist/api/identity-link.js +1 -1
  19. package/build/dist/api/launch.js +1 -1
  20. package/build/dist/api/merkle.js +1 -1
  21. package/build/dist/api/metadata.js +1 -1
  22. package/build/dist/api/module.js +1 -1
  23. package/build/dist/api/modules/beefy/boosts.js +1 -1
  24. package/build/dist/api/modules/beefy/clm.js +1 -1
  25. package/build/dist/api/modules/beefy/guard.js +1 -1
  26. package/build/dist/api/modules/beefy/index.js +1 -1
  27. package/build/dist/api/modules/beefy/liquidity.js +1 -1
  28. package/build/dist/api/modules/beefy/management.js +1 -1
  29. package/build/dist/api/modules/beefy/vaults.js +1 -1
  30. package/build/dist/api/modules/borro/abi.d.ts +149 -0
  31. package/build/dist/api/modules/borro/abi.js +1 -0
  32. package/build/dist/api/modules/borro/actions.d.ts +2 -0
  33. package/build/dist/api/modules/borro/actions.js +1 -0
  34. package/build/dist/api/modules/borro/checks.d.ts +151 -0
  35. package/build/dist/api/modules/borro/checks.js +1 -0
  36. package/build/dist/api/modules/borro/copy.d.ts +174 -0
  37. package/build/dist/api/modules/borro/copy.js +1 -0
  38. package/build/dist/api/modules/borro/index.d.ts +13 -0
  39. package/build/dist/api/modules/borro/index.js +1 -0
  40. package/build/dist/api/modules/borro/liquidity.d.ts +4 -0
  41. package/build/dist/api/modules/borro/liquidity.js +1 -0
  42. package/build/dist/api/modules/borro/pins.d.ts +264 -0
  43. package/build/dist/api/modules/borro/pins.js +1 -0
  44. package/build/dist/api/modules/borro/positions.d.ts +8 -0
  45. package/build/dist/api/modules/borro/positions.js +1 -0
  46. package/build/dist/api/modules/borro/rates.d.ts +20 -0
  47. package/build/dist/api/modules/borro/rates.js +1 -0
  48. package/build/dist/api/modules/borro/reader.d.ts +32 -0
  49. package/build/dist/api/modules/borro/reader.js +1 -0
  50. package/build/dist/api/modules/borro/types.d.ts +120 -0
  51. package/build/dist/api/modules/borro/types.js +0 -0
  52. package/build/dist/api/modules/clanker/extensions.js +1 -1
  53. package/build/dist/api/modules/clanker/index.js +1 -1
  54. package/build/dist/api/modules/clanker/manage.js +1 -1
  55. package/build/dist/api/modules/clanker/pool-config.js +1 -1
  56. package/build/dist/api/modules/clanker/protocol.js +1 -1
  57. package/build/dist/api/modules/clanker/state.js +1 -1
  58. package/build/dist/api/modules/earn/copy.d.ts +114 -0
  59. package/build/dist/api/modules/earn/copy.js +1 -0
  60. package/build/dist/api/modules/earn/cost.d.ts +47 -0
  61. package/build/dist/api/modules/earn/cost.js +1 -0
  62. package/build/dist/api/modules/earn/index.d.ts +8 -0
  63. package/build/dist/api/modules/earn/index.js +1 -0
  64. package/build/dist/api/modules/earn/lp.d.ts +17 -0
  65. package/build/dist/api/modules/earn/lp.js +1 -0
  66. package/build/dist/api/modules/earn/options.d.ts +36 -0
  67. package/build/dist/api/modules/earn/options.js +1 -0
  68. package/build/dist/api/modules/earn/types.d.ts +39 -0
  69. package/build/dist/api/modules/earn/types.js +0 -0
  70. package/build/dist/api/modules/erc8004/abi.js +1 -1
  71. package/build/dist/api/modules/erc8004/common.js +1 -1
  72. package/build/dist/api/modules/erc8004/domain.js +1 -1
  73. package/build/dist/api/modules/erc8004/index.js +1 -1
  74. package/build/dist/api/modules/erc8004/management.js +1 -1
  75. package/build/dist/api/modules/erc8004/reputation.js +1 -1
  76. package/build/dist/api/modules/erc8004/services.js +1 -1
  77. package/build/dist/api/modules/erc8004/validation.js +1 -1
  78. package/build/dist/api/modules/grove/index.js +1 -1
  79. package/build/dist/api/modules/heyresearch/backoff.js +1 -1
  80. package/build/dist/api/modules/heyresearch/builder-feed.js +1 -1
  81. package/build/dist/api/modules/heyresearch/freshness.js +1 -1
  82. package/build/dist/api/modules/heyresearch/index.js +1 -1
  83. package/build/dist/api/modules/heyresearch/proof-reads.js +1 -1
  84. package/build/dist/api/modules/heyresearch/public-reads.js +1 -1
  85. package/build/dist/api/modules/heyresearch/scan.js +1 -1
  86. package/build/dist/api/modules/heyresearch/status-labels.d.ts +1 -1
  87. package/build/dist/api/modules/heyresearch/status-labels.js +1 -1
  88. package/build/dist/api/modules/heyresearch/token-facts.js +1 -1
  89. package/build/dist/api/modules/hoodag/chain-reads.js +1 -1
  90. package/build/dist/api/modules/hoodag/index.js +1 -1
  91. package/build/dist/api/modules/hoodag/management.js +1 -1
  92. package/build/dist/api/modules/hoodag/public-reads.js +1 -1
  93. package/build/dist/api/modules/hoodag/reconstruct.js +1 -1
  94. package/build/dist/api/modules/hoodlock/airdrop.js +1 -1
  95. package/build/dist/api/modules/hoodlock/buyback.js +1 -1
  96. package/build/dist/api/modules/hoodlock/commerce.js +1 -1
  97. package/build/dist/api/modules/hoodlock/fee.js +1 -1
  98. package/build/dist/api/modules/hoodlock/guard.js +1 -1
  99. package/build/dist/api/modules/hoodlock/index.js +1 -1
  100. package/build/dist/api/modules/hoodlock/lifecycle.js +1 -1
  101. package/build/dist/api/modules/hoodlock/locks-burn.js +1 -1
  102. package/build/dist/api/modules/hoodlock/public.js +1 -1
  103. package/build/dist/api/modules/hookr/actions.js +1 -1
  104. package/build/dist/api/modules/hookr/addons.js +1 -1
  105. package/build/dist/api/modules/hookr/agent-gate.js +1 -1
  106. package/build/dist/api/modules/hookr/contracts.js +1 -1
  107. package/build/dist/api/modules/hookr/create-cancel.js +1 -1
  108. package/build/dist/api/modules/hookr/discovery.js +1 -1
  109. package/build/dist/api/modules/hookr/fill-bounty.js +1 -1
  110. package/build/dist/api/modules/hookr/index.js +1 -1
  111. package/build/dist/api/modules/hookr/launch-options.js +1 -1
  112. package/build/dist/api/modules/hookr/launch-profile.js +1 -1
  113. package/build/dist/api/modules/hookr/launch-receipt.js +1 -1
  114. package/build/dist/api/modules/hookr/launch.js +1 -1
  115. package/build/dist/api/modules/hookr/liquidity.js +1 -1
  116. package/build/dist/api/modules/hookr/lp-positions.js +1 -1
  117. package/build/dist/api/modules/hookr/lp-reads.js +1 -1
  118. package/build/dist/api/modules/hookr/lp-receipt.js +1 -1
  119. package/build/dist/api/modules/hookr/lp-state.js +1 -1
  120. package/build/dist/api/modules/hookr/pins.js +1 -1
  121. package/build/dist/api/modules/hookr/public-reads.js +1 -1
  122. package/build/dist/api/modules/hookr/read-utils.js +1 -1
  123. package/build/dist/api/modules/hookr/relay.js +1 -1
  124. package/build/dist/api/modules/hookr/revenue.js +1 -1
  125. package/build/dist/api/modules/kyberswap/index.js +1 -1
  126. package/build/dist/api/modules/kyberswap/source-pools.js +1 -1
  127. package/build/dist/api/modules/layerbank/abi.d.ts +165 -0
  128. package/build/dist/api/modules/layerbank/abi.js +1 -0
  129. package/build/dist/api/modules/layerbank/actions.d.ts +2 -0
  130. package/build/dist/api/modules/layerbank/actions.js +1 -0
  131. package/build/dist/api/modules/layerbank/checks.d.ts +21 -0
  132. package/build/dist/api/modules/layerbank/checks.js +1 -0
  133. package/build/dist/api/modules/layerbank/index.d.ts +2 -0
  134. package/build/dist/api/modules/layerbank/index.js +1 -0
  135. package/build/dist/api/modules/layerbank/merkl.d.ts +6 -0
  136. package/build/dist/api/modules/layerbank/merkl.js +1 -0
  137. package/build/dist/api/modules/layerbank/reader.d.ts +15 -0
  138. package/build/dist/api/modules/layerbank/reader.js +1 -0
  139. package/build/dist/api/modules/layerbank/reserve.d.ts +13 -0
  140. package/build/dist/api/modules/layerbank/reserve.js +1 -0
  141. package/build/dist/api/modules/lighter/index.js +1 -1
  142. package/build/dist/api/modules/longbow/administration.js +1 -1
  143. package/build/dist/api/modules/longbow/analytics.js +1 -1
  144. package/build/dist/api/modules/longbow/fixed.js +1 -1
  145. package/build/dist/api/modules/longbow/index.js +1 -1
  146. package/build/dist/api/modules/longbow/nft.js +1 -1
  147. package/build/dist/api/modules/longbow/rebates.js +1 -1
  148. package/build/dist/api/modules/longbow/staking.js +1 -1
  149. package/build/dist/api/modules/meridian/index.js +1 -1
  150. package/build/dist/api/modules/meridian/markets.js +1 -1
  151. package/build/dist/api/modules/meridian/perps-batch.js +1 -1
  152. package/build/dist/api/modules/meridian/perps-common.js +1 -1
  153. package/build/dist/api/modules/meridian/perps-guards.js +1 -1
  154. package/build/dist/api/modules/meridian/perps-intents.js +1 -1
  155. package/build/dist/api/modules/meridian/perps-stream.js +1 -1
  156. package/build/dist/api/modules/meridian/perps.d.ts +1 -0
  157. package/build/dist/api/modules/meridian/perps.js +1 -1
  158. package/build/dist/api/modules/meridian/predict-read.js +1 -1
  159. package/build/dist/api/modules/meridian/rfq.js +1 -1
  160. package/build/dist/api/modules/merkl/discovery.js +1 -1
  161. package/build/dist/api/modules/merkl/index.js +1 -1
  162. package/build/dist/api/modules/merkl/manage.js +1 -1
  163. package/build/dist/api/modules/merkl/protocol.js +1 -1
  164. package/build/dist/api/modules/morpho/allocator.js +1 -1
  165. package/build/dist/api/modules/morpho/bundles-abi.js +1 -1
  166. package/build/dist/api/modules/morpho/bundles.js +1 -1
  167. package/build/dist/api/modules/morpho/in-kind.js +1 -1
  168. package/build/dist/api/modules/morpho/index.js +1 -1
  169. package/build/dist/api/modules/morpho/local-guard.js +1 -1
  170. package/build/dist/api/modules/morpho/midnight-abi.js +1 -1
  171. package/build/dist/api/modules/morpho/midnight.js +1 -1
  172. package/build/dist/api/modules/morpho/protocol.js +1 -1
  173. package/build/dist/api/modules/morpho/surface.js +1 -1
  174. package/build/dist/api/modules/morpho/vault-management.js +1 -1
  175. package/build/dist/api/modules/morpho/vault-tools.js +1 -1
  176. package/build/dist/api/modules/morpho/vault-v2.js +1 -1
  177. package/build/dist/api/modules/netnet/blackjack-hashes.js +1 -1
  178. package/build/dist/api/modules/netnet/card-abi.js +1 -1
  179. package/build/dist/api/modules/netnet/card-plan.js +1 -1
  180. package/build/dist/api/modules/netnet/card-policy.js +1 -1
  181. package/build/dist/api/modules/netnet/card-read.js +1 -1
  182. package/build/dist/api/modules/netnet/card-recovery.js +1 -1
  183. package/build/dist/api/modules/netnet/desk-action-abi.js +1 -1
  184. package/build/dist/api/modules/netnet/desk-action.js +1 -1
  185. package/build/dist/api/modules/netnet/desk-read.js +1 -1
  186. package/build/dist/api/modules/netnet/desk-registry.js +1 -1
  187. package/build/dist/api/modules/netnet/financial-abi.js +1 -1
  188. package/build/dist/api/modules/netnet/financial.js +1 -1
  189. package/build/dist/api/modules/netnet/index.js +1 -1
  190. package/build/dist/api/modules/netnet/staking.js +1 -1
  191. package/build/dist/api/modules/orbio/gateway.js +1 -1
  192. package/build/dist/api/modules/orbio/index.js +1 -1
  193. package/build/dist/api/modules/orbio/pins.js +1 -1
  194. package/build/dist/api/modules/orbio/positions.d.ts +2 -0
  195. package/build/dist/api/modules/orbio/positions.js +1 -0
  196. package/build/dist/api/modules/pendle/abi.d.ts +205 -0
  197. package/build/dist/api/modules/pendle/abi.js +1 -0
  198. package/build/dist/api/modules/pendle/convert.d.ts +24 -0
  199. package/build/dist/api/modules/pendle/convert.js +1 -0
  200. package/build/dist/api/modules/pendle/costs.d.ts +3 -0
  201. package/build/dist/api/modules/pendle/costs.js +1 -0
  202. package/build/dist/api/modules/pendle/index.d.ts +11 -0
  203. package/build/dist/api/modules/pendle/index.js +1 -0
  204. package/build/dist/api/modules/pendle/markets.d.ts +37 -0
  205. package/build/dist/api/modules/pendle/markets.js +1 -0
  206. package/build/dist/api/modules/pendle/positions.d.ts +18 -0
  207. package/build/dist/api/modules/pendle/positions.js +1 -0
  208. package/build/dist/api/modules/pendle/pricecheck.d.ts +95 -0
  209. package/build/dist/api/modules/pendle/pricecheck.js +1 -0
  210. package/build/dist/api/modules/pendle/reader.d.ts +17 -0
  211. package/build/dist/api/modules/pendle/reader.js +1 -0
  212. package/build/dist/api/modules/pendle/redeem.d.ts +15 -0
  213. package/build/dist/api/modules/pendle/redeem.js +1 -0
  214. package/build/dist/api/modules/pendle/trade.d.ts +2 -0
  215. package/build/dist/api/modules/pendle/trade.js +1 -0
  216. package/build/dist/api/modules/pendle/types.d.ts +41 -0
  217. package/build/dist/api/modules/pendle/types.js +0 -0
  218. package/build/dist/api/modules/pendle/validate.d.ts +424 -0
  219. package/build/dist/api/modules/pendle/validate.js +1 -0
  220. package/build/dist/api/modules/pendle/verify.d.ts +22 -0
  221. package/build/dist/api/modules/pendle/verify.js +1 -0
  222. package/build/dist/api/modules/pons/claim.js +1 -1
  223. package/build/dist/api/modules/pons/holder-directory.js +1 -1
  224. package/build/dist/api/modules/pons/index.js +1 -1
  225. package/build/dist/api/modules/pons/launch-status.js +1 -1
  226. package/build/dist/api/modules/pons/prices.js +1 -1
  227. package/build/dist/api/modules/pons/reads.d.ts +38 -2
  228. package/build/dist/api/modules/pons/reads.js +1 -1
  229. package/build/dist/api/modules/pons/swap-terms.js +1 -1
  230. package/build/dist/api/modules/pons/trade.js +1 -1
  231. package/build/dist/api/modules/poolstrade/index.js +1 -1
  232. package/build/dist/api/modules/priors/coverage.js +1 -1
  233. package/build/dist/api/modules/priors/discovery.js +1 -1
  234. package/build/dist/api/modules/priors/features.js +1 -1
  235. package/build/dist/api/modules/priors/holdings.d.ts +4 -0
  236. package/build/dist/api/modules/priors/holdings.js +1 -0
  237. package/build/dist/api/modules/priors/index.js +1 -1
  238. package/build/dist/api/modules/priors/integration.js +1 -1
  239. package/build/dist/api/modules/priors/market.js +1 -1
  240. package/build/dist/api/modules/priors/pt.js +1 -1
  241. package/build/dist/api/modules/priors/savings-exit.js +1 -1
  242. package/build/dist/api/modules/priors/starter-line.js +1 -1
  243. package/build/dist/api/modules/priors/stock-swap.js +1 -1
  244. package/build/dist/api/modules/relay/api.js +1 -1
  245. package/build/dist/api/modules/relay/bootstrap.js +1 -1
  246. package/build/dist/api/modules/relay/discovery.js +1 -1
  247. package/build/dist/api/modules/relay/inbound.d.ts +2 -0
  248. package/build/dist/api/modules/relay/inbound.js +1 -1
  249. package/build/dist/api/modules/relay/index.js +1 -1
  250. package/build/dist/api/modules/relay/order.js +1 -1
  251. package/build/dist/api/modules/relay/outbound-status.js +1 -1
  252. package/build/dist/api/modules/relay/readiness.js +1 -1
  253. package/build/dist/api/modules/relay/reads.js +1 -1
  254. package/build/dist/api/modules/relay/vaults.js +1 -1
  255. package/build/dist/api/modules/spark/actions.js +1 -1
  256. package/build/dist/api/modules/spark/details.js +1 -1
  257. package/build/dist/api/modules/spark/index.js +1 -1
  258. package/build/dist/api/modules/spark/management.js +1 -1
  259. package/build/dist/api/modules/steakhouse/analytics.js +1 -1
  260. package/build/dist/api/modules/steakhouse/erc4626.js +1 -1
  261. package/build/dist/api/modules/steakhouse/index.js +1 -1
  262. package/build/dist/api/modules/steakhouse/local-guard.js +1 -1
  263. package/build/dist/api/modules/steakhouse/management.js +1 -1
  264. package/build/dist/api/modules/steakhouse/share-symbol.d.ts +3 -0
  265. package/build/dist/api/modules/steakhouse/share-symbol.js +1 -0
  266. package/build/dist/api/modules/steakhouse/v2-exit.js +1 -1
  267. package/build/dist/api/modules/tickerspring/basket-routes.js +1 -1
  268. package/build/dist/api/modules/tickerspring/contract-reads.js +1 -1
  269. package/build/dist/api/modules/tickerspring/discovery.js +1 -1
  270. package/build/dist/api/modules/tickerspring/exit-preview.js +1 -1
  271. package/build/dist/api/modules/tickerspring/guards.js +1 -1
  272. package/build/dist/api/modules/tickerspring/index.js +1 -1
  273. package/build/dist/api/modules/tickerspring/journeys.js +1 -1
  274. package/build/dist/api/modules/tickerspring/ladder.js +1 -1
  275. package/build/dist/api/modules/tickerspring/maker.js +1 -1
  276. package/build/dist/api/modules/tickerspring/order-accounting.js +1 -1
  277. package/build/dist/api/modules/tickerspring/research.js +1 -1
  278. package/build/dist/api/modules/tickerspring/strategies.js +1 -1
  279. package/build/dist/api/modules/uniswap/auction-create.js +1 -1
  280. package/build/dist/api/modules/uniswap/auction.js +1 -1
  281. package/build/dist/api/modules/uniswap/batch.js +1 -1
  282. package/build/dist/api/modules/uniswap/common.js +1 -1
  283. package/build/dist/api/modules/uniswap/fees.js +1 -1
  284. package/build/dist/api/modules/uniswap/index.js +1 -1
  285. package/build/dist/api/modules/uniswap/local-guard.js +1 -1
  286. package/build/dist/api/modules/uniswap/oracle.js +1 -1
  287. package/build/dist/api/modules/uniswap/pool-math.js +1 -1
  288. package/build/dist/api/modules/uniswap/pools.js +1 -1
  289. package/build/dist/api/modules/uniswap/position.js +1 -1
  290. package/build/dist/api/modules/uniswap/protocol.js +1 -1
  291. package/build/dist/api/modules/uniswap/token-jar.js +1 -1
  292. package/build/dist/api/modules/uniswap/trade-batch.js +1 -1
  293. package/build/dist/api/modules/uniswap/trade.js +1 -1
  294. package/build/dist/api/modules/uniswap/v2.js +1 -1
  295. package/build/dist/api/modules/uniswap/v3.d.ts +11 -0
  296. package/build/dist/api/modules/uniswap/v3.js +1 -1
  297. package/build/dist/api/modules/uniswap/v4.js +1 -1
  298. package/build/dist/api/modules/uniswap/wrap.js +1 -1
  299. package/build/dist/api/modules/velora/claims.js +1 -1
  300. package/build/dist/api/modules/velora/delta-reads.js +1 -1
  301. package/build/dist/api/modules/velora/index.js +1 -1
  302. package/build/dist/api/modules/wormhole/index.js +1 -1
  303. package/build/dist/api/modules/wormhole/license.js +1 -1
  304. package/build/dist/api/modules/wormhole/quotetext.js +1 -1
  305. package/build/dist/api/modules/wormhole/scan-text.js +1 -1
  306. package/build/dist/api/modules/wormhole/token-check.js +1 -1
  307. package/build/dist/api/owner-signature.js +1 -1
  308. package/build/dist/api/positions.d.ts +5 -5
  309. package/build/dist/api/positions.js +1 -1
  310. package/build/dist/api/pricenote.js +1 -1
  311. package/build/dist/api/prices.js +1 -1
  312. package/build/dist/api/pricing.js +1 -1
  313. package/build/dist/api/reads.js +1 -1
  314. package/build/dist/api/routes.js +1 -1
  315. package/build/dist/api/rpc.js +1 -1
  316. package/build/dist/api/secret-fields.js +1 -1
  317. package/build/dist/api/send.js +1 -1
  318. package/build/dist/api/signing-registry.js +1 -1
  319. package/build/dist/api/signing.js +1 -1
  320. package/build/dist/api/simulate.js +1 -1
  321. package/build/dist/api/swap.js +1 -1
  322. package/build/dist/api/token-output.js +1 -1
  323. package/build/dist/api/tokens.d.ts +1 -0
  324. package/build/dist/api/tokens.js +1 -1
  325. package/build/dist/api/tool-policy.js +1 -1
  326. package/build/dist/api/tx.js +1 -1
  327. package/build/dist/api/types.d.ts +7 -2
  328. package/build/dist/api/untrusted.js +1 -1
  329. package/build/dist/api/vendor-limits.js +1 -1
  330. package/build/dist/chunks/{PEA32CWB.js → 2KYAMXTS.js} +1 -1
  331. package/build/dist/chunks/2MAMJJJC.js +1 -0
  332. package/build/dist/chunks/2MZXTOZU.js +1 -0
  333. package/build/dist/chunks/{VC2RCYQE.js → 2TK3ETUO.js} +1 -1
  334. package/build/dist/chunks/{LKJBMHCE.js → 326QMOTR.js} +1 -1
  335. package/build/dist/chunks/{OE3CLZHR.js → 3FUVMSCF.js} +1 -1
  336. package/build/dist/chunks/{3EFV4FQF.js → 3GOHSYHW.js} +1 -1
  337. package/build/dist/chunks/{CY75R4FK.js → 3MLUCYCB.js} +1 -1
  338. package/build/dist/chunks/{5O5ZE3ZV.js → 3NJ5KQ3Q.js} +1 -1
  339. package/build/dist/chunks/{EVANKNJV.js → 3XNZUIRU.js} +1 -1
  340. package/build/dist/chunks/3XXBLNEX.js +1 -0
  341. package/build/dist/chunks/{6IM6A5VA.js → 43LI5NKJ.js} +1 -1
  342. package/build/dist/chunks/{YZSTP2E6.js → 45BRW2ZF.js} +1 -1
  343. package/build/dist/chunks/46547QT3.js +1 -0
  344. package/build/dist/chunks/{C3TJLARP.js → 46KWRAYK.js} +1 -1
  345. package/build/dist/chunks/{SOYQOE5P.js → 4BVP652W.js} +1 -1
  346. package/build/dist/chunks/4HG6FRVH.js +1 -0
  347. package/build/dist/chunks/4MXM6Q4W.js +1 -0
  348. package/build/dist/chunks/{NWSPC3NH.js → 4PY3UFNR.js} +1 -1
  349. package/build/dist/chunks/52ELWNXJ.js +2 -0
  350. package/build/dist/chunks/{O5IVZHHP.js → 553UE2ZQ.js} +1 -1
  351. package/build/dist/chunks/{FUXT7GRK.js → 57MEFFCU.js} +1 -1
  352. package/build/dist/chunks/{XWEFKXKA.js → 5APS4T2D.js} +1 -1
  353. package/build/dist/chunks/{3RFSGU2Y.js → 5CAAFU7R.js} +1 -1
  354. package/build/dist/chunks/{6AWTAE4Q.js → 5SMVQCAP.js} +1 -1
  355. package/build/dist/chunks/63YRSLDK.js +1 -0
  356. package/build/dist/chunks/{53N7PNJH.js → 64GOINYS.js} +1 -1
  357. package/build/dist/chunks/66F5ZH34.js +1 -0
  358. package/build/dist/chunks/{6ZYLNB2B.js → 6B3VVISQ.js} +1 -1
  359. package/build/dist/chunks/6D5DJA5B.js +1 -0
  360. package/build/dist/chunks/{DZGEQBO7.js → 6I4NTKB2.js} +1 -1
  361. package/build/dist/chunks/{DCTUYDWF.js → 6OGDTEGH.js} +1 -1
  362. package/build/dist/chunks/6PBGEPUK.js +20 -0
  363. package/build/dist/chunks/{E7R3J4H7.js → 6WD4HHID.js} +1 -1
  364. package/build/dist/chunks/{RAKUK5VR.js → 6WZX7C4T.js} +1 -1
  365. package/build/dist/chunks/{MKQVS3IO.js → 74Y2KDNR.js} +1 -1
  366. package/build/dist/chunks/{AMICUXS6.js → 7WSHW7KW.js} +1 -1
  367. package/build/dist/chunks/A3PN3PK3.js +1 -0
  368. package/build/dist/chunks/{CXLEQCP3.js → ABPL3ZZI.js} +1 -1
  369. package/build/dist/chunks/{YQUKU2LS.js → AFBEZXNV.js} +1 -1
  370. package/build/dist/chunks/AKYF5264.js +7 -0
  371. package/build/dist/chunks/{ASDKY5NX.js → APGLZXIW.js} +1 -1
  372. package/build/dist/chunks/{UNZRE3YU.js → AVG4W3Y7.js} +1 -1
  373. package/build/dist/chunks/{VFKNXQXI.js → B3RXD5ET.js} +1 -1
  374. package/build/dist/chunks/{V5LTA42G.js → BBS3ODWZ.js} +1 -1
  375. package/build/dist/chunks/{U3F6DDML.js → BJ2VGRF4.js} +1 -1
  376. package/build/dist/chunks/{VFSRRDLY.js → BTD5SMOW.js} +1 -1
  377. package/build/dist/chunks/{PTAWEHKB.js → BTPXJAUX.js} +1 -1
  378. package/build/dist/chunks/{R53P2K3C.js → C36BFZH6.js} +1 -1
  379. package/build/dist/chunks/{L62M7LOB.js → C5ZZAYXD.js} +1 -1
  380. package/build/dist/chunks/{VVEUJ36E.js → C7AXJHBT.js} +1 -1
  381. package/build/dist/chunks/CBG5HARQ.js +2 -0
  382. package/build/dist/chunks/{ELZNT5Q3.js → CCTXCMH4.js} +1 -1
  383. package/build/dist/chunks/{AJP5LDM2.js → CHXBOXOD.js} +1 -1
  384. package/build/dist/chunks/D3YLXQPW.js +1 -0
  385. package/build/dist/chunks/DFM4T6ZE.js +1 -0
  386. package/build/dist/chunks/{GGUEKSR4.js → DJN3JAWB.js} +1 -1
  387. package/build/dist/chunks/{52DHGSG4.js → DW4V5PUY.js} +1 -1
  388. package/build/dist/chunks/E3RACZUY.js +1 -0
  389. package/build/dist/chunks/{VCLPOU7T.js → E674J2MD.js} +1 -1
  390. package/build/dist/chunks/EE64JSLY.js +1 -0
  391. package/build/dist/chunks/EJ7O75A7.js +1 -0
  392. package/build/dist/chunks/{ZXQMF56D.js → ELSXLZN5.js} +1 -1
  393. package/build/dist/chunks/ER47KGRM.js +1 -0
  394. package/build/dist/chunks/FQ6UZCM6.js +1 -0
  395. package/build/dist/chunks/FWD4L3CJ.js +1 -0
  396. package/build/dist/chunks/GEIFITAQ.js +1 -0
  397. package/build/dist/chunks/{S3HNPTXA.js → GGSAKCND.js} +1 -1
  398. package/build/dist/chunks/GL4NCUMH.js +1 -0
  399. package/build/dist/chunks/GNC6RXLT.js +1 -0
  400. package/build/dist/chunks/{YA5WWDEW.js → GQ5GYUEH.js} +1 -1
  401. package/build/dist/chunks/{TLJPVYRJ.js → GW5IXLKU.js} +1 -1
  402. package/build/dist/chunks/{57HAXNQV.js → GW626GG2.js} +1 -1
  403. package/build/dist/chunks/{CE7D6MUS.js → H2XDMFQQ.js} +1 -1
  404. package/build/dist/chunks/H43RNCX2.js +1 -0
  405. package/build/dist/chunks/HAQPIBYR.js +1 -0
  406. package/build/dist/chunks/HCUHMCBW.js +1 -0
  407. package/build/dist/chunks/HKEMQBFA.js +1 -0
  408. package/build/dist/chunks/{WTSMPDT5.js → HM72DH4V.js} +1 -1
  409. package/build/dist/chunks/HSCQZ66A.js +1 -0
  410. package/build/dist/chunks/{4KQZTPMS.js → I26DMNJG.js} +1 -1
  411. package/build/dist/chunks/{YHPOXAKA.js → IMO3GDA5.js} +1 -1
  412. package/build/dist/chunks/INOZIE55.js +1 -0
  413. package/build/dist/chunks/IOYRL6AY.js +1 -0
  414. package/build/dist/chunks/IX3GZMTM.js +1 -0
  415. package/build/dist/chunks/IY7BXLT4.js +1 -0
  416. package/build/dist/chunks/J2OT4KAH.js +1 -0
  417. package/build/dist/chunks/JKD2B6OX.js +1 -0
  418. package/build/dist/chunks/JUZ5JU6D.js +70 -0
  419. package/build/dist/chunks/{5OEHZJ6X.js → JVLLVNF2.js} +1 -1
  420. package/build/dist/chunks/K3RDPI5J.js +1 -0
  421. package/build/dist/chunks/{WCKMQFGS.js → K4DHHQBI.js} +1 -1
  422. package/build/dist/chunks/KBKK7UNY.js +1 -0
  423. package/build/dist/chunks/KIFSRO5K.js +1 -0
  424. package/build/dist/chunks/KIFZ5ZSK.js +1 -0
  425. package/build/dist/chunks/{4AKIXLXH.js → KPCY5V35.js} +1 -1
  426. package/build/dist/chunks/L4N2RSK2.js +1 -0
  427. package/build/dist/chunks/{2W46IRX6.js → L5BLHY34.js} +1 -1
  428. package/build/dist/chunks/{ZT47KN7A.js → LSXUAHOE.js} +1 -1
  429. package/build/dist/chunks/{NATG6YA6.js → M37654RL.js} +1 -1
  430. package/build/dist/chunks/MJ6WEWMI.js +3 -0
  431. package/build/dist/chunks/{ACN2BFMA.js → MQK6OP7S.js} +1 -1
  432. package/build/dist/chunks/{XV2HQKND.js → MR5L7V6Z.js} +1 -1
  433. package/build/dist/chunks/MRMR4QHA.js +1 -0
  434. package/build/dist/chunks/{TWSTOFN3.js → N4Q6GN65.js} +1 -1
  435. package/build/dist/chunks/{H4S2ZCWK.js → NAZPDRIF.js} +1 -1
  436. package/build/dist/chunks/{FBSUTF3B.js → NDCLTVIU.js} +1 -1
  437. package/build/dist/chunks/NEEZBJBC.js +1 -0
  438. package/build/dist/chunks/{MRWCFTMS.js → NKX3FE34.js} +1 -1
  439. package/build/dist/chunks/{J3GFCBZZ.js → NKZKKCK2.js} +1 -1
  440. package/build/dist/chunks/{73N3TOJL.js → NWNYJ26T.js} +1 -1
  441. package/build/dist/chunks/{LBEMCOND.js → O7HCEPQY.js} +1 -1
  442. package/build/dist/chunks/{F6WBPPBN.js → OJ4WJUPP.js} +1 -1
  443. package/build/dist/chunks/OJPG45AC.js +1 -0
  444. package/build/dist/chunks/{SKQGLGES.js → OKUO3BVM.js} +1 -1
  445. package/build/dist/chunks/OTXSKFUD.js +1 -0
  446. package/build/dist/chunks/{AAGDMH54.js → P3S4BR5G.js} +1 -1
  447. package/build/dist/chunks/P56RZC2M.js +1 -0
  448. package/build/dist/chunks/{EA6IYKIB.js → P5PYFK7L.js} +1 -1
  449. package/build/dist/chunks/{JST5JGAP.js → P7I62KFR.js} +1 -1
  450. package/build/dist/chunks/{5IIR3GIN.js → PK66GCDT.js} +1 -1
  451. package/build/dist/chunks/PSBQWDYI.js +1 -0
  452. package/build/dist/chunks/{WQ6H62DM.js → PV5FDT6O.js} +1 -1
  453. package/build/dist/chunks/{TQL7UDFL.js → PXT5YTWU.js} +1 -1
  454. package/build/dist/chunks/Q42YI3EP.js +1 -0
  455. package/build/dist/chunks/{SQ5BNSXR.js → QA3UHEO3.js} +1 -1
  456. package/build/dist/chunks/QC3HH5UD.js +3 -0
  457. package/build/dist/chunks/{TWCSCRFS.js → QF52OIBS.js} +1 -1
  458. package/build/dist/chunks/{LQUDJCAR.js → QO3KCJMP.js} +1 -1
  459. package/build/dist/chunks/QQECG3WP.js +1 -0
  460. package/build/dist/chunks/QSHCBASA.js +1 -0
  461. package/build/dist/chunks/QU5XKRGK.js +1 -0
  462. package/build/dist/chunks/{TPDOUL4N.js → QZZ4O34L.js} +1 -1
  463. package/build/dist/chunks/RQ4GHJXE.js +1 -0
  464. package/build/dist/chunks/{ALK6NKFP.js → RUC7KH7A.js} +1 -1
  465. package/build/dist/chunks/RUX3RY7Y.js +1 -0
  466. package/build/dist/chunks/{GIV5JMTE.js → RVDUSNWW.js} +1 -1
  467. package/build/dist/chunks/S47VUTHM.js +1 -0
  468. package/build/dist/chunks/{2LM7U4S7.js → S7IFAQPG.js} +1 -1
  469. package/build/dist/chunks/{XQUPZ3GU.js → SIYUNOLI.js} +1 -1
  470. package/build/dist/chunks/{7XLEYOZH.js → SJJR4ZBZ.js} +1 -1
  471. package/build/dist/chunks/SK2VBNAU.js +1 -0
  472. package/build/dist/chunks/SMYWWIE6.js +1 -0
  473. package/build/dist/chunks/SPJCSEKP.js +1 -0
  474. package/build/dist/chunks/{L3ZM77SJ.js → SSHCD6RZ.js} +1 -1
  475. package/build/dist/chunks/{3NDVXEBR.js → T2WHOZXM.js} +1 -1
  476. package/build/dist/chunks/T3AJSQYT.js +1 -0
  477. package/build/dist/chunks/TAEZTP4L.js +1 -0
  478. package/build/dist/chunks/TEJ7W534.js +1 -0
  479. package/build/dist/chunks/TFDPEAVZ.js +1 -0
  480. package/build/dist/chunks/TM2XCRU7.js +1 -0
  481. package/build/dist/chunks/{XQXLFF7Y.js → TMVO2DAK.js} +1 -1
  482. package/build/dist/chunks/{2UU5TBBB.js → TVWMTMEF.js} +1 -1
  483. package/build/dist/chunks/{AFHHRDPJ.js → TX2EOIRS.js} +1 -1
  484. package/build/dist/chunks/{QRDDKA4I.js → U4JGEMKT.js} +1 -1
  485. package/build/dist/chunks/{PARWLWXW.js → U5PMVP56.js} +1 -1
  486. package/build/dist/chunks/U67J4BCH.js +1 -0
  487. package/build/dist/chunks/{SSTROLQM.js → UHTRW2R6.js} +1 -1
  488. package/build/dist/chunks/{XUYHMOHS.js → UHVSINR5.js} +1 -1
  489. package/build/dist/chunks/{NRBIXV7V.js → UMIZMJWW.js} +1 -1
  490. package/build/dist/chunks/{VXLJRRKV.js → UNJJRQIU.js} +1 -1
  491. package/build/dist/chunks/V74F6IDY.js +1 -0
  492. package/build/dist/chunks/VEQBHI6O.js +1 -0
  493. package/build/dist/chunks/VHV6WQ5F.js +1 -0
  494. package/build/dist/chunks/{DRWWPBOQ.js → VJS4DHQQ.js} +1 -1
  495. package/build/dist/chunks/{R7FXNZRM.js → VOMGT5SG.js} +1 -1
  496. package/build/dist/chunks/{QXNPPCOU.js → VY7XRHZQ.js} +1 -1
  497. package/build/dist/chunks/{TCPPYBGQ.js → VYAJXLND.js} +1 -1
  498. package/build/dist/chunks/{WWFOYZT2.js → VYN2NRAP.js} +1 -1
  499. package/build/dist/chunks/{OVK4EEOD.js → VYYSL557.js} +1 -1
  500. package/build/dist/chunks/W2BYU5JQ.js +2 -0
  501. package/build/dist/chunks/W6BS3T7S.js +1 -0
  502. package/build/dist/chunks/WCNHZYQQ.js +1 -0
  503. package/build/dist/chunks/{BX7XQANB.js → WDK6VOG4.js} +1 -1
  504. package/build/dist/chunks/{QYYFRAWY.js → WIRBCS4W.js} +1 -1
  505. package/build/dist/chunks/{3WBDHUV2.js → WLMWWEP7.js} +1 -1
  506. package/build/dist/chunks/{TNSKEHPC.js → WP6RHXGN.js} +1 -1
  507. package/build/dist/chunks/WTXC3XKW.js +1 -0
  508. package/build/dist/chunks/{R7QPJQP6.js → WU7XIAXB.js} +1 -1
  509. package/build/dist/chunks/{OQVZVR2S.js → WV3A3OUU.js} +1 -1
  510. package/build/dist/chunks/{GCWA4Z3W.js → X2KFXCVD.js} +1 -1
  511. package/build/dist/chunks/X3BYCOWS.js +1 -0
  512. package/build/dist/chunks/{L7YBCMZU.js → X3PQMS4N.js} +1 -1
  513. package/build/dist/chunks/{WVXW6VL3.js → XBE3B6Y2.js} +1 -1
  514. package/build/dist/chunks/XLOYBLFI.js +1 -0
  515. package/build/dist/chunks/XR7VK24E.js +1 -0
  516. package/build/dist/chunks/XSD5NL7J.js +1 -0
  517. package/build/dist/chunks/{NU4K3TEZ.js → XSRIJUFU.js} +1 -1
  518. package/build/dist/chunks/{WQQJ7UPJ.js → Y25EXZCO.js} +1 -1
  519. package/build/dist/chunks/{2FSX7MMR.js → YCZPSMZ5.js} +1 -1
  520. package/build/dist/chunks/YDNTY67T.js +1 -0
  521. package/build/dist/chunks/YN56C7PN.js +1 -0
  522. package/build/dist/chunks/YWRDZQI6.js +1 -0
  523. package/build/dist/chunks/{SJPM5ST4.js → YXTSWRV5.js} +1 -1
  524. package/build/dist/chunks/Z43BTOTE.js +1 -0
  525. package/build/dist/chunks/{PWBL4WKB.js → Z4FZVJ5Z.js} +1 -1
  526. package/build/dist/chunks/ZMFRMWHR.js +1 -0
  527. package/build/dist/chunks/{KSZMMNXK.js → ZQAFFWDK.js} +1 -1
  528. package/build/dist/chunks/{LMVB3B6T.js → ZSN4IRI5.js} +1 -1
  529. package/build/dist/chunks/{CQCVFRQ5.js → ZV5HIQXC.js} +1 -1
  530. package/package.json +2 -2
  531. package/build/dist/chunks/2MSQ6JII.js +0 -1
  532. package/build/dist/chunks/3SC5UI35.js +0 -1
  533. package/build/dist/chunks/4GHVIBL5.js +0 -1
  534. package/build/dist/chunks/4X2JOQ2L.js +0 -1
  535. package/build/dist/chunks/5VHH5PW3.js +0 -1
  536. package/build/dist/chunks/5YS5V2LK.js +0 -1
  537. package/build/dist/chunks/6UPPUHCL.js +0 -1
  538. package/build/dist/chunks/7YU6DELJ.js +0 -1
  539. package/build/dist/chunks/AXYOJBX6.js +0 -1
  540. package/build/dist/chunks/CEIPDEXZ.js +0 -1
  541. package/build/dist/chunks/CUNQ5RG5.js +0 -1
  542. package/build/dist/chunks/EG6M6SSO.js +0 -1
  543. package/build/dist/chunks/EGUMOD3A.js +0 -1
  544. package/build/dist/chunks/EXRKBBX2.js +0 -1
  545. package/build/dist/chunks/G3MHDTGT.js +0 -1
  546. package/build/dist/chunks/G6HCV67X.js +0 -1
  547. package/build/dist/chunks/GJY3P6OG.js +0 -1
  548. package/build/dist/chunks/HIMVOTIU.js +0 -1
  549. package/build/dist/chunks/IBXYIN7Q.js +0 -1
  550. package/build/dist/chunks/IUE6RASI.js +0 -1
  551. package/build/dist/chunks/JPOYTTTW.js +0 -1
  552. package/build/dist/chunks/JWCOXLYA.js +0 -1
  553. package/build/dist/chunks/KHJFXJBU.js +0 -1
  554. package/build/dist/chunks/LLM5WDM3.js +0 -1
  555. package/build/dist/chunks/LQGPMOD2.js +0 -1
  556. package/build/dist/chunks/MYBDO5SA.js +0 -1
  557. package/build/dist/chunks/NAYRD43N.js +0 -1
  558. package/build/dist/chunks/NMYGNJIJ.js +0 -1
  559. package/build/dist/chunks/NSOEDRBU.js +0 -3
  560. package/build/dist/chunks/PZHR4ITH.js +0 -1
  561. package/build/dist/chunks/R7SXC74O.js +0 -1
  562. package/build/dist/chunks/RETS2ZEK.js +0 -1
  563. package/build/dist/chunks/SJPYXNOK.js +0 -1
  564. package/build/dist/chunks/SQZRVIVF.js +0 -1
  565. package/build/dist/chunks/SXAIXD56.js +0 -1
  566. package/build/dist/chunks/SXX3VTBP.js +0 -1
  567. package/build/dist/chunks/TMGWXDCZ.js +0 -1
  568. package/build/dist/chunks/TNLHMDWL.js +0 -1
  569. package/build/dist/chunks/UFS2RVEZ.js +0 -1
  570. package/build/dist/chunks/USSOVTD5.js +0 -1
  571. package/build/dist/chunks/UWOFA6GV.js +0 -1
  572. package/build/dist/chunks/V2OOOV6B.js +0 -1
  573. package/build/dist/chunks/XVFLT275.js +0 -1
  574. package/build/dist/chunks/YHB55C5T.js +0 -1
  575. package/build/dist/chunks/YOENHHKI.js +0 -1
  576. package/build/dist/chunks/Z7RL4NGX.js +0 -1
@@ -0,0 +1 @@
1
+ import{a as w}from"./Z25UKUJF.js";import{b as v,c as A}from"./43LI5NKJ.js";import{h as S,j as x}from"./66F5ZH34.js";import{c as M,d as g}from"./IX3GZMTM.js";import{a as i,e as h}from"./XSD5NL7J.js";function N(o){return{...o,unsignedTx:v,approval:A,parseAmount:M,formatAmount:g,plainError:h}}function y(o,s,t){let a=new Set(s);if(!Array.isArray(o))throw new i("A module must provide a tools array.");for(let e of o){if(!e||typeof e.name!="string"||!/^[a-z][a-z0-9_]*$/.test(e.name)||t&&(!e.name.startsWith(`${t}_`)||e.name.length<=t.length+1))throw new i("A tool must have a valid name with its module prefix.");if(a.has(e.name))throw new i(`Tool ${e.name} is already registered.`);if(!e.inputSchema||typeof e.inputSchema!="object"||Array.isArray(e.inputSchema)||e.inputSchema.type!=="object"||typeof e.execute!="function")throw new i(`Tool ${e.name} must provide an object input schema and an execute function.`);a.add(e.name)}}var $=new WeakSet;function T(o){if($.has(o))return;let s=o.inputSchema,t=o.execute;o.inputSchema=S(s),o.execute=async(a,e)=>{try{return await t(x(s,a),e)}catch(n){if(n instanceof i&&/^(Unsupported|Unexpected)\b.* argument\.$/.test(n.message)){let u=Object.keys(s.properties??{});throw new i(`${n.message} Accepted fields for ${o.name}: ${u.join(", ")||"(none)"}.`)}throw n}},$.add(o)}function P(o,s,t){if(typeof o!="string"||!/^[a-z][a-z0-9]*$/.test(o))throw new i("Provide a valid module name.");let a=[],e=[];for(let n of s){if(!n||!Array.isArray(n.tools))throw new i(`Module ${o} has an invalid part.`);if(a.push(...n.tools),n.positions!==void 0){if(typeof n.positions!="function")throw new i(`Module ${o} has an invalid positions reader.`);e.push(n.positions.bind(n))}}if(y(a,new Set,o),t&&(typeof t.name!="string"||!t.name||typeof t.quote!="function"||typeof t.build!="function"))throw new i(`Module ${o} has an invalid swap provider.`);return{name:o,tools:a,...e.length?{positions:async(n,u)=>(await Promise.all(e.map(d=>d(n,u)))).flat()}:{},...t?{swapProvider:t}:{}}}function O(o,s,t=[]){y(t,new Set);let a=[...t],e=[],n=[],u=new Set,d=new Set(t.map(p=>p.name));for(let[p,b]of s.entries())try{let l=b(o),r=P(l.name,[l],l.swapProvider);if(u.has(r.name))throw new i(`Module ${r.name} is already registered.`);y(r.tools,d,r.name);for(let c of r.tools){T(c);let f=c.execute;c.execute=async(m,j)=>w(await f(m,j))}if(r.positions){let c=r.positions;r.positions=async(f,m)=>w(await c(f,m))}a.push(...r.tools),e.push(r),u.add(r.name),r.tools.forEach(c=>d.add(c.name))}catch(l){n.push({index:p,error:h(l)})}return{tools:a,modules:e,errors:n}}export{N as a,P as b,O as c};
@@ -1,4 +1,4 @@
1
- import{a as ae}from"./3CCBUYUM.js";import{a as bt,d as wt,e as ht}from"./AJP5LDM2.js";import{a as Ne}from"./7MR37STI.js";import{a as We,b as Be,d as pt}from"./AMICUXS6.js";import{b as ut,c as mt,d as ft}from"./JPOYTTTW.js";import{d as ct,e as te}from"./5O5ZE3ZV.js";import{a as dt}from"./CY75R4FK.js";import{b as lt}from"./AXYOJBX6.js";import{a as q}from"./6IM6A5VA.js";import{a as A,d as z}from"./UWOFA6GV.js";import{d as De,g as E,i as Ue}from"./73N3TOJL.js";import{a as Me}from"./RETS2ZEK.js";import{j as it}from"./CXLEQCP3.js";import{a as p,i as V}from"./G6HCV67X.js";import{a as i,d as se}from"./5YS5V2LK.js";import{a as ze}from"./JXOEJPJ4.js";import{encodeFunctionData as me,erc20Abi as Ha,getAddress as Kt,parseAbi as st,zeroAddress as qa}from"viem";import{decodeAbiParameters as aa,encodeFunctionData as oa,getAddress as ie,parseAbiParameters as ra,zeroAddress as fe,zeroHash as It}from"viem";import{decodeAbiParameters as Xt,encodeFunctionData as Yt,erc20Abi as Jt,getAddress as St,parseAbi as Zt,parseAbiParameters as ea,zeroHash as kt}from"viem";var Ke=St("0xCE29862924756584BBD0D75CA1249d22007E2813"),At="(address loanToken,address collateralToken,address oracle,address irm,uint256 lltv)",ta="(uint256 value,uint256 nonce,uint256 deadline,uint8 v,bytes32 r,bytes32 s)",yt=Zt(["function BLUE() view returns (address)",`function vaultExitBundlesV1InKindRedemptionVaultV2(address vault,address adapter,${At}[] marketParamsList,uint256 exitAssets,${ta} sharesPermit,uint256 deadline)`]);function N(e,t=!1){if(typeof e!="string"||!/^\d{1,78}$/.test(e)||BigInt(e)>=1n<<256n||!t&&BigInt(e)===0n)throw new i("Provide a positive uint256 decimal base-unit string.");return BigInt(e)}var gt=(e,t)=>e<t?e:t;async function Za(e,t,s,r,n){q(n);let l=N(r.amount),a=N(r.maxShares),o=N(r.maxPenaltyAssets,!0),u=N(r.deadline),d=e.clientFor(p),m=await pt(d,t,s),c=(S,B,Te,ee=[])=>d.readContract({address:S,abi:B,functionName:Te,args:ee,blockNumber:m.blockNumber}),[f,b,w,h]=await Promise.all([d.getBlock({blockNumber:m.blockNumber}),c(Ke,yt,"BLUE"),c(t,Jt,"balanceOf",[n]),c(t,We,"previewRedeem",[a])]);if(typeof b!="string"||St(b)!==U)throw new i("VaultExitBundlesV1 does not report the pinned Morpho Blue.");if(u<f.timestamp||u>f.timestamp+300n)throw new i("Use an absolute Unix deadline within the next five minutes.");if(a>Be(w))throw new i("maxShares exceeds the wallet share balance.");let y=gt(m.idle,l),k=m.markets.filter(S=>S.supplied>0n&&W(S.id)),g=l-y,T=k[0]?.penalty??0n,I=g*10n**18n/(10n**18n+T);if(g>0n&&I===0n)throw new i("The penalty-adjusted in-kind amount rounds to zero.");let M=[];for(let S of k){if(I===0n)break;let B=gt(S.supplied,I);M.push({marketId:S.id,assets:B,penalty:(B*S.penalty+10n**18n-1n)/10n**18n}),I-=B}if(I>0n)throw new i("The supported adapter positions cannot cover the requested in-kind exit. Reduce the amount; unverified market positions are not transferred.");if(l+BigInt(M.length)>Be(h))throw new i("maxShares cannot cover the exit and per-market rounding buffer.");if(M.some(S=>S.assets>m.blueCash))throw new i("Morpho Blue cannot fund the largest in-kind callback. Reduce the amount.");let C=M.reduce((S,B)=>S+B.penalty,0n);if(C>o)throw new i("In-kind penalty exceeds maxPenaltyAssets.");let v=[...y?[y]:[],...M.flatMap(S=>[S.assets,S.penalty].filter(B=>B>0n))],G=(await Promise.all(v.map(S=>c(t,We,"previewWithdraw",[S])))).reduce((S,B)=>S+Be(B),0n);if(G===0n||G>a)throw new i("Separately rounded burns exceed maxShares.");let Z=M.map(S=>Xt(ea(At),m.markets.find(B=>B.id===S.marketId).data)[0]),H=m.markets[0]?.adapter;if(!H)throw new i("In-kind exit requires a verified market adapter.");let F=`In-kind exit from ${t}: spend at most ${G} share base units; receive ${y} ${s.symbol} base units and Morpho Blue supply positions ${M.map(S=>`${S.marketId}: ${S.assets} ${s.symbol} base units`).join(", ")||"none"}. Penalty ${C} ${s.symbol} base units. Deadline ${u} (Unix seconds). Supply positions remain exposed to borrower default and can only be withdrawn when market liquidity returns. This is not a cash exit. The exact share allowance bounds drift; accrual can require a fresh preview.`,P=Yt({abi:yt,functionName:"vaultExitBundlesV1InKindRedemptionVaultV2",args:[t,H,Z,l,{value:0n,nonce:0n,deadline:0n,v:0,r:kt,s:kt},u]}),D=[e.approval(t,Ke,G.toString(),p),e.unsignedTx({to:Ke,data:P,value:"0",chainId:p,description:F})],$=await e.preview(D,n),j=-$.changes.filter(S=>S.token.chainId===p&&E(S.token.address,t)).reduce((S,B)=>{if(B.token.decimals!==18||!/^-?\d+$/.test(B.amount))throw new i("Invalid in-kind share preview.");return S+BigInt(B.amount)},0n);if(j<=0n||j>G)throw new i("In-kind preview exceeds the exact share authorization or burns no shares.");return{txs:D,preview:$,summary:F,receipt:{idleAssets:y.toString(),positions:M.map(S=>({marketId:S.marketId,asset:s,assets:S.assets.toString()})),penaltyAssets:C.toString()}}}var pe=ie("0x53A1eB6589861F686af7c531211E35Aefe30210f"),xt=["supply","withdraw","supplyCollateralAndBorrow","repayAndWithdrawCollateral","migrateBorrowPosition"],Qe={kind:0,data:"0x"},Oe={nonce:0n,deadline:0n,signature:{v:0,r:It,s:It}},na=ra("(address loanToken,address collateralToken,address oracle,address irm,uint256 lltv)"),Tt=e=>({tools:[{name:"morpho_bundle",inputSchema:{type:"object",additionalProperties:!1,required:["operation","marketId","deadline"],properties:{operation:{type:"string",enum:xt},marketId:{type:"string"},destinationMarketId:{type:"string"},assets:A(),collateralAssets:A(),shares:A(),maxRepayAssets:A(),maxLtv:A(),deadline:A(),allocations:{type:"array",maxItems:4,items:{type:"object",additionalProperties:!1,required:["vault","assets","maxPenaltyAssets"],properties:{vault:{type:"string"},sourceMarketId:{type:"string"},assets:A(),maxPenaltyAssets:A()}}}}},execute:async(t,s)=>{try{q(s);let r=t.operation,n=e.clientFor(p);if(await n.getChainId()!==p||typeof r!="string"||!xt.includes(r))throw new i("Choose a supported Blue bundle on chain 4663.");let l=["operation","marketId","deadline",...r==="supply"?["assets"]:r==="withdraw"?["assets","shares","allocations"]:r==="supplyCollateralAndBorrow"?["collateralAssets","assets","maxLtv","allocations"]:r==="repayAndWithdrawCollateral"?["assets","shares","maxRepayAssets","collateralAssets","maxLtv"]:["destinationMarketId","maxLtv","allocations"]];if(Object.keys(t).some(P=>!l.includes(P)))throw new i("Unexpected argument for this Blue bundle.");let a=await n.getBlock(),o=N(t.deadline);if(o<a.timestamp||o>a.timestamp+300n)throw new i("Use an absolute Unix deadline within the next five minutes.");let[u,d]=await Promise.all([n.readContract({address:pe,abi:Ne,functionName:"BLUE",blockNumber:a.number}),n.readContract({address:pe,abi:Ne,functionName:"PUBLIC_ALLOCATOR",blockNumber:a.number})]);if(ie(u)!==U||ie(d)!==bt)throw new i("BlueBundlesV1 deployment does not match Oak\u2019s pinned Blue and Public Allocator.");let m=async P=>{if(typeof P!="string"||!W(P))throw new i("Choose a verified Morpho market with a supported exit.");let D=await n.readContract({address:U,abi:O,functionName:"idToMarketParams",args:[P],blockNumber:a.number}),$={loanToken:ie(D[0]),collateralToken:ie(D[1]),oracle:ie(D[2]),irm:ie(D[3]),lltv:D[4]};if(!E(be({...$,lltv:String($.lltv)}),P))throw new i("Blue bundle market identity mismatch.");return $},c=await m(t.marketId),f=r==="migrateBorrowPosition"?await m(t.destinationMarketId):c;if(c.loanToken!==f.loanToken||c.collateralToken!==f.collateralToken)throw new i("Migration requires the same loan and collateral tokens.");if(r==="migrateBorrowPosition"&&t.marketId===t.destinationMarketId)throw new i("Choose a different destination market.");if(r!=="supply"&&!await n.readContract({address:U,abi:O,functionName:"isAuthorized",args:[s,pe],blockNumber:a.number}))throw new i(`Authorize the pinned Blue bundle explicitly with morpho_manage setAuthorization account ${pe}, enabled true, then retry. That authority covers all Blue positions. Revoke it with enabled false after the bundle.`);let b=t.assets===void 0?0n:N(t.assets,!0),w=t.shares===void 0?0n:N(t.shares,!0),h=t.collateralAssets===void 0?0n:N(t.collateralAssets,!0),y=r==="supply"||r==="withdraw"?0n:N(t.maxLtv,!0);if(y>f.lltv)throw new i("maxLtv cannot exceed the verified destination market LLTV.");if(r==="supply"&&b===0n||r==="withdraw"&&b===0n==(w===0n)||r==="supplyCollateralAndBorrow"&&h===0n&&b===0n||r==="repayAndWithdrawCollateral"&&(b>0n&&w>0n||b===0n&&w===0n&&h===0n))throw new i("Choose a nonzero amount; assets and shares are mutually exclusive for repayment/withdrawal.");let k=t.allocations??[];if(!Array.isArray(k)||k.length>4||k.length&&r==="supplyCollateralAndBorrow"&&b===0n)throw new i("Provide at most four explicit allocations, only with a borrow or withdrawal.");let g=new Set,T=[],I=0n;for(let P of k){if(!P||typeof P!="object"||Array.isArray(P)||Object.keys(P).some(Ve=>!["vault","sourceMarketId","assets","maxPenaltyAssets"].includes(Ve)))throw new i("Unsupported bundled allocation input.");let D=P,$=await wt(e,{vault:D.vault,marketId:r==="migrateBorrowPosition"?t.destinationMarketId:t.marketId});if(g.has($.definition.vault.toLowerCase()))throw new i("Use each source vault at most once per bundle.");g.add($.definition.vault.toLowerCase());let j=N(D.assets),S=N(D.maxPenaltyAssets,!0);if(!$.permission||j>=1n<<128n||j>$.headroom||$.penalty>10n**18n||$.asset.address!==f.loanToken)throw new i("Bundled allocation is disabled, unqualified or exceeds target capacity.");let B=(j*$.penalty+10n**18n-1n)/10n**18n;if(B>S)throw new i("Bundled allocation exceeds maxPenaltyAssets.");I+=B;let Te=D.sourceMarketId===void 0,ee=Te?void 0:$.sources.find(Ve=>E(Ve.id,String(D.sourceMarketId)));if(Te?!$.canIdle||j>$.data.idle:!ee||!ee.canPull||j>ee.capacity||j>$.data.blueCash)throw new i("Bundled allocation source cannot cover the requested amount.");T.push({vault:$.definition.vault,adapter:$.target.adapter,marketParams:$.params,sourceAdapter:ee?.adapter??fe,sourceMarketParams:ee?aa(na,ee.data)[0]:$.params,assets:j,penalty:$.penalty,fromIdle:Te})}let M,C,v,x=0n;if(r==="supply")M="blueBundlesV1Supply",v=c.loanToken,x=b,C=[c,b,Qe,0n,fe,o];else if(r==="withdraw")M="blueBundlesV1Withdraw",C=[c,b,w,Oe,T,0n,fe,o];else if(r==="supplyCollateralAndBorrow"){if(M="blueBundlesV1SupplyCollateralAndBorrow",v=c.collateralToken,x=h,I>=b&&I>0n)throw new i("Allocation penalties would consume the borrow proceeds.");C=[c,h,b,y,Qe,Oe,T,0n,fe,o]}else if(r==="repayAndWithdrawCollateral"){if(M="blueBundlesV1RepayAndWithdrawCollateral",v=c.loanToken,x=N(t.maxRepayAssets,!0),b>x||w>0n&&x===0n)throw new i("Repayment requires a sufficient maxRepayAssets budget.");C=[c,b,w,x,h,y,Qe,Oe,0n,fe,o]}else M="blueBundlesV1MigrateBorrowPosition",C=[c,f,y,Oe,T,0n,fe,o];let G=`Morpho Blue atomic ${r}: ${JSON.stringify(t)}. Allocation penalties ${I} loan-token base units; zero referral fee. Max LTV ${y}; absolute deadline ${o}. Migration adds allocation penalties to destination debt; borrowing deducts them from proceeds. Exact input approval ${x}. Existing Blue bundle authorization remains until explicitly revoked with morpho_manage. No opaque callback, permit or signature is accepted.`,Z=[...v&&x?[e.approval(v,pe,x.toString(),p)]:[],e.unsignedTx({to:pe,data:oa({abi:Ne,functionName:M,args:C}),value:"0",chainId:p,description:G})],H=await e.preview(Z,s),F=new Map;for(let P of H.changes)if(BigInt(P.amount)<0n){let D=P.token.address.toLowerCase();F.set(D,(F.get(D)??0n)-BigInt(P.amount))}if([...F].some(([P,D])=>!v||P!==v.toLowerCase()||D>x))throw new i("Bundle preview spends outside the exact input budget.");return{txs:Z,preview:H,summary:G}}catch(r){throw new i(e.plainError(r))}}}]});import{concatHex as Mt,decodeAbiParameters as sa,encodeAbiParameters as $t,encodeFunctionData as Xe,erc20Abi as Pt,getAddress as K,keccak256 as Je,zeroAddress as we,zeroHash as ia}from"viem";var Y=K("0x6120765Ba5336150BbdDdD0Cd9108B5bFD369632"),la=["0x90B800999e4ACd1bD20283BD450bBd2e06D91F7C","0x708d6Bf6F847202a0755bb5636bE663B174242ea"].map(e=>K(e)),Ze=ae.find(e=>e.name==="take"),vt=[Ze.inputs[0]],da=[Ze.inputs[0].components[0]];function Ct(e){let t=Je(Mt(["0x600b380380600b5f395ff3",$t(da,[e])]));return Je(Mt(["0xff",e.midnight,ia,t]))}var le=10n**18n,Lt=(e,t)=>(e+(t-1n)/2n)/t;function Dt(e){if(e<0n)return 10n**36n/Dt(-e);let t=693147180559945309n,s=(e+322611214989459870n)/t,r=e-s*t,n=r*r/(2n*le),l=n*r/(3n*le);return le+r+n+l<<s}function ca(e){if(e<0n||e>6744n)throw new i("Midnight tick is outside 0..6744.");return Lt(Lt(10n**36n,le+Dt(4987541511039073n*(3372n-e))),10n**11n)*10n**11n}function Ge(e,t){if(typeof e!="string"||!/^0x([0-9a-f]{2})*$/i.test(e)||e.length>32770||t!==void 0&&e.length!==2+t*2)throw new i("Provide bounded canonical hex data.");return e}function Ye(e,t){if(!Array.isArray(e)||e.length!==t)throw new i("Invalid Midnight state tuple.");return e.map(s=>{if(typeof s=="number"&&Number.isSafeInteger(s)&&s>=0)return BigInt(s);if(typeof s=="bigint"&&s>=0n)return s;throw new i("Invalid Midnight integer state.")})}var ua=e=>JSON.parse(JSON.stringify(e,(t,s)=>typeof s=="bigint"?s.toString():s)),Ut=e=>{async function t(n,l){let a=Ge(n,32),o=e.clientFor(p);if(await o.getChainId()!==p)throw new i("Midnight requires chain 4663.");let u=await o.getBlock(),d=(k,g=[])=>o.readContract({address:Y,abi:ae,functionName:k,args:g,blockNumber:u.number}),m=await d("toMarket",[a]);if(m.chainId!==BigInt(p)||K(m.midnight)!==Y||!E(Ct(m),a))throw new i("Midnight market identity does not match the pinned chain and contract.");if(![V[p].tokens.USDG.address,V[p].tokens.WETH.address].some(k=>E(k,m.loanToken)))throw new i("This Midnight loan token needs a qualified transfer and exit fixture.");if(!m.collateralParams.length||m.collateralParams.length>128)throw new i("Invalid Midnight collateral inventory.");let[f,b,w,h]=await Promise.all([d("position",[a,l]),d("updatePositionView",[m,a,l]),d("marketState",[a]),d("isHealthy",[m,a,l])]),y=async k=>{let[g,T]=await Promise.all([o.readContract({address:k,abi:Pt,functionName:"decimals",blockNumber:u.number}),o.readContract({address:k,abi:Pt,functionName:"symbol",blockNumber:u.number})]);if(!Number.isInteger(g)||g>36||typeof T!="string")throw new i("Invalid Midnight token metadata.");return{address:K(k),decimals:g,symbol:T.replace(/[^a-zA-Z0-9.$_-]/g,"").slice(0,32),chainId:p}};return{id:a,rpc:o,block:u,market:m,read:d,token:y,loan:await y(m.loanToken),position:Ye(f,6),updated:Ye(b,3),state:Ye(w,13),healthy:h}}let s=(n,l,a,o)=>({name:n,inputSchema:{type:"object",properties:l,required:a,additionalProperties:!1},execute:async(u,d)=>{try{if(q(d),Object.keys(u).some(m=>!Object.hasOwn(l,m)))throw new i("Unsupported Midnight argument.");return await o(u,d)}catch(m){throw new i(e.plainError(m))}}});async function r(n,l,a){return{txs:n,preview:await e.preview(n,l),summary:a}}return{tools:[s("morpho_midnight_status",{marketId:{type:"string"}},["marketId"],async(n,l)=>{let a=await t(n.marketId,l),o=await Promise.all(a.market.collateralParams.map(async(m,c)=>({token:await a.token(m.token),lltvWad:m.lltv.toString(),oracle:m.oracle,assets:String(await a.read("collateral",[a.id,l,BigInt(c)]))}))),u=["configurator","feeSetter","feeClaimer","tickSpacingSetter"],d=await Promise.all(u.map(m=>a.read(m)));return{protocol:Object.fromEntries(u.map((m,c)=>[m,K(String(d[c]))])),continuousFeePerSecondWad:String(a.state[11]),tickSpacing:String(a.state[12]),settlementFeeCbps:a.state.slice(4,11).map(String),settlementFeeCbpWadScale:"1000000000000",chainId:p,midnight:Y,marketId:a.id,blockNumber:String(a.block.number),market:ua(a.market),loanToken:a.loan,collaterals:o,debtUnits:String(a.position[4]),creditUnits:String(a.updated[0]),pendingFeeUnits:String(a.updated[1]),withdrawableUnits:String(a.state[2]),healthy:a.healthy,maturity:String(a.market.maturity),matured:a.block.timestamp>a.market.maturity,warning:"Maturity does not guarantee lender liquidity. Borrowers become liquidatable after maturity even when collateralized. Lender credit may absorb borrower default losses."}}),s("morpho_midnight_take",{offer:{type:"string",description:"ABI-encoded Offer struct, never transaction calldata."},ratifierData:{type:"string"},units:A(),maxAssets:A(),minAssets:A()},["offer","ratifierData","units","maxAssets","minAssets"],async(n,l)=>{let a=Ge(n.offer),[o]=sa(vt,a);if(!E($t(vt,[o]),a))throw new i("Offer encoding is not canonical.");let u=await t(Ct(o.market),l),d=N(n.units),m=N(n.maxAssets,!0),c=N(n.minAssets,!0),f=Ge(n.ratifierData);if(d>=1n<<128n||E(o.maker,l)||o.callback!==we||o.callbackData!=="0x"||!la.includes(K(o.ratifier)))throw new i("Use a non-self offer with a pinned ratifier and no maker callbacks. Callback routes need a separate qualified builder.");if(u.block.timestamp<o.start||u.block.timestamp>o.expiry||o.expiry<o.start)throw new i("The Midnight offer is not currently live.");if(o.buy&&o.receiverIfMakerIsSeller!==we||!o.buy&&o.receiverIfMakerIsSeller===we)throw new i("Invalid offer seller receiver.");if(o.buy&&u.block.timestamp>u.market.maturity&&d>u.updated[0])throw new i("Post-maturity sales cannot increase this wallet\u2019s debt.");let b=await u.read("settlementFee",[u.id,u.market.maturity>u.block.timestamp?u.market.maturity-u.block.timestamp:0n]),w=ca(o.tick);if(b>w&&o.buy)throw new i("Settlement fee exceeds the offer price.");let h=o.buy?w-b:w,y=h+b,k=P=>o.buy?P/le:(P+le-1n)/le,g=k(d*y),T=k(d*h);if(o.buy?T<c||T===0n:g>m||g===0n)throw new i("Midnight proceeds/spend do not fit the requested bounds.");let I=await u.read("consumed",[o.maker,o.group]);if(o.maxAssets===0n==(o.maxUnits===0n)||I+(o.maxAssets?o.buy?g:T:d)>(o.maxAssets||o.maxUnits))throw new i("Midnight offer capacity is exhausted or invalid.");if(u.state[11]>o.continuousFeeCap||o.tick%u.state[12]!==0n)throw new i("Offer fee cap or market tick spacing no longer permits execution.");let M=await u.read("isAuthorized",[o.maker,o.ratifier]),C=[{type:"function",name:"isRatified",stateMutability:"view",inputs:[Ze.inputs[0],{type:"bytes"},{type:"address"}],outputs:[{type:"bytes32"}]}],v=await u.rpc.readContract({address:o.ratifier,abi:C,functionName:"isRatified",args:[o,f,l],blockNumber:u.block.number});if(M!==!0||v!==Je(new TextEncoder().encode("morpho.midnight.callbackSuccess")))throw new i("The maker has not authorized and ratified this exact offer.");let x=Xe({abi:ae,functionName:"take",args:[o,f,d,l,o.buy?l:we,we,"0x"]}),G=`Midnight ${o.buy?"sell credit or borrow":"buy credit or reduce debt"}: ${d} fixed debt units; ${o.buy?`receive ${T}`:`spend ${g}`} ${u.loan.symbol} base units (token ${u.loan.address}, decimals ${u.loan.decimals}). Maturity ${u.market.maturity} Unix seconds; offer expiry ${o.expiry}. A borrower can lose collateral after maturity; lender withdrawal depends on repayments and bears default losses. No lender signature or callback is created. Bounds are rechecked locally; the take calldata fixes the offer and units. Exact buyer approval caps wallet spending.`,Z=[...o.buy?[]:[e.approval(u.loan.address,Y,g.toString(),p)],e.unsignedTx({to:Y,data:x,value:"0",chainId:p,description:G})],H=await r(Z,l,G),F=H.preview.changes.filter(P=>P.token.chainId===p&&E(P.token.address,u.loan.address)).reduce((P,D)=>P+BigInt(D.amount),0n);if(o.buy?F<T:F!==-g)throw new i("Midnight preview does not match the exact quoted cash flow.");return H}),s("morpho_midnight_action",{marketId:{type:"string"},operation:{enum:["supplyCollateral","withdrawCollateral","repay","withdraw","updatePosition","claimContinuousFee"]},amount:A(),collateralIndex:{type:"integer",minimum:0,maximum:127}},["marketId","operation"],async(n,l)=>{let a=await t(n.marketId,l),o=n.operation;if(!["supplyCollateral","withdrawCollateral","repay","withdraw","updatePosition","claimContinuousFee"].includes(String(o)))throw new i("Choose a finite Midnight position operation.");let u,d,m=a.loan,c=0n;if(o==="updatePosition"){if(n.amount!==void 0||n.collateralIndex!==void 0)throw new i("Position update takes no amount or collateral index.");u=[a.market,l]}else if(o==="claimContinuousFee"){if(c=N(n.amount),n.collateralIndex!==void 0||K(String(await a.read("feeClaimer")))!==K(l))throw new i("This wallet lacks the Midnight fee claimer role or supplied an unused collateral index.");u=[a.market,c,l]}else{if(c=N(n.amount),c>=1n<<128n)throw new i("Midnight position amount exceeds uint128.");if(o==="supplyCollateral"||o==="withdrawCollateral"){if(!Number.isInteger(n.collateralIndex)||Number(n.collateralIndex)<0||Number(n.collateralIndex)>=a.market.collateralParams.length)throw new i("Choose a current collateral index.");let w=BigInt(String(n.collateralIndex)),h=await a.token(a.market.collateralParams[Number(w)].token);if(m=h,o==="withdrawCollateral"&&c>await a.read("collateral",[a.id,l,w]))throw new i("Insufficient Midnight collateral.");u=o==="supplyCollateral"?[a.market,w,c,l]:[a.market,w,c,l,l],o==="supplyCollateral"&&(d=h)}else{if(n.collateralIndex!==void 0)throw new i("This operation takes no collateral index.");if(o==="repay"&&c>a.position[4]||o==="withdraw"&&(c>a.updated[0]||c>a.state[2]))throw new i("Amount exceeds current debt, credit or available repayment liquidity.");u=o==="repay"?[a.market,c,l,we,"0x"]:[a.market,c,l,l],o==="repay"&&(d=a.loan)}}let f=`Midnight ${o}: ${c} ${m.symbol} base units (token ${m.address}, decimals ${m.decimals}) on ${a.id}; beneficiary ${l}; maturity ${a.market.maturity} Unix seconds. No callbacks or delegation. Withdrawal can fail if collateral health or lender liquidity changes.`,b=[...d?[e.approval(d.address,Y,c.toString(),p)]:[],e.unsignedTx({to:Y,data:Xe({abi:ae,functionName:String(o),args:u}),value:"0",chainId:p,description:f})];return r(b,l,f)}),s("morpho_midnight_manage",{operation:{type:"string",enum:["setConsumed","setIsAuthorized","setConfigurator","setFeeSetter","setFeeClaimer","setTickSpacingSetter","enableLltv","enableLiquidationCursor","setMarketTickSpacing","setMarketSettlementFee","setMarketContinuousFee","setDefaultSettlementFee","setDefaultContinuousFee","claimSettlementFee"]},values:{type:"array",maxItems:3,items:{oneOf:[{type:"string"},{type:"boolean"}]}}},["operation","values"],async(n,l)=>{let a={setConfigurator:"configurator",setFeeSetter:"configurator",setFeeClaimer:"configurator",setTickSpacingSetter:"configurator",enableLltv:"configurator",enableLiquidationCursor:"configurator",setMarketTickSpacing:"tickSpacingSetter",setMarketSettlementFee:"feeSetter",setMarketContinuousFee:"feeSetter",setDefaultSettlementFee:"feeSetter",setDefaultContinuousFee:"feeSetter",claimSettlementFee:"feeClaimer"};if(typeof n.operation!="string"||!["setConsumed","setIsAuthorized",...Object.keys(a)].includes(n.operation)||!Array.isArray(n.values))throw new i("Choose a finite Midnight management operation and ordered values.");let o=n.operation,u=ae.find(f=>f.name===o);if(n.values.length!==u.inputs.length)throw new i("Provide the exact ordered operation values.");let d=e.clientFor(p);if(await d.getChainId()!==p)throw new i("Midnight requires chain 4663.");let m=u.inputs.map((f,b)=>{let w=n.values[b];if(f.type==="bool"){if(typeof w!="boolean")throw new i("Use boolean management values.");return w}if(f.type==="address")return Ue(w,"Use explicit management addresses.",De);if(f.type==="bytes32")return Ge(w,32);if(/^uint/.test(f.type)){let h=N(w,!0);if(h>=1n<<BigInt(f.type.slice(4)))throw new i("Management integer exceeds its ABI width.");return h}throw new i("Unsupported management argument type.")});if(o==="setConsumed"||o==="setIsAuthorized"){if(!E(String(m[2]),l))throw new i("Midnight management is bound to this wallet.")}else{let f=await d.readContract({address:Y,abi:ae,functionName:a[o]});if(typeof f!="string"||K(f)!==K(l))throw new i("This wallet lacks the Midnight configuration, fee or tick role.")}let c=`Midnight ${o}, ordered values ${JSON.stringify(n.values)}. ${o==="setIsAuthorized"&&m[1]?"This grants authority over all Midnight positions, cancellations and further delegation, without an amount cap. Revoke with false when done.":""}${o==="setConsumed"?"Consumption only increases; setting uint128 maximum permanently cancels this offer group.":""}`;return r([e.unsignedTx({to:Y,data:Xe({abi:ae,functionName:o,args:m}),value:"0",chainId:p,description:c})],l,c)})]}};import{decodeAbiParameters as oe,encodeAbiParameters as ma,encodeFunctionData as R,erc20Abi as et,getAddress as L,isAddress as Re,keccak256 as fa,parseAbi as Ee,parseAbiParameters as J}from"viem";var Pe="morpho",pa="https://api.morpho.org/graphql",U=L(V[p].morpho.morpho_blue.address),ba=L(V[p].morpho.adaptive_curve_irm.address),wa=L(V[p].morpho.USDG.address),de=L(V[p].morpho.WETH.address),ha=["0x7c820d6a09502d63be80bb8025ec479d29d7c06e70f8df65a92aaeed23a366e2","0x1fa5293f9f60059a7f6a4923022156fcdcc038bd3749be55897000c03afe92d8"],ka={"oak-recorded":"Oak recorded chain observations (block 100362239).","morpho-listed":"Morpho API (POST https://api.morpho.org/graphql, markets where chainId_in [4663]) returned listed: true, fetched 2026-10-31 UTC.",longbow:"Longbow market list: Longbow MCP list_markets/get_market (https://mcp.longbow.credit/mcp, named on https://longbow.cash/mcp) and the live market list on https://longbow.cash/earn, fetched 2026-10-31 UTC; each ID re-read on chain.",netnet:"NetNet Credit: six stock-token market IDs printed at https://docs.netnet.capital/credit, plus the Loopback wsNET/USDG market returned by NetNet's Turbo router marketId() and Credit adapter marketIds(6); fetched 2026-10-31 UTC."},tt=[{marketId:"0x7c820d6a09502d63be80bb8025ec479d29d7c06e70f8df65a92aaeed23a366e2",label:"WETH/USDG 77%",source:"oak-recorded"},{marketId:"0x1fa5293f9f60059a7f6a4923022156fcdcc038bd3749be55897000c03afe92d8",label:"USDG/WETH",source:"oak-recorded"},{marketId:"0x0309c02dabf0be02682af1a2bde9a457f4df0f0b6bc889cde3f948e5315e4114",label:"spUSDG/USDG 91.5%",source:"morpho-listed"},{marketId:"0x10151e2ac82a820153520d9d77d56de1c84775e23b79bdc11e2e34282d9afa10",label:"SPCX/USDG 62.5%",source:"morpho-listed"},{marketId:"0x127353ba63e08f74d8e9ce8a1c2b41b5f89c7167135b1c09fbed34a71b4cb06b",label:"WETH/USDG 86%",source:"morpho-listed"},{marketId:"0x1a31d1c8c05a98b94777663912e4166bf50f3fcdc9c3c3d29deb55634ac58239",label:"PONS/USDG 62.5%",source:"morpho-listed"},{marketId:"0x1efd13a2d1dc66a2466e7c25820537028e604791f00454d9c686fdfbf70f404d",label:"mGLO/USDG 91.5%",source:"morpho-listed"},{marketId:"0x21ea2a012b888120e328775c2a7bf6fb4619cf4c4c631ad1c9b6db51f8882d5a",label:"SPCX/USDG 62.5%",source:"morpho-listed"},{marketId:"0x22e4598e5cc16cff0056e72d61c5f1f2f8bf5bbffc22da5277ab196939c8a59e",label:"TSLA/USDG 62.5%",source:"morpho-listed"},{marketId:"0x66306c087add8907752320b309934abcc354d21626de8115c79df49d9c214edc",label:"NVDA/USDG 62.5%",source:"morpho-listed"},{marketId:"0x69400cfe81f2ae381b9a9f27076a4d637338379d999e9ffdfbde52f0876312ee",label:"META/USDG 62.5%",source:"morpho-listed"},{marketId:"0x7408b08b03e05ffd2d21c797489a0e77a28e4bb36acb4e827c69e805d06272b4",label:"GOOGL/USDG 77%",source:"morpho-listed"},{marketId:"0x7c1e38bf461da47df9805ae9b7e97a12ec023625a1f92d2a403b3b9a92260894",label:"CASHCAT/USDG 62.5%",source:"morpho-listed"},{marketId:"0x919a9b6b94dae7c86620eaf7a08e597aae8a4c3a9e9c7671771fbaf62b6b61c7",label:"syrupUSDG/USDG 91.5%",source:"morpho-listed"},{marketId:"0x93ed7865910b09f5a2e0dbfd4670c2d3bc1da9647f7c68e7975f37f497898cdb",label:"mGLO/USDG 91.5%",source:"morpho-listed"},{marketId:"0x947ae981cc823024ea00b602f6ea72d049cac05d66ef096198ceeb998651c175",label:"AAPL/USDG 62.5%",source:"morpho-listed"},{marketId:"0x95312f02c1dae8407b2c80468a5657a9bd19c45ac277f1a61aa52c11444c5314",label:"NVDA/USDG 62.5%",source:"morpho-listed"},{marketId:"0xba01f6625137b692c5dd86afb8e654b4016d7b64e36dfca4124e84bef98bc4d2",label:"GOOGL/USDG 62.5%",source:"morpho-listed"},{marketId:"0xc845da65a020ddca5f132efa8fea79676d8edfdea504226a4c01e7a9e34cddd6",label:"USDe/USDG 91.5%",source:"morpho-listed"},{marketId:"0xcaa167af7ba0422c76424fae56167b7db25bf19f4f435215e6dd7d06a943bdac",label:"AAPL/USDG 62.5%",source:"morpho-listed"},{marketId:"0xe29c7d3790037800101ecbad9c45de2067698d206cbcab7c25069a9f43c9eb98",label:"TSLA/USDG 62.5%",source:"morpho-listed"},{marketId:"0xe5a6d99c3721ef2ab00fb16f0ad226bc7c87a90394f82e27dc6bbca4b1d95c5d",label:"AI/USDG 62.5%",source:"morpho-listed"},{marketId:"0xeb1739b2a69dd22a4285d366a06698a01018b37c24d2994fefe19cc72f313613",label:"SPY/USDG 77%",source:"morpho-listed"},{marketId:"0xf5ff7d546af5e72f3912d2aa723088fd0bf66fddc158714995637714d9db6e4c",label:"NVDA/USDG 62.5%",source:"morpho-listed"},{marketId:"0xaa586d26a6fe62d9c0f0948fede6e2130500ac7a655587447e2d4a37e6330589",label:"wsNET/USDG 62.5% (NetNet Loopback)",source:"netnet"},{marketId:"0x8b16891f032a93b771347c9cb470a780e6699dd701553d3402aa3cdba6189c3e",label:"NVDA/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x9b4b47cdf7e295341c6c6cdfd3efb9805c4a5b3d580dba0c0c39d3a4232b297b",label:"SPCX/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0xdeb4782d012d5fd3b24962538c2f6559049d70bda4dabd2e4212dacb96c28d45",label:"AAPL/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x7fa81b10e5d21b2e4c571f862442bc11aff2ed14f02335868d0ff933fd40d0ba",label:"GOOGL/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x2e1859aa8f143b7220088f80562c6dfe0bf8e52b87d9cedf8da8805f231994ce",label:"MSFT/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x3ebd43d91c3960a9fac32bedd5c60428e0e414de5bdd67fda770207afb0eb615",label:"COIN/USDG 38.5% (NetNet Credit)",source:"netnet"},{marketId:"0x26f3bd5919ba0e6ea6f4bca1b8bd95ce29cbe3aad4ef824fb007570eac35103b",label:"cbBTC/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xb095654f06f4d17d4fc010c2d89a107649e3c5b58e53a3812d1736c95e63e3f8",label:"NVDAon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x947c05e7c0fa3ba187d57db710d04ba8be4fef53baba0cfbe71ce61b34a1367d",label:"SPCXon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf8f0b5badf06192908bc47af32b93742d9b4fb6072d388cb183ff7849ee6534c",label:"SPYon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x26c80a00f8facc6b081989965d89cedc274b90b81be660e69245a74e5384f5de",label:"METAon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xeefec6c3e5cb7df1f2366ea7cf96a583081205b9720e807d2868d9866a702229",label:"GOOGLon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf511a080dcb4d0a3b9d6aebb06e24afa011cda87f9f71ada70c60f8220e94f35",label:"AAPLon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xa87da1cc931faa945a41861cc9c90076772ceeae9a663836df6b265c4f30106d",label:"MSTRon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x0279ea145eff84ed2ffd3b1ed1f2aca333060d9cef6fdd48bd21073c13ec86bf",label:"CRCLon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xff2063ef18bc5f71867c56d6d3290b61f3da1d010c8a0552bdb7995cfad8cacc",label:"TSLAon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x83d542605940b5495ef38d4b62a39293766a486a24e5c67930f41acd919cf1d1",label:"QQQon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x9b01d5ad5ce8e477510854132cc47853f6e82a708c9c4723887550412f4ee522",label:"GMEon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x8b2af4d69ad861a4099b995b6279aeaf6a905225a0ee889bce424c7faf19b7d9",label:"AMZN/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x4edbd2f2f3b33bc5f80ab588def67fab8c10945fc99f855d80ff4bef2c4aa1f0",label:"SLV/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x7e6ebfdc58a893a5cddba0fba0483baf4fac2efece627ad50821dbe27d6f9738",label:"GOOGL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x30a2a5f1a098b23ed91eadc4529a8d1c967f2cdc2e40a709f3a5992004b01ac0",label:"AAPL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x14973a168cf6c6b1148309f5d567c255b292863ffe9cca59f4284e1426636f00",label:"RKLB/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf049167e6bf18a1b41b8e2acefcf7bc9b13ea013d8d65c7fbc7cbaeb3fe9b4e2",label:"NBIS/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x8114b65dfc5e64222103e5588de261eca9defd25f47ea4ae2f91d49fe4fa2993",label:"CLSK/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x96d3d5f9bc842e4c8a935c5628abd02fb0e10115560c35a9add768781434f471",label:"CRWV/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x1b3555f7c1273688f01ae82da7dc8e508e6a7841ec0038dbb15767154a277b86",label:"EWY/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x039503b6308d6d818d181e626d3fbc667d6e68393c3d74332a6124cd2dd6e755",label:"CASHCAT_LEGACY/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x597227ca652ea5e8afb6e4801ecd766a4d6eb9b3b9fafa9127ba88a8b1f19629",label:"SPCX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x50bc39b5722fb5634c436d74c6787f3c125b879e7b73cf9e9ecc01bbb57b8e55",label:"SPY/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x315b99abb698487891243a84afd28a5ff56fe02143f203c03edd3f103936bf60",label:"QQQ/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x4979137c23c8fb519cd507adc290944c3c2120e8a3191547531fced28360e9c2",label:"GME/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x6b8a1f62d88d1cd1e8de609aef07cafc8226172ba703e57c52c3730350e61df1",label:"USO/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xafc86936af4f7edf083eb2550b8c42311b83c685982742b9271b309a58268855",label:"MSFT/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf6f3dbe0a19e948147e79e66502c6b05709d8dfde977fec7db1528fc8f0ebdfa",label:"SGOV/USDG 86% (Longbow)",source:"longbow"},{marketId:"0x2ab6a14c9f68d4216dcb3b4e6ed607cf82f2e6badfa2bd5618d7f69d012d7fab",label:"USAR/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xb41b34c5989420ad080e79363a9cfe3e23bec7459fcd2d88029250da370288df",label:"TSLA/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x4d2075836fd32183b10e5be1b383f6430de859df6d2bd5ec5b859970c4dd14e8",label:"AMD/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x9df4f54a2e46b35bd326cec97dbabc4203fa6c64a8e4182128f277adba8fefaf",label:"MU/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xb5ba72c0d55c353fa37c0bea104eb117afb2f4934473bcb736d2218ae5686746",label:"PLTR/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xda5584635e8b14ea18f674dbe4243365505910fefd8e3aa1ac9bfaac0eba74e8",label:"INTC/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x74fece475178af9e06d31fb64f405046a305f8f0abc588782f596d6f261c1fbb",label:"SNDK/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xee04847a312224d551d2267bb5c2c2695777af5fd1f05347bdcca397e8f54336",label:"ORCL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x508b47fb12dbb8747644d4436aae65489b5f2819936adefc8a591323f64a5b01",label:"COIN/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x243ac165f79a75a0590d2e994ffa9e260b70292fd1ca134ace95f3640895b19f",label:"TSM/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x01baec96478004fc7b74c8dfe38abef8d716fea59ffd481b6ec74db915d3bc80",label:"MSTR/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf0959f62e748938cf260ca6fe7cb21a412e0a6643913460f4a6770c3f4b90af6",label:"CRCL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xbe881499e682850931951c998e76cfbf38c7979b1beeae7cbbb97a39b3336a07",label:"ASML/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xdd578ca54b4ef6a7827c6e9fc06905699a577f6e2f00712853d8aab13383bc38",label:"BABA/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xd8b502d5c43f6e5cfff7f938c7ef18e684f114fb5b362611981144397e5d5aef",label:"DELL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x003390b057d753bd839981a0d45f9a567aa0b0ed6373fd42e951eac8ee86c2ba",label:"RGTI/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xc6e16cff2bcf185639562ab937b7a1c381522768ff16aefc85a25ff6ab1c45ea",label:"AI/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xaba3ac501ce4c6b80c08ed0dba19e1ac0de495f17af3ed692a38e92d176a6c9e",label:"PONS/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x8097c1d1000eb657e75265384137041ac92856c8dc0b72c99569c3681320a430",label:"DELTA/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x6e6762ae397a2b3f2500ea2f48f8adce0eadfbf54cbc37f6108602e907e844ad",label:"INDEX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x378713071c58206c6a826287d0051bcae113d83d6e3d3b6370b7e73128d06162",label:"STONKBROKER/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x2695be2638c98241c887e4cad4eeba0f01137205f46b9e302edab04b5fee0570",label:"AVGO/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x6c12c02536aa27831f713d658b59f74e149cc62b48528cb74455e79fab32f772",label:"GLD/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x298e8ff9b31f22be90507bc61b55e66ab93e78b55a60593035e309ed93137cb8",label:"RDDT/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xb33399a677e1a21152fa9969f02c57a7a342e692ec45608a3fa0d3d92519c343",label:"COST/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x3be7fe1b6b439cfeb737d9921e9b83c92095a23a4f50aeee0d6d04f44446170f",label:"DJT/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x0066bc47b87597993af0bca6f526175c0abae011b764d4bf12a3def45e1f4e78",label:"NFLX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x8c170f5c5df593791640ac9fbac297d59d08c2e92e86f38fe52d38e929e60fa3",label:"AMC/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x0f18d4fd8d86bd4d100b867b67e1fd38c80981fcd43e442313c2d5408da9352d",label:"LLY/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x7d4313cf1b0ede39395a2c7495dc1b1b47370caf51f70571d927f22e715e5f58",label:"LULU/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xa85928d77bd25cc348e13ea6587b8b3ca3793f4af5e5db8ca07d0f20fd5cfa99",label:"IBM/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x9d61e320efb766ce5c375032b399f08afe644b095a9cb0b2d6d1f6ab68399a6f",label:"F/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x43c51f6ff44ab406ab9c97cb5512c881f4a7498209f94bbcfd874d8f97fad79d",label:"HIMS/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xe6284cf12d0603aee18ff5ab412e262cf99f120e967579111d7a51f37f276f54",label:"TTWO/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xe8d9b45cdbedc4401a3145be7726c9f72b715e03c5399c961439f11636ee9fb6",label:"MRNA/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x46eea143d473cdb8587505f8886dad452037f285f7729a7763e8c233c63b2e8e",label:"RIVN/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x8338aed363a309039b2f271a83558831e7e445f2d13c6e72c576ec0b8a969415",label:"RBLX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x4e92b336ecad6c842be20ae2ae27b28b3cf5ced6c5388a808167c03a8d75fdf8",label:"SPY/WETH 38.5% (Longbow)",source:"longbow"},{marketId:"0x141c2b1d2bbecf7f8a76563307d7e5bf586457e873c3d97c4bb1502e57b77952",label:"NVDA/WETH 38.5% (Longbow)",source:"longbow"}],ya=new Map(tt.map(e=>[e.marketId.toLowerCase(),e]));function W(e){return ya.get(e.toLowerCase())}function ot(e){let t=W(e);return t?{actions:"enabled",label:t.label,source:ka[t.source]}:{actions:"read-only",reason:"Not in Oak's verified Morpho market registry; Oak builds no transactions for it."}}var Bt=20,ve=120n,_e=1000000n,He=1n,he=10n**18n,ga=10n**36n,Et=(1n<<128n)-1n,Sa=(1n<<256n)-1n,X=Ee(["function idToMarketParams(bytes32 id) view returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv)","function market(bytes32 id) view returns (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee)","function position(bytes32 id, address user) view returns (uint256 supplyShares, uint128 borrowShares, uint128 collateral)","function supplyCollateral((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, address onBehalf, bytes data)","function withdrawCollateral((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, address onBehalf, address receiver)","function borrow((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver) returns (uint256 assetsBorrowed, uint256 sharesBorrowed)","function repay((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) returns (uint256 assetsRepaid, uint256 sharesRepaid)","function supply((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) returns (uint256 assetsSupplied, uint256 sharesSupplied)","function withdraw((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver) returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn)"]),Aa=Ee(["function price() view returns (uint256)"]),Ia=Ee(["function borrowRateView((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee) market) view returns (uint256)"]),_t=Ee(["function deposit() payable"]);function ce(e){return{loanToken:e.loanToken,collateralToken:e.collateralToken,oracle:e.oracle,irm:e.irm,lltv:e.lltv.toString()}}function Ce(e,t){return e===0n?0n:(e+t-1n)/t}function xa(e,t,s){return e*(s+_e)/(t+He)}function Ta(e,t,s){return Ce(e*(s+_e),t+He)}function rt(e,t,s){return e*(t+He)/(s+_e)}function ne(e,t,s){return Ce(e*(t+He),s+_e)}function ke(e,t,s){return e*t/ga*s/he}function Ma(e,t,s){return t.startsWith("-")?`-${e.formatAmount(t.slice(1),s)}`:e.formatAmount(t,s)}function ye(e,t){let s=[],r={};for(let n of t.changes){let l=Ma(e,n.amount,n.token.decimals);s.push({token:n.token,amount:n.amount,formattedAmount:l}),r[n.token.address.toLowerCase()]=l}return{formattedChanges:s,formattedNetOutflows:r}}function Ht(e){if(typeof e!="string"||!/^0x[0-9a-fA-F]{64}$/.test(e))throw new i("Morpho marketId must be a 32-byte hex string.");return e.toLowerCase()}function qe(e){if(!e||typeof e!="object")throw new i("Morpho marketParams must be an object.");for(let a of[e.loanToken,e.collateralToken,e.oracle,e.irm])if(typeof a!="string"||!Re(a,{strict:!1}))throw new i("Morpho marketParams contains an invalid address.");let t=L(e.loanToken),s=L(e.collateralToken),r=L(e.oracle),n=L(e.irm),l=typeof e.lltv=="bigint"?e.lltv:Me(String(e.lltv));if(t===te||s===te||r===te)throw new i("Morpho marketParams loan, collateral, and oracle addresses must be non-zero.");if(l<=0n||l>=he)throw new i("Morpho marketParams LLTV must be between 0 and 1e18.");return{loanToken:t,collateralToken:s,oracle:r,irm:n,lltv:l}}function be(e){let t=qe(e),s=ma(J("address, address, address, address, uint256"),[t.loanToken,t.collateralToken,t.oracle,t.irm,t.lltv]);return fa(s)}function at(e){let t=e.toLowerCase();return t===dt.toLowerCase()||t===ct.toLowerCase()||t===te.toLowerCase()}function ge(e,t){let s=t??e.wallet;if(!s)throw new i("Provide a valid wallet address.");return q(s),L(s)}async function re(e,t,s){if(typeof e.call=="function"){let r=await e.call({to:t,data:s});if(r&&typeof r.data=="string")return r.data}if(typeof e.request=="function"){let r=await e.request({method:"eth_call",params:[{to:t,data:s},"latest"]});if(typeof r=="string")return r}throw new i(`Unable to execute eth_call on contract ${t}.`)}function qt(e){return typeof e=="string"&&/^[A-Za-z0-9$._+-]{1,32}$/.test(e)?e:"UNKNOWN"}async function Q(e,t,s=p){if(q(t),at(t))return{...ut,chainId:s};let r=L(t),n=r.toLowerCase();if(s===p){if(n===wa.toLowerCase())return mt;if(n===de.toLowerCase())return ft}let[l,a]=await Promise.all([re(e,r,R({abi:et,functionName:"symbol"})),re(e,r,R({abi:et,functionName:"decimals"}))]),[o]=oe(J("string"),l),[u]=oe(J("uint8"),a);return{address:r,symbol:qt(o),decimals:Number(u),chainId:s}}async function Ft(e,t){let s=await re(e,U,R({abi:X,functionName:"idToMarketParams",args:[t]})),[r,n,l,a,o]=oe(J("address, address, address, address, uint256"),s);return{loanToken:L(r),collateralToken:L(n),oracle:L(l),irm:L(a),lltv:o}}async function jt(e,t){let s=await re(e,U,R({abi:X,functionName:"market",args:[t]})),[r,n,l,a,o,u]=oe(J("uint128, uint128, uint128, uint128, uint128, uint128"),s);return{totalSupplyAssets:r,totalSupplyShares:n,totalBorrowAssets:l,totalBorrowShares:a,lastUpdate:o,fee:u}}async function Se(e,t,s){let r=await re(e,U,R({abi:X,functionName:"position",args:[t,L(s)]})),[n,l,a]=oe(J("uint256, uint128, uint128"),r);return{supplyShares:n,borrowShares:l,collateral:a}}async function Fe(e,t){let s=await re(e,L(t),R({abi:Aa,functionName:"price"})),[r]=oe(J("uint256"),s);return r}async function Pa(e,t,s){if(t.irm===te)return 0n;let r=await re(e,L(t.irm),R({abi:Ia,functionName:"borrowRateView",args:[t,s]})),[n]=oe(J("uint256"),r);return n}function je(e,t,s){let r=s>e.lastUpdate?s-e.lastUpdate:0n,n=t*r,l=Ce(n*n,2n*he),a=Ce(l*n,3n*he);return e.totalBorrowAssets+Ce(e.totalBorrowAssets*(n+l+a),he)}async function Le(e,t,s,r=0n){let[n,l]=await Promise.all([e.getBlock({blockTag:"latest"}),Pa(e,t,s)]),a=BigInt(Math.ceil(Date.now()/1e3)),o=(n.timestamp>a?n.timestamp:a)+r;return{totalBorrowAssets:je(s,l,o),accruedThrough:o,rate:l}}async function Vt(e,t,s){let r=await re(e,L(t),R({abi:et,functionName:"balanceOf",args:[L(s)]})),[n]=oe(J("uint256"),r);return n}async function ue(e,t,s=!1){let r=t.marketId,n=t.marketParams;if(!r&&!n)throw new i("Provide either marketId or marketParams for the Morpho Blue market.");let l=n?qe(n):void 0,a=l?be(l):void 0,o=r!==void 0?Ht(r):void 0;if(o&&a&&o!==a.toLowerCase())throw new i(`MarketParams tuple hash (${a}) does not match marketId (${o}).`);let u=(o??a).toLowerCase();if(s&&!W(u))throw new i(`Morpho actions require a known market from Oak's verified registry, which pins its oracle. Find one with morpho_status {"discover":true}; other markets are read-only.`);let[d,m]=await Promise.all([Ft(e,u),jt(e,u)]);if(d.loanToken===te||d.collateralToken===te||d.lltv===0n||m.lastUpdate===0n)throw new i(`Morpho market ${u} is not initialized on chain ${p}.`);let c=be(d);if(c.toLowerCase()!==u.toLowerCase())throw new i(`On-chain idToMarketParams tuple hash (${c}) does not match marketId (${u}).`);if(l&&!(l.loanToken.toLowerCase()===d.loanToken.toLowerCase()&&l.collateralToken.toLowerCase()===d.collateralToken.toLowerCase()&&l.oracle.toLowerCase()===d.oracle.toLowerCase()&&l.irm.toLowerCase()===d.irm.toLowerCase()&&l.lltv===d.lltv))throw new i(`Provided marketParams tuple does not match on-chain idToMarketParams for ${u}.`);return{marketId:u,marketParams:d,marketState:m}}function Ae(e){if(e.assets!==void 0&&e.amount!==void 0)throw new i("Specify either assets or amount, not both.");let t=e.assets??e.amount;if(typeof t!="string")throw new i("Provide an amount as a base-unit integer string.");let s=Me(t);if(s<=0n||s>Et)throw new i("Asset amount must be greater than zero and fit in uint128.");return s}function Ie(e,t){for(let s of["onBehalf","receiver"])if(e[s]!==void 0&&(typeof e[s]!="string"||e[s].toLowerCase()!==t.toLowerCase()))throw new i(`Morpho ${s} must be the wallet; overrides are not supported.`);if(e.data!==void 0&&e.data!=="0x")throw new i("Morpho callback data must be empty (0x).")}async function va(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=e.clientFor(p),{marketId:a,marketParams:o}=await ue(l,t,!0),u=await Q(l,o.collateralToken,p),d=o.collateralToken.toLowerCase()===de.toLowerCase(),m=typeof t.collateralToken=="string"?(q(t.collateralToken),L(t.collateralToken)):void 0,c=z("wrapNative",t.wrapNative)===!0||m!==void 0&&at(m);if(m&&!at(m)&&m.toLowerCase()!==o.collateralToken.toLowerCase())throw new i(`Collateral token ${m} does not match market collateral ${o.collateralToken}.`);if(c&&!d)throw new i("Native ETH wrapping is only supported when market collateralToken is WETH.");let f=Ae(t),b=f.toString(),w=e.formatAmount(b,u.decimals),h=[];c&&h.push(e.unsignedTx({chainId:p,to:de,data:R({abi:_t,functionName:"deposit"}),value:b,description:`Wrap ${w} ETH into WETH at ${de}.`})),h.push(e.approval(o.collateralToken,U,b,p)),h.push(e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"supplyCollateral",args:[o,f,n,"0x"]}),value:"0",description:`Supply ${w} ${u.symbol} (${b} base units) collateral to Morpho market ${a}.`}));let y=await e.preview(h,r),{formattedChanges:k,formattedNetOutflows:g}=ye(e,y);return{action:"morpho_supply_collateral",chainId:p,marketId:a,marketParams:ce(o),collateralToken:u,assets:b,formattedAssets:w,onBehalf:n,txs:h,summary:`${c?`Send ${w} ETH to wrap into WETH. `:""}Supply ${w} ${u.symbol} collateral to Morpho Blue market ${a}.`,preview:y,formattedChanges:k,formattedNetOutflows:g}}async function Ca(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=r,a=e.clientFor(p),{marketId:o,marketParams:u,marketState:d}=await ue(a,t,!0),[m,c,f,b]=await Promise.all([Q(a,u.loanToken,p),Se(a,o,n),Fe(a,u.oracle),Le(a,u,d,ve)]),w=Ae(t),h=w.toString(),y=e.formatAmount(h,m.decimals),k=d.totalSupplyAssets>d.totalBorrowAssets?d.totalSupplyAssets-d.totalBorrowAssets:0n;if(w>k)throw new i(`Insufficient market liquidity: requested ${h} base units, available ${k.toString()} base units.`);let g=ke(c.collateral,f,u.lltv),T=ne(c.borrowShares,b.totalBorrowAssets,d.totalBorrowShares);if(c.collateral===0n||T+w>g)throw new i(`Insufficient collateral or unhealthy borrow: total debt ${(T+w).toString()} exceeds max borrow ${g.toString()} base units.`);let I=Ta(w,b.totalBorrowAssets,d.totalBorrowShares),C=[e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"borrow",args:[u,w,0n,n,l]}),value:"0",description:`Borrow ${y} ${m.symbol} (${h} base units) from Morpho market ${o}.`})],v=await e.preview(C,r),{formattedChanges:x,formattedNetOutflows:G}=ye(e,v);return{action:"morpho_borrow",chainId:p,marketId:o,marketParams:ce(u),loanToken:m,assets:h,formattedAssets:y,borrowShares:I.toString(),onBehalf:n,receiver:l,txs:C,summary:`Borrow ${y} ${m.symbol} from Morpho Blue market ${o}.`,preview:v,formattedChanges:x,formattedNetOutflows:G}}async function La(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=e.clientFor(p);if(t.shares!==void 0){let x=Me(t.shares);if(x<=0n||x===Sa||x>Et)throw new i("Morpho Blue core does not accept maxUint256 or out-of-range share sentinels; pass exact position.borrowShares.")}if(z("repayAll",t.repayAll)===!0&&(t.shares!==void 0||t.assets!==void 0||t.amount!==void 0))throw new i("Specify repayAll alone, without shares or assets/amount.");if(t.shares!==void 0&&(t.assets!==void 0||t.amount!==void 0))throw new i("Specify either assets/amount or shares for Morpho repay, not both.");let{marketId:a,marketParams:o,marketState:u}=await ue(l,t,!0),[d,m,c]=await Promise.all([Q(l,o.loanToken,p),Se(l,a,n),Vt(l,o.loanToken,r)]);if(m.borrowShares===0n)throw new i(`Position has no active borrow debt on Morpho market ${a}.`);let f=0n,b=0n;if(z("repayAll",t.repayAll)===!0)b=m.borrowShares;else if(t.shares!==void 0){let x=Me(t.shares);if(x>m.borrowShares)throw new i(`Repay shares (${x.toString()}) exceed current position borrowShares (${m.borrowShares.toString()}).`);b=x}else f=Ae(t);let w=b>0n?await Le(l,o,u,ve):void 0,h=b>0n?ne(b,w.totalBorrowAssets,u.totalBorrowShares):f;if(c<h)throw new i(`Insufficient loan token balance for repayment: wallet holds ${c.toString()} base units, but ${h.toString()} base units are required (including accrued interest).`);let y=h.toString(),k=e.formatAmount(y,d.decimals),g=e.approval(o.loanToken,U,y,p),T=e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"repay",args:[o,f,b,n,"0x"]}),value:"0",description:b>0n?`Repay ${b.toString()} borrow shares (${k} ${d.symbol}) on Morpho market ${a}.`:`Repay ${k} ${d.symbol} (${f.toString()} base units) on Morpho market ${a}.`}),I=[g,T],M=await e.preview(I,r),{formattedChanges:C,formattedNetOutflows:v}=ye(e,M);return{action:"morpho_repay",chainId:p,marketId:a,marketParams:ce(o),loanToken:d,repayAssets:f.toString(),repayShares:b.toString(),requiredAssets:y,...w?{accruedThrough:w.accruedThrough.toString(),borrowRatePerSecond:w.rate.toString(),inclusionSeconds:ve.toString()}:{},formattedRequiredAssets:k,onBehalf:n,txs:I,summary:b>0n?`Repay ${b.toString()} borrow shares (approval up to ${k} ${d.symbol}) on Morpho Blue market ${a}. Refresh if signing/inclusion takes more than ${ve} seconds.`:`Repay ${k} ${d.symbol} on Morpho Blue market ${a}.`,preview:M,formattedChanges:C,formattedNetOutflows:v}}async function $a(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=r,a=e.clientFor(p),{marketId:o,marketParams:u,marketState:d}=await ue(a,t,!0),[m,c,f,b]=await Promise.all([Q(a,u.collateralToken,p),Se(a,o,n),Fe(a,u.oracle),Le(a,u,d,ve)]),w=z("withdrawAll",t.withdrawAll)===!0?c.collateral:Ae(t);if(w<=0n||w>c.collateral)throw new i(`Insufficient collateral to withdraw: requested ${w.toString()} base units, position holds ${c.collateral.toString()} base units.`);if(c.borrowShares>0n){let C=c.collateral-w,v=ke(C,f,u.lltv),x=ne(c.borrowShares,b.totalBorrowAssets,d.totalBorrowShares);if(x>v)throw new i(`Unhealthy collateral withdrawal: remaining max borrow ${v.toString()} would fall below current debt ${x.toString()} base units.`)}let h=w.toString(),y=e.formatAmount(h,m.decimals),g=[e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"withdrawCollateral",args:[u,w,n,l]}),value:"0",description:`Withdraw ${y} ${m.symbol} (${h} base units) collateral from Morpho market ${o}.`})],T=await e.preview(g,r),{formattedChanges:I,formattedNetOutflows:M}=ye(e,T);return{action:"morpho_withdraw_collateral",chainId:p,marketId:o,marketParams:ce(u),collateralToken:m,assets:h,formattedAssets:y,onBehalf:n,receiver:l,txs:g,summary:`Withdraw ${y} ${m.symbol} collateral from Morpho Blue market ${o}.`,preview:T,formattedChanges:I,formattedNetOutflows:M}}async function Da(e,t,s){let r=ge(t,s);Ie(t,r);let n=e.clientFor(p),{marketId:l,marketParams:a,marketState:o}=await ue(n,t,!0),u=z("wrapNative",t.wrapNative)===!0;if(u&&a.loanToken.toLowerCase()!==de.toLowerCase())throw new i("Native ETH wrapping is only supported when the market loanToken is WETH.");let d=Ae(t),m=d.toString(),[c,f]=await Promise.all([Q(n,a.loanToken,p),u?Promise.resolve(d):Vt(n,a.loanToken,r)]);if(f<d)throw new i(`Insufficient ${c.symbol} balance to lend: wallet holds ${f.toString()} base units, requested ${m}.`);let b=e.formatAmount(m,c.decimals),w=[];u&&w.push(e.unsignedTx({chainId:p,to:de,data:R({abi:_t,functionName:"deposit"}),value:m,description:`Wrap ${b} ETH into WETH at ${de}.`})),w.push(e.approval(a.loanToken,U,m,p)),w.push(e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"supply",args:[a,d,0n,r,"0x"]}),value:"0",description:`Lend ${b} ${c.symbol} (${m} base units) to Morpho market ${l}.`}));let h=xa(d,o.totalSupplyAssets,o.totalSupplyShares),y=await e.preview(w,r),{formattedChanges:k,formattedNetOutflows:g}=ye(e,y);return{action:"morpho_supply",chainId:p,marketId:l,marketParams:ce(a),loanToken:c,assets:m,formattedAssets:b,supplySharesEstimated:h.toString(),onBehalf:r,oak:ot(l),txs:w,summary:`${u?`Send ${b} ETH to wrap into WETH. `:""}Lend ${b} ${c.symbol} to Morpho Blue market ${l}. It earns the market supply rate and is exposed to the market's collateral, oracle and liquidity risk.`,preview:y,formattedChanges:k,formattedNetOutflows:g}}async function Ua(e,t,s){let r=ge(t,s);Ie(t,r);let n=e.clientFor(p),l=z("withdrawAll",t.withdrawAll)===!0;if(l&&(t.assets!==void 0||t.amount!==void 0))throw new i("Specify withdrawAll alone, without assets/amount.");let{marketId:a,marketParams:o,marketState:u}=await ue(n,t,!0),[d,m]=await Promise.all([Q(n,o.loanToken,p),Se(n,a,r)]);if(m.supplyShares===0n)throw new i(`This wallet has no lent ${d.symbol} on Morpho market ${a}.`);let c=rt(m.supplyShares,u.totalSupplyAssets,u.totalSupplyShares),f=l?0n:Ae(t),b=l?m.supplyShares:0n;if(!l&&f>c)throw new i(`Withdrawal exceeds the lent balance: requested ${f.toString()} base units, position holds about ${c.toString()}. Use withdrawAll for a full exit.`);let w=u.totalSupplyAssets>u.totalBorrowAssets?u.totalSupplyAssets-u.totalBorrowAssets:0n,h=l?c:f;if(h>w)throw new i(`Insufficient market liquidity: withdrawing ${h.toString()} base units needs idle assets, but only ${w.toString()} are available until borrowers repay. Withdraw at most that amount, or retry later.`);let y=e.formatAmount(h.toString(),d.decimals),g=[e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"withdraw",args:[o,f,b,r,r]}),value:"0",description:l?`Withdraw all ${m.supplyShares.toString()} supply shares (about ${y} ${d.symbol}) from Morpho market ${a}.`:`Withdraw ${y} ${d.symbol} (${f.toString()} base units) of lent assets from Morpho market ${a}.`})],T=await e.preview(g,r),{formattedChanges:I,formattedNetOutflows:M}=ye(e,T);return{action:"morpho_withdraw",chainId:p,marketId:a,marketParams:ce(o),loanToken:d,withdrawAssets:f.toString(),withdrawShares:b.toString(),estimatedAssets:h.toString(),formattedAssets:y,receiver:r,txs:g,summary:l?`Withdraw all lent ${d.symbol} (about ${y}, including interest) from Morpho Blue market ${a}.`:`Withdraw ${y} lent ${d.symbol} from Morpho Blue market ${a}.`,preview:T,formattedChanges:I,formattedNetOutflows:M}}async function zt(e,t,s){let r=await e.http(pa,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({query:t,variables:s})});if(!r.ok)throw new i(`Morpho GraphQL request failed (HTTP ${r.status}).`);let n=await r.json();if(n.errors?.length)throw new i("Morpho GraphQL returned query errors.");return n.data??{}}async function Wt(e){let t=`query Markets($chainId: Int!) {
1
+ import{a as ae}from"./3CCBUYUM.js";import{a as bt,d as wt,e as ht}from"./CHXBOXOD.js";import{a as Ne}from"./7MR37STI.js";import{a as We,b as Be,d as pt}from"./7WSHW7KW.js";import{b as ut,c as mt,d as ft}from"./P56RZC2M.js";import{d as ct,e as te}from"./3NJ5KQ3Q.js";import{a as dt}from"./3MLUCYCB.js";import{b as lt}from"./SPJCSEKP.js";import{a as q}from"./43LI5NKJ.js";import{a as A,d as z}from"./66F5ZH34.js";import{d as De,g as E,i as Ue}from"./NWNYJ26T.js";import{b as Me}from"./IX3GZMTM.js";import{j as it}from"./ABPL3ZZI.js";import{a as p,i as V}from"./FWD4L3CJ.js";import{a as i,e as se}from"./XSD5NL7J.js";import{a as ze}from"./JXOEJPJ4.js";import{encodeFunctionData as me,erc20Abi as Ha,getAddress as Kt,parseAbi as st,zeroAddress as qa}from"viem";import{decodeAbiParameters as aa,encodeFunctionData as oa,getAddress as ie,parseAbiParameters as ra,zeroAddress as fe,zeroHash as It}from"viem";import{decodeAbiParameters as Xt,encodeFunctionData as Yt,erc20Abi as Jt,getAddress as St,parseAbi as Zt,parseAbiParameters as ea,zeroHash as kt}from"viem";var Ke=St("0xCE29862924756584BBD0D75CA1249d22007E2813"),At="(address loanToken,address collateralToken,address oracle,address irm,uint256 lltv)",ta="(uint256 value,uint256 nonce,uint256 deadline,uint8 v,bytes32 r,bytes32 s)",yt=Zt(["function BLUE() view returns (address)",`function vaultExitBundlesV1InKindRedemptionVaultV2(address vault,address adapter,${At}[] marketParamsList,uint256 exitAssets,${ta} sharesPermit,uint256 deadline)`]);function N(e,t=!1){if(typeof e!="string"||!/^\d{1,78}$/.test(e)||BigInt(e)>=1n<<256n||!t&&BigInt(e)===0n)throw new i("Provide a positive uint256 decimal base-unit string.");return BigInt(e)}var gt=(e,t)=>e<t?e:t;async function Za(e,t,s,r,n){q(n);let l=N(r.amount),a=N(r.maxShares),o=N(r.maxPenaltyAssets,!0),u=N(r.deadline),d=e.clientFor(p),m=await pt(d,t,s),c=(S,B,Te,ee=[])=>d.readContract({address:S,abi:B,functionName:Te,args:ee,blockNumber:m.blockNumber}),[f,b,w,h]=await Promise.all([d.getBlock({blockNumber:m.blockNumber}),c(Ke,yt,"BLUE"),c(t,Jt,"balanceOf",[n]),c(t,We,"previewRedeem",[a])]);if(typeof b!="string"||St(b)!==U)throw new i("VaultExitBundlesV1 does not report the pinned Morpho Blue.");if(u<f.timestamp||u>f.timestamp+300n)throw new i("Use an absolute Unix deadline within the next five minutes.");if(a>Be(w))throw new i("maxShares exceeds the wallet share balance.");let y=gt(m.idle,l),k=m.markets.filter(S=>S.supplied>0n&&W(S.id)),g=l-y,T=k[0]?.penalty??0n,I=g*10n**18n/(10n**18n+T);if(g>0n&&I===0n)throw new i("The penalty-adjusted in-kind amount rounds to zero.");let M=[];for(let S of k){if(I===0n)break;let B=gt(S.supplied,I);M.push({marketId:S.id,assets:B,penalty:(B*S.penalty+10n**18n-1n)/10n**18n}),I-=B}if(I>0n)throw new i("The supported adapter positions cannot cover the requested in-kind exit. Reduce the amount; unverified market positions are not transferred.");if(l+BigInt(M.length)>Be(h))throw new i("maxShares cannot cover the exit and per-market rounding buffer.");if(M.some(S=>S.assets>m.blueCash))throw new i("Morpho Blue cannot fund the largest in-kind callback. Reduce the amount.");let C=M.reduce((S,B)=>S+B.penalty,0n);if(C>o)throw new i("In-kind penalty exceeds maxPenaltyAssets.");let v=[...y?[y]:[],...M.flatMap(S=>[S.assets,S.penalty].filter(B=>B>0n))],G=(await Promise.all(v.map(S=>c(t,We,"previewWithdraw",[S])))).reduce((S,B)=>S+Be(B),0n);if(G===0n||G>a)throw new i("Separately rounded burns exceed maxShares.");let Z=M.map(S=>Xt(ea(At),m.markets.find(B=>B.id===S.marketId).data)[0]),H=m.markets[0]?.adapter;if(!H)throw new i("In-kind exit requires a verified market adapter.");let F=`In-kind exit from ${t}: spend at most ${G} share base units; receive ${y} ${s.symbol} base units and Morpho Blue supply positions ${M.map(S=>`${S.marketId}: ${S.assets} ${s.symbol} base units`).join(", ")||"none"}. Penalty ${C} ${s.symbol} base units. Deadline ${u} (Unix seconds). Supply positions remain exposed to borrower default and can only be withdrawn when market liquidity returns. This is not a cash exit. The exact share allowance bounds drift; accrual can require a fresh preview.`,P=Yt({abi:yt,functionName:"vaultExitBundlesV1InKindRedemptionVaultV2",args:[t,H,Z,l,{value:0n,nonce:0n,deadline:0n,v:0,r:kt,s:kt},u]}),D=[e.approval(t,Ke,G.toString(),p),e.unsignedTx({to:Ke,data:P,value:"0",chainId:p,description:F})],$=await e.preview(D,n),j=-$.changes.filter(S=>S.token.chainId===p&&E(S.token.address,t)).reduce((S,B)=>{if(B.token.decimals!==18||!/^-?\d+$/.test(B.amount))throw new i("Invalid in-kind share preview.");return S+BigInt(B.amount)},0n);if(j<=0n||j>G)throw new i("In-kind preview exceeds the exact share authorization or burns no shares.");return{txs:D,preview:$,summary:F,receipt:{idleAssets:y.toString(),positions:M.map(S=>({marketId:S.marketId,asset:s,assets:S.assets.toString()})),penaltyAssets:C.toString()}}}var pe=ie("0x53A1eB6589861F686af7c531211E35Aefe30210f"),xt=["supply","withdraw","supplyCollateralAndBorrow","repayAndWithdrawCollateral","migrateBorrowPosition"],Qe={kind:0,data:"0x"},Oe={nonce:0n,deadline:0n,signature:{v:0,r:It,s:It}},na=ra("(address loanToken,address collateralToken,address oracle,address irm,uint256 lltv)"),Tt=e=>({tools:[{name:"morpho_bundle",inputSchema:{type:"object",additionalProperties:!1,required:["operation","marketId","deadline"],properties:{operation:{type:"string",enum:xt},marketId:{type:"string"},destinationMarketId:{type:"string"},assets:A(),collateralAssets:A(),shares:A(),maxRepayAssets:A(),maxLtv:A(),deadline:A(),allocations:{type:"array",maxItems:4,items:{type:"object",additionalProperties:!1,required:["vault","assets","maxPenaltyAssets"],properties:{vault:{type:"string"},sourceMarketId:{type:"string"},assets:A(),maxPenaltyAssets:A()}}}}},execute:async(t,s)=>{try{q(s);let r=t.operation,n=e.clientFor(p);if(await n.getChainId()!==p||typeof r!="string"||!xt.includes(r))throw new i("Choose a supported Blue bundle on chain 4663.");let l=["operation","marketId","deadline",...r==="supply"?["assets"]:r==="withdraw"?["assets","shares","allocations"]:r==="supplyCollateralAndBorrow"?["collateralAssets","assets","maxLtv","allocations"]:r==="repayAndWithdrawCollateral"?["assets","shares","maxRepayAssets","collateralAssets","maxLtv"]:["destinationMarketId","maxLtv","allocations"]];if(Object.keys(t).some(P=>!l.includes(P)))throw new i("Unexpected argument for this Blue bundle.");let a=await n.getBlock(),o=N(t.deadline);if(o<a.timestamp||o>a.timestamp+300n)throw new i("Use an absolute Unix deadline within the next five minutes.");let[u,d]=await Promise.all([n.readContract({address:pe,abi:Ne,functionName:"BLUE",blockNumber:a.number}),n.readContract({address:pe,abi:Ne,functionName:"PUBLIC_ALLOCATOR",blockNumber:a.number})]);if(ie(u)!==U||ie(d)!==bt)throw new i("BlueBundlesV1 deployment does not match Oak\u2019s pinned Blue and Public Allocator.");let m=async P=>{if(typeof P!="string"||!W(P))throw new i("Choose a verified Morpho market with a supported exit.");let D=await n.readContract({address:U,abi:O,functionName:"idToMarketParams",args:[P],blockNumber:a.number}),$={loanToken:ie(D[0]),collateralToken:ie(D[1]),oracle:ie(D[2]),irm:ie(D[3]),lltv:D[4]};if(!E(be({...$,lltv:String($.lltv)}),P))throw new i("Blue bundle market identity mismatch.");return $},c=await m(t.marketId),f=r==="migrateBorrowPosition"?await m(t.destinationMarketId):c;if(c.loanToken!==f.loanToken||c.collateralToken!==f.collateralToken)throw new i("Migration requires the same loan and collateral tokens.");if(r==="migrateBorrowPosition"&&t.marketId===t.destinationMarketId)throw new i("Choose a different destination market.");if(r!=="supply"&&!await n.readContract({address:U,abi:O,functionName:"isAuthorized",args:[s,pe],blockNumber:a.number}))throw new i(`Authorize the pinned Blue bundle explicitly with morpho_manage setAuthorization account ${pe}, enabled true, then retry. That authority covers all Blue positions. Revoke it with enabled false after the bundle.`);let b=t.assets===void 0?0n:N(t.assets,!0),w=t.shares===void 0?0n:N(t.shares,!0),h=t.collateralAssets===void 0?0n:N(t.collateralAssets,!0),y=r==="supply"||r==="withdraw"?0n:N(t.maxLtv,!0);if(y>f.lltv)throw new i("maxLtv cannot exceed the verified destination market LLTV.");if(r==="supply"&&b===0n||r==="withdraw"&&b===0n==(w===0n)||r==="supplyCollateralAndBorrow"&&h===0n&&b===0n||r==="repayAndWithdrawCollateral"&&(b>0n&&w>0n||b===0n&&w===0n&&h===0n))throw new i("Choose a nonzero amount; assets and shares are mutually exclusive for repayment/withdrawal.");let k=t.allocations??[];if(!Array.isArray(k)||k.length>4||k.length&&r==="supplyCollateralAndBorrow"&&b===0n)throw new i("Provide at most four explicit allocations, only with a borrow or withdrawal.");let g=new Set,T=[],I=0n;for(let P of k){if(!P||typeof P!="object"||Array.isArray(P)||Object.keys(P).some(Ve=>!["vault","sourceMarketId","assets","maxPenaltyAssets"].includes(Ve)))throw new i("Unsupported bundled allocation input.");let D=P,$=await wt(e,{vault:D.vault,marketId:r==="migrateBorrowPosition"?t.destinationMarketId:t.marketId});if(g.has($.definition.vault.toLowerCase()))throw new i("Use each source vault at most once per bundle.");g.add($.definition.vault.toLowerCase());let j=N(D.assets),S=N(D.maxPenaltyAssets,!0);if(!$.permission||j>=1n<<128n||j>$.headroom||$.penalty>10n**18n||$.asset.address!==f.loanToken)throw new i("Bundled allocation is disabled, unqualified or exceeds target capacity.");let B=(j*$.penalty+10n**18n-1n)/10n**18n;if(B>S)throw new i("Bundled allocation exceeds maxPenaltyAssets.");I+=B;let Te=D.sourceMarketId===void 0,ee=Te?void 0:$.sources.find(Ve=>E(Ve.id,String(D.sourceMarketId)));if(Te?!$.canIdle||j>$.data.idle:!ee||!ee.canPull||j>ee.capacity||j>$.data.blueCash)throw new i("Bundled allocation source cannot cover the requested amount.");T.push({vault:$.definition.vault,adapter:$.target.adapter,marketParams:$.params,sourceAdapter:ee?.adapter??fe,sourceMarketParams:ee?aa(na,ee.data)[0]:$.params,assets:j,penalty:$.penalty,fromIdle:Te})}let M,C,v,x=0n;if(r==="supply")M="blueBundlesV1Supply",v=c.loanToken,x=b,C=[c,b,Qe,0n,fe,o];else if(r==="withdraw")M="blueBundlesV1Withdraw",C=[c,b,w,Oe,T,0n,fe,o];else if(r==="supplyCollateralAndBorrow"){if(M="blueBundlesV1SupplyCollateralAndBorrow",v=c.collateralToken,x=h,I>=b&&I>0n)throw new i("Allocation penalties would consume the borrow proceeds.");C=[c,h,b,y,Qe,Oe,T,0n,fe,o]}else if(r==="repayAndWithdrawCollateral"){if(M="blueBundlesV1RepayAndWithdrawCollateral",v=c.loanToken,x=N(t.maxRepayAssets,!0),b>x||w>0n&&x===0n)throw new i("Repayment requires a sufficient maxRepayAssets budget.");C=[c,b,w,x,h,y,Qe,Oe,0n,fe,o]}else M="blueBundlesV1MigrateBorrowPosition",C=[c,f,y,Oe,T,0n,fe,o];let G=`Morpho Blue atomic ${r}: ${JSON.stringify(t)}. Allocation penalties ${I} loan-token base units; zero referral fee. Max LTV ${y}; absolute deadline ${o}. Migration adds allocation penalties to destination debt; borrowing deducts them from proceeds. Exact input approval ${x}. Existing Blue bundle authorization remains until explicitly revoked with morpho_manage. No opaque callback, permit or signature is accepted.`,Z=[...v&&x?[e.approval(v,pe,x.toString(),p)]:[],e.unsignedTx({to:pe,data:oa({abi:Ne,functionName:M,args:C}),value:"0",chainId:p,description:G})],H=await e.preview(Z,s),F=new Map;for(let P of H.changes)if(BigInt(P.amount)<0n){let D=P.token.address.toLowerCase();F.set(D,(F.get(D)??0n)-BigInt(P.amount))}if([...F].some(([P,D])=>!v||P!==v.toLowerCase()||D>x))throw new i("Bundle preview spends outside the exact input budget.");return{txs:Z,preview:H,summary:G}}catch(r){throw new i(e.plainError(r))}}}]});import{concatHex as Mt,decodeAbiParameters as sa,encodeAbiParameters as $t,encodeFunctionData as Xe,erc20Abi as Pt,getAddress as K,keccak256 as Je,zeroAddress as we,zeroHash as ia}from"viem";var Y=K("0x6120765Ba5336150BbdDdD0Cd9108B5bFD369632"),la=["0x90B800999e4ACd1bD20283BD450bBd2e06D91F7C","0x708d6Bf6F847202a0755bb5636bE663B174242ea"].map(e=>K(e)),Ze=ae.find(e=>e.name==="take"),vt=[Ze.inputs[0]],da=[Ze.inputs[0].components[0]];function Ct(e){let t=Je(Mt(["0x600b380380600b5f395ff3",$t(da,[e])]));return Je(Mt(["0xff",e.midnight,ia,t]))}var le=10n**18n,Lt=(e,t)=>(e+(t-1n)/2n)/t;function Dt(e){if(e<0n)return 10n**36n/Dt(-e);let t=693147180559945309n,s=(e+322611214989459870n)/t,r=e-s*t,n=r*r/(2n*le),l=n*r/(3n*le);return le+r+n+l<<s}function ca(e){if(e<0n||e>6744n)throw new i("Midnight tick is outside 0..6744.");return Lt(Lt(10n**36n,le+Dt(4987541511039073n*(3372n-e))),10n**11n)*10n**11n}function Ge(e,t){if(typeof e!="string"||!/^0x([0-9a-f]{2})*$/i.test(e)||e.length>32770||t!==void 0&&e.length!==2+t*2)throw new i("Provide bounded canonical hex data.");return e}function Ye(e,t){if(!Array.isArray(e)||e.length!==t)throw new i("Invalid Midnight state tuple.");return e.map(s=>{if(typeof s=="number"&&Number.isSafeInteger(s)&&s>=0)return BigInt(s);if(typeof s=="bigint"&&s>=0n)return s;throw new i("Invalid Midnight integer state.")})}var ua=e=>JSON.parse(JSON.stringify(e,(t,s)=>typeof s=="bigint"?s.toString():s)),Ut=e=>{async function t(n,l){let a=Ge(n,32),o=e.clientFor(p);if(await o.getChainId()!==p)throw new i("Midnight requires chain 4663.");let u=await o.getBlock(),d=(k,g=[])=>o.readContract({address:Y,abi:ae,functionName:k,args:g,blockNumber:u.number}),m=await d("toMarket",[a]);if(m.chainId!==BigInt(p)||K(m.midnight)!==Y||!E(Ct(m),a))throw new i("Midnight market identity does not match the pinned chain and contract.");if(![V[p].tokens.USDG.address,V[p].tokens.WETH.address].some(k=>E(k,m.loanToken)))throw new i("This Midnight loan token needs a qualified transfer and exit fixture.");if(!m.collateralParams.length||m.collateralParams.length>128)throw new i("Invalid Midnight collateral inventory.");let[f,b,w,h]=await Promise.all([d("position",[a,l]),d("updatePositionView",[m,a,l]),d("marketState",[a]),d("isHealthy",[m,a,l])]),y=async k=>{let[g,T]=await Promise.all([o.readContract({address:k,abi:Pt,functionName:"decimals",blockNumber:u.number}),o.readContract({address:k,abi:Pt,functionName:"symbol",blockNumber:u.number})]);if(!Number.isInteger(g)||g>36||typeof T!="string")throw new i("Invalid Midnight token metadata.");return{address:K(k),decimals:g,symbol:T.replace(/[^a-zA-Z0-9.$_-]/g,"").slice(0,32),chainId:p}};return{id:a,rpc:o,block:u,market:m,read:d,token:y,loan:await y(m.loanToken),position:Ye(f,6),updated:Ye(b,3),state:Ye(w,13),healthy:h}}let s=(n,l,a,o)=>({name:n,inputSchema:{type:"object",properties:l,required:a,additionalProperties:!1},execute:async(u,d)=>{try{if(q(d),Object.keys(u).some(m=>!Object.hasOwn(l,m)))throw new i("Unsupported Midnight argument.");return await o(u,d)}catch(m){throw new i(e.plainError(m))}}});async function r(n,l,a){return{txs:n,preview:await e.preview(n,l),summary:a}}return{tools:[s("morpho_midnight_status",{marketId:{type:"string"}},["marketId"],async(n,l)=>{let a=await t(n.marketId,l),o=await Promise.all(a.market.collateralParams.map(async(m,c)=>({token:await a.token(m.token),lltvWad:m.lltv.toString(),oracle:m.oracle,assets:String(await a.read("collateral",[a.id,l,BigInt(c)]))}))),u=["configurator","feeSetter","feeClaimer","tickSpacingSetter"],d=await Promise.all(u.map(m=>a.read(m)));return{protocol:Object.fromEntries(u.map((m,c)=>[m,K(String(d[c]))])),continuousFeePerSecondWad:String(a.state[11]),tickSpacing:String(a.state[12]),settlementFeeCbps:a.state.slice(4,11).map(String),settlementFeeCbpWadScale:"1000000000000",chainId:p,midnight:Y,marketId:a.id,blockNumber:String(a.block.number),market:ua(a.market),loanToken:a.loan,collaterals:o,debtUnits:String(a.position[4]),creditUnits:String(a.updated[0]),pendingFeeUnits:String(a.updated[1]),withdrawableUnits:String(a.state[2]),healthy:a.healthy,maturity:String(a.market.maturity),matured:a.block.timestamp>a.market.maturity,warning:"Maturity does not guarantee lender liquidity. Borrowers become liquidatable after maturity even when collateralized. Lender credit may absorb borrower default losses."}}),s("morpho_midnight_take",{offer:{type:"string",description:"ABI-encoded Offer struct, never transaction calldata."},ratifierData:{type:"string"},units:A(),maxAssets:A(),minAssets:A()},["offer","ratifierData","units","maxAssets","minAssets"],async(n,l)=>{let a=Ge(n.offer),[o]=sa(vt,a);if(!E($t(vt,[o]),a))throw new i("Offer encoding is not canonical.");let u=await t(Ct(o.market),l),d=N(n.units),m=N(n.maxAssets,!0),c=N(n.minAssets,!0),f=Ge(n.ratifierData);if(d>=1n<<128n||E(o.maker,l)||o.callback!==we||o.callbackData!=="0x"||!la.includes(K(o.ratifier)))throw new i("Use a non-self offer with a pinned ratifier and no maker callbacks. Callback routes need a separate qualified builder.");if(u.block.timestamp<o.start||u.block.timestamp>o.expiry||o.expiry<o.start)throw new i("The Midnight offer is not currently live.");if(o.buy&&o.receiverIfMakerIsSeller!==we||!o.buy&&o.receiverIfMakerIsSeller===we)throw new i("Invalid offer seller receiver.");if(o.buy&&u.block.timestamp>u.market.maturity&&d>u.updated[0])throw new i("Post-maturity sales cannot increase this wallet\u2019s debt.");let b=await u.read("settlementFee",[u.id,u.market.maturity>u.block.timestamp?u.market.maturity-u.block.timestamp:0n]),w=ca(o.tick);if(b>w&&o.buy)throw new i("Settlement fee exceeds the offer price.");let h=o.buy?w-b:w,y=h+b,k=P=>o.buy?P/le:(P+le-1n)/le,g=k(d*y),T=k(d*h);if(o.buy?T<c||T===0n:g>m||g===0n)throw new i("Midnight proceeds/spend do not fit the requested bounds.");let I=await u.read("consumed",[o.maker,o.group]);if(o.maxAssets===0n==(o.maxUnits===0n)||I+(o.maxAssets?o.buy?g:T:d)>(o.maxAssets||o.maxUnits))throw new i("Midnight offer capacity is exhausted or invalid.");if(u.state[11]>o.continuousFeeCap||o.tick%u.state[12]!==0n)throw new i("Offer fee cap or market tick spacing no longer permits execution.");let M=await u.read("isAuthorized",[o.maker,o.ratifier]),C=[{type:"function",name:"isRatified",stateMutability:"view",inputs:[Ze.inputs[0],{type:"bytes"},{type:"address"}],outputs:[{type:"bytes32"}]}],v=await u.rpc.readContract({address:o.ratifier,abi:C,functionName:"isRatified",args:[o,f,l],blockNumber:u.block.number});if(M!==!0||v!==Je(new TextEncoder().encode("morpho.midnight.callbackSuccess")))throw new i("The maker has not authorized and ratified this exact offer.");let x=Xe({abi:ae,functionName:"take",args:[o,f,d,l,o.buy?l:we,we,"0x"]}),G=`Midnight ${o.buy?"sell credit or borrow":"buy credit or reduce debt"}: ${d} fixed debt units; ${o.buy?`receive ${T}`:`spend ${g}`} ${u.loan.symbol} base units (token ${u.loan.address}, decimals ${u.loan.decimals}). Maturity ${u.market.maturity} Unix seconds; offer expiry ${o.expiry}. A borrower can lose collateral after maturity; lender withdrawal depends on repayments and bears default losses. No lender signature or callback is created. Bounds are rechecked locally; the take calldata fixes the offer and units. Exact buyer approval caps wallet spending.`,Z=[...o.buy?[]:[e.approval(u.loan.address,Y,g.toString(),p)],e.unsignedTx({to:Y,data:x,value:"0",chainId:p,description:G})],H=await r(Z,l,G),F=H.preview.changes.filter(P=>P.token.chainId===p&&E(P.token.address,u.loan.address)).reduce((P,D)=>P+BigInt(D.amount),0n);if(o.buy?F<T:F!==-g)throw new i("Midnight preview does not match the exact quoted cash flow.");return H}),s("morpho_midnight_action",{marketId:{type:"string"},operation:{enum:["supplyCollateral","withdrawCollateral","repay","withdraw","updatePosition","claimContinuousFee"]},amount:A(),collateralIndex:{type:"integer",minimum:0,maximum:127}},["marketId","operation"],async(n,l)=>{let a=await t(n.marketId,l),o=n.operation;if(!["supplyCollateral","withdrawCollateral","repay","withdraw","updatePosition","claimContinuousFee"].includes(String(o)))throw new i("Choose a finite Midnight position operation.");let u,d,m=a.loan,c=0n;if(o==="updatePosition"){if(n.amount!==void 0||n.collateralIndex!==void 0)throw new i("Position update takes no amount or collateral index.");u=[a.market,l]}else if(o==="claimContinuousFee"){if(c=N(n.amount),n.collateralIndex!==void 0||K(String(await a.read("feeClaimer")))!==K(l))throw new i("This wallet lacks the Midnight fee claimer role or supplied an unused collateral index.");u=[a.market,c,l]}else{if(c=N(n.amount),c>=1n<<128n)throw new i("Midnight position amount exceeds uint128.");if(o==="supplyCollateral"||o==="withdrawCollateral"){if(!Number.isInteger(n.collateralIndex)||Number(n.collateralIndex)<0||Number(n.collateralIndex)>=a.market.collateralParams.length)throw new i("Choose a current collateral index.");let w=BigInt(String(n.collateralIndex)),h=await a.token(a.market.collateralParams[Number(w)].token);if(m=h,o==="withdrawCollateral"&&c>await a.read("collateral",[a.id,l,w]))throw new i("Insufficient Midnight collateral.");u=o==="supplyCollateral"?[a.market,w,c,l]:[a.market,w,c,l,l],o==="supplyCollateral"&&(d=h)}else{if(n.collateralIndex!==void 0)throw new i("This operation takes no collateral index.");if(o==="repay"&&c>a.position[4]||o==="withdraw"&&(c>a.updated[0]||c>a.state[2]))throw new i("Amount exceeds current debt, credit or available repayment liquidity.");u=o==="repay"?[a.market,c,l,we,"0x"]:[a.market,c,l,l],o==="repay"&&(d=a.loan)}}let f=`Midnight ${o}: ${c} ${m.symbol} base units (token ${m.address}, decimals ${m.decimals}) on ${a.id}; beneficiary ${l}; maturity ${a.market.maturity} Unix seconds. No callbacks or delegation. Withdrawal can fail if collateral health or lender liquidity changes.`,b=[...d?[e.approval(d.address,Y,c.toString(),p)]:[],e.unsignedTx({to:Y,data:Xe({abi:ae,functionName:String(o),args:u}),value:"0",chainId:p,description:f})];return r(b,l,f)}),s("morpho_midnight_manage",{operation:{type:"string",enum:["setConsumed","setIsAuthorized","setConfigurator","setFeeSetter","setFeeClaimer","setTickSpacingSetter","enableLltv","enableLiquidationCursor","setMarketTickSpacing","setMarketSettlementFee","setMarketContinuousFee","setDefaultSettlementFee","setDefaultContinuousFee","claimSettlementFee"]},values:{type:"array",maxItems:3,items:{oneOf:[{type:"string"},{type:"boolean"}]}}},["operation","values"],async(n,l)=>{let a={setConfigurator:"configurator",setFeeSetter:"configurator",setFeeClaimer:"configurator",setTickSpacingSetter:"configurator",enableLltv:"configurator",enableLiquidationCursor:"configurator",setMarketTickSpacing:"tickSpacingSetter",setMarketSettlementFee:"feeSetter",setMarketContinuousFee:"feeSetter",setDefaultSettlementFee:"feeSetter",setDefaultContinuousFee:"feeSetter",claimSettlementFee:"feeClaimer"};if(typeof n.operation!="string"||!["setConsumed","setIsAuthorized",...Object.keys(a)].includes(n.operation)||!Array.isArray(n.values))throw new i("Choose a finite Midnight management operation and ordered values.");let o=n.operation,u=ae.find(f=>f.name===o);if(n.values.length!==u.inputs.length)throw new i("Provide the exact ordered operation values.");let d=e.clientFor(p);if(await d.getChainId()!==p)throw new i("Midnight requires chain 4663.");let m=u.inputs.map((f,b)=>{let w=n.values[b];if(f.type==="bool"){if(typeof w!="boolean")throw new i("Use boolean management values.");return w}if(f.type==="address")return Ue(w,"Use explicit management addresses.",De);if(f.type==="bytes32")return Ge(w,32);if(/^uint/.test(f.type)){let h=N(w,!0);if(h>=1n<<BigInt(f.type.slice(4)))throw new i("Management integer exceeds its ABI width.");return h}throw new i("Unsupported management argument type.")});if(o==="setConsumed"||o==="setIsAuthorized"){if(!E(String(m[2]),l))throw new i("Midnight management is bound to this wallet.")}else{let f=await d.readContract({address:Y,abi:ae,functionName:a[o]});if(typeof f!="string"||K(f)!==K(l))throw new i("This wallet lacks the Midnight configuration, fee or tick role.")}let c=`Midnight ${o}, ordered values ${JSON.stringify(n.values)}. ${o==="setIsAuthorized"&&m[1]?"This grants authority over all Midnight positions, cancellations and further delegation, without an amount cap. Revoke with false when done.":""}${o==="setConsumed"?"Consumption only increases; setting uint128 maximum permanently cancels this offer group.":""}`;return r([e.unsignedTx({to:Y,data:Xe({abi:ae,functionName:o,args:m}),value:"0",chainId:p,description:c})],l,c)})]}};import{decodeAbiParameters as oe,encodeAbiParameters as ma,encodeFunctionData as R,erc20Abi as et,getAddress as L,isAddress as Re,keccak256 as fa,parseAbi as Ee,parseAbiParameters as J}from"viem";var Pe="morpho",pa="https://api.morpho.org/graphql",U=L(V[p].morpho.morpho_blue.address),ba=L(V[p].morpho.adaptive_curve_irm.address),wa=L(V[p].morpho.USDG.address),de=L(V[p].morpho.WETH.address),ha=["0x7c820d6a09502d63be80bb8025ec479d29d7c06e70f8df65a92aaeed23a366e2","0x1fa5293f9f60059a7f6a4923022156fcdcc038bd3749be55897000c03afe92d8"],ka={"oak-recorded":"Oak recorded chain observations (block 100362239).","morpho-listed":"Morpho API (POST https://api.morpho.org/graphql, markets where chainId_in [4663]) returned listed: true, fetched 2026-10-31 UTC.",longbow:"Longbow market list: Longbow MCP list_markets/get_market (https://mcp.longbow.credit/mcp, named on https://longbow.cash/mcp) and the live market list on https://longbow.cash/earn, fetched 2026-10-31 UTC; each ID re-read on chain.",netnet:"NetNet Credit: six stock-token market IDs printed at https://docs.netnet.capital/credit, plus the Loopback wsNET/USDG market returned by NetNet's Turbo router marketId() and Credit adapter marketIds(6); fetched 2026-10-31 UTC."},tt=[{marketId:"0x7c820d6a09502d63be80bb8025ec479d29d7c06e70f8df65a92aaeed23a366e2",label:"WETH/USDG 77%",source:"oak-recorded"},{marketId:"0x1fa5293f9f60059a7f6a4923022156fcdcc038bd3749be55897000c03afe92d8",label:"USDG/WETH",source:"oak-recorded"},{marketId:"0x0309c02dabf0be02682af1a2bde9a457f4df0f0b6bc889cde3f948e5315e4114",label:"spUSDG/USDG 91.5%",source:"morpho-listed"},{marketId:"0x10151e2ac82a820153520d9d77d56de1c84775e23b79bdc11e2e34282d9afa10",label:"SPCX/USDG 62.5%",source:"morpho-listed"},{marketId:"0x127353ba63e08f74d8e9ce8a1c2b41b5f89c7167135b1c09fbed34a71b4cb06b",label:"WETH/USDG 86%",source:"morpho-listed"},{marketId:"0x1a31d1c8c05a98b94777663912e4166bf50f3fcdc9c3c3d29deb55634ac58239",label:"PONS/USDG 62.5%",source:"morpho-listed"},{marketId:"0x1efd13a2d1dc66a2466e7c25820537028e604791f00454d9c686fdfbf70f404d",label:"mGLO/USDG 91.5%",source:"morpho-listed"},{marketId:"0x21ea2a012b888120e328775c2a7bf6fb4619cf4c4c631ad1c9b6db51f8882d5a",label:"SPCX/USDG 62.5%",source:"morpho-listed"},{marketId:"0x22e4598e5cc16cff0056e72d61c5f1f2f8bf5bbffc22da5277ab196939c8a59e",label:"TSLA/USDG 62.5%",source:"morpho-listed"},{marketId:"0x66306c087add8907752320b309934abcc354d21626de8115c79df49d9c214edc",label:"NVDA/USDG 62.5%",source:"morpho-listed"},{marketId:"0x69400cfe81f2ae381b9a9f27076a4d637338379d999e9ffdfbde52f0876312ee",label:"META/USDG 62.5%",source:"morpho-listed"},{marketId:"0x7408b08b03e05ffd2d21c797489a0e77a28e4bb36acb4e827c69e805d06272b4",label:"GOOGL/USDG 77%",source:"morpho-listed"},{marketId:"0x7c1e38bf461da47df9805ae9b7e97a12ec023625a1f92d2a403b3b9a92260894",label:"CASHCAT/USDG 62.5%",source:"morpho-listed"},{marketId:"0x919a9b6b94dae7c86620eaf7a08e597aae8a4c3a9e9c7671771fbaf62b6b61c7",label:"syrupUSDG/USDG 91.5%",source:"morpho-listed"},{marketId:"0x93ed7865910b09f5a2e0dbfd4670c2d3bc1da9647f7c68e7975f37f497898cdb",label:"mGLO/USDG 91.5%",source:"morpho-listed"},{marketId:"0x947ae981cc823024ea00b602f6ea72d049cac05d66ef096198ceeb998651c175",label:"AAPL/USDG 62.5%",source:"morpho-listed"},{marketId:"0x95312f02c1dae8407b2c80468a5657a9bd19c45ac277f1a61aa52c11444c5314",label:"NVDA/USDG 62.5%",source:"morpho-listed"},{marketId:"0xba01f6625137b692c5dd86afb8e654b4016d7b64e36dfca4124e84bef98bc4d2",label:"GOOGL/USDG 62.5%",source:"morpho-listed"},{marketId:"0xc845da65a020ddca5f132efa8fea79676d8edfdea504226a4c01e7a9e34cddd6",label:"USDe/USDG 91.5%",source:"morpho-listed"},{marketId:"0xcaa167af7ba0422c76424fae56167b7db25bf19f4f435215e6dd7d06a943bdac",label:"AAPL/USDG 62.5%",source:"morpho-listed"},{marketId:"0xe29c7d3790037800101ecbad9c45de2067698d206cbcab7c25069a9f43c9eb98",label:"TSLA/USDG 62.5%",source:"morpho-listed"},{marketId:"0xe5a6d99c3721ef2ab00fb16f0ad226bc7c87a90394f82e27dc6bbca4b1d95c5d",label:"AI/USDG 62.5%",source:"morpho-listed"},{marketId:"0xeb1739b2a69dd22a4285d366a06698a01018b37c24d2994fefe19cc72f313613",label:"SPY/USDG 77%",source:"morpho-listed"},{marketId:"0xf5ff7d546af5e72f3912d2aa723088fd0bf66fddc158714995637714d9db6e4c",label:"NVDA/USDG 62.5%",source:"morpho-listed"},{marketId:"0xaa586d26a6fe62d9c0f0948fede6e2130500ac7a655587447e2d4a37e6330589",label:"wsNET/USDG 62.5% (NetNet Loopback)",source:"netnet"},{marketId:"0x8b16891f032a93b771347c9cb470a780e6699dd701553d3402aa3cdba6189c3e",label:"NVDA/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x9b4b47cdf7e295341c6c6cdfd3efb9805c4a5b3d580dba0c0c39d3a4232b297b",label:"SPCX/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0xdeb4782d012d5fd3b24962538c2f6559049d70bda4dabd2e4212dacb96c28d45",label:"AAPL/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x7fa81b10e5d21b2e4c571f862442bc11aff2ed14f02335868d0ff933fd40d0ba",label:"GOOGL/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x2e1859aa8f143b7220088f80562c6dfe0bf8e52b87d9cedf8da8805f231994ce",label:"MSFT/USDG 62.5% (NetNet Credit)",source:"netnet"},{marketId:"0x3ebd43d91c3960a9fac32bedd5c60428e0e414de5bdd67fda770207afb0eb615",label:"COIN/USDG 38.5% (NetNet Credit)",source:"netnet"},{marketId:"0x26f3bd5919ba0e6ea6f4bca1b8bd95ce29cbe3aad4ef824fb007570eac35103b",label:"cbBTC/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xb095654f06f4d17d4fc010c2d89a107649e3c5b58e53a3812d1736c95e63e3f8",label:"NVDAon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x947c05e7c0fa3ba187d57db710d04ba8be4fef53baba0cfbe71ce61b34a1367d",label:"SPCXon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf8f0b5badf06192908bc47af32b93742d9b4fb6072d388cb183ff7849ee6534c",label:"SPYon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x26c80a00f8facc6b081989965d89cedc274b90b81be660e69245a74e5384f5de",label:"METAon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xeefec6c3e5cb7df1f2366ea7cf96a583081205b9720e807d2868d9866a702229",label:"GOOGLon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf511a080dcb4d0a3b9d6aebb06e24afa011cda87f9f71ada70c60f8220e94f35",label:"AAPLon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xa87da1cc931faa945a41861cc9c90076772ceeae9a663836df6b265c4f30106d",label:"MSTRon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x0279ea145eff84ed2ffd3b1ed1f2aca333060d9cef6fdd48bd21073c13ec86bf",label:"CRCLon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xff2063ef18bc5f71867c56d6d3290b61f3da1d010c8a0552bdb7995cfad8cacc",label:"TSLAon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x83d542605940b5495ef38d4b62a39293766a486a24e5c67930f41acd919cf1d1",label:"QQQon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x9b01d5ad5ce8e477510854132cc47853f6e82a708c9c4723887550412f4ee522",label:"GMEon/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x8b2af4d69ad861a4099b995b6279aeaf6a905225a0ee889bce424c7faf19b7d9",label:"AMZN/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x4edbd2f2f3b33bc5f80ab588def67fab8c10945fc99f855d80ff4bef2c4aa1f0",label:"SLV/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x7e6ebfdc58a893a5cddba0fba0483baf4fac2efece627ad50821dbe27d6f9738",label:"GOOGL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x30a2a5f1a098b23ed91eadc4529a8d1c967f2cdc2e40a709f3a5992004b01ac0",label:"AAPL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x14973a168cf6c6b1148309f5d567c255b292863ffe9cca59f4284e1426636f00",label:"RKLB/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf049167e6bf18a1b41b8e2acefcf7bc9b13ea013d8d65c7fbc7cbaeb3fe9b4e2",label:"NBIS/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x8114b65dfc5e64222103e5588de261eca9defd25f47ea4ae2f91d49fe4fa2993",label:"CLSK/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x96d3d5f9bc842e4c8a935c5628abd02fb0e10115560c35a9add768781434f471",label:"CRWV/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x1b3555f7c1273688f01ae82da7dc8e508e6a7841ec0038dbb15767154a277b86",label:"EWY/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x039503b6308d6d818d181e626d3fbc667d6e68393c3d74332a6124cd2dd6e755",label:"CASHCAT_LEGACY/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x597227ca652ea5e8afb6e4801ecd766a4d6eb9b3b9fafa9127ba88a8b1f19629",label:"SPCX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x50bc39b5722fb5634c436d74c6787f3c125b879e7b73cf9e9ecc01bbb57b8e55",label:"SPY/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x315b99abb698487891243a84afd28a5ff56fe02143f203c03edd3f103936bf60",label:"QQQ/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x4979137c23c8fb519cd507adc290944c3c2120e8a3191547531fced28360e9c2",label:"GME/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x6b8a1f62d88d1cd1e8de609aef07cafc8226172ba703e57c52c3730350e61df1",label:"USO/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xafc86936af4f7edf083eb2550b8c42311b83c685982742b9271b309a58268855",label:"MSFT/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf6f3dbe0a19e948147e79e66502c6b05709d8dfde977fec7db1528fc8f0ebdfa",label:"SGOV/USDG 86% (Longbow)",source:"longbow"},{marketId:"0x2ab6a14c9f68d4216dcb3b4e6ed607cf82f2e6badfa2bd5618d7f69d012d7fab",label:"USAR/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xb41b34c5989420ad080e79363a9cfe3e23bec7459fcd2d88029250da370288df",label:"TSLA/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x4d2075836fd32183b10e5be1b383f6430de859df6d2bd5ec5b859970c4dd14e8",label:"AMD/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x9df4f54a2e46b35bd326cec97dbabc4203fa6c64a8e4182128f277adba8fefaf",label:"MU/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xb5ba72c0d55c353fa37c0bea104eb117afb2f4934473bcb736d2218ae5686746",label:"PLTR/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xda5584635e8b14ea18f674dbe4243365505910fefd8e3aa1ac9bfaac0eba74e8",label:"INTC/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x74fece475178af9e06d31fb64f405046a305f8f0abc588782f596d6f261c1fbb",label:"SNDK/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xee04847a312224d551d2267bb5c2c2695777af5fd1f05347bdcca397e8f54336",label:"ORCL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x508b47fb12dbb8747644d4436aae65489b5f2819936adefc8a591323f64a5b01",label:"COIN/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x243ac165f79a75a0590d2e994ffa9e260b70292fd1ca134ace95f3640895b19f",label:"TSM/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x01baec96478004fc7b74c8dfe38abef8d716fea59ffd481b6ec74db915d3bc80",label:"MSTR/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xf0959f62e748938cf260ca6fe7cb21a412e0a6643913460f4a6770c3f4b90af6",label:"CRCL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xbe881499e682850931951c998e76cfbf38c7979b1beeae7cbbb97a39b3336a07",label:"ASML/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xdd578ca54b4ef6a7827c6e9fc06905699a577f6e2f00712853d8aab13383bc38",label:"BABA/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xd8b502d5c43f6e5cfff7f938c7ef18e684f114fb5b362611981144397e5d5aef",label:"DELL/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0x003390b057d753bd839981a0d45f9a567aa0b0ed6373fd42e951eac8ee86c2ba",label:"RGTI/USDG 62.5% (Longbow)",source:"longbow"},{marketId:"0xc6e16cff2bcf185639562ab937b7a1c381522768ff16aefc85a25ff6ab1c45ea",label:"AI/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xaba3ac501ce4c6b80c08ed0dba19e1ac0de495f17af3ed692a38e92d176a6c9e",label:"PONS/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x8097c1d1000eb657e75265384137041ac92856c8dc0b72c99569c3681320a430",label:"DELTA/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x6e6762ae397a2b3f2500ea2f48f8adce0eadfbf54cbc37f6108602e907e844ad",label:"INDEX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x378713071c58206c6a826287d0051bcae113d83d6e3d3b6370b7e73128d06162",label:"STONKBROKER/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x2695be2638c98241c887e4cad4eeba0f01137205f46b9e302edab04b5fee0570",label:"AVGO/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x6c12c02536aa27831f713d658b59f74e149cc62b48528cb74455e79fab32f772",label:"GLD/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x298e8ff9b31f22be90507bc61b55e66ab93e78b55a60593035e309ed93137cb8",label:"RDDT/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xb33399a677e1a21152fa9969f02c57a7a342e692ec45608a3fa0d3d92519c343",label:"COST/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x3be7fe1b6b439cfeb737d9921e9b83c92095a23a4f50aeee0d6d04f44446170f",label:"DJT/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x0066bc47b87597993af0bca6f526175c0abae011b764d4bf12a3def45e1f4e78",label:"NFLX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x8c170f5c5df593791640ac9fbac297d59d08c2e92e86f38fe52d38e929e60fa3",label:"AMC/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x0f18d4fd8d86bd4d100b867b67e1fd38c80981fcd43e442313c2d5408da9352d",label:"LLY/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x7d4313cf1b0ede39395a2c7495dc1b1b47370caf51f70571d927f22e715e5f58",label:"LULU/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xa85928d77bd25cc348e13ea6587b8b3ca3793f4af5e5db8ca07d0f20fd5cfa99",label:"IBM/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x9d61e320efb766ce5c375032b399f08afe644b095a9cb0b2d6d1f6ab68399a6f",label:"F/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x43c51f6ff44ab406ab9c97cb5512c881f4a7498209f94bbcfd874d8f97fad79d",label:"HIMS/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xe6284cf12d0603aee18ff5ab412e262cf99f120e967579111d7a51f37f276f54",label:"TTWO/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0xe8d9b45cdbedc4401a3145be7726c9f72b715e03c5399c961439f11636ee9fb6",label:"MRNA/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x46eea143d473cdb8587505f8886dad452037f285f7729a7763e8c233c63b2e8e",label:"RIVN/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x8338aed363a309039b2f271a83558831e7e445f2d13c6e72c576ec0b8a969415",label:"RBLX/USDG 38.5% (Longbow)",source:"longbow"},{marketId:"0x4e92b336ecad6c842be20ae2ae27b28b3cf5ced6c5388a808167c03a8d75fdf8",label:"SPY/WETH 38.5% (Longbow)",source:"longbow"},{marketId:"0x141c2b1d2bbecf7f8a76563307d7e5bf586457e873c3d97c4bb1502e57b77952",label:"NVDA/WETH 38.5% (Longbow)",source:"longbow"}],ya=new Map(tt.map(e=>[e.marketId.toLowerCase(),e]));function W(e){return ya.get(e.toLowerCase())}function ot(e){let t=W(e);return t?{actions:"enabled",label:t.label,source:ka[t.source]}:{actions:"read-only",reason:"Not in Oak's verified Morpho market registry; Oak builds no transactions for it."}}var Bt=20,ve=120n,_e=1000000n,He=1n,he=10n**18n,ga=10n**36n,Et=(1n<<128n)-1n,Sa=(1n<<256n)-1n,X=Ee(["function idToMarketParams(bytes32 id) view returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv)","function market(bytes32 id) view returns (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee)","function position(bytes32 id, address user) view returns (uint256 supplyShares, uint128 borrowShares, uint128 collateral)","function supplyCollateral((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, address onBehalf, bytes data)","function withdrawCollateral((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, address onBehalf, address receiver)","function borrow((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver) returns (uint256 assetsBorrowed, uint256 sharesBorrowed)","function repay((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) returns (uint256 assetsRepaid, uint256 sharesRepaid)","function supply((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) returns (uint256 assetsSupplied, uint256 sharesSupplied)","function withdraw((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver) returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn)"]),Aa=Ee(["function price() view returns (uint256)"]),Ia=Ee(["function borrowRateView((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee) market) view returns (uint256)"]),_t=Ee(["function deposit() payable"]);function ce(e){return{loanToken:e.loanToken,collateralToken:e.collateralToken,oracle:e.oracle,irm:e.irm,lltv:e.lltv.toString()}}function Ce(e,t){return e===0n?0n:(e+t-1n)/t}function xa(e,t,s){return e*(s+_e)/(t+He)}function Ta(e,t,s){return Ce(e*(s+_e),t+He)}function rt(e,t,s){return e*(t+He)/(s+_e)}function ne(e,t,s){return Ce(e*(t+He),s+_e)}function ke(e,t,s){return e*t/ga*s/he}function Ma(e,t,s){return t.startsWith("-")?`-${e.formatAmount(t.slice(1),s)}`:e.formatAmount(t,s)}function ye(e,t){let s=[],r={};for(let n of t.changes){let l=Ma(e,n.amount,n.token.decimals);s.push({token:n.token,amount:n.amount,formattedAmount:l}),r[n.token.address.toLowerCase()]=l}return{formattedChanges:s,formattedNetOutflows:r}}function Ht(e){if(typeof e!="string"||!/^0x[0-9a-fA-F]{64}$/.test(e))throw new i("Morpho marketId must be a 32-byte hex string.");return e.toLowerCase()}function qe(e){if(!e||typeof e!="object")throw new i("Morpho marketParams must be an object.");for(let a of[e.loanToken,e.collateralToken,e.oracle,e.irm])if(typeof a!="string"||!Re(a,{strict:!1}))throw new i("Morpho marketParams contains an invalid address.");let t=L(e.loanToken),s=L(e.collateralToken),r=L(e.oracle),n=L(e.irm),l=typeof e.lltv=="bigint"?e.lltv:Me(String(e.lltv));if(t===te||s===te||r===te)throw new i("Morpho marketParams loan, collateral, and oracle addresses must be non-zero.");if(l<=0n||l>=he)throw new i("Morpho marketParams LLTV must be between 0 and 1e18.");return{loanToken:t,collateralToken:s,oracle:r,irm:n,lltv:l}}function be(e){let t=qe(e),s=ma(J("address, address, address, address, uint256"),[t.loanToken,t.collateralToken,t.oracle,t.irm,t.lltv]);return fa(s)}function at(e){let t=e.toLowerCase();return t===dt.toLowerCase()||t===ct.toLowerCase()||t===te.toLowerCase()}function ge(e,t){let s=t??e.wallet;if(!s)throw new i("Provide a valid wallet address.");return q(s),L(s)}async function re(e,t,s){if(typeof e.call=="function"){let r=await e.call({to:t,data:s});if(r&&typeof r.data=="string")return r.data}if(typeof e.request=="function"){let r=await e.request({method:"eth_call",params:[{to:t,data:s},"latest"]});if(typeof r=="string")return r}throw new i(`Unable to execute eth_call on contract ${t}.`)}function qt(e){return typeof e=="string"&&/^[A-Za-z0-9$._+-]{1,32}$/.test(e)?e:"UNKNOWN"}async function Q(e,t,s=p){if(q(t),at(t))return{...ut,chainId:s};let r=L(t),n=r.toLowerCase();if(s===p){if(n===wa.toLowerCase())return mt;if(n===de.toLowerCase())return ft}let[l,a]=await Promise.all([re(e,r,R({abi:et,functionName:"symbol"})),re(e,r,R({abi:et,functionName:"decimals"}))]),[o]=oe(J("string"),l),[u]=oe(J("uint8"),a);return{address:r,symbol:qt(o),decimals:Number(u),chainId:s}}async function Ft(e,t){let s=await re(e,U,R({abi:X,functionName:"idToMarketParams",args:[t]})),[r,n,l,a,o]=oe(J("address, address, address, address, uint256"),s);return{loanToken:L(r),collateralToken:L(n),oracle:L(l),irm:L(a),lltv:o}}async function jt(e,t){let s=await re(e,U,R({abi:X,functionName:"market",args:[t]})),[r,n,l,a,o,u]=oe(J("uint128, uint128, uint128, uint128, uint128, uint128"),s);return{totalSupplyAssets:r,totalSupplyShares:n,totalBorrowAssets:l,totalBorrowShares:a,lastUpdate:o,fee:u}}async function Se(e,t,s){let r=await re(e,U,R({abi:X,functionName:"position",args:[t,L(s)]})),[n,l,a]=oe(J("uint256, uint128, uint128"),r);return{supplyShares:n,borrowShares:l,collateral:a}}async function Fe(e,t){let s=await re(e,L(t),R({abi:Aa,functionName:"price"})),[r]=oe(J("uint256"),s);return r}async function Pa(e,t,s){if(t.irm===te)return 0n;let r=await re(e,L(t.irm),R({abi:Ia,functionName:"borrowRateView",args:[t,s]})),[n]=oe(J("uint256"),r);return n}function je(e,t,s){let r=s>e.lastUpdate?s-e.lastUpdate:0n,n=t*r,l=Ce(n*n,2n*he),a=Ce(l*n,3n*he);return e.totalBorrowAssets+Ce(e.totalBorrowAssets*(n+l+a),he)}async function Le(e,t,s,r=0n){let[n,l]=await Promise.all([e.getBlock({blockTag:"latest"}),Pa(e,t,s)]),a=BigInt(Math.ceil(Date.now()/1e3)),o=(n.timestamp>a?n.timestamp:a)+r;return{totalBorrowAssets:je(s,l,o),accruedThrough:o,rate:l}}async function Vt(e,t,s){let r=await re(e,L(t),R({abi:et,functionName:"balanceOf",args:[L(s)]})),[n]=oe(J("uint256"),r);return n}async function ue(e,t,s=!1){let r=t.marketId,n=t.marketParams;if(!r&&!n)throw new i("Provide either marketId or marketParams for the Morpho Blue market.");let l=n?qe(n):void 0,a=l?be(l):void 0,o=r!==void 0?Ht(r):void 0;if(o&&a&&o!==a.toLowerCase())throw new i(`MarketParams tuple hash (${a}) does not match marketId (${o}).`);let u=(o??a).toLowerCase();if(s&&!W(u))throw new i(`Morpho actions require a known market from Oak's verified registry, which pins its oracle. Find one with morpho_status {"discover":true}; other markets are read-only.`);let[d,m]=await Promise.all([Ft(e,u),jt(e,u)]);if(d.loanToken===te||d.collateralToken===te||d.lltv===0n||m.lastUpdate===0n)throw new i(`Morpho market ${u} is not initialized on chain ${p}.`);let c=be(d);if(c.toLowerCase()!==u.toLowerCase())throw new i(`On-chain idToMarketParams tuple hash (${c}) does not match marketId (${u}).`);if(l&&!(l.loanToken.toLowerCase()===d.loanToken.toLowerCase()&&l.collateralToken.toLowerCase()===d.collateralToken.toLowerCase()&&l.oracle.toLowerCase()===d.oracle.toLowerCase()&&l.irm.toLowerCase()===d.irm.toLowerCase()&&l.lltv===d.lltv))throw new i(`Provided marketParams tuple does not match on-chain idToMarketParams for ${u}.`);return{marketId:u,marketParams:d,marketState:m}}function Ae(e){if(e.assets!==void 0&&e.amount!==void 0)throw new i("Specify either assets or amount, not both.");let t=e.assets??e.amount;if(typeof t!="string")throw new i("Provide an amount as a base-unit integer string.");let s=Me(t);if(s<=0n||s>Et)throw new i("Asset amount must be greater than zero and fit in uint128.");return s}function Ie(e,t){for(let s of["onBehalf","receiver"])if(e[s]!==void 0&&(typeof e[s]!="string"||e[s].toLowerCase()!==t.toLowerCase()))throw new i(`Morpho ${s} must be the wallet; overrides are not supported.`);if(e.data!==void 0&&e.data!=="0x")throw new i("Morpho callback data must be empty (0x).")}async function va(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=e.clientFor(p),{marketId:a,marketParams:o}=await ue(l,t,!0),u=await Q(l,o.collateralToken,p),d=o.collateralToken.toLowerCase()===de.toLowerCase(),m=typeof t.collateralToken=="string"?(q(t.collateralToken),L(t.collateralToken)):void 0,c=z("wrapNative",t.wrapNative)===!0||m!==void 0&&at(m);if(m&&!at(m)&&m.toLowerCase()!==o.collateralToken.toLowerCase())throw new i(`Collateral token ${m} does not match market collateral ${o.collateralToken}.`);if(c&&!d)throw new i("Native ETH wrapping is only supported when market collateralToken is WETH.");let f=Ae(t),b=f.toString(),w=e.formatAmount(b,u.decimals),h=[];c&&h.push(e.unsignedTx({chainId:p,to:de,data:R({abi:_t,functionName:"deposit"}),value:b,description:`Wrap ${w} ETH into WETH at ${de}.`})),h.push(e.approval(o.collateralToken,U,b,p)),h.push(e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"supplyCollateral",args:[o,f,n,"0x"]}),value:"0",description:`Supply ${w} ${u.symbol} (${b} base units) collateral to Morpho market ${a}.`}));let y=await e.preview(h,r),{formattedChanges:k,formattedNetOutflows:g}=ye(e,y);return{action:"morpho_supply_collateral",chainId:p,marketId:a,marketParams:ce(o),collateralToken:u,assets:b,formattedAssets:w,onBehalf:n,txs:h,summary:`${c?`Send ${w} ETH to wrap into WETH. `:""}Supply ${w} ${u.symbol} collateral to Morpho Blue market ${a}.`,preview:y,formattedChanges:k,formattedNetOutflows:g}}async function Ca(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=r,a=e.clientFor(p),{marketId:o,marketParams:u,marketState:d}=await ue(a,t,!0),[m,c,f,b]=await Promise.all([Q(a,u.loanToken,p),Se(a,o,n),Fe(a,u.oracle),Le(a,u,d,ve)]),w=Ae(t),h=w.toString(),y=e.formatAmount(h,m.decimals),k=d.totalSupplyAssets>d.totalBorrowAssets?d.totalSupplyAssets-d.totalBorrowAssets:0n;if(w>k)throw new i(`Insufficient market liquidity: requested ${h} base units, available ${k.toString()} base units.`);let g=ke(c.collateral,f,u.lltv),T=ne(c.borrowShares,b.totalBorrowAssets,d.totalBorrowShares);if(c.collateral===0n||T+w>g)throw new i(`Insufficient collateral or unhealthy borrow: total debt ${(T+w).toString()} exceeds max borrow ${g.toString()} base units.`);let I=Ta(w,b.totalBorrowAssets,d.totalBorrowShares),C=[e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"borrow",args:[u,w,0n,n,l]}),value:"0",description:`Borrow ${y} ${m.symbol} (${h} base units) from Morpho market ${o}.`})],v=await e.preview(C,r),{formattedChanges:x,formattedNetOutflows:G}=ye(e,v);return{action:"morpho_borrow",chainId:p,marketId:o,marketParams:ce(u),loanToken:m,assets:h,formattedAssets:y,borrowShares:I.toString(),onBehalf:n,receiver:l,txs:C,summary:`Borrow ${y} ${m.symbol} from Morpho Blue market ${o}.`,preview:v,formattedChanges:x,formattedNetOutflows:G}}async function La(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=e.clientFor(p);if(t.shares!==void 0){let x=Me(t.shares);if(x<=0n||x===Sa||x>Et)throw new i("Morpho Blue core does not accept maxUint256 or out-of-range share sentinels; pass exact position.borrowShares.")}if(z("repayAll",t.repayAll)===!0&&(t.shares!==void 0||t.assets!==void 0||t.amount!==void 0))throw new i("Specify repayAll alone, without shares or assets/amount.");if(t.shares!==void 0&&(t.assets!==void 0||t.amount!==void 0))throw new i("Specify either assets/amount or shares for Morpho repay, not both.");let{marketId:a,marketParams:o,marketState:u}=await ue(l,t,!0),[d,m,c]=await Promise.all([Q(l,o.loanToken,p),Se(l,a,n),Vt(l,o.loanToken,r)]);if(m.borrowShares===0n)throw new i(`Position has no active borrow debt on Morpho market ${a}.`);let f=0n,b=0n;if(z("repayAll",t.repayAll)===!0)b=m.borrowShares;else if(t.shares!==void 0){let x=Me(t.shares);if(x>m.borrowShares)throw new i(`Repay shares (${x.toString()}) exceed current position borrowShares (${m.borrowShares.toString()}).`);b=x}else f=Ae(t);let w=b>0n?await Le(l,o,u,ve):void 0,h=b>0n?ne(b,w.totalBorrowAssets,u.totalBorrowShares):f;if(c<h)throw new i(`Insufficient loan token balance for repayment: wallet holds ${c.toString()} base units, but ${h.toString()} base units are required (including accrued interest).`);let y=h.toString(),k=e.formatAmount(y,d.decimals),g=e.approval(o.loanToken,U,y,p),T=e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"repay",args:[o,f,b,n,"0x"]}),value:"0",description:b>0n?`Repay ${b.toString()} borrow shares (${k} ${d.symbol}) on Morpho market ${a}.`:`Repay ${k} ${d.symbol} (${f.toString()} base units) on Morpho market ${a}.`}),I=[g,T],M=await e.preview(I,r),{formattedChanges:C,formattedNetOutflows:v}=ye(e,M);return{action:"morpho_repay",chainId:p,marketId:a,marketParams:ce(o),loanToken:d,repayAssets:f.toString(),repayShares:b.toString(),requiredAssets:y,...w?{accruedThrough:w.accruedThrough.toString(),borrowRatePerSecond:w.rate.toString(),inclusionSeconds:ve.toString()}:{},formattedRequiredAssets:k,onBehalf:n,txs:I,summary:b>0n?`Repay ${b.toString()} borrow shares (approval up to ${k} ${d.symbol}) on Morpho Blue market ${a}. Refresh if signing/inclusion takes more than ${ve} seconds.`:`Repay ${k} ${d.symbol} on Morpho Blue market ${a}.`,preview:M,formattedChanges:C,formattedNetOutflows:v}}async function $a(e,t,s){let r=ge(t,s);Ie(t,r);let n=r,l=r,a=e.clientFor(p),{marketId:o,marketParams:u,marketState:d}=await ue(a,t,!0),[m,c,f,b]=await Promise.all([Q(a,u.collateralToken,p),Se(a,o,n),Fe(a,u.oracle),Le(a,u,d,ve)]),w=z("withdrawAll",t.withdrawAll)===!0?c.collateral:Ae(t);if(w<=0n||w>c.collateral)throw new i(`Insufficient collateral to withdraw: requested ${w.toString()} base units, position holds ${c.collateral.toString()} base units.`);if(c.borrowShares>0n){let C=c.collateral-w,v=ke(C,f,u.lltv),x=ne(c.borrowShares,b.totalBorrowAssets,d.totalBorrowShares);if(x>v)throw new i(`Unhealthy collateral withdrawal: remaining max borrow ${v.toString()} would fall below current debt ${x.toString()} base units.`)}let h=w.toString(),y=e.formatAmount(h,m.decimals),g=[e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"withdrawCollateral",args:[u,w,n,l]}),value:"0",description:`Withdraw ${y} ${m.symbol} (${h} base units) collateral from Morpho market ${o}.`})],T=await e.preview(g,r),{formattedChanges:I,formattedNetOutflows:M}=ye(e,T);return{action:"morpho_withdraw_collateral",chainId:p,marketId:o,marketParams:ce(u),collateralToken:m,assets:h,formattedAssets:y,onBehalf:n,receiver:l,txs:g,summary:`Withdraw ${y} ${m.symbol} collateral from Morpho Blue market ${o}.`,preview:T,formattedChanges:I,formattedNetOutflows:M}}async function Da(e,t,s){let r=ge(t,s);Ie(t,r);let n=e.clientFor(p),{marketId:l,marketParams:a,marketState:o}=await ue(n,t,!0),u=z("wrapNative",t.wrapNative)===!0;if(u&&a.loanToken.toLowerCase()!==de.toLowerCase())throw new i("Native ETH wrapping is only supported when the market loanToken is WETH.");let d=Ae(t),m=d.toString(),[c,f]=await Promise.all([Q(n,a.loanToken,p),u?Promise.resolve(d):Vt(n,a.loanToken,r)]);if(f<d)throw new i(`Insufficient ${c.symbol} balance to lend: wallet holds ${f.toString()} base units, requested ${m}.`);let b=e.formatAmount(m,c.decimals),w=[];u&&w.push(e.unsignedTx({chainId:p,to:de,data:R({abi:_t,functionName:"deposit"}),value:m,description:`Wrap ${b} ETH into WETH at ${de}.`})),w.push(e.approval(a.loanToken,U,m,p)),w.push(e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"supply",args:[a,d,0n,r,"0x"]}),value:"0",description:`Lend ${b} ${c.symbol} (${m} base units) to Morpho market ${l}.`}));let h=xa(d,o.totalSupplyAssets,o.totalSupplyShares),y=await e.preview(w,r),{formattedChanges:k,formattedNetOutflows:g}=ye(e,y);return{action:"morpho_supply",chainId:p,marketId:l,marketParams:ce(a),loanToken:c,assets:m,formattedAssets:b,supplySharesEstimated:h.toString(),onBehalf:r,oak:ot(l),txs:w,summary:`${u?`Send ${b} ETH to wrap into WETH. `:""}Lend ${b} ${c.symbol} to Morpho Blue market ${l}. It earns the market supply rate and is exposed to the market's collateral, oracle and liquidity risk.`,preview:y,formattedChanges:k,formattedNetOutflows:g}}async function Ua(e,t,s){let r=ge(t,s);Ie(t,r);let n=e.clientFor(p),l=z("withdrawAll",t.withdrawAll)===!0;if(l&&(t.assets!==void 0||t.amount!==void 0))throw new i("Specify withdrawAll alone, without assets/amount.");let{marketId:a,marketParams:o,marketState:u}=await ue(n,t,!0),[d,m]=await Promise.all([Q(n,o.loanToken,p),Se(n,a,r)]);if(m.supplyShares===0n)throw new i(`This wallet has no lent ${d.symbol} on Morpho market ${a}.`);let c=rt(m.supplyShares,u.totalSupplyAssets,u.totalSupplyShares),f=l?0n:Ae(t),b=l?m.supplyShares:0n;if(!l&&f>c)throw new i(`Withdrawal exceeds the lent balance: requested ${f.toString()} base units, position holds about ${c.toString()}. Use withdrawAll for a full exit.`);let w=u.totalSupplyAssets>u.totalBorrowAssets?u.totalSupplyAssets-u.totalBorrowAssets:0n,h=l?c:f;if(h>w)throw new i(`Insufficient market liquidity: withdrawing ${h.toString()} base units needs idle assets, but only ${w.toString()} are available until borrowers repay. Withdraw at most that amount, or retry later.`);let y=e.formatAmount(h.toString(),d.decimals),g=[e.unsignedTx({chainId:p,to:U,data:R({abi:X,functionName:"withdraw",args:[o,f,b,r,r]}),value:"0",description:l?`Withdraw all ${m.supplyShares.toString()} supply shares (about ${y} ${d.symbol}) from Morpho market ${a}.`:`Withdraw ${y} ${d.symbol} (${f.toString()} base units) of lent assets from Morpho market ${a}.`})],T=await e.preview(g,r),{formattedChanges:I,formattedNetOutflows:M}=ye(e,T);return{action:"morpho_withdraw",chainId:p,marketId:a,marketParams:ce(o),loanToken:d,withdrawAssets:f.toString(),withdrawShares:b.toString(),estimatedAssets:h.toString(),formattedAssets:y,receiver:r,txs:g,summary:l?`Withdraw all lent ${d.symbol} (about ${y}, including interest) from Morpho Blue market ${a}.`:`Withdraw ${y} lent ${d.symbol} from Morpho Blue market ${a}.`,preview:T,formattedChanges:I,formattedNetOutflows:M}}async function zt(e,t,s){let r=await e.http(pa,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({query:t,variables:s})});if(!r.ok)throw new i(`Morpho GraphQL request failed (HTTP ${r.status}).`);let n=await r.json();if(n.errors?.length)throw new i("Morpho GraphQL returned query errors.");return n.data??{}}async function Wt(e){let t=`query Markets($chainId: Int!) {
2
2
  markets(first: 1000, where: { chainId_in: [$chainId] }) {
3
3
  items {
4
4
  marketId chain { id } lltv listed
@@ -1 +1 @@
1
- import{j as p}from"./6ZYLNB2B.js";import{a as d}from"./CY75R4FK.js";import{a as f}from"./6IM6A5VA.js";import{d as a,i as c}from"./73N3TOJL.js";import{a as m}from"./RETS2ZEK.js";import{a as i}from"./G6HCV67X.js";import{a as s}from"./5YS5V2LK.js";import{erc20Abi as u,zeroAddress as b}from"viem";function T(r,n,e=256,t=!1){if(typeof r!="string"||!/^[0-9]+$/.test(r))throw new s(`${n} must be a decimal base-unit string.`);let o=m(r);if(!t&&o===0n||o>=1n<<BigInt(e))throw new s(`${n} must be ${t?"a":"a positive"} uint${e}.`);return o}function g(r){return c(r,"Provide a token or contract address.",a)}function E(r){return typeof r=="string"&&["eth",d.toLowerCase()].includes(r.toLowerCase())?b:g(r)}function D(r){let n=r??50;if(typeof n!="number"||!Number.isInteger(n)||n<0||n>=1e4)throw new s("Slippage must be an integer from 0 to 9999 bps.");return n}async function N(r,n,e){if(n===b)return{address:d,symbol:"ETH",decimals:18,chainId:i};let t=r.clientFor(i),[o,w]=await Promise.all([t.readContract({address:n,abi:u,functionName:"symbol",blockNumber:e}),t.readContract({address:n,abi:u,functionName:"decimals",blockNumber:e})]);return{address:n,symbol:p(o,n),decimals:w,chainId:i}}async function S(r,n,e,t){return f(e),{txs:n,preview:await r.preview(n,e),summary:t}}function $(r,n){if(Object.keys(r).some(e=>!n.includes(e)))throw new s(`Provide only ${n.join(", ")}.`)}export{T as a,g as b,E as c,D as d,N as e,S as f,$ as g};
1
+ import{j as p}from"./6B3VVISQ.js";import{a as d}from"./3MLUCYCB.js";import{a as f}from"./43LI5NKJ.js";import{d as a,i as c}from"./NWNYJ26T.js";import{b as m}from"./IX3GZMTM.js";import{a as i}from"./FWD4L3CJ.js";import{a as s}from"./XSD5NL7J.js";import{erc20Abi as u,zeroAddress as b}from"viem";function T(r,n,e=256,t=!1){if(typeof r!="string"||!/^[0-9]+$/.test(r))throw new s(`${n} must be a decimal base-unit string.`);let o=m(r);if(!t&&o===0n||o>=1n<<BigInt(e))throw new s(`${n} must be ${t?"a":"a positive"} uint${e}.`);return o}function g(r){return c(r,"Provide a token or contract address.",a)}function E(r){return typeof r=="string"&&["eth",d.toLowerCase()].includes(r.toLowerCase())?b:g(r)}function D(r){let n=r??50;if(typeof n!="number"||!Number.isInteger(n)||n<0||n>=1e4)throw new s("Slippage must be an integer from 0 to 9999 bps.");return n}async function N(r,n,e){if(n===b)return{address:d,symbol:"ETH",decimals:18,chainId:i};let t=r.clientFor(i),[o,w]=await Promise.all([t.readContract({address:n,abi:u,functionName:"symbol",blockNumber:e}),t.readContract({address:n,abi:u,functionName:"decimals",blockNumber:e})]);return{address:n,symbol:p(o,n),decimals:w,chainId:i}}async function S(r,n,e,t){return f(e),{txs:n,preview:await r.preview(n,e),summary:t}}function $(r,n){if(Object.keys(r).some(e=>!n.includes(e)))throw new s(`Provide only ${n.join(", ")}.`)}export{T as a,g as b,E as c,D as d,N as e,S as f,$ as g};
@@ -0,0 +1 @@
1
+ import{a as j}from"./NCQFWPAW.js";import{a as v}from"./6OGDTEGH.js";import{K as A}from"./SSHCD6RZ.js";import{c as k}from"./P56RZC2M.js";import{a as O}from"./43LI5NKJ.js";import{a as x}from"./66F5ZH34.js";import{d as F,g as M,i as q,m as $}from"./NWNYJ26T.js";import{a as y}from"./FWD4L3CJ.js";import{a}from"./XSD5NL7J.js";import{encodeFunctionData as G,erc20Abi as R,getAddress as g,zeroAddress as z}from"viem";var D={genesis:g("0x575b7B7c97Ef3E21C82DAeB427899d583e1E913f"),bond:g("0xff32a969A0c567129eECD926D04657728E1980C1"),inverse:g("0x92166e94Eea5B7799b761653881692f881dFC4C9"),treasury:g("0x04822Ea321A0DEE6F40656172F29312104855d66"),pteam:g("0x650F58079dAa17ee28928c2F92d22291d038B2B0"),rwa:g("0x99B6eE6eDe47d9a8a9bfd03F728a99B789df1961"),premium:g("0x346e1a31171A0f7aC73909010b5435768d3B5462"),tax:g("0x086C58400b8708Ef993f256E12e752dcF0AC918e")},H=g("0x59F95461E68e0c77605299791E1449f175165B54"),_={genesis:["purchase","finalize","refund","claim"],bond:["deposit","redeem"],inverse:["swap"],treasury:["rebalanceToMorpho","rebalanceFromMorpho","mintNet","spendUsdg"],pteam:["exercise"],rwa:["redeem","depositInventory","pokeHwm","setDiscount","setInventoryMax","setHalt","setMenu","skim"],premium:["execute"],tax:["convert"]},V={genesis:["wired","finalized","finalizeTime","saleStart","saleDeadline","raisedRaw","totalRaised","registryLength"],bond:["wired","enabled","startTime","marketCount"],inverse:["active","price","capacityRemaining","spreadBps"],treasury:["wired","rfv","backingPerToken","liquidUsdg","morphoAssets","polRfv","morphoCapBps","morphoVault","canonicalPair"],pteam:["wired","holder","vestedFraction","exercisableNow","exercised","strikeWad","capBps","circulatingSupply","excludedFromFloat"],rwa:["manager","halted","inventory","inventoryMax","owedNet","bHwm","deskDiscountBps","VEST","MAX_DISCOUNT_BPS","INVENTORY_HARD_CAP","menu","routerSource","sleeve"],premium:["active","clipSize","lastExecuteAt","premiumThresholdWad","router","pairContract"],tax:["wired","pendingNet","teamBps","treasuryBps","teamWallet","router","pairContract"]},T=h=>JSON.parse(JSON.stringify(h,(P,E)=>typeof E=="bigint"?E.toString():E));function N(h){return q(h,"Provide a checksummed address.",F)}var ae=h=>{async function P(t){if(typeof t!="string"||!Object.hasOwn(D,t))throw new a("Choose a published NetNet financial product.");let c=t,e=D[c],r=j[c],u=h.clientFor(y);if(await u.getChainId()!==y)throw new a("NetNet requires chain 4663.");let n=await u.getBlock(),o=(w,I=[])=>u.readContract({address:e,abi:r,functionName:w,args:I,blockNumber:n.number}),[i,s,l,p]=await Promise.all([o("net"),o("usdg"),u.readContract({address:v.address,abi:R,functionName:"decimals",blockNumber:n.number}),u.readContract({address:k.address,abi:R,functionName:"decimals",blockNumber:n.number})]);if(N(i)!==v.address||N(s)!==k.address||l!==v.decimals||p!==k.decimals)throw new a("NetNet financial token pins or decimals do not match the deployment.");return{product:c,contract:e,abi:r,rpc:u,block:n,read:o}}async function E(t){O(t);let c=(e,r)=>({module:"netnet",id:`4663:${D.bond.toLowerCase()}:${e}`,chainId:y,incomplete:!0,assets:[],description:`NetNet bond notes unreadable: ${h.plainError(r)} Use netnet_financial_status with product bond to inspect notes.`});try{let e=await P("bond"),r=$(await e.read("noteCount",[t]),"Invalid NetNet bond note count."),u=r<50n?Number(r):50,n=[];for(let o=0;o<u;o++)try{let i=await e.read("notes",[t,BigInt(o)]);if(!Array.isArray(i)||i.length!==4)throw new a("Invalid NetNet bond note.");let[s,l,p,w]=i.map(C=>$(C,"Invalid NetNet bond note amount or timestamp."));if(l>s||w<=p||w>=1n<<64n)throw new a("Invalid NetNet bond note vesting or claimed amount.");let I=s-l;if(I===0n)continue;let S=e.block.timestamp>=w?s:e.block.timestamp<=p?0n:s*(e.block.timestamp-p)/(w-p),B=S>l?S-l:0n;n.push({module:"netnet",id:`4663:${e.contract.toLowerCase()}:${o}`,chainId:y,matured:e.block.timestamp>=w,assets:[{token:v,amount:I.toString()}],description:`NetNet bond note ${o}: ${I} NET base units outstanding; ${B} claimable now, vesting ends at Unix ${w}. Redeem vested NET with netnet_financial_action product bond operation redeem. Payment cannot be withdrawn. Block ${e.block.number}.`})}catch(i){n.push(c(String(o),i))}return r>BigInt(u)&&n.push({module:"netnet",id:`4663:${e.contract.toLowerCase()}:coverage`,chainId:y,incomplete:!0,assets:[],description:`NetNet bond positions checked the first ${u} of ${r} notes. Use netnet_financial_status product bond offset ${u} to read the remaining notes.`}),n}catch(e){return[c("unreadable",e)]}}let U=(t,c,e,r)=>({name:t,inputSchema:{type:"object",properties:c,required:e,additionalProperties:!1},execute:async(u,n)=>{try{if(O(n),Object.keys(u).some(o=>!Object.hasOwn(c,o)))throw new a("Unsupported NetNet financial argument.");return await r(u,n)}catch(o){throw new a(h.plainError(o))}}}),W={type:"string",enum:Object.keys(D)};return{positions:E,tools:[U("netnet_financial_status",{product:W,offset:{type:"integer",minimum:0},limit:{type:"integer",minimum:1,maximum:50}},["product"],async(t,c)=>{let e=await P(t.product),r=V[e.product],u=t.offset??0,n=t.limit??20;if(!Number.isSafeInteger(u)||Number(u)<0||!Number.isSafeInteger(n)||Number(n)<1||Number(n)>50)throw new a("Use a nonnegative offset and limit 1..50.");let o=await Promise.all(r.map(async s=>{try{return[s,{value:T(await e.read(s))}]}catch(l){return[s,{unavailable:h.plainError(l)}]}})),i={};if(e.product==="genesis")for(let s of["purchasedRaw","purchasedNetOf","claimedNet","claimableNetOf"])i[s]=T(await e.read(s,[c]));if(e.product==="bond"||e.product==="rwa"){i.pending=T(await e.read("pendingFor",[c]));let s=await e.read("noteCount",[c]);if(typeof s!="bigint"||s<0n)throw new a("Invalid NetNet note count.");let l=s<BigInt(Number(u)+Number(n))?s:BigInt(Number(u)+Number(n));i.noteCount=s.toString(),i.notes=await Promise.all(Array.from({length:Math.max(0,Number(l-BigInt(Number(u))))},async(p,w)=>({id:String(Number(u)+w),note:T(await e.read(e.product==="bond"?"notes":"noteAt",[c,BigInt(Number(u)+w)]))}))),i.nextOffset=l<s?l.toString():null,e.product==="bond"&&(i.markets=await Promise.all([0n,1n].map(async p=>{try{return{id:p.toString(),quoteToken:N(await e.read("quoteToken",[p])),priceWad:String(await e.read("bondPrice",[p]))}}catch(w){return{id:p.toString(),unavailable:h.plainError(w)}}})))}return e.product==="treasury"&&(i.isMinter=await e.read("isMinter",[c]),i.isSpender=await e.read("isSpender",[c])),{chainId:y,contract:e.contract,product:e.product,blockNumber:String(e.block.number),tokens:[v,k],metrics:Object.fromEntries(o),wallet:i,units:"Raw token amounts use each token\u2019s decimals. Prices, NAV, reserve values and capacityRemaining use 18-decimal USDG WAD. Note timestamps are Unix seconds.",operations:_[e.product],caveat:"An unavailable metric is not zero. Formulaic eligibility, oracle liveness, caps and vesting are checked by the action preview. RWA entry/router calldata and initial deployment wiring remain unsupported."}}),U("netnet_financial_action",{product:W,operation:{type:"string",enum:[...new Set(Object.values(_).flat())]},amount:x(),minAmountOut:x(),maxPriceWad:x(),maxPayment:x(),marketId:{type:"integer",enum:[0,1]},recipient:{type:"string"},halted:{type:"boolean"},token:{type:"string"},noteIds:{type:"array",maxItems:50,items:x()},menu:{type:"array",maxItems:32,items:{type:"object"}}},["product","operation"],async(t,c)=>{let e=await P(t.product),r=t.operation;if(typeof r!="string"||!_[e.product].includes(r))throw new a("This operation is not supported by the selected financial product.");let u=new Set(["product","operation"]),n=[],o,i=0n,s="",l=(...d)=>d.forEach(m=>u.add(m)),p=()=>(l("amount"),A(t.amount)),w=()=>(l("minAmountOut"),A(t.minAmountOut));if(e.product==="genesis"){if(r==="purchase"&&(i=p(),o=k,n=[i],s="Founding subscription; NET is claimable only after successful finalization and vesting. A failed sale requires refund."),r==="claim"&&await e.read("claimableNetOf",[c])===0n)throw new a("No vested founding NET is claimable by this wallet.")}else if(e.product==="bond")if(r==="deposit"){if(l("marketId","maxPriceWad"),t.marketId!==0&&t.marketId!==1)throw new a("Bond marketId must be 0 (USDG) or 1 (canonical LP).");let d=BigInt(t.marketId);if(N(await e.read("quoteToken",[d]))!==(d===0n?k.address:H))throw new a("Bond quote token is not the pinned USDG or canonical LP.");i=p(),o=d===0n?k:{address:H,decimals:18,symbol:"NET/USDG LP",chainId:y};let f=A(t.maxPriceWad),b=await e.read("bondPrice",[d]);if(typeof b!="bigint"||b===0n||b>f)throw new a("Bond price exceeds maxPriceWad or is invalid.");n=[d,i,f,c],s="Payment is exchanged for a non-transferable NET note with two-day linear vesting. Redeem vested NET with the same product; payment cannot be withdrawn."}else n=[c];else if(e.product==="inverse"){if(i=p(),o=v,n=[i,w()],s="Purchased NET is burned permanently; USDG pays directly to this wallet. Capacity is denominated in USDG WAD, not raw USDG.",await e.read("active")!==!0)throw new a("NetNet buyback is inactive: oracle, finalization or capacity is unavailable.")}else if(e.product==="pteam"){if(N(await e.read("holder"))!==g(c))throw new a("This wallet is not the immutable pTEAM holder.");let d=p();if(l("maxPayment"),d>await e.read("exercisableNow"))throw new a("The NET exercise amount exceeds the vested cap.");let m=await e.read("strikeWad");if(i=(d*m/10n**BigInt(v.decimals)+10n**12n-1n)/10n**12n,i===0n||i>A(t.maxPayment))throw new a("The exercise payment exceeds maxPayment or rounds to zero.");o=k,n=[d],s=`Exercise pays ${i} USDG base units into treasury reserves and mints ${d} NET base units to the immutable holder. No withdrawal or exercise reversal exists.`}else if(e.product==="treasury"){let d=p();if(r==="mintNet"||r==="spendUsdg"){l("recipient");let m=N(t.recipient);if(await e.read(r==="mintNet"?"isMinter":"isSpender",[c])!==!0)throw new a("This wallet lacks the fixed NetNet treasury minter/spender role.");n=[m,d],s=`Protocol treasury operation sends ${d} base units to ${m}; it does not deposit into this wallet\u2019s savings.`}else n=[d],s="Permissionless protocol reserve rebalance; assets remain owned by the NetNet treasury. The deployed fraction is constrained by the immutable cap."}else if(e.product==="rwa"){if(["depositInventory","setDiscount","setInventoryMax","setHalt","setMenu"].includes(r)&&N(await e.read("manager"))!==g(c))throw new a("This wallet lacks the immutable RWA manager role.");if(r==="redeem")if(l("noteIds"),t.noteIds===void 0)n=[c];else{if(!Array.isArray(t.noteIds)||!t.noteIds.length||t.noteIds.length>50)throw new a("Provide 1..50 unique note IDs.");let m=t.noteIds.map(b=>A(b,!0));if(new Set(m.map(String)).size!==m.length)throw new a("Note IDs must be unique.");let f=await e.read("noteCount",[c]);if(m.some(b=>b>=f))throw new a("RWA note ID is out of range.");n=[c,m]}else if(r==="setHalt"){if(l("halted"),typeof t.halted!="boolean")throw new a("Provide halted as a boolean.");n=[t.halted]}else if(r==="setMenu"){if(l("menu"),!Array.isArray(t.menu)||!t.menu.length||t.menu.length>32)throw new a("Provide 1..32 explicit RWA menu entries.");let m=t.menu.map(f=>{if(!f||typeof f!="object"||Array.isArray(f)||Object.keys(f).some(L=>!["token","feed","targetWeightBps","active"].includes(L)))throw new a("Invalid RWA menu fields.");let b=f;if(typeof b.active!="boolean")throw new a("RWA active must be boolean.");return{token:N(b.token),feed:N(b.feed),targetWeightBps:A(b.targetWeightBps,!0),active:b.active}});if(new Set(m.map(f=>f.token)).size!==m.length||m.reduce((f,b)=>f+b.targetWeightBps,0n)!==10000n||m.some(f=>f.active&&(f.token===z||f.feed===z)))throw new a("RWA menu tokens must be unique, weights sum to 10000, active feeds/tokens nonzero.");n=[m],s=`Replace the complete RWA equity menu: ${JSON.stringify(T(m))}.`}else if(r==="skim")l("token"),n=[N(t.token)],s=`Sweep eligible stray assets to sleeve ${N(await e.read("sleeve"))}, not to this wallet.`;else if(r!=="pokeHwm"){let m=p();if(n=[m],r==="depositInventory"&&(o=v,i=m,s="Inventory funding is one-way. The manager cannot withdraw these NET; they are committed to bond obligations."),r==="setDiscount"&&m>await e.read("MAX_DISCOUNT_BPS")||r==="setInventoryMax"&&m>await e.read("INVENTORY_HARD_CAP"))throw new a("RWA setting exceeds its immutable maximum.")}}else e.product==="premium"?(n=[w()],s="Permissionless mint-and-sell keeper operation; all sale proceeds go to NetNet treasury. The caller receives no reward."):(n=[p(),w()],s="Convert NET already owned by the tax collector. Proceeds split to treasury and team; the caller receives no reward and supplies no NET.");if(Object.keys(t).some(d=>!u.has(d)))throw new a("Unexpected fields for this NetNet operation.");if(o&&await e.rpc.readContract({address:o.address,abi:R,functionName:"balanceOf",args:[c],blockNumber:e.block.number})<i)throw new a(`Top up ${o.symbol}: needs ${i} base units.`);let I=`NetNet ${e.product}.${r}, contract ${e.contract}, chain ${y}, values ${JSON.stringify(T(n))}. ${o?`Approve exactly ${i} ${o.symbol} base units (${o.address}, decimals ${o.decimals}). `:""}${s}`,S=[...o?[h.approval(o.address,e.contract,i.toString(),y)]:[],h.unsignedTx({to:e.contract,data:G({abi:e.abi,functionName:r,args:n}),value:"0",chainId:y,description:I})],B=await h.preview(S,c),C=0n;for(let d of B.changes){if(!/^-?\d+$/.test(d.amount))throw new a("Invalid NetNet preview amount.");if(BigInt(d.amount)<0n&&(C-=BigInt(d.amount)),BigInt(d.amount)<0n&&(!o||d.token.chainId!==y||!M(d.token.address,o.address)||d.token.decimals!==o.decimals||-BigInt(d.amount)>i))throw new a("NetNet preview spends outside the exact input budget.")}if(C>i)throw new a("NetNet preview exceeds the aggregate input budget.");return{txs:S,preview:B,summary:I}})]}};export{D as a,H as b,ae as c};
@@ -0,0 +1 @@
1
+ import{a as u,f as I,g}from"./6JCEJ66K.js";import{a as P}from"./43LI5NKJ.js";import{m as B}from"./NWNYJ26T.js";import{a as e,i as _}from"./FWD4L3CJ.js";import{a as m}from"./XSD5NL7J.js";import{erc20Abi as C,getAddress as l}from"viem";var b=l(u.staking),f=l(u.agentVault),p=l(u.orbio),w={address:l(_[e].orbio.credit.address),chainId:e,symbol:"CREDIT",decimals:6},D=g.find(o=>o.type==="event"&&o.name==="AgentLaunched"),$=10000000n,A=o=>B(o,"Orbio returned an invalid on-chain amount.");async function F(o,N){try{P(N);let i=l(N),n=o.clientFor(e);if(await n.getChainId()!==e)throw new m(`Orbio requires chain ${e}.`);let a=await n.getBlockNumber(),[s,v,E,S,T]=await Promise.all([n.readContract({address:p,abi:C,functionName:"decimals",blockNumber:a}),n.readContract({address:b,abi:I,functionName:"positionOf",args:[i],blockNumber:a}),n.readContract({address:b,abi:I,functionName:"settledOf",args:[i],blockNumber:a}),n.readContract({address:p,abi:C,functionName:"balanceOf",args:[i],blockNumber:a}),n.readContract({address:w.address,abi:C,functionName:"balanceOf",args:[i],blockNumber:a})]);if(typeof s!="number"||!Number.isInteger(s)||s<0||s>36)throw new m("Orbio returned invalid ORBIO decimals.");let h={address:p,chainId:e,symbol:"ORBIO",decimals:s},R=[],d=(t,r,c,k)=>{let O=A(c);O!==0n&&R.push({module:"orbio",id:`${e}:${t}`,chainId:e,assets:[{token:{...r},amount:O.toString()}],description:`${k}: ${O} ${r.symbol} base units (${r.decimals} decimals).`})};d(`${b}:principal`,h,v,"Staked ORBIO principal; withdraw with orbio_unstake"),d(`${b}:credit`,w,E,"Claim settled staking CREDIT with orbio_claim_staking"),d(`${p}:held`,h,S,"Held ORBIO in this wallet"),d(`${w.address}:held`,w,T,"Held unactivated CREDIT in this wallet");let y=new Set;for(let t=0n;t<=a;t+=$){let r=t+$-1n<a?t+$-1n:a,c=await n.getLogs({address:f,event:D,args:{owner:i},fromBlock:t,toBlock:r,strict:!0});for(let k of c)y.add(A(k.args.agentId))}for(let t of y){let[r,c]=await Promise.all([n.readContract({address:f,abi:g,functionName:"stakeOf",args:[t],blockNumber:a}),n.readContract({address:f,abi:g,functionName:"unlocksAt",args:[t],blockNumber:a})]);d(`${f}:agent:${t}`,h,r,`ORBIO principal staked for owned agent ${t}; principal unlock time ${A(c)} (Unix seconds); withdraw with orbio_agent_withdraw_principal`)}return R}catch(i){throw new m(o.plainError(i))}}export{F as a};
@@ -0,0 +1 @@
1
+ import{c as k,i as S,l as O,m as R,n as $}from"./NWNYJ26T.js";import{a as f,i as P}from"./FWD4L3CJ.js";import{a as c}from"./XSD5NL7J.js";import{a as A}from"./JXOEJPJ4.js";import{encodeFunctionData as x,erc20Abi as E,parseAbi as U,zeroAddress as j}from"viem";var g=P[f].merkl.distributor.address,H=["function accessControlManager() view returns (address)","function isGovernor(address) view returns (bool)","function isGovernorOrGuardian(address) view returns (bool)","function canUpdateMerkleRoot(address) view returns (uint256)","function mainOperators(address,address) view returns (uint256)","function disputeToken() view returns (address)","function disputeAmount() view returns (uint256)","function disputer() view returns (address)","function endOfDisputePeriod() view returns (uint48)","function getMerkleRoot() view returns (bytes32)","function getEpochDuration() view returns (uint32)","function disputePeriod() view returns (uint48)","function upgradeabilityDeactivated() view returns (uint256)","function disputeTree(string)","function updateTree((bytes32 merkleRoot,bytes32 ipfsHash))","function toggleTrusted(address)","function toggleMainOperatorStatus(address,address)","function revokeUpgradeability()","function setEpochDuration(uint32)","function resolveDispute(bool)","function revokeTree()","function recoverERC20(address,address,uint256)","function setDisputePeriod(uint48)","function setDisputeToken(address)","function setDisputeAmount(uint256)"],y=U(H),F={type:"string",pattern:"^\\d+$"},C={type:"string",pattern:"^0x[0-9a-fA-F]{64}$"},G="Provide a valid address.";function m(o,l=!1){let n=S(o,G);return l?n:O(n,G)}function _(o,l=256){return $(o,`Value exceeds uint${l}.`,{bits:l})}function b(o){return R(o,"Merkl returned invalid protocol state.")}function I(o){return typeof o=="number"&&Number.isSafeInteger(o)&&o>=0?String(o):b(o).toString()}var D={updateTree:["merkleRoot","ipfsHash"],toggleTrusted:["target","enabled"],toggleMainOperatorStatus:["target","token","enabled"],revokeUpgradeability:[],setEpochDuration:["amount"],resolveDispute:["valid"],revokeTree:[],recoverERC20:["token","recipient","amount"],setDisputePeriod:["amount"],setDisputeToken:["token"],setDisputeAmount:["amount"]},K=o=>{let l=()=>o.clientFor(f),n=(r,i=[],e=g)=>l().readContract({address:e,abi:y,functionName:r,args:i}),h=(r,i,e,p)=>({name:`merkl_${r}`,inputSchema:{type:"object",properties:i,required:e,additionalProperties:!1},execute:async(u,s)=>{try{let a=Object.keys(u).find(d=>!Object.hasOwn(i,d));if(a)throw new c(`Unsupported Merkl input: ${a}.`);return await p(u,m(s))}catch(a){throw new c(o.plainError(a))}}}),z=async(r,i,e,p)=>{let u=[o.unsignedTx({to:g,data:x({abi:y,functionName:r,args:i}),value:"0",chainId:f,description:e})],s=await o.preview(u,p);return{txs:u,preview:s,summary:`Powered by Merkl \u2014 https://app.merkl.xyz. ${e} ${s.summary}`}};return{tools:[h("distributor_status",{},[],async(r,i)=>{let[e,p,u,s,a,d,t,w,N]=await Promise.all([n("getMerkleRoot"),n("disputeToken"),n("disputeAmount"),n("disputer"),n("endOfDisputePeriod"),n("getEpochDuration"),n("disputePeriod"),n("upgradeabilityDeactivated"),n("accessControlManager")]);if(typeof e!="string"||!/^0x[0-9a-fA-F]{64}$/.test(e)||typeof d!="number"||!Number.isInteger(d)||d<0||d>4294967295)throw new c("Merkl returned invalid Distributor state.");let v=m(N),[M,T]=await Promise.all([n("isGovernor",[i],v),n("isGovernorOrGuardian",[i],v)]);if(typeof M!="boolean"||typeof T!="boolean")throw new c("Merkl returned invalid governance roles.");return{chainId:f,distributor:g,root:e,disputeToken:m(p,!0),disputeAmount:b(u).toString(),disputer:m(s,!0),endOfDisputePeriod:I(a),epochDuration:String(d),disputePeriod:I(t),upgradeabilityDeactivated:b(w).toString(),accessControlManager:v,governor:M,governorOrGuardian:T,summary:"Powered by Merkl \u2014 https://app.merkl.xyz. Dispute amounts are token base units. Opening a dispute locks collateral until governor resolution; a rejected dispute forfeits it."}}),h("dispute",{reason:{type:"string",minLength:1,maxLength:2e3}},["reason"],async(r,i)=>{if(typeof r.reason!="string"||!r.reason.trim()||r.reason.length>2e3)throw new c("Provide a public dispute reason of 1 to 2000 characters.");let e=m(await n("disputeToken")),p=b(await n("disputeAmount")),[u,s]=await Promise.all([l().readContract({address:e,abi:E,functionName:"symbol"}),l().readContract({address:e,abi:E,functionName:"decimals"})]);if(typeof u!="string"||!u.trim()||typeof s!="number"||!Number.isInteger(s)||s<0||s>255)throw new c("Merkl dispute token metadata is invalid.");let a=`Dispute Merkl's tree: ${r.reason}. Lock ${p} ${A(u)} base units (token ${e}, decimals ${s}) until governor resolution; rejection forfeits the deposit. There is no unilateral withdrawal.`,d=[...p?[o.approval(e,g,p.toString(),f)]:[],o.unsignedTx({to:g,data:x({abi:y,functionName:"disputeTree",args:[r.reason]}),value:"0",chainId:f,description:a})],t=await o.preview(d,i);return{txs:d,preview:t,deposit:{token:{address:e,symbol:u,decimals:s,chainId:f},amount:p.toString()},summary:`Powered by Merkl \u2014 https://app.merkl.xyz. ${a} ${t.summary}`}}),h("distributor_admin",{operation:{enum:Object.keys(D)},target:k,token:k,recipient:k,amount:F,enabled:{type:"boolean"},valid:{type:"boolean"},merkleRoot:C,ipfsHash:C},["operation"],async(r,i)=>{let e=String(r.operation);if(!Object.hasOwn(D,e))throw new c("Choose a supported Distributor operation.");let p=D[e];for(let t of Object.keys(r))if(t!=="operation"&&!p.includes(t))throw new c(`Input ${t} does not match this Distributor operation.`);let u=m(await n("accessControlManager")),s=await n("isGovernor",[i],u);if(typeof s!="boolean")throw new c("Merkl returned invalid governor status.");if(!s&&!(e==="updateTree"?await n("canUpdateMerkleRoot",[i])===1n:e==="toggleMainOperatorStatus"&&r.token!==j?await n("isGovernorOrGuardian",[i],u)===!0:!1))throw new c("The connected wallet lacks the required Merkl governance role.");let a=p.map(t=>{if(t==="enabled"||t==="valid"){if(typeof r[t]!="boolean")throw new c(`Provide ${t} as boolean.`);return r[t]}if(t==="amount"){let w=_(r[t],e==="setEpochDuration"?32:e==="setDisputePeriod"?48:256);return e==="setEpochDuration"?Number(w):w}if(t==="merkleRoot"||t==="ipfsHash"){if(typeof r[t]!="string"||!/^0x[0-9a-fA-F]{64}$/.test(r[t]))throw new c("Provide a bytes32 root and IPFS hash.");return r[t]}return m(r[t],t==="token"&&e==="toggleMainOperatorStatus")}),d=a;if(e==="updateTree"&&(d=[{merkleRoot:a[0],ipfsHash:a[1]}]),e==="toggleTrusted"||e==="toggleMainOperatorStatus"){let t=await n(e==="toggleTrusted"?"canUpdateMerkleRoot":"mainOperators",e==="toggleTrusted"?[a[0]]:a.slice(0,2));if(t!==0n&&t!==1n)throw new c("Merkl returned invalid authorization state.");if(t===1n===r.enabled)return{txs:[],summary:"Powered by Merkl \u2014 https://app.merkl.xyz. Authorization already has the requested state."};d=a.slice(0,-1)}return z(e,d,`Merkl Distributor ${e} ${JSON.stringify(r)}. Governance affects every claimant. Upgradeability revocation is permanent; dispute resolution returns or forfeits collateral. Authorization operations toggle the observed state; re-preview if state changes.`,i)})]}};export{K as a};
@@ -0,0 +1 @@
1
+ import{a as n,b as o,c,g as b,h as i}from"./2MZXTOZU.js";import{e as m,h as t}from"./NWNYJ26T.js";import{a as d}from"./FWD4L3CJ.js";import{a}from"./XSD5NL7J.js";var p="LayerBank's setup no longer matches what Oak checked. Nothing was signed.";async function C(r,u){try{if(await r.getChainId()!==d)throw new a("LayerBank requires chain 4663.");let e=u??await r.getBlockNumber({cacheTime:0}),[l,k,f,s]=await Promise.all([r.readContract({address:o,abi:i,functionName:"POOL",blockNumber:e}),r.readContract({address:o,abi:i,functionName:"UNDERLYING_ASSET_ADDRESS",blockNumber:e}),r.readContract({address:o,abi:i,functionName:"decimals",blockNumber:e}),r.readContract({address:n,abi:b,functionName:"getReserveData",args:[c.address],blockNumber:e})]);if(!t(l,n)||!t(k,c.address)||f!==6||!m(s)||!t(s.aTokenAddress,o))throw new a(p);return s}catch(e){throw e instanceof a?e:new a("LayerBank setup could not be read. Please try again.")}}export{p as a,C as b};
@@ -0,0 +1 @@
1
+ import{b as Ae,o as ce}from"./3NJ5KQ3Q.js";import{a as ae}from"./3MLUCYCB.js";import{b as xe}from"./SPJCSEKP.js";import{a as Ie}from"./IOYRL6AY.js";import{a as Te}from"./66F5ZH34.js";import{e as W,g as p,i as be,n as ke}from"./NWNYJ26T.js";import{a as x,i as ye}from"./FWD4L3CJ.js";import{a}from"./XSD5NL7J.js";import{a as re}from"./JXOEJPJ4.js";import{decodeErrorResult as He,decodeEventLog as ie,encodeAbiParameters as D,encodeFunctionData as N,erc20Abi as Q,parseAbi as Ce,parseAbiParameters as q,toHex as ve,zeroAddress as $}from"viem";var h=ye[x].poolsTrade,J=h.liquidityLauncher.address,C=h.uerc20BeneficiaryVault.address,de=h.universalRouter.address,ne=10n**27n,U=(1n<<128n)-1n,Ne=`0x${"00".repeat(32)}`,R=63127652n,ue=100000n,oe=10000000n,Re=2000n,le={address:ae,symbol:"ETH",decimals:18,chainId:x},m=Ce(["function multicall(bytes[] data) payable returns (bytes[])","function createToken(address factory,string name,string symbol,uint8 decimals,uint128 initialSupply,address recipient,bytes tokenData) payable returns (address)","function distributeToken(address token,(address strategy,uint128 amount,bytes configData) distribution,bytes32 salt) payable","function distributeWithNative(address strategy,bytes configData,bytes32 salt,uint256 nativeAmount) payable","function getGraffiti(address sender) view returns (bytes32)","function getUERC20Address(string name,string symbol,uint8 decimals,address recipient,bytes32 graffiti) view returns (address)","function execute(bytes commands,bytes[] inputs,uint256 deadline) payable","function collectFees(uint256[] ids)","function claim(uint256 id,uint256 minCurrency0Amount,uint256 minCurrency1Amount)","function amounts(uint256 id) view returns (uint128 eth,uint128 token)","function ownerOf(uint256 id) view returns (address)","function getApproved(uint256 id) view returns (address)","function approve(address spender,uint256 id)","function safeTransferFrom(address from,address to,uint256 id)","function approve(address token,address spender,uint160 amount,uint48 expiration)","error V4TooLittleReceived(uint256 minAmountOut,uint256 amountOut)"]),z=Ce(["event TokenLaunched(bytes32 indexed poolId,address indexed token,address indexed feeSplitter,(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey)","event Transfer(address indexed from,address indexed to,uint256 indexed tokenId)"]),j=[h.instantLaunchStrategyFeesOn.address,h.instantLaunchStrategyFeesOff.address];function se(l){if(l.status!=="success")throw new a("The launch receipt did not succeed.");let c=[];for(let y of l.logs){let O=j.findIndex(F=>p(F,y.address));if(O===-1||y.topics[0]!=="0x3b3d2bafdcae274a232217e1f80ee4305d3af6aa25c8b14b1681bd68d18042a4")continue;let V=ie({abi:z,eventName:"TokenLaunched",data:y.data,topics:[...y.topics]}),{token:T,poolId:Y,poolKey:M,feeSplitter:Z}=V.args,_=O===0?h.feeSplitterFeesOn.address:h.feeSplitterFeesOff.address;if(!p(Z,_)||!p(M.currency0,$)||!p(M.currency1,T)||M.fee!==2500||M.tickSpacing!==25||!p(M.hooks,$))throw new a("The launch does not match the current native ETH strategy.");let ee=l.logs.filter(F=>p(F.address,h.v4PositionManager.address)).flatMap(F=>{if(F.topics[0]!=="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")return[];let P=ie({abi:z,eventName:"Transfer",data:F.data,topics:[...F.topics]}).args;return p(P.from,$)&&p(P.to,j[O])?[P.tokenId]:[]});if(ee.length!==1)throw new a("The launch receipt must identify one matching position mint.");c.push({token:T,poolId:Y,positionId:ee[0].toString(),creatorFees:O===0})}return c}function S(l){return be(l,"Provide a valid wallet or token address.")}function L(l,c,y=!1){return ke(l,`${c} is outside its supported range.`,{notString:`${c} must be an integer string in base units.`,positive:!y})}function X(l,c,y=!1){if(y&&l===void 0)return"";if(typeof l!="string"||!y&&!l.trim()||l.length>4096)throw new a(`Provide a valid ${c}.`);return l}function fe(l){if(typeof l!="string"||!/^0x[0-9a-fA-F]{64}$/.test(l))throw new a("Provide a valid launch transaction hash.");return l}function pe(l,c,y="minAmountOut"){let O=c.slippageBps??Ae;if(typeof O!="number")throw new a("Slippage must be an integer in basis points.");let V=ce(l.toString(),O),T=c[y]===void 0?BigInt(V):L(c[y],y,l===0n);if(T>l||l>0n&&T===0n||T>U)throw new a("The minimum output must be positive and no larger than the simulated output.");return T}var Me=l=>{let c=l.clientFor(x),y=(e,s,o,n)=>l.unsignedTx({to:e,data:s,value:o.toString(),chainId:x,description:n}),O=e=>{throw new a(l.plainError(e))};async function V(){if(await c.getChainId()!==x)throw new a("pools.trade requires Robinhood Chain 4663.")}async function T(e,s,o){let n=await l.preview(e,s),t=n.changes.map(({token:r,amount:d})=>{let i=d.startsWith("-");return`${i?"-":""}${l.formatAmount(i?d.slice(1):d,r.decimals)} ${re(r.symbol)} (${r.address}, chain ${r.chainId})`});return{txs:e,summary:[o,n.summary,...t].join(" ")}}async function Y(){return(await c.getBlock()).timestamp+600n}function M(e,s,o,n,t,r){let d=[$,e,2500,25,$],i=[D(q("((address,address,uint24,int24,address),bool,uint128,uint128,uint256,bytes)"),[[d,s,o,n,0n,"0x"]]),D(q("address,uint256"),[s?$:e,o]),D(q("address,address,uint256"),[s?e:$,t,0n])],f=[D(q("bytes,bytes[]"),["0x060c0e",i])];return{inputs:f,encoded:D(q("bytes,bytes[],uint256"),["0x10",f,r])}}async function Z(e,s){let o=await c.request({method:"eth_simulateV1",params:[{blockStateCalls:[{calls:e.map(i=>({from:s,gas:ve(Ie),to:i.to,data:i.data,value:ve(BigInt(i.value))}))}],validation:!1,traceTransfers:!1},"latest"]},{retryCount:0});if(!Array.isArray(o)||o.length!==1||!W(o[0])||!Array.isArray(o[0].calls)||o[0].calls.length!==e.length)throw new a("The output simulation returned a malformed response.");let n=o[0].calls;if(!n.slice(0,-1).every(i=>W(i)&&i.status==="0x1"&&!i.error))throw new a("A prerequisite failed during the output simulation.");let t=n.at(-1);if(!W(t)||t.status!=="0x0")throw new a("The output simulation did not return the expected minimum-output control.");let r=typeof t.returnData=="string"&&t.returnData!=="0x"?t.returnData:W(t.error)?t.error.data:void 0;if(typeof r!="string"||!/^0x[0-9a-fA-F]+$/.test(r))throw new a("The output simulation did not report an expected amount.");let d=He({abi:m,data:r});if(d.errorName!=="V4TooLittleReceived"||d.args[0]!==U||d.args[1]<=0n||d.args[1]>=U)throw new a("The output simulation did not report a valid amount.");return d.args[1]}let _=new Map,ee=2e3;async function F(e,s,o,n=()=>!0){let t=await c.getBlockNumber(),r=t<R?0n:(t-R)/oe+1n,d=1n,i=(u=1n)=>{if(d+=u,d>Re)throw new a("Pools.trade scan exceeds the 2000-request limit. Use launchTx for a specific launch; positions coverage is incomplete.")};i(r*BigInt(j.length+(e&&!o?1:0)));let f=new Map,w=new Set;for(let u=R;u<=t&&n();u+=oe){let b=u+oe-1n>t?t:u+oe-1n,v=(await Promise.all(j.map(k=>c.getLogs({address:k,event:z[0],...s?{args:{token:s}}:{},fromBlock:u,toBlock:b,strict:!0})))).flat(),E=[...new Set(v.map(k=>k.transactionHash))].filter(k=>!k||!f.has(k));for(let k=0;k<E.length&&n();k+=8)await Promise.all(E.slice(k,k+8).map(async B=>{if(!B)throw new a("A launch log is missing its transaction hash.");let H=_.get(B);H||(i(),H=await c.getTransactionReceipt({hash:B}),_.size>=ee&&_.delete(_.keys().next().value),_.set(B,H)),f.set(B,H),n()&&await o?.(H)}));if(!n())break;if(e&&!o){let k=await c.getLogs({address:C,event:z[1],args:{to:e},fromBlock:u,toBlock:b,strict:!0});for(let B of k){let H=ie({abi:z,eventName:"Transfer",data:B.data,topics:B.topics}).args;w.add(H.tokenId.toString())}}}return{receipts:[...f.values()],feeIds:w}}async function P(e){let o=(e.launchTx!==void 0?[await c.getTransactionReceipt({hash:fe(e.launchTx)})]:(await F(void 0,e.token===void 0?void 0:S(e.token))).receipts).flatMap(se).filter(n=>e.positionId!==void 0?n.positionId===L(e.positionId,"positionId").toString():p(n.token,S(e.token)));if(o.length!==1)throw new a("No unique current-strategy launch was found. Older strategy generations are unsupported.");return o[0]}async function Se(e,s){if(typeof e.creatorFees!="boolean")throw new a("creatorFees must be an explicit boolean; the choice is permanent.");if(e.pair!==void 0&&!p(S(e.pair),$)&&!p(S(e.pair),ae))throw new a("Only the native ETH pair is supported.");if(e.decimals!==void 0&&e.decimals!==18)throw new a("Instant Launch requires 18 decimals.");if(e.supply!==void 0&&L(e.supply,"supply")!==ne)throw new a("Instant Launch requires a supply of one billion tokens.");let o=S(e.feeBeneficiary);if(p(o,$)||p(o,J))throw new a("The fee beneficiary must be a wallet other than the launcher or zero address.");let n=X(e.name,"name"),t=X(e.symbol,"symbol"),r=e.initialBuy===void 0?0n:L(e.initialBuy,"initialBuy",!0);if(r>U)throw new a("The initial buy exceeds uint128.");if(r===0n&&e.minAmountOut!==void 0)throw new a("A minimum output requires an initial buy.");let d=await c.readContract({address:J,abi:m,functionName:"getGraffiti",args:[s]}),i=S(await c.readContract({address:h.uerc20Factory.address,abi:m,functionName:"getUERC20Address",args:[n,t,18,J,d]})),f=await c.getCode({address:i});if(f&&f!=="0x")throw new a("This wallet already launched that name and symbol.");let w=D(q("(string,string,string,bytes)"),[[X(e.description,"description",!0),X(e.website,"website",!0),X(e.imageUri,"image URI",!0),"0x"]]),u=e.creatorFees?j[0]:j[1],b=[N({abi:m,functionName:"createToken",args:[h.uerc20Factory.address,n,t,18,ne,J,w]}),N({abi:m,functionName:"distributeToken",args:[i,{strategy:u,amount:ne,configData:D(q("address"),[o])},Ne]})],v=await Y(),G=k=>{let B=[...b];if(r>0n){let H=D(q("(address,address,bytes)"),[[de,s,M(i,!0,r,k,s,v).encoded]]);B.push(N({abi:m,functionName:"distributeWithNative",args:[h.universalRouterStrategyApp.address,H,Ne,r]}))}return y(J,N({abi:m,functionName:"multicall",args:[B]}),r,`Atomic Instant Launch: creator fees ${e.creatorFees?"on":"off"} (permanent); beneficiary ${o}.`)},E=r>0n?pe(await Z([G(U)],s),e):0n;return T([G(E)],s,`Launch ${n} (${i}, chain 4663), supply 1000000000, decimals 18. Creator fees ${e.creatorFees?"on":"off"} are permanent; fee beneficiary ${o}. Creator ETH fees come from buys only (recorded 0.09996%); sells compound into locked liquidity. Initial-buy minimum ${E} token base units. Off-chain image/display unproven; no private metadata registration. No transaction sent.`)}async function Be(e,s,o){let n=L(e.amountIn,"amountIn");if(n>U)throw new a("The trade amount exceeds uint128.");let t=S(e.token);await P(e);let r=await Y(),d=[];o||(await c.readContract({address:t,abi:Q,functionName:"allowance",args:[s,h.permit2.address]})<n&&d.push(l.approval(t,h.permit2.address,n.toString(),x)),d.push(y(h.permit2.address,N({abi:m,functionName:"approve",args:[t,de,n,Number(r)]}),0n,`Permit the exact ${n} token base units until ${r}.`)));let i=u=>[...d,y(de,N({abi:m,functionName:"execute",args:["0x10",M(t,o,n,u,s,r).inputs,r]}),o?n:0n,`${o?"Buy":"Sell"} ${t} with minimum output ${u}.`)],f=await Z(i(U),s),w=pe(f,e);return T(i(w),s,`${o?"Buy":"Sell"} token ${t} (chain 4663, 18 decimals), amountIn ${n}, minimum output ${w} ${o?"token":"ETH"} base units (18 decimals). Recorded swap fee 0.2899%; creator ETH fees from buys only, none from sells. No transaction sent.`)}async function me(e,s,o){let n=await P(e),t=BigInt(n.positionId),r=n.creatorFees?h.feeSplitterFeesOn.address:h.feeSplitterFeesOff.address,d=await c.readContract({address:h.v4PositionManager.address,abi:m,functionName:"ownerOf",args:[t]});if(!p(d,r))throw new a("The position is not locked in its current-strategy splitter.");if(!o)return T([y(r,N({abi:m,functionName:"collectFees",args:[[t]]}),0n,`Collect fees for position ${t}; permissionless.`)],s,"Collect fees for the entitled recipients; collection does not transfer creator fees to the collector. No transaction sent.");if(!n.creatorFees)throw new a("Creator fees are permanently disabled for this position.");let i=await c.readContract({address:C,abi:m,functionName:"ownerOf",args:[t]});if(!p(i,s))throw new a("Only the current fee NFT holder is entitled to claim.");let f=await c.readContract({address:C,abi:m,functionName:"amounts",args:[t]}),w=pe(f[0],e,"minEth");if(f[1]!==0n)throw new a("The current buy-only creator fee configuration returned unexpected token fees.");return T([y(C,N({abi:m,functionName:"claim",args:[t,w,0n]}),0n,`Claim collected ETH fees for position ${t} to ${s}.`)],s,`Claim collected fees: ${f[0]} ETH base units (18 decimals), minimum ${w}. Uncollected fees require poolstrade_collect first. No transaction sent.`)}async function $e(e,s){let o=await P(e),n=S(e.to);if(p(n,$))throw new a("The token recipient cannot be the zero address.");let t=L(e.amount,"amount"),r=await te(o.token,await c.getBlockNumber());return T([y(r.address,N({abi:Q,functionName:"transfer",args:[n,t]}),0n,`Transfer exactly ${t} ${re(r.symbol)} base units to ${n}.`)],s,`Transfer ${t} token base units (token ${r.address}, decimals ${r.decimals}, chain ${r.chainId}) to ${n}. No approval; no transaction sent.`)}async function Fe(e,s){if(!Array.isArray(e.positionIds)||e.positionIds.length<1||e.positionIds.length>20||!Array.isArray(e.launchTxs)||e.launchTxs.length!==e.positionIds.length)throw new a("Provide 1 to 20 positionIds and one matching launchTxs entry for each.");let o=e.positionIds.map(d=>L(d,"positionId").toString());if(new Set(o).size!==o.length)throw new a("Each position ID must appear once.");let n=e.launchTxs.map(fe),t=new Map;for(let[d,i]of o.entries()){let w=(await P({positionId:i,launchTx:n[d]})).creatorFees?h.feeSplitterFeesOn.address:h.feeSplitterFeesOff.address,u=BigInt(i),b=await c.readContract({address:h.v4PositionManager.address,abi:m,functionName:"ownerOf",args:[u]});if(!p(b,w))throw new a("The position is not locked in its current-strategy splitter.");t.set(w,[...t.get(w)??[],u])}let r=[...t].map(([d,i])=>y(d,N({abi:m,functionName:"collectFees",args:[i]}),0n,`Collect fees for positions ${i.join(", ")}; permissionless.`));return T(r,s,"Collect fees in batches for the fixed entitled recipients. Collection does not pay the collector. No transaction sent.")}let K="Current native ETH Instant Launch strategies only. Crowd Launch and older deployments are not covered.";async function te(e,s){let[o,n]=await Promise.all([c.readContract({address:e,abi:Q,functionName:"symbol",blockNumber:s}),c.readContract({address:e,abi:Q,functionName:"decimals",blockNumber:s})]);if(typeof o!="string"||!o||o.length>256||n!==18)throw new a("The current launch token returned invalid metadata.");return{address:e,symbol:o,decimals:n,chainId:x}}async function he(e,s,o,n){let t=n??await te(e.token,o),r=await c.readContract({address:t.address,abi:Q,functionName:"balanceOf",args:[s],blockNumber:o});return{token:t,amount:r.toString(),humanAmount:l.formatAmount(r.toString(),t.decimals)}}async function Pe(e,s){let o=await P(e),n=await c.getBlockNumber();return{wallet:s,...await he(o,s,n),blockNumber:n.toString(),coverage:K}}async function Le(e,s){let o=fe(e.launchTx),n=await c.getTransactionReceipt({hash:o}),t=se(n);if(e.token!==void 0&&(t=t.filter(i=>p(i.token,S(e.token)))),e.positionId!==void 0&&(t=t.filter(i=>i.positionId===L(e.positionId,"positionId").toString())),!t.length)throw new a("The receipt contains no matching current Instant Launch. Crowd Launch and older strategies are not covered.");let r=await c.getBlockNumber(),d=await Promise.all(t.map(async i=>{let f=i.creatorFees?h.feeSplitterFeesOn.address:h.feeSplitterFeesOff.address,w=await c.readContract({address:h.v4PositionManager.address,abi:m,functionName:"ownerOf",args:[BigInt(i.positionId)],blockNumber:r});if(!p(w,f))throw new a("The position is not locked in its current-strategy splitter.");let u=i.creatorFees?{owner:await c.readContract({address:C,abi:m,functionName:"ownerOf",args:[BigInt(i.positionId)],blockNumber:r}),approved:await c.readContract({address:C,abi:m,functionName:"getApproved",args:[BigInt(i.positionId)],blockNumber:r}),collected:await c.readContract({address:C,abi:m,functionName:"amounts",args:[BigInt(i.positionId)],blockNumber:r})}:void 0,b=await te(i.token,r);return{...i,token:b,custodian:w,holding:await he(i,s,r,b),...u?{feeEntitlement:{owner:u.owner,approved:u.approved,collected:[{token:le,amount:u.collected[0].toString()},{token:b,amount:u.collected[1].toString()}],uncollectedFeesIncluded:!1}}:{}}}));return{launchTx:o,wallet:s,creator:n.from,blockNumber:r.toString(),launches:d,coverage:K}}async function Oe(e){let s=await c.getBlockNumber(),o=e.limit??20;if(typeof o!="number"||!Number.isInteger(o)||o<1||o>50)throw new a("limit must be an integer from 1 to 50.");let n=e.fromBlock===void 0?s>=R+ue?s-ue+1n:R:L(e.fromBlock,"fromBlock",!0),t=e.toBlock===void 0?s:L(e.toBlock,"toBlock",!0),r=0;if(e.cursor!==void 0){if(typeof e.cursor!="string"||!/^[0-9]{1,78}:[0-9]{1,78}:[0-9]{1,10}$/.test(e.cursor))throw new a("Provide the browse cursor exactly as returned.");let u=e.cursor.split(":"),b=BigInt(u[0]),v=BigInt(u[1]);if(e.fromBlock!==void 0&&n!==b||e.toBlock!==void 0&&t!==v)throw new a("The cursor does not match this block range.");n=b,t=v,r=Number(u[2])}if(s<R&&e.fromBlock===void 0&&e.toBlock===void 0&&e.cursor===void 0)return{launches:[],cursor:null,fromBlock:R.toString(),toBlock:s.toString(),coverage:K,predeployment:!0};if(n<R||t<n||t>s||t-n>=ue)throw new a("Choose a deployed block range of at most 100000 blocks, ending no later than the current head.");let d=await c.getLogs({address:j,event:z[0],fromBlock:n,toBlock:t,strict:!0});if(d.some(u=>u.blockNumber===null||u.logIndex===null||!u.transactionHash))throw new a("The launch feed returned an incomplete log.");if(d.sort((u,b)=>u.blockNumber===b.blockNumber?b.logIndex-u.logIndex:u.blockNumber>b.blockNumber?-1:1),r>d.length)throw new a("The browse cursor is outside the launch feed.");let i=new Map,f=[];for(let u of d.slice(r,r+o)){let b=u.transactionHash,v=i.get(b);v||(v=await c.getTransactionReceipt({hash:b}),i.set(b,v));let G=ie({abi:z,eventName:"TokenLaunched",data:u.data,topics:u.topics}).args,E=se(v).filter(k=>p(k.token,G.token)&&p(k.poolId,G.poolId));if(E.length!==1)throw new a("The launch feed log does not match one verified receipt launch.");f.push({...E[0],launchTx:b,blockNumber:u.blockNumber.toString(),token:await te(E[0].token,t),creator:v.from})}let w=r+o;return{launches:f,cursor:w<d.length?`${n}:${t}:${w}`:null,fromBlock:n.toString(),toBlock:t.toString(),coverage:K,previousToBlock:n>R?(n-1n).toString():null,summary:"Newest launches first within this fixed block range. Empty does not establish absence outside the range or covered strategies."}}async function ge(e,s,o){let n=await P(e);if(!n.creatorFees)throw new a("Creator fees are permanently disabled for this position.");let t=BigInt(n.positionId),r=await c.readContract({address:h.v4PositionManager.address,abi:m,functionName:"ownerOf",args:[t]});if(!p(r,h.feeSplitterFeesOn.address))throw new a("The position is not locked in its current-strategy splitter.");let d=await c.readContract({address:C,abi:m,functionName:"ownerOf",args:[t]});if(!p(d,s))throw new a("Only the current fee NFT holder can change this entitlement.");let i=S(o?e.to:e.spender);if(p(i,C)||o&&p(i,$))throw new a("The fee NFT recipient cannot be the vault or zero address.");let f=o?N({abi:m,functionName:"safeTransferFrom",args:[s,i,t]}):N({abi:m,functionName:"approve",args:[i,t]});return T([y(C,f,0n,o?`Transfer fee NFT ${t} to ${i}, including accrued and future fees.`:`Approve ${i} for fee NFT ${t} only; zero address revokes approval.`)],s,o?`Transfer the entire fee entitlement for position ${t} to ${i}. This includes collected and future fees; locked LP remains in its splitter. No transaction sent.`:`Set the exact single-NFT approval for position ${t} to ${i}. This permits transfer of that fee entitlement; zero address revokes. No transaction sent.`)}async function Ee(){return{chainId:x,instant:{supported:!0,supply:ne.toString(),decimals:18,currency:le,permanentCreatorFeeChoice:!0},crowd:{status:"BLOCKED",strategy:"0xbf1aB81f7d534b2CC0Da76fcf4d541322bB0e000",factory:"0x000000001F26a0044BaA66024e7b6599c61963F8",missing:"A verified Pools-specific auction configuration (BlockNumberish timing, reserve allocation, Q96 floor/tick, USD FDV conversion, issuance steps, locked LP plan) and a bytecode-matched factory-created auction ABI with success/refund fixtures. Generic CCA parameters are not a verified Pools Crowd Launch.",source:"https://github.com/Uniswap/sdks/blob/main/sdks/liquidity-launcher-sdk/src/addresses.ts"},coverage:K}}let g={type:"string"},I=Te(),we={chainId:{type:"integer",const:x},slippageBps:{type:"integer",minimum:0,maximum:9999}};function A(e,s,o,n){return{name:`poolstrade_${e}`,inputSchema:{type:"object",additionalProperties:!1,properties:{...we,...s},required:o},execute:async(t,r)=>{try{let d=new Set([...Object.keys(we),...Object.keys(s)]);if(Object.keys(t).some(i=>!d.has(i)))throw new a("Unsupported input for this pools.trade tool.");if(t.chainId!==void 0&&t.chainId!==x)throw new a("pools.trade requires chain 4663.");if(S(r),t.slippageBps!==void 0){if(typeof t.slippageBps!="number")throw new a("Slippage must be an integer in basis points.");ce("10000",t.slippageBps)}return await V(),await n(t,r)}catch(d){O(d)}}}}return{tools:[A("launch",{name:g,symbol:g,creatorFees:{type:"boolean",description:"Permanent choice; must be explicit."},feeBeneficiary:g,pair:g,decimals:{type:"integer",const:18},supply:I,initialBuy:I,minAmountOut:I,description:g,website:g,imageUri:g},["name","symbol","creatorFees","feeBeneficiary"],Se),...["buy","sell"].map(e=>A(e,{token:g,amountIn:I,minAmountOut:I,launchTx:g},["token","amountIn"],(s,o)=>Be(s,o,e==="buy"))),A("collect",{positionId:I,launchTx:g},["positionId"],(e,s)=>me(e,s,!1)),A("claim",{positionId:I,launchTx:g,minEth:I},["positionId"],(e,s)=>me(e,s,!0)),A("browse",{fromBlock:I,toBlock:I,limit:{type:"integer",minimum:1,maximum:50},cursor:g},[],Oe),A("balance",{token:g,launchTx:g},["token"],Pe),A("status",{launchTx:g,token:g,positionId:I},["launchTx"],Le),A("launch_options",{},[],Ee),A("fee_transfer",{positionId:I,launchTx:g,to:g},["positionId","to"],(e,s)=>ge(e,s,!0)),A("fee_approve",{positionId:I,launchTx:g,spender:g},["positionId","spender"],(e,s)=>ge(e,s,!1)),A("transfer",{token:g,amount:I,to:g,launchTx:g},["token","amount","to"],$e),A("collect_many",{positionIds:{type:"array",items:I,minItems:1,maxItems:20},launchTxs:{type:"array",items:g,minItems:1,maxItems:20}},["positionIds","launchTxs"],Fe)],positions:async e=>{S(e);let s=[],o=0,n=!0,t,r=i=>({module:"poolstrade",id:"poolstrade-discovery-incomplete",chainId:x,assets:[],incomplete:!0,description:`${i} Checked ${o} launch receipts. Readable holdings are retained. Check a known launch with poolstrade_status {"launchTx":"<hash>"} or its token holding with poolstrade_balance {"token":"<address>","launchTx":"<hash>"}. Crowd Launch and older deployments are outside this reader's coverage.`}),d=async()=>{await V(),n&&await F(e,void 0,async i=>{o++;for(let f of se(i)){if(!n)return;let w=f.creatorFees&&p(await c.readContract({address:C,abi:m,functionName:"ownerOf",args:[BigInt(f.positionId)]}),e);if(!n)return;if(!w&&!p(i.from,e))continue;let u=w?[{token:le,amount:(await c.readContract({address:C,abi:m,functionName:"amounts",args:[BigInt(f.positionId)]}))[0].toString()}]:[];n&&s.push({module:"poolstrade",id:f.positionId,chainId:x,assets:u,description:`Current Instant Launch ${f.token} (18 decimals, supply 1000000000), pool ${f.poolId}; creator fees ${f.creatorFees?"on":"off"} (permanent). ${w?"Collected ETH fees only; uncollected fees excluded.":"Launch record; no fee entitlement held."} Liquidity is permanently locked.`})}},()=>n)};try{return await Promise.race([d().then(()=>!0),new Promise(f=>{t=setTimeout(()=>{n=!1,f(!1)},6e3)})])?s:[...s,r("Pools.trade global launch discovery reached its 6000 ms read budget; the historical scan is incomplete.")]}catch(i){return[...s,r(`Pools.trade discovery could not finish: ${l.plainError(i)}`)]}finally{n=!1,t!==void 0&&clearTimeout(t)}}}};function Qe(l){return xe("poolstrade",[Me(l)])}export{se as a,Me as b,Qe as c};
@@ -1 +1 @@
1
- import{e as h}from"./73N3TOJL.js";import{a as e}from"./5YS5V2LK.js";import{getAddress as y,isAddress as m,keccak256 as E,toBytes as _}from"viem";var l={source:"https://heyresearch.xyz/openapi.json",retrievedAt:"2026-11-02T21:21:26Z",sha256:"789fdd4f67e290e4c75f6c5992041a465b57dd55fa8d4ac5d4136a7145095ffa",note:"Excerpt of two operations only. No other operation is described here; the 55-operation catalogue.json keeps its own older pin.",operations:[{operation:"getProofOfShipShips",path:"/api/v1/proof-of-ship/ships",summary:"The ships HEY counts for a project in a closed window, unsigned",parameters:[{name:"slug",in:"query",required:!0,schema:{type:"string",pattern:"^[a-z0-9][a-z0-9-]{0,79}$",maxLength:80,minLength:1}},{name:"since",in:"query",required:!0,schema:{type:"integer",minimum:0}},{name:"until",in:"query",required:!0,schema:{type:"integer",minimum:0}}],format:"json",response:{type:"object",required:["slug","currentSlug","since","until","ships","evidenceIds","evidenceUrls","evidenceHash","definition"],properties:{slug:{type:"string"},currentSlug:{type:"string"},since:{type:"integer"},until:{type:"integer"},ships:{type:"integer",minimum:0},evidenceIds:{type:"array",items:{type:"string"}},evidenceUrls:{type:"array",items:{type:"string"}},evidenceHash:{type:"string",pattern:"^0x[0-9a-f]{64}$"},definition:{type:"string"}}}},{operation:"getProofOfShipTie",path:"/api/v1/proof-of-ship/tie",summary:"The payout addresses HEY would sign a Proof of Ship attestation for",parameters:[{name:"slug",in:"query",required:!0,schema:{type:"string",pattern:"^[a-z0-9][a-z0-9-]{0,79}$",maxLength:80,minLength:1}}],format:"json",response:{type:"object",required:["slug","currentSlug","payable","ties"],properties:{slug:{type:"string",description:"The slug as asked."},currentSlug:{type:"string",description:"The page's current slug."},payable:{type:"boolean",description:"Whether `ties` holds an address the attestation would accept as `builder`."},ties:{type:"array",items:{type:"object",required:["kind","address"],properties:{kind:{type:"string",enum:["wallet_claim","token_deployer"]},address:{type:"string",pattern:"^0x[0-9a-fA-F]{40}$",description:"Checksummed."}}}},reason:{type:"string",enum:["no_token","token_not_verified","issuer_token","site_disclaims_contract","site_names_another_contract","contested","no_tie"],description:"Present only when `ties` is empty."},attestationsPaused:{type:"boolean",enum:[!0],description:"Present only while the operator has paused attestations."}}}}]};var B="Builder evidence, not a trading signal. HEY Research Lab tracks builder activity only. It is not an endorsement, audit or rating.",v=["getProofOfShipShips","getProofOfShipTie"],g=/^[a-z0-9][a-z0-9-]{0,79}$/,S=/^ship:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,P=/^0x[0-9a-f]{64}$/,H=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u,k="https://heyresearch.xyz/evidence/",O=400*86400,Y=["wallet_claim","token_deployer"],x=["no_token","token_not_verified","issuer_token","site_disclaims_contract","site_names_another_contract","contested","no_tie"],I=["chain","chainId","chain_id"];function A(r){return v.includes(r)}function f(r){return typeof r=="number"&&Number.isSafeInteger(r)&&r>=0}function T(r,t,n=Math.floor(Date.now()/1e3)){if(!A(r))throw new e("Choose getProofOfShipShips or getProofOfShipTie.");if(!h(t))throw new e("Provide the documented parameters as an object.");let o=l.operations.find(i=>i.operation===r);for(let i of Object.keys(t)){if(I.includes(i))throw new e("Proof of ship reads cover Robinhood Chain mainnet (4663) only and take no chain parameter.");if(!o.parameters.some(d=>d.name===i))throw new e(`Unsupported parameter ${i} for ${r}.`)}for(let i of o.parameters)if(i.required&&t[i.name]===void 0)throw new e(`Provide ${i.name} for ${r}.`);if(typeof t.slug!="string"||!g.test(t.slug))throw new e("Provide the project slug exactly as HEY publishes it: lower-case letters, digits and hyphens, at most 80 characters.");if(r==="getProofOfShipTie")return;let{since:a,until:s}=t;if(!f(a)||!f(s))throw new e("Provide since and until as whole unix seconds.");if(s>n)throw new e("The window must have ended: until cannot be in the future.");if(a>s)throw new e("The window must start before it ends.");if(s-a>O)throw new e("The window can be at most 400 days long.")}function p(r,t){let n=r[t];if(typeof n!="string"||!g.test(n))throw new e(`HEY returned an unexpected ${t}. Please try again.`);return n}function q(r,t){if(p(t,"slug")!==r.slug)throw new e("HEY returned a different project than the one requested.");if(p(t,"currentSlug"),t.since!==r.since||t.until!==r.until)throw new e("HEY returned a different window than the one requested.");let{ships:n,evidenceIds:o,evidenceUrls:a,evidenceHash:s,definition:i}=t;if(!f(n)||!Array.isArray(o)||!Array.isArray(a))throw new e("HEY returned an unexpected ships count. Please try again.");if(!o.every(u=>typeof u=="string"&&S.test(u)))throw new e("HEY returned an evidence id that is not a ship receipt.");let d=o;if(!d.every((u,c)=>c===0||d[c-1]<u))throw new e("HEY returned evidence ids that are not sorted and unique.");if(n!==d.length)throw new e("HEY returned a ships count that does not match its evidence ids.");if(a.length!==d.length||!d.every((u,c)=>a[c]===`${k}${u}`))throw new e("HEY returned an evidence link that is not the published HEY receipt link.");if(typeof s!="string"||!P.test(s)||E(_(d.join(",")))!==s)throw new e("HEY returned an evidence hash that does not match its evidence ids.");if(typeof i!="string"||!i||H.test(i))throw new e("HEY returned an unexpected counting definition. Please try again.")}function R(r,t){if(p(t,"slug")!==r.slug)throw new e("HEY returned a different project than the one requested.");p(t,"currentSlug");let{payable:n,ties:o,reason:a,attestationsPaused:s}=t;if(typeof n!="boolean"||!Array.isArray(o))throw new e("HEY returned an unexpected tie answer. Please try again.");for(let i of o)if(!h(i)||!Y.includes(i.kind)||typeof i.address!="string"||!m(i.address,{strict:!1})||y(i.address)!==i.address)throw new e("HEY returned a tie that is not a known kind with a checksummed address.");if(n!==o.length>0)throw new e("HEY returned a payable flag that does not match its ties.");if(o.length?a!==void 0:!x.includes(a))throw new e("HEY returned an unexpected reason for the tie answer.");if(s!==void 0&&s!==!0)throw new e("HEY returned an unexpected attestation pause flag.")}function D(r,t,n,o=Math.floor(Date.now()/1e3)){if(T(r,t,o),!h(n)||!Object.keys(n).length||n.error!==void 0)throw new e("HEY returned an unexpected response. Please try again.");if(n.chainId!==void 0&&n.chainId!==4663||n.chain_id!==void 0&&n.chain_id!==4663)throw new e("HEY returned another chain.");if(n.nextCursor!=null||n.nextOffset!=null)throw new e("HEY signalled a continuation that this read does not support, so the answer may be incomplete.");r==="getProofOfShipShips"?q(t,n):R(t,n)}export{l as a,B as b,v as c,T as d,D as e};
1
+ import{e as h}from"./NWNYJ26T.js";import{a as e}from"./XSD5NL7J.js";import{getAddress as y,isAddress as m,keccak256 as E,toBytes as _}from"viem";var l={source:"https://heyresearch.xyz/openapi.json",retrievedAt:"2026-11-02T21:21:26Z",sha256:"789fdd4f67e290e4c75f6c5992041a465b57dd55fa8d4ac5d4136a7145095ffa",note:"Excerpt of two operations only. No other operation is described here; the 55-operation catalogue.json keeps its own older pin.",operations:[{operation:"getProofOfShipShips",path:"/api/v1/proof-of-ship/ships",summary:"The ships HEY counts for a project in a closed window, unsigned",parameters:[{name:"slug",in:"query",required:!0,schema:{type:"string",pattern:"^[a-z0-9][a-z0-9-]{0,79}$",maxLength:80,minLength:1}},{name:"since",in:"query",required:!0,schema:{type:"integer",minimum:0}},{name:"until",in:"query",required:!0,schema:{type:"integer",minimum:0}}],format:"json",response:{type:"object",required:["slug","currentSlug","since","until","ships","evidenceIds","evidenceUrls","evidenceHash","definition"],properties:{slug:{type:"string"},currentSlug:{type:"string"},since:{type:"integer"},until:{type:"integer"},ships:{type:"integer",minimum:0},evidenceIds:{type:"array",items:{type:"string"}},evidenceUrls:{type:"array",items:{type:"string"}},evidenceHash:{type:"string",pattern:"^0x[0-9a-f]{64}$"},definition:{type:"string"}}}},{operation:"getProofOfShipTie",path:"/api/v1/proof-of-ship/tie",summary:"The payout addresses HEY would sign a Proof of Ship attestation for",parameters:[{name:"slug",in:"query",required:!0,schema:{type:"string",pattern:"^[a-z0-9][a-z0-9-]{0,79}$",maxLength:80,minLength:1}}],format:"json",response:{type:"object",required:["slug","currentSlug","payable","ties"],properties:{slug:{type:"string",description:"The slug as asked."},currentSlug:{type:"string",description:"The page's current slug."},payable:{type:"boolean",description:"Whether `ties` holds an address the attestation would accept as `builder`."},ties:{type:"array",items:{type:"object",required:["kind","address"],properties:{kind:{type:"string",enum:["wallet_claim","token_deployer"]},address:{type:"string",pattern:"^0x[0-9a-fA-F]{40}$",description:"Checksummed."}}}},reason:{type:"string",enum:["no_token","token_not_verified","issuer_token","site_disclaims_contract","site_names_another_contract","contested","no_tie"],description:"Present only when `ties` is empty."},attestationsPaused:{type:"boolean",enum:[!0],description:"Present only while the operator has paused attestations."}}}}]};var B="Builder evidence, not a trading signal. HEY Research Lab tracks builder activity only. It is not an endorsement, audit or rating.",v=["getProofOfShipShips","getProofOfShipTie"],g=/^[a-z0-9][a-z0-9-]{0,79}$/,S=/^ship:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,P=/^0x[0-9a-f]{64}$/,H=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u,k="https://heyresearch.xyz/evidence/",O=400*86400,Y=["wallet_claim","token_deployer"],x=["no_token","token_not_verified","issuer_token","site_disclaims_contract","site_names_another_contract","contested","no_tie"],I=["chain","chainId","chain_id"];function A(r){return v.includes(r)}function f(r){return typeof r=="number"&&Number.isSafeInteger(r)&&r>=0}function T(r,t,n=Math.floor(Date.now()/1e3)){if(!A(r))throw new e("Choose getProofOfShipShips or getProofOfShipTie.");if(!h(t))throw new e("Provide the documented parameters as an object.");let o=l.operations.find(i=>i.operation===r);for(let i of Object.keys(t)){if(I.includes(i))throw new e("Proof of ship reads cover Robinhood Chain mainnet (4663) only and take no chain parameter.");if(!o.parameters.some(d=>d.name===i))throw new e(`Unsupported parameter ${i} for ${r}.`)}for(let i of o.parameters)if(i.required&&t[i.name]===void 0)throw new e(`Provide ${i.name} for ${r}.`);if(typeof t.slug!="string"||!g.test(t.slug))throw new e("Provide the project slug exactly as HEY publishes it: lower-case letters, digits and hyphens, at most 80 characters.");if(r==="getProofOfShipTie")return;let{since:a,until:s}=t;if(!f(a)||!f(s))throw new e("Provide since and until as whole unix seconds.");if(s>n)throw new e("The window must have ended: until cannot be in the future.");if(a>s)throw new e("The window must start before it ends.");if(s-a>O)throw new e("The window can be at most 400 days long.")}function p(r,t){let n=r[t];if(typeof n!="string"||!g.test(n))throw new e(`HEY returned an unexpected ${t}. Please try again.`);return n}function q(r,t){if(p(t,"slug")!==r.slug)throw new e("HEY returned a different project than the one requested.");if(p(t,"currentSlug"),t.since!==r.since||t.until!==r.until)throw new e("HEY returned a different window than the one requested.");let{ships:n,evidenceIds:o,evidenceUrls:a,evidenceHash:s,definition:i}=t;if(!f(n)||!Array.isArray(o)||!Array.isArray(a))throw new e("HEY returned an unexpected ships count. Please try again.");if(!o.every(u=>typeof u=="string"&&S.test(u)))throw new e("HEY returned an evidence id that is not a ship receipt.");let d=o;if(!d.every((u,c)=>c===0||d[c-1]<u))throw new e("HEY returned evidence ids that are not sorted and unique.");if(n!==d.length)throw new e("HEY returned a ships count that does not match its evidence ids.");if(a.length!==d.length||!d.every((u,c)=>a[c]===`${k}${u}`))throw new e("HEY returned an evidence link that is not the published HEY receipt link.");if(typeof s!="string"||!P.test(s)||E(_(d.join(",")))!==s)throw new e("HEY returned an evidence hash that does not match its evidence ids.");if(typeof i!="string"||!i||H.test(i))throw new e("HEY returned an unexpected counting definition. Please try again.")}function R(r,t){if(p(t,"slug")!==r.slug)throw new e("HEY returned a different project than the one requested.");p(t,"currentSlug");let{payable:n,ties:o,reason:a,attestationsPaused:s}=t;if(typeof n!="boolean"||!Array.isArray(o))throw new e("HEY returned an unexpected tie answer. Please try again.");for(let i of o)if(!h(i)||!Y.includes(i.kind)||typeof i.address!="string"||!m(i.address,{strict:!1})||y(i.address)!==i.address)throw new e("HEY returned a tie that is not a known kind with a checksummed address.");if(n!==o.length>0)throw new e("HEY returned a payable flag that does not match its ties.");if(o.length?a!==void 0:!x.includes(a))throw new e("HEY returned an unexpected reason for the tie answer.");if(s!==void 0&&s!==!0)throw new e("HEY returned an unexpected attestation pause flag.")}function D(r,t,n,o=Math.floor(Date.now()/1e3)){if(T(r,t,o),!h(n)||!Object.keys(n).length||n.error!==void 0)throw new e("HEY returned an unexpected response. Please try again.");if(n.chainId!==void 0&&n.chainId!==4663||n.chain_id!==void 0&&n.chain_id!==4663)throw new e("HEY returned another chain.");if(n.nextCursor!=null||n.nextOffset!=null)throw new e("HEY signalled a continuation that this read does not support, so the answer may be incomplete.");r==="getProofOfShipShips"?q(t,n):R(t,n)}export{l as a,B as b,v as c,T as d,D as e};
@@ -1 +1 @@
1
- import{b as G}from"./TCPPYBGQ.js";import{a as p}from"./6IM6A5VA.js";import{a as W}from"./UWOFA6GV.js";import{g as P}from"./73N3TOJL.js";import{a as T}from"./RETS2ZEK.js";import{a as w,d as R,i as B}from"./G6HCV67X.js";import{a as o}from"./5YS5V2LK.js";import{encodeFunctionData as h,getAddress as L,parseAbi as x}from"viem";var y={address:L("0x451b42a15100c340ca12f7c66de06fac5ea2d751"),symbol:"BOW",decimals:18,chainId:w},u=L("0xeba502e1177f5fad9432c2deb273569d8381e01a"),b={address:B[w].tokens.USDG.address,symbol:"USDG",decimals:R,chainId:w},i=x(["function stakingToken() view returns (address)","function rewardsToken() view returns (address)","function balanceOf(address account) view returns (uint256)","function earned(address account) view returns (uint256)","function stake(uint256 amount)","function withdraw(uint256 amount)","function getReward()","function exit()","function cooldown() view returns (uint256)","function stakedAt(address) view returns (uint256)","function stakePaused() view returns (bool)","function totalSupply() view returns (uint256)","function rewardRate() view returns (uint256)","function rewardsDuration() view returns (uint256)","function periodFinish() view returns (uint256)","function owner() view returns (address)","function rewardsDistribution() view returns (address)","function notifyRewardAmount(uint256 reward)","function setRewardsDistribution(address distribution)","function setRewardsDuration(uint256 duration)","function setCooldown(uint256 cooldown)","function setStakePaused(bool paused)","function recoverERC20(address token,uint256 amount)","function transferOwnership(address newOwner)","function renounceOwnership()"]),X=m=>{async function D(n){try{return await n()}catch(t){throw new o(m.plainError(t))}}function A(n,t){if(Object.keys(n).some(e=>!t.includes(e)))throw new o("Unsupported Longbow staking input. Use the fields in the tool schema.")}async function U(){let n=m.clientFor(w);if(await n.getChainId()!==w)throw new o("Longbow requires a client on chain 4663.");let[t,e]=await Promise.all([n.readContract({address:u,abi:i,functionName:"stakingToken"}),n.readContract({address:u,abi:i,functionName:"rewardsToken"})]);if(typeof t!="string"||typeof e!="string"||!P(t,y.address)||!P(e,b.address))throw new o("Longbow staking does not report the pinned BOW stake and USDG reward tokens.");return n}async function S(n){let t=await U(),[e,a,s]=await Promise.all([t.readContract({address:u,abi:i,functionName:"balanceOf",args:[n]}),t.readContract({address:u,abi:i,functionName:"earned",args:[n]}),t.readContract({address:y.address,abi:i,functionName:"balanceOf",args:[n]})]);return{staked:e,earned:a,held:s,rpc:t}}async function v(n,t,e){let a=await m.preview(n,t),s=a.changes.map(({token:r,amount:d})=>{let c=d.startsWith("-");return`${c?"-":"+"}${m.formatAmount(c?d.slice(1):d,r.decimals)} ${r.symbol}`}).join(", ");return{txs:n,preview:a,summary:`${e} ${a.summary} ${s?`Estimated changes: ${s}. `:""}No transaction was sent.`}}let O=(n,t)=>m.unsignedTx({to:u,data:n,value:"0",chainId:w,description:t}),l=n=>m.formatAmount(n.toString(),y.decimals);async function _(n,t){if(A(n,["amount"]),p(t),typeof n.amount!="string")throw new o("Provide an integer BOW amount in base units (18 decimals).");let e=T(n.amount),{held:a,rpc:s}=await S(t),[r,d]=await Promise.all([s.readContract({address:u,abi:i,functionName:"cooldown"}),s.readContract({address:u,abi:i,functionName:"stakePaused"})]);if(d)throw new o("Longbow new stakes are paused; withdrawals and claims remain available.");if(e<=0n)throw new o("Stake amount must be positive.");if(e>a)throw new o(`Insufficient BOW: wallet holds ${a.toString()} base units, requested ${e.toString()}.`);return v([m.approval(y.address,u,e.toString(),w),O(h({abi:i,functionName:"stake",args:[e]}),`Stake ${l(e)} BOW in Longbow StakingRewards.`)],t,`Approve exactly ${l(e)} BOW, then stake it for USDG rewards. Current withdrawal cooldown: ${r} seconds; staking restarts that clock.`)}async function I(n,t){A(n,["amount"]),p(t);let{staked:e,earned:a,rpc:s}=await S(t),r=await s.readContract({address:u,abi:i,functionName:"cooldown"});if(r>0n){let[c,g]=await Promise.all([s.readContract({address:u,abi:i,functionName:"stakedAt",args:[t]}),s.getBlock()]);if(g.timestamp<c+r)throw new o(`Longbow unstaking cooldown ends at Unix second ${c+r}. Rewards can still be claimed.`)}if(e===0n)throw new o("This wallet has no BOW staked with Longbow.");if(n.amount==="all")return v([O(h({abi:i,functionName:"exit"}),`Unstake all ${l(e)} BOW and claim USDG rewards.`)],t,`Exit Longbow staking: return all ${l(e)} staked BOW and claim ${m.formatAmount(a.toString(),b.decimals)} USDG of earned rewards in one call.`);if(typeof n.amount!="string")throw new o('Provide an integer BOW amount in base units, or "all".');let d=T(n.amount);if(d<=0n||d>e)throw new o(`Unstake amount must be positive and at most the ${e.toString()} base units staked.`);return v([O(h({abi:i,functionName:"withdraw",args:[d]}),`Unstake ${l(d)} BOW.`)],t,`Unstake ${l(d)} BOW. Earned USDG rewards stay claimable with longbow_claim_rewards.`)}async function E(n,t){A(n,[]),p(t);let{earned:e}=await S(t);if(e===0n)throw new o("No Longbow staking rewards to claim for this wallet.");let a=m.formatAmount(e.toString(),b.decimals);return v([O(h({abi:i,functionName:"getReward"}),`Claim ${a} USDG of Longbow staking rewards.`)],t,`Claim ${a} USDG of earned Longbow staking rewards; staked BOW stays staked.`)}async function F(n){return D(async()=>{p(n);let{staked:t,earned:e}=await S(n);return t===0n&&e===0n?[]:[{module:"longbow",id:`${w}:${u.toLowerCase()}`,chainId:w,assets:[...t>0n?[{token:{...y},amount:t.toString()}]:[],...e>0n?[{token:{...b},amount:e.toString()}]:[]],description:`Longbow BOW staking: ${l(t)} BOW staked, ${m.formatAmount(e.toString(),b.decimals)} USDG rewards earned and claimable.`}]})}let $=(n,t,e,a)=>({name:n,inputSchema:{type:"object",properties:t,required:e,additionalProperties:!1},execute:(s,r)=>D(()=>a(s,r))});async function j(n,t){A(n,[]),p(t);let{staked:e,earned:a,held:s,rpc:r}=await S(t),d=["cooldown","stakePaused","totalSupply","rewardRate","rewardsDuration","periodFinish","owner","rewardsDistribution"],c=await Promise.all(d.map(f=>r.readContract({address:u,abi:i,functionName:f}))),g=await r.readContract({address:u,abi:i,functionName:"stakedAt",args:[t]});return{chainId:w,staking:u,stakeToken:y,rewardToken:b,staked:e.toString(),earned:a.toString(),walletBalance:s.toString(),stakedAt:g.toString(),...Object.fromEntries(d.map((f,k)=>[f,typeof c[k]=="bigint"?c[k].toString():c[k]])),rewardRateScale:"1000000000000000000",caveat:"rewardRate is USDG base units multiplied by 1e18 per second, not APY. Cooldown and pause state are owner-configurable."}}let C=[["notifyRewardAmount",["uint256"]],["setRewardsDistribution",["address"]],["setRewardsDuration",["uint256"]],["setCooldown",["uint256"]],["setStakePaused",["bool"]],["recoverERC20",["address","uint256"]],["transferOwnership",["address"]],["renounceOwnership",[]]];async function q(n,t){A(n,["operation","values","fund"]),p(t);let e=C.find(([f])=>f===n.operation);if(!e||!Array.isArray(n.values)||n.values.length!==e[1].length)throw new o("Choose a staking operation and its exact ordered values.");let a=e[1].map((f,k)=>G(f,n.values[k])),s=await U(),r=e[0]==="notifyRewardAmount",d=await s.readContract({address:u,abi:i,functionName:r?"rewardsDistribution":"owner"});if(!P(d,t))throw new o("This wallet lacks the Longbow staking owner/distribution role.");if(n.fund!==void 0&&(typeof n.fund!="boolean"||!r))throw new o("fund is a boolean available only for notifyRewardAmount.");let c=`Longbow staking ${e[0]}, values ${JSON.stringify(n.values)}.${e[0]==="renounceOwnership"?" Owner administration is permanently relinquished.":""}`,g=[];if(r&&n.fund===!0){let f=a[0];if(f===0n)throw new o("Reward funding must be positive.");let k=x(["function transfer(address,uint256) returns (bool)"]);g.push(m.unsignedTx({to:b.address,data:h({abi:k,functionName:"transfer",args:[u,f]}),value:"0",chainId:w,description:`Fund exactly ${f} USDG base units before notifying rewards.`}))}return g.push(O(h({abi:i,functionName:e[0],args:a}),c)),v(g,t,`${c} ${n.fund===!0?"Funding and notification are separate transactions. A failed notification leaves funded USDG in the staking contract.":""}`)}let N=W("Positive BOW amount in integer base units (18 decimals).");return{positions:F,tools:[$("longbow_staking_status",{},[],j),$("longbow_manage_staking",{operation:{enum:C.map(([n])=>n)},values:{type:"array",maxItems:2,items:{oneOf:[{type:"string"},{type:"boolean"}]}},fund:{type:"boolean"}},["operation","values"],q),$("longbow_stake",{amount:N},["amount"],_),$("longbow_unstake",{amount:{anyOf:[N,{const:"all",description:"Unstake everything and claim rewards in one exit() call."}]}},["amount"],I),$("longbow_claim_rewards",{},[],E)]}};export{y as a,u as b,X as c};
1
+ import{b as G}from"./VYAJXLND.js";import{a as p}from"./43LI5NKJ.js";import{a as W}from"./66F5ZH34.js";import{g as P}from"./NWNYJ26T.js";import{b as T}from"./IX3GZMTM.js";import{a as w,d as R,i as B}from"./FWD4L3CJ.js";import{a as o}from"./XSD5NL7J.js";import{encodeFunctionData as h,getAddress as L,parseAbi as x}from"viem";var y={address:L("0x451b42a15100c340ca12f7c66de06fac5ea2d751"),symbol:"BOW",decimals:18,chainId:w},u=L("0xeba502e1177f5fad9432c2deb273569d8381e01a"),b={address:B[w].tokens.USDG.address,symbol:"USDG",decimals:R,chainId:w},i=x(["function stakingToken() view returns (address)","function rewardsToken() view returns (address)","function balanceOf(address account) view returns (uint256)","function earned(address account) view returns (uint256)","function stake(uint256 amount)","function withdraw(uint256 amount)","function getReward()","function exit()","function cooldown() view returns (uint256)","function stakedAt(address) view returns (uint256)","function stakePaused() view returns (bool)","function totalSupply() view returns (uint256)","function rewardRate() view returns (uint256)","function rewardsDuration() view returns (uint256)","function periodFinish() view returns (uint256)","function owner() view returns (address)","function rewardsDistribution() view returns (address)","function notifyRewardAmount(uint256 reward)","function setRewardsDistribution(address distribution)","function setRewardsDuration(uint256 duration)","function setCooldown(uint256 cooldown)","function setStakePaused(bool paused)","function recoverERC20(address token,uint256 amount)","function transferOwnership(address newOwner)","function renounceOwnership()"]),X=m=>{async function D(n){try{return await n()}catch(t){throw new o(m.plainError(t))}}function A(n,t){if(Object.keys(n).some(e=>!t.includes(e)))throw new o("Unsupported Longbow staking input. Use the fields in the tool schema.")}async function U(){let n=m.clientFor(w);if(await n.getChainId()!==w)throw new o("Longbow requires a client on chain 4663.");let[t,e]=await Promise.all([n.readContract({address:u,abi:i,functionName:"stakingToken"}),n.readContract({address:u,abi:i,functionName:"rewardsToken"})]);if(typeof t!="string"||typeof e!="string"||!P(t,y.address)||!P(e,b.address))throw new o("Longbow staking does not report the pinned BOW stake and USDG reward tokens.");return n}async function S(n){let t=await U(),[e,a,s]=await Promise.all([t.readContract({address:u,abi:i,functionName:"balanceOf",args:[n]}),t.readContract({address:u,abi:i,functionName:"earned",args:[n]}),t.readContract({address:y.address,abi:i,functionName:"balanceOf",args:[n]})]);return{staked:e,earned:a,held:s,rpc:t}}async function v(n,t,e){let a=await m.preview(n,t),s=a.changes.map(({token:r,amount:d})=>{let c=d.startsWith("-");return`${c?"-":"+"}${m.formatAmount(c?d.slice(1):d,r.decimals)} ${r.symbol}`}).join(", ");return{txs:n,preview:a,summary:`${e} ${a.summary} ${s?`Estimated changes: ${s}. `:""}No transaction was sent.`}}let O=(n,t)=>m.unsignedTx({to:u,data:n,value:"0",chainId:w,description:t}),l=n=>m.formatAmount(n.toString(),y.decimals);async function _(n,t){if(A(n,["amount"]),p(t),typeof n.amount!="string")throw new o("Provide an integer BOW amount in base units (18 decimals).");let e=T(n.amount),{held:a,rpc:s}=await S(t),[r,d]=await Promise.all([s.readContract({address:u,abi:i,functionName:"cooldown"}),s.readContract({address:u,abi:i,functionName:"stakePaused"})]);if(d)throw new o("Longbow new stakes are paused; withdrawals and claims remain available.");if(e<=0n)throw new o("Stake amount must be positive.");if(e>a)throw new o(`Insufficient BOW: wallet holds ${a.toString()} base units, requested ${e.toString()}.`);return v([m.approval(y.address,u,e.toString(),w),O(h({abi:i,functionName:"stake",args:[e]}),`Stake ${l(e)} BOW in Longbow StakingRewards.`)],t,`Approve exactly ${l(e)} BOW, then stake it for USDG rewards. Current withdrawal cooldown: ${r} seconds; staking restarts that clock.`)}async function I(n,t){A(n,["amount"]),p(t);let{staked:e,earned:a,rpc:s}=await S(t),r=await s.readContract({address:u,abi:i,functionName:"cooldown"});if(r>0n){let[c,g]=await Promise.all([s.readContract({address:u,abi:i,functionName:"stakedAt",args:[t]}),s.getBlock()]);if(g.timestamp<c+r)throw new o(`Longbow unstaking cooldown ends at Unix second ${c+r}. Rewards can still be claimed.`)}if(e===0n)throw new o("This wallet has no BOW staked with Longbow.");if(n.amount==="all")return v([O(h({abi:i,functionName:"exit"}),`Unstake all ${l(e)} BOW and claim USDG rewards.`)],t,`Exit Longbow staking: return all ${l(e)} staked BOW and claim ${m.formatAmount(a.toString(),b.decimals)} USDG of earned rewards in one call.`);if(typeof n.amount!="string")throw new o('Provide an integer BOW amount in base units, or "all".');let d=T(n.amount);if(d<=0n||d>e)throw new o(`Unstake amount must be positive and at most the ${e.toString()} base units staked.`);return v([O(h({abi:i,functionName:"withdraw",args:[d]}),`Unstake ${l(d)} BOW.`)],t,`Unstake ${l(d)} BOW. Earned USDG rewards stay claimable with longbow_claim_rewards.`)}async function E(n,t){A(n,[]),p(t);let{earned:e}=await S(t);if(e===0n)throw new o("No Longbow staking rewards to claim for this wallet.");let a=m.formatAmount(e.toString(),b.decimals);return v([O(h({abi:i,functionName:"getReward"}),`Claim ${a} USDG of Longbow staking rewards.`)],t,`Claim ${a} USDG of earned Longbow staking rewards; staked BOW stays staked.`)}async function F(n){return D(async()=>{p(n);let{staked:t,earned:e}=await S(n);return t===0n&&e===0n?[]:[{module:"longbow",id:`${w}:${u.toLowerCase()}`,chainId:w,assets:[...t>0n?[{token:{...y},amount:t.toString()}]:[],...e>0n?[{token:{...b},amount:e.toString()}]:[]],description:`Longbow BOW staking: ${l(t)} BOW staked, ${m.formatAmount(e.toString(),b.decimals)} USDG rewards earned and claimable.`}]})}let $=(n,t,e,a)=>({name:n,inputSchema:{type:"object",properties:t,required:e,additionalProperties:!1},execute:(s,r)=>D(()=>a(s,r))});async function j(n,t){A(n,[]),p(t);let{staked:e,earned:a,held:s,rpc:r}=await S(t),d=["cooldown","stakePaused","totalSupply","rewardRate","rewardsDuration","periodFinish","owner","rewardsDistribution"],c=await Promise.all(d.map(f=>r.readContract({address:u,abi:i,functionName:f}))),g=await r.readContract({address:u,abi:i,functionName:"stakedAt",args:[t]});return{chainId:w,staking:u,stakeToken:y,rewardToken:b,staked:e.toString(),earned:a.toString(),walletBalance:s.toString(),stakedAt:g.toString(),...Object.fromEntries(d.map((f,k)=>[f,typeof c[k]=="bigint"?c[k].toString():c[k]])),rewardRateScale:"1000000000000000000",caveat:"rewardRate is USDG base units multiplied by 1e18 per second, not APY. Cooldown and pause state are owner-configurable."}}let C=[["notifyRewardAmount",["uint256"]],["setRewardsDistribution",["address"]],["setRewardsDuration",["uint256"]],["setCooldown",["uint256"]],["setStakePaused",["bool"]],["recoverERC20",["address","uint256"]],["transferOwnership",["address"]],["renounceOwnership",[]]];async function q(n,t){A(n,["operation","values","fund"]),p(t);let e=C.find(([f])=>f===n.operation);if(!e||!Array.isArray(n.values)||n.values.length!==e[1].length)throw new o("Choose a staking operation and its exact ordered values.");let a=e[1].map((f,k)=>G(f,n.values[k])),s=await U(),r=e[0]==="notifyRewardAmount",d=await s.readContract({address:u,abi:i,functionName:r?"rewardsDistribution":"owner"});if(!P(d,t))throw new o("This wallet lacks the Longbow staking owner/distribution role.");if(n.fund!==void 0&&(typeof n.fund!="boolean"||!r))throw new o("fund is a boolean available only for notifyRewardAmount.");let c=`Longbow staking ${e[0]}, values ${JSON.stringify(n.values)}.${e[0]==="renounceOwnership"?" Owner administration is permanently relinquished.":""}`,g=[];if(r&&n.fund===!0){let f=a[0];if(f===0n)throw new o("Reward funding must be positive.");let k=x(["function transfer(address,uint256) returns (bool)"]);g.push(m.unsignedTx({to:b.address,data:h({abi:k,functionName:"transfer",args:[u,f]}),value:"0",chainId:w,description:`Fund exactly ${f} USDG base units before notifying rewards.`}))}return g.push(O(h({abi:i,functionName:e[0],args:a}),c)),v(g,t,`${c} ${n.fund===!0?"Funding and notification are separate transactions. A failed notification leaves funded USDG in the staking contract.":""}`)}let N=W("Positive BOW amount in integer base units (18 decimals).");return{positions:F,tools:[$("longbow_staking_status",{},[],j),$("longbow_manage_staking",{operation:{enum:C.map(([n])=>n)},values:{type:"array",maxItems:2,items:{oneOf:[{type:"string"},{type:"boolean"}]}},fund:{type:"boolean"}},["operation","values"],q),$("longbow_stake",{amount:N},["amount"],_),$("longbow_unstake",{amount:{anyOf:[N,{const:"all",description:"Unstake everything and claim rewards in one exit() call."}]}},["amount"],I),$("longbow_claim_rewards",{},[],E)]}};export{y as a,u as b,X as c};
@@ -1 +1 @@
1
- import{c as B}from"./MYBDO5SA.js";import{b as x,e as d,g as k}from"./73N3TOJL.js";import{a as l}from"./5YS5V2LK.js";import{getAddress as C,keccak256 as I,toHex as D}from"viem";var R="https://balancesapi.ponsfamily.com/v1",P=/^(0|[1-9][0-9]{0,77})$/,$=/^[0-9A-Za-z_.-]{1,128}$/,y=e=>typeof e=="number"&&Number.isSafeInteger(e)&&e>=0,p=e=>typeof e=="string"&&P.test(e),S=e=>typeof e=="string"&&x.test(e);function M(e){return d(e)&&S(e.token)&&y(e.holders)&&p(e.supply)&&p(e.burned)&&p(e.circulating)&&d(e.as_of)&&y(e.as_of.rollup_bucket)&&y(e.as_of.tail_from_block)&&(e.next_cursor===null||e.next_cursor===void 0||typeof e.next_cursor=="string"&&$.test(e.next_cursor))&&Array.isArray(e.page)&&e.page.length<=50&&e.page.every(t=>d(t)&&S(t.wallet)&&p(t.balance)&&(t.label===void 0||t.label===null||typeof t.label=="string"))}var A=new WeakMap,c=()=>new l("The Pons holder index changed or returned an incomplete directory. Retry pons_holders without a cursor.");async function T(e,t){let n=A.get(e);n||(n=new Map,A.set(e,n));let f=n.get(t);if(f&&f.expires>Date.now())return f.directory;let o,g,m=new Set,_=new Set,s=[];for(let b=0;b<2e3;b++){let h=new URL(`${R}/tokens/${t.toLowerCase()}/holders`);h.searchParams.set("limit","50"),g&&h.searchParams.set("cursor",g);let r=await B(e.http,h.toString(),{method:"GET",redirect:"error",headers:{accept:"application/json"}},M);if(!k(r.token,t))throw c();if(r.holders>1e5)throw new l("The Pons holder directory exceeds 100000 indexed holders. No total or rank was computed.");if(o??=r,r.holders!==o.holders||r.supply!==o.supply||r.burned!==o.burned||r.circulating!==o.circulating||r.as_of.rollup_bucket!==o.as_of.rollup_bucket||r.as_of.tail_from_block!==o.as_of.tail_from_block)throw c();for(let u of r.page){let i=C(u.wallet);if(_.has(i)||BigInt(u.balance)===0n)throw c();_.add(i),s.push({...u,wallet:i})}if(s.length>o.holders)throw c();if(!r.next_cursor){if(s.length!==o.holders)throw c();s.sort((a,w)=>BigInt(a.balance)>BigInt(w.balance)?-1:BigInt(a.balance)<BigInt(w.balance)?1:a.wallet.toLowerCase().localeCompare(w.wallet.toLowerCase()));let u=I(D(JSON.stringify([t,o.as_of,s.map(a=>[a.wallet,a.balance])]))).slice(2,18),i={body:o,rows:s,fingerprint:u,fetchedAt:new Date().toISOString()};return n.delete(t),n.size>=4&&n.delete(n.keys().next().value),n.set(t,{directory:i,expires:Date.now()+15e3}),i}if(!r.page.length||m.has(r.next_cursor))throw c();m.add(r.next_cursor),g=r.next_cursor}throw new l("The Pons holder directory exceeds 100000 indexed holders. No total or rank was computed.")}function U(e){if(e===void 0)return{offset:0};if(typeof e!="string")throw new l("Use the nextCursor returned by the previous pons_holders page.");let t=/^holders_([0-9]{1,6})_([0-9a-f]{16})$/.exec(e);if(!t)throw new l("Use the nextCursor returned by the previous pons_holders page.");return{offset:Number(t[1]),fingerprint:t[2]}}function z(e,t){if(BigInt(t)===0n)return null;let n=BigInt(e)*10n**18n/BigInt(t);return`${n/10n**18n}.${(n%10n**18n).toString().padStart(18,"0")}`}export{R as a,T as b,U as c,z as d};
1
+ import{c as B}from"./VEQBHI6O.js";import{b as x,e as d,g as k}from"./NWNYJ26T.js";import{a as l}from"./XSD5NL7J.js";import{getAddress as C,keccak256 as I,toHex as D}from"viem";var R="https://balancesapi.ponsfamily.com/v1",P=/^(0|[1-9][0-9]{0,77})$/,$=/^[0-9A-Za-z_.-]{1,128}$/,y=e=>typeof e=="number"&&Number.isSafeInteger(e)&&e>=0,p=e=>typeof e=="string"&&P.test(e),S=e=>typeof e=="string"&&x.test(e);function M(e){return d(e)&&S(e.token)&&y(e.holders)&&p(e.supply)&&p(e.burned)&&p(e.circulating)&&d(e.as_of)&&y(e.as_of.rollup_bucket)&&y(e.as_of.tail_from_block)&&(e.next_cursor===null||e.next_cursor===void 0||typeof e.next_cursor=="string"&&$.test(e.next_cursor))&&Array.isArray(e.page)&&e.page.length<=50&&e.page.every(t=>d(t)&&S(t.wallet)&&p(t.balance)&&(t.label===void 0||t.label===null||typeof t.label=="string"))}var A=new WeakMap,c=()=>new l("The Pons holder index changed or returned an incomplete directory. Retry pons_holders without a cursor.");async function T(e,t){let n=A.get(e);n||(n=new Map,A.set(e,n));let f=n.get(t);if(f&&f.expires>Date.now())return f.directory;let o,g,m=new Set,_=new Set,s=[];for(let b=0;b<2e3;b++){let h=new URL(`${R}/tokens/${t.toLowerCase()}/holders`);h.searchParams.set("limit","50"),g&&h.searchParams.set("cursor",g);let r=await B(e.http,h.toString(),{method:"GET",redirect:"error",headers:{accept:"application/json"}},M);if(!k(r.token,t))throw c();if(r.holders>1e5)throw new l("The Pons holder directory exceeds 100000 indexed holders. No total or rank was computed.");if(o??=r,r.holders!==o.holders||r.supply!==o.supply||r.burned!==o.burned||r.circulating!==o.circulating||r.as_of.rollup_bucket!==o.as_of.rollup_bucket||r.as_of.tail_from_block!==o.as_of.tail_from_block)throw c();for(let u of r.page){let i=C(u.wallet);if(_.has(i)||BigInt(u.balance)===0n)throw c();_.add(i),s.push({...u,wallet:i})}if(s.length>o.holders)throw c();if(!r.next_cursor){if(s.length!==o.holders)throw c();s.sort((a,w)=>BigInt(a.balance)>BigInt(w.balance)?-1:BigInt(a.balance)<BigInt(w.balance)?1:a.wallet.toLowerCase().localeCompare(w.wallet.toLowerCase()));let u=I(D(JSON.stringify([t,o.as_of,s.map(a=>[a.wallet,a.balance])]))).slice(2,18),i={body:o,rows:s,fingerprint:u,fetchedAt:new Date().toISOString()};return n.delete(t),n.size>=4&&n.delete(n.keys().next().value),n.set(t,{directory:i,expires:Date.now()+15e3}),i}if(!r.page.length||m.has(r.next_cursor))throw c();m.add(r.next_cursor),g=r.next_cursor}throw new l("The Pons holder directory exceeds 100000 indexed holders. No total or rank was computed.")}function U(e){if(e===void 0)return{offset:0};if(typeof e!="string")throw new l("Use the nextCursor returned by the previous pons_holders page.");let t=/^holders_([0-9]{1,6})_([0-9a-f]{16})$/.exec(e);if(!t)throw new l("Use the nextCursor returned by the previous pons_holders page.");return{offset:Number(t[1]),fingerprint:t[2]}}function z(e,t){if(BigInt(t)===0n)return null;let n=BigInt(e)*10n**18n/BigInt(t);return`${n/10n**18n}.${(n%10n**18n).toString().padStart(18,"0")}`}export{R as a,T as b,U as c,z as d};