import{ar as s,aw as i,__tla as __tla_0}from"./_virtual_wxt-plugins-D2Qy6pl9.js";let w,C;let __tla=Promise.all([(()=>{try{return __tla_0}catch{}})()]).then(async()=>{function u(t){return typeof t=="object"&&t!==null}function d(...t){for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e}function g(t){const e=s(t);return/^[0-9a-f]{64}$/.test(e)?e:null}function m(t,e){if(!u(t)||typeof t.contractAddress!="string"||e.dialect==="canonical"&&typeof t.network!="string")return null;const r=e.dialect==="mobile"?g(t.contractAddress):s(t.contractAddress);if(r===null)return null;if(e.mode==="read"&&e.dialect==="canonical")return t;const n={...t,contractAddress:r};return e.mode==="write"&&e.dialect==="canonical"&&(n.network=e.network,n.tokenColor=typeof t.tokenColor=="string"&&t.tokenColor.length>0?s(t.tokenColor):void 0),n}function a(t,e){if(!Array.isArray(t))return[];const r=t.map(n=>m(n,e));return e.dialect==="canonical"&&e.mode==="read"&&r.some(n=>n===null)?[]:r.filter(n=>n!==null)}function y(t,e){const r=new Map;for(const n of t)r.set(s(n.contractAddress),n);for(const n of e){const o=s(n.contractAddress),c=r.get(o);if(!c){r.set(o,n);continue}r.set(o,{...c,...n,name:d(n.name,c.name)??n.name,kind:n.kind??c.kind,tokenColor:d(n.tokenColor,c.tokenColor),createdAt:c.createdAt||n.createdAt})}return Array.from(r.values())}function l(t,e){const r=new Map;for(const n of t){const o=s(n.contractAddress);(e==="last"||!r.has(o))&&r.set(o,n)}return Array.from(r.values())}function A(t,e){const r=t.map(n=>a(n,{...e,mode:"read"}));if(r.length===0)return[];if(e.dialect==="mobile"){let n=r[0]??[];for(const o of r.slice(1))n=y(o,n);return n}return l(r.flat(),"first")}function k(t){{const e={...t.incoming,contractAddress:s(t.incoming.contractAddress),network:t.network,createdAt:t.incoming.createdAt??t.now},r=s(e.contractAddress);return[...t.existing.filter(n=>s(n.contractAddress)!==r),e]}}function f(t){return`ftContracts:${t}`}w=async function(t,e){const r=typeof t=="string"?[t]:t,n=[];for(const o of r){if(!o)continue;const c=`${f(e)}:${o}`;n.push(await i().persistentStore.get(c))}return A(n,{dialect:"canonical",network:e})};async function R(t,e,r){const n=a(r,{dialect:"canonical",network:e,mode:"write"}),o=l(n,"last"),c=`${f(e)}:${t}`;await i().persistentStore.set(c,o)}C=async function(t,e,r,n=[]){const o=await w([t,...n],e),c=k({network:e,existing:o,incoming:r,now:i().now()});return await R(t,e,c),c}});export{w as loadManagedFtContracts,C as registerLaunchedAssetToken,__tla};