@latticexyz/entrykit 2.2.17-923ab7f680d27d21d0c6daa84df58977b680b7f3 → 2.2.17-94d82cfafbdbee448884643681b0b8db53eedfda

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.
@@ -1392,7 +1392,7 @@ video {
1392
1392
  --tw-text-opacity: 1;
1393
1393
  color: rgb(255 255 255 / var(--tw-text-opacity));
1394
1394
  }
1395
- `;import{useResizeObserver as tr}from"usehooks-ts";import{mergeRefs as rr}from"react-merge-refs";import{createContext as Vt,useContext as Wt}from"react";import{jsx as _t}from"react/jsx-runtime";var Ce=Vt(null);function ke({frame:e,children:t}){if(Wt(Ce))throw new Error("`FrameProvider` can only be used once.");return _t(Ce.Provider,{value:{frame:e},children:t})}import{useMediaQuery as $t}from"usehooks-ts";import"@rainbow-me/rainbowkit/styles.css";import{createContext as Yt,useContext as Ne}from"react";import{RainbowKitProvider as Xt,lightTheme as Se,midnightTheme as Pe}from"@rainbow-me/rainbowkit";import{useChains as jt}from"wagmi";import{jsx as Ae}from"react/jsx-runtime";var ne=Yt(null);function Ee({config:e,children:t}){if(Ne(ne))throw new Error("`EntryKitProvider` can only be used once.");let n=jt().find(({id:a})=>a===e.chainId);if(!n)throw new Error(`Could not find configured chain for chain ID ${e.chainId}.`);return Ae(Xt,{initialChain:0,appInfo:{appName:e.appName},theme:e.theme==="light"?Se({borderRadius:"none"}):e.theme==="dark"?Pe({borderRadius:"none"}):{lightMode:Se({borderRadius:"none"}),darkMode:Pe({borderRadius:"none"})},children:Ae(ne.Provider,{value:{...e,chain:n},children:t})})}function l(){let e=Ne(ne);if(!e)throw new Error("`useEntryKitConfig` can only be used within a `EntryKitProvider`.");return e}function Re(){let{theme:e}=l(),t=$t("(prefers-color-scheme: dark)");return e??(t?"dark":"light")}import{jsx as z,jsxs as nr}from"react/jsx-runtime";function or({onSize:e,...t}){let r=Me(null);return tr({ref:r,onResize:e}),z("div",{ref:r,...t,style:{...t.style,display:"inline-grid"}})}var G=Zt(function({mode:t,children:r},o){let n=Me(null),[a,i]=Te(!1),s=a?n.current:null,[d,f]=Te({width:void 0,height:void 0}),m=s?.contentDocument,c=Re();Jt(()=>{m&&m.body.setAttribute("data-theme",c)},[m,c]);let p=t==="modal"?{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"2147483646"}:d.width&&d.height?{all:"unset",display:"inline-grid",width:`${d.width}px`,height:`${d.height}px`}:{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",opacity:0,pointerEvents:"none"};return z("iframe",{ref:rr([o,n]),style:p,onLoad:()=>i(!0),srcDoc:"<!doctype html><title>\u2026</title>",children:m?er.createPortal(nr(ke,{frame:s,children:[z("div",{children:t==="modal"?r:z(or,{onSize:f,children:r})}),z("style",{dangerouslySetInnerHTML:{__html:ve}})]}),m.body):null})});import{twMerge as Ie}from"tailwind-merge";import{jsx as R,jsxs as lr}from"react/jsx-runtime";function He({open:e,onOpenChange:t,children:r}){return R(ar,{open:e,onOpenChange:t,children:R(ir,{children:lr(G,{mode:"modal",children:[R("div",{className:Ie("fixed inset-0","bg-neutral-800/85","animate-in animate-duration-300 fade-in")}),R("div",{className:Ie("fixed inset-0","grid items-end sm:items-center","animate-in animate-duration-300 fade-in slide-in-from-bottom-16"),children:R("div",{children:R(sr,{className:"outline-none w-full max-w-[26rem] mx-auto","aria-describedby":void 0,onOpenAutoFocus:o=>{o.preventDefault()},children:r})})})]})})})}import{useCallback as ae,useMemo as cr}from"react";import{useStore as dr}from"zustand";import{createStore as pr}from"zustand/vanilla";var Q=pr(()=>({open:!1}));function C(){let e=dr(Q,n=>n.open),t=ae(()=>{Q.setState({open:!0})},[]),r=ae(()=>{Q.setState({open:!1})},[]),o=ae(n=>{Q.setState({open:n})},[]);return cr(()=>({accountModalOpen:e,openAccountModal:t,closeAccountModal:r,toggleAccountModal:o}),[e,t,r,o])}import{twMerge as Ht}from"tailwind-merge";import{useAccount as An,useConnectorClient as Nn}from"wagmi";import{useAccount as xr}from"wagmi";import{twMerge as B}from"tailwind-merge";import{twMerge as mr}from"tailwind-merge";import{jsx as Oe,jsxs as ur}from"react/jsx-runtime";function w({className:e,...t}){return ur("svg",{className:mr("-my-[0.125em] h-[1.25em] w-[1.25em] animate-spin",e),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",...t,children:[Oe("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),Oe("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}import{jsx as q,jsxs as gr}from"react/jsx-runtime";var fr=({variant:e="secondary"}={})=>B("group/button self-center leading-none outline-none border-4 border-transparent","transition hover:brightness-125 active:brightness-150","focus:border-orange-500","aria-disabled:pointer-events-none aria-busy:pointer-events-none","aria-disabled:opacity-50","p-[.75em] font-medium",{primary:B("bg-orange-600 text-white focus:border-yellow-400"),secondary:B("bg-neutral-700 text-white focus:border-orange-500"),tertiary:B("bg-neutral-800 text-white focus:border-orange-500")}[e]),y=({pending:e,variant:t,type:r,className:o,children:n,disabled:a,...i})=>q("button",{type:r||"button",className:B(fr({variant:t,pending:e}),o),"aria-busy":e,"aria-disabled":a,disabled:a||e,...i,children:gr("span",{className:"grid grid-cols-[1fr_auto_1fr] gap-2",children:[q("span",{className:"flex items-center justify-end text-[.75em]",children:q("span",{className:"transition opacity-0 translate-x-2 group-aria-busy/button:opacity-100 group-aria-busy/button:translate-x-0 duration-100 group-aria-busy/button:duration-300",children:q(w,{})})}),q("span",{children:n})]})});import{useConnectModal as vr}from"@rainbow-me/rainbowkit";import{twMerge as hr}from"tailwind-merge";import{jsx as ie,jsxs as yr}from"react/jsx-runtime";function P({className:e,...t}){return yr("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 8 8",fill:"currentColor",shapeRendering:"crispEdges",className:hr("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...t,children:[ie("path",{d:"M0 0h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm2-1h1v1H7zm0 1h1v1H7zM6 7h1v1H6zm1-2h1v1H7zm0-1h1v1H7zm0-1h1v1H7z"}),ie("path",{d:"M2 2h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm1-3h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm0 1h1v1H5zm0 1h1v1H5zm0 1h1v1H5zM4 5h1v1H4zM3 5h1v1H3z",opacity:".5"}),ie("path",{d:"M7 2h1v1H7zm0-1h1v1H7zM1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm1 0h1v1H6zm1 0h1v1H7z"})]})}import{useQuery as wr}from"@tanstack/react-query";function V(e){return wr({enabled:!!e,retry:!1,retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,queryKey:["preloadImage",e],queryFn:()=>new Promise((t,r)=>{if(!e)throw new Error("usePreloadImage: Must provide `url` to preload image.");let o=new Image;o.onload=()=>t(o),o.onerror=()=>r(new Error(`usePreloadImage: Could not load image.
1395
+ `;import{useResizeObserver as tr}from"usehooks-ts";import{mergeRefs as rr}from"react-merge-refs";import{createContext as Vt,useContext as Wt}from"react";import{jsx as _t}from"react/jsx-runtime";var Ce=Vt(null);function ke({frame:e,children:t}){if(Wt(Ce))throw new Error("`FrameProvider` can only be used once.");return _t(Ce.Provider,{value:{frame:e},children:t})}import{useMediaQuery as $t}from"usehooks-ts";import"@rainbow-me/rainbowkit/styles.css";import{createContext as Yt,useContext as Ne}from"react";import{RainbowKitProvider as Xt,lightTheme as Se,midnightTheme as Pe}from"@rainbow-me/rainbowkit";import{useChains as jt}from"wagmi";import{jsx as Ae}from"react/jsx-runtime";var ne=Yt(null);function Ee({config:e,children:t}){if(Ne(ne))throw new Error("`EntryKitProvider` can only be used once.");let n=jt().find(({id:a})=>a===e.chainId);if(!n)throw new Error(`Could not find configured chain for chain ID ${e.chainId}.`);return Ae(Xt,{initialChain:0,appInfo:{appName:e.appName},theme:e.theme==="light"?Se({borderRadius:"none"}):e.theme==="dark"?Pe({borderRadius:"none"}):{lightMode:Se({borderRadius:"none"}),darkMode:Pe({borderRadius:"none"})},children:Ae(ne.Provider,{value:{...e,chain:n},children:t})})}function l(){let e=Ne(ne);if(!e)throw new Error("`useEntryKitConfig` can only be used within a `EntryKitProvider`.");return e}function Re(){let{theme:e}=l(),t=$t("(prefers-color-scheme: dark)");return e??(t?"dark":"light")}import{jsx as z,jsxs as nr}from"react/jsx-runtime";function or({onSize:e,...t}){let r=Me(null);return tr({ref:r,onResize:e}),z("div",{ref:r,...t,style:{...t.style,display:"inline-grid"}})}var G=Zt(function({mode:t,children:r},o){let n=Me(null),[a,i]=Te(!1),s=a?n.current:null,[d,f]=Te({width:void 0,height:void 0}),m=s?.contentDocument,c=Re();Jt(()=>{m&&m.body.setAttribute("data-theme",c)},[m,c]);let p=t==="modal"?{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"2147483646"}:d.width&&d.height?{all:"unset",display:"inline-grid",width:`${d.width}px`,height:`${d.height}px`}:{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",opacity:0,pointerEvents:"none"};return z("iframe",{ref:rr([o,n]),style:p,onLoad:()=>i(!0),srcDoc:"<!doctype html><title>\u2026</title>",children:m?er.createPortal(nr(ke,{frame:s,children:[z("div",{children:t==="modal"?r:z(or,{onSize:f,children:r})}),z("style",{dangerouslySetInnerHTML:{__html:ve}})]}),m.body):null})});import{twMerge as Ie}from"tailwind-merge";import{jsx as R,jsxs as lr}from"react/jsx-runtime";function He({open:e,onOpenChange:t,children:r}){return R(ar,{open:e,onOpenChange:t,children:R(ir,{children:lr(G,{mode:"modal",children:[R("div",{className:Ie("fixed inset-0","bg-neutral-800/85","animate-in animate-duration-300 fade-in")}),R("div",{className:Ie("fixed inset-0","grid items-end sm:items-center","animate-in animate-duration-300 fade-in slide-in-from-bottom-16"),children:R("div",{children:R(sr,{className:"outline-none w-full max-w-[26rem] mx-auto","aria-describedby":void 0,onOpenAutoFocus:o=>{o.preventDefault()},children:r})})})]})})})}import{useCallback as ae,useMemo as cr}from"react";import{useStore as dr}from"zustand";import{createStore as pr}from"zustand/vanilla";var Q=pr(()=>({open:!1}));function C(){let e=dr(Q,n=>n.open),t=ae(()=>{Q.setState({open:!0})},[]),r=ae(()=>{Q.setState({open:!1})},[]),o=ae(n=>{Q.setState({open:n})},[]);return cr(()=>({accountModalOpen:e,openAccountModal:t,closeAccountModal:r,toggleAccountModal:o}),[e,t,r,o])}import{twMerge as Ht}from"tailwind-merge";import{useAccount as Nn,useConnectorClient as En}from"wagmi";import{useAccount as xr}from"wagmi";import{twMerge as B}from"tailwind-merge";import{twMerge as mr}from"tailwind-merge";import{jsx as Oe,jsxs as ur}from"react/jsx-runtime";function w({className:e,...t}){return ur("svg",{className:mr("-my-[0.125em] h-[1.25em] w-[1.25em] animate-spin",e),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",...t,children:[Oe("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),Oe("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}import{jsx as q,jsxs as gr}from"react/jsx-runtime";var fr=({variant:e="secondary"}={})=>B("group/button self-center leading-none outline-none border-4 border-transparent","transition hover:brightness-125 active:brightness-150","focus:border-orange-500","aria-disabled:pointer-events-none aria-busy:pointer-events-none","aria-disabled:opacity-50","p-[.75em] font-medium",{primary:B("bg-orange-600 text-white focus:border-yellow-400"),secondary:B("bg-neutral-700 text-white focus:border-orange-500"),tertiary:B("bg-neutral-800 text-white focus:border-orange-500")}[e]),y=({pending:e,variant:t,type:r,className:o,children:n,disabled:a,...i})=>q("button",{type:r||"button",className:B(fr({variant:t,pending:e}),o),"aria-busy":e,"aria-disabled":a,disabled:a||e,...i,children:gr("span",{className:"grid grid-cols-[1fr_auto_1fr] gap-2",children:[q("span",{className:"flex items-center justify-end text-[.75em]",children:q("span",{className:"transition opacity-0 translate-x-2 group-aria-busy/button:opacity-100 group-aria-busy/button:translate-x-0 duration-100 group-aria-busy/button:duration-300",children:q(w,{})})}),q("span",{children:n})]})});import{useConnectModal as vr}from"@rainbow-me/rainbowkit";import{twMerge as hr}from"tailwind-merge";import{jsx as ie,jsxs as yr}from"react/jsx-runtime";function P({className:e,...t}){return yr("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 8 8",fill:"currentColor",shapeRendering:"crispEdges",className:hr("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...t,children:[ie("path",{d:"M0 0h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm2-1h1v1H7zm0 1h1v1H7zM6 7h1v1H6zm1-2h1v1H7zm0-1h1v1H7zm0-1h1v1H7z"}),ie("path",{d:"M2 2h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm1-3h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm0 1h1v1H5zm0 1h1v1H5zm0 1h1v1H5zM4 5h1v1H4zM3 5h1v1H3z",opacity:".5"}),ie("path",{d:"M7 2h1v1H7zm0-1h1v1H7zM1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm1 0h1v1H6zm1 0h1v1H7z"})]})}import{useQuery as wr}from"@tanstack/react-query";function V(e){return wr({enabled:!!e,retry:!1,retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,queryKey:["preloadImage",e],queryFn:()=>new Promise((t,r)=>{if(!e)throw new Error("usePreloadImage: Must provide `url` to preload image.");let o=new Image;o.onload=()=>t(o),o.onerror=()=>r(new Error(`usePreloadImage: Could not load image.
1396
1396
 
1397
- URL: ${e}`)),o.src=e})})}import{jsx as W,jsxs as br}from"react/jsx-runtime";function ze(){let{appName:e,appIcon:t}=l(),{data:r,isLoading:o}=V(t);return br("div",{className:"flex-grow flex flex-col items-center justify-center gap-2",children:[W("div",{className:"w-16 h-16 m-2",children:o?null:r?W("img",{src:t,className:"w-full h-full object-cover"}):W(P,{className:"w-full h-full text-orange-500 dark:bg-neutral-800"})}),W("div",{className:"text-2xl text-white text-center",children:e})]})}import{twMerge as Cr}from"tailwind-merge";import{useEffect as kr,useState as Sr}from"react";import{jsx as _,jsxs as Pr}from"react/jsx-runtime";function qe(){let e=xr(),{openConnectModal:t,connectModalOpen:r}=vr(),[o,n]=Sr(!1);return kr(()=>{!r&&!o&&(t?.(),n(!0))},[r,o,t]),Pr("div",{className:Cr("flex flex-col gap-6 p-6","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:[_("div",{className:"p-4",children:_(ze,{})}),_("div",{className:"self-center flex flex-col gap-2 w-60",children:_(y,{variant:"secondary",className:"self-auto flex justify-center",disabled:e.status==="connecting",onClick:t,autoFocus:!0,children:"Connect wallet"},"create")})]})}import{useEffect as Cn,useMemo as kn,useRef as Sn,useState as Pn}from"react";import{twMerge as ye}from"tailwind-merge";import{parseEther as Ar}from"viem";var A=Ar("0.01");import{useClient as zr}from"wagmi";import{queryOptions as qr,useQuery as Br}from"@tanstack/react-query";import{numberToHex as Tr}from"viem";import{defineStore as Nr}from"@latticexyz/store";import{parseAbi as Er}from"viem";var se=Er(["error SpenderSystem_AlreadyRegistered(address spender, address user)","error SpenderSystem_HasOwnBalance(address spender)","function registerSpender(address spender)"]),Rr=Nr({namespaces:{root:{namespace:"",tables:{Allowance:{schema:{user:"address",allowance:"uint256"},key:["user"]},Grantor:{schema:{grantor:"address",allowance:"uint256"},key:["grantor"]},PassHolder:{schema:{user:"address",passId:"bytes32",lastRenewed:"uint256",lastClaimed:"uint256"},key:["user","passId"]},PassConfig:{schema:{passId:"bytes32",claimAmount:"uint256",claimInterval:"uint256",validityPeriod:"uint256",grantor:"address"},key:["passId"]},Spender:{schema:{spender:"address",user:"address"},key:["spender"]},SystemConfig:{schema:{entryPoint:"address"},key:[]}}}}}),T=Rr.namespaces.root.tables;import{getRecord as Mr,getStaticDataLocation as Ir}from"@latticexyz/store/internal";import{getKeyTuple as Hr}from"@latticexyz/protocol-parser/internal";import{setStorageAt as Or}from"viem/actions";function h(e){let t=e.contracts??{};if("quarryPaymaster"in t&&t.quarryPaymaster!=null&&"address"in t.quarryPaymaster)return{type:"quarry",address:t.quarryPaymaster.address};if("paymaster"in t&&t.paymaster!=null&&"address"in t.paymaster)return{type:"simple",address:t.paymaster.address}}async function Be({client:e,userAddress:t}){let r=h(e.chain);return r?.type!=="quarry"?null:(await Mr(e,{address:r.address,table:T.Allowance,key:{user:t},blockTag:"pending"})).allowance}async function Le({client:e,userAddress:t,allowance:r}){let o=h(e.chain);if(o?.type!=="quarry")return;let n=Ir(T.Allowance.tableId,Hr(T.Allowance,{user:t}));await Or(e.extend(()=>({mode:"anvil"})),{address:o.address,index:n,value:Tr(r,{size:32})})}function le({client:e,userAddress:t}){let r=["getAllowance",e?.chain.id,t];return qr(e&&t?{queryKey:r,queryFn:()=>Be({client:e,userAddress:t})}:{queryKey:r,enabled:!1})}function Fe(e){let{chainId:t}=l(),r=zr({chainId:t});return Br(le({client:r,userAddress:e}))}import{useClient as Li}from"wagmi";import{queryOptions as Fr,useQuery as Ki}from"@tanstack/react-query";import{getRecord as Lr}from"@latticexyz/store/internal";async function Ke({client:e,userAddress:t,sessionAddress:r}){let o=h(e.chain);return o?.type!=="quarry"?null:(await Lr(e,{address:o.address,table:T.Spender,key:{spender:r},blockTag:"pending"})).user.toLowerCase()===t.toLowerCase()}function Ue({client:e,userAddress:t,sessionAddress:r}){let o=["getSpender",e?.chain.id,t,r];return Fr(e&&t&&r?{queryKey:o,queryFn:()=>Ke({client:e,userAddress:t,sessionAddress:r})}:{queryKey:o,enabled:!1})}import{useClient as ns}from"wagmi";import{queryOptions as Qr,useQuery as is}from"@tanstack/react-query";import{getRecord as Gr}from"@latticexyz/store/internal";import{resourceToHex as Kr}from"@latticexyz/common";import{parseAbi as Ur}from"viem";import Dr from"@latticexyz/world/mud.config";var De={pollingInterval:250},L=Kr({type:"system",namespace:"",name:"unlimited"}),Ge=Dr.namespaces.world.tables,Qe=Ur(["function registerDelegation(address delegatee, bytes32 delegationControlId, bytes initCallData)"]);async function Ve({client:e,worldAddress:t,userAddress:r,sessionAddress:o}){return(await Gr(e,{address:t,table:Ge.UserDelegationControl,key:{delegator:r,delegatee:o},blockTag:"pending"})).delegationControlId===L}function We({client:e,worldAddress:t,userAddress:r,sessionAddress:o}){let n=["getDelegation",e?.chain.id,t,r,o];return Qr(e&&r&&o?{queryKey:n,queryFn:()=>Ve({client:e,worldAddress:t,userAddress:r,sessionAddress:o})}:{queryKey:n,enabled:!1})}import{queryOptions as eo,useQuery as to,useQueryClient as ro}from"@tanstack/react-query";import{useClient as oo,useConfig as no}from"wagmi";import{useClient as $r}from"wagmi";import{queryOptions as Zr,useQuery as Jr}from"@tanstack/react-query";import{toSimpleSmartAccount as jr}from"permissionless/accounts";import{createStore as Vr}from"zustand/vanilla";import{persist as Wr}from"zustand/middleware";var F=Vr(Wr(()=>({signers:{}}),{name:"mud:entrykit",partialize:({signers:e})=>({signers:e})}));function _r(e){e.key===F.persist.getOptions().name&&F.persist.rehydrate()}window.addEventListener("storage",_r);import{generatePrivateKey as Yr,privateKeyToAccount as Xr}from"viem/accounts";function _e(e){let t=F.getState().signers[e]??(()=>{let r=Yr();return F.setState(o=>({signers:{...o.signers,[e]:r}})),r})();return Xr(t)}async function Ye({client:e,userAddress:t}){let r=_e(t);return await jr({client:e,owner:r})}function ce({client:e,userAddress:t}){let r=["getSessionAccount",e?.chain.id,t];return Zr(e&&t?{queryKey:r,queryFn:()=>Ye({client:e,userAddress:t}),staleTime:1/0}:{queryKey:r,enabled:!1})}function Xe(e){let{chainId:t}=l(),r=$r({chainId:t});return Jr(ce({userAddress:e,client:r}))}import{getBalanceQueryOptions as ao}from"wagmi/query";function io({queryClient:e,config:t,client:r,userAddress:o,worldAddress:n}){let a=["getPrerequisites",r?.chain.id,o];return eo(r&&o?{queryKey:a,queryFn:async()=>{let i=h(r.chain),{address:s}=await e.fetchQuery(ce({client:r,userAddress:o})),[d,f,m,c]=await Promise.all([i?null:e.fetchQuery(ao(t,{chainId:r.chain.id,address:s})),i?.type==="quarry"?e.fetchQuery(le({client:r,userAddress:o})):null,i?.type==="quarry"?e.fetchQuery(Ue({client:r,userAddress:o,sessionAddress:s})):null,e.fetchQuery(We({client:r,worldAddress:n,userAddress:o,sessionAddress:s}))]),p=f==null||f>=A,g=m??!0,x=d==null||d.value>=A;return{sessionAddress:s,hasAllowance:p,isSpender:g,hasGasBalance:x,hasDelegation:c,complete:p&&g&&c}}}:{queryKey:a,enabled:!1})}function M(e){let t=ro(),{chainId:r,worldAddress:o}=l(),n=no(),a=oo({chainId:r});return to(io({config:n,queryClient:t,client:a,userAddress:e,worldAddress:o}),t)}import{useDisconnect as co}from"wagmi";import{useQuery as so}from"@tanstack/react-query";function Y(e){let t=e?.toLowerCase();return so({enabled:!!t,queryKey:["ens",t],queryFn:async()=>{let r=await fetch(`https://api.ensideas.com/ens/resolve/${t}`).then(o=>o.json());return{address:r.address??void 0,name:r.name??void 0,displayName:r.displayName??void 0,avatar:r.avatar??void 0}}})}import{jsx as de,jsxs as lo}from"react/jsx-runtime";function I({hex:e}){return e.length<=10?de("span",{title:e,children:e}):lo("span",{title:e,children:[de("span",{className:"after:select-none after:content-['\u2026']",children:e.slice(0,6)}),de("span",{className:"tracking-[-1ch] text-transparent",children:e.slice(6,-4)}),e.slice(-4)]})}import{jsx as K,jsxs as pe}from"react/jsx-runtime";function je({isActive:e,isExpanded:t,userAddress:r}){let{data:o}=Y(r),{disconnect:n,isPending:a}=co(),{closeAccountModal:i}=C();return pe("div",{className:"flex flex-col gap-4",children:[pe("div",{className:"flex justify-between gap-4",children:[pe("div",{children:[K("div",{children:"Account"}),K("div",{className:"font-mono text-white",children:o?.name??K(I,{hex:r})})]}),K(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:a,onClick:()=>{i(),n()},children:"Sign out"})]}),t?K("p",{className:"text-sm",children:"Each of your onchain actions in this app is associated with your account."}):null]})}import{parseEther as uo}from"viem";import{useMutation as fo,useQueryClient as go}from"@tanstack/react-query";import{http as po}from"viem";function $e(){return({chain:e})=>{if(!e)throw new Error("No chain provided to issuer transport.");let t="quarryPassIssuer"in e.rpcUrls?e.rpcUrls.quarryPassIssuer.http[0]:void 0;if(!t)throw new Error(`No \`quarryPassIssuer\` RPC URL found for chain ${e.id}.`);return po(t)({chain:e,retryCount:0})}}import Ze from"debug";var me=Ze("mud:entrykit"),mo=Ze("mud:entrykit");me.log=console.debug.bind(console);mo.log=console.error.bind(console);var H=me.extend("quarry");async function Je({chain:e,userAddress:t}){let r=$e()({chain:e});H("Issuing gas pass to",t),await r.request({method:"quarry_issuePass",params:["0x01",t]}),H("Claiming gas allowance for",t),await r.request({method:"quarry_claimAllowance",params:["0x01",t]})}import{useClient as ho}from"wagmi";function et(){let e=go(),{chain:t}=l(),r=ho({chainId:t.id}),o=["claimGasPass",t.id];return fo({mutationKey:o,onError:n=>console.error(n),mutationFn:async n=>{if(t.id===31337){if(!r)throw new Error("No client?");await Le({client:r,userAddress:n,allowance:uo("1")})}else await Je({chain:t,userAddress:n});await Promise.all([e.invalidateQueries({queryKey:["getAllowance"]}),e.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{twMerge as yo}from"tailwind-merge";import{jsx as X,jsxs as wo}from"react/jsx-runtime";function tt({className:e,...t}){return wo("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 263 428",fill:"currentColor",className:yo("w-[0.6em] h-[1em]",e),...t,children:[X("path",{d:"M132 321V428L263 243L132 321Z"}),X("path",{d:"M0 243L132 321V428",fillOpacity:"0.5"}),X("path",{d:"M132 0V296L263 218"}),X("path",{d:"M0 218L132 296V0L0 218Z",fillOpacity:"0.5"})]})}import{formatEther as bo}from"viem";function rt(e){let t=bo(e),r=Math.floor(parseFloat(t)).toString().length;return parseFloat(t).toLocaleString("en-US",{maximumFractionDigits:Math.max(0,6-r)})}import{formatEther as xo}from"viem";import{jsx as vo,jsxs as Co}from"react/jsx-runtime";function j({wei:e}){return Co("span",{className:"inline-flex items-center gap-1",title:xo(e),children:[rt(e)," ",vo(tt,{})]})}import{useEffect as ko}from"react";import{jsx as O,jsxs as ue}from"react/jsx-runtime";function ot({isActive:e,isExpanded:t,userAddress:r}){let o=Fe(r),n=et();return ko(()=>{let a=setTimeout(()=>{e&&n.status==="idle"&&o.isSuccess&&o.data!=null&&o.data<A&&n.mutate(r)});return()=>clearTimeout(a)},[o.data,o.isSuccess,n,e,r]),ue("div",{className:"flex flex-col gap-4",children:[ue("div",{className:"flex justify-between gap-4",children:[ue("div",{children:[O("div",{children:"Allowance"}),O("div",{className:"font-mono text-white",children:o.data!=null?O(j,{wei:o.data}):O(w,{className:"text-sm"})})]}),O(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:o.status==="pending"||n.status==="pending",onClick:()=>n.mutate(r),children:"Top up"})]}),t?O("p",{className:"text-sm",children:"Your allowance is used to pay for onchain computation."}):null]})}import{encodeFunctionData as at}from"viem";import{useMutation as Oo,useQueryClient as zo}from"@tanstack/react-query";import{getAction as ge}from"viem/utils";import{sendUserOperation as qo,waitForUserOperationReceipt as Bo}from"viem/account-abstraction";import{waitForTransactionReceipt as Lo}from"viem/actions";import{useClient as Fo}from"wagmi";import{resourceToHex as it}from"@latticexyz/common";import Ko from"@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json";import{writeContract as Mo}from"viem/actions";import{getAction as Io}from"viem/utils";import{toHex as So}from"viem";import{signTypedData as Po}from"viem/actions";import{callWithSignatureTypes as Ao}from"@latticexyz/world-module-callwithsignature/internal";import{getRecord as No}from"@latticexyz/store/internal";import Eo from"@latticexyz/world-module-callwithsignature/mud.config";import{hexToResource as Ro}from"@latticexyz/common";import{getAction as To}from"viem/utils";async function nt({userClient:e,worldAddress:t,systemId:r,callData:o,nonce:n,client:a}){let i=n??(a?(await No(a,{address:t,table:Eo.tables.CallWithSignatureNonces,key:{signer:e.account.address},blockTag:"pending"})).nonce:0n),{namespace:s,name:d}=Ro(r);return await To(e,Po,"signTypedData")({account:e.account,domain:{verifyingContract:t,salt:So(e.chain.id,{size:32})},types:Ao,primaryType:"Call",message:{signer:e.account.address,systemNamespace:s,systemName:d,callData:o,nonce:i}})}import Ho from"@latticexyz/world-module-callwithsignature/out/CallWithSignatureSystem.sol/CallWithSignatureSystem.abi.json";async function fe({sessionClient:e,...t}){let r=await nt(t);return Io(e,Mo,"writeContract")({address:t.worldAddress,abi:Ho,functionName:"callWithSignature",args:[t.userClient.account.address,t.systemId,t.callData,r]})}function st({userClient:e}){let t=zo(),{chainId:r,worldAddress:o}=l(),n=Fo({chainId:r}),a=["setupSession",n?.chain.id,e.account.address];return Oo({mutationKey:a,onError:i=>console.error(i),mutationFn:async({sessionClient:i,registerSpender:s,registerDelegation:d})=>{if(!n)throw new Error("Client not ready.");let f=h(n.chain),m=i.account.address;if(console.log("setting up session"),e.account.type==="smart"){let c=[];if(s&&f?.type==="quarry"&&(console.log("registering spender"),c.push({to:f.address,abi:se,functionName:"registerSpender",args:[m]})),d&&(console.log("registering delegation"),c.push({to:o,abi:Qe,functionName:"registerDelegation",args:[m,L,"0x"]})),!c.length)return;console.log("setting up account with",c,e);let p=await ge(e,qo,"sendUserOperation")({calls:c});console.log("got user op hash",p);let g=await ge(e,Bo,"waitForUserOperationReceipt")({hash:p});console.log("got user op receipt",g),g.success||console.error("not successful?",g)}else{let c=[];if(s&&f?.type==="quarry"){console.log("registering spender");let p=await fe({client:n,userClient:e,sessionClient:i,worldAddress:f.address,systemId:it({type:"system",namespace:"",name:"SpenderSystem"}),callData:at({abi:se,functionName:"registerSpender",args:[m]})});console.log("got spender tx",p),c.push(p)}if(d){console.log("registering delegation");let p=await fe({client:n,userClient:e,sessionClient:i,worldAddress:o,systemId:it({type:"system",namespace:"",name:"Registration"}),callData:at({abi:Ko,functionName:"registerDelegation",args:[m,L,"0x"]})});console.log("got delegation tx",p),c.push(p)}if(!c.length)return;console.log("waiting for",c.length,"receipts");for(let p of c){let g=await ge(n,Lo,"waitForTransactionReceipt")({hash:p});console.log("got tx receipt",g),g.status==="reverted"&&console.error("tx reverted?",g)}}await Promise.all([t.invalidateQueries({queryKey:["getSpender"]}),t.invalidateQueries({queryKey:["getDelegation"]}),t.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{useEffect as fn}from"react";import{useClient as dn}from"wagmi";import{queryOptions as pn,useQuery as mn}from"@tanstack/react-query";import{smartAccountActions as ln}from"permissionless";import{callFrom as cn}from"@latticexyz/world/internal";import{createBundlerClient as Uo}from"viem/account-abstraction";var Do=new Set([31337,17420,17069,690]);function lt(e){let t=e.chain??e.client?.chain,r=t?h(t):void 0;return Uo({...De,paymaster:r?{getPaymasterData:async()=>({paymaster:r.address,paymasterData:"0x"})}:void 0,userOperation:{estimateFeesPerGas:t&&Do.has(t.id)?async()=>({maxFeePerGas:100000n,maxPriorityFeePerGas:0n}):void 0},...e})}import{transactionQueue as en}from"@latticexyz/common/actions";import{createClient as tn,fallback as rn,http as ht,keccak256 as on,stringToHex as nn,webSocket as an}from"viem";import{privateKeyToAccount as sn}from"viem/accounts";import{createTransport as jo,numberToHex as $o,parseEther as Zo}from"viem";import{entryPoint07Address as ft}from"viem/account-abstraction";import{formatUserOperationRequest as Go}from"viem/account-abstraction";async function ct(e){return Go({callGasLimit:20000000n,preVerificationGas:200000n,verificationGasLimit:2000000n,paymasterVerificationGasLimit:200000n,paymasterPostOpGasLimit:200000n})}import{parseEventLogs as Qo}from"viem";import{formatUserOperation as Vo,toPackedUserOperation as Wo,getUserOperationHash as _o,entryPoint07Address as dt,entryPoint07Abi as pt}from"viem/account-abstraction";import{waitForTransactionReceipt as Yo,writeContract as Xo}from"viem/actions";import{getAction as mt}from"viem/utils";async function ut({executor:e,rpcUserOp:t}){let r=Vo(t),o=Wo(r),n=_o({userOperation:r,chainId:e.chain.id,entryPointVersion:"0.7",entryPointAddress:dt}),a=await mt(e,Xo,"writeContract")({abi:pt,address:dt,functionName:"handleOps",args:[[o],e.account.address],chain:e.chain,account:e.account}),i=await mt(e,Yo,"waitForTransactionReceipt")({hash:a});return{success:Qo({logs:i.logs,abi:pt,eventName:"UserOperationEvent"})[0].args.success,userOpHash:n,receipt:i}}import{setBalance as Jo}from"viem/actions";function gt({executor:e}){return()=>{H("using a local user op executor",e.account.address),e.chain.id===31337&&(H("setting executor balance"),Jo(e.extend(()=>({mode:"anvil"})),{address:e.account.address,value:Zo("100")}));let t=new Map;return jo({key:"userOpExecutor",type:"userOpExecutor",name:"User Operation Executor Transport",request:async({method:o,params:n})=>{if(o==="eth_chainId")return $o(e.chain.id);if(o==="eth_supportedEntryPoints")return[ft];if(o==="eth_sendUserOperation"){let[a,i]=n;if(i===ft){let s=await ut({executor:e,rpcUserOp:a});return t.set(s.userOpHash,s),s.userOpHash}}if(o==="eth_getUserOperationReceipt"){let[a]=n;return t.get(a)??null}if(o==="eth_estimateUserOperationGas")return await ct(n);throw new Error("Method not implemented.")}})}}function yt(e){let t=e.rpcUrls.bundler?.http[0],r=t?ht(t):e.id===31337?gt({executor:tn({chain:e,transport:rn([an(),ht()]),account:sn(on(nn("local user op executor"))),pollingInterval:10}).extend(en())}):null;if(!r)throw new Error(`Chain ${e.id} config did not include a bundler RPC URL.`);return r}async function wt({client:e,userAddress:t,sessionAccount:r,worldAddress:o}){let n=yt(e.chain);return lt({transport:n,client:e,account:r}).extend(ln).extend(cn({worldAddress:o,delegatorAddress:t,publicClient:e})).extend(()=>({userAddress:t}))}function un({sessionAccount:e,client:t,userAddress:r,worldAddress:o}){let n=["getSessionClient",t?.uid,r,e?.address,o];return pn(t&&r&&e?{queryKey:n,queryFn:()=>wt({sessionAccount:e,client:t,userAddress:r,worldAddress:o}),staleTime:1/0}:{queryKey:n,enabled:!1})}function $(e){let{chainId:t,worldAddress:r}=l(),o=dn({chainId:t}),{data:n}=Xe(e);return mn(un({sessionAccount:n,userAddress:e,client:o,worldAddress:r}))}import{jsx as U,jsxs as he}from"react/jsx-runtime";function bt({isActive:e,isExpanded:t,userClient:r,registerSpender:o,registerDelegation:n}){let a=$(r.account.address),i=st({userClient:r}),s=!n&&!n;return fn(()=>{let d=setTimeout(()=>{e&&i.status==="idle"&&a.data&&!s&&i.mutate({sessionClient:a.data,registerSpender:o,registerDelegation:n})});return()=>clearTimeout(d)},[s,e,n,o,a,i]),he("div",{className:"flex flex-col gap-4",children:[he("div",{className:"flex justify-between gap-4",children:[he("div",{children:[U("div",{children:"Session"}),U("div",{className:"font-mono text-white",children:s?"Enabled":"Set up"})]}),s?U(y,{variant:"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,disabled:!0,children:"Enabled"}):U(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:!a.data||i.status==="pending",onClick:a.data?()=>i.mutate({sessionClient:a.data,registerSpender:o,registerDelegation:n}):void 0,children:"Enable"})]}),t?U("p",{className:"text-sm",children:"You can perform actions in this app without interruptions for approvals."}):null]})}import{useBalance as xn}from"wagmi";var xt={"1":"ethereum","10":"optimism","56":"bnb","100":"gnosis","111":"bob","137":"polygon","185":"mint","288":"boba","324":"zksync","360":"shape","480":"world-chain","690":"redstone","919":"mode-testnet","1101":"polygon-zkevm","1135":"lisk","1301":"unichain-sepolia","1329":"sei","1625":"gravity","1993":"b3","2911":"hychain","4202":"lisk-sepolia","4321":"echos","5000":"mantle","5112":"ham","7560":"cyber","8333":"B3","8453":"base","9897":"arena-z-testnet","11011":"shape-sepolia","11124":"abstract","13746":"game7-testnet","17000":"holesky","17071":"onchain-points","33139":"apechain","33979":"funki","34443":"mode","42161":"arbitrum","42170":"arbitrum-nova","43114":"avalanche","55244":"superposition","57073":"ink","59144":"linea","60808":"bob","70700":"apex","70701":"boss","70800":"apex-testnet","70805":"cloud","80002":"amoy","81457":"blast","84532":"base-sepolia","167009":"hekla","421614":"arbitrum-sepolia","534352":"scroll","543210":"zero-network","660279":"xai","911867":"odyssey","984122":"forma","1118190":"eclipse-testnet","3397901":"funki-testnet","4457845":"zero-sepolia","7777777":"zora","8253038":"bitcoin","9092725":"bitcoin-testnet4","9286185":"eclipse","11155111":"sepolia","11155420":"op-sepolia","666666666":"degen","792703809":"solana","888888888":"ancient8","999999999":"zora-sepolia","1380012617":"rari","1936682084":"solana-devnet","88153591557":"arbitrum-blueberry"};import{useQueryClient as hn,useMutation as yn}from"@tanstack/react-query";import{setBalance as wn}from"viem/actions";import{useClient as bn}from"wagmi";function vt(){let e=hn(),{chainId:t}=l(),r=bn({chainId:t});return yn({mutationKey:["setBalance",t],onError:o=>console.error(o),mutationFn:async o=>(r&&(await wn({...r,mode:"anvil"},o),await Promise.all([e.invalidateQueries({queryKey:["balance"]}),e.invalidateQueries({queryKey:["getPrerequisites"]})])),null),retry:0})}import{Fragment as vn,jsx as b,jsxs as D}from"react/jsx-runtime";function Ct({isActive:e,isExpanded:t,sessionAddress:r}){let{chain:o}=l(),n=xn({chainId:o.id,address:r,query:{refetchInterval:2e3}}),a=vt(),i=xt[o.id];return D("div",{className:"flex flex-col gap-4",children:[D("div",{className:"flex justify-between gap-4",children:[D("div",{children:[b("div",{children:"Gas balance"}),b("div",{className:"font-mono text-white",children:n.data!=null?b(j,{wei:n.data.value}):b(w,{className:"text-sm"})})]}),o.id===31337?b(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:n.status==="pending"||a.status==="pending",onClick:()=>a.mutate({address:r,value:A+(n.data?.value??0n)}),children:"Top up"}):i!=null?b("a",{href:`https://relay.link/bridge/${i}?${new URLSearchParams({toAddress:r})}`,target:"_blank",rel:"noopener noreferrer",children:b(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:n.status==="pending",children:"Top up"})}):null]}),t?D(vn,{children:[b("p",{className:"text-sm",children:"Your session's gas balance is used to pay for onchain computation."}),i==null?D("p",{className:"text-sm",children:["Send funds to"," ",b("span",{className:"font-mono text-white",children:b(I,{hex:r})})," ","on ",o.name," to top up your session balance."]}):null]}):null]})}import{jsx as N}from"react/jsx-runtime";function kt({userClient:e,initialUserAddress:t}){let{chain:r}=l(),o=h(r),n=e.account.address,{data:a}=M(n),{closeAccountModal:i}=C(),s=n!==t,d=Sn(a);Cn(()=>{a!=null&&(d.current==null&&(d.current=a),a.complete&&(s||!d.current.complete)&&i())},[i,s,a]);let{sessionAddress:f,hasAllowance:m,isSpender:c,hasDelegation:p,hasGasBalance:g}=a??{},x=kn(()=>{if(!n)return[{id:"wallet",isComplete:!1,content:()=>null}];let u=[{id:"wallet",isComplete:!0,content:v=>N(je,{...v,userAddress:n})}];return o?o.type==="quarry"&&u.push({id:"allowance",isComplete:!!m,content:v=>N(ot,{...v,userAddress:n})}):f!=null&&u.push({id:"gasBalance",isComplete:!!g,content:v=>N(Ct,{...v,sessionAddress:f})}),u.push({id:"session",isComplete:!!c&&!!p,content:v=>N(bt,{...v,userClient:e,registerSpender:!c,registerDelegation:!p})}),u},[m,p,g,c,o,f,n,e]),[be]=Pn(null),Kt=x.find(u=>u.content!=null&&!u.isComplete),te=x.filter(u=>u.isComplete),re=(be!=null?x.find(u=>u.id===be):null)??Kt??(te.length<x.length?te.at(-1):null),xe=re?x.indexOf(re):-1;return N("div",{className:ye("px-8 flex flex-col divide-y divide-neutral-800","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:x.map((u,v)=>{let oe=u===re,Ut=oe||te.length===x.length,Dt=!u.isComplete&&xe!==-1&&v>xe;return N("div",{className:ye("py-8 flex flex-col justify-center",oe?"flex-grow":null),children:N("div",{className:ye("flex flex-col",Dt?"opacity-30 pointer-events-none":null),children:u.content({isActive:oe,isExpanded:Ut})})},u.id)})})}import{useRef as En}from"react";import{jsx as St}from"react/jsx-runtime";function Pt(){let{chainId:e}=l(),t=Nn({chainId:e}),{address:r}=An(),o=En(r);return t.status!=="success"?St(qe,{}):St(kt,{userClient:t.data,initialUserAddress:o.current})}import{useState as Hn}from"react";import{ErrorBoundary as On}from"react-error-boundary";import{twMerge as Rn}from"tailwind-merge";import{BaseError as Tn,UserRejectedRequestError as Mn}from"viem";import{jsx as At,jsxs as In}from"react/jsx-runtime";function Nt({title:e,error:t}){if(!t||t instanceof Tn&&t.walk(n=>n instanceof Mn)!=null)return null;let r=e??"Error",o=typeof t=="string"?t:t instanceof Error?String(t):"Something unexpected happened.";return In("div",{className:Rn("text-sm border-l-4 border-red-500","bg-red-100 text-red-900","dark:bg-red-900 dark:text-red-50"),children:[At("div",{className:"p-3 font-semibold",children:r}),At("div",{className:"px-3 whitespace-break-spaces break-all max-h-32 overflow-y-scroll",children:o})]})}import{wait as zn}from"@latticexyz/common/utils";import{twMerge as qn}from"tailwind-merge";import{useIsMounted as Bn}from"usehooks-ts";import{jsx as Z,jsxs as Et}from"react/jsx-runtime";function Rt({children:e}){let t=Bn(),[r,o]=Hn(1);return Z(On,{fallbackRender:({error:n,resetErrorBoundary:a})=>Et("div",{className:qn("flex-grow flex flex-col justify-center p-5 gap-2"),children:[Z(Nt,{error:n instanceof Error?n.stack??n.message:n}),r>0?Et("button",{type:"button",onClick:async i=>{i.currentTarget.ariaBusy="true",await zn(1e3),a(),t()&&(o(s=>s-1),i.currentTarget.ariaBusy=null)},className:"group aria-busy:pointer-events-none self-end flex items-center gap-1",children:[Z(w,{className:"transition opacity-0 group-aria-busy:opacity-100 text-xs text-neutral-500 dark:text-neutral-400"}),Z("span",{className:"text-sm text-neutral-500 dark:text-neutral-400 group-hover:text-black dark:group-hover:text-white",children:"Retry?"})]}):null]}),children:e})}import{DialogClose as Kn,DialogTitle as Un}from"@radix-ui/react-dialog";import{twMerge as Ln}from"tailwind-merge";import{jsx as Fn}from"react/jsx-runtime";function Tt({className:e,children:t,...r}){return Fn("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:Ln("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...r,children:t})}import{jsx as Mt}from"react/jsx-runtime";function It(e){return Mt(Tt,{strokeWidth:"2",stroke:"currentColor",...e,children:Mt("path",{d:"M6 18L18 6M6 6L18 18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as k,jsxs as we}from"react/jsx-runtime";function Ot(){let{accountModalOpen:e,toggleAccountModal:t}=C();return we(He,{open:e,onOpenChange:t,children:[k(Un,{className:"sr-only",children:"Connect with EntryKit"}),e?we("div",{className:Ht("relative py-2 ring-1","bg-neutral-900 text-neutral-400 ring-neutral-700/50 divide-neutral-700","links:font-medium links:underline links:underline-offset-4","links:text-white","links:decoration-neutral-500 hover:links:decoration-orange-500"),children:[k(Rt,{children:k(Pt,{})}),we("a",{href:"https://mud.dev",target:"_blank",rel:"noreferrer noopener",className:"group self-center p-3 flex items-center justify-center gap-2 links-unset text-sm font-mono transition text-neutral-400 hover:text-white",children:[k("span",{className:"block w-4 h-4",children:k(P,{className:"w-full h-full text-orange-500 group-hover:rotate-90 transition duration-300"})}),k("span",{children:"Powered by MUD"})]}),k("div",{className:"absolute top-0 right-0",children:k(Kn,{className:Ht("pointer-events-auto leading-none p-2 transition","text-neutral-700 hover:text-neutral-500"),title:"Close",children:k(It,{className:"m-0"})})})]}):null]})}import{jsx as Gn,jsxs as Qn}from"react/jsx-runtime";function Dn({config:e,children:t}){return Qn(Ee,{config:e,children:[t,Gn(Ot,{})]})}import{useAccount as Wn}from"wagmi";import{twMerge as E}from"tailwind-merge";import{twMerge as zt}from"tailwind-merge";import{Fragment as Vn,jsx as J,jsxs as qt}from"react/jsx-runtime";function Bt({address:e}){let{data:t}=Y(e),r=V(t?.avatar);return qt(Vn,{children:[qt("span",{className:"flex-shrink-0 w-6 h-6 -my-1 -mx-0.5 grid place-items-center",children:[J("img",{src:t?.avatar&&r.isSuccess?t.avatar:void 0,className:zt("col-start-1 row-start-1","inline-flex w-full h-full rounded-full bg-black/10 dark:bg-white/10 bg-cover bg-no-repeat bg-center","transtion duration-300",r.isSuccess?"opacity-100":"opacity-0")}),J(P,{className:zt("col-start-1 row-start-1 text-orange-500","transition duration-300",t&&(!t.avatar||r.isError)?"opacity-100":"opacity-0")})]}),J("span",{className:"flex-grow",children:t?.name??J(I,{hex:e})})]})}import{useRef as _n}from"react";import{jsx as S,jsxs as Ft}from"react/jsx-runtime";var Lt=E("w-48 p-3 inline-flex outline-none transition","border border-transparent","text-base leading-none"),Yn=E("bg-neutral-100 border-neutral-300 text-black","dark:bg-neutral-800 dark:border-neutral-700 dark:text-white"),Xn=E("cursor-pointer outline-none hover:bg-neutral-200 data-[highlighted]:bg-neutral-200 dark:hover:bg-neutral-700");function jn(){let{openAccountModal:e,accountModalOpen:t}=C(),{status:r,address:o}=Wn(),n=_n(o),a=M(o),i=r==="connected"||r==="reconnecting"&&o,s=o!==n.current,d=a.isSuccess?a.data.complete:s?!1:i,f=(()=>{if(a.isSuccess){if(!a.data.hasAllowance)return"Top up";if(!a.data.hasDelegation||!a.data.isSpender)return"Set up"}return"Sign in"})();return S(G,{mode:"child",children:d?S("button",{type:"button",className:E(Lt,Yn,Xn),onClick:e,children:S("span",{className:"flex-grow inline-flex gap-2.5 items-center text-left font-medium",children:o?S(Bt,{address:o}):null})},"connected"):Ft("button",{type:"button",className:E(Lt,"group","items-center justify-center gap-2.5","bg-orange-500 text-white font-medium","hover:bg-orange-400","active:bg-orange-600"),"aria-busy":t,onClick:e,children:[Ft("span",{className:"pointer-events-none inline-grid place-items-center -ml-3",children:[S("span",{className:E("col-start-1 row-start-1 leading-none","scale-100 opacity-100 transition duration-300","group-aria-busy:scale-125 group-aria-busy:opacity-0"),children:S(P,{})}),S("span",{"aria-hidden":!0,className:E("col-start-1 row-start-1","scale-50 opacity-0 transition duration-300 delay-50","group-aria-busy:scale-100 group-aria-busy:opacity-100"),children:S(w,{})})]}),S("span",{className:"font-medium",children:f})]},"sign in")})}import{useConnectorClient as $n}from"wagmi";function Zn(){let{chainId:e}=l(),t=$n({chainId:e});t.error&&console.error("Error retrieving user client",t.error);let r=t.data?.account.address,o=M(r),n=$(r);return t.isSuccess?!o.isSuccess||!o.data.complete?{...o,data:void 0}:n:{...t,data:void 0}}import{connectorsForWallets as ea}from"@rainbow-me/rainbowkit";import{createConfig as ta}from"wagmi";import{getDefaultWallets as Jn}from"@rainbow-me/rainbowkit";function ee(e){let{wallets:t}=Jn();return[...t]}function ra(e){let t=ee(e),r=ea(t,{appName:e.appName,projectId:e.walletConnectProjectId});return ta({connectors:r,chains:e.chains,transports:e.transports,pollingInterval:e.pollingInterval})}import{connectorsForWallets as oa}from"@rainbow-me/rainbowkit";function gm({wallets:e,...t}){return oa(e??ee(t),{appName:t.appName,projectId:t.walletConnectProjectId})}export{jn as AccountButton,Dn as EntryKitProvider,ra as createWagmiConfig,Gt as defineConfig,gm as getConnectors,ee as getWallets,C as useAccountModal,l as useEntryKitConfig,Zn as useSessionClient};
1397
+ URL: ${e}`)),o.src=e})})}import{jsx as W,jsxs as br}from"react/jsx-runtime";function ze(){let{appName:e,appIcon:t}=l(),{data:r,isLoading:o}=V(t);return br("div",{className:"flex-grow flex flex-col items-center justify-center gap-2",children:[W("div",{className:"w-16 h-16 m-2",children:o?null:r?W("img",{src:t,className:"w-full h-full object-cover"}):W(P,{className:"w-full h-full text-orange-500 dark:bg-neutral-800"})}),W("div",{className:"text-2xl text-white text-center",children:e})]})}import{twMerge as Cr}from"tailwind-merge";import{useEffect as kr,useState as Sr}from"react";import{jsx as _,jsxs as Pr}from"react/jsx-runtime";function qe(){let e=xr(),{openConnectModal:t,connectModalOpen:r}=vr(),[o,n]=Sr(!1);return kr(()=>{!r&&!o&&(t?.(),n(!0))},[r,o,t]),Pr("div",{className:Cr("flex flex-col gap-6 p-6","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:[_("div",{className:"p-4",children:_(ze,{})}),_("div",{className:"self-center flex flex-col gap-2 w-60",children:_(y,{variant:"secondary",className:"self-auto flex justify-center",disabled:e.status==="connecting",onClick:t,autoFocus:!0,children:"Connect wallet"},"create")})]})}import{useEffect as kn,useMemo as Sn,useRef as Pn,useState as An}from"react";import{twMerge as ye}from"tailwind-merge";import{parseEther as Ar}from"viem";var A=Ar("0.01");import{useClient as zr}from"wagmi";import{queryOptions as qr,useQuery as Br}from"@tanstack/react-query";import{numberToHex as Tr}from"viem";import{defineStore as Nr}from"@latticexyz/store";import{parseAbi as Er}from"viem";var se=Er(["error SpenderSystem_AlreadyRegistered(address spender, address user)","error SpenderSystem_HasOwnBalance(address spender)","function registerSpender(address spender)"]),Rr=Nr({namespaces:{root:{namespace:"",tables:{Allowance:{schema:{user:"address",allowance:"uint256"},key:["user"]},Grantor:{schema:{grantor:"address",allowance:"uint256"},key:["grantor"]},PassHolder:{schema:{user:"address",passId:"bytes32",lastRenewed:"uint256",lastClaimed:"uint256"},key:["user","passId"]},PassConfig:{schema:{passId:"bytes32",claimAmount:"uint256",claimInterval:"uint256",validityPeriod:"uint256",grantor:"address"},key:["passId"]},Spender:{schema:{spender:"address",user:"address"},key:["spender"]},SystemConfig:{schema:{entryPoint:"address"},key:[]}}}}}),T=Rr.namespaces.root.tables;import{getRecord as Mr,getStaticDataLocation as Ir}from"@latticexyz/store/internal";import{getKeyTuple as Hr}from"@latticexyz/protocol-parser/internal";import{setStorageAt as Or}from"viem/actions";function h(e){let t=e.contracts??{};if("quarryPaymaster"in t&&t.quarryPaymaster!=null&&"address"in t.quarryPaymaster)return{type:"quarry",address:t.quarryPaymaster.address};if("paymaster"in t&&t.paymaster!=null&&"address"in t.paymaster)return{type:"simple",address:t.paymaster.address}}async function Be({client:e,userAddress:t}){let r=h(e.chain);return r?.type!=="quarry"?null:(await Mr(e,{address:r.address,table:T.Allowance,key:{user:t},blockTag:"pending"})).allowance}async function Le({client:e,userAddress:t,allowance:r}){let o=h(e.chain);if(o?.type!=="quarry")return;let n=Ir(T.Allowance.tableId,Hr(T.Allowance,{user:t}));await Or(e.extend(()=>({mode:"anvil"})),{address:o.address,index:n,value:Tr(r,{size:32})})}function le({client:e,userAddress:t}){let r=["getAllowance",e?.chain.id,t];return qr(e&&t?{queryKey:r,queryFn:()=>Be({client:e,userAddress:t})}:{queryKey:r,enabled:!1})}function Fe(e){let{chainId:t}=l(),r=zr({chainId:t});return Br(le({client:r,userAddress:e}))}import{useClient as Fi}from"wagmi";import{queryOptions as Fr,useQuery as Ui}from"@tanstack/react-query";import{getRecord as Lr}from"@latticexyz/store/internal";async function Ke({client:e,userAddress:t,sessionAddress:r}){let o=h(e.chain);return o?.type!=="quarry"?null:(await Lr(e,{address:o.address,table:T.Spender,key:{spender:r},blockTag:"pending"})).user.toLowerCase()===t.toLowerCase()}function Ue({client:e,userAddress:t,sessionAddress:r}){let o=["getSpender",e?.chain.id,t,r];return Fr(e&&t&&r?{queryKey:o,queryFn:()=>Ke({client:e,userAddress:t,sessionAddress:r})}:{queryKey:o,enabled:!1})}import{useClient as as}from"wagmi";import{queryOptions as Qr,useQuery as ss}from"@tanstack/react-query";import{getRecord as Gr}from"@latticexyz/store/internal";import{resourceToHex as Kr}from"@latticexyz/common";import{parseAbi as Ur}from"viem";import Dr from"@latticexyz/world/mud.config";var De={pollingInterval:250},L=Kr({type:"system",namespace:"",name:"unlimited"}),Ge=Dr.namespaces.world.tables,Qe=Ur(["function registerDelegation(address delegatee, bytes32 delegationControlId, bytes initCallData)"]);async function Ve({client:e,worldAddress:t,userAddress:r,sessionAddress:o}){return(await Gr(e,{address:t,table:Ge.UserDelegationControl,key:{delegator:r,delegatee:o},blockTag:"pending"})).delegationControlId===L}function We({client:e,worldAddress:t,userAddress:r,sessionAddress:o}){let n=["getDelegation",e?.chain.id,t,r,o];return Qr(e&&r&&o?{queryKey:n,queryFn:()=>Ve({client:e,worldAddress:t,userAddress:r,sessionAddress:o})}:{queryKey:n,enabled:!1})}import{queryOptions as to,useQuery as ro,useQueryClient as oo}from"@tanstack/react-query";import{useClient as no,useConfig as ao}from"wagmi";import{useClient as Zr}from"wagmi";import{queryOptions as Jr,useQuery as eo}from"@tanstack/react-query";import{toSimpleSmartAccount as $r}from"permissionless/accounts";import{isHex as Yr}from"viem";import{createStore as Vr}from"zustand/vanilla";import{persist as Wr}from"zustand/middleware";var F=Vr(Wr(()=>({signers:{}}),{name:"mud:entrykit",partialize:({signers:e})=>({signers:e})}));function _r(e){e.key===F.persist.getOptions().name&&F.persist.rehydrate()}window.addEventListener("storage",_r);import{generatePrivateKey as Xr,privateKeyToAccount as jr}from"viem/accounts";function _e(e){let t=e.toLowerCase(),r=F.getState().signers[t]??(()=>{let o=localStorage.getItem(`mud:appSigner:privateKey:${e.toLowerCase()}`),n=Yr(o)?o:Xr();return F.setState(a=>({signers:{...a.signers,[t]:n}})),n})();return jr(r)}async function Ye({client:e,userAddress:t}){let r=_e(t);return await $r({client:e,owner:r})}function ce({client:e,userAddress:t}){let r=["getSessionAccount",e?.chain.id,t];return Jr(e&&t?{queryKey:r,queryFn:()=>Ye({client:e,userAddress:t}),staleTime:1/0}:{queryKey:r,enabled:!1})}function Xe(e){let{chainId:t}=l(),r=Zr({chainId:t});return eo(ce({userAddress:e,client:r}))}import{getBalanceQueryOptions as io}from"wagmi/query";function so({queryClient:e,config:t,client:r,userAddress:o,worldAddress:n}){let a=["getPrerequisites",r?.chain.id,o];return to(r&&o?{queryKey:a,queryFn:async()=>{let i=h(r.chain),{address:s}=await e.fetchQuery(ce({client:r,userAddress:o})),[d,f,m,c]=await Promise.all([i?null:e.fetchQuery(io(t,{chainId:r.chain.id,address:s})),i?.type==="quarry"?e.fetchQuery(le({client:r,userAddress:o})):null,i?.type==="quarry"?e.fetchQuery(Ue({client:r,userAddress:o,sessionAddress:s})):null,e.fetchQuery(We({client:r,worldAddress:n,userAddress:o,sessionAddress:s}))]),p=f==null||f>=A,g=m??!0,x=d==null||d.value>=A;return{sessionAddress:s,hasAllowance:p,isSpender:g,hasGasBalance:x,hasDelegation:c,complete:p&&g&&c}}}:{queryKey:a,enabled:!1})}function M(e){let t=oo(),{chainId:r,worldAddress:o}=l(),n=ao(),a=no({chainId:r});return ro(so({config:n,queryClient:t,client:a,userAddress:e,worldAddress:o}),t)}import{useDisconnect as po}from"wagmi";import{useQuery as lo}from"@tanstack/react-query";function Y(e){let t=e?.toLowerCase();return lo({enabled:!!t,queryKey:["ens",t],queryFn:async()=>{let r=await fetch(`https://api.ensideas.com/ens/resolve/${t}`).then(o=>o.json());return{address:r.address??void 0,name:r.name??void 0,displayName:r.displayName??void 0,avatar:r.avatar??void 0}}})}import{jsx as de,jsxs as co}from"react/jsx-runtime";function I({hex:e}){return e.length<=10?de("span",{title:e,children:e}):co("span",{title:e,children:[de("span",{className:"after:select-none after:content-['\u2026']",children:e.slice(0,6)}),de("span",{className:"tracking-[-1ch] text-transparent",children:e.slice(6,-4)}),e.slice(-4)]})}import{jsx as K,jsxs as pe}from"react/jsx-runtime";function je({isActive:e,isExpanded:t,userAddress:r}){let{data:o}=Y(r),{disconnect:n,isPending:a}=po(),{closeAccountModal:i}=C();return pe("div",{className:"flex flex-col gap-4",children:[pe("div",{className:"flex justify-between gap-4",children:[pe("div",{children:[K("div",{children:"Account"}),K("div",{className:"font-mono text-white",children:o?.name??K(I,{hex:r})})]}),K(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:a,onClick:()=>{i(),n()},children:"Sign out"})]}),t?K("p",{className:"text-sm",children:"Each of your onchain actions in this app is associated with your account."}):null]})}import{parseEther as fo}from"viem";import{useMutation as go,useQueryClient as ho}from"@tanstack/react-query";import{http as mo}from"viem";function $e(){return({chain:e})=>{if(!e)throw new Error("No chain provided to issuer transport.");let t="quarryPassIssuer"in e.rpcUrls?e.rpcUrls.quarryPassIssuer.http[0]:void 0;if(!t)throw new Error(`No \`quarryPassIssuer\` RPC URL found for chain ${e.id}.`);return mo(t)({chain:e,retryCount:0})}}import Ze from"debug";var me=Ze("mud:entrykit"),uo=Ze("mud:entrykit");me.log=console.debug.bind(console);uo.log=console.error.bind(console);var H=me.extend("quarry");async function Je({chain:e,userAddress:t}){let r=$e()({chain:e});H("Issuing gas pass to",t),await r.request({method:"quarry_issuePass",params:["0x01",t]}),H("Claiming gas allowance for",t),await r.request({method:"quarry_claimAllowance",params:["0x01",t]})}import{useClient as yo}from"wagmi";function et(){let e=ho(),{chain:t}=l(),r=yo({chainId:t.id}),o=["claimGasPass",t.id];return go({mutationKey:o,onError:n=>console.error(n),mutationFn:async n=>{if(t.id===31337){if(!r)throw new Error("No client?");await Le({client:r,userAddress:n,allowance:fo("1")})}else await Je({chain:t,userAddress:n});await Promise.all([e.invalidateQueries({queryKey:["getAllowance"]}),e.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{twMerge as wo}from"tailwind-merge";import{jsx as X,jsxs as bo}from"react/jsx-runtime";function tt({className:e,...t}){return bo("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 263 428",fill:"currentColor",className:wo("w-[0.6em] h-[1em]",e),...t,children:[X("path",{d:"M132 321V428L263 243L132 321Z"}),X("path",{d:"M0 243L132 321V428",fillOpacity:"0.5"}),X("path",{d:"M132 0V296L263 218"}),X("path",{d:"M0 218L132 296V0L0 218Z",fillOpacity:"0.5"})]})}import{formatEther as xo}from"viem";function rt(e){let t=xo(e),r=Math.floor(parseFloat(t)).toString().length;return parseFloat(t).toLocaleString("en-US",{maximumFractionDigits:Math.max(0,6-r)})}import{formatEther as vo}from"viem";import{jsx as Co,jsxs as ko}from"react/jsx-runtime";function j({wei:e}){return ko("span",{className:"inline-flex items-center gap-1",title:vo(e),children:[rt(e)," ",Co(tt,{})]})}import{useEffect as So}from"react";import{jsx as O,jsxs as ue}from"react/jsx-runtime";function ot({isActive:e,isExpanded:t,userAddress:r}){let o=Fe(r),n=et();return So(()=>{let a=setTimeout(()=>{e&&n.status==="idle"&&o.isSuccess&&o.data!=null&&o.data<A&&n.mutate(r)});return()=>clearTimeout(a)},[o.data,o.isSuccess,n,e,r]),ue("div",{className:"flex flex-col gap-4",children:[ue("div",{className:"flex justify-between gap-4",children:[ue("div",{children:[O("div",{children:"Allowance"}),O("div",{className:"font-mono text-white",children:o.data!=null?O(j,{wei:o.data}):O(w,{className:"text-sm"})})]}),O(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:o.status==="pending"||n.status==="pending",onClick:()=>n.mutate(r),children:"Top up"})]}),t?O("p",{className:"text-sm",children:"Your allowance is used to pay for onchain computation."}):null]})}import{encodeFunctionData as at}from"viem";import{useMutation as zo,useQueryClient as qo}from"@tanstack/react-query";import{getAction as ge}from"viem/utils";import{sendUserOperation as Bo,waitForUserOperationReceipt as Lo}from"viem/account-abstraction";import{waitForTransactionReceipt as Fo}from"viem/actions";import{useClient as Ko}from"wagmi";import{resourceToHex as it}from"@latticexyz/common";import Uo from"@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json";import{writeContract as Io}from"viem/actions";import{getAction as Ho}from"viem/utils";import{toHex as Po}from"viem";import{signTypedData as Ao}from"viem/actions";import{callWithSignatureTypes as No}from"@latticexyz/world-module-callwithsignature/internal";import{getRecord as Eo}from"@latticexyz/store/internal";import Ro from"@latticexyz/world-module-callwithsignature/mud.config";import{hexToResource as To}from"@latticexyz/common";import{getAction as Mo}from"viem/utils";async function nt({userClient:e,worldAddress:t,systemId:r,callData:o,nonce:n,client:a}){let i=n??(a?(await Eo(a,{address:t,table:Ro.tables.CallWithSignatureNonces,key:{signer:e.account.address},blockTag:"pending"})).nonce:0n),{namespace:s,name:d}=To(r);return await Mo(e,Ao,"signTypedData")({account:e.account,domain:{verifyingContract:t,salt:Po(e.chain.id,{size:32})},types:No,primaryType:"Call",message:{signer:e.account.address,systemNamespace:s,systemName:d,callData:o,nonce:i}})}import Oo from"@latticexyz/world-module-callwithsignature/out/CallWithSignatureSystem.sol/CallWithSignatureSystem.abi.json";async function fe({sessionClient:e,...t}){let r=await nt(t);return Ho(e,Io,"writeContract")({address:t.worldAddress,abi:Oo,functionName:"callWithSignature",args:[t.userClient.account.address,t.systemId,t.callData,r]})}function st({userClient:e}){let t=qo(),{chainId:r,worldAddress:o}=l(),n=Ko({chainId:r}),a=["setupSession",n?.chain.id,e.account.address];return zo({mutationKey:a,onError:i=>console.error(i),mutationFn:async({sessionClient:i,registerSpender:s,registerDelegation:d})=>{if(!n)throw new Error("Client not ready.");let f=h(n.chain),m=i.account.address;if(console.log("setting up session"),e.account.type==="smart"){let c=[];if(s&&f?.type==="quarry"&&(console.log("registering spender"),c.push({to:f.address,abi:se,functionName:"registerSpender",args:[m]})),d&&(console.log("registering delegation"),c.push({to:o,abi:Qe,functionName:"registerDelegation",args:[m,L,"0x"]})),!c.length)return;console.log("setting up account with",c,e);let p=await ge(e,Bo,"sendUserOperation")({calls:c});console.log("got user op hash",p);let g=await ge(e,Lo,"waitForUserOperationReceipt")({hash:p});console.log("got user op receipt",g),g.success||console.error("not successful?",g)}else{let c=[];if(s&&f?.type==="quarry"){console.log("registering spender");let p=await fe({client:n,userClient:e,sessionClient:i,worldAddress:f.address,systemId:it({type:"system",namespace:"",name:"SpenderSystem"}),callData:at({abi:se,functionName:"registerSpender",args:[m]})});console.log("got spender tx",p),c.push(p)}if(d){console.log("registering delegation");let p=await fe({client:n,userClient:e,sessionClient:i,worldAddress:o,systemId:it({type:"system",namespace:"",name:"Registration"}),callData:at({abi:Uo,functionName:"registerDelegation",args:[m,L,"0x"]})});console.log("got delegation tx",p),c.push(p)}if(!c.length)return;console.log("waiting for",c.length,"receipts");for(let p of c){let g=await ge(n,Fo,"waitForTransactionReceipt")({hash:p});console.log("got tx receipt",g),g.status==="reverted"&&console.error("tx reverted?",g)}}await Promise.all([t.invalidateQueries({queryKey:["getSpender"]}),t.invalidateQueries({queryKey:["getDelegation"]}),t.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{useEffect as gn}from"react";import{useClient as pn}from"wagmi";import{queryOptions as mn,useQuery as un}from"@tanstack/react-query";import{smartAccountActions as cn}from"permissionless";import{callFrom as dn}from"@latticexyz/world/internal";import{createBundlerClient as Do}from"viem/account-abstraction";var Go=new Set([31337,17420,17069,690]);function lt(e){let t=e.chain??e.client?.chain,r=t?h(t):void 0;return Do({...De,paymaster:r?{getPaymasterData:async()=>({paymaster:r.address,paymasterData:"0x"})}:void 0,userOperation:{estimateFeesPerGas:t&&Go.has(t.id)?async()=>({maxFeePerGas:100000n,maxPriorityFeePerGas:0n}):void 0},...e})}import{transactionQueue as tn}from"@latticexyz/common/actions";import{createClient as rn,fallback as on,http as ht,keccak256 as nn,stringToHex as an,webSocket as sn}from"viem";import{privateKeyToAccount as ln}from"viem/accounts";import{createTransport as $o,numberToHex as Zo,parseEther as Jo}from"viem";import{entryPoint07Address as ft}from"viem/account-abstraction";import{formatUserOperationRequest as Qo}from"viem/account-abstraction";async function ct(e){return Qo({callGasLimit:20000000n,preVerificationGas:200000n,verificationGasLimit:2000000n,paymasterVerificationGasLimit:200000n,paymasterPostOpGasLimit:200000n})}import{parseEventLogs as Vo}from"viem";import{formatUserOperation as Wo,toPackedUserOperation as _o,getUserOperationHash as Yo,entryPoint07Address as dt,entryPoint07Abi as pt}from"viem/account-abstraction";import{waitForTransactionReceipt as Xo,writeContract as jo}from"viem/actions";import{getAction as mt}from"viem/utils";async function ut({executor:e,rpcUserOp:t}){let r=Wo(t),o=_o(r),n=Yo({userOperation:r,chainId:e.chain.id,entryPointVersion:"0.7",entryPointAddress:dt}),a=await mt(e,jo,"writeContract")({abi:pt,address:dt,functionName:"handleOps",args:[[o],e.account.address],chain:e.chain,account:e.account}),i=await mt(e,Xo,"waitForTransactionReceipt")({hash:a});return{success:Vo({logs:i.logs,abi:pt,eventName:"UserOperationEvent"})[0].args.success,userOpHash:n,receipt:i}}import{setBalance as en}from"viem/actions";function gt({executor:e}){return()=>{H("using a local user op executor",e.account.address),e.chain.id===31337&&(H("setting executor balance"),en(e.extend(()=>({mode:"anvil"})),{address:e.account.address,value:Jo("100")}));let t=new Map;return $o({key:"userOpExecutor",type:"userOpExecutor",name:"User Operation Executor Transport",request:async({method:o,params:n})=>{if(o==="eth_chainId")return Zo(e.chain.id);if(o==="eth_supportedEntryPoints")return[ft];if(o==="eth_sendUserOperation"){let[a,i]=n;if(i===ft){let s=await ut({executor:e,rpcUserOp:a});return t.set(s.userOpHash,s),s.userOpHash}}if(o==="eth_getUserOperationReceipt"){let[a]=n;return t.get(a)??null}if(o==="eth_estimateUserOperationGas")return await ct(n);throw new Error("Method not implemented.")}})}}function yt(e){let t=e.rpcUrls.bundler?.http[0],r=t?ht(t):e.id===31337?gt({executor:rn({chain:e,transport:on([sn(),ht()]),account:ln(nn(an("local user op executor"))),pollingInterval:10}).extend(tn())}):null;if(!r)throw new Error(`Chain ${e.id} config did not include a bundler RPC URL.`);return r}async function wt({client:e,userAddress:t,sessionAccount:r,worldAddress:o}){let n=yt(e.chain);return lt({transport:n,client:e,account:r}).extend(cn).extend(dn({worldAddress:o,delegatorAddress:t,publicClient:e})).extend(()=>({userAddress:t}))}function fn({sessionAccount:e,client:t,userAddress:r,worldAddress:o}){let n=["getSessionClient",t?.uid,r,e?.address,o];return mn(t&&r&&e?{queryKey:n,queryFn:()=>wt({sessionAccount:e,client:t,userAddress:r,worldAddress:o}),staleTime:1/0}:{queryKey:n,enabled:!1})}function $(e){let{chainId:t,worldAddress:r}=l(),o=pn({chainId:t}),{data:n}=Xe(e);return un(fn({sessionAccount:n,userAddress:e,client:o,worldAddress:r}))}import{jsx as U,jsxs as he}from"react/jsx-runtime";function bt({isActive:e,isExpanded:t,userClient:r,registerSpender:o,registerDelegation:n}){let a=$(r.account.address),i=st({userClient:r}),s=!n&&!n;return gn(()=>{let d=setTimeout(()=>{e&&i.status==="idle"&&a.data&&!s&&i.mutate({sessionClient:a.data,registerSpender:o,registerDelegation:n})});return()=>clearTimeout(d)},[s,e,n,o,a,i]),he("div",{className:"flex flex-col gap-4",children:[he("div",{className:"flex justify-between gap-4",children:[he("div",{children:[U("div",{children:"Session"}),U("div",{className:"font-mono text-white",children:s?"Enabled":"Set up"})]}),s?U(y,{variant:"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,disabled:!0,children:"Enabled"}):U(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:!a.data||i.status==="pending",onClick:a.data?()=>i.mutate({sessionClient:a.data,registerSpender:o,registerDelegation:n}):void 0,children:"Enable"})]}),t?U("p",{className:"text-sm",children:"You can perform actions in this app without interruptions for approvals."}):null]})}import{useBalance as vn}from"wagmi";var xt={"1":"ethereum","10":"optimism","56":"bnb","100":"gnosis","111":"bob","137":"polygon","185":"mint","288":"boba","324":"zksync","360":"shape","480":"world-chain","690":"redstone","919":"mode-testnet","1101":"polygon-zkevm","1135":"lisk","1301":"unichain-sepolia","1329":"sei","1625":"gravity","1993":"b3","2911":"hychain","4202":"lisk-sepolia","4321":"echos","5000":"mantle","5112":"ham","7560":"cyber","8333":"B3","8453":"base","9897":"arena-z-testnet","11011":"shape-sepolia","11124":"abstract","13746":"game7-testnet","17000":"holesky","17071":"onchain-points","33139":"apechain","33979":"funki","34443":"mode","42161":"arbitrum","42170":"arbitrum-nova","43114":"avalanche","55244":"superposition","57073":"ink","59144":"linea","60808":"bob","70700":"apex","70701":"boss","70800":"apex-testnet","70805":"cloud","80002":"amoy","81457":"blast","84532":"base-sepolia","167009":"hekla","421614":"arbitrum-sepolia","534352":"scroll","543210":"zero-network","660279":"xai","911867":"odyssey","984122":"forma","1118190":"eclipse-testnet","3397901":"funki-testnet","4457845":"zero-sepolia","7777777":"zora","8253038":"bitcoin","9092725":"bitcoin-testnet4","9286185":"eclipse","11155111":"sepolia","11155420":"op-sepolia","666666666":"degen","792703809":"solana","888888888":"ancient8","999999999":"zora-sepolia","1380012617":"rari","1936682084":"solana-devnet","88153591557":"arbitrum-blueberry"};import{useQueryClient as yn,useMutation as wn}from"@tanstack/react-query";import{setBalance as bn}from"viem/actions";import{useClient as xn}from"wagmi";function vt(){let e=yn(),{chainId:t}=l(),r=xn({chainId:t});return wn({mutationKey:["setBalance",t],onError:o=>console.error(o),mutationFn:async o=>(r&&(await bn({...r,mode:"anvil"},o),await Promise.all([e.invalidateQueries({queryKey:["balance"]}),e.invalidateQueries({queryKey:["getPrerequisites"]})])),null),retry:0})}import{Fragment as Cn,jsx as b,jsxs as D}from"react/jsx-runtime";function Ct({isActive:e,isExpanded:t,sessionAddress:r}){let{chain:o}=l(),n=vn({chainId:o.id,address:r,query:{refetchInterval:2e3}}),a=vt(),i=xt[o.id];return D("div",{className:"flex flex-col gap-4",children:[D("div",{className:"flex justify-between gap-4",children:[D("div",{children:[b("div",{children:"Gas balance"}),b("div",{className:"font-mono text-white",children:n.data!=null?b(j,{wei:n.data.value}):b(w,{className:"text-sm"})})]}),o.id===31337?b(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:n.status==="pending"||a.status==="pending",onClick:()=>a.mutate({address:r,value:A+(n.data?.value??0n)}),children:"Top up"}):i!=null?b("a",{href:`https://relay.link/bridge/${i}?${new URLSearchParams({toAddress:r})}`,target:"_blank",rel:"noopener noreferrer",children:b(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:n.status==="pending",children:"Top up"})}):null]}),t?D(Cn,{children:[b("p",{className:"text-sm",children:"Your session's gas balance is used to pay for onchain computation."}),i==null?D("p",{className:"text-sm",children:["Send funds to"," ",b("span",{className:"font-mono text-white",children:b(I,{hex:r})})," ","on ",o.name," to top up your session balance."]}):null]}):null]})}import{jsx as N}from"react/jsx-runtime";function kt({userClient:e,initialUserAddress:t}){let{chain:r}=l(),o=h(r),n=e.account.address,{data:a}=M(n),{closeAccountModal:i}=C(),s=n!==t,d=Pn(a);kn(()=>{a!=null&&(d.current==null&&(d.current=a),a.complete&&(s||!d.current.complete)&&i())},[i,s,a]);let{sessionAddress:f,hasAllowance:m,isSpender:c,hasDelegation:p,hasGasBalance:g}=a??{},x=Sn(()=>{if(!n)return[{id:"wallet",isComplete:!1,content:()=>null}];let u=[{id:"wallet",isComplete:!0,content:v=>N(je,{...v,userAddress:n})}];return o?o.type==="quarry"&&u.push({id:"allowance",isComplete:!!m,content:v=>N(ot,{...v,userAddress:n})}):f!=null&&u.push({id:"gasBalance",isComplete:!!g,content:v=>N(Ct,{...v,sessionAddress:f})}),u.push({id:"session",isComplete:!!c&&!!p,content:v=>N(bt,{...v,userClient:e,registerSpender:!c,registerDelegation:!p})}),u},[m,p,g,c,o,f,n,e]),[be]=An(null),Kt=x.find(u=>u.content!=null&&!u.isComplete),te=x.filter(u=>u.isComplete),re=(be!=null?x.find(u=>u.id===be):null)??Kt??(te.length<x.length?te.at(-1):null),xe=re?x.indexOf(re):-1;return N("div",{className:ye("px-8 flex flex-col divide-y divide-neutral-800","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:x.map((u,v)=>{let oe=u===re,Ut=oe||te.length===x.length,Dt=!u.isComplete&&xe!==-1&&v>xe;return N("div",{className:ye("py-8 flex flex-col justify-center",oe?"flex-grow":null),children:N("div",{className:ye("flex flex-col",Dt?"opacity-30 pointer-events-none":null),children:u.content({isActive:oe,isExpanded:Ut})})},u.id)})})}import{useRef as Rn}from"react";import{jsx as St}from"react/jsx-runtime";function Pt(){let{chainId:e}=l(),t=En({chainId:e}),{address:r}=Nn(),o=Rn(r);return t.status!=="success"?St(qe,{}):St(kt,{userClient:t.data,initialUserAddress:o.current})}import{useState as On}from"react";import{ErrorBoundary as zn}from"react-error-boundary";import{twMerge as Tn}from"tailwind-merge";import{BaseError as Mn,UserRejectedRequestError as In}from"viem";import{jsx as At,jsxs as Hn}from"react/jsx-runtime";function Nt({title:e,error:t}){if(!t||t instanceof Mn&&t.walk(n=>n instanceof In)!=null)return null;let r=e??"Error",o=typeof t=="string"?t:t instanceof Error?String(t):"Something unexpected happened.";return Hn("div",{className:Tn("text-sm border-l-4 border-red-500","bg-red-100 text-red-900","dark:bg-red-900 dark:text-red-50"),children:[At("div",{className:"p-3 font-semibold",children:r}),At("div",{className:"px-3 whitespace-break-spaces break-all max-h-32 overflow-y-scroll",children:o})]})}import{wait as qn}from"@latticexyz/common/utils";import{twMerge as Bn}from"tailwind-merge";import{useIsMounted as Ln}from"usehooks-ts";import{jsx as Z,jsxs as Et}from"react/jsx-runtime";function Rt({children:e}){let t=Ln(),[r,o]=On(1);return Z(zn,{fallbackRender:({error:n,resetErrorBoundary:a})=>Et("div",{className:Bn("flex-grow flex flex-col justify-center p-5 gap-2"),children:[Z(Nt,{error:n instanceof Error?n.stack??n.message:n}),r>0?Et("button",{type:"button",onClick:async i=>{i.currentTarget.ariaBusy="true",await qn(1e3),a(),t()&&(o(s=>s-1),i.currentTarget.ariaBusy=null)},className:"group aria-busy:pointer-events-none self-end flex items-center gap-1",children:[Z(w,{className:"transition opacity-0 group-aria-busy:opacity-100 text-xs text-neutral-500 dark:text-neutral-400"}),Z("span",{className:"text-sm text-neutral-500 dark:text-neutral-400 group-hover:text-black dark:group-hover:text-white",children:"Retry?"})]}):null]}),children:e})}import{DialogClose as Un,DialogTitle as Dn}from"@radix-ui/react-dialog";import{twMerge as Fn}from"tailwind-merge";import{jsx as Kn}from"react/jsx-runtime";function Tt({className:e,children:t,...r}){return Kn("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:Fn("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...r,children:t})}import{jsx as Mt}from"react/jsx-runtime";function It(e){return Mt(Tt,{strokeWidth:"2",stroke:"currentColor",...e,children:Mt("path",{d:"M6 18L18 6M6 6L18 18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as k,jsxs as we}from"react/jsx-runtime";function Ot(){let{accountModalOpen:e,toggleAccountModal:t}=C();return we(He,{open:e,onOpenChange:t,children:[k(Dn,{className:"sr-only",children:"Connect with EntryKit"}),e?we("div",{className:Ht("relative py-2 ring-1","bg-neutral-900 text-neutral-400 ring-neutral-700/50 divide-neutral-700","links:font-medium links:underline links:underline-offset-4","links:text-white","links:decoration-neutral-500 hover:links:decoration-orange-500"),children:[k(Rt,{children:k(Pt,{})}),we("a",{href:"https://mud.dev",target:"_blank",rel:"noreferrer noopener",className:"group self-center p-3 flex items-center justify-center gap-2 links-unset text-sm font-mono transition text-neutral-400 hover:text-white",children:[k("span",{className:"block w-4 h-4",children:k(P,{className:"w-full h-full text-orange-500 group-hover:rotate-90 transition duration-300"})}),k("span",{children:"Powered by MUD"})]}),k("div",{className:"absolute top-0 right-0",children:k(Un,{className:Ht("pointer-events-auto leading-none p-2 transition","text-neutral-700 hover:text-neutral-500"),title:"Close",children:k(It,{className:"m-0"})})})]}):null]})}import{jsx as Qn,jsxs as Vn}from"react/jsx-runtime";function Gn({config:e,children:t}){return Vn(Ee,{config:e,children:[t,Qn(Ot,{})]})}import{useAccount as _n}from"wagmi";import{twMerge as E}from"tailwind-merge";import{twMerge as zt}from"tailwind-merge";import{Fragment as Wn,jsx as J,jsxs as qt}from"react/jsx-runtime";function Bt({address:e}){let{data:t}=Y(e),r=V(t?.avatar);return qt(Wn,{children:[qt("span",{className:"flex-shrink-0 w-6 h-6 -my-1 -mx-0.5 grid place-items-center",children:[J("img",{src:t?.avatar&&r.isSuccess?t.avatar:void 0,className:zt("col-start-1 row-start-1","inline-flex w-full h-full rounded-full bg-black/10 dark:bg-white/10 bg-cover bg-no-repeat bg-center","transtion duration-300",r.isSuccess?"opacity-100":"opacity-0")}),J(P,{className:zt("col-start-1 row-start-1 text-orange-500","transition duration-300",t&&(!t.avatar||r.isError)?"opacity-100":"opacity-0")})]}),J("span",{className:"flex-grow",children:t?.name??J(I,{hex:e})})]})}import{useRef as Yn}from"react";import{jsx as S,jsxs as Ft}from"react/jsx-runtime";var Lt=E("w-48 p-3 inline-flex outline-none transition","border border-transparent","text-base leading-none"),Xn=E("bg-neutral-100 border-neutral-300 text-black","dark:bg-neutral-800 dark:border-neutral-700 dark:text-white"),jn=E("cursor-pointer outline-none hover:bg-neutral-200 data-[highlighted]:bg-neutral-200 dark:hover:bg-neutral-700");function $n(){let{openAccountModal:e,accountModalOpen:t}=C(),{status:r,address:o}=_n(),n=Yn(o),a=M(o),i=r==="connected"||r==="reconnecting"&&o,s=o!==n.current,d=a.isSuccess?a.data.complete:s?!1:i,f=(()=>{if(a.isSuccess){if(!a.data.hasAllowance)return"Top up";if(!a.data.hasDelegation||!a.data.isSpender)return"Set up"}return"Sign in"})();return S(G,{mode:"child",children:d?S("button",{type:"button",className:E(Lt,Xn,jn),onClick:e,children:S("span",{className:"flex-grow inline-flex gap-2.5 items-center text-left font-medium",children:o?S(Bt,{address:o}):null})},"connected"):Ft("button",{type:"button",className:E(Lt,"group","items-center justify-center gap-2.5","bg-orange-500 text-white font-medium","hover:bg-orange-400","active:bg-orange-600"),"aria-busy":t,onClick:e,children:[Ft("span",{className:"pointer-events-none inline-grid place-items-center -ml-3",children:[S("span",{className:E("col-start-1 row-start-1 leading-none","scale-100 opacity-100 transition duration-300","group-aria-busy:scale-125 group-aria-busy:opacity-0"),children:S(P,{})}),S("span",{"aria-hidden":!0,className:E("col-start-1 row-start-1","scale-50 opacity-0 transition duration-300 delay-50","group-aria-busy:scale-100 group-aria-busy:opacity-100"),children:S(w,{})})]}),S("span",{className:"font-medium",children:f})]},"sign in")})}import{useConnectorClient as Zn}from"wagmi";function Jn(){let{chainId:e}=l(),t=Zn({chainId:e});t.error&&console.error("Error retrieving user client",t.error);let r=t.data?.account.address,o=M(r),n=$(r);return t.isSuccess?!o.isSuccess||!o.data.complete?{...o,data:void 0}:n:{...t,data:void 0}}import{connectorsForWallets as ta}from"@rainbow-me/rainbowkit";import{createConfig as ra}from"wagmi";import{getDefaultWallets as ea}from"@rainbow-me/rainbowkit";function ee(e){let{wallets:t}=ea();return[...t]}function oa(e){let t=ee(e),r=ta(t,{appName:e.appName,projectId:e.walletConnectProjectId});return ra({connectors:r,chains:e.chains,transports:e.transports,pollingInterval:e.pollingInterval})}import{connectorsForWallets as na}from"@rainbow-me/rainbowkit";function wm({wallets:e,...t}){return na(e??ee(t),{appName:t.appName,projectId:t.walletConnectProjectId})}export{$n as AccountButton,Gn as EntryKitProvider,oa as createWagmiConfig,Gt as defineConfig,wm as getConnectors,ee as getWallets,C as useAccountModal,l as useEntryKitConfig,Jn as useSessionClient};
1398
1398
  //# sourceMappingURL=internal.js.map