@oakagentkit/core 0.2.0 → 0.2.1
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.
- package/build/dist/api/history.js +1 -1
- package/build/dist/api/modules/grove/index.js +1 -1
- package/build/dist/api/modules/hoodlock/airdrop.js +1 -1
- package/build/dist/api/modules/hoodlock/fee.js +1 -1
- package/build/dist/api/modules/hoodlock/guard.js +1 -1
- package/build/dist/api/modules/hoodlock/index.js +1 -1
- package/build/dist/api/modules/hoodlock/lifecycle.js +1 -1
- package/build/dist/api/modules/hoodlock/locks-burn.js +1 -1
- package/build/dist/api/modules/hoodlock/public.js +1 -1
- package/build/dist/api/modules/hookr/create-cancel.js +1 -1
- package/build/dist/api/modules/hookr/discovery.js +1 -1
- package/build/dist/api/modules/hookr/fill-bounty.js +1 -1
- package/build/dist/api/modules/hookr/index.js +1 -1
- package/build/dist/api/modules/hookr/public-reads.js +1 -1
- package/build/dist/api/modules/hookr/relay.js +1 -1
- package/build/dist/api/modules/longbow/administration.js +1 -1
- package/build/dist/api/modules/longbow/fixed.js +1 -1
- package/build/dist/api/modules/longbow/index.js +1 -1
- package/build/dist/api/modules/morpho/bundles.js +1 -1
- package/build/dist/api/modules/morpho/in-kind.js +1 -1
- package/build/dist/api/modules/morpho/index.js +1 -1
- package/build/dist/api/modules/morpho/local-guard.js +1 -1
- package/build/dist/api/modules/morpho/midnight.js +1 -1
- package/build/dist/api/modules/morpho/protocol.js +1 -1
- package/build/dist/api/modules/morpho/vault-tools.js +1 -1
- package/build/dist/api/modules/netnet/card-plan.js +1 -1
- package/build/dist/api/modules/netnet/card-read.js +1 -1
- package/build/dist/api/modules/netnet/card-recovery.js +1 -1
- package/build/dist/api/modules/netnet/desk-action.js +1 -1
- package/build/dist/api/modules/netnet/financial.js +1 -1
- package/build/dist/api/modules/netnet/index.js +1 -1
- package/build/dist/api/modules/priors/coverage.js +1 -1
- package/build/dist/api/modules/priors/discovery.js +1 -1
- package/build/dist/api/modules/priors/index.js +1 -1
- package/build/dist/api/modules/priors/integration.js +1 -1
- package/build/dist/api/modules/priors/stock-swap.js +1 -1
- package/build/dist/api/modules/steakhouse/index.js +1 -1
- package/build/dist/api/modules/steakhouse/local-guard.js +1 -1
- package/build/dist/api/modules/steakhouse/management.js +1 -1
- package/build/dist/api/modules/steakhouse/v2-exit.js +1 -1
- package/build/dist/api/modules/tickerspring/basket-routes.js +1 -1
- package/build/dist/api/modules/tickerspring/contract-reads.js +1 -1
- package/build/dist/api/modules/tickerspring/exit-preview.js +1 -1
- package/build/dist/api/modules/tickerspring/guards.js +1 -1
- package/build/dist/api/modules/tickerspring/index.js +1 -1
- package/build/dist/api/modules/tickerspring/journeys.js +1 -1
- package/build/dist/api/modules/tickerspring/ladder.js +1 -1
- package/build/dist/api/modules/tickerspring/maker.js +1 -1
- package/build/dist/api/modules/tickerspring/order-accounting.js +1 -1
- package/build/dist/api/modules/tickerspring/research.js +1 -1
- package/build/dist/api/modules/tickerspring/strategies.js +1 -1
- package/build/dist/api/modules/uniswap/auction-create.js +1 -1
- package/build/dist/api/modules/uniswap/auction.js +1 -1
- package/build/dist/api/modules/uniswap/batch.js +1 -1
- package/build/dist/api/modules/uniswap/common.js +1 -1
- package/build/dist/api/modules/uniswap/fees.js +1 -1
- package/build/dist/api/modules/uniswap/index.js +1 -1
- package/build/dist/api/modules/uniswap/local-guard.js +1 -1
- package/build/dist/api/modules/uniswap/oracle.js +1 -1
- package/build/dist/api/modules/uniswap/pool-math.js +1 -1
- package/build/dist/api/modules/uniswap/pools.js +1 -1
- package/build/dist/api/modules/uniswap/position.js +1 -1
- package/build/dist/api/modules/uniswap/protocol.js +1 -1
- package/build/dist/api/modules/uniswap/token-jar.js +1 -1
- package/build/dist/api/modules/uniswap/trade-batch.js +1 -1
- package/build/dist/api/modules/uniswap/trade.js +1 -1
- package/build/dist/api/modules/uniswap/v2.js +1 -1
- package/build/dist/api/modules/uniswap/v3.js +1 -1
- package/build/dist/api/modules/uniswap/v4.js +1 -1
- package/build/dist/api/modules/uniswap/wrap.js +1 -1
- package/build/dist/api/prices.js +1 -1
- package/build/dist/api/signing-registry.js +1 -1
- package/build/dist/api/tokens.d.ts +4 -0
- package/build/dist/api/tokens.js +1 -1
- package/build/dist/chunks/{5VXNQFYJ.js → 22S4SFD5.js} +1 -1
- package/build/dist/chunks/{ITV52TIE.js → 2CS3M32D.js} +1 -1
- package/build/dist/chunks/{R7D256HG.js → 3R3C3CU5.js} +1 -1
- package/build/dist/chunks/{2SNQWKHA.js → 3ZVGHC6S.js} +1 -1
- package/build/dist/chunks/{5FTSKYQH.js → 5LQBHXFA.js} +1 -1
- package/build/dist/chunks/{5HW6JKME.js → 5RKWSFD2.js} +1 -1
- package/build/dist/chunks/6L6DSMCU.js +1 -0
- package/build/dist/chunks/{A25P24G2.js → 72AWP4BM.js} +1 -1
- package/build/dist/chunks/{4IPW5WZ4.js → AZGMF26W.js} +1 -1
- package/build/dist/chunks/{XKRWJCYE.js → BBVKWG65.js} +1 -1
- package/build/dist/chunks/{QZTUMSQY.js → BEPSWFJX.js} +1 -1
- package/build/dist/chunks/{ZCGVBK5K.js → BG4S6MSN.js} +1 -1
- package/build/dist/chunks/{TNRDCBGO.js → D4WURN33.js} +1 -1
- package/build/dist/chunks/{7Z5IM2QZ.js → DD7755AW.js} +1 -1
- package/build/dist/chunks/{IUXOUKQN.js → DGGOO4RN.js} +1 -1
- package/build/dist/chunks/{KQFDLDHL.js → DVKDWXEJ.js} +1 -1
- package/build/dist/chunks/{N6RL3SUZ.js → E24S22BZ.js} +1 -1
- package/build/dist/chunks/FBQWTWPT.js +1 -0
- package/build/dist/chunks/{PJ65ZOQ7.js → FKAA7VUR.js} +1 -1
- package/build/dist/chunks/{K463HFGC.js → GECX5U3F.js} +1 -1
- package/build/dist/chunks/{BFVLBENV.js → GUBB5P6V.js} +1 -1
- package/build/dist/chunks/{SDICP7BT.js → I7NUTSSX.js} +1 -1
- package/build/dist/chunks/{64AF7ECA.js → IAXKPME3.js} +1 -1
- package/build/dist/chunks/{WQZLYX64.js → IRWEY7TQ.js} +1 -1
- package/build/dist/chunks/{WDGPCPQJ.js → IUETZH6I.js} +1 -1
- package/build/dist/chunks/{ANQ43XJA.js → JG24LNUI.js} +1 -1
- package/build/dist/chunks/{U3FMCX3L.js → K7HIKXNT.js} +1 -1
- package/build/dist/chunks/LFN3OODW.js +1 -0
- package/build/dist/chunks/{3ACEWCKZ.js → MEMVFR7Z.js} +1 -1
- package/build/dist/chunks/{DLIOZCEG.js → MNFU7PO3.js} +1 -1
- package/build/dist/chunks/{NO57NGRV.js → N37ZLNCT.js} +1 -1
- package/build/dist/chunks/{NIOBE2LK.js → N3GWFLG6.js} +1 -1
- package/build/dist/chunks/{O5SU2I3G.js → NCEJZWGX.js} +1 -1
- package/build/dist/chunks/{GSI5COTD.js → NKY3DT34.js} +1 -1
- package/build/dist/chunks/{QQWF6A4P.js → NUTHT4FE.js} +1 -1
- package/build/dist/chunks/{JC4SYMBV.js → O7PQDUVT.js} +1 -1
- package/build/dist/chunks/{ZYR5LSVB.js → OMTCWXQR.js} +1 -1
- package/build/dist/chunks/{55NX776C.js → PR2QED25.js} +1 -1
- package/build/dist/chunks/{QCD33HMD.js → Q4RZQCDS.js} +1 -1
- package/build/dist/chunks/{7BTELNNI.js → QR7ALOR4.js} +1 -1
- package/build/dist/chunks/{SQH7A4O3.js → QXFJZGVB.js} +1 -1
- package/build/dist/chunks/{GHDDVBPK.js → QYHJWU5T.js} +1 -1
- package/build/dist/chunks/{Y2IWPNEW.js → RM5W63LO.js} +1 -1
- package/build/dist/chunks/T3MGNKA6.js +1 -0
- package/build/dist/chunks/{FSPNOVKB.js → TDN3C4IG.js} +1 -1
- package/build/dist/chunks/{HRG2VVPY.js → ULJ6E4HP.js} +1 -1
- package/build/dist/chunks/{BXN3MDS4.js → WLACEU2Y.js} +1 -1
- package/build/dist/chunks/{JREVERSC.js → X6G4BD35.js} +1 -1
- package/build/dist/chunks/{6PU2CMQZ.js → XGUKLFBU.js} +1 -1
- package/build/dist/chunks/XUJSQV52.js +1 -0
- package/build/dist/chunks/{LI7FYINH.js → YMB553OJ.js} +1 -1
- package/package.json +2 -2
- package/build/dist/chunks/46ZA2R5L.js +0 -1
- package/build/dist/chunks/74BPMUAG.js +0 -1
- package/build/dist/chunks/G4PDM3MX.js +0 -1
- package/build/dist/chunks/NBRMUFJP.js +0 -1
- package/build/dist/chunks/OJMYESQU.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as Re,d as je,e as qe,f as be,i as Le,j as ze}from"./3ACEWCKZ.js";import{i as ue}from"./NBRMUFJP.js";import{b as Ie,o as Ce}from"./CAU44UWP.js";import{a as de}from"./VJ3W2V3B.js";import{a as $,b as Oe}from"./6IM6A5VA.js";import{a as L}from"./UWOFA6GV.js";import{a as D}from"./RETS2ZEK.js";import{a as f,d as Xe,i as ee,j as Be}from"./XPFVT2EA.js";import{a as o,b as He,d as oe}from"./5YS5V2LK.js";import{encodeAbiParameters as A,encodeFunctionData as re,erc20Abi as We,getAddress as y,isAddress as An,keccak256 as xn,pad as Sn,parseAbi as Ae,parseAbiParameters as j,toEventSelector as In,toHex as Ge}from"viem";var Cn=y(ee[4663].uniswap.v4_pool_manager.address),T=y(ee[4663].uniswap.v4_position_manager.address),fe=y(ee[4663].uniswap.v4_state_view.address),_e=y(ee[4663].uniswap.permit2.address),at=y(ee[4663].ponsTrade.universal_router.address),se=y(ee[4663].uniswap.WETH.address),_=y(Be),g="0x0000000000000000000000000000000000000000",De=8388608,Ee=-887272,Pe=887272,pn=(1n<<48n)-1n,ne=(1n<<128n)-1n,qn=(1n<<160n)-1n,pe=1n<<96n,Ze=1800n,Ln="0xbac3aa3b91584a53a579b3c999a56756e954e59247e497bad1d25a4334bde551",Ke=[{poolId:"0xbac3aa3b91584a53a579b3c999a56756e954e59247e497bad1d25a4334bde551",key:{currency0:g,currency1:_,fee:8388608,tickSpacing:10,hooks:y("0x06a889870c8f83640d6816319f72e2aa579b6080")},liquidity:"5532026605872066941",sqrtPriceX96:"3839897026469220985301794",tick:-198703,protocolFee:0,lpFee:0},{poolId:"0x387bf619da4d3fb62bb276482693dba1b9b3520f573cabdfe033384a24125982",key:{currency0:g,currency1:_,fee:500,tickSpacing:10,hooks:g},liquidity:"225820987949255613",sqrtPriceX96:"3840577772610961024680304",tick:-198700,protocolFee:512125,lpFee:500},{poolId:"0x54f7883914619af9105355bf83ed678bcf9f63560218ac61c9963b9503d0ba32",key:{currency0:g,currency1:_,fee:460,tickSpacing:9,hooks:g},liquidity:"85654324417347171",sqrtPriceX96:"3840419018843648722761192",tick:-198701,protocolFee:479349,lpFee:460},{poolId:"0xc7b615a3721594f73664eb3f62d8290d0fcc8d9d1156aed1ddecbd7f32efd9f5",key:{currency0:g,currency1:_,fee:8388608,tickSpacing:10,hooks:y("0xcb787a5cdea8b3715d984d82f1203fd7bfebe0c4")},liquidity:"50517446454827887",sqrtPriceX96:"3840495145865430860317598",tick:-198700,protocolFee:0,lpFee:0},{poolId:"0x24107d152f14a76d292123265ae3f3c71f863fc2f4ef7ba49d64e78d28ea379e",key:{currency0:g,currency1:_,fee:100,tickSpacing:1,hooks:g},liquidity:"36478878201789434",sqrtPriceX96:"3840363370720475418748563",tick:-198701,protocolFee:102425,lpFee:100},{poolId:"0x84bd4e2d8be11aeb0afc1195b38f587b61e90068548f1063fdbe448fb8cad0b6",key:{currency0:se,currency1:_,fee:200,tickSpacing:4,hooks:g},liquidity:"5980655057479791",sqrtPriceX96:"3839891926195366283625355",tick:-198703,protocolFee:213044,lpFee:200},{poolId:"0x3b0cbf0603ecc67b5fc9bb4fbb6ac9e08d3b2f406b63d1662a36063a7fe5e866",key:{currency0:g,currency1:_,fee:87,tickSpacing:1,hooks:g},liquidity:"5486760264498148",sqrtPriceX96:"3840563617639470134132117",tick:-198700,protocolFee:90134,lpFee:87}],Ne=y("0x987e330f00b79864a07fe81dfac344d0078abcc0"),fn="0xa791e5169faf703c0b63fd9552c33ec1128a773a00f5dc33a640da62a022cd35",Tn={currency0:g,currency1:_,fee:De,tickSpacing:1,hooks:Ne},$n=new Set([...Ke.map(e=>e.key.hooks.toLowerCase()),Ne.toLowerCase()]),Mn=j("address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks"),_n=j("(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) poolKey, int24 tickLower, int24 tickUpper, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, address owner, bytes hookData"),En=j("address currency0, address currency1"),Un=j("address currency, address recipient"),ge=j("uint256 tokenId, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes hookData"),Dn=j("uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes hookData"),Te=j("address currency0, address currency1, address recipient"),le=j("bytes actions, bytes[] params"),H=Ae(["function modifyLiquidities(bytes unlockData, uint256 deadline) payable","function poolKeys(bytes25 poolId) view returns (address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks)","function getPositionLiquidity(uint256 tokenId) view returns (uint128 liquidity)","function getPoolAndPositionInfo(uint256 tokenId) view returns ((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) poolKey, uint256 info)","function positionInfo(uint256 tokenId) view returns (uint256 info)","function ownerOf(uint256 tokenId) view returns (address owner)","function nextTokenId() view returns (uint256 tokenId)"]),Kn=Ae(["function initialize((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, uint160 sqrtPriceX96) returns (int24 tick)"]),Ye=j("address currency"),Qe=1e6,me=Ae(["function getSlot0(bytes32 poolId) view returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)","function getLiquidity(bytes32 poolId) view returns (uint128 liquidity)"]),Nn=Ae(["function approve(address token, address spender, uint160 amount, uint48 expiration)"]),Fn=In("Transfer(address,address,uint256)");function ve(e){if(typeof e!="string"||!An(e,{strict:!1}))throw new o("Provide a valid v4 currency address.");let n=e.toLowerCase();return n===g||n===de.toLowerCase()?g:y(e)}function R(e){let n=e.toLowerCase();return n===g||n===de.toLowerCase()}function ye(e){let n=ve(e.currency0),i=ve(e.currency1);$(e.hooks);let r=y(e.hooks);return xn(A(Mn,[n,i,e.fee,e.tickSpacing,r]))}function mn(e){return((typeof e=="number"?e:e.fee)&De)!==0}function Je(e,n){return mn(e)?{dynamicFee:!0,storedLpFee:n,swapsAreFree:!1,feeNote:"Pool uses dynamic fee flag 0x800000; stored lpFee=0 does not mean swaps are free. The hook determines the swap fee; a past observation is not a current quote."}:{dynamicFee:!1,storedLpFee:n,swapsAreFree:n===0,feeNote:`Static LP fee ${n} pips.`}}function ke(e,n){if(!e||typeof e!="object")throw new o("Provide a valid v4 PoolKey.");let i=ve(e.currency0),r=ve(e.currency1);if(BigInt(i)>=BigInt(r))throw new o("PoolKey currencies must be strictly sorted (currency0 < currency1).");if(!Number.isInteger(e.tickSpacing)||e.tickSpacing<=0||e.tickSpacing>32767)throw new o("PoolKey tickSpacing must be a positive integer.");if(!Number.isInteger(e.fee)||e.fee<0||e.fee>16777215)throw new o("PoolKey fee must be a valid uint24.");$(e.hooks);let c=y(e.hooks),s=mn(e.fee);if(!s&&e.fee>Qe)throw new o(`PoolKey static fee ${e.fee} exceeds the v4 maximum of ${Qe} pips (100%).`);if(s&&e.fee!==De)throw new o("Dynamic-fee PoolKey must use exact fee flag 0x800000 (8388608).");if(s&&c.toLowerCase()===g)throw new o("Dynamic-fee PoolKey requires a non-zero hook address.");if(!$n.has(c.toLowerCase()))throw new o(`Unsupported v4 hook ${c}: Oak does not assure arbitrary v4 hooks outside measured PoolKeys.`);let t={currency0:i,currency1:r,fee:e.fee,tickSpacing:e.tickSpacing,hooks:c},d=ye(t);if(c===Ne&&d.toLowerCase()!==fn)throw new o("Only the documented VolatilePair ETH/USDG PoolKey is supported. Pool creation requires the Uniswap Labs role.");if(n!==void 0){if(typeof n!="string"||!/^0x[0-9a-fA-F]{64}$/.test(n))throw new o("Provide a 32-byte hex poolId.");if(d.toLowerCase()!==n.toLowerCase())throw new o(`PoolKey hash (${d}) does not match expected poolId (${n}).`)}return t}function Vn(e){if(!Number.isInteger(e)||e<=0||e>Pe)throw new o("tickSpacing must be a positive integer.");let n=Math.trunc(Ee/e)*e,i=Math.trunc(Pe/e)*e;return{tickLower:n===0?0:n,tickUpper:i===0?0:i}}function Hn(e,n,i){if(!Number.isInteger(i)||i<=0)throw new o("tickSpacing must be a positive integer.");if(!Number.isInteger(e)||!Number.isInteger(n))throw new o("tickLower and tickUpper must be integers.");if(e<Ee||n>Pe)throw new o(`Ticks [${e}, ${n}] are outside Uniswap bounds [${Ee}, ${Pe}].`);if(e>=n)throw new o("tickLower must be strictly less than tickUpper.");if(e%i!==0||n%i!==0)throw new o(`Ticks [${e}, ${n}] must be divisible by tickSpacing ${i}.`)}function en(e,n,i,r,c=f){if($(e),$(n),R(e))throw new o("Native ETH does not use Permit2 approval.");let s=D(i);if(s<=0n||s>qn)throw new o("Permit2 approval amount must be a positive integer within uint160.");let t=D(String(r));if(t<=0n||t>pn)throw new o("Permit2 expiration must be a positive timestamp within uint48.");let d=re({abi:Nn,functionName:"approve",args:[e,n,s,Number(t)]});return Oe({to:_e,data:d,value:"0",chainId:c,description:`Approve Permit2 allowance of ${s} base units of ${e} for ${n} until ${t}.`})}function nn(e){let n=Number(e&0xffffffn);return(n&8388608)!==0?n-16777216:n}function Xn(e){let n=(e&0xffn)!==0n,i=nn(e>>8n&0xffffffn),r=nn(e>>32n&0xffffffn);return{poolIdBytes25:`0x${(e>>56n&(1n<<200n)-1n).toString(16).padStart(50,"0")}`,tickLower:i,tickUpper:r,hasSubscriber:n}}function tn(e,n,i,r=!1){let[c,s]=e<=n?[e,n]:[n,e];if(c<=0n||s<=0n)return 0n;let t=(i<<96n)*(s-c),d=s*c;return r?(t+d-1n)/d:t/d}function on(e,n,i,r=!1){let[c,s]=e<=n?[e,n]:[n,e],t=i*(s-c);return r?(t+pe-1n)/pe:t/pe}function yn(e){if(e.liquidity<=0n)return{amount0:0n,amount1:0n};let n=ue(e.tickLower),i=ue(e.tickUpper);return e.sqrtPriceX96<=n?{amount0:tn(n,i,e.liquidity,e.roundUp),amount1:0n}:e.sqrtPriceX96<i?{amount0:tn(e.sqrtPriceX96,i,e.liquidity,e.roundUp),amount1:on(n,e.sqrtPriceX96,e.liquidity,e.roundUp)}:{amount0:0n,amount1:on(n,i,e.liquidity,e.roundUp)}}function Bn(e){let n=ue(e.tickLower),i=ue(e.tickUpper),r=(s,t,d)=>t<=s||d<=0n?0n:d*s*t/pe/(t-s),c=(s,t,d)=>t<=s||d<=0n?0n:d*pe/(t-s);if(e.sqrtPriceX96<=n)return r(n,i,e.amount0);if(e.sqrtPriceX96<i){let s=r(e.sqrtPriceX96,i,e.amount0),t=c(n,e.sqrtPriceX96,e.amount1);return s<t?s:t}return c(n,i,e.amount1)}function $e(e,n){return e.map(i=>{let r=i.amount.trim(),c=r.startsWith("-"),s=c||r.startsWith("+")?r.slice(1):r,t=n(s,i.token.decimals);return`${c?"-":""}${t} ${i.token.symbol}`})}function rn(e,n=f){if(R(e))return{address:de,symbol:"ETH",decimals:18,chainId:n};let i=y(e);return i.toLowerCase()===_.toLowerCase()?{address:_,symbol:"USDG",decimals:Xe,chainId:n}:i.toLowerCase()===se.toLowerCase()?{address:se,symbol:"WETH",decimals:18,chainId:n}:{address:i,symbol:i.slice(0,10),decimals:18,chainId:n}}async function V(e,n,i=f){if(R(n))return rn(n,i);let r=y(n);if(r.toLowerCase()===_.toLowerCase()||r.toLowerCase()===se.toLowerCase())return rn(r,i);let[c,s]=await Promise.all([e.readContract({address:r,abi:We,functionName:"symbol"}),e.readContract({address:r,abi:We,functionName:"decimals"})]);if(!Number.isInteger(Number(s))||Number(s)<0||Number(s)>77)throw new o(`Token ${r} reports invalid decimals.`);return{address:r,symbol:ze(c,r),decimals:Number(s),chainId:i}}function W(e,n){if(typeof e!="string"||!/^\d+$/.test(e))throw new o(`${n} must be a non-negative integer string in base units.`);return D(e)}function sn(e,n,i,r){let c=e===void 0?D(Ce(n.toString(),i)):W(e,r);if(c<=1n||c>ne)throw new o(`${r} must exceed 1 base unit and fit in uint128; the simulated amount may be too small.`);return c}async function wn(e,n){if(typeof n=="number"&&Number.isFinite(n)&&n>0)return BigInt(Math.floor(n>1e11?n/1e3:n));if(typeof n=="string"&&/^\d+$/.test(n.trim()))return BigInt(n.trim());try{let i=await e.request({method:"eth_getBlockByNumber",params:["latest",!1]});if(i&&typeof i.timestamp=="string")return BigInt(i.timestamp)}catch{}return BigInt(Math.floor(Date.now()/1e3))}async function Me(e,n,i){let r=await wn(e,i);if(n==null)return r+1800n;let c=D(String(n));if(c<=r)throw new o(`Transaction deadline ${c} has expired (current timestamp ${r}).`);return c}async function Ue(e,n){let i=typeof n.poolId=="string"?n.poolId.trim():void 0,r=n.poolKey&&typeof n.poolKey=="object"&&!Array.isArray(n.poolKey)?n.poolKey:void 0,c=r?{currency0:String(r.currency0??g),currency1:String(r.currency1??_),fee:Number(r.fee),tickSpacing:Number(r.tickSpacing),hooks:String(r.hooks??g)}:n.currency0!==void 0&&n.currency1!==void 0&&n.fee!==void 0&&n.tickSpacing!==void 0?{currency0:String(n.currency0),currency1:String(n.currency1),fee:Number(n.fee),tickSpacing:Number(n.tickSpacing),hooks:String(n.hooks??g)}:void 0;if(c){if(R(c.currency0)&&typeof n.token0=="string"&&n.token0.toLowerCase()===se.toLowerCase())throw new o("Native ETH currency0 differs from WETH; do not supply WETH for a native-ETH v4 pool.");let b=ke(c,i);return{poolId:ye(b),poolKey:b}}let s=(i??Ln).toLowerCase();if(s===fn)return{poolId:s,poolKey:ke(Tn,s)};let t=Ke.find(b=>b.poolId.toLowerCase()===s);if(t){if(R(t.key.currency0)&&typeof n.token0=="string"&&n.token0.toLowerCase()===se.toLowerCase())throw new o("Native ETH currency0 differs from WETH; do not supply WETH for a native-ETH v4 pool.");return{poolId:t.poolId,poolKey:t.key}}let d=s.slice(0,52),a=await e.readContract({address:T,abi:H,functionName:"poolKeys",args:[d]}),[p,l,m,u,k]=a;if(p.toLowerCase()===g&&l.toLowerCase()===g&&Number(u)===0)throw new o(`Unknown or uninitialized v4 poolId ${s}.`);let w=ke({currency0:p,currency1:l,fee:Number(m),tickSpacing:Number(u),hooks:k},s);return{poolId:s,poolKey:w}}async function he(e,n,i){try{let[r,c]=await e.readContract({address:T,abi:H,functionName:"getPoolAndPositionInfo",args:[n]}),s=ke({currency0:r.currency0,currency1:r.currency1,fee:Number(r.fee),tickSpacing:Number(r.tickSpacing),hooks:r.hooks});if((i.poolKey||i.poolId)&&(await Ue(e,i)).poolId.toLowerCase()!==ye(s).toLowerCase())throw new o("The supplied PoolKey does not match this v4 position.");let t=Xn(BigInt(c));return{poolKey:s,poolId:ye(s),tickLower:t.tickLower,tickUpper:t.tickUpper}}catch(r){throw new o(`Could not read v4 position #${n}. ${oe(r)}`)}}async function an(e,n,i={}){$(n);let r=y(n),c=e.clientFor(f),s=new Set;if(i.tokenIds)for(let d of i.tokenIds)s.add(D(String(d)).toString());try{let d=await c.getBlockNumber(),a=10000000n;for(let p=0n;p<=d;p+=a){let l=p+a-1n<d?p+a-1n:d,m=await c.request({method:"eth_getLogs",params:[{address:T.toLowerCase(),topics:[Fn,null,Sn(r)],fromBlock:Ge(p),toBlock:Ge(l)}]});if(!Array.isArray(m))throw new o("Invalid v4 position log response.");for(let u of m){if(!Array.isArray(u.topics)||u.topics.length!==4||!/^0x[0-9a-fA-F]{64}$/.test(u.topics[3]??""))throw new o("Invalid v4 position transfer log.");s.add(BigInt(u.topics[3]).toString())}}}catch(d){if(!i.tokenIds)throw new o(`Could not discover v4 positions. ${oe(d)}`)}let t=[];for(let d of s){let a=BigInt(d);try{let p;try{p=await c.readContract({address:T,abi:H,functionName:"ownerOf",args:[a]})}catch(P){if(He(P,3))continue;throw P}if(p.toLowerCase()!==r.toLowerCase())continue;let l=await c.readContract({address:T,abi:H,functionName:"getPositionLiquidity",args:[a]}),m=BigInt(l);if(m===0n&&!i.includeZero)continue;let{poolKey:u,poolId:k,tickLower:w,tickUpper:b}=await he(c,a,{}),S=await c.readContract({address:fe,abi:me,functionName:"getSlot0",args:[k]}),I=BigInt(S[0]),{amount0:h,amount1:x}=yn({liquidity:m,tickLower:w,tickUpper:b,sqrtPriceX96:I}),[v,E]=await Promise.all([V(c,u.currency0,f),V(c,u.currency1,f)]);t.push({module:"uniswap",id:`uniswap:v4:${a.toString()}`,chainId:f,assets:[{token:v,amount:h.toString()},{token:E,amount:x.toString()}],description:`Uniswap v4 LP position #${a.toString()} (${v.symbol}/${E.symbol}, liquidity=${m.toString()}, ticks=[${w},${b}], poolId=${k})`})}catch(p){throw new o(`Could not read v4 position #${a}. ${oe(p)}`)}}return t}var On={type:"object",properties:{version:{type:"string",enum:["v4"]},poolId:{type:"string",description:"32-byte Uniswap v4 poolId hex string."},poolKey:{type:"object",properties:{currency0:{type:"string"},currency1:{type:"string"},fee:{type:"number"},tickSpacing:{type:"number"},hooks:{type:"string"}}},currency0:{type:"string"},currency1:{type:"string"},fee:{type:"number"},tickSpacing:{type:"number"},hooks:{type:"string"},tickLower:{type:"number"},tickUpper:{type:"number"},fullRange:{type:"boolean"},liquidity:L("Position liquidity in base units."),amount0Max:L("Maximum currency0 base units to spend."),amount1Max:L("Maximum currency1 base units to spend."),recipient:{type:"string"},deadline:L(),permit2Expiration:{type:"string"},hookData:{type:"string"},tokenId:L("Existing v4 position NFT to increase (keeps its tick range). Omit to mint a new position."),initialPrice:{type:"string",description:"Only when the pool does not exist: starting price as token1 per 1 token0 in human units (native ETH is 18 decimals). Needs the full poolKey. Creates the pool then mints the first position in separately confirmed transactions."},sqrtPriceX96:{type:"string",description:"Alternative to initialPrice: exact starting sqrtPriceX96."},acceptPriceDeviation:{type:"boolean",description:"Allow a starting price more than 500 bps from other live pools of the pair."}}},Rn={type:"object",description:"Create and initialize an empty Uniswap v4 pool (permissionless PoolManager.initialize). Add liquidity afterwards with uniswap_add.",properties:{version:{type:"string",enum:["v4"]},poolKey:{type:"object",properties:{currency0:{type:"string"},currency1:{type:"string"},fee:{type:"number"},tickSpacing:{type:"number"},hooks:{type:"string"}}},currency0:{type:"string",description:"Lower sorted currency; the zero address is native ETH."},currency1:{type:"string"},fee:{type:"number",description:"Static LP fee in pips (3000 = 0.30%), at most 1000000."},tickSpacing:{type:"number"},hooks:{type:"string",description:"Hook address; only hooks Oak has measured are accepted. Defaults to none."},initialPrice:{type:"string",description:'Starting price as token1 per 1 token0 in human units, e.g. "3000" for 1 ETH = 3000 USDG.'},sqrtPriceX96:{type:"string",description:"Alternative to initialPrice: exact starting sqrtPriceX96."},acceptPriceDeviation:{type:"boolean",description:"Allow a starting price more than 500 bps from other live pools of the pair."}}},jn={type:"object",properties:{version:{type:"string",enum:["v4"]},tokenId:L(),poolId:{type:"string"},poolKey:{type:"object"},amount0Min:L(),amount1Min:L(),recipient:{type:"string"},deadline:L(),hookData:{type:"string"}},required:["tokenId"]},zn={type:"object",properties:{version:{type:"string",enum:["v4"]},tokenId:L(),liquidity:{type:"string",pattern:"^(?:[0-9]+|all)$",description:"Positive base-unit liquidity amount, or all for a full burn."},slippageBps:{type:"integer",minimum:0,maximum:9999,default:Ie},fullExit:{type:"boolean"},burn:{type:"boolean"},amount0Min:L(),amount1Min:L(),poolId:{type:"string"},poolKey:{type:"object"},recipient:{type:"string"},deadline:L(),hookData:{type:"string"}},required:["tokenId"]},Wn={type:"object",properties:{version:{type:"string",enum:["v4"]},tokenIds:{type:"array",items:L()},includeZero:{type:"boolean"}}};function cn(e){let n=e.poolKey&&typeof e.poolKey=="object"&&!Array.isArray(e.poolKey)?e.poolKey:e;for(let i of["currency0","currency1","fee","tickSpacing"])if(n[i]===void 0)throw new o(`Creating a pool needs the full poolKey (currency0, currency1, fee, tickSpacing, hooks); ${i} is missing. A poolId alone cannot describe a pool that does not exist yet.`)}function dn(e,n,i){if(e.initialPrice!==void 0&&e.sqrtPriceX96!==void 0)throw new o("Provide initialPrice or sqrtPriceX96, not both.");if(e.sqrtPriceX96!==void 0){if(typeof e.sqrtPriceX96!="string"||!/^\d+$/.test(e.sqrtPriceX96))throw new o("sqrtPriceX96 must be a non-negative integer string.");return je(BigInt(e.sqrtPriceX96))}return Re(e.initialPrice,n,i)}async function Gn(e,n,i){let r;try{r=await e.readContract({address:T,abi:H,functionName:"ownerOf",args:[n]})}catch(c){throw new o(`Could not verify owner of Uniswap v4 position #${n}. ${oe(c)}`)}if(y(r)!==y(i))throw new o(`Wallet ${y(i)} is not the owner of Uniswap v4 position #${n} (owned by ${y(r)}).`)}async function un(e,n){let i=ye(n).toLowerCase(),r=new Map;for(let s of Ke)s.key.currency0.toLowerCase()===n.currency0.toLowerCase()&&s.key.currency1.toLowerCase()===n.currency1.toLowerCase()&&r.set(s.poolId.toLowerCase(),s.key);let c=[];for(let[s,t]of r){if(s===i||BigInt(await e.readContract({address:fe,abi:me,functionName:"getLiquidity",args:[s]}))===0n)continue;let a=await e.readContract({address:fe,abi:me,functionName:"getSlot0",args:[s]});BigInt(a[0])>0n&&c.push({label:`v4 fee ${t.fee} spacing ${t.tickSpacing} pool ${s}`,sqrtPriceX96:BigInt(a[0])})}return c}function ln(e,n,i,r,c,s){return e.unsignedTx({to:Cn.toLowerCase(),data:re({abi:Kn,functionName:"initialize",args:[{currency0:n.currency0.toLowerCase(),currency1:n.currency1.toLowerCase(),fee:n.fee,tickSpacing:n.tickSpacing,hooks:n.hooks.toLowerCase()},r]}),value:"0",chainId:f,description:`Create and initialize Uniswap v4 pool ${i} (${c.symbol}/${s.symbol}, fee ${n.fee}, tickSpacing ${n.tickSpacing}) at ${be(r,c.decimals,s.decimals)} ${s.symbol} per ${c.symbol}.`})}var Zn=e=>({tools:[{name:"uniswap_add",inputSchema:On,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=t.tokenId===void 0?void 0:D(String(t.tokenId));if(a!==void 0&&a<=0n)throw new o("Provide a positive v4 position tokenId.");let p=t.initialPrice!==void 0||t.sqrtPriceX96!==void 0;if(a!==void 0&&p)throw new o("initialPrice cannot be combined with tokenId.");if(t.amount0Min!==void 0||t.amount1Min!==void 0||t.slippageBps!==void 0)throw new o("V4 mint encodes fixed liquidity and amount0Max/amount1Max; amount minima and slippageBps are not supported for minting.");let l=e.clientFor(f);p&&cn(t);let m,u,k,w;if(a!==void 0){if(t.tickLower!==void 0||t.tickUpper!==void 0||t.fullRange!==void 0)throw new o("An existing v4 position keeps its tick range; omit tickLower, tickUpper and fullRange when increasing.");await Gn(l,a,d),{poolId:m,poolKey:u,tickLower:k,tickUpper:w}=await he(l,a,t)}else{({poolId:m,poolKey:u}=await Ue(l,t));let q=Vn(u.tickSpacing);k=t.fullRange===!0&&t.tickLower===void 0?q.tickLower:Number(t.tickLower),w=t.fullRange===!0&&t.tickUpper===void 0?q.tickUpper:Number(t.tickUpper),Hn(k,w,u.tickSpacing)}let[b,S]=await Promise.all([V(l,u.currency0,f),V(l,u.currency1,f)]),I=W(t.amount0Max??t.amount0Desired,"amount0Max"),h=W(t.amount1Max??t.amount1Desired,"amount1Max");if(I<=0n&&h<=0n||I>ne||h>ne)throw new o("Provide positive amount0Max/amount1Max within uint128.");let x=await l.readContract({address:fe,abi:me,functionName:"getSlot0",args:[m]}),v=BigInt(x[0]),E=Number(x[3]),P;if(p){if(v>0n)throw new o(`Pool ${m} already exists; remove initialPrice/sqrtPriceX96 to add liquidity at its current price.`);let q=dn(t,b.decimals,S.decimals),F=Le(q,await un(l,u),t.acceptPriceDeviation===!0,b.decimals,S.decimals);P={sqrtPriceX96:q,note:F},v=q}else if(v<=0n)throw new o(`Pool ${m} is not initialized on StateView. To create it and add the first liquidity in one tool call with separately confirmed transactions, pass the full poolKey plus initialPrice (token1 per 1 token0, human units); to create it without liquidity use uniswap_create_pool.`);let C=t.liquidity!==void 0?W(t.liquidity,"liquidity"):Bn({amount0:I,amount1:h,tickLower:k,tickUpper:w,sqrtPriceX96:v});if(C<=0n||C>ne)throw new o("Position liquidity must be a positive integer within uint128.");let{amount0:U,amount1:X}=yn({liquidity:C,tickLower:k,tickUpper:w,sqrtPriceX96:v,roundUp:!0});if(U>I||X>h)throw new o("Liquidity requires more tokens than amount0Max or amount1Max.");let G=t.recipient!==void 0?String(t.recipient):d;if($(G),y(G)!==y(d))throw new o("Uniswap recipient must be the signing wallet.");let Z=await wn(l),te=await Me(l,t.deadline,Z.toString()),ae=te<Z+Ze?te:Z+Ze,Y=t.permit2Expiration===void 0?ae:D(String(t.permit2Expiration));if(Y<=Z||Y>ae||Y>pn)throw new o("Permit2 expiration must be in the next 30 minutes and no later than the transaction deadline.");let M=typeof t.hookData=="string"?t.hookData:"0x",K=(q,F)=>{let z=P?[ln(e,u,m,P.sqrtPriceX96,b,S)]:[];if(!R(u.currency0)&&q>0n){let ce=u.currency0.toLowerCase();z.push(e.approval(ce,_e.toLowerCase(),q.toString(),f)),z.push(en(ce,T.toLowerCase(),q.toString(),Y.toString(),f))}if(!R(u.currency1)&&F>0n){let ce=u.currency1.toLowerCase();z.push(e.approval(ce,_e.toLowerCase(),F.toString(),f)),z.push(en(ce,T.toLowerCase(),F.toString(),Y.toString(),f))}let O={currency0:u.currency0.toLowerCase(),currency1:u.currency1.toLowerCase(),fee:u.fee,tickSpacing:u.tickSpacing,hooks:u.hooks.toLowerCase()},Se=A(_n,[O,k,w,C,q,F,G.toLowerCase(),M]),gn=A(En,[O.currency0,O.currency1]),Ve=A(Un,[g,G.toLowerCase()]),kn=A(ge,[a??0n,C,q,F,M]),hn=a===void 0?A(le,["0x020d14",[Se,gn,Ve]]):A(le,["0x00121214",[kn,A(Ye,[O.currency0]),A(Ye,[O.currency1]),Ve]]),Pn=re({abi:H,functionName:"modifyLiquidities",args:[hn,te]}),vn=R(u.currency0)?q.toString():"0";return z.push(e.unsignedTx({to:T.toLowerCase(),data:Pn,value:vn,chainId:f,description:a!==void 0?`Increase Uniswap v4 position #${a} on pool ${m} (liquidity +${C}).`:`Mint Uniswap v4 position on pool ${m} (ticks [${k}, ${w}], liquidity ${C}).`})),z},Q=K(U,X),J=await e.preview(Q,d),B=(q,F)=>{let z=R(F)?de:F.toLowerCase();return-q.changes.filter(O=>O.token.address.toLowerCase()===z).reduce((O,Se)=>O+BigInt(Se.amount),0n)},N=B(J,u.currency0),ie=B(J,u.currency1);if(N<0n||ie<0n||N>U||ie>X||N===0n&&ie===0n&&a===void 0)throw new o("Invalid simulated v4 mint spend. Refresh the liquidity preview.");let Fe=a===void 0?K(N,ie):Q,we=a!==void 0||N===U&&ie===X?J:await e.preview(Fe,d);if(B(we,u.currency0)!==N||B(we,u.currency1)!==ie)throw new o("V4 mint spend changed. Refresh the liquidity preview.");let bn=$e(we.changes,e.formatAmount),xe=Je(u,E);return{txs:Fe,preview:we,poolId:m,poolKey:u,tickLower:k,tickUpper:w,liquidity:C.toString(),amount0Max:{token:b,amount:I.toString()},amount1Max:{token:S,amount:h.toString()},dynamicFee:xe.dynamicFee,swapsAreFree:xe.swapsAreFree,action:a!==void 0?"increase":P?"createAndMint":"mint",...a!==void 0?{tokenId:a.toString()}:{},...P?{poolCreated:!0,sqrtPriceX96:P.sqrtPriceX96.toString(),initialPrice:be(P.sqrtPriceX96,b.decimals,S.decimals),initialTick:qe(P.sqrtPriceX96),priceCheck:P.note}:{},summary:`${a!==void 0?`Increase Uniswap v4 position #${a}`:P?"Create Uniswap v4 pool and add first liquidity":"Add Uniswap v4 liquidity"} (${C} L, ticks [${k}, ${w}]) on pool ${m}. Preview deltas: ${bn.join(", ")||"none"}. ${xe.feeNote}${P?` ${P.note}`:""}`}}},{name:"uniswap_collect",inputSchema:jn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=D(String(t.tokenId??""));if(a<=0n)throw new o("Provide a positive v4 position tokenId.");let p=e.clientFor(f),l=t.recipient!==void 0?String(t.recipient):d;if($(l),y(l)!==y(d))throw new o("Uniswap recipient must be the signing wallet.");let m=await Me(p,t.deadline,t.now),u=t.amount0Min!==void 0?W(t.amount0Min,"amount0Min"):0n,k=t.amount1Min!==void 0?W(t.amount1Min,"amount1Min"):0n;if(u>ne||k>ne)throw new o("amount0Min and amount1Min must fit in uint128.");let w=typeof t.hookData=="string"?t.hookData:"0x",{poolKey:b,poolId:S}=await he(p,a,t),[I,h]=await Promise.all([V(p,b.currency0,f),V(p,b.currency1,f)]),x=A(ge,[a,0n,u,k,w]),v=A(Te,[b.currency0.toLowerCase(),b.currency1.toLowerCase(),l.toLowerCase()]),E=A(le,["0x0111",[x,v]]),P=re({abi:H,functionName:"modifyLiquidities",args:[E,m]}),C=[e.unsignedTx({to:T.toLowerCase(),data:P,value:"0",chainId:f,description:`Collect Uniswap v4 fees from position #${a} to ${l}.`})],U=await e.preview(C,d),X=$e(U.changes,e.formatAmount);return{txs:C,preview:U,tokenId:a.toString(),poolId:S,recipient:l,currencies:[I,h],summary:`Collect Uniswap v4 fees for position #${a} (actions 0x0111). Preview deltas: ${X.join(", ")||"0"}.`}}},{name:"uniswap_remove",inputSchema:zn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=D(String(t.tokenId??""));if(a<=0n)throw new o("Provide a positive v4 position tokenId.");let p=e.clientFor(f),l=t.recipient!==void 0?String(t.recipient):d;if($(l),y(l)!==y(d))throw new o("Uniswap recipient must be the signing wallet.");let m=await Me(p,t.deadline,t.now),{poolKey:u,poolId:k}=await he(p,a,t),[w,b]=await Promise.all([V(p,u.currency0,f),V(p,u.currency1,f)]),S=t.slippageBps??Ie;if(typeof S!="number")throw new o("Slippage must be an integer from 0 to 9999 bps.");Ce("0",S);let I=typeof t.hookData=="string"?t.hookData:"0x",h=t.fullExit===!0||t.burn===!0||t.liquidity==="all";if(!h&&t.liquidity===void 0)throw new o('Provide a liquidity amount or explicitly choose liquidity "all" for a full exit.');let x=t.liquidity===void 0||t.liquidity==="all"?void 0:W(t.liquidity,"liquidity");if(x!==void 0&&(x<0n||x===0n&&!h||x>ne))throw new o("Provide positive liquidity within uint128 for v4 removal.");let v;try{v=BigInt(await p.readContract({address:T,abi:H,functionName:"getPositionLiquidity",args:[a]}))}catch(M){throw new o(`Could not read v4 position liquidity. ${oe(M)}`)}if(v<0n||v===0n&&!h||x!==void 0&&x>v)throw new o("Removal requires a nonempty position and cannot exceed its liquidity.");if(h&&x!==void 0&&x!==v)throw new o("A full burn must match the position liquidity; omit the amount when explicitly choosing all.");let E=h?"0x0311":"0x0111",P=(M,K,Q)=>{let J=h?A(Dn,[a,M,K,I]):A(ge,[a,x,M,K,I]),B=A(Te,[u.currency0,u.currency1,Q]);return e.unsignedTx({to:T.toLowerCase(),data:re({abi:H,functionName:"modifyLiquidities",args:[A(le,[E,[J,B]]),m]}),value:"0",chainId:f,description:`${h?"Burn and exit":"Decrease"} Uniswap v4 position #${a} (${E}).`})},C=0n,U=0n;if(v>0n&&(t.amount0Min===void 0||t.amount1Min===void 0)){let M=e.unsignedTx({to:T.toLowerCase(),data:re({abi:H,functionName:"modifyLiquidities",args:[A(le,["0x0111",[A(ge,[a,0n,0n,0n,I]),A(Te,[u.currency0,u.currency1,T])]]),m]}),value:"0",chainId:f,description:"Simulation only: separate fees from removal principal."}),K=await e.preview([M,P(2n,2n,d)],d),Q=J=>K.changes.reduce((B,N)=>N.token.chainId===f&&N.token.address.toLowerCase()===J.address.toLowerCase()?B+BigInt(N.amount):B,0n);if(C=Q(w),U=Q(b),C<0n||U<0n)throw new o("Removal simulation did not return the expected currencies.")}let X=(M,K)=>{if(M!==void 0&&W(M,K)!==0n)throw new o(`${K} must be zero for an empty position burn.`);return 0n},G=v===0n?X(t.amount0Min,"amount0Min"):sn(t.amount0Min,C,S,"amount0Min"),Z=v===0n?X(t.amount1Min,"amount1Min"):sn(t.amount1Min,U,S,"amount1Min"),te=[P(G,Z,l)],ae=await e.preview(te,d),Y=$e(ae.changes,e.formatAmount);return{txs:te,preview:ae,action:E,tokenId:a.toString(),poolId:k,amount0Min:{token:w,amount:G.toString()},amount1Min:{token:b,amount:Z.toString()},summary:`${h?"Full exit":"Partial remove"} Uniswap v4 position #${a} (${E})${h?`; burns position #${a} at ${T}`:""}. Preview deltas: ${Y.join(", ")||"none"}.`}}},{name:"uniswap_list_positions",inputSchema:Wn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=Array.isArray(t.tokenIds)?t.tokenIds:void 0,p=t.includeZero===!0,l=await an(e,d,{tokenIds:a,includeZero:p});return{version:"v4",positions:l,summary:`Found ${l.length} active Uniswap v4 position(s) for ${d}.`}}},{name:"uniswap_create_pool",inputSchema:Rn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');cn(t);let a=e.clientFor(f),{poolId:p,poolKey:l}=await Ue(a,t),[m,u]=await Promise.all([V(a,l.currency0,f),V(a,l.currency1,f)]),k=await a.readContract({address:fe,abi:me,functionName:"getSlot0",args:[p]});if(BigInt(k[0])>0n)throw new o(`Uniswap v4 pool ${p} already exists. Use uniswap_add to provide liquidity.`);let w=dn(t,m.decimals,u.decimals),b=Le(w,await un(a,l),t.acceptPriceDeviation===!0,m.decimals,u.decimals),S=be(w,m.decimals,u.decimals),I=[ln(e,l,p,w,m,u)],h=await e.preview(I,d),x=Je(l,l.fee);return{txs:I,preview:h,poolId:p,poolKey:l,sqrtPriceX96:w.toString(),initialPrice:S,initialTick:qe(w),priceCheck:b,action:"createPool",summary:`${I[0].description} The pool starts empty: nothing trades until liquidity is added with uniswap_add. ${x.feeNote} ${b}`}}}],positions:t=>an(e,t)}),ct=Zn;export{Cn as a,T as b,fe as c,_e as d,at as e,se as f,_ as g,g as h,De as i,Ee as j,Pe as k,Ln as l,Ke as m,Ne as n,fn as o,Tn as p,$n as q,R as r,ye as s,mn as t,Je as u,ke as v,Vn as w,Hn as x,en as y,Xn as z,yn as A,Bn as B,$e as C,rn as D,V as E,he as F,an as G,On as H,Rn as I,jn as J,zn as K,Wn as L,un as M,Zn as N,ct as O};
|
|
1
|
+
import{c as Re,d as je,e as qe,f as be,i as Le,j as ze}from"./MEMVFR7Z.js";import{i as ue}from"./LFN3OODW.js";import{b as Ie,o as Ce}from"./CAU44UWP.js";import{a as de}from"./VJ3W2V3B.js";import{a as $,b as Oe}from"./6IM6A5VA.js";import{a as L}from"./UWOFA6GV.js";import{a as D}from"./RETS2ZEK.js";import{a as f,d as Xe,i as ee,j as Be}from"./XPFVT2EA.js";import{a as o,b as He,d as oe}from"./5YS5V2LK.js";import{encodeAbiParameters as A,encodeFunctionData as re,erc20Abi as We,getAddress as y,isAddress as An,keccak256 as xn,pad as Sn,parseAbi as Ae,parseAbiParameters as j,toEventSelector as In,toHex as Ge}from"viem";var Cn=y(ee[4663].uniswap.v4_pool_manager.address),T=y(ee[4663].uniswap.v4_position_manager.address),fe=y(ee[4663].uniswap.v4_state_view.address),_e=y(ee[4663].uniswap.permit2.address),at=y(ee[4663].ponsTrade.universal_router.address),se=y(ee[4663].uniswap.WETH.address),_=y(Be),g="0x0000000000000000000000000000000000000000",De=8388608,Ee=-887272,Pe=887272,pn=(1n<<48n)-1n,ne=(1n<<128n)-1n,qn=(1n<<160n)-1n,pe=1n<<96n,Ze=1800n,Ln="0xbac3aa3b91584a53a579b3c999a56756e954e59247e497bad1d25a4334bde551",Ke=[{poolId:"0xbac3aa3b91584a53a579b3c999a56756e954e59247e497bad1d25a4334bde551",key:{currency0:g,currency1:_,fee:8388608,tickSpacing:10,hooks:y("0x06a889870c8f83640d6816319f72e2aa579b6080")},liquidity:"5532026605872066941",sqrtPriceX96:"3839897026469220985301794",tick:-198703,protocolFee:0,lpFee:0},{poolId:"0x387bf619da4d3fb62bb276482693dba1b9b3520f573cabdfe033384a24125982",key:{currency0:g,currency1:_,fee:500,tickSpacing:10,hooks:g},liquidity:"225820987949255613",sqrtPriceX96:"3840577772610961024680304",tick:-198700,protocolFee:512125,lpFee:500},{poolId:"0x54f7883914619af9105355bf83ed678bcf9f63560218ac61c9963b9503d0ba32",key:{currency0:g,currency1:_,fee:460,tickSpacing:9,hooks:g},liquidity:"85654324417347171",sqrtPriceX96:"3840419018843648722761192",tick:-198701,protocolFee:479349,lpFee:460},{poolId:"0xc7b615a3721594f73664eb3f62d8290d0fcc8d9d1156aed1ddecbd7f32efd9f5",key:{currency0:g,currency1:_,fee:8388608,tickSpacing:10,hooks:y("0xcb787a5cdea8b3715d984d82f1203fd7bfebe0c4")},liquidity:"50517446454827887",sqrtPriceX96:"3840495145865430860317598",tick:-198700,protocolFee:0,lpFee:0},{poolId:"0x24107d152f14a76d292123265ae3f3c71f863fc2f4ef7ba49d64e78d28ea379e",key:{currency0:g,currency1:_,fee:100,tickSpacing:1,hooks:g},liquidity:"36478878201789434",sqrtPriceX96:"3840363370720475418748563",tick:-198701,protocolFee:102425,lpFee:100},{poolId:"0x84bd4e2d8be11aeb0afc1195b38f587b61e90068548f1063fdbe448fb8cad0b6",key:{currency0:se,currency1:_,fee:200,tickSpacing:4,hooks:g},liquidity:"5980655057479791",sqrtPriceX96:"3839891926195366283625355",tick:-198703,protocolFee:213044,lpFee:200},{poolId:"0x3b0cbf0603ecc67b5fc9bb4fbb6ac9e08d3b2f406b63d1662a36063a7fe5e866",key:{currency0:g,currency1:_,fee:87,tickSpacing:1,hooks:g},liquidity:"5486760264498148",sqrtPriceX96:"3840563617639470134132117",tick:-198700,protocolFee:90134,lpFee:87}],Ne=y("0x987e330f00b79864a07fe81dfac344d0078abcc0"),fn="0xa791e5169faf703c0b63fd9552c33ec1128a773a00f5dc33a640da62a022cd35",Tn={currency0:g,currency1:_,fee:De,tickSpacing:1,hooks:Ne},$n=new Set([...Ke.map(e=>e.key.hooks.toLowerCase()),Ne.toLowerCase()]),Mn=j("address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks"),_n=j("(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) poolKey, int24 tickLower, int24 tickUpper, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, address owner, bytes hookData"),En=j("address currency0, address currency1"),Un=j("address currency, address recipient"),ge=j("uint256 tokenId, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes hookData"),Dn=j("uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes hookData"),Te=j("address currency0, address currency1, address recipient"),le=j("bytes actions, bytes[] params"),H=Ae(["function modifyLiquidities(bytes unlockData, uint256 deadline) payable","function poolKeys(bytes25 poolId) view returns (address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks)","function getPositionLiquidity(uint256 tokenId) view returns (uint128 liquidity)","function getPoolAndPositionInfo(uint256 tokenId) view returns ((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) poolKey, uint256 info)","function positionInfo(uint256 tokenId) view returns (uint256 info)","function ownerOf(uint256 tokenId) view returns (address owner)","function nextTokenId() view returns (uint256 tokenId)"]),Kn=Ae(["function initialize((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, uint160 sqrtPriceX96) returns (int24 tick)"]),Ye=j("address currency"),Qe=1e6,me=Ae(["function getSlot0(bytes32 poolId) view returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)","function getLiquidity(bytes32 poolId) view returns (uint128 liquidity)"]),Nn=Ae(["function approve(address token, address spender, uint160 amount, uint48 expiration)"]),Fn=In("Transfer(address,address,uint256)");function ve(e){if(typeof e!="string"||!An(e,{strict:!1}))throw new o("Provide a valid v4 currency address.");let n=e.toLowerCase();return n===g||n===de.toLowerCase()?g:y(e)}function R(e){let n=e.toLowerCase();return n===g||n===de.toLowerCase()}function ye(e){let n=ve(e.currency0),i=ve(e.currency1);$(e.hooks);let r=y(e.hooks);return xn(A(Mn,[n,i,e.fee,e.tickSpacing,r]))}function mn(e){return((typeof e=="number"?e:e.fee)&De)!==0}function Je(e,n){return mn(e)?{dynamicFee:!0,storedLpFee:n,swapsAreFree:!1,feeNote:"Pool uses dynamic fee flag 0x800000; stored lpFee=0 does not mean swaps are free. The hook determines the swap fee; a past observation is not a current quote."}:{dynamicFee:!1,storedLpFee:n,swapsAreFree:n===0,feeNote:`Static LP fee ${n} pips.`}}function ke(e,n){if(!e||typeof e!="object")throw new o("Provide a valid v4 PoolKey.");let i=ve(e.currency0),r=ve(e.currency1);if(BigInt(i)>=BigInt(r))throw new o("PoolKey currencies must be strictly sorted (currency0 < currency1).");if(!Number.isInteger(e.tickSpacing)||e.tickSpacing<=0||e.tickSpacing>32767)throw new o("PoolKey tickSpacing must be a positive integer.");if(!Number.isInteger(e.fee)||e.fee<0||e.fee>16777215)throw new o("PoolKey fee must be a valid uint24.");$(e.hooks);let c=y(e.hooks),s=mn(e.fee);if(!s&&e.fee>Qe)throw new o(`PoolKey static fee ${e.fee} exceeds the v4 maximum of ${Qe} pips (100%).`);if(s&&e.fee!==De)throw new o("Dynamic-fee PoolKey must use exact fee flag 0x800000 (8388608).");if(s&&c.toLowerCase()===g)throw new o("Dynamic-fee PoolKey requires a non-zero hook address.");if(!$n.has(c.toLowerCase()))throw new o(`Unsupported v4 hook ${c}: Oak does not assure arbitrary v4 hooks outside measured PoolKeys.`);let t={currency0:i,currency1:r,fee:e.fee,tickSpacing:e.tickSpacing,hooks:c},d=ye(t);if(c===Ne&&d.toLowerCase()!==fn)throw new o("Only the documented VolatilePair ETH/USDG PoolKey is supported. Pool creation requires the Uniswap Labs role.");if(n!==void 0){if(typeof n!="string"||!/^0x[0-9a-fA-F]{64}$/.test(n))throw new o("Provide a 32-byte hex poolId.");if(d.toLowerCase()!==n.toLowerCase())throw new o(`PoolKey hash (${d}) does not match expected poolId (${n}).`)}return t}function Vn(e){if(!Number.isInteger(e)||e<=0||e>Pe)throw new o("tickSpacing must be a positive integer.");let n=Math.trunc(Ee/e)*e,i=Math.trunc(Pe/e)*e;return{tickLower:n===0?0:n,tickUpper:i===0?0:i}}function Hn(e,n,i){if(!Number.isInteger(i)||i<=0)throw new o("tickSpacing must be a positive integer.");if(!Number.isInteger(e)||!Number.isInteger(n))throw new o("tickLower and tickUpper must be integers.");if(e<Ee||n>Pe)throw new o(`Ticks [${e}, ${n}] are outside Uniswap bounds [${Ee}, ${Pe}].`);if(e>=n)throw new o("tickLower must be strictly less than tickUpper.");if(e%i!==0||n%i!==0)throw new o(`Ticks [${e}, ${n}] must be divisible by tickSpacing ${i}.`)}function en(e,n,i,r,c=f){if($(e),$(n),R(e))throw new o("Native ETH does not use Permit2 approval.");let s=D(i);if(s<=0n||s>qn)throw new o("Permit2 approval amount must be a positive integer within uint160.");let t=D(String(r));if(t<=0n||t>pn)throw new o("Permit2 expiration must be a positive timestamp within uint48.");let d=re({abi:Nn,functionName:"approve",args:[e,n,s,Number(t)]});return Oe({to:_e,data:d,value:"0",chainId:c,description:`Approve Permit2 allowance of ${s} base units of ${e} for ${n} until ${t}.`})}function nn(e){let n=Number(e&0xffffffn);return(n&8388608)!==0?n-16777216:n}function Xn(e){let n=(e&0xffn)!==0n,i=nn(e>>8n&0xffffffn),r=nn(e>>32n&0xffffffn);return{poolIdBytes25:`0x${(e>>56n&(1n<<200n)-1n).toString(16).padStart(50,"0")}`,tickLower:i,tickUpper:r,hasSubscriber:n}}function tn(e,n,i,r=!1){let[c,s]=e<=n?[e,n]:[n,e];if(c<=0n||s<=0n)return 0n;let t=(i<<96n)*(s-c),d=s*c;return r?(t+d-1n)/d:t/d}function on(e,n,i,r=!1){let[c,s]=e<=n?[e,n]:[n,e],t=i*(s-c);return r?(t+pe-1n)/pe:t/pe}function yn(e){if(e.liquidity<=0n)return{amount0:0n,amount1:0n};let n=ue(e.tickLower),i=ue(e.tickUpper);return e.sqrtPriceX96<=n?{amount0:tn(n,i,e.liquidity,e.roundUp),amount1:0n}:e.sqrtPriceX96<i?{amount0:tn(e.sqrtPriceX96,i,e.liquidity,e.roundUp),amount1:on(n,e.sqrtPriceX96,e.liquidity,e.roundUp)}:{amount0:0n,amount1:on(n,i,e.liquidity,e.roundUp)}}function Bn(e){let n=ue(e.tickLower),i=ue(e.tickUpper),r=(s,t,d)=>t<=s||d<=0n?0n:d*s*t/pe/(t-s),c=(s,t,d)=>t<=s||d<=0n?0n:d*pe/(t-s);if(e.sqrtPriceX96<=n)return r(n,i,e.amount0);if(e.sqrtPriceX96<i){let s=r(e.sqrtPriceX96,i,e.amount0),t=c(n,e.sqrtPriceX96,e.amount1);return s<t?s:t}return c(n,i,e.amount1)}function $e(e,n){return e.map(i=>{let r=i.amount.trim(),c=r.startsWith("-"),s=c||r.startsWith("+")?r.slice(1):r,t=n(s,i.token.decimals);return`${c?"-":""}${t} ${i.token.symbol}`})}function rn(e,n=f){if(R(e))return{address:de,symbol:"ETH",decimals:18,chainId:n};let i=y(e);return i.toLowerCase()===_.toLowerCase()?{address:_,symbol:"USDG",decimals:Xe,chainId:n}:i.toLowerCase()===se.toLowerCase()?{address:se,symbol:"WETH",decimals:18,chainId:n}:{address:i,symbol:i.slice(0,10),decimals:18,chainId:n}}async function V(e,n,i=f){if(R(n))return rn(n,i);let r=y(n);if(r.toLowerCase()===_.toLowerCase()||r.toLowerCase()===se.toLowerCase())return rn(r,i);let[c,s]=await Promise.all([e.readContract({address:r,abi:We,functionName:"symbol"}),e.readContract({address:r,abi:We,functionName:"decimals"})]);if(!Number.isInteger(Number(s))||Number(s)<0||Number(s)>77)throw new o(`Token ${r} reports invalid decimals.`);return{address:r,symbol:ze(c,r),decimals:Number(s),chainId:i}}function W(e,n){if(typeof e!="string"||!/^\d+$/.test(e))throw new o(`${n} must be a non-negative integer string in base units.`);return D(e)}function sn(e,n,i,r){let c=e===void 0?D(Ce(n.toString(),i)):W(e,r);if(c<=1n||c>ne)throw new o(`${r} must exceed 1 base unit and fit in uint128; the simulated amount may be too small.`);return c}async function wn(e,n){if(typeof n=="number"&&Number.isFinite(n)&&n>0)return BigInt(Math.floor(n>1e11?n/1e3:n));if(typeof n=="string"&&/^\d+$/.test(n.trim()))return BigInt(n.trim());try{let i=await e.request({method:"eth_getBlockByNumber",params:["latest",!1]});if(i&&typeof i.timestamp=="string")return BigInt(i.timestamp)}catch{}return BigInt(Math.floor(Date.now()/1e3))}async function Me(e,n,i){let r=await wn(e,i);if(n==null)return r+1800n;let c=D(String(n));if(c<=r)throw new o(`Transaction deadline ${c} has expired (current timestamp ${r}).`);return c}async function Ue(e,n){let i=typeof n.poolId=="string"?n.poolId.trim():void 0,r=n.poolKey&&typeof n.poolKey=="object"&&!Array.isArray(n.poolKey)?n.poolKey:void 0,c=r?{currency0:String(r.currency0??g),currency1:String(r.currency1??_),fee:Number(r.fee),tickSpacing:Number(r.tickSpacing),hooks:String(r.hooks??g)}:n.currency0!==void 0&&n.currency1!==void 0&&n.fee!==void 0&&n.tickSpacing!==void 0?{currency0:String(n.currency0),currency1:String(n.currency1),fee:Number(n.fee),tickSpacing:Number(n.tickSpacing),hooks:String(n.hooks??g)}:void 0;if(c){if(R(c.currency0)&&typeof n.token0=="string"&&n.token0.toLowerCase()===se.toLowerCase())throw new o("Native ETH currency0 differs from WETH; do not supply WETH for a native-ETH v4 pool.");let b=ke(c,i);return{poolId:ye(b),poolKey:b}}let s=(i??Ln).toLowerCase();if(s===fn)return{poolId:s,poolKey:ke(Tn,s)};let t=Ke.find(b=>b.poolId.toLowerCase()===s);if(t){if(R(t.key.currency0)&&typeof n.token0=="string"&&n.token0.toLowerCase()===se.toLowerCase())throw new o("Native ETH currency0 differs from WETH; do not supply WETH for a native-ETH v4 pool.");return{poolId:t.poolId,poolKey:t.key}}let d=s.slice(0,52),a=await e.readContract({address:T,abi:H,functionName:"poolKeys",args:[d]}),[p,l,m,u,k]=a;if(p.toLowerCase()===g&&l.toLowerCase()===g&&Number(u)===0)throw new o(`Unknown or uninitialized v4 poolId ${s}.`);let w=ke({currency0:p,currency1:l,fee:Number(m),tickSpacing:Number(u),hooks:k},s);return{poolId:s,poolKey:w}}async function he(e,n,i){try{let[r,c]=await e.readContract({address:T,abi:H,functionName:"getPoolAndPositionInfo",args:[n]}),s=ke({currency0:r.currency0,currency1:r.currency1,fee:Number(r.fee),tickSpacing:Number(r.tickSpacing),hooks:r.hooks});if((i.poolKey||i.poolId)&&(await Ue(e,i)).poolId.toLowerCase()!==ye(s).toLowerCase())throw new o("The supplied PoolKey does not match this v4 position.");let t=Xn(BigInt(c));return{poolKey:s,poolId:ye(s),tickLower:t.tickLower,tickUpper:t.tickUpper}}catch(r){throw new o(`Could not read v4 position #${n}. ${oe(r)}`)}}async function an(e,n,i={}){$(n);let r=y(n),c=e.clientFor(f),s=new Set;if(i.tokenIds)for(let d of i.tokenIds)s.add(D(String(d)).toString());try{let d=await c.getBlockNumber(),a=10000000n;for(let p=0n;p<=d;p+=a){let l=p+a-1n<d?p+a-1n:d,m=await c.request({method:"eth_getLogs",params:[{address:T.toLowerCase(),topics:[Fn,null,Sn(r)],fromBlock:Ge(p),toBlock:Ge(l)}]});if(!Array.isArray(m))throw new o("Invalid v4 position log response.");for(let u of m){if(!Array.isArray(u.topics)||u.topics.length!==4||!/^0x[0-9a-fA-F]{64}$/.test(u.topics[3]??""))throw new o("Invalid v4 position transfer log.");s.add(BigInt(u.topics[3]).toString())}}}catch(d){if(!i.tokenIds)throw new o(`Could not discover v4 positions. ${oe(d)}`)}let t=[];for(let d of s){let a=BigInt(d);try{let p;try{p=await c.readContract({address:T,abi:H,functionName:"ownerOf",args:[a]})}catch(P){if(He(P,3))continue;throw P}if(p.toLowerCase()!==r.toLowerCase())continue;let l=await c.readContract({address:T,abi:H,functionName:"getPositionLiquidity",args:[a]}),m=BigInt(l);if(m===0n&&!i.includeZero)continue;let{poolKey:u,poolId:k,tickLower:w,tickUpper:b}=await he(c,a,{}),S=await c.readContract({address:fe,abi:me,functionName:"getSlot0",args:[k]}),I=BigInt(S[0]),{amount0:h,amount1:x}=yn({liquidity:m,tickLower:w,tickUpper:b,sqrtPriceX96:I}),[v,E]=await Promise.all([V(c,u.currency0,f),V(c,u.currency1,f)]);t.push({module:"uniswap",id:`uniswap:v4:${a.toString()}`,chainId:f,assets:[{token:v,amount:h.toString()},{token:E,amount:x.toString()}],description:`Uniswap v4 LP position #${a.toString()} (${v.symbol}/${E.symbol}, liquidity=${m.toString()}, ticks=[${w},${b}], poolId=${k})`})}catch(p){throw new o(`Could not read v4 position #${a}. ${oe(p)}`)}}return t}var On={type:"object",properties:{version:{type:"string",enum:["v4"]},poolId:{type:"string",description:"32-byte Uniswap v4 poolId hex string."},poolKey:{type:"object",properties:{currency0:{type:"string"},currency1:{type:"string"},fee:{type:"number"},tickSpacing:{type:"number"},hooks:{type:"string"}}},currency0:{type:"string"},currency1:{type:"string"},fee:{type:"number"},tickSpacing:{type:"number"},hooks:{type:"string"},tickLower:{type:"number"},tickUpper:{type:"number"},fullRange:{type:"boolean"},liquidity:L("Position liquidity in base units."),amount0Max:L("Maximum currency0 base units to spend."),amount1Max:L("Maximum currency1 base units to spend."),recipient:{type:"string"},deadline:L(),permit2Expiration:{type:"string"},hookData:{type:"string"},tokenId:L("Existing v4 position NFT to increase (keeps its tick range). Omit to mint a new position."),initialPrice:{type:"string",description:"Only when the pool does not exist: starting price as token1 per 1 token0 in human units (native ETH is 18 decimals). Needs the full poolKey. Creates the pool then mints the first position in separately confirmed transactions."},sqrtPriceX96:{type:"string",description:"Alternative to initialPrice: exact starting sqrtPriceX96."},acceptPriceDeviation:{type:"boolean",description:"Allow a starting price more than 500 bps from other live pools of the pair."}}},Rn={type:"object",description:"Create and initialize an empty Uniswap v4 pool (permissionless PoolManager.initialize). Add liquidity afterwards with uniswap_add.",properties:{version:{type:"string",enum:["v4"]},poolKey:{type:"object",properties:{currency0:{type:"string"},currency1:{type:"string"},fee:{type:"number"},tickSpacing:{type:"number"},hooks:{type:"string"}}},currency0:{type:"string",description:"Lower sorted currency; the zero address is native ETH."},currency1:{type:"string"},fee:{type:"number",description:"Static LP fee in pips (3000 = 0.30%), at most 1000000."},tickSpacing:{type:"number"},hooks:{type:"string",description:"Hook address; only hooks Oak has measured are accepted. Defaults to none."},initialPrice:{type:"string",description:'Starting price as token1 per 1 token0 in human units, e.g. "3000" for 1 ETH = 3000 USDG.'},sqrtPriceX96:{type:"string",description:"Alternative to initialPrice: exact starting sqrtPriceX96."},acceptPriceDeviation:{type:"boolean",description:"Allow a starting price more than 500 bps from other live pools of the pair."}}},jn={type:"object",properties:{version:{type:"string",enum:["v4"]},tokenId:L(),poolId:{type:"string"},poolKey:{type:"object"},amount0Min:L(),amount1Min:L(),recipient:{type:"string"},deadline:L(),hookData:{type:"string"}},required:["tokenId"]},zn={type:"object",properties:{version:{type:"string",enum:["v4"]},tokenId:L(),liquidity:{type:"string",pattern:"^(?:[0-9]+|all)$",description:"Positive base-unit liquidity amount, or all for a full burn."},slippageBps:{type:"integer",minimum:0,maximum:9999,default:Ie},fullExit:{type:"boolean"},burn:{type:"boolean"},amount0Min:L(),amount1Min:L(),poolId:{type:"string"},poolKey:{type:"object"},recipient:{type:"string"},deadline:L(),hookData:{type:"string"}},required:["tokenId"]},Wn={type:"object",properties:{version:{type:"string",enum:["v4"]},tokenIds:{type:"array",items:L()},includeZero:{type:"boolean"}}};function cn(e){let n=e.poolKey&&typeof e.poolKey=="object"&&!Array.isArray(e.poolKey)?e.poolKey:e;for(let i of["currency0","currency1","fee","tickSpacing"])if(n[i]===void 0)throw new o(`Creating a pool needs the full poolKey (currency0, currency1, fee, tickSpacing, hooks); ${i} is missing. A poolId alone cannot describe a pool that does not exist yet.`)}function dn(e,n,i){if(e.initialPrice!==void 0&&e.sqrtPriceX96!==void 0)throw new o("Provide initialPrice or sqrtPriceX96, not both.");if(e.sqrtPriceX96!==void 0){if(typeof e.sqrtPriceX96!="string"||!/^\d+$/.test(e.sqrtPriceX96))throw new o("sqrtPriceX96 must be a non-negative integer string.");return je(BigInt(e.sqrtPriceX96))}return Re(e.initialPrice,n,i)}async function Gn(e,n,i){let r;try{r=await e.readContract({address:T,abi:H,functionName:"ownerOf",args:[n]})}catch(c){throw new o(`Could not verify owner of Uniswap v4 position #${n}. ${oe(c)}`)}if(y(r)!==y(i))throw new o(`Wallet ${y(i)} is not the owner of Uniswap v4 position #${n} (owned by ${y(r)}).`)}async function un(e,n){let i=ye(n).toLowerCase(),r=new Map;for(let s of Ke)s.key.currency0.toLowerCase()===n.currency0.toLowerCase()&&s.key.currency1.toLowerCase()===n.currency1.toLowerCase()&&r.set(s.poolId.toLowerCase(),s.key);let c=[];for(let[s,t]of r){if(s===i||BigInt(await e.readContract({address:fe,abi:me,functionName:"getLiquidity",args:[s]}))===0n)continue;let a=await e.readContract({address:fe,abi:me,functionName:"getSlot0",args:[s]});BigInt(a[0])>0n&&c.push({label:`v4 fee ${t.fee} spacing ${t.tickSpacing} pool ${s}`,sqrtPriceX96:BigInt(a[0])})}return c}function ln(e,n,i,r,c,s){return e.unsignedTx({to:Cn.toLowerCase(),data:re({abi:Kn,functionName:"initialize",args:[{currency0:n.currency0.toLowerCase(),currency1:n.currency1.toLowerCase(),fee:n.fee,tickSpacing:n.tickSpacing,hooks:n.hooks.toLowerCase()},r]}),value:"0",chainId:f,description:`Create and initialize Uniswap v4 pool ${i} (${c.symbol}/${s.symbol}, fee ${n.fee}, tickSpacing ${n.tickSpacing}) at ${be(r,c.decimals,s.decimals)} ${s.symbol} per ${c.symbol}.`})}var Zn=e=>({tools:[{name:"uniswap_add",inputSchema:On,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=t.tokenId===void 0?void 0:D(String(t.tokenId));if(a!==void 0&&a<=0n)throw new o("Provide a positive v4 position tokenId.");let p=t.initialPrice!==void 0||t.sqrtPriceX96!==void 0;if(a!==void 0&&p)throw new o("initialPrice cannot be combined with tokenId.");if(t.amount0Min!==void 0||t.amount1Min!==void 0||t.slippageBps!==void 0)throw new o("V4 mint encodes fixed liquidity and amount0Max/amount1Max; amount minima and slippageBps are not supported for minting.");let l=e.clientFor(f);p&&cn(t);let m,u,k,w;if(a!==void 0){if(t.tickLower!==void 0||t.tickUpper!==void 0||t.fullRange!==void 0)throw new o("An existing v4 position keeps its tick range; omit tickLower, tickUpper and fullRange when increasing.");await Gn(l,a,d),{poolId:m,poolKey:u,tickLower:k,tickUpper:w}=await he(l,a,t)}else{({poolId:m,poolKey:u}=await Ue(l,t));let q=Vn(u.tickSpacing);k=t.fullRange===!0&&t.tickLower===void 0?q.tickLower:Number(t.tickLower),w=t.fullRange===!0&&t.tickUpper===void 0?q.tickUpper:Number(t.tickUpper),Hn(k,w,u.tickSpacing)}let[b,S]=await Promise.all([V(l,u.currency0,f),V(l,u.currency1,f)]),I=W(t.amount0Max??t.amount0Desired,"amount0Max"),h=W(t.amount1Max??t.amount1Desired,"amount1Max");if(I<=0n&&h<=0n||I>ne||h>ne)throw new o("Provide positive amount0Max/amount1Max within uint128.");let x=await l.readContract({address:fe,abi:me,functionName:"getSlot0",args:[m]}),v=BigInt(x[0]),E=Number(x[3]),P;if(p){if(v>0n)throw new o(`Pool ${m} already exists; remove initialPrice/sqrtPriceX96 to add liquidity at its current price.`);let q=dn(t,b.decimals,S.decimals),F=Le(q,await un(l,u),t.acceptPriceDeviation===!0,b.decimals,S.decimals);P={sqrtPriceX96:q,note:F},v=q}else if(v<=0n)throw new o(`Pool ${m} is not initialized on StateView. To create it and add the first liquidity in one tool call with separately confirmed transactions, pass the full poolKey plus initialPrice (token1 per 1 token0, human units); to create it without liquidity use uniswap_create_pool.`);let C=t.liquidity!==void 0?W(t.liquidity,"liquidity"):Bn({amount0:I,amount1:h,tickLower:k,tickUpper:w,sqrtPriceX96:v});if(C<=0n||C>ne)throw new o("Position liquidity must be a positive integer within uint128.");let{amount0:U,amount1:X}=yn({liquidity:C,tickLower:k,tickUpper:w,sqrtPriceX96:v,roundUp:!0});if(U>I||X>h)throw new o("Liquidity requires more tokens than amount0Max or amount1Max.");let G=t.recipient!==void 0?String(t.recipient):d;if($(G),y(G)!==y(d))throw new o("Uniswap recipient must be the signing wallet.");let Z=await wn(l),te=await Me(l,t.deadline,Z.toString()),ae=te<Z+Ze?te:Z+Ze,Y=t.permit2Expiration===void 0?ae:D(String(t.permit2Expiration));if(Y<=Z||Y>ae||Y>pn)throw new o("Permit2 expiration must be in the next 30 minutes and no later than the transaction deadline.");let M=typeof t.hookData=="string"?t.hookData:"0x",K=(q,F)=>{let z=P?[ln(e,u,m,P.sqrtPriceX96,b,S)]:[];if(!R(u.currency0)&&q>0n){let ce=u.currency0.toLowerCase();z.push(e.approval(ce,_e.toLowerCase(),q.toString(),f)),z.push(en(ce,T.toLowerCase(),q.toString(),Y.toString(),f))}if(!R(u.currency1)&&F>0n){let ce=u.currency1.toLowerCase();z.push(e.approval(ce,_e.toLowerCase(),F.toString(),f)),z.push(en(ce,T.toLowerCase(),F.toString(),Y.toString(),f))}let O={currency0:u.currency0.toLowerCase(),currency1:u.currency1.toLowerCase(),fee:u.fee,tickSpacing:u.tickSpacing,hooks:u.hooks.toLowerCase()},Se=A(_n,[O,k,w,C,q,F,G.toLowerCase(),M]),gn=A(En,[O.currency0,O.currency1]),Ve=A(Un,[g,G.toLowerCase()]),kn=A(ge,[a??0n,C,q,F,M]),hn=a===void 0?A(le,["0x020d14",[Se,gn,Ve]]):A(le,["0x00121214",[kn,A(Ye,[O.currency0]),A(Ye,[O.currency1]),Ve]]),Pn=re({abi:H,functionName:"modifyLiquidities",args:[hn,te]}),vn=R(u.currency0)?q.toString():"0";return z.push(e.unsignedTx({to:T.toLowerCase(),data:Pn,value:vn,chainId:f,description:a!==void 0?`Increase Uniswap v4 position #${a} on pool ${m} (liquidity +${C}).`:`Mint Uniswap v4 position on pool ${m} (ticks [${k}, ${w}], liquidity ${C}).`})),z},Q=K(U,X),J=await e.preview(Q,d),B=(q,F)=>{let z=R(F)?de:F.toLowerCase();return-q.changes.filter(O=>O.token.address.toLowerCase()===z).reduce((O,Se)=>O+BigInt(Se.amount),0n)},N=B(J,u.currency0),ie=B(J,u.currency1);if(N<0n||ie<0n||N>U||ie>X||N===0n&&ie===0n&&a===void 0)throw new o("Invalid simulated v4 mint spend. Refresh the liquidity preview.");let Fe=a===void 0?K(N,ie):Q,we=a!==void 0||N===U&&ie===X?J:await e.preview(Fe,d);if(B(we,u.currency0)!==N||B(we,u.currency1)!==ie)throw new o("V4 mint spend changed. Refresh the liquidity preview.");let bn=$e(we.changes,e.formatAmount),xe=Je(u,E);return{txs:Fe,preview:we,poolId:m,poolKey:u,tickLower:k,tickUpper:w,liquidity:C.toString(),amount0Max:{token:b,amount:I.toString()},amount1Max:{token:S,amount:h.toString()},dynamicFee:xe.dynamicFee,swapsAreFree:xe.swapsAreFree,action:a!==void 0?"increase":P?"createAndMint":"mint",...a!==void 0?{tokenId:a.toString()}:{},...P?{poolCreated:!0,sqrtPriceX96:P.sqrtPriceX96.toString(),initialPrice:be(P.sqrtPriceX96,b.decimals,S.decimals),initialTick:qe(P.sqrtPriceX96),priceCheck:P.note}:{},summary:`${a!==void 0?`Increase Uniswap v4 position #${a}`:P?"Create Uniswap v4 pool and add first liquidity":"Add Uniswap v4 liquidity"} (${C} L, ticks [${k}, ${w}]) on pool ${m}. Preview deltas: ${bn.join(", ")||"none"}. ${xe.feeNote}${P?` ${P.note}`:""}`}}},{name:"uniswap_collect",inputSchema:jn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=D(String(t.tokenId??""));if(a<=0n)throw new o("Provide a positive v4 position tokenId.");let p=e.clientFor(f),l=t.recipient!==void 0?String(t.recipient):d;if($(l),y(l)!==y(d))throw new o("Uniswap recipient must be the signing wallet.");let m=await Me(p,t.deadline,t.now),u=t.amount0Min!==void 0?W(t.amount0Min,"amount0Min"):0n,k=t.amount1Min!==void 0?W(t.amount1Min,"amount1Min"):0n;if(u>ne||k>ne)throw new o("amount0Min and amount1Min must fit in uint128.");let w=typeof t.hookData=="string"?t.hookData:"0x",{poolKey:b,poolId:S}=await he(p,a,t),[I,h]=await Promise.all([V(p,b.currency0,f),V(p,b.currency1,f)]),x=A(ge,[a,0n,u,k,w]),v=A(Te,[b.currency0.toLowerCase(),b.currency1.toLowerCase(),l.toLowerCase()]),E=A(le,["0x0111",[x,v]]),P=re({abi:H,functionName:"modifyLiquidities",args:[E,m]}),C=[e.unsignedTx({to:T.toLowerCase(),data:P,value:"0",chainId:f,description:`Collect Uniswap v4 fees from position #${a} to ${l}.`})],U=await e.preview(C,d),X=$e(U.changes,e.formatAmount);return{txs:C,preview:U,tokenId:a.toString(),poolId:S,recipient:l,currencies:[I,h],summary:`Collect Uniswap v4 fees for position #${a} (actions 0x0111). Preview deltas: ${X.join(", ")||"0"}.`}}},{name:"uniswap_remove",inputSchema:zn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=D(String(t.tokenId??""));if(a<=0n)throw new o("Provide a positive v4 position tokenId.");let p=e.clientFor(f),l=t.recipient!==void 0?String(t.recipient):d;if($(l),y(l)!==y(d))throw new o("Uniswap recipient must be the signing wallet.");let m=await Me(p,t.deadline,t.now),{poolKey:u,poolId:k}=await he(p,a,t),[w,b]=await Promise.all([V(p,u.currency0,f),V(p,u.currency1,f)]),S=t.slippageBps??Ie;if(typeof S!="number")throw new o("Slippage must be an integer from 0 to 9999 bps.");Ce("0",S);let I=typeof t.hookData=="string"?t.hookData:"0x",h=t.fullExit===!0||t.burn===!0||t.liquidity==="all";if(!h&&t.liquidity===void 0)throw new o('Provide a liquidity amount or explicitly choose liquidity "all" for a full exit.');let x=t.liquidity===void 0||t.liquidity==="all"?void 0:W(t.liquidity,"liquidity");if(x!==void 0&&(x<0n||x===0n&&!h||x>ne))throw new o("Provide positive liquidity within uint128 for v4 removal.");let v;try{v=BigInt(await p.readContract({address:T,abi:H,functionName:"getPositionLiquidity",args:[a]}))}catch(M){throw new o(`Could not read v4 position liquidity. ${oe(M)}`)}if(v<0n||v===0n&&!h||x!==void 0&&x>v)throw new o("Removal requires a nonempty position and cannot exceed its liquidity.");if(h&&x!==void 0&&x!==v)throw new o("A full burn must match the position liquidity; omit the amount when explicitly choosing all.");let E=h?"0x0311":"0x0111",P=(M,K,Q)=>{let J=h?A(Dn,[a,M,K,I]):A(ge,[a,x,M,K,I]),B=A(Te,[u.currency0,u.currency1,Q]);return e.unsignedTx({to:T.toLowerCase(),data:re({abi:H,functionName:"modifyLiquidities",args:[A(le,[E,[J,B]]),m]}),value:"0",chainId:f,description:`${h?"Burn and exit":"Decrease"} Uniswap v4 position #${a} (${E}).`})},C=0n,U=0n;if(v>0n&&(t.amount0Min===void 0||t.amount1Min===void 0)){let M=e.unsignedTx({to:T.toLowerCase(),data:re({abi:H,functionName:"modifyLiquidities",args:[A(le,["0x0111",[A(ge,[a,0n,0n,0n,I]),A(Te,[u.currency0,u.currency1,T])]]),m]}),value:"0",chainId:f,description:"Simulation only: separate fees from removal principal."}),K=await e.preview([M,P(2n,2n,d)],d),Q=J=>K.changes.reduce((B,N)=>N.token.chainId===f&&N.token.address.toLowerCase()===J.address.toLowerCase()?B+BigInt(N.amount):B,0n);if(C=Q(w),U=Q(b),C<0n||U<0n)throw new o("Removal simulation did not return the expected currencies.")}let X=(M,K)=>{if(M!==void 0&&W(M,K)!==0n)throw new o(`${K} must be zero for an empty position burn.`);return 0n},G=v===0n?X(t.amount0Min,"amount0Min"):sn(t.amount0Min,C,S,"amount0Min"),Z=v===0n?X(t.amount1Min,"amount1Min"):sn(t.amount1Min,U,S,"amount1Min"),te=[P(G,Z,l)],ae=await e.preview(te,d),Y=$e(ae.changes,e.formatAmount);return{txs:te,preview:ae,action:E,tokenId:a.toString(),poolId:k,amount0Min:{token:w,amount:G.toString()},amount1Min:{token:b,amount:Z.toString()},summary:`${h?"Full exit":"Partial remove"} Uniswap v4 position #${a} (${E})${h?`; burns position #${a} at ${T}`:""}. Preview deltas: ${Y.join(", ")||"none"}.`}}},{name:"uniswap_list_positions",inputSchema:Wn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');let a=Array.isArray(t.tokenIds)?t.tokenIds:void 0,p=t.includeZero===!0,l=await an(e,d,{tokenIds:a,includeZero:p});return{version:"v4",positions:l,summary:`Found ${l.length} active Uniswap v4 position(s) for ${d}.`}}},{name:"uniswap_create_pool",inputSchema:Rn,async execute(t,d){if($(d),t.version!==void 0&&t.version!=="v4")throw new o('Uniswap v4 part only handles version "v4".');cn(t);let a=e.clientFor(f),{poolId:p,poolKey:l}=await Ue(a,t),[m,u]=await Promise.all([V(a,l.currency0,f),V(a,l.currency1,f)]),k=await a.readContract({address:fe,abi:me,functionName:"getSlot0",args:[p]});if(BigInt(k[0])>0n)throw new o(`Uniswap v4 pool ${p} already exists. Use uniswap_add to provide liquidity.`);let w=dn(t,m.decimals,u.decimals),b=Le(w,await un(a,l),t.acceptPriceDeviation===!0,m.decimals,u.decimals),S=be(w,m.decimals,u.decimals),I=[ln(e,l,p,w,m,u)],h=await e.preview(I,d),x=Je(l,l.fee);return{txs:I,preview:h,poolId:p,poolKey:l,sqrtPriceX96:w.toString(),initialPrice:S,initialTick:qe(w),priceCheck:b,action:"createPool",summary:`${I[0].description} The pool starts empty: nothing trades until liquidity is added with uniswap_add. ${x.feeNote} ${b}`}}}],positions:t=>an(e,t)}),ct=Zn;export{Cn as a,T as b,fe as c,_e as d,at as e,se as f,_ as g,g as h,De as i,Ee as j,Pe as k,Ln as l,Ke as m,Ne as n,fn as o,Tn as p,$n as q,R as r,ye as s,mn as t,Je as u,ke as v,Vn as w,Hn as x,en as y,Xn as z,yn as A,Bn as B,$e as C,rn as D,V as E,he as F,an as G,On as H,Rn as I,jn as J,zn as K,Wn as L,un as M,Zn as N,ct as O};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as h}from"./
|
|
1
|
+
import{a as h}from"./72AWP4BM.js";import{c as p}from"./73N3TOJL.js";import{a as l}from"./XPFVT2EA.js";import{a}from"./5YS5V2LK.js";import{getAddress as v}from"viem";var f={type:"string",pattern:"^0x[0-9a-fA-F]{64}$"},w=[["hookr_release",{},[],"Read verified release contracts, block and recapture lane."],["hookr_blocks",{},[],"Read all Hook Blocks and their current availability."],["hookr_kings",{poolId:f},[],"Read King of the Pool rounds, leaders, pots and endings."],["hookr_claims",{poolId:f},[],"Read the signing wallet's prizes, royalties, recapture and PoolManager claims."],["hookr_revenue_tokens",{limit:{type:"integer",minimum:1,maximum:50},cursor:{type:"string",pattern:"^(v1|v1:[1-9][0-9]{0,19}|v2:[1-9][0-9]{0,19})$"}},[],"Read revenue tokens, tokenizer provenance, streams and income, page by page."],["hookr_revenue_token",{token:p},["token"],"Read a revenue token, stream endings, income, drops and the signing wallet's claims."],["hookr_hook",{address:p},["address"],"Read shared or owned hook provenance, ownership, allowed blocks, opening and pools."]],H=[...w.map(d=>d[0]),"hookr_contracts","hookr_read","hookr_revenue_read","hookr_addon_read","hookr_api_read"];function j(d){return[...w.map(([t,c,s,o])=>({name:t,inputSchema:{type:"object",description:o,properties:c,required:s,additionalProperties:!1},execute:async(r,g)=>{if(Object.keys(r).some(n=>!Object.hasOwn(c,n))||s.some(n=>r[n]===void 0))throw new a(`Provide the documented arguments for ${t}.`);let k={};for(let[n,i]of Object.entries(r)){let u=c[n];if(u.type==="integer"){if(typeof i!="number"||!Number.isInteger(i)||i<Number(u.minimum)||i>Number(u.maximum))throw new a("Hookr revenue page limit must be an integer from 1 to 50.")}else if(typeof i!="string"||!new RegExp(String(u.pattern)).test(i))throw new a(`Provide a valid Hookr ${n}.`);k[n]=n==="token"||n==="address"?v(String(i)):i}return(t==="hookr_claims"||t==="hookr_revenue_token")&&(k.account=g),{...await h(d,t,k),chainId:l,source:"https://hookr.fun/api/mcp"}}})),y(d)]}var m={catalog:"/api/hooks/catalog",stats:"/api/protocol-stats",poolApr:"/api/pool-apr",revenueTokens:"/api/revenue-tokens",revenueIncome:"/api/revenue-tokens/income"};function y(d){return{name:"hookr_api_read",inputSchema:{type:"object",description:"Read Hookr public catalog, protocol stats, pool APR, revenue directory/income, or one token's doors/mark. Marks are project metadata, not investment or security endorsements.",properties:{resource:{type:"string",enum:[...Object.keys(m),"revenueDoors","revenueMark"]},token:p},required:["resource"],additionalProperties:!1},execute:async e=>{if(Object.keys(e).some(o=>!["resource","token"].includes(o))||typeof e.resource!="string")throw new a("Choose a documented Hookr public resource.");let t=["revenueDoors","revenueMark"].includes(e.resource);if(!t&&e.token!==void 0||t&&typeof e.token!="string")throw new a("Only the revenueDoors and revenueMark resources take a token address.");let c;if(t){let o;try{o=v(String(e.token))}catch{throw new a("Provide a valid revenue token address.")}c=`/api/revenue-tokens/${o}/${e.resource==="revenueDoors"?"doors":"mark"}`}else{if(!Object.hasOwn(m,e.resource))throw new a("Choose a documented Hookr public resource.");c=m[e.resource]}let s=`https://hookr.fun${c}`;try{let o=await d.http(s,{method:"GET",redirect:"error",signal:AbortSignal.timeout(15e3)});if(!o.ok)throw new Error("Unavailable");if(e.resource==="revenueMark"){if(!o.headers.get("content-type")?.includes("image/svg+xml"))throw new Error("Invalid mark");return{chainId:l,source:s,imageUrl:s,pngUrl:`${s}.png`,note:"Official SVG mark URL; SVG code is not executed or returned. The PNG URL has not been fetched."}}let r=await o.json();if(!r||typeof r!="object"||"error"in r||"status"in r&&r.status==="unavailable")throw new Error("Unavailable");return{chainId:l,source:s,data:r}}catch{throw new a("Hookr public resource is unavailable. Retry later; no empty or zero result is implied.")}}}}export{H as a,j as b,y as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{m as v,n as F}from"./D3OWLDVB.js";import{b as A,i as U,n as X,o as V,q as j}from"./CCEWSOBT.js";import{a as q}from"./RFJCG4NA.js";import{b as z,e as C,n as Y}from"./T3MGNKA6.js";import{a as w,b as S}from"./VJ3W2V3B.js";import{a as k}from"./LIUXNOLP.js";import{a as x}from"./OG5HRQU4.js";import{a as B}from"./AXYOJBX6.js";import{b as $}from"./MYBDO5SA.js";import{a as T}from"./RETS2ZEK.js";import{o as y}from"./IWALIX7Q.js";import{a as u,b as f,c as H,d as P,i as g,j as R,k as W,p as K}from"./XPFVT2EA.js";import{a as o}from"./5YS5V2LK.js";import{a as N,b as L}from"./JXOEJPJ4.js";import{getAddress as b,isAddress as J,parseAbi as se}from"viem";var Q=[{inputs:[],name:"available",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"ethUsdE18",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"liquidityUsdgE6",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"phase",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"priceSigner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"signer",type:"address"}],name:"setPriceSigner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"spotOakPerEthE18",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"supplyNet",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"syncPhase",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"wallet",type:"address"},{internalType:"uint256",name:"oakPerEthE18",type:"uint256"},{internalType:"uint64",name:"timestamp",type:"uint64"},{internalType:"bytes32",name:"nonce",type:"bytes32"}],internalType:"struct PriceNote",name:"n",type:"tuple"},{internalType:"bytes",name:"sig",type:"bytes"},{internalType:"address",name:"boundWallet",type:"address"}],name:"verifyNote",outputs:[{internalType:"uint256",name:"oakPerEthE18",type:"uint256"}],stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"signer",type:"address"}],name:"PriceSignerSet",type:"event"},{inputs:[],name:"NotReady",type:"error"},{inputs:[],name:"NoteBadSignature",type:"error"},{inputs:[],name:"NoteExpired",type:"error"},{inputs:[],name:"NoteNotYetValid",type:"error"},{inputs:[{internalType:"uint256",name:"spot",type:"uint256"},{internalType:"uint256",name:"note",type:"uint256"}],name:"NoteOutsideGuard",type:"error"},{inputs:[],name:"NoteWrongWallet",type:"error"},{inputs:[{internalType:"address",name:"source",type:"address"}],name:"OracleUnreadable",type:"error"}];var M=300,oe="1000000000000000000",ee=b(g[u].tokens.USDG.address),te=b(g[f].deployments.test_USDG.address),O=b(g[u].tokens.WETH.address),_=b(g[f].deployments.test_WETH.address);function ne(n){let e=n.address.toLowerCase();return n.chainId===u?e===ee.toLowerCase():n.chainId===f?e===te.toLowerCase():!1}function re(n){return n.chainId!==u&&n.chainId!==f?!1:S(n.address)===w}function ie(n){let e=n.address.toLowerCase();return n.chainId===u?e===O.toLowerCase():n.chainId===f?e===_.toLowerCase():!1}function de(n){return re(n)||ie(n)}var ce=-887272,me=887272,ue=(1n<<256n)-1n,fe=se(["function observe(uint32[] secondsAgos) view returns (int56[] tickCumulatives, uint160[] secondsPerLiquidityCumulativeX128s)","function slot0() view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)"]);function I(n,e){if(typeof n=="bigint")return n;if(typeof n=="number"){if(!Number.isSafeInteger(n))throw new o(`Invalid ${e} timestamp.`);return BigInt(n)}if(typeof n=="string"&&/^-?\d+$/.test(n.trim()))return BigInt(n.trim());throw new o(`Invalid ${e} timestamp.`)}function Oe(n,e=BigInt(Math.floor(Date.now()/1e3)),t=M){try{return l(n,e,t),!0}catch{return!1}}function l(n,e=BigInt(Math.floor(Date.now()/1e3)),t=M){if(!Number.isInteger(t)||t<0)throw new o("Maximum price age must be a non-negative integer.");let s=I(n,"price"),a=I(e,"current");if(s<=0n)throw new o("Price timestamp must be positive.");if(s>a)throw new o("Price timestamp is in the future.");let r=a-s;if(r>BigInt(t))throw new o(`Price is stale: age ${r}s exceeds ${t}s.`);return s.toString()}function le(n){if(!Number.isInteger(n)||n<ce||n>me)throw new o(`Tick ${n} is outside valid Uniswap bounds.`);let e=BigInt(n<0?-n:n),t=(e&0x1n)!==0n?0xfffcb933bd6fad37aa2d162d1a594001n:0x100000000000000000000000000000000n;return(e&0x2n)!==0n&&(t=t*0xfff97272373d413259a46990580e213an>>128n),(e&0x4n)!==0n&&(t=t*0xfff2e50f5f656932ef12357cf3c7fdccn>>128n),(e&0x8n)!==0n&&(t=t*0xffe5caca7e10e4e61c3624eaa0941cd0n>>128n),(e&0x10n)!==0n&&(t=t*0xffcb9843d60f6159c9db58835c926644n>>128n),(e&0x20n)!==0n&&(t=t*0xff973b41fa98c081472e6896dfb254c0n>>128n),(e&0x40n)!==0n&&(t=t*0xff2ea16466c96a3843ec78b326b52861n>>128n),(e&0x80n)!==0n&&(t=t*0xfe5dee046a99a2a811c461f1969c3053n>>128n),(e&0x100n)!==0n&&(t=t*0xfcbe86c7900a88aedcffc83b479aa3a4n>>128n),(e&0x200n)!==0n&&(t=t*0xf987a7253ac413176f2b074cf7815e54n>>128n),(e&0x400n)!==0n&&(t=t*0xf3392b0822b70005940c7a398e4b70f3n>>128n),(e&0x800n)!==0n&&(t=t*0xe7159475a2c29b7443b29c7fa6e889d9n>>128n),(e&0x1000n)!==0n&&(t=t*0xd097f3bdfd2022b8845ad8f792aa5825n>>128n),(e&0x2000n)!==0n&&(t=t*0xa9f746462d870fdf8a65dc1f90e061e5n>>128n),(e&0x4000n)!==0n&&(t=t*0x70d869a156d2a1b890bb3df62baf32f7n>>128n),(e&0x8000n)!==0n&&(t=t*0x31be135f97d08fd981231505542fcfa6n>>128n),(e&0x10000n)!==0n&&(t=t*0x9aa508b5b7a84e1c677de54f3e99bc9n>>128n),(e&0x20000n)!==0n&&(t=t*0x5d6af8dedb81196699c329225ee604n>>128n),(e&0x40000n)!==0n&&(t=t*0x2216e584f5fa1ea926041bedfe98n>>128n),(e&0x80000n)!==0n&&(t=t*0x48a170391f7dc42444e8fa2n>>128n),n>0&&(t=ue/t),(t>>32n)+(t%(1n<<32n)===0n?0n:1n)}async function Z(n,e,t,s){let a=async()=>{throw new o("Price identity resolution is read-only.")},r=B({network:e===f?"testnet":"mainnet",clientFor:i=>t.client??y(t.rpcUrl,i),http:t.http??$(),preview:a,quoteSwap:a,buildSwap:a}),c=await Y(n,{context:r,oakTokenAddress:t.oakTokenAddress??process.env.OAK_TOKEN_ADDRESS,officialStockTokens:t.officialStockTokens,tokenMetadata:s,blockNumber:t.blockNumber,readMetadata:async i=>{let d=t.client??y(t.rpcUrl,e),[m,p]=await Promise.all([x(d,e,i,"symbol",t.blockNumber),x(d,e,i,"decimals",t.blockNumber)]);return{address:i,symbol:m,decimals:p,chainId:e}}});return{address:c.address,symbol:c.kind==="erc20"&&s?s.symbol:c.symbol,decimals:c.decimals,chainId:c.chainId}}async function be(n,e,t){if(typeof n=="object"&&n!==null){let i=n.chainId??e,d=S(n.address)===w?w:b(n.address),m={address:d,symbol:n.symbol,decimals:n.decimals,chainId:i};return ne(m)?{address:d,symbol:"USDG",decimals:P,chainId:i}:re(m)?{address:w,symbol:"ETH",decimals:18,chainId:i}:ie(m)?{address:d,symbol:"WETH",decimals:18,chainId:i}:Z(m.address,i,t,m)}let s=n.trim(),a=s.toUpperCase(),r=s.toLowerCase();if(a==="ETH"||J(s,{strict:!1})&&S(s)===w)return{...z,chainId:e};if(a==="WETH"||e===u&&r===O.toLowerCase()||e===f&&r===_.toLowerCase()){if(e!==u&&e!==f)throw new o(`No canonical WETH address configured for chain ${e}.`);return{address:e===f?_:O,symbol:"WETH",decimals:18,chainId:e}}if(a==="USDG"||e===u&&r===R.toLowerCase()||e===f&&r===W.toLowerCase()){if(e!==u&&e!==f)throw new o(`No canonical USDG address configured for chain ${e}.`);return{address:e===f?te:ee,symbol:"USDG",decimals:P,chainId:e}}if(e===u&&(a==="USDE"||r===C.address.toLowerCase()))return{...C,chainId:e};let c=t.oakTokenAddress??process.env.OAK_TOKEN_ADDRESS;if(a==="OAK"||c&&s.toLowerCase()===c.toLowerCase()){if(!c&&!J(s,{strict:!1}))throw new o("OAK token address is required to price OAK.");return{address:b(c??s),symbol:"OAK",decimals:H,chainId:e}}return Z(n,e,t)}async function h(n,e,t){if(e)return(await n.readContract({address:e,abi:Q,functionName:"ethUsdE18",blockNumber:t})).toString();let a=(await n.readContract({address:b(K),abi:fe,functionName:"observe",args:[[A,0]],blockNumber:t}))[0];if(!a||a.length<2)throw new o("ETH/USDG pool observation returned insufficient tick cumulatives.");let r=X(a[0],a[1],A),c=le(r);return V(c)}async function D(n,e,t,s){if(n.timestamp!==void 0)return l(n.timestamp,t(),s);if(e&&typeof e.getBlock=="function"){let r=await k(e,n.blockNumber);return l(r.timestamp,t(),s)}let a=t();return l(a,a,s)}async function _e(n,e={}){let t=e.chainId??u,s=e.maxAgeSeconds??M,a=()=>e.now!==void 0?I(e.now,"current"):BigInt(Math.floor(Date.now()/1e3)),r=await be(n,t,e);if((L(r.symbol)||r.symbol.length>256)&&(r.symbol=N(r.symbol)),e.signedNote||e.priceNote){let i=e.signedNote?e.signedNote.note:e.priceNote,d=l(i.timestamp,a(),s);if(e.spotOakPerEthE18!==void 0&&!v(i.oakPerEthE18,e.spotOakPerEthE18))throw new o("Price note is outside the 50% spot guard band.");let m=e.signedNote?.signature??e.signature,p=e.signedNote?.consumer??e.consumer;if(m&&p){let G=await F({note:i,signature:m,consumer:p,signer:e.signer,now:a(),spotOakPerEthE18:e.spotOakPerEthE18,chainId:t});if(!G.valid)throw new o(G.error??"Price note verification failed.")}let E=e.ethUsdE18!==void 0?e.ethUsdE18.toString():await h(e.client??y(e.rpcUrl,t),e.oracleAddress);return{token:r,usdE18:U(E,i.oakPerEthE18),timestamp:d}}if(e.trades){let i=await D(e,e.client,a,s),d=j(e.trades,{now:a(),windowStart:e.windowStart,windowEnd:e.windowEnd});if(e.spotOakPerEthE18!==void 0&&!v(d,e.spotOakPerEthE18))throw new o("30-minute average is outside the 50% spot guard band.");let m=e.ethUsdE18!==void 0?e.ethUsdE18.toString():await h(e.client??y(e.rpcUrl,t),e.oracleAddress);return{token:r,usdE18:U(m,d),timestamp:i}}if(e.usdE18!==void 0){let i=await D(e,e.client,a,s),d=T(e.usdE18.toString());if(d<=0n)throw new o("USD price must be positive.");return{token:r,usdE18:d.toString(),timestamp:i}}if(e.resolver){let i=await e.resolver(r),d=l(i.timestamp,a(),s),m=T(i.usdE18);if(m<=0n)throw new o("USD price must be positive.");return{token:r,usdE18:m.toString(),timestamp:d}}let c=e.client??y(e.rpcUrl,t);if(ne(r)){let i=await D(e,c,a,s);return{token:r,usdE18:oe,timestamp:i}}if(de(r)){let i=await D(e,c,a,s),d=await h(c,e.oracleAddress,e.blockNumber);return{token:r,usdE18:d,timestamp:i}}if(r.chainId===u)try{let i=await k(c,e.blockNumber),d=l(i.timestamp,a(),s);if(i.number===null)throw new o("Pons reference requires a mined block.");let[m,p]=await Promise.all([q(r,c,i.number),h(c,e.oracleAddress,i.number)]),E=T(p)*m.numerator/m.denominator;if(E<=0n)throw new o("Pons USD reference price must be positive.");return{token:r,usdE18:E.toString(),timestamp:d}}catch{}throw new o(`No fresh on-chain price source available for token ${N(r.symbol)} (${r.address}).`)}export{M as a,oe as b,ne as c,re as d,ie as e,de as f,Oe as g,l as h,le as i,_e as j};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as l}from"./
|
|
1
|
+
import{i as l}from"./LFN3OODW.js";import{a}from"./5YS5V2LK.js";var m=4295128739n,h=1461446703485210103287273052203988822378723970342n,d=-887272,$=887272;function I(t){if(t<2n)return t;let n=t,i=n+1n>>1n;for(;i<n;)n=i,i=n+t/n>>1n;return n}function w(t,n){if(typeof t!="string"||!/^\d+(?:\.\d+)?$/.test(t.trim()))throw new a(`${n} must be a positive decimal string such as "3000.5".`);let[i,e=""]=t.trim().split("."),r=BigInt(`${i}${e}`);if(r<=0n)throw new a(`${n} must be greater than zero.`);return{n:r,d:10n**BigInt(e.length)}}function _(t,n,i){let{n:e,d:r}=w(t,"initialPrice"),s=e*10n**BigInt(i),o=r*10n**BigInt(n),c=I((s<<192n)/o);return b(c)}function b(t){if(t<m||t>=h)throw new a("Initial price is outside the range Uniswap can represent.");return t}function S(t){b(t);let n=d,i=$;for(;n<i;){let e=Math.ceil((n+i)/2);l(e)<=t?n=e:i=e-1}return n}function f(t,n,i){let r=(t*t*10n**BigInt(n+18)/((1n<<192n)*10n**BigInt(i))).toString().padStart(19,"0"),s=r.slice(0,-18),o=r.slice(-18).replace(/0+$/,"");return o?`${s}.${o}`:s}function x(t,n){let i=t*t,e=n*n;return(i>e?i-e:e-i)*10000n/e}var P=500n;function R(t,n,i,e,r){if(n.length===0)return"No other pool for this pair was found, so the starting price could not be checked against a market. Anyone can trade against a wrong price immediately.";let s=[...n].sort((p,u)=>p.sqrtPriceX96<u.sqrtPriceX96?-1:p.sqrtPriceX96>u.sqrtPriceX96?1:0),o=s[Math.floor(s.length/2)],c=x(t,o.sqrtPriceX96),g=`${f(o.sqrtPriceX96,e,r)} (${o.label})`;if(c>P&&!i)throw new a(`Initial price ${f(t,e,r)} is ${c} bps from the existing market price ${g}. A mispriced new pool is arbitraged against your deposit. Fix the price, or pass acceptPriceDeviation:true if this is intentional.`);return`Existing market price ${g}; starting price deviates ${c} bps.`}function T(t,n){return typeof t=="string"&&/^[A-Za-z0-9][A-Za-z0-9.$_-]{0,15}$/.test(t)?t:`${n.slice(0,6)}\u2026${n.slice(-4)}`}export{m as a,h as b,_ as c,b as d,S as e,f,x as g,P as h,R as i,T as j};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as R}from"./
|
|
1
|
+
import{d as R}from"./DD7755AW.js";import{H as O,J as L,K as N,b as p,d as l,y as j}from"./JG24LNUI.js";import{a as D,f as H,g as b}from"./IAXKPME3.js";import{g as d}from"./73N3TOJL.js";import{a as y}from"./XPFVT2EA.js";import{a as e}from"./5YS5V2LK.js";import{decodeAbiParameters as J,decodeFunctionData as A,encodeAbiParameters as K,encodeFunctionData as Q,erc20Abi as W,getAddress as Y,parseAbi as Z,parseAbiParameters as ee}from"viem";var U=Z(["function modifyLiquidities(bytes unlockData,uint256 deadline) payable"]),V=ee("bytes actions,bytes[] params");function de(f,$){return{tools:[{name:"uniswap_batch",inputSchema:{type:"object",additionalProperties:!1,required:["operations"],properties:{operations:{type:"array",minItems:1,maxItems:20,items:{type:"object",additionalProperties:!1,required:["name","arguments"],properties:{name:{type:"string",enum:["uniswap_add","uniswap_collect","uniswap_remove"]},arguments:{anyOf:[O,L,N]}}}}}},async execute(a,v){if(b(a,["operations"]),!Array.isArray(a.operations)||a.operations.length<1||a.operations.length>20)throw new e("Provide 1 to 20 v4 liquidity operations.");let s="0x",c,h=[],P=0n,g=new Map,_=new Set,E=new Set;for(let t of a.operations){if(!t||typeof t!="object"||Array.isArray(t))throw new e("Each operation needs name and arguments.");let o=t;if(b(o,["name","arguments"]),!["uniswap_add","uniswap_collect","uniswap_remove"].includes(String(o.name))||!o.arguments||typeof o.arguments!="object"||Array.isArray(o.arguments))throw new e("Batch supports v4 add, collect and remove operations only.");let r=o.arguments;if(r.version!=="v4")throw new e("Every batch operation must explicitly select version v4.");if(r.initialPrice!==void 0||r.sqrtPriceX96!==void 0)throw new e("Create a pool before batching its liquidity operations.");if(r.tokenId!==void 0){let n=D(r.tokenId,"tokenId").toString();if(E.has(n))throw new e("Batch tokenIds must be distinct decimal strings.");E.add(n)}else if(o.name!=="uniswap_add")throw new e("Existing-position operations require tokenId.");let I=await $.tools.find(n=>n.name===o.name).execute(r,v),u=I.txs.at(-1);if(!u||!d(u.to,p))throw new e("Batch operation returned an unexpected destination.");P+=BigInt(u.value);for(let n of I.txs.slice(0,-1)){if(BigInt(n.value)!==0n)throw new e("Batch prerequisite cannot send native currency.");if(d(n.to,l)){let i=A({abi:R,data:n.data}),[B,G,X,z]=i.args;if(!d(G,p))throw new e("Batch Permit2 spender must be PositionManager.");let T=B.toLowerCase(),m=g.get(T),q=BigInt(z),C=(m?.amount??0n)+X;if(C>=1n<<160n)throw new e("Batch approval exceeds uint160.");g.set(T,{token:B,amount:C,expiration:m&&m.expiration<q?m.expiration:q})}else{let i=A({abi:W,data:n.data});if(i.functionName!=="approve"||!d(i.args[0],l))throw new e("Unexpected batch prerequisite.")}}let S=A({abi:U,data:u.data}),[F,x]=J(V,S.args[0]),k=F.slice(2).match(/../g)??[];if(k.length!==x.length)throw new e("Batch action/parameter count differs.");k.forEach((n,i)=>{n==="14"?_.add(x[i]):(s=`${s}${n}`,h.push(x[i]))});let M=S.args[1];c=c===void 0||M<c?M:c}for(let t of _)s=`${s}14`,h.push(t);let w=[];for(let t of g.values())w.push(f.approval(Y(t.token),l,t.amount.toString(),y),j(t.token,p,t.amount.toString(),t.expiration.toString()));return w.push(f.unsignedTx({to:p,data:Q({abi:U,functionName:"modifyLiquidities",args:[K(V,[s,h]),c]}),value:P.toString(),chainId:y,description:`Atomically modify ${a.operations.length} v4 positions; recipients are the signing wallet.`})),H(f,w,v,"Atomic v4 batch: every operation must succeed. Each position retains its own minimums; preview covers the complete action stream.")}}]}}export{U as a,V as b,de as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as v,d as N,e as h}from"./
|
|
1
|
+
import{c as v,d as N,e as h}from"./ULJ6E4HP.js";import{a as m}from"./UWOFA6GV.js";import{c as d,f as B,g as p,i as E}from"./73N3TOJL.js";import{a as H}from"./XPFVT2EA.js";import{a as o}from"./5YS5V2LK.js";import{decodeEventLog as W,encodeFunctionData as G,getAddress as V,hashStruct as Y,isHex as J,parseAbi as Q,zeroAddress as k}from"viem";var Z="struct HookrSwapIntent { PoolKey key; bool zeroForOne; int128 amountSpecified; uint128 amountBound; uint160 sqrtPriceLimitX96; address recipient; address relayer; uint256 relayerFee; address engagement; uint256[] campaigns; uint256 nonce; uint256 deadline; }",I=Q(["struct PoolKey { address currency0; address currency1; uint24 fee; int24 tickSpacing; address hooks; }",Z,"function execute(HookrSwapIntent intent, address owner, bytes signature) returns (uint256 amountIn, uint256 amountOut)","function hashIntent(HookrSwapIntent intent) pure returns (bytes32)","function pullOf(HookrSwapIntent intent) view returns (address token, uint256 amount, bool feeFromInput)","function isNonceUsed(address owner, uint256 intentNonce) view returns (bool)","function router() view returns (address)","function registry() view returns (address)","function permit2() view returns (address)","event IntentExecuted(bytes32 indexed intentHash,address indexed owner,address indexed relayer,bytes32 poolId,uint256 amountIn,uint256 amountOut,uint256 relayerFee,bool feeFromInput)"]),ee={PoolKey:[{name:"currency0",type:"address"},{name:"currency1",type:"address"},{name:"fee",type:"uint24"},{name:"tickSpacing",type:"int24"},{name:"hooks",type:"address"}],HookrSwapIntent:[{name:"key",type:"PoolKey"},{name:"zeroForOne",type:"bool"},{name:"amountSpecified",type:"int128"},{name:"amountBound",type:"uint128"},{name:"sqrtPriceLimitX96",type:"uint160"},{name:"recipient",type:"address"},{name:"relayer",type:"address"},{name:"relayerFee",type:"uint256"},{name:"engagement",type:"address"},{name:"campaigns",type:"uint256[]"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},ne=V("0x000000000022D473030F116dDEE9F6B43aC78BA3"),F={key:{type:"object",properties:{currency0:d,currency1:d,fee:{type:"integer"},tickSpacing:{type:"integer"},hooks:d},required:["currency0","currency1","fee","tickSpacing","hooks"],additionalProperties:!1},zeroForOne:{type:"boolean"},amountSpecified:{type:"string",pattern:"^-?[0-9]+$"},amountBound:m(),sqrtPriceLimitX96:m(),recipient:d,relayer:d,relayerFee:m(),engagement:d,campaigns:{type:"array",items:m(),maxItems:8},nonce:m(),deadline:m()},x={owner:d,signature:{type:"string",pattern:"^0x[0-9a-fA-F]+$"},intent:{type:"object",properties:F,required:Object.keys(F),additionalProperties:!1}};function D(t){return B(t,"Provide a complete trader-signed Hookr intent.")}function y(t,i=256,e=!1){if(typeof t!="string"||!/^-?\d+$/.test(t)||t.length>79)throw new o("Hookr intent amounts, nonce and deadline must be decimal base-unit strings.");let n=BigInt(t);if(e?n<=-(1n<<BigInt(i-1))||n>=1n<<BigInt(i-1):n<0n||n>=1n<<BigInt(i))throw new o("Hookr intent integer is outside its ABI range.");return n}function l(t){return E(t,"Provide valid Hookr intent addresses.")}function j(t,i){if(Object.keys(t).some(s=>!Object.hasOwn(x,s)))throw new o("Provide only owner, intent and the trader signature for Hookr relay.");let e=D(t.intent);if(Object.keys(e).some(s=>!Object.hasOwn(F,s)))throw new o("Hookr intent contains an undocumented field.");let n=D(e.key);if(Object.keys(n).some(s=>!["currency0","currency1","fee","tickSpacing","hooks"].includes(s))||typeof n.fee!="number"||!Number.isInteger(n.fee)||n.fee<0||n.fee>16777215||typeof n.tickSpacing!="number"||!Number.isInteger(n.tickSpacing)||n.tickSpacing<=0||n.tickSpacing>8388607||typeof e.zeroForOne!="boolean")throw new o("Provide a valid canonical v4 pool key and direction.");let a={currency0:l(n.currency0),currency1:l(n.currency1),fee:n.fee,tickSpacing:n.tickSpacing,hooks:l(n.hooks)};if(BigInt(a.currency0)>=BigInt(a.currency1))throw new o("Hookr pool currencies must sort strictly by address.");let r=l(t.owner);if(r===k||p(r,i))throw new o("Hookr relay requires another trader as owner; the relayer funds gas only.");if(!Array.isArray(e.campaigns)||e.campaigns.length>8)throw new o("Provide at most eight Hookr campaign IDs.");let c={key:a,zeroForOne:e.zeroForOne,amountSpecified:y(e.amountSpecified,128,!0),amountBound:y(e.amountBound,128),sqrtPriceLimitX96:y(e.sqrtPriceLimitX96,160),recipient:l(e.recipient),relayer:l(e.relayer),relayerFee:y(e.relayerFee),engagement:l(e.engagement),campaigns:e.campaigns.map(s=>y(s)),nonce:y(e.nonce),deadline:y(e.deadline)};if(c.amountSpecified===0n||c.amountBound===0n)throw new o("Hookr intent input/output amounts and bound must be nonzero.");if([k,h,v].some(s=>p(s,c.recipient)))throw new o("Hookr intent recipient is reserved.");if(c.relayer!==k&&!p(c.relayer,i)||c.relayer===k&&c.relayerFee!==0n)throw new o("Hookr intent names a different relayer or an open relay with a fee.");if(c.engagement===k!=(c.campaigns.length===0))throw new o("Hookr engagement and campaigns must be supplied together.");let f=c.zeroForOne?a.currency0:a.currency1;if(f===k)throw new o("Hookr Permit2 relay cannot pull native ETH input.");if(typeof t.signature!="string"||!J(t.signature,{strict:!0})||t.signature.length<4||t.signature.length%2!==0||t.signature.length>16386)throw new o("Provide the trader-signed Permit2 witness signature, never a private key.");let S=t.signature,w=Y({data:c,primaryType:"HookrSwapIntent",types:ee});return{owner:r,intent:c,signature:S,input:f,intentHash:w}}function q(t,i){let{owner:e,intent:n,signature:a}=j(t,i);return{chainId:H,to:h,value:"0",data:G({abi:I,functionName:"execute",args:[n,e,a]}),description:`Relay Hookr trader ${e} to recipient ${n.recipient}; relayer fee ${n.relayerFee} in pool quote currency. Relayer pays gas; owner supplies Permit2 funds.`}}function ce(t,i,e){let n=q(i,e);if(t.length!==1||t[0].chainId!==n.chainId||!p(t[0].to,n.to)||t[0].value!=="0"||!p(t[0].data,n.data))throw new o("Hookr relay calldata differs from the locally requested signed intent.")}function ue(t){return[{name:"hookr_relay",inputSchema:{type:"object",description:"Preview a trader-signed Permit2 swap for local human-confirmed submission. Relayer pays gas; the trader supplies input. No signature is created by this tool.",properties:x,required:Object.keys(x),additionalProperties:!1},execute:async(i,e)=>{let n=j(i,e),{owner:a,intent:r,signature:c,input:f,intentHash:S}=n,w=t.clientFor(H),s=await w.getBlock();if(typeof s.number!="bigint"||typeof s.timestamp!="bigint"||s.timestamp<=0n||s.timestamp>r.deadline)throw new o("Hookr signed intent expired or the chain timestamp is unavailable.");let g=(X,M=[])=>w.readContract({address:h,abi:I,functionName:X,args:M,blockNumber:s.number}),[_,u,z,K,$,U]=await Promise.all([g("hashIntent",[r]),g("pullOf",[r]),g("isNonceUsed",[a,r.nonce]),g("router"),g("registry"),g("permit2")]);if(_!==S||z!==!1||K!==v||$!==N||U!==ne)throw new o("Hookr intent hash, nonce or forwarder deployment is invalid. Ask the trader for a fresh signed intent.");if(!Array.isArray(u)||u.length!==3||typeof u[0]!="string"||!p(u[0],f)||typeof u[1]!="bigint"||typeof u[2]!="boolean")throw new o("Hookr Permit2 pull could not be verified.");let b=u[2],P=r.amountSpecified<0n?-r.amountSpecified:r.amountBound;if(u[1]!==P+(b?r.relayerFee:0n)||r.amountSpecified>0n&&!b&&r.relayerFee>r.amountSpecified)throw new o("Hookr Permit2 pull or output-side fee differs from the signed terms.");let C=await w.simulateContract({address:h,abi:I,functionName:"execute",args:[r,a,c],account:e,blockNumber:s.number}),[A,R]=C.result,T=r.amountSpecified<0n?r.amountBound:r.amountSpecified-(b?0n:r.relayerFee);if(A>P||R<T)throw new o("Hookr relay simulation did not satisfy the signed input/output bounds.");let O=[t.unsignedTx(q(i,e))],L=await t.preview(O,e);return{txs:O,preview:L,summary:O[0].description,intentHash:S,owner:a,recipient:r.recipient,relayer:e,inputToken:f,maximumPull:u[1].toString(),feeToken:b?f:r.zeroForOne?r.key.currency1:r.key.currency0,relayerFee:r.relayerFee.toString(),feeFromInput:b,minimumOutput:T.toString(),simulatedAmountIn:A.toString(),simulatedAmountOut:R.toString(),note:"Verify IntentExecuted in the receipt and your fee balance after submission."}}},{name:"hookr_relay_receipt",inputSchema:{type:"object",description:"Read the executed intent and fee from a mined Hookr relay receipt.",properties:{transactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$"}},required:["transactionHash"],additionalProperties:!1},execute:async i=>{if(Object.keys(i).some(a=>a!=="transactionHash")||typeof i.transactionHash!="string"||!/^0x[0-9a-fA-F]{64}$/.test(i.transactionHash))throw new o("Provide a Hookr relay transactionHash.");let e=await t.clientFor(H).getTransactionReceipt({hash:i.transactionHash});if(e.status!=="success")throw new o("Hookr relay reverted. No fee is proven paid.");let n=e.logs.filter(a=>p(a.address,h)).flatMap(a=>{try{let r=W({abi:I,eventName:"IntentExecuted",topics:a.topics,data:a.data});return[{...r.args,amountIn:r.args.amountIn.toString(),amountOut:r.args.amountOut.toString(),relayerFee:r.args.relayerFee.toString()}]}catch{return[]}});if(!n.length)throw new o("Receipt contains no verified Hookr IntentExecuted event.");return{chainId:H,transactionHash:e.transactionHash,blockNumber:e.blockNumber.toString(),intents:n,note:"Event evidence at this mined block; check balances and finality."}}}]}export{I as a,j as b,q as c,ce as d,ue as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as c}from"./
|
|
1
|
+
import{f as c}from"./JG24LNUI.js";import{a,f as p,g as u}from"./IAXKPME3.js";import{a as e}from"./UWOFA6GV.js";import{a as r}from"./XPFVT2EA.js";import{a as n}from"./5YS5V2LK.js";import{encodeFunctionData as d,parseAbi as f}from"viem";var m=f(["function deposit() payable","function withdraw(uint256)"]);function H(i){return{tools:[{name:"uniswap_wrap",inputSchema:{type:"object",additionalProperties:!1,required:["direction","amount"],properties:{direction:{type:"string",enum:["wrap","unwrap"]},amount:e()}},async execute(t,w){if(u(t,["direction","amount"]),t.direction!=="wrap"&&t.direction!=="unwrap")throw new n("Choose direction wrap or unwrap.");let o=a(t.amount,"amount"),s=t.direction==="wrap"?d({abi:m,functionName:"deposit"}):d({abi:m,functionName:"withdraw",args:[o]});return p(i,[i.unsignedTx({to:c,data:s,value:t.direction==="wrap"?o.toString():"0",chainId:r,description:`${t.direction} ${o} ETH/WETH base units to the signing wallet.`})],w,"Wrap or unwrap native ETH at the pinned WETH contract. Ratio 1:1; network gas is additional.")}}]}}export{m as a,H as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as P,g as A,m as S}from"./
|
|
1
|
+
import{d as P,g as A,m as S}from"./3R3C3CU5.js";import{N as y,b as h}from"./JG24LNUI.js";import{a as I,b as k,f as N,g as v}from"./IAXKPME3.js";import{a as b}from"./UWOFA6GV.js";import{c as w,g}from"./73N3TOJL.js";import{a as m}from"./XPFVT2EA.js";import{a as r}from"./5YS5V2LK.js";import{encodeFunctionData as f,parseAbi as T,zeroAddress as _}from"viem";var i=T(["function ownerOf(uint256) view returns (address)","function getApproved(uint256) view returns (address)","function getPositionLiquidity(uint256) view returns (uint128)","function safeTransferFrom(address from,address to,uint256 tokenId)","function approve(address spender,uint256 tokenId)","function burn(uint256 tokenId)"]),q={version:{type:"string",enum:["v3","v4"]},tokenId:b(),operation:{type:"string",enum:["transfer","approve","revoke","burn"]},target:w};function D(s){return{tools:[!1,!0].map(c=>({name:c?"uniswap_position_manage":"uniswap_position_status",inputSchema:{type:"object",additionalProperties:!1,required:c?["version","tokenId","operation"]:["version","tokenId"],properties:q},async execute(e,p){if(e.version!=="v3"&&e.version!=="v4")throw new r("Specify position version v3 or v4.");let o=I(e.tokenId,"tokenId"),a=e.version==="v3"?P.positionManager:h,d=s.clientFor(m),l=await d.readContract({address:a,abi:i,functionName:"ownerOf",args:[o]});if(!c){v(e,["version","tokenId"]);let n=await d.readContract({address:a,abi:i,functionName:"getApproved",args:[o]});return{version:e.version,tokenId:o.toString(),manager:a,owner:l,approved:n}}if(!g(l,p))throw new r("Only manage a Uniswap NFT owned by the signing wallet.");let t=e.operation;v(e,["version","tokenId","operation",...["transfer","approve"].includes(String(t))?["target"]:[]]);let u;if(t==="transfer"||t==="approve"){let n=k(e.target);if(n===_)throw new r("Choose a nonzero target, or operation revoke to clear approval.");u=t==="transfer"?f({abi:i,functionName:"safeTransferFrom",args:[p,n,o]}):f({abi:i,functionName:"approve",args:[n,o]})}else if(t==="revoke")u=f({abi:i,functionName:"approve",args:[_,o]});else if(t==="burn"){if(e.version==="v4"){if(await d.readContract({address:a,abi:i,functionName:"getPositionLiquidity",args:[o]})!==0n)throw new r("Remove all liquidity before burning an empty position.");return y(s).tools.find(O=>O.name==="uniswap_remove").execute({version:"v4",tokenId:o.toString(),liquidity:"all",amount0Min:"0",amount1Min:"0"},p)}let n=S(await d.readContract({address:a,abi:A,functionName:"positions",args:[o]}));if(n.liquidity!==0n||n.tokensOwed0!==0n||n.tokensOwed1!==0n)throw new r("Remove liquidity and collect all owed tokens before burning a v3 NFT.");u=f({abi:i,functionName:"burn",args:[o]})}else throw new r("Choose transfer, approve, revoke or burn. Operator-wide approvals are not exact approvals.");return N(s,[s.unsignedTx({to:a,data:u,value:"0",chainId:m,description:`${t} Uniswap ${e.version} NFT #${o}${e.target?` with target ${e.target}`:""}.`})],p,"Position ownership or exact per-NFT approval changes. A transferred position includes its liquidity and accrued rights; burn requires an empty NFT.")}}))}}export{i as a,D as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{q as m}from"./
|
|
1
|
+
import{q as m}from"./BBVKWG65.js";import{c as u,f as h}from"./QRUC7EFE.js";import{d as p,f}from"./3ZVGHC6S.js";import{i as g,j as k}from"./IUETZH6I.js";import{a as d}from"./AXYOJBX6.js";import{g as l}from"./73N3TOJL.js";import{a as i}from"./5YS5V2LK.js";var w=["hoodlock_lock","hoodlock_burn","hoodlock_airdrop_create","hoodlock_airdrop_claim",...p,...u];async function H(e,r,t,s){if(!w.includes(e))throw new i("Unknown HoodLock action; nothing was signed.");let o=async()=>{throw new i("HoodLock does not require a swap for this action.")},n=d({clientFor:()=>s,http:fetch,preview:async a=>({txs:a,changes:[],summary:"Locally reconstructed HoodLock intent."}),quoteSwap:o,buildSwap:o}),c=await[g(n),k(n),...m(n).tools,...f(n).tools,...h(n).tools].find(a=>a.name===e).execute(r,t);if(!Array.isArray(c.txs)||c.txs.length===0)throw new i("HoodLock action has no transactions; use the read route.");return c.txs.map(a=>({...a}))}function I(e,r){if(!r.length||e.length!==r.length||e.some((t,s)=>{let o=r[s];return t.chainId!==o.chainId||!l(t.to,o.to)||!l(t.data,o.data)||t.value!==o.value}))throw new i("HoodLock transaction differs from the locally reconstructed request; nothing was signed.")}export{w as a,H as b,I as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as g,d as H,m as M}from"./
|
|
1
|
+
import{c as g,d as H,m as M}from"./DD7755AW.js";import{d,e as s,y as C}from"./JG24LNUI.js";import{f as _,g as k}from"./IAXKPME3.js";import{g as h}from"./73N3TOJL.js";import{a as w}from"./XPFVT2EA.js";import{a as t}from"./5YS5V2LK.js";import{decodeFunctionData as b,encodeFunctionData as B,erc20Abi as $,getAddress as O}from"viem";function K(u){return{tools:[{name:"uniswap_swap_batch",inputSchema:{type:"object",additionalProperties:!1,required:["routes"],properties:{routes:{type:"array",minItems:1,maxItems:20,items:{type:"object",description:"Complete uniswap_swap arguments, including an absolute minAmountOut or maxAmountIn."}}}},async execute(n,v){if(k(n,["routes"]),!Array.isArray(n.routes)||n.routes.length<1||n.routes.length>20)throw new t("Provide 1 to 20 explicit bounded Uniswap routes.");let c=new Map,i="0x",A=0n,a,m=[],y=new Set;for(let e of n.routes){if(!e||typeof e!="object"||Array.isArray(e))throw new t("Each route must contain uniswap_swap arguments.");let I=await M(u,e,v,!1);if(!("txs"in I))throw new t("Route did not build swap transactions.");let E=I.txs;for(let r of E.slice(0,-1))if(h(r.to,d)){let[o,D,N,S]=b({abi:H,data:r.data}).args;if(D!==s)throw new t("Unexpected route approval spender.");let T=o.toLowerCase(),p=c.get(T),U=(p?.amount??0n)+N;if(U>=1n<<160n)throw new t("Combined input approvals exceed uint160.");c.set(T,{token:o,amount:U,expiration:p&&p.expiration<BigInt(S)?p.expiration:BigInt(S)})}else{let o=b({abi:$,data:r.data});if(o.functionName!=="approve"||!h(o.args[0],d))throw new t("Unexpected route prerequisite.")}let f=E.at(-1);if(f.to!==s)throw new t("Route does not use the pinned Universal Router.");A+=BigInt(f.value);let[j,x,P]=b({abi:g,data:f.data}).args,R=j.slice(2).match(/../g)??[];if(R.length!==x.length)throw new t("Unexpected route command/parameter count.");R.forEach((r,o)=>{r==="04"?y.add(x[o]):(i=`${i}${r}`,m.push(x[o]))}),a=a===void 0||P<a?P:a}for(let e of y)i=`${i}04`,m.push(e);let l=[];for(let e of c.values())l.push(u.approval(O(e.token),d,e.amount.toString(),w),C(e.token,s,e.amount.toString(),e.expiration.toString()));return l.push(u.unsignedTx({to:s,data:B({abi:g,functionName:"execute",args:[i,m,a]}),value:A.toString(),chainId:w,description:`Atomically execute ${n.routes.length} caller-selected v2/v3/v4 routes, preserving each route's trade bound.`})),_(u,l,v,"Explicit mixed-version/split routes; every route must meet its own bound. No automatic best-route search or allow-revert branch. The wallet must fund each independently previewed route.")}}]}}export{K as a};
|