@oracle-agent/oracle 0.28.23 → 0.28.24

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import{createHash as He}from"node:crypto";import L from"node:net";import Oe from"node:dns";var Fe=new Set(["localhost","metadata.google.internal","metadata.goog"]);function K(t){let e=String(t).toLowerCase().split("%")[0];if((e.match(/::/g)||[]).length>1)return null;let n=u=>{if(!u)return[];let i=u.split(":"),p=i.at(-1);if(p?.includes(".")){let h=p.split(".").map(Number);if(h.length!==4||h.some(f=>!Number.isInteger(f)||f<0||f>255))return null;i.splice(i.length-1,1,(h[0]<<8|h[1]).toString(16),(h[2]<<8|h[3]).toString(16))}return i.some(h=>!/^[0-9a-f]{1,4}$/.test(h))?null:i.map(h=>Number.parseInt(h,16))},[r,a]=e.split("::"),o=n(r),s=n(a);if(!o||!s)return null;let c=e.includes("::"),d=8-o.length-s.length;if(!c&&d!==0||c&&d<1)return null;let l=[...o,...Array(Math.max(0,d)).fill(0),...s];return l.length!==8?null:Uint8Array.from(l.flatMap(u=>[u>>8,u&255]))}function Q(t,e,n){let r=Math.floor(n/8),a=n%8;for(let s=0;s<r;s+=1)if(t[s]!==e[s])return!1;if(!a)return!0;let o=255<<8-a;return(t[r]&o)===(e[r]&o)}function X(t){if(L.isIPv4(t)){let e=t.split(".").map(Number);return!(e[0]===0||e[0]===10||e[0]===127||e[0]>=224||e[0]===100&&e[1]>=64&&e[1]<=127||e[0]===169&&e[1]===254||e[0]===172&&e[1]>=16&&e[1]<=31||e[0]===192&&(e[1]===0||e[1]===2||e[1]===168)||e[0]===192&&e[1]===88&&e[2]===99||e[0]===198&&(e[1]===18||e[1]===19||e[1]===51)||e[0]===203&&e[1]===0&&e[2]===113)}if(L.isIPv6(t)){let e=K(t);if(!e)return!1;let n=K("::ffff:0:0");return Q(e,n,96)?X([...e.slice(12)].join(".")):Q(e,K("2000::"),3)?![["2001::",23],["2001:db8::",32],["2001:10::",28],["2001:2::",48],["2002::",16],["3fff::",20]].some(([a,o])=>Q(e,K(a),o)):!1}return!1}function De(t){let e;try{e=new URL(String(t))}catch{return{ok:!1,error:`not a valid URL: ${String(t).slice(0,120)}`}}if(e.protocol!=="http:"&&e.protocol!=="https:")return{ok:!1,error:`refused protocol ${e.protocol} (only http/https)`};let n=e.hostname.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.+$/,"");if(Fe.has(n)||n.endsWith(".localhost")||n.endsWith(".internal"))return{ok:!1,error:`refused internal host ${n}`};let r=L.isIP(n);return r!==0&&!X(n)?{ok:!1,error:`refused private address ${n}`}:{ok:!0,url:e,host:n,isLiteralIp:r!==0}}async function J(t,{lookupFn:e=Oe.promises.lookup}={}){let n=De(t);if(!n.ok)return n;if(n.isLiteralIp)return{ok:!0,url:n.url,addresses:[{address:n.host,family:L.isIPv6(n.host)?6:4}]};let r;try{r=await e(n.host,{all:!0,verbatim:!0})}catch{return{ok:!1,error:`refused: ${n.host} did not resolve`}}return!Array.isArray(r)||r.length===0||r.some(a=>!X(a.address))?{ok:!1,error:`refused: ${n.host} resolves to a non-public address`}:{ok:!0,url:n.url,addresses:r}}async function Z({requireUndici:t=!1,importUndici:e=()=>import("undici")}={}){let n,r;try{let i=await e();n=i.Agent,r=i.fetch}catch(i){if(t)throw new Error(`egress-guard: untrustedUrl pinning requires the undici package, which failed to load: ${i?.message||i}`);return null}if(typeof n!="function"||typeof r!="function"){if(t)throw new Error("egress-guard: untrustedUrl pinning requires undici's Agent and fetch exports, which were not found on the imported module");return null}let a=i=>String(i).toLowerCase().replace(/^\[|\]$/g,"").replace(/\.+$/,""),o=new Map,s=i=>(Array.isArray(i)?i:[i]).map(p=>typeof p=="string"?{address:p}:p).filter(p=>p&&p.address).map(p=>({address:p.address,family:p.family||(L.isIPv6(p.address)?6:4)})),c=(i,p,h)=>{o.set(a(i),s(typeof p=="string"?[{address:p,family:h}]:p))},d=i=>{let p=a(i);if(L.isIP(p))return[{address:p,family:L.isIPv6(p)?6:4}];let h=o.get(p);if(!h||!h.length)throw new Error(`refused: unpinned host ${i} during pinned fetch`);return h},l=new n({connect:{lookup(i,p,h){let f;try{f=d(i)}catch(v){return h(v)}return p?.all?h(null,f):h(null,f[0].address,f[0].family)}}}),u=Ve((i,p={})=>r(i,{...p,dispatcher:l}),c);return{dispatcher:l,fetch:u,pin:c,resolve:d,async close(){try{await l.destroy()}catch{}}}}var ee=Symbol.for("oracle.egressGuard.pinCapableFetch");function Ve(t,e){if(typeof t!="function")throw new Error("markPinCapableFetch: fetchImpl must be a function");if(typeof e!="function")throw new Error("markPinCapableFetch: pin must be a function");return t[ee]=Object.freeze({pin:e}),t}function te(t){return typeof t=="function"&&typeof t[ee]?.pin=="function"}function le(t,e,n){if(!te(t))throw new Error("pinFetchToAddresses: fetchImpl is not pin-capable");t[ee].pin(e,n)}var Me=new Set([408,425,429,500,502,503,504]),de=new Set(["GET","HEAD","OPTIONS","PUT","DELETE"]),je=2,pe=4e3,be=["authorization","x-api-key","x-tensor-api-key","0x-api-key","api-key","cookie","proxy-authorization"],Ke=new Set([301,302,303,307,308]),he=3,We=64*1024;function ze(t){let e=String(t||"").toLowerCase();return be.includes(e)||/(^|-)(api[-_]?key|key|token|secret|auth|authorization|session|cookie|signature|access)(-|$)/.test(e)}function Ge(t){let e={};for(let[n,r]of Object.entries(t||{}))ze(n)||(e[n]=r);return e}function Ye(t,e){if(!t)throw new Error(`HTTP redirect from ${e} missing Location`);let n=new URL(String(t),String(e));if(n.protocol!=="http:"&&n.protocol!=="https:")throw new Error(`HTTP redirect from ${e} used unsupported protocol ${n.protocol}`);return n.toString()}function Qe(t,e){return new URL(String(t)).origin===new URL(String(e)).origin}var ne=new Map;function Xe(t,e,n,r={}){let a={};for(let[u,i]of Object.entries(n||{}))a[u.toLowerCase()]=i;let o=Object.keys(a).filter(u=>/(^|-)(api[-_]?key|key|token|secret|auth|authorization|session|cookie|signature|access)(-|$)/.test(u)),c=[...new Set([...be,...o])].sort().map(u=>`${u}=${a[u]??""}`).join(`
3
- `),d=He("sha256").update(c).digest("hex").slice(0,32),l=`${r.untrustedUrl?"untrusted":"trusted"}:${r.maxResponseBytes??"unbounded"}`;return`${t} ${e} ${l} ${d}`}function Je(t,e){let n=Number(e);return Number.isFinite(n)&&n>0?Math.min(n*1e3,pe):Math.min(250*2**t,pe)+Math.floor(Math.random()*100)}var Ze=t=>new Promise(e=>setTimeout(e,t));function O(t,e={}){let n=new Error(t);return n.retryable=!1,Object.assign(n,e),n}function re(t,e,n){return O(`HTTP response from ${t} exceeded maxResponseBytes ${n} (${e})`,{oversize:!0})}function F(t){try{let e=t?.body?.cancel?.();e&&typeof e.then=="function"&&e.catch(()=>{})}catch{}}function et(t){return t?t.byteLength??t.length??0:0}async function fe(t,e,{url:n,truncate:r=!1,onOversize:a}={}){if(e==null)return await t.text();let o=Number(t.headers?.get?.("content-length"));if(Number.isFinite(o)&&o>e&&(F(t),!r))throw re(n,`content-length ${o}`,e);let s=t.body?.getReader?.();if(!s){let i=await t.text(),p=Buffer.byteLength(i,"utf8");if(p>e){if(!r)throw re(n,`body ${p} bytes`,e);return Buffer.from(i,"utf8").subarray(0,e).toString("utf8")}return i}let c=[],d=0,l=!1;try{for(;;){let{value:i,done:p}=await s.read();if(p)break;if(i&&(c.push(Buffer.from(i)),d+=et(i),d>e)){l=!0;break}}}finally{if(l)try{await s.cancel()}catch{}try{s.releaseLock?.()}catch{}}if(l&&(typeof a=="function"&&a(),!r))throw re(n,`streamed ${d} bytes`,e);let u=Buffer.concat(c);return(l?u.subarray(0,e):u).toString("utf8")}function me(t){if(!t)return null;try{return JSON.parse(t)}catch{return null}}async function tt(t,{fetchImpl:e,method:n,headers:r,body:a,timeoutMs:o,lookupFn:s,realFetch:c,untrustedUrl:d=!1,maxResponseBytes:l=null,importUndici:u,validateResponse:i}){let p=new AbortController,h=setTimeout(()=>p.abort(),o),f=null,v=e,E=s?{lookupFn:s}:{};if(d&&!c&&!te(v))throw O(`HTTP refused ${t}: untrustedUrl requires a pin-capable fetchImpl (see markPinCapableFetch in egress-guard.mjs) or no fetchImpl override so Oracle can pin the connection itself`);let x=async(g,{status:S=null}={})=>{let C=await J(g,E);if(!C.ok)throw O(S==null?`HTTP refused ${g}: ${C.error}`:`HTTP redirect to ${g} ${C.error}`,S==null?{}:{status:S});let y=new URL(g).hostname;if(c){if(f&&(await f.close(),f=null),!f)try{f=await Z({requireUndici:!0,...u?{importUndici:u}:{}})}catch(I){throw O(S==null?`HTTP refused ${g}: ${I?.message||I}`:`HTTP redirect to ${g} refused: ${I?.message||I}`,S==null?{}:{status:S})}f.pin(y,C.addresses),v=f.fetch}else le(v,y,C.addresses);return C};try{let g=String(t),S={...r||{}};d&&await x(g);for(let C=0;C<=he;C+=1){let y=await v(g,{method:n,headers:S,body:a,signal:p.signal,redirect:"manual"});if(Ke.has(y.status)){if(n!=="GET"&&n!=="HEAD"){let T=await fe(y,l??We,{url:g,truncate:!0}),_=new Error(`HTTP ${y.status} ${n} ${g} redirected non-idempotent request`);throw _.status=y.status,_.body=me(T)??T.slice(0,300),_}if(C===he)throw F(y),new Error(`HTTP redirect loop for ${t}`);let N=y.headers?.get?.("location"),R;try{R=Ye(N,g)}catch(T){throw F(y),T}let j=!Qe(R,g);if(F(y),j&&(S=Ge(S)),d)await x(R,{status:y.status});else if(j){let T=await J(R,E);if(!T.ok){let _=new Error(`HTTP redirect from ${g} ${T.error}`);throw _.status=y.status,_.retryable=!1,_}c&&T.addresses?.length&&(f||(f=await Z(u?{importUndici:u}:{})),f&&(f.pin(new URL(R).hostname,T.addresses),v=f.fetch))}g=R;continue}if(typeof i=="function")try{await i(y,{url:g})}catch(N){throw F(y),O(N?.message||String(N))}let I=await fe(y,l,{url:g,onOversize:()=>p.abort()}),B=me(I);if(!y.ok){let N=new Error(`HTTP ${y.status} ${n} ${g}`);throw N.status=y.status,N.retryAfter=y.headers?.get?.("retry-after")??null,N.body=B??I.slice(0,300),N}return B??I}throw new Error(`HTTP redirect loop for ${t}`)}finally{clearTimeout(h),f&&await f.close()}}async function W(t,e={}){let n=e.fetchImpl||globalThis.fetch;if(typeof n!="function")throw new Error("fetch unavailable \u2014 pass opts.fetchImpl");let r=e.timeoutMs??12e3,a=(e.method||"GET").toUpperCase(),o={Accept:"application/json",...e.headers||{}},s=e.body;s!=null&&typeof s!="string"&&(o["Content-Type"]=o["Content-Type"]||"application/json",s=JSON.stringify(s));let c=Number.isInteger(e.retries)?Math.max(e.retries,0):je,d=e.lookupFn,l=!e.fetchImpl,u=e.untrustedUrl===!0,i=e.importUndici,p=e.validateResponse,h=Number(e.maxResponseBytes),f=Number.isFinite(h)&&h>0?Math.floor(h):null,v=async()=>{let C;for(let y=0;y<=c;y++)try{return await tt(t,{fetchImpl:n,method:a,headers:o,body:s,timeoutMs:r,lookupFn:d,realFetch:l,untrustedUrl:u,maxResponseBytes:f,importUndici:i,validateResponse:p})}catch(I){C=I;let B=I?.status,N=I?.name==="AbortError",R=new Set([408,425,429]),j=I?.retryable===!1?!1:B!=null?R.has(B)||Me.has(B)&&de.has(a):!N&&de.has(a);if(y===c||!j)throw I;await Ze(Je(y,I?.retryAfter))}throw C};if(!(e.dedupe!==!1&&a==="GET"&&s==null))return v();let x=Xe(a,t,o,{untrustedUrl:u,maxResponseBytes:f}),g=ne.get(x);if(g)return g;let S=v().finally(()=>ne.delete(x));return ne.set(x,S),S}var ve={robinhood:{chainId:4663,name:"Robinhood Chain",rpcEnv:["RH_CHAIN_RPC"],evm:!0},ethereum:{chainId:1,name:"Ethereum",rpcEnv:["ETH_RPC_URL","ETHEREUM_RPC_URL","MAINNET_RPC_URL"],evm:!0},polygon:{chainId:137,name:"Polygon",rpcEnv:["POLYGON_RPC_URL","POLYGON_RPC"],evm:!0},arbitrum:{chainId:42161,name:"Arbitrum One",rpcEnv:["ARBITRUM_RPC_URL","ARB_RPC_URL"],evm:!0},base:{chainId:8453,name:"Base",rpcEnv:["BASE_RPC_URL"],evm:!0},hyperevm:{chainId:999,name:"HyperEVM",rpcEnv:["HYPEREVM_RPC_URL","HYPER_EVM_RPC"],evm:!0},bsc:{chainId:56,name:"BNB Smart Chain",rpcEnv:["BSC_RPC_URL","BNB_RPC_URL"],evm:!0},avalanche:{chainId:43114,name:"Avalanche C-Chain",rpcEnv:["AVALANCHE_RPC_URL","AVAX_RPC_URL"],evm:!0},optimism:{chainId:10,name:"OP Mainnet",rpcEnv:["OPTIMISM_RPC_URL","OP_RPC_URL"],evm:!0},abstract:{chainId:2741,name:"Abstract",rpcEnv:["ABSTRACT_RPC_URL","ABS_RPC_URL"],evm:!0},stable:{chainId:988,name:"Stable Mainnet",rpcEnv:["STABLE_RPC_URL","STABLE_RPC"],evm:!0}},nt=new Map(Object.values(ve).map(t=>[t.chainId,t]));function ge(t){return nt.get(Number(t))||null}function ye(t,e=process.env){let n=ge(t);if(!n)return null;for(let r of n.rpcEnv){let a=(e[r]||"").trim();if(a)return a}return null}import{Interface as rt,getAddress as ot}from"ethers";var we=new rt(["function allowance(address owner,address spender) view returns (uint256)","function balanceOf(address account) view returns (uint256)"]);function Ee(t,e){try{return ot(t).toLowerCase()}catch{throw new Error(`${e} must be a valid EVM address`)}}var at={1:"https://ethereum.publicnode.com",137:"https://polygon-bor-rpc.publicnode.com",42161:"https://arbitrum-one-rpc.publicnode.com",8453:"https://base-rpc.publicnode.com",10:"https://optimism-rpc.publicnode.com",988:"https://rpc.stable.xyz",56:"https://bsc-rpc.publicnode.com",43114:"https://avalanche-c-chain-rpc.publicnode.com",999:"https://rpc.hyperliquid.xyz/evm",2741:"https://api.mainnet.abs.xyz",4663:"https://rpc.mainnet.chain.robinhood.com"};function it(t,{rpcUrl:e,env:n=process.env}={}){if(e)return e;let r=ye(t,n);return r||at[Number(t)]||null}var st=/^(?:eth_(?:call|blocknumber|chainid|get[a-z0-9]+|feehistory|gasprice|maxpriorityfeepergas|syncing|protocolversion|estimategas|createaccesslist)|net_(?:version|listening|peercount)|web3_(?:clientversion|sha3))$/;function ct(t){let e=String(t||""),n=e.toLowerCase();if(e!==e.trim()||!/^[a-zA-Z0-9_]+$/.test(e)||!st.test(n))throw new Error(`evm-rpc: ${e} refused \u2014 @oracle-agent/oracle is prepare-only (read RPC only; no broadcast/sign)`);return n}async function k(t,e,n=[],r={}){let a=String(e||"");ct(a);let o=it(t,r);if(!o)throw new Error(`No RPC URL for chainId ${t} (set env from chain registry rpcEnv or pass rpcUrl)`);let c=await W(o,{method:"POST",body:{jsonrpc:"2.0",id:1,method:e,params:n},fetchImpl:r.fetchImpl,timeoutMs:r.timeoutMs??12e3});if(c?.error){let d=new Error(c.error.message||JSON.stringify(c.error));throw d.code=c.error.code,d}return c.result}async function Se(t,e={}){let n=await k(t,"eth_blockNumber",[],e);return parseInt(n,16)}async function Ie(t,e,n={}){if(!e)throw new Error("rpcGetBalance requires address");let r=await k(t,"eth_getBalance",[e,"latest"],n);return{chainId:Number(t),address:e,balanceWei:BigInt(r).toString(),balanceHex:r}}async function Ce(t={},e={}){let n=Number(t.chainId??e.chainId??1),r=Ee(t.token||t.tokenAddress,"token"),a=Ee(t.account||t.owner||t.address,"account"),o=we.encodeFunctionData("balanceOf",[a]),s=await k(n,"eth_call",[{to:r,data:o},t.blockTag||"latest"],e),c=we.decodeFunctionResult("balanceOf",s),d=BigInt(c[0]);return{chainId:n,token:r,account:a,balance:d.toString(),balanceHex:`0x${d.toString(16)}`,blockTag:t.blockTag||"latest"}}var ut="https://api.dexscreener.com",$t=Object.freeze({1:"ethereum",10:"optimism",56:"bsc",137:"polygon",8453:"base",42161:"arbitrum",43114:"avalanche",999:"hyperevm",4663:"robinhood"});function lt(t={}){return(t.baseUrl||process.env.DEXSCREENER_API_URL||ut).replace(/\/$/,"")}async function xe(t,e={}){if(!t)throw new Error("tokenAddress required");return W(`${lt(e)}/latest/dex/tokens/${t}`,{fetchImpl:e.fetchImpl,timeoutMs:e.timeoutMs??12e3})}var D=Object.freeze(["blockNumber","nativeBalance","tokenBalance","resolveToken","resolvePools","scanBlocks","scoreRisk","quote","sellSimulation","prepareUnsignedTx"]),b=Object.freeze({LIVE:"LIVE",CACHED:"CACHED",STALE:"STALE",UNKNOWN:"UNKNOWN",UNAVAILABLE:"UNAVAILABLE"}),m=Object.freeze({PASS:"PASS",CAUTION:"CAUTION",FAIL:"FAIL",UNKNOWN:"UNKNOWN"}),dt=/^0x[0-9a-fA-F]{40}$/;function pt(t={}){let e=[],n=[];if(!t||typeof t!="object")return{ok:!1,errors:["definition must be an object"],warnings:n};if((!Number.isInteger(t.chainId)||t.chainId<=0)&&e.push("chainId must be a positive integer"),(typeof t.key!="string"||!/^[a-z][a-z0-9-]*$/.test(t.key||""))&&e.push('key must be a lowercase slug (e.g. "base")'),(typeof t.name!="string"||!t.name.trim())&&e.push("name is required"),!Array.isArray(t.rpcEnv)||t.rpcEnv.length===0)e.push("rpcEnv must list at least one environment variable name");else for(let a of t.rpcEnv)(typeof a!="string"||!/^[A-Z][A-Z0-9_]*$/.test(a))&&e.push(`rpcEnv entry "${a}" should be an UPPER_SNAKE env var name`);if(t.nativeCurrency){let a=t.nativeCurrency;(typeof a.symbol!="string"||!a.symbol)&&e.push("nativeCurrency.symbol is required when nativeCurrency is set"),Number.isInteger(a.decimals)||e.push("nativeCurrency.decimals must be an integer")}for(let[a,o]of(t.venues||[]).entries()){let s=`venues[${a}]`;if(!o||typeof o!="object"){e.push(`${s} must be an object`);continue}dt.test(o.address||"")||e.push(`${s}.address is not a valid 20-byte address`),/^0x0{40}$/.test(o.address||"")&&e.push(`${s}.address is the zero address -- placeholder left in place?`),o.kind||e.push(`${s}.kind is required (router|quoter|factory|...)`),o.verified?(o.verified.method||e.push(`${s}.verified.method is required`),o.verified.source||e.push(`${s}.verified.source is required`),o.verified.date||n.push(`${s}.verified.date missing -- add one so staleness is visible`)):e.push(`${s} must record verification: { verified: { method, source, date } }. An unverified venue stays blocked.`)}let r=t.capabilities||{};for(let a of Object.keys(r))D.includes(a)?typeof r[a]!="function"&&e.push(`capability "${a}" must be a function`):e.push(`unknown capability "${a}"`);return Object.keys(r).length===0&&n.push("scanner implements no capabilities -- it can only be registered, not used"),r.prepareUnsignedTx&&!r.quote&&n.push("prepareUnsignedTx without quote: no priced expectation to validate the built tx against"),r.prepareUnsignedTx&&!r.sellSimulation&&n.push("prepareUnsignedTx without sellSimulation: cannot prove an asset is exitable before buying"),{ok:e.length===0,errors:e,warnings:n}}function ht(t){let{ok:e,errors:n,warnings:r}=pt(t);if(!e)throw new Error(`invalid scanner for ${t?.key??"<unknown>"}:
3
+ `),d=He("sha256").update(c).digest("hex").slice(0,32),l=`${r.untrustedUrl?"untrusted":"trusted"}:${r.maxResponseBytes??"unbounded"}`;return`${t} ${e} ${l} ${d}`}function Je(t,e){let n=Number(e);return Number.isFinite(n)&&n>0?Math.min(n*1e3,pe):Math.min(250*2**t,pe)+Math.floor(Math.random()*100)}var Ze=t=>new Promise(e=>setTimeout(e,t));function O(t,e={}){let n=new Error(t);return n.retryable=!1,Object.assign(n,e),n}function re(t,e,n){return O(`HTTP response from ${t} exceeded maxResponseBytes ${n} (${e})`,{oversize:!0})}function F(t){try{let e=t?.body?.cancel?.();e&&typeof e.then=="function"&&e.catch(()=>{})}catch{}}function et(t){return t?t.byteLength??t.length??0:0}async function fe(t,e,{url:n,truncate:r=!1,onOversize:a}={}){if(e==null)return await t.text();let o=Number(t.headers?.get?.("content-length"));if(Number.isFinite(o)&&o>e&&(F(t),!r))throw re(n,`content-length ${o}`,e);let s=t.body?.getReader?.();if(!s){let i=await t.text(),p=Buffer.byteLength(i,"utf8");if(p>e){if(!r)throw re(n,`body ${p} bytes`,e);return Buffer.from(i,"utf8").subarray(0,e).toString("utf8")}return i}let c=[],d=0,l=!1;try{for(;;){let{value:i,done:p}=await s.read();if(p)break;if(i&&(c.push(Buffer.from(i)),d+=et(i),d>e)){l=!0;break}}}finally{if(l)try{await s.cancel()}catch{}try{s.releaseLock?.()}catch{}}if(l&&(typeof a=="function"&&a(),!r))throw re(n,`streamed ${d} bytes`,e);let u=Buffer.concat(c);return(l?u.subarray(0,e):u).toString("utf8")}function me(t){if(!t)return null;try{return JSON.parse(t)}catch{return null}}async function tt(t,{fetchImpl:e,method:n,headers:r,body:a,timeoutMs:o,lookupFn:s,realFetch:c,untrustedUrl:d=!1,maxResponseBytes:l=null,importUndici:u,validateResponse:i}){let p=new AbortController,h=setTimeout(()=>p.abort(),o),f=null,v=e,E=s?{lookupFn:s}:{};if(d&&!c&&!te(v))throw O(`HTTP refused ${t}: untrustedUrl requires a pin-capable fetchImpl (see markPinCapableFetch in egress-guard.mjs) or no fetchImpl override so Oracle can pin the connection itself`);let C=async(g,{status:S=null}={})=>{let x=await J(g,E);if(!x.ok)throw O(S==null?`HTTP refused ${g}: ${x.error}`:`HTTP redirect to ${g} ${x.error}`,S==null?{}:{status:S});let y=new URL(g).hostname;if(c){if(f&&(await f.close(),f=null),!f)try{f=await Z({requireUndici:!0,...u?{importUndici:u}:{}})}catch(I){throw O(S==null?`HTTP refused ${g}: ${I?.message||I}`:`HTTP redirect to ${g} refused: ${I?.message||I}`,S==null?{}:{status:S})}f.pin(y,x.addresses),v=f.fetch}else le(v,y,x.addresses);return x};try{let g=String(t),S={...r||{}};d&&await C(g);for(let x=0;x<=he;x+=1){let y=await v(g,{method:n,headers:S,body:a,signal:p.signal,redirect:"manual"});if(Ke.has(y.status)){if(n!=="GET"&&n!=="HEAD"){let T=await fe(y,l??We,{url:g,truncate:!0}),_=new Error(`HTTP ${y.status} ${n} ${g} redirected non-idempotent request`);throw _.status=y.status,_.body=me(T)??T.slice(0,300),_}if(x===he)throw F(y),new Error(`HTTP redirect loop for ${t}`);let N=y.headers?.get?.("location"),R;try{R=Ye(N,g)}catch(T){throw F(y),T}let j=!Qe(R,g);if(F(y),j&&(S=Ge(S)),d)await C(R,{status:y.status});else if(j){let T=await J(R,E);if(!T.ok){let _=new Error(`HTTP redirect from ${g} ${T.error}`);throw _.status=y.status,_.retryable=!1,_}c&&T.addresses?.length&&(f||(f=await Z(u?{importUndici:u}:{})),f&&(f.pin(new URL(R).hostname,T.addresses),v=f.fetch))}g=R;continue}if(typeof i=="function")try{await i(y,{url:g})}catch(N){throw F(y),O(N?.message||String(N))}let I=await fe(y,l,{url:g,onOversize:()=>p.abort()}),B=me(I);if(!y.ok){let N=new Error(`HTTP ${y.status} ${n} ${g}`);throw N.status=y.status,N.retryAfter=y.headers?.get?.("retry-after")??null,N.body=B??I.slice(0,300),N}return B??I}throw new Error(`HTTP redirect loop for ${t}`)}finally{clearTimeout(h),f&&await f.close()}}async function W(t,e={}){let n=e.fetchImpl||globalThis.fetch;if(typeof n!="function")throw new Error("fetch unavailable \u2014 pass opts.fetchImpl");let r=e.timeoutMs??12e3,a=(e.method||"GET").toUpperCase(),o={Accept:"application/json",...e.headers||{}},s=e.body;s!=null&&typeof s!="string"&&(o["Content-Type"]=o["Content-Type"]||"application/json",s=JSON.stringify(s));let c=Number.isInteger(e.retries)?Math.max(e.retries,0):je,d=e.lookupFn,l=!e.fetchImpl,u=e.untrustedUrl===!0,i=e.importUndici,p=e.validateResponse,h=Number(e.maxResponseBytes),f=Number.isFinite(h)&&h>0?Math.floor(h):null,v=async()=>{let x;for(let y=0;y<=c;y++)try{return await tt(t,{fetchImpl:n,method:a,headers:o,body:s,timeoutMs:r,lookupFn:d,realFetch:l,untrustedUrl:u,maxResponseBytes:f,importUndici:i,validateResponse:p})}catch(I){x=I;let B=I?.status,N=I?.name==="AbortError",R=new Set([408,425,429]),j=I?.retryable===!1?!1:B!=null?R.has(B)||Me.has(B)&&de.has(a):!N&&de.has(a);if(y===c||!j)throw I;await Ze(Je(y,I?.retryAfter))}throw x};if(!(e.dedupe!==!1&&a==="GET"&&s==null))return v();let C=Xe(a,t,o,{untrustedUrl:u,maxResponseBytes:f}),g=ne.get(C);if(g)return g;let S=v().finally(()=>ne.delete(C));return ne.set(C,S),S}var ve={robinhood:{chainId:4663,name:"Robinhood Chain",rpcEnv:["RH_CHAIN_RPC"],evm:!0},ethereum:{chainId:1,name:"Ethereum",rpcEnv:["ETH_RPC_URL","ETHEREUM_RPC_URL","MAINNET_RPC_URL"],evm:!0},polygon:{chainId:137,name:"Polygon",rpcEnv:["POLYGON_RPC_URL","POLYGON_RPC"],evm:!0},arbitrum:{chainId:42161,name:"Arbitrum One",rpcEnv:["ARBITRUM_RPC_URL","ARB_RPC_URL"],evm:!0},base:{chainId:8453,name:"Base",rpcEnv:["BASE_RPC_URL"],evm:!0},hyperevm:{chainId:999,name:"HyperEVM",rpcEnv:["HYPEREVM_RPC_URL","HYPER_EVM_RPC"],evm:!0},bsc:{chainId:56,name:"BNB Smart Chain",rpcEnv:["BSC_RPC_URL","BNB_RPC_URL"],evm:!0},avalanche:{chainId:43114,name:"Avalanche C-Chain",rpcEnv:["AVALANCHE_RPC_URL","AVAX_RPC_URL"],evm:!0},optimism:{chainId:10,name:"OP Mainnet",rpcEnv:["OPTIMISM_RPC_URL","OP_RPC_URL"],evm:!0},abstract:{chainId:2741,name:"Abstract",rpcEnv:["ABSTRACT_RPC_URL","ABS_RPC_URL"],evm:!0},stable:{chainId:988,name:"Stable Mainnet",rpcEnv:["STABLE_RPC_URL","STABLE_RPC"],evm:!0}},nt=new Map(Object.values(ve).map(t=>[t.chainId,t]));function ge(t){return nt.get(Number(t))||null}function ye(t,e=process.env){let n=ge(t);if(!n)return null;for(let r of n.rpcEnv){let a=(e[r]||"").trim();if(a)return a}return null}import{Interface as rt,getAddress as ot}from"ethers";var we=new rt(["function allowance(address owner,address spender) view returns (uint256)","function balanceOf(address account) view returns (uint256)"]);function Ee(t,e){try{return ot(t).toLowerCase()}catch{throw new Error(`${e} must be a valid EVM address`)}}var at={1:"https://ethereum.publicnode.com",137:"https://polygon-bor-rpc.publicnode.com",42161:"https://arbitrum-one-rpc.publicnode.com",8453:"https://base-rpc.publicnode.com",10:"https://optimism-rpc.publicnode.com",988:"https://rpc.stable.xyz",56:"https://bsc-rpc.publicnode.com",43114:"https://avalanche-c-chain-rpc.publicnode.com",999:"https://rpc.hyperliquid.xyz/evm",2741:"https://api.mainnet.abs.xyz",4663:"https://rpc.mainnet.chain.robinhood.com"};function it(t,{rpcUrl:e,env:n=process.env}={}){if(e)return e;let r=ye(t,n);return r||at[Number(t)]||null}var st=/^(?:eth_(?:call|blocknumber|chainid|get[a-z0-9]+|feehistory|gasprice|maxpriorityfeepergas|syncing|protocolversion|estimategas|createaccesslist)|net_(?:version|listening|peercount)|web3_(?:clientversion|sha3))$/;function ct(t){let e=String(t||""),n=e.toLowerCase();if(e!==e.trim()||!/^[a-zA-Z0-9_]+$/.test(e)||!st.test(n))throw new Error(`evm-rpc: ${e} refused \u2014 @oracle-agent/oracle is prepare-only (read RPC only; no broadcast/sign)`);return n}async function k(t,e,n=[],r={}){let a=String(e||"");ct(a);let o=it(t,r);if(!o)throw new Error(`No RPC URL for chainId ${t} (set env from chain registry rpcEnv or pass rpcUrl)`);let c=await W(o,{method:"POST",body:{jsonrpc:"2.0",id:1,method:e,params:n},fetchImpl:r.fetchImpl,timeoutMs:r.timeoutMs??12e3});if(c?.error){let d=new Error(c.error.message||JSON.stringify(c.error));throw d.code=c.error.code,d}return c.result}async function Se(t,e={}){let n=await k(t,"eth_blockNumber",[],e);return parseInt(n,16)}async function Ie(t,e,n={}){if(!e)throw new Error("rpcGetBalance requires address");let r=await k(t,"eth_getBalance",[e,"latest"],n);return{chainId:Number(t),address:e,balanceWei:BigInt(r).toString(),balanceHex:r}}async function xe(t={},e={}){let n=Number(t.chainId??e.chainId??1),r=Ee(t.token||t.tokenAddress,"token"),a=Ee(t.account||t.owner||t.address,"account"),o=we.encodeFunctionData("balanceOf",[a]),s=await k(n,"eth_call",[{to:r,data:o},t.blockTag||"latest"],e),c=we.decodeFunctionResult("balanceOf",s),d=BigInt(c[0]);return{chainId:n,token:r,account:a,balance:d.toString(),balanceHex:`0x${d.toString(16)}`,blockTag:t.blockTag||"latest"}}var ut="https://api.dexscreener.com",$t=Object.freeze({1:"ethereum",10:"optimism",56:"bsc",137:"polygon",8453:"base",42161:"arbitrum",43114:"avalanche",999:"hyperevm",4663:"robinhood"});function lt(t={}){return(t.baseUrl||process.env.DEXSCREENER_API_URL||ut).replace(/\/$/,"")}async function Ce(t,e={}){if(!t)throw new Error("tokenAddress required");return W(`${lt(e)}/latest/dex/tokens/${t}`,{fetchImpl:e.fetchImpl,timeoutMs:e.timeoutMs??12e3})}var D=Object.freeze(["blockNumber","nativeBalance","tokenBalance","resolveToken","resolvePools","scanBlocks","scoreRisk","quote","sellSimulation","prepareUnsignedTx"]),b=Object.freeze({LIVE:"LIVE",CACHED:"CACHED",STALE:"STALE",UNKNOWN:"UNKNOWN",UNAVAILABLE:"UNAVAILABLE"}),m=Object.freeze({PASS:"PASS",CAUTION:"CAUTION",FAIL:"FAIL",UNKNOWN:"UNKNOWN"}),dt=/^0x[0-9a-fA-F]{40}$/;function pt(t={}){let e=[],n=[];if(!t||typeof t!="object")return{ok:!1,errors:["definition must be an object"],warnings:n};if((!Number.isInteger(t.chainId)||t.chainId<=0)&&e.push("chainId must be a positive integer"),(typeof t.key!="string"||!/^[a-z][a-z0-9-]*$/.test(t.key||""))&&e.push('key must be a lowercase slug (e.g. "base")'),(typeof t.name!="string"||!t.name.trim())&&e.push("name is required"),!Array.isArray(t.rpcEnv)||t.rpcEnv.length===0)e.push("rpcEnv must list at least one environment variable name");else for(let a of t.rpcEnv)(typeof a!="string"||!/^[A-Z][A-Z0-9_]*$/.test(a))&&e.push(`rpcEnv entry "${a}" should be an UPPER_SNAKE env var name`);if(t.nativeCurrency){let a=t.nativeCurrency;(typeof a.symbol!="string"||!a.symbol)&&e.push("nativeCurrency.symbol is required when nativeCurrency is set"),Number.isInteger(a.decimals)||e.push("nativeCurrency.decimals must be an integer")}for(let[a,o]of(t.venues||[]).entries()){let s=`venues[${a}]`;if(!o||typeof o!="object"){e.push(`${s} must be an object`);continue}dt.test(o.address||"")||e.push(`${s}.address is not a valid 20-byte address`),/^0x0{40}$/.test(o.address||"")&&e.push(`${s}.address is the zero address -- placeholder left in place?`),o.kind||e.push(`${s}.kind is required (router|quoter|factory|...)`),o.verified?(o.verified.method||e.push(`${s}.verified.method is required`),o.verified.source||e.push(`${s}.verified.source is required`),o.verified.date||n.push(`${s}.verified.date missing -- add one so staleness is visible`)):e.push(`${s} must record verification: { verified: { method, source, date } }. An unverified venue stays blocked.`)}let r=t.capabilities||{};for(let a of Object.keys(r))D.includes(a)?typeof r[a]!="function"&&e.push(`capability "${a}" must be a function`):e.push(`unknown capability "${a}"`);return Object.keys(r).length===0&&n.push("scanner implements no capabilities -- it can only be registered, not used"),r.prepareUnsignedTx&&!r.quote&&n.push("prepareUnsignedTx without quote: no priced expectation to validate the built tx against"),r.prepareUnsignedTx&&!r.sellSimulation&&n.push("prepareUnsignedTx without sellSimulation: cannot prove an asset is exitable before buying"),{ok:e.length===0,errors:e,warnings:n}}function ht(t){let{ok:e,errors:n,warnings:r}=pt(t);if(!e)throw new Error(`invalid scanner for ${t?.key??"<unknown>"}:
4
4
  - ${n.join(`
5
- - `)}`);let a=t.capabilities||{},o=D.filter(c=>typeof a[c]=="function"),s={key:t.key,chainId:t.chainId,name:t.name,rpcEnv:[...t.rpcEnv],nativeCurrency:t.nativeCurrency?{...t.nativeCurrency}:null,wrappedNative:t.wrappedNative||null,explorer:t.explorer||null,venues:(t.venues||[]).map(c=>({...c})),warnings:r,capabilities(){return{chainId:t.chainId,key:t.key,supported:[...o],unsupported:D.filter(c=>!o.includes(c))}},supports(c){return o.includes(c)}};for(let c of D)o.includes(c)?s[c]=async(...d)=>a[c](...d,{scanner:s}):s[c]=async()=>{throw new Error(`${t.key} (chain ${t.chainId}) does not implement "${c}". Supported: ${o.join(", ")||"none"}. An unimplemented capability is absent, not assumed -- implement it or treat this chain as fail-closed for that operation.`)};return Object.freeze(s)}var V=new Map;function Ae(t){let e=ht(t);return V.set(e.chainId,e),e}function oe(t){return V.get(Number(t))||null}function z(){return[...V.values()]}function Ne(){let t={};for(let e of V.values())t[e.chainId]={key:e.key,name:e.name,...e.capabilities(),venueCount:e.venues.length,failClosed:e.venues.length===0};return{generatedAt:new Date().toISOString(),chainCount:V.size,capabilities:[...D],chains:t}}var ie={getAmountsOut:"d06ca61f",swapExactTokensForTokens:"38ed1739",swapExactETHForTokens:"7ff36ab5"},A=t=>BigInt(t).toString(16).padStart(64,"0"),H=t=>t.slice(2).toLowerCase().padStart(64,"0");function ft(t,e){return`0x${ie.getAmountsOut}`+A(t)+A(64)+A(e.length)+e.map(H).join("")}function mt(t){if(!t||t==="0x")return null;let e=t.slice(2);if(e.length<128)return null;let n=Number(BigInt(`0x${e.slice(64,128)}`));if(!Number.isFinite(n)||n<1||n>16)return null;let r=[];for(let a=0;a<n;a++){let o=128+a*64;if(e.length<o+64)return null;r.push(BigInt(`0x${e.slice(o,o+64)}`))}return r}function ae(t,e="router"){return(t?.venues||[]).find(r=>r.kind===e)?.address??null}var se=100;function bt(t,e){let n=Number(e);if(!Number.isFinite(n)||n<0)throw new Error("slippageBps must be a non-negative number");if(n>se)throw new Error(`slippageBps ${n} exceeds the ${se} bps ceiling. Block and requote or split the order -- do not widen the guard to force a fill.`);return BigInt(t)*BigInt(1e4-Math.floor(n))/10000n}function ke(t){let{chainId:e,wrappedNative:n}=t;async function r(a,o,s,c){let d=await k(e,"eth_call",[{to:a,data:ft(o,s)},"latest"],c);return mt(d?.result??d)}return{async quote({tokenIn:a,tokenOut:o,amountIn:s,path:c},d={}){let l=ae(d.scanner);if(!l)return{chainId:e,evidence:b.UNAVAILABLE,reason:"no verified router configured for this chain; quoting stays fail-closed rather than guessing a venue address"};let u=c||[a,o];if(u.some(p=>!/^0x[0-9a-fA-F]{40}$/.test(p||"")))throw new Error("quote requires valid 20-byte addresses");let i=await r(l,s,u,d);return i?{chainId:e,router:l,path:u,amountIn:String(s),amountOut:i[i.length-1].toString(),hops:u.length-1,evidence:b.LIVE,note:"exact-input quote at current reserves; not a guaranteed fill"}:{chainId:e,router:l,path:u,evidence:b.UNKNOWN,reason:"router returned no amounts -- no pool for this path, or the call reverted"}},async sellSimulation({token:a,amountIn:o,base:s},c={}){let d=ae(c.scanner),l=s||n;if(l&&String(a).toLowerCase()===String(l).toLowerCase())return{chainId:e,token:a,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:"token is the base asset for this chain, so there is nothing to round-trip against. Sellability must be judged against a different quote asset."};if(!d||!l)return{chainId:e,token:a,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:d?"no wrappedNative configured for this chain, so no base asset to round-trip against":"no verified router configured for this chain"};let u=await r(d,o,[l,a],c);if(!u)return{chainId:e,token:a,verdict:m.FAIL,evidence:b.LIVE,leg:"buy",reason:"buy leg returned no amounts -- no route in"};let i=u[u.length-1];if(i===0n)return{chainId:e,token:a,verdict:m.FAIL,evidence:b.LIVE,leg:"buy",reason:"buy leg quotes zero output"};let p=await r(d,i,[a,l],c);if(!p)return{chainId:e,token:a,verdict:m.FAIL,evidence:b.LIVE,leg:"sell",bought:i.toString(),reason:"SELL LEG FAILED while the buy leg quoted fine. This is the honeypot signature: do not trade."};let h=p[p.length-1],f=Number(h*10000n/BigInt(o)),v=m.PASS,E="round trip completes with expected fee/impact loss";return f<5e3?(v=m.FAIL,E=`round trip returns only ${(f/100).toFixed(2)}% -- punitive tax or no real liquidity`):f<9e3&&(v=m.CAUTION,E=`round trip returns ${(f/100).toFixed(2)}% -- transfer tax or thin liquidity at this size`),{chainId:e,token:a,base:l,router:d,verdict:v,reason:E,amountIn:String(o),bought:i.toString(),returned:h.toString(),retentionBps:f,evidence:b.LIVE,note:"Quote-level round trip. It does not prove transfer hooks absent at execution time."}},async prepareUnsignedTx({tokenIn:a,tokenOut:o,amountIn:s,recipient:c,slippageBps:d=50,deadlineSeconds:l=900,path:u},i={}){let p=i.scanner,h=ae(p);if(!h)throw new Error(`chain ${e} has no verified router; preparing a swap stays fail-closed. Add a venue with recorded provenance first (see docs/adding-a-chain.md).`);if(!/^0x[0-9a-fA-F]{40}$/.test(c||""))throw new Error("prepareUnsignedTx requires a valid recipient address");let f=u||[a,o],v=await this.quote({tokenIn:a,tokenOut:o,amountIn:s,path:f},i);if(v.evidence!==b.LIVE)throw new Error(`cannot prepare without a live quote (${v.evidence}: ${v.reason??"no reason given"})`);let E=bt(v.amountOut,d);if(E<=0n)throw new Error("computed minOut is zero -- refusing to prepare");let x=BigInt(Math.floor(Date.now()/1e3)+Number(l)),g=n&&f[0].toLowerCase()===n.toLowerCase()&&i.useNative,S=g?`0x${ie.swapExactETHForTokens}`+A(E)+A(128)+H(c)+A(x)+A(f.length)+f.map(H).join(""):`0x${ie.swapExactTokensForTokens}`+A(s)+A(E)+A(160)+H(c)+A(x)+A(f.length)+f.map(H).join("");return{unsigned:!0,signedBy:"user-wallet",chainId:e,tx:{to:h,data:S,value:g?`0x${BigInt(s).toString(16)}`:"0x0"},guard:{quotedOut:v.amountOut,minOut:E.toString(),slippageBps:d,maxSlippageBps:se,deadline:x.toString()},requires:g?[]:[{step:"approve",token:f[0],spender:h,amount:String(s)}],note:"UNSIGNED. Re-verify the guard against a fresh quote immediately before signing -- a quote-time minimum is not a minimum at broadcast time."}}}}var vt=[100,500,3e3,1e4],Ue={quoteExactInputSingle:"c6a5026a",exactInputSingle:"04e45aaf"},q=t=>BigInt(t).toString(16).padStart(64,"0"),M=t=>t.slice(2).toLowerCase().padStart(64,"0"),Te=/^0x[0-9a-fA-F]{40}$/,ue=100;function gt(t,e){let n=Number(e);if(!Number.isFinite(n)||n<0)throw new Error("slippageBps must be a non-negative number");if(n>ue)throw new Error(`slippageBps ${n} exceeds the ${ue} bps ceiling. Block and requote or split the order -- do not widen the guard to force a fill.`);return BigInt(t)*BigInt(1e4-Math.floor(n))/10000n}function ce(t,e){return(t?.venues||[]).find(n=>n.kind===e)?.address??null}function Re(t){let{chainId:e,wrappedNative:n}=t;async function r({quoter:o,tokenIn:s,tokenOut:c,amountIn:d,fee:l},u){let i=`0x${Ue.quoteExactInputSingle}`+M(s)+M(c)+q(d)+q(l)+q(0),p=await k(e,"eth_call",[{to:o,data:i},"latest"],u).catch(()=>null),h=p?.result??p;if(!h||h==="0x"||h.length<66)return null;let f=BigInt(`0x${h.slice(2,66)}`);return f>0n?f:null}async function a({quoter:o,tokenIn:s,tokenOut:c,amountIn:d},l){let u=[],i=null;for(let p of vt){let h=await r({quoter:o,tokenIn:s,tokenOut:c,amountIn:d,fee:p},l);u.push({fee:p,amountOut:h?h.toString():null}),h&&(!i||h>i.amountOut)&&(i={fee:p,amountOut:h})}return{best:i,tried:u}}return{async quote({tokenIn:o,tokenOut:s,amountIn:c},d={}){let l=ce(d.scanner,"quoter");if(!l)return{chainId:e,evidence:b.UNAVAILABLE,reason:"no verified quoter configured for this chain; quoting stays fail-closed rather than guessing a venue address"};for(let p of[o,s])if(!Te.test(p||""))throw new Error("quote requires valid 20-byte addresses");let{best:u,tried:i}=await a({quoter:l,tokenIn:o,tokenOut:s,amountIn:c},d);return u?{chainId:e,venue:"uniswap-v3",quoter:l,tokenIn:o,tokenOut:s,amountIn:String(c),amountOut:u.amountOut.toString(),fee:u.fee,useNative:!!n&&String(o).toLowerCase()===String(n).toLowerCase(),triedFeeTiers:i,evidence:b.LIVE,note:"exact-input single-hop quote at current tick; not a guaranteed fill"}:{chainId:e,quoter:l,tokenIn:o,tokenOut:s,triedFeeTiers:i,evidence:b.UNKNOWN,reason:"no fee tier returned a quote -- no V3 pool for this pair, or no liquidity"}},async sellSimulation({token:o,amountIn:s,base:c},d={}){let l=ce(d.scanner,"quoter"),u=c||n;if(u&&String(o).toLowerCase()===String(u).toLowerCase())return{chainId:e,token:o,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:"token is the base asset for this chain, so there is nothing to round-trip against. Sellability must be judged against a different quote asset."};if(!l||!u)return{chainId:e,token:o,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:l?"no wrappedNative configured, so there is no base asset to round-trip against":"no verified quoter configured for this chain"};let i=await a({quoter:l,tokenIn:u,tokenOut:o,amountIn:s},d);if(!i.best)return{chainId:e,token:o,verdict:m.FAIL,evidence:b.LIVE,leg:"buy",reason:"no V3 pool priced the buy leg on any fee tier"};let p=await a({quoter:l,tokenIn:o,tokenOut:u,amountIn:i.best.amountOut},d);if(!p.best)return{chainId:e,token:o,verdict:m.FAIL,evidence:b.LIVE,leg:"sell",bought:i.best.amountOut.toString(),reason:"SELL LEG FAILED while the buy leg quoted fine. This is the honeypot signature: do not trade."};let h=p.best.amountOut,f=Number(h*10000n/BigInt(s)),v=m.PASS,E="round trip completes with expected fee/impact loss";return f<5e3?(v=m.FAIL,E=`round trip returns only ${(f/100).toFixed(2)}% -- punitive tax or no real liquidity`):f<9e3&&(v=m.CAUTION,E=`round trip returns ${(f/100).toFixed(2)}% -- transfer tax or thin liquidity at this size`),{chainId:e,venue:"uniswap-v3",token:o,base:u,verdict:v,reason:E,amountIn:String(s),bought:i.best.amountOut.toString(),returned:h.toString(),retentionBps:f,buyFee:i.best.fee,sellFee:p.best.fee,evidence:b.LIVE,note:"Quote-level round trip. It does not prove transfer hooks absent at execution time."}},async prepareUnsignedTx({tokenIn:o,tokenOut:s,amountIn:c,recipient:d,slippageBps:l=50,fee:u},i={}){let p=ce(i.scanner,"router");if(!p)throw new Error(`chain ${e} has no verified V3 router; preparing a swap stays fail-closed. Add a venue with recorded provenance first (see docs/adding-a-chain.md).`);if(!Te.test(d||""))throw new Error("prepareUnsignedTx requires a valid recipient address");let h=await this.quote({tokenIn:o,tokenOut:s,amountIn:c},i);if(h.evidence!==b.LIVE)throw new Error(`cannot prepare without a live quote (${h.evidence}: ${h.reason??"no reason given"})`);let f=u??h.fee,v=gt(h.amountOut,l);if(v<=0n)throw new Error("computed minOut is zero -- refusing to prepare");let E=!!(i.useNative||h.useNative)&&n&&String(o).toLowerCase()===String(n).toLowerCase(),x=`0x${Ue.exactInputSingle}`+M(o)+M(s)+q(f)+M(d)+q(c)+q(v)+q(0);return{unsigned:!0,signedBy:"user-wallet",chainId:e,venue:"uniswap-v3",tx:{to:p,data:x,value:E?String(c):"0x0"},guard:{quotedOut:h.amountOut,minOut:v.toString(),slippageBps:l,maxSlippageBps:ue,fee:f},requires:E?[]:[{step:"approve",token:o,spender:p,amount:String(c)}],note:"UNSIGNED. Re-verify the guard against a fresh quote immediately before signing -- a quote-time minimum is not a minimum at broadcast time."}}}}var G={decimals:"0x313ce567",symbol:"0x95d89b41",name:"0x06fdde03",totalSupply:"0x18160ddd",owner:"0x8da5cb5b"};function _e(t){if(!t||t==="0x")return null;try{return BigInt(t)}catch{return null}}function Le(t){if(!t||t==="0x")return null;let e=t.slice(2);if(e.length>=128){let r=Number(BigInt(`0x${e.slice(64,128)}`));if(r>0&&r<=256&&e.length>=128+r*2){let a=e.slice(128,128+r*2),o=Buffer.from(a,"hex").toString("utf8").replace(/\0+$/,"");if(o)return o}}return Buffer.from(e.slice(0,64),"hex").toString("utf8").replace(/\0+$/,"")||null}function yt(t){let{chainId:e}=t;async function n(r,a,o){return k(e,"eth_call",[{to:r,data:a},"latest"],o)}return{async blockNumber(r={}){let a=await Se(e,r);return{chainId:e,blockNumber:a?.blockNumber??a,evidence:b.LIVE}},async nativeBalance(r,a={}){let o=await Ie(e,r,a);return{chainId:e,address:r,wei:o?.wei??o?.balance??null,symbol:t.nativeCurrency?.symbol??null,decimals:t.nativeCurrency?.decimals??18,evidence:b.LIVE}},async tokenBalance({token:r,owner:a},o={}){let s=await Ce({chainId:e,token:r,owner:a},o);return{chainId:e,token:r,owner:a,raw:s?.balance??s,evidence:b.LIVE}},async resolveToken(r,a={}){if(!/^0x[0-9a-fA-F]{40}$/.test(r||""))return{chainId:e,token:r,evidence:b.UNKNOWN,error:"resolveToken needs a 20-byte address; symbol lookup is a market-data concern"};let[o,s,c,d]=await Promise.all([n(r,G.decimals,a).catch(()=>null),n(r,G.symbol,a).catch(()=>null),n(r,G.name,a).catch(()=>null),n(r,G.totalSupply,a).catch(()=>null)]),l=_e(o?.result??o),u=l!==null||s?.result||c?.result;return{chainId:e,address:r,decimals:l===null?null:Number(l),symbol:Le(s?.result??s),name:Le(c?.result??c),totalSupply:(_e(d?.result??d)??null)?.toString()??null,evidence:u?b.LIVE:b.UNKNOWN,warning:u?void 0:"no ERC-20 metadata returned -- may not be a token contract"}},async resolvePools(r,a={}){let o=t.dexscreenerSlug;if(!o)return{chainId:e,token:r,pools:[],evidence:b.UNAVAILABLE,reason:"no dexscreenerSlug configured for this chain; pool discovery is unavailable rather than guessed"};let s=await xe(r,a).catch(()=>null),d=(s?.pairs||s?.data?.pairs||[]).filter(l=>String(l.chainId).toLowerCase()===String(o).toLowerCase()).map(l=>({pair:l.pairAddress,dex:l.dexId,base:l.baseToken?.address,quote:l.quoteToken?.address,liquidityUsd:l.liquidity?.usd??null,priceUsd:l.priceUsd??null,volume24hUsd:l.volume?.h24??null,createdAt:l.pairCreatedAt??null})).sort((l,u)=>(u.liquidityUsd??0)-(l.liquidityUsd??0));return{chainId:e,token:r,pools:d,evidence:d.length?b.LIVE:b.UNKNOWN}},async scanBlocks({fromBlock:r,toBlock:a,address:o,topics:s,chunkSize:c=2e3}={},d={}){if(!Number.isInteger(r)||!Number.isInteger(a))throw new Error("scanBlocks requires integer fromBlock and toBlock");if(a<r)throw new Error("toBlock must be >= fromBlock");let l=[],u=[];for(let i=r;i<=a;i+=c){let p=Math.min(i+c-1,a);u.push([i,p])}for(let[i,p]of u){let h={fromBlock:`0x${i.toString(16)}`,toBlock:`0x${p.toString(16)}`};o&&(h.address=o),s&&(h.topics=s);let f=await k(e,"eth_getLogs",[h],d).catch(v=>({error:String(v?.message||v)}));if(f?.error)return{chainId:e,fromBlock:r,toBlock:a,logs:l,complete:!1,failedAt:[i,p],error:f.error,evidence:b.UNKNOWN};for(let v of f?.result??f??[])l.push(v)}return{chainId:e,fromBlock:r,toBlock:a,logs:l,complete:!0,chunks:u.length,evidence:b.LIVE}},async scoreRisk(r,a={}){let o=[],s=m.PASS,c=u=>{let i={[m.PASS]:0,[m.CAUTION]:1,[m.UNKNOWN]:2,[m.FAIL]:3};i[u]>i[s]&&(s=u)},d=await this.resolveToken(r,a);d.evidence!==b.LIVE?(o.push({check:"erc20-metadata",result:m.UNKNOWN,detail:d.warning}),c(m.UNKNOWN)):o.push({check:"erc20-metadata",result:m.PASS,detail:`${d.symbol} / ${d.decimals}d`});let l=await this.resolvePools(r,a);if(l.evidence===b.UNAVAILABLE)o.push({check:"liquidity",result:m.UNKNOWN,detail:l.reason}),c(m.UNKNOWN);else if(!l.pools.length)o.push({check:"liquidity",result:m.FAIL,detail:"no pool with liquidity found"}),c(m.FAIL);else{let u=l.pools[0],i=u.liquidityUsd??0;i<5e3?(o.push({check:"liquidity",result:m.CAUTION,detail:`top pool only $${i}`}),c(m.CAUTION)):o.push({check:"liquidity",result:m.PASS,detail:`$${i} on ${u.dex}`}),u.createdAt&&Date.now()-u.createdAt<24*3600*1e3&&(o.push({check:"age",result:m.CAUTION,detail:"pool under 24h old"}),c(m.CAUTION))}if(typeof this.sellSimulation=="function"){let u=await this.sellSimulation({token:r,amountIn:(10n**16n).toString()},a).catch(i=>({verdict:m.UNKNOWN,reason:String(i?.message||i)}));o.push({check:"sellability",result:u.verdict,detail:u.retentionBps!=null?`round trip returns ${(u.retentionBps/100).toFixed(2)}% -- ${u.reason}`:u.reason}),c(u.verdict)}else o.push({check:"sellability",result:m.UNKNOWN,detail:"no verified router on this chain, so a round-trip sell simulation cannot run. Treat as unproven -- a buy path is not an exit path."}),c(m.UNKNOWN);return{chainId:e,token:r,verdict:s,checks:o,note:"Structural checks only. UNKNOWN is not PASS. A token is not tradeable until a sell simulation succeeds."}}}}function qe(t){let n={...yt(t)},r=new Set((t.venues||[]).map(o=>o.kind));t.venueKind==="uniswap-v3"&&r.has("quoter")&&r.has("router")?Object.assign(n,Re({chainId:t.chainId,wrappedNative:t.wrappedNative})):t.venueKind==="uniswap-v2"&&r.has("router")&&Object.assign(n,ke({chainId:t.chainId,wrappedNative:t.wrappedNative}));let a={};for(let[o,s]of Object.entries(n))a[o]=s.bind(n);return{key:t.key,chainId:t.chainId,name:t.name,rpcEnv:t.rpcEnv,nativeCurrency:t.nativeCurrency,explorer:t.explorer,venues:t.venues||[],capabilities:a}}var wt=Object.freeze([{key:"ethereum",chainId:1,name:"Ethereum",rpcEnv:["ETH_RPC_URL","ETHEREUM_RPC_URL","MAINNET_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://etherscan.io",dexscreenerSlug:"ethereum",venueKind:"uniswap-v3",wrappedNative:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDC fee 500 quoted 1908.71 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:1}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:1}}]},{key:"optimism",chainId:10,name:"OP Mainnet",rpcEnv:["OPTIMISM_RPC_URL","OP_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://optimistic.etherscan.io",dexscreenerSlug:"optimism",venueKind:"uniswap-v3",wrappedNative:"0x4200000000000000000000000000000000000006",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDC fee 500 quoted 1905.23 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:10}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:10}}]},{key:"bsc",chainId:56,name:"BNB Smart Chain",rpcEnv:["BSC_RPC_URL","BNB_RPC_URL"],nativeCurrency:{symbol:"BNB",decimals:18},explorer:"https://bscscan.com",dexscreenerSlug:"bsc",venueKind:"uniswap-v3",wrappedNative:"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",venues:[{kind:"quoter",address:"0x78D78E420Da98ad378D7799bE8f4AF69033EB077",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WBNB->USDC fee 500 quoted 413.86 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:56}},{kind:"router",address:"0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:56}}]},{key:"polygon",chainId:137,name:"Polygon",rpcEnv:["POLYGON_RPC_URL","POLYGON_RPC"],nativeCurrency:{symbol:"POL",decimals:18},explorer:"https://polygonscan.com",dexscreenerSlug:"polygon",venueKind:"uniswap-v3",wrappedNative:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WMATIC->USDC fee 500 quoted 0.0720 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:137}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:137}}]},{key:"stable",chainId:988,name:"Stable Mainnet",rpcEnv:["STABLE_RPC_URL","STABLE_RPC"],nativeCurrency:{symbol:"USDT0",decimals:18},venueKind:"uniswap-v3",wrappedNative:"0x5d442b349590a6048Eb2dC0eC346cAA5F47A9ab5",venues:[{kind:"quoter",address:"0xb070179E7032CdA868b53e6C1742F80c9e940d1A",label:"Uniswap V3 QuoterV2 (canonical)",verified:{method:"Stable is on the OFFICIAL Uniswap v3 Deployments List (governance-recognised 2026-05-12, UAC process completed 2026-04, deployed by Protofire), so this is a canonical deployment rather than a fork. eth_getCode returned 8273 bytes, the same size as the canonical quoter on the seven already-verified chains. Functional probe on a live pool (TOAST -> USDT0, fee 10000): 100 in -> 0.000003, 1000 -> 0.000031, 10000 -> 0.000319 USDT0. Output scales monotonically with input, which is a working quoter answering, not a revert. Two of three sampled pools carry non-zero liquidity. NOTE: the pools discovered so far are thin, so real routing size is limited -- the venue is proved, deep liquidity is not.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:988}},{kind:"router",address:"0x32eaf9B5d5F2CD7361c5012890C943D7de84C22a",label:"Uniswap SwapRouter02 (canonical)",verified:{method:"eth_getCode returned 24497 bytes. Cross-checked on-chain rather than trusted from docs: router.factory() returns 0x88f0a512ef09175d456bc9547f914f48c013e4aa, the same v3 core factory that created the pools quoted above, and router.WETH9() returns the wrappedNative recorded on this chain entry. Address published in the Stable docs DEX reference and the Uniswap deployments list.",source:"docs.stable.xyz/en/reference/dexes + on-chain factory()/WETH9() round-trip",date:"2026-08-05",chainId:988}}]},{key:"hyperevm",chainId:999,name:"HyperEVM",rpcEnv:["HYPEREVM_RPC_URL","HYPER_EVM_RPC"],nativeCurrency:{symbol:"HYPE",decimals:18},dexscreenerSlug:"hyperevm",venueKind:"uniswap-v3",wrappedNative:"0x5555555555555555555555555555555555555555",venues:[{kind:"quoter",address:"0x03A918028f22D9E1473B7959C927AD7425A45C7C",label:"HyperSwap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle(1 WHYPE -> USDT0) returned live output on all four fee tiers (100: 57.3385, 500: 57.4187, 3000: 57.3237, 10000: 56.1963 USDT0). Decimals read on-chain: WHYPE 18, USDT0 6. Best tier checked against an INDEPENDENT control the same minute -- Hyperliquid allMids put HYPE at 57.3205, so the pool is 0.171% from the perp mid, which is the right shape for fee plus impact rather than a wrong contract or a decimals bug.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:999}},{kind:"router",address:"0x4E2960a8cd19B467b82d26D83fAcb0fAE26b094D",label:"HyperSwap V3 SwapRouter",verified:{method:"eth_getCode returned 12070 bytes, and it is the router paired with the quoter proved above -- the same pair already shipped in UNI_V3_VENUES[999].hyperswap, which is the map the quote/prepare path actually routes through.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:999}}]},{key:"abstract",chainId:2741,name:"Abstract",rpcEnv:["ABSTRACT_RPC_URL","ABS_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},venueKind:"uniswap-v3",wrappedNative:"0x3439153EB7AF838Ad19d56E1571FBD09333C2809",venues:[{kind:"quoter",address:"0x728BD3eC25D5EDBafebB84F3d67367Cd9EBC7693",label:"Uniswap V3 QuoterV2 (Abstract deployment)",verified:{method:"Abstract is a ZK-stack chain, so CREATE2 addresses differ and the canonical Uniswap addresses are NOT valid here -- probing them returns codesize 0, which is what previously made this chain look like it had no V3 at all. Found the real deployment from live traffic instead: scanned recent Swap(...) logs, took the busiest pool, read pool.factory() = 0xa1160e73b63f322ae88cc2d8e700833e71d0b2a1, then enumerated that factory's deployer (0xf3d63166F0Ca56C3c1A3508FcE03Ff0Cf3Fb691e) and probed each of its 56 contracts with a real quoteExactInputSingle call. Exactly one answered: 1 WETH -> 1846.475731 USDC.e at fee 500. Independent sanity check: the pool's own slot0() spot price is 1873.11 USDC.e per WETH, so the quoter sits ~1.4% below spot, the right shape for fee plus price impact on this size.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:2741}},{kind:"router",address:"0x7712FA47387542819d4E35A23f8116C90C18767C",label:"Uniswap SwapRouter02 (Abstract deployment)",verified:{method:"eth_getCode returned 167392 bytes and the runtime contains the exactInputSingle selector. router.factory() matches the factory proved above and router.WETH9() matches the wrappedNative on this entry. Chosen over its byte-identical twin (0xfD6257F4...) because this is the address real users actually route through: it appeared as tx.to on live swaps against the WETH/USDC.e pool.",source:"on-chain factory()/WETH9() round-trip + live swap tx.to sampling",date:"2026-08-05",chainId:2741}}]},{key:"robinhood",chainId:4663,name:"Robinhood Chain",rpcEnv:["RH_CHAIN_RPC","ROBINHOOD_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},dexscreenerSlug:"robinhood",venueKind:"uniswap-v3",wrappedNative:"0x0bd7d308f8e1639fab988df18a8011f41eacad73",venues:[{kind:"quoter",address:"0x33e885ed0ec9bf04ecfb19341582aadcb4c8a9e7",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDG fee 100 quoted 1866.58 USDG, and USDG->CASHCAT fee 10000 quoted a live amount). A contract that correctly prices known pairs IS a working V3 quoter",source:"live eth_call against rpc.mainnet.chain.robinhood.com",date:"2026-07-31",chainId:4663}},{kind:"router",address:"0xcaf681a66d020601342297493863e78c959e5cb2",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode (24497 bytes) on this chain and the paired quoter at the same deployment passed a live functional quote",source:"live eth_getCode against rpc.mainnet.chain.robinhood.com",date:"2026-07-31",chainId:4663}},{kind:"factory",address:"0x1f7d7550b1b028f7571e69a784071f0205fd2efa",label:"Uniswap V3 Factory",verified:{method:"eth_getCode returned real bytecode (24535 bytes) and a PoolCreated log scan over this factory returned 76 pools in ~9000 recent blocks",source:"live eth_getLogs against rpc.mainnet.chain.robinhood.com",date:"2026-07-31",chainId:4663}}]},{key:"base",chainId:8453,name:"Base",rpcEnv:["BASE_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://basescan.org",dexscreenerSlug:"base",venueKind:"uniswap-v3",wrappedNative:"0x4200000000000000000000000000000000000006",venues:[{kind:"quoter",address:"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",label:"Uniswap V3 QuoterV2 (Base)",verified:{method:"functional probe: quoteExactInputSingle returned WETH->USDC at fee 500 = 1908.44 USDC, a live sane price. The canonical mainnet quoter address also has bytecode on Base but does NOT price this pair, which is exactly the false positive a codesize-only check accepts",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:8453}},{kind:"router",address:"0x2626664c2603336E57B271c5C0b26F421741e481",label:"Uniswap V3 SwapRouter02 (Base)",verified:{method:"eth_getCode returned real bytecode and the paired Base quoter passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:8453}},{kind:"router-v2",address:"0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",label:"Uniswap V2 Router02 (Base)",verified:{method:"eth_getCode returned 17891 bytes; live getAmountsOut on WETH->USDC round-tripped to 98.75% (2x0.30% fee + impact)",source:"https://docs.uniswap.org/contracts/v2/reference/smart-contracts/v2-deployments",date:"2026-07-30",chainId:8453}}]},{key:"arbitrum",chainId:42161,name:"Arbitrum One",rpcEnv:["ARBITRUM_RPC_URL","ARB_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://arbiscan.io",dexscreenerSlug:"arbitrum",venueKind:"uniswap-v3",wrappedNative:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDC fee 500 quoted 1908.72 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:42161}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:42161}}]},{key:"avalanche",chainId:43114,name:"Avalanche C-Chain",rpcEnv:["AVALANCHE_RPC_URL","AVAX_RPC_URL"],nativeCurrency:{symbol:"AVAX",decimals:18},explorer:"https://snowtrace.io",dexscreenerSlug:"avalanche",venueKind:"uniswap-v3",wrappedNative:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",venues:[{kind:"quoter",address:"0xbe0F5544EC67e9B3b2D979aaA43f18Fd87E6257F",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WAVAX->USDC fee 500 quoted 6.48 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:43114}},{kind:"router",address:"0xbb00FF08d01D300023C629E8fFfFcb65A5a578cE",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:43114}}]}]);function $e(){return wt.map(t=>Ae(qe(t)))}$e();var[Be,...Pe]=process.argv.slice(2),Y=Pe.includes("--json"),w=Pe.filter(t=>t!=="--json");function P(t){t||U("missing <chain>");let e=oe(Number(t));if(e)return e;let n=z().find(r=>r.key===String(t).toLowerCase());if(n)return n;U(`unknown chain "${t}". Known: ${z().map(r=>`${r.key}(${r.chainId})`).join(", ")}`)}function U(t){console.error(`error: ${t}`),process.exit(1)}function $(t){process.stdout.write(`${JSON.stringify(t,null,2)}
5
+ - `)}`);let a=t.capabilities||{},o=D.filter(c=>typeof a[c]=="function"),s={key:t.key,chainId:t.chainId,name:t.name,rpcEnv:[...t.rpcEnv],nativeCurrency:t.nativeCurrency?{...t.nativeCurrency}:null,wrappedNative:t.wrappedNative||null,explorer:t.explorer||null,venues:(t.venues||[]).map(c=>({...c})),warnings:r,capabilities(){return{chainId:t.chainId,key:t.key,supported:[...o],unsupported:D.filter(c=>!o.includes(c))}},supports(c){return o.includes(c)}};for(let c of D)o.includes(c)?s[c]=async(...d)=>a[c](...d,{scanner:s}):s[c]=async()=>{throw new Error(`${t.key} (chain ${t.chainId}) does not implement "${c}". Supported: ${o.join(", ")||"none"}. An unimplemented capability is absent, not assumed -- implement it or treat this chain as fail-closed for that operation.`)};return Object.freeze(s)}var V=new Map;function Ae(t){let e=ht(t);return V.set(e.chainId,e),e}function oe(t){return V.get(Number(t))||null}function z(){return[...V.values()]}function Ne(){let t={};for(let e of V.values())t[e.chainId]={key:e.key,name:e.name,...e.capabilities(),venueCount:e.venues.length,failClosed:e.venues.length===0};return{generatedAt:new Date().toISOString(),chainCount:V.size,capabilities:[...D],chains:t}}var ie={getAmountsOut:"d06ca61f",swapExactTokensForTokens:"38ed1739",swapExactETHForTokens:"7ff36ab5"},A=t=>BigInt(t).toString(16).padStart(64,"0"),H=t=>t.slice(2).toLowerCase().padStart(64,"0");function ft(t,e){return`0x${ie.getAmountsOut}`+A(t)+A(64)+A(e.length)+e.map(H).join("")}function mt(t){if(!t||t==="0x")return null;let e=t.slice(2);if(e.length<128)return null;let n=Number(BigInt(`0x${e.slice(64,128)}`));if(!Number.isFinite(n)||n<1||n>16)return null;let r=[];for(let a=0;a<n;a++){let o=128+a*64;if(e.length<o+64)return null;r.push(BigInt(`0x${e.slice(o,o+64)}`))}return r}function ae(t,e="router"){return(t?.venues||[]).find(r=>r.kind===e)?.address??null}var se=100;function bt(t,e){let n=Number(e);if(!Number.isFinite(n)||n<0)throw new Error("slippageBps must be a non-negative number");if(n>se)throw new Error(`slippageBps ${n} exceeds the ${se} bps ceiling. Block and requote or split the order -- do not widen the guard to force a fill.`);return BigInt(t)*BigInt(1e4-Math.floor(n))/10000n}function ke(t){let{chainId:e,wrappedNative:n}=t;async function r(a,o,s,c){let d=await k(e,"eth_call",[{to:a,data:ft(o,s)},"latest"],c);return mt(d?.result??d)}return{async quote({tokenIn:a,tokenOut:o,amountIn:s,path:c},d={}){let l=ae(d.scanner);if(!l)return{chainId:e,evidence:b.UNAVAILABLE,reason:"no verified router configured for this chain; quoting stays fail-closed rather than guessing a venue address"};let u=c||[a,o];if(u.some(p=>!/^0x[0-9a-fA-F]{40}$/.test(p||"")))throw new Error("quote requires valid 20-byte addresses");let i=await r(l,s,u,d);return i?{chainId:e,router:l,path:u,amountIn:String(s),amountOut:i[i.length-1].toString(),hops:u.length-1,evidence:b.LIVE,note:"exact-input quote at current reserves; not a guaranteed fill"}:{chainId:e,router:l,path:u,evidence:b.UNKNOWN,reason:"router returned no amounts -- no pool for this path, or the call reverted"}},async sellSimulation({token:a,amountIn:o,base:s},c={}){let d=ae(c.scanner),l=s||n;if(l&&String(a).toLowerCase()===String(l).toLowerCase())return{chainId:e,token:a,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:"token is the base asset for this chain, so there is nothing to round-trip against. Sellability must be judged against a different quote asset."};if(!d||!l)return{chainId:e,token:a,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:d?"no wrappedNative configured for this chain, so no base asset to round-trip against":"no verified router configured for this chain"};let u=await r(d,o,[l,a],c);if(!u)return{chainId:e,token:a,verdict:m.FAIL,evidence:b.LIVE,leg:"buy",reason:"buy leg returned no amounts -- no route in"};let i=u[u.length-1];if(i===0n)return{chainId:e,token:a,verdict:m.FAIL,evidence:b.LIVE,leg:"buy",reason:"buy leg quotes zero output"};let p=await r(d,i,[a,l],c);if(!p)return{chainId:e,token:a,verdict:m.FAIL,evidence:b.LIVE,leg:"sell",bought:i.toString(),reason:"SELL LEG FAILED while the buy leg quoted fine. This is the honeypot signature: do not trade."};let h=p[p.length-1],f=Number(h*10000n/BigInt(o)),v=m.PASS,E="round trip completes with expected fee/impact loss";return f<5e3?(v=m.FAIL,E=`round trip returns only ${(f/100).toFixed(2)}% -- punitive tax or no real liquidity`):f<9e3&&(v=m.CAUTION,E=`round trip returns ${(f/100).toFixed(2)}% -- transfer tax or thin liquidity at this size`),{chainId:e,token:a,base:l,router:d,verdict:v,reason:E,amountIn:String(o),bought:i.toString(),returned:h.toString(),retentionBps:f,evidence:b.LIVE,note:"Quote-level round trip. It does not prove transfer hooks absent at execution time."}},async prepareUnsignedTx({tokenIn:a,tokenOut:o,amountIn:s,recipient:c,slippageBps:d=50,deadlineSeconds:l=900,path:u},i={}){let p=i.scanner,h=ae(p);if(!h)throw new Error(`chain ${e} has no verified router; preparing a swap stays fail-closed. Add a venue with recorded provenance first (see docs/adding-a-chain.md).`);if(!/^0x[0-9a-fA-F]{40}$/.test(c||""))throw new Error("prepareUnsignedTx requires a valid recipient address");let f=u||[a,o],v=await this.quote({tokenIn:a,tokenOut:o,amountIn:s,path:f},i);if(v.evidence!==b.LIVE)throw new Error(`cannot prepare without a live quote (${v.evidence}: ${v.reason??"no reason given"})`);let E=bt(v.amountOut,d);if(E<=0n)throw new Error("computed minOut is zero -- refusing to prepare");let C=BigInt(Math.floor(Date.now()/1e3)+Number(l)),g=n&&f[0].toLowerCase()===n.toLowerCase()&&i.useNative,S=g?`0x${ie.swapExactETHForTokens}`+A(E)+A(128)+H(c)+A(C)+A(f.length)+f.map(H).join(""):`0x${ie.swapExactTokensForTokens}`+A(s)+A(E)+A(160)+H(c)+A(C)+A(f.length)+f.map(H).join("");return{unsigned:!0,signedBy:"user-wallet",chainId:e,tx:{to:h,data:S,value:g?`0x${BigInt(s).toString(16)}`:"0x0"},guard:{quotedOut:v.amountOut,minOut:E.toString(),slippageBps:d,maxSlippageBps:se,deadline:C.toString()},requires:g?[]:[{step:"approve",token:f[0],spender:h,amount:String(s)}],note:"UNSIGNED. Re-verify the guard against a fresh quote immediately before signing -- a quote-time minimum is not a minimum at broadcast time."}}}}var vt=[100,500,3e3,1e4],Ue={quoteExactInputSingle:"c6a5026a",exactInputSingle:"04e45aaf"},q=t=>BigInt(t).toString(16).padStart(64,"0"),M=t=>t.slice(2).toLowerCase().padStart(64,"0"),Te=/^0x[0-9a-fA-F]{40}$/,ue=100;function gt(t,e){let n=Number(e);if(!Number.isFinite(n)||n<0)throw new Error("slippageBps must be a non-negative number");if(n>ue)throw new Error(`slippageBps ${n} exceeds the ${ue} bps ceiling. Block and requote or split the order -- do not widen the guard to force a fill.`);return BigInt(t)*BigInt(1e4-Math.floor(n))/10000n}function ce(t,e){return(t?.venues||[]).find(n=>n.kind===e)?.address??null}function Re(t){let{chainId:e,wrappedNative:n}=t;async function r({quoter:o,tokenIn:s,tokenOut:c,amountIn:d,fee:l},u){let i=`0x${Ue.quoteExactInputSingle}`+M(s)+M(c)+q(d)+q(l)+q(0),p=await k(e,"eth_call",[{to:o,data:i},"latest"],u).catch(()=>null),h=p?.result??p;if(!h||h==="0x"||h.length<66)return null;let f=BigInt(`0x${h.slice(2,66)}`);return f>0n?f:null}async function a({quoter:o,tokenIn:s,tokenOut:c,amountIn:d},l){let u=[],i=null;for(let p of vt){let h=await r({quoter:o,tokenIn:s,tokenOut:c,amountIn:d,fee:p},l);u.push({fee:p,amountOut:h?h.toString():null}),h&&(!i||h>i.amountOut)&&(i={fee:p,amountOut:h})}return{best:i,tried:u}}return{async quote({tokenIn:o,tokenOut:s,amountIn:c},d={}){let l=ce(d.scanner,"quoter");if(!l)return{chainId:e,evidence:b.UNAVAILABLE,reason:"no verified quoter configured for this chain; quoting stays fail-closed rather than guessing a venue address"};for(let p of[o,s])if(!Te.test(p||""))throw new Error("quote requires valid 20-byte addresses");let{best:u,tried:i}=await a({quoter:l,tokenIn:o,tokenOut:s,amountIn:c},d);return u?{chainId:e,venue:"uniswap-v3",quoter:l,tokenIn:o,tokenOut:s,amountIn:String(c),amountOut:u.amountOut.toString(),fee:u.fee,useNative:!!n&&String(o).toLowerCase()===String(n).toLowerCase(),triedFeeTiers:i,evidence:b.LIVE,note:"exact-input single-hop quote at current tick; not a guaranteed fill"}:{chainId:e,quoter:l,tokenIn:o,tokenOut:s,triedFeeTiers:i,evidence:b.UNKNOWN,reason:"no fee tier returned a quote -- no V3 pool for this pair, or no liquidity"}},async sellSimulation({token:o,amountIn:s,base:c},d={}){let l=ce(d.scanner,"quoter"),u=c||n;if(u&&String(o).toLowerCase()===String(u).toLowerCase())return{chainId:e,token:o,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:"token is the base asset for this chain, so there is nothing to round-trip against. Sellability must be judged against a different quote asset."};if(!l||!u)return{chainId:e,token:o,verdict:m.UNKNOWN,evidence:b.UNAVAILABLE,reason:l?"no wrappedNative configured, so there is no base asset to round-trip against":"no verified quoter configured for this chain"};let i=await a({quoter:l,tokenIn:u,tokenOut:o,amountIn:s},d);if(!i.best)return{chainId:e,token:o,verdict:m.FAIL,evidence:b.LIVE,leg:"buy",reason:"no V3 pool priced the buy leg on any fee tier"};let p=await a({quoter:l,tokenIn:o,tokenOut:u,amountIn:i.best.amountOut},d);if(!p.best)return{chainId:e,token:o,verdict:m.FAIL,evidence:b.LIVE,leg:"sell",bought:i.best.amountOut.toString(),reason:"SELL LEG FAILED while the buy leg quoted fine. This is the honeypot signature: do not trade."};let h=p.best.amountOut,f=Number(h*10000n/BigInt(s)),v=m.PASS,E="round trip completes with expected fee/impact loss";return f<5e3?(v=m.FAIL,E=`round trip returns only ${(f/100).toFixed(2)}% -- punitive tax or no real liquidity`):f<9e3&&(v=m.CAUTION,E=`round trip returns ${(f/100).toFixed(2)}% -- transfer tax or thin liquidity at this size`),{chainId:e,venue:"uniswap-v3",token:o,base:u,verdict:v,reason:E,amountIn:String(s),bought:i.best.amountOut.toString(),returned:h.toString(),retentionBps:f,buyFee:i.best.fee,sellFee:p.best.fee,evidence:b.LIVE,note:"Quote-level round trip. It does not prove transfer hooks absent at execution time."}},async prepareUnsignedTx({tokenIn:o,tokenOut:s,amountIn:c,recipient:d,slippageBps:l=50,fee:u},i={}){let p=ce(i.scanner,"router");if(!p)throw new Error(`chain ${e} has no verified V3 router; preparing a swap stays fail-closed. Add a venue with recorded provenance first (see docs/adding-a-chain.md).`);if(!Te.test(d||""))throw new Error("prepareUnsignedTx requires a valid recipient address");let h=await this.quote({tokenIn:o,tokenOut:s,amountIn:c},i);if(h.evidence!==b.LIVE)throw new Error(`cannot prepare without a live quote (${h.evidence}: ${h.reason??"no reason given"})`);let f=u??h.fee,v=gt(h.amountOut,l);if(v<=0n)throw new Error("computed minOut is zero -- refusing to prepare");let E=!!(i.useNative||h.useNative)&&n&&String(o).toLowerCase()===String(n).toLowerCase(),C=`0x${Ue.exactInputSingle}`+M(o)+M(s)+q(f)+M(d)+q(c)+q(v)+q(0);return{unsigned:!0,signedBy:"user-wallet",chainId:e,venue:"uniswap-v3",tx:{to:p,data:C,value:E?String(c):"0x0"},guard:{quotedOut:h.amountOut,minOut:v.toString(),slippageBps:l,maxSlippageBps:ue,fee:f},requires:E?[]:[{step:"approve",token:o,spender:p,amount:String(c)}],note:"UNSIGNED. Re-verify the guard against a fresh quote immediately before signing -- a quote-time minimum is not a minimum at broadcast time."}}}}var G={decimals:"0x313ce567",symbol:"0x95d89b41",name:"0x06fdde03",totalSupply:"0x18160ddd",owner:"0x8da5cb5b"};function _e(t){if(!t||t==="0x")return null;try{return BigInt(t)}catch{return null}}function Le(t){if(!t||t==="0x")return null;let e=t.slice(2);if(e.length>=128){let r=Number(BigInt(`0x${e.slice(64,128)}`));if(r>0&&r<=256&&e.length>=128+r*2){let a=e.slice(128,128+r*2),o=Buffer.from(a,"hex").toString("utf8").replace(/\0+$/,"");if(o)return o}}return Buffer.from(e.slice(0,64),"hex").toString("utf8").replace(/\0+$/,"")||null}function yt(t){let{chainId:e}=t;async function n(r,a,o){return k(e,"eth_call",[{to:r,data:a},"latest"],o)}return{async blockNumber(r={}){let a=await Se(e,r);return{chainId:e,blockNumber:a?.blockNumber??a,evidence:b.LIVE}},async nativeBalance(r,a={}){let o=await Ie(e,r,a);return{chainId:e,address:r,wei:o?.wei??o?.balance??null,symbol:t.nativeCurrency?.symbol??null,decimals:t.nativeCurrency?.decimals??18,evidence:b.LIVE}},async tokenBalance({token:r,owner:a},o={}){let s=await xe({chainId:e,token:r,owner:a},o);return{chainId:e,token:r,owner:a,raw:s?.balance??s,evidence:b.LIVE}},async resolveToken(r,a={}){if(!/^0x[0-9a-fA-F]{40}$/.test(r||""))return{chainId:e,token:r,evidence:b.UNKNOWN,error:"resolveToken needs a 20-byte address; symbol lookup is a market-data concern"};let[o,s,c,d]=await Promise.all([n(r,G.decimals,a).catch(()=>null),n(r,G.symbol,a).catch(()=>null),n(r,G.name,a).catch(()=>null),n(r,G.totalSupply,a).catch(()=>null)]),l=_e(o?.result??o),u=l!==null||s?.result||c?.result;return{chainId:e,address:r,decimals:l===null?null:Number(l),symbol:Le(s?.result??s),name:Le(c?.result??c),totalSupply:(_e(d?.result??d)??null)?.toString()??null,evidence:u?b.LIVE:b.UNKNOWN,warning:u?void 0:"no ERC-20 metadata returned -- may not be a token contract"}},async resolvePools(r,a={}){let o=t.dexscreenerSlug;if(!o)return{chainId:e,token:r,pools:[],evidence:b.UNAVAILABLE,reason:"no dexscreenerSlug configured for this chain; pool discovery is unavailable rather than guessed"};let s=await Ce(r,a).catch(()=>null),d=(s?.pairs||s?.data?.pairs||[]).filter(l=>String(l.chainId).toLowerCase()===String(o).toLowerCase()).map(l=>({pair:l.pairAddress,dex:l.dexId,base:l.baseToken?.address,quote:l.quoteToken?.address,liquidityUsd:l.liquidity?.usd??null,priceUsd:l.priceUsd??null,volume24hUsd:l.volume?.h24??null,createdAt:l.pairCreatedAt??null})).sort((l,u)=>(u.liquidityUsd??0)-(l.liquidityUsd??0));return{chainId:e,token:r,pools:d,evidence:d.length?b.LIVE:b.UNKNOWN}},async scanBlocks({fromBlock:r,toBlock:a,address:o,topics:s,chunkSize:c=2e3}={},d={}){if(!Number.isInteger(r)||!Number.isInteger(a))throw new Error("scanBlocks requires integer fromBlock and toBlock");if(a<r)throw new Error("toBlock must be >= fromBlock");let l=[],u=[];for(let i=r;i<=a;i+=c){let p=Math.min(i+c-1,a);u.push([i,p])}for(let[i,p]of u){let h={fromBlock:`0x${i.toString(16)}`,toBlock:`0x${p.toString(16)}`};o&&(h.address=o),s&&(h.topics=s);let f=await k(e,"eth_getLogs",[h],d).catch(v=>({error:String(v?.message||v)}));if(f?.error)return{chainId:e,fromBlock:r,toBlock:a,logs:l,complete:!1,failedAt:[i,p],error:f.error,evidence:b.UNKNOWN};for(let v of f?.result??f??[])l.push(v)}return{chainId:e,fromBlock:r,toBlock:a,logs:l,complete:!0,chunks:u.length,evidence:b.LIVE}},async scoreRisk(r,a={}){let o=[],s=m.PASS,c=u=>{let i={[m.PASS]:0,[m.CAUTION]:1,[m.UNKNOWN]:2,[m.FAIL]:3};i[u]>i[s]&&(s=u)},d=await this.resolveToken(r,a);d.evidence!==b.LIVE?(o.push({check:"erc20-metadata",result:m.UNKNOWN,detail:d.warning}),c(m.UNKNOWN)):o.push({check:"erc20-metadata",result:m.PASS,detail:`${d.symbol} / ${d.decimals}d`});let l=await this.resolvePools(r,a);if(l.evidence===b.UNAVAILABLE)o.push({check:"liquidity",result:m.UNKNOWN,detail:l.reason}),c(m.UNKNOWN);else if(!l.pools.length)o.push({check:"liquidity",result:m.FAIL,detail:"no pool with liquidity found"}),c(m.FAIL);else{let u=l.pools[0],i=u.liquidityUsd??0;i<5e3?(o.push({check:"liquidity",result:m.CAUTION,detail:`top pool only $${i}`}),c(m.CAUTION)):o.push({check:"liquidity",result:m.PASS,detail:`$${i} on ${u.dex}`}),u.createdAt&&Date.now()-u.createdAt<24*3600*1e3&&(o.push({check:"age",result:m.CAUTION,detail:"pool under 24h old"}),c(m.CAUTION))}if(typeof this.sellSimulation=="function"){let u=await this.sellSimulation({token:r,amountIn:(10n**16n).toString()},a).catch(i=>({verdict:m.UNKNOWN,reason:String(i?.message||i)}));o.push({check:"sellability",result:u.verdict,detail:u.retentionBps!=null?`round trip returns ${(u.retentionBps/100).toFixed(2)}% -- ${u.reason}`:u.reason}),c(u.verdict)}else o.push({check:"sellability",result:m.UNKNOWN,detail:"no verified router on this chain, so a round-trip sell simulation cannot run. Treat as unproven -- a buy path is not an exit path."}),c(m.UNKNOWN);return{chainId:e,token:r,verdict:s,checks:o,note:"Structural checks only. UNKNOWN is not PASS. A token is not tradeable until a sell simulation succeeds."}}}}function qe(t){let n={...yt(t)},r=new Set((t.venues||[]).map(o=>o.kind));t.venueKind==="uniswap-v3"&&r.has("quoter")&&r.has("router")?Object.assign(n,Re({chainId:t.chainId,wrappedNative:t.wrappedNative})):t.venueKind==="uniswap-v2"&&r.has("router")&&Object.assign(n,ke({chainId:t.chainId,wrappedNative:t.wrappedNative}));let a={};for(let[o,s]of Object.entries(n))a[o]=s.bind(n);return{key:t.key,chainId:t.chainId,name:t.name,rpcEnv:t.rpcEnv,nativeCurrency:t.nativeCurrency,explorer:t.explorer,venues:t.venues||[],capabilities:a}}var wt=Object.freeze([{key:"ethereum",chainId:1,name:"Ethereum",rpcEnv:["ETH_RPC_URL","ETHEREUM_RPC_URL","MAINNET_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://etherscan.io",dexscreenerSlug:"ethereum",venueKind:"uniswap-v3",wrappedNative:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDC fee 500 quoted 1908.71 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:1}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:1}}]},{key:"optimism",chainId:10,name:"OP Mainnet",rpcEnv:["OPTIMISM_RPC_URL","OP_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://optimistic.etherscan.io",dexscreenerSlug:"optimism",venueKind:"uniswap-v3",wrappedNative:"0x4200000000000000000000000000000000000006",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDC fee 500 quoted 1905.23 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:10}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:10}}]},{key:"bsc",chainId:56,name:"BNB Smart Chain",rpcEnv:["BSC_RPC_URL","BNB_RPC_URL"],nativeCurrency:{symbol:"BNB",decimals:18},explorer:"https://bscscan.com",dexscreenerSlug:"bsc",venueKind:"uniswap-v3",wrappedNative:"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",venues:[{kind:"quoter",address:"0x78D78E420Da98ad378D7799bE8f4AF69033EB077",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WBNB->USDC fee 500 quoted 413.86 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:56}},{kind:"router",address:"0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:56}}]},{key:"polygon",chainId:137,name:"Polygon",rpcEnv:["POLYGON_RPC_URL","POLYGON_RPC"],nativeCurrency:{symbol:"POL",decimals:18},explorer:"https://polygonscan.com",dexscreenerSlug:"polygon",venueKind:"uniswap-v3",wrappedNative:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WMATIC->USDC fee 500 quoted 0.0720 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:137}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:137}}]},{key:"stable",chainId:988,name:"Stable Mainnet",rpcEnv:["STABLE_RPC_URL","STABLE_RPC"],nativeCurrency:{symbol:"USDT0",decimals:18},venueKind:"uniswap-v3",wrappedNative:"0x5d442b349590a6048Eb2dC0eC346cAA5F47A9ab5",venues:[{kind:"quoter",address:"0xb070179E7032CdA868b53e6C1742F80c9e940d1A",label:"Uniswap V3 QuoterV2 (canonical)",verified:{method:"Stable is on the OFFICIAL Uniswap v3 Deployments List (governance-recognised 2026-05-12, UAC process completed 2026-04, deployed by Protofire), so this is a canonical deployment rather than a fork. eth_getCode returned 8273 bytes, the same size as the canonical quoter on the seven already-verified chains. Functional probe on a live pool (TOAST -> USDT0, fee 10000): 100 in -> 0.000003, 1000 -> 0.000031, 10000 -> 0.000319 USDT0. Output scales monotonically with input, which is a working quoter answering, not a revert. Two of three sampled pools carry non-zero liquidity. NOTE: the pools discovered so far are thin, so real routing size is limited -- the venue is proved, deep liquidity is not.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:988}},{kind:"router",address:"0x32eaf9B5d5F2CD7361c5012890C943D7de84C22a",label:"Uniswap SwapRouter02 (canonical)",verified:{method:"eth_getCode returned 24497 bytes. Cross-checked on-chain rather than trusted from docs: router.factory() returns 0x88f0a512ef09175d456bc9547f914f48c013e4aa, the same v3 core factory that created the pools quoted above, and router.WETH9() returns the wrappedNative recorded on this chain entry. Address published in the Stable docs DEX reference and the Uniswap deployments list.",source:"docs.stable.xyz/en/reference/dexes + on-chain factory()/WETH9() round-trip",date:"2026-08-05",chainId:988}}]},{key:"hyperevm",chainId:999,name:"HyperEVM",rpcEnv:["HYPEREVM_RPC_URL","HYPER_EVM_RPC"],nativeCurrency:{symbol:"HYPE",decimals:18},dexscreenerSlug:"hyperevm",venueKind:"uniswap-v3",wrappedNative:"0x5555555555555555555555555555555555555555",venues:[{kind:"quoter",address:"0x03A918028f22D9E1473B7959C927AD7425A45C7C",label:"HyperSwap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle(1 WHYPE -> USDT0) returned live output on all four fee tiers (100: 57.3385, 500: 57.4187, 3000: 57.3237, 10000: 56.1963 USDT0). Decimals read on-chain: WHYPE 18, USDT0 6. Best tier checked against an INDEPENDENT control the same minute -- Hyperliquid allMids put HYPE at 57.3205, so the pool is 0.171% from the perp mid, which is the right shape for fee plus impact rather than a wrong contract or a decimals bug.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:999}},{kind:"router",address:"0x4E2960a8cd19B467b82d26D83fAcb0fAE26b094D",label:"HyperSwap V3 SwapRouter",verified:{method:"eth_getCode returned 12070 bytes, and it is the router paired with the quoter proved above -- the same pair already shipped in UNI_V3_VENUES[999].hyperswap, which is the map the quote/prepare path actually routes through.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:999}}]},{key:"abstract",chainId:2741,name:"Abstract",rpcEnv:["ABSTRACT_RPC_URL","ABS_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},venueKind:"uniswap-v3",wrappedNative:"0x3439153EB7AF838Ad19d56E1571FBD09333C2809",venues:[{kind:"quoter",address:"0x728BD3eC25D5EDBafebB84F3d67367Cd9EBC7693",label:"Uniswap V3 QuoterV2 (Abstract deployment)",verified:{method:"Abstract is a ZK-stack chain, so CREATE2 addresses differ and the canonical Uniswap addresses are NOT valid here -- probing them returns codesize 0, which is what previously made this chain look like it had no V3 at all. Found the real deployment from live traffic instead: scanned recent Swap(...) logs, took the busiest pool, read pool.factory() = 0xa1160e73b63f322ae88cc2d8e700833e71d0b2a1, then enumerated that factory's deployer (0xf3d63166F0Ca56C3c1A3508FcE03Ff0Cf3Fb691e) and probed each of its 56 contracts with a real quoteExactInputSingle call. Exactly one answered: 1 WETH -> 1846.475731 USDC.e at fee 500. Independent sanity check: the pool's own slot0() spot price is 1873.11 USDC.e per WETH, so the quoter sits ~1.4% below spot, the right shape for fee plus price impact on this size.",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-08-05",chainId:2741}},{kind:"router",address:"0x7712FA47387542819d4E35A23f8116C90C18767C",label:"Uniswap SwapRouter02 (Abstract deployment)",verified:{method:"eth_getCode returned 167392 bytes and the runtime contains the exactInputSingle selector. router.factory() matches the factory proved above and router.WETH9() matches the wrappedNative on this entry. Chosen over its byte-identical twin (0xfD6257F4...) because this is the address real users actually route through: it appeared as tx.to on live swaps against the WETH/USDC.e pool.",source:"on-chain factory()/WETH9() round-trip + live swap tx.to sampling",date:"2026-08-05",chainId:2741}}]},{key:"robinhood",chainId:4663,name:"Robinhood Chain",rpcEnv:["RH_CHAIN_RPC","ROBINHOOD_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},dexscreenerSlug:"robinhood",venueKind:"uniswap-v3",wrappedNative:"0x0bd7d308f8e1639fab988df18a8011f41eacad73",venues:[{kind:"quoter",address:"0x33e885ed0ec9bf04ecfb19341582aadcb4c8a9e7",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDG fee 100 quoted 1866.58 USDG, and USDG->CASHCAT fee 10000 quoted a live amount). A contract that correctly prices known pairs IS a working V3 quoter",source:"live eth_call against rpc.mainnet.chain.robinhood.com",date:"2026-07-31",chainId:4663}},{kind:"router",address:"0xcaf681a66d020601342297493863e78c959e5cb2",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode (24497 bytes) on this chain and the paired quoter at the same deployment passed a live functional quote",source:"live eth_getCode against rpc.mainnet.chain.robinhood.com",date:"2026-07-31",chainId:4663}},{kind:"factory",address:"0x1f7d7550b1b028f7571e69a784071f0205fd2efa",label:"Uniswap V3 Factory",verified:{method:"eth_getCode returned real bytecode (24535 bytes) and a PoolCreated log scan over this factory returned 76 pools in ~9000 recent blocks",source:"live eth_getLogs against rpc.mainnet.chain.robinhood.com",date:"2026-07-31",chainId:4663}}]},{key:"base",chainId:8453,name:"Base",rpcEnv:["BASE_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://basescan.org",dexscreenerSlug:"base",venueKind:"uniswap-v3",wrappedNative:"0x4200000000000000000000000000000000000006",venues:[{kind:"quoter",address:"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",label:"Uniswap V3 QuoterV2 (Base)",verified:{method:"functional probe: quoteExactInputSingle returned WETH->USDC at fee 500 = 1908.44 USDC, a live sane price. The canonical mainnet quoter address also has bytecode on Base but does NOT price this pair, which is exactly the false positive a codesize-only check accepts",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:8453}},{kind:"router",address:"0x2626664c2603336E57B271c5C0b26F421741e481",label:"Uniswap V3 SwapRouter02 (Base)",verified:{method:"eth_getCode returned real bytecode and the paired Base quoter passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:8453}},{kind:"router-v2",address:"0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",label:"Uniswap V2 Router02 (Base)",verified:{method:"eth_getCode returned 17891 bytes; live getAmountsOut on WETH->USDC round-tripped to 98.75% (2x0.30% fee + impact)",source:"https://docs.uniswap.org/contracts/v2/reference/smart-contracts/v2-deployments",date:"2026-07-30",chainId:8453}}]},{key:"arbitrum",chainId:42161,name:"Arbitrum One",rpcEnv:["ARBITRUM_RPC_URL","ARB_RPC_URL"],nativeCurrency:{symbol:"ETH",decimals:18},explorer:"https://arbiscan.io",dexscreenerSlug:"arbitrum",venueKind:"uniswap-v3",wrappedNative:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",venues:[{kind:"quoter",address:"0x61fFE014bA17989E743c5F6cB21bF9697530B21e",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WETH->USDC fee 500 quoted 1908.72 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:42161}},{kind:"router",address:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:42161}}]},{key:"avalanche",chainId:43114,name:"Avalanche C-Chain",rpcEnv:["AVALANCHE_RPC_URL","AVAX_RPC_URL"],nativeCurrency:{symbol:"AVAX",decimals:18},explorer:"https://snowtrace.io",dexscreenerSlug:"avalanche",venueKind:"uniswap-v3",wrappedNative:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",venues:[{kind:"quoter",address:"0xbe0F5544EC67e9B3b2D979aaA43f18Fd87E6257F",label:"Uniswap V3 QuoterV2",verified:{method:"functional probe, not a codesize check: quoteExactInputSingle returned a live sane price (WAVAX->USDC fee 500 quoted 6.48 USDC). A contract that correctly prices a known pair IS a working V3 quoter",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:43114}},{kind:"router",address:"0xbb00FF08d01D300023C629E8fFfFcb65A5a578cE",label:"Uniswap V3 SwapRouter02",verified:{method:"eth_getCode returned real bytecode on this chain and the paired quoter at the same deployment passed a live functional quote",source:"scripts/verify-v3-venues.mjs (re-runnable)",date:"2026-07-30",chainId:43114}}]}]);function $e(){return wt.map(t=>Ae(qe(t)))}$e();var[Be,...Pe]=process.argv.slice(2),Y=Pe.includes("--json"),w=Pe.filter(t=>t!=="--json");function P(t){t||U("missing <chain>");let e=oe(Number(t));if(e)return e;let n=z().find(r=>r.key===String(t).toLowerCase());if(n)return n;U(`unknown chain "${t}". Known: ${z().map(r=>`${r.key}(${r.chainId})`).join(", ")}`)}function U(t){console.error(`error: ${t}`),process.exit(1)}function $(t){process.stdout.write(`${JSON.stringify(t,null,2)}
6
6
  `)}function Et(t,e){let n=String(e?.message||e);return/rpc|fetch|ECONN|timeout|provider/i.test(n)?`${n}
7
7
 
8
8
  This chain reads its RPC from: ${t.rpcEnv.join(" or ")}