@latticexyz/cli 2.2.1 → 2.2.2-main-ef6f7c0c6afcc46e7463d18c00fa99c7cafcae65
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.
@@ -10,7 +10,7 @@ gracefully shutting down from SIGINT (Crtl-C)`),r.kill(),process.exit()}),await
|
|
10
10
|
Bytecode for ${t} (${r} bytes) is over the contract size limit (${F} bytes). Run \`forge build --sizes\` for more info.
|
11
11
|
`):r>F*.95&&console.warn(`
|
12
12
|
Bytecode for ${t} (${r} bytes) is almost over the contract size limit (${F} bytes). Run \`forge build --sizes\` for more info.
|
13
|
-
`),p("deploying",t,"at",s),[await bt(()=>gt(e,{chain:e.chain??null,to:o,data:ft([x,n])}),{retries:3,onFailedAttempt:()=>p(`failed to deploy ${t}, retrying...`)})])}import{uniqueBy as wt}from"@latticexyz/common/utils";import{waitForTransactionReceipt as ht}from"viem/actions";async function M({client:e,hashes:o,debugLabel:n="transactions"}){if(o.length){p(`waiting for ${n} to confirm`);for(let r of o)if((await ht(e,{hash:r})).status==="reverted")throw new Error(`Transaction reverted: ${r}`)}}async function P({client:e,deployerAddress:o,contracts:n}){let r=wt(n,s=>s.bytecode),t=(await Promise.all(r.map(s=>Be({client:e,deployerAddress:o,...s})))).flat();return await M({client:e,hashes:t,debugLabel:"contract deploys"}),t}import $e from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.json"assert{type:"json"};import St from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json"assert{type:"json"};import{getCreate2Address as vt,encodeDeployData as At,size as Dt}from"viem";import Ie from"@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json"assert{type:"json"};import We from"@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json"assert{type:"json"};import Re from"@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json"assert{type:"json"};import He from"@latticexyz/world/out/RegistrationSystem.sol/RegistrationSystem.json"assert{type:"json"};import je from"@latticexyz/world/out/InitModule.sol/InitModule.json"assert{type:"json"};import xt from"@latticexyz/world/out/InitModule.sol/InitModule.abi.json"assert{type:"json"};import{getCreate2Address as z,encodeDeployData as Ct,size as L}from"viem";function G(e){let o=L(Ie.deployedBytecode.object),n=Ie.bytecode.object,r=z({from:e,bytecode:n,salt:x}),t=L(We.deployedBytecode.object),s=We.bytecode.object,i=z({from:e,bytecode:s,salt:x}),a=L(Re.deployedBytecode.object),l=Re.bytecode.object,d=z({from:e,bytecode:l,salt:x}),f=L(He.deployedBytecode.object),c=He.bytecode.object,y=z({from:e,bytecode:c,salt:x}),g=L(je.deployedBytecode.object),h=Ct({bytecode:je.bytecode.object,abi:xt,args:[r,i,d,y]}),w=z({from:e,bytecode:h,salt:x});return{AccessManagementSystem:{bytecode:n,deployedBytecodeSize:o,debugLabel:"access management system",address:r},BalanceTransferSystem:{bytecode:s,deployedBytecodeSize:t,debugLabel:"balance transfer system",address:i},BatchCallSystem:{bytecode:l,deployedBytecodeSize:a,debugLabel:"batch call system",address:d},RegistrationSystem:{bytecode:c,deployedBytecodeSize:f,debugLabel:"core registration system",address:y},InitModule:{bytecode:h,deployedBytecodeSize:g,debugLabel:"core module",address:w}}}function Q(e){let o=G(e),n=Dt($e.deployedBytecode.object),r=At({bytecode:$e.bytecode.object,abi:St,args:[o.InitModule.address]}),t=vt({from:e,bytecode:r,salt:x});return{...o,WorldFactory:{bytecode:r,deployedBytecodeSize:n,debugLabel:"world factory",address:t}}}import Ee from"@latticexyz/world/out/WorldProxyFactory.sol/WorldProxyFactory.json"assert{type:"json"};import Tt from"@latticexyz/world/out/WorldProxyFactory.sol/WorldProxyFactory.abi.json"assert{type:"json"};import{getCreate2Address as Pt,encodeDeployData as kt,size as Mt}from"viem";function Z(e){let o=G(e),n=Mt(Ee.deployedBytecode.object),r=kt({bytecode:Ee.bytecode.object,abi:Tt,args:[o.InitModule.address]}),t=Pt({from:e,bytecode:r,salt:x});return{...o,WorldProxyFactory:{bytecode:r,deployedBytecodeSize:n,debugLabel:"world proxy factory",address:t}}}async function X(e,o,n){if(n){let t=Z(o);return await P({client:e,deployerAddress:o,contracts:Object.values(t)}),t.WorldProxyFactory.address}let r=Q(o);return await P({client:e,deployerAddress:o,contracts:Object.values(r)}),r.WorldFactory.address}import Ht from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json"assert{type:"json"};import{writeContract as jt}from"@latticexyz/common";import{AbiEventSignatureNotFoundError as Ot,decodeEventLog as Bt,hexToString as Fe,parseAbi as It}from"viem";import{isDefined as Wt}from"@latticexyz/common/utils";function ee(e){let o=e.map(i=>{try{return{...i,...Bt({strict:!0,abi:It(Y),topics:i.topics,data:i.data})}}catch(a){if(a instanceof Ot)return;throw a}}).filter(Wt),{address:n,deployBlock:r,worldVersion:t,storeVersion:s}=o.reduce((i,a)=>({...i,address:a.address,deployBlock:a.blockNumber,...a.eventName==="HelloWorld"?{worldVersion:Fe(a.args.worldVersion).replace(/\0+$/,"")}:null,...a.eventName==="HelloStore"?{storeVersion:Fe(a.args.storeVersion).replace(/\0+$/,"")}:null}),{});if(n==null)throw new Error("could not find world address");if(r==null)throw new Error("could not find world deploy block number");if(t==null)throw new Error("could not find world version");if(s==null)throw new Error("could not find store version");return{address:n,deployBlock:r,worldVersion:t,storeVersion:s}}async function ze(e,o,n,r){let t=await X(e,o,r);p("deploying world");let s=await jt(e,{chain:e.chain??null,address:t,abi:Ht,functionName:"deployWorld",args:[n]});p("waiting for world deploy");let i=await Rt(e,{hash:s});if(i.status!=="success")throw console.error("world deploy failed",i),new Error("world deploy failed");let a=ee(i.logs);return p("deployed world to",a.address,"at block",a.deployBlock),{...a,stateBlock:a.deployBlock}}import{resourceToLabel as pe,writeContract as _t}from"@latticexyz/common";import{valueSchemaToFieldLayoutHex as Kt,keySchemaToHex as Jt,valueSchemaToHex as qt,getSchemaTypes as Ke,getValueSchema as Yt,getKeySchema as Gt}from"@latticexyz/protocol-parser/internal";import{parseAbiItem as $t,decodeAbiParameters as Le,parseAbiParameters as Ne}from"viem";import{hexToResource as Et}from"@latticexyz/common";import{storeSetRecordEvent as Ft}from"@latticexyz/store";import{getLogs as zt}from"viem/actions";import{decodeKey as Lt,decodeValueArgs as Nt,getKeySchema as Vt,getSchemaTypes as Ve,getValueSchema as Ut,hexToSchema as Ue}from"@latticexyz/protocol-parser/internal";import me from"@latticexyz/store/mud.config";async function _e({client:e,worldDeploy:o}){p("looking up tables for",o.address);let r=(await zt(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:$t(Ft),args:{tableId:me.namespaces.store.tables.Tables.tableId}})).map(t=>{let{tableId:s}=Lt(Ve(Vt(me.namespaces.store.tables.Tables)),t.args.keyTuple),{type:i,namespace:a,name:l}=Et(s),d=Nt(Ve(Ut(me.namespaces.store.tables.Tables)),t.args),f=Ue(d.keySchema),c=Ue(d.valueSchema),y=Le(Ne("string[]"),d.abiEncodedKeyNames)[0],g=Le(Ne("string[]"),d.abiEncodedFieldNames)[0],h=[...c.staticFields,...c.dynamicFields],w=Object.fromEntries(f.staticFields.map((u,S)=>[y[S],{type:u,internalType:u}])),v=Object.fromEntries(h.map((u,S)=>[g[S],{type:u,internalType:u}]));return{type:i,namespace:a,name:l,tableId:s,schema:{...w,...v},key:Object.keys(w)}});return p("found",r.length,"tables for",o.address),r}import Qt from"p-retry";async function Je({client:e,worldDeploy:o,tables:n}){let t=(await _e({client:e,worldDeploy:o})).map(a=>a.tableId),s=n.filter(a=>t.includes(a.tableId));s.length&&p("existing tables:",s.map(pe).join(", "));let i=n.filter(a=>!t.includes(a.tableId));return i.length?(p("registering tables:",i.map(pe).join(", ")),await Promise.all(i.map(a=>{let l=Ke(Gt(a)),d=Ke(Yt(a));return Qt(()=>_t(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerTable",args:[a.tableId,Kt(d),Jt(l),qt(d),Object.keys(l),Object.keys(d)]}),{retries:3,onFailedAttempt:()=>p(`failed to register table ${pe(a)}, retrying...`)})}))):[]}import{getAddress as O}from"viem";import{writeContract as ye,resourceToLabel as N}from"@latticexyz/common";import{hexToResource as gr,resourceToLabel as br}from"@latticexyz/common";import{getFunctions as hr}from"@latticexyz/world/internal";import{parseAbiItem as Zt,HttpRequestError as Xt}from"viem";import{getLogs as er}from"viem/actions";import{storeSpliceStaticDataEvent as or}from"@latticexyz/store";import tr from"p-retry";import rr from"@latticexyz/store/mud.config";async function oe({client:e,worldDeploy:o}){p("looking up resource IDs for",o.address);let r=(await tr(()=>er(e,{strict:!0,address:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock,event:Zt(or),args:{tableId:rr.namespaces.store.tables.ResourceIds.tableId}}),{retries:3,onFailedAttempt:async t=>{if(!(t instanceof Xt&&t.status===400&&t.message.includes("block is out of range")))throw t}})).map(t=>t.args.keyTuple[0]);return p("found",r.length,"resource IDs for",o.address),r}import{decodeValueArgs as nr,encodeKey as sr,getKeySchema as ar,getSchemaTypes as qe,getValueSchema as ir}from"@latticexyz/protocol-parser/internal";import{readContract as dr}from"viem/actions";async function R({client:e,worldDeploy:o,table:n,key:r}){let[t,s,i]=await dr(e,{blockNumber:o.stateBlock,address:o.address,abi:C,functionName:"getRecord",args:[n.tableId,sr(qe(ar(n)),r)]});return nr(qe(ir(n)),{staticData:t,encodedLengths:s,dynamicData:i})}import{parseAbiItem as lr,getAddress as cr}from"viem";import{storeSpliceStaticDataEvent as mr}from"@latticexyz/store";import{getLogs as pr}from"viem/actions";import{decodeKey as fr,getKeySchema as yr,getSchemaTypes as ur}from"@latticexyz/protocol-parser/internal";import fe from"@latticexyz/world/mud.config";async function te({client:e,worldDeploy:o}){p("looking up resource access for",o.address);let r=(await pr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:lr(mr),args:{tableId:fe.namespaces.world.tables.ResourceAccess.tableId}})).map(s=>fr(ur(yr(fe.namespaces.world.tables.ResourceAccess)),s.args.keyTuple)),t=(await Promise.all(r.map(async s=>[s,await R({client:e,worldDeploy:o,table:fe.namespaces.world.tables.ResourceAccess,key:s})]))).filter(([,s])=>s.access).map(([s])=>({resourceId:s.resourceId,address:cr(s.caller)}));return p("found",t.length,"resource<>address access pairs"),t}import wr from"@latticexyz/world/mud.config";async function Ye({client:e,worldDeploy:o}){let[n,r,t]=await Promise.all([oe({client:e,worldDeploy:o}),hr({client:e,worldAddress:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock}),te({client:e,worldDeploy:o})]),s=n.map(gr).filter(i=>i.type==="system");return p("looking up systems:",s.map(br).join(", ")),await Promise.all(s.map(async i=>{let{system:a,publicAccess:l}=await R({client:e,worldDeploy:o,table:wr.namespaces.world.tables.Systems,key:{systemId:i.resourceId}}),d=r.filter(f=>f.systemId===i.resourceId);return{address:a,namespace:i.namespace,name:i.name,systemId:i.resourceId,allowAll:l,allowedAddresses:t.filter(({resourceId:f})=>f===i.resourceId).map(({address:f})=>f),worldFunctions:d}}))}import ue from"p-retry";async function Ge({client:e,deployerAddress:o,libraries:n,worldDeploy:r,systems:t}){let[s,i]=await Promise.all([Ye({client:e,worldDeploy:r}),te({client:e,worldDeploy:r})]),a=t.filter(m=>s.some(b=>b.systemId===m.systemId&&O(b.address)===O(m.prepareDeploy(o,n).address)));a.length&&p("existing systems:",a.map(N).join(", "));let l=a.map(m=>m.systemId),d=t.filter(m=>!l.includes(m.systemId));if(!d.length)return[];let f=d.filter(m=>s.some(b=>b.systemId===m.systemId&&O(b.address)!==O(m.prepareDeploy(o,n).address)));f.length&&p("upgrading systems:",f.map(N).join(", "));let c=d.filter(m=>!s.some(b=>b.systemId===m.systemId));c.length&&p("registering new systems:",c.map(N).join(", ")),await P({client:e,deployerAddress:o,contracts:d.map(m=>({bytecode:m.prepareDeploy(o,n).bytecode,deployedBytecodeSize:m.deployedBytecodeSize,debugLabel:`${N(m)} system`}))});let y=await Promise.all(d.map(m=>ue(()=>ye(e,{chain:e.chain??null,address:r.address,abi:C,functionName:"registerSystem",args:[m.systemId,m.prepareDeploy(o,n).address,m.allowAll]}),{retries:3,onFailedAttempt:()=>p(`failed to register system ${N(m)}, retrying...`)}))),g=t.map(m=>m.systemId),h=i.filter(({resourceId:m})=>g.includes(m)),w=[...t.flatMap(m=>m.allowedAddresses.map(b=>({resourceId:m.systemId,address:b}))),...t.flatMap(m=>m.allowedSystemIds.map(b=>({resourceId:m.systemId,address:s.find(T=>T.systemId===b)?.address??t.find(T=>T.systemId===b)?.prepareDeploy(o,n).address})).filter(b=>b.address!=null))],v=w.filter(m=>!h.some(({resourceId:b,address:T})=>b===m.resourceId&&O(T)===O(m.address))),u=h.filter(m=>!w.some(({resourceId:b,address:T})=>b===m.resourceId&&O(T)===O(m.address)));u.length&&p("revoking",u.length,"access grants"),v.length&&p("adding",v.length,"access grants");let S=await Promise.all([...u.map(m=>ue(()=>ye(e,{chain:e.chain??null,address:r.address,abi:C,functionName:"revokeAccess",args:[m.resourceId,m.address]}),{retries:3,onFailedAttempt:()=>p("failed to revoke access, retrying...")})),...v.map(m=>ue(()=>ye(e,{chain:e.chain??null,address:r.address,abi:C,functionName:"grantAccess",args:[m.resourceId,m.address]}),{retries:3,onFailedAttempt:()=>p("failed to grant access, retrying...")}))]);return[...y,...S]}import{getAddress as xr,parseAbi as Cr}from"viem";import{getBlockNumber as Sr,getLogs as vr}from"viem/actions";var Qe=new Map;async function Ze(e,o){let n=xr(o),r=Qe.get(n);if(r!=null)return r;p("looking up world deploy for",n);let t=await Sr(e),s=await vr(e,{strict:!0,address:n,events:Cr(Y),fromBlock:"earliest",toBlock:t});return r={...ee(s),stateBlock:t},Qe.set(n,r),p("found world deploy for",n,"at block",r.deployBlock),r}import{hexToResource as Ar,writeContract as Dr}from"@latticexyz/common";import{getFunctions as Tr}from"@latticexyz/world/internal";import Pr from"p-retry";async function Xe({client:e,worldDeploy:o,functions:n}){let r=await Tr({client:e,worldAddress:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock}),t=Object.fromEntries(r.map(a=>[a.selector,a])),s=n.filter(a=>t[a.selector]),i=n.filter(a=>!s.includes(a));if(s.length){p("functions already registered:",s.map(l=>l.signature).join(", "));let a=s.filter(l=>l.systemId!==t[l.selector]?.systemId);a.length&&console.warn("found",a.length,"functions already registered but pointing at a different system ID:",a.map(l=>l.signature).join(", "))}return i.length?(p("registering functions:",i.map(a=>a.signature).join(", ")),Promise.all(i.map(a=>{let{namespace:l}=Ar(a.systemId),d=l===""?{functionName:"registerRootFunctionSelector",args:[a.systemId,a.systemFunctionSignature,a.systemFunctionSignature]}:{functionName:"registerFunctionSelector",args:[a.systemId,a.systemFunctionSignature]};return Pr(()=>Dr(e,{chain:e.chain??null,address:o.address,abi:C,...d}),{retries:3,onFailedAttempt:()=>p(`failed to register function ${a.signature}, retrying...`)})}))):[]}import{BaseError as kr}from"viem";import{writeContract as Mr}from"@latticexyz/common";import{isDefined as Or}from"@latticexyz/common/utils";import Br from"p-retry";async function re({client:e,deployerAddress:o,libraries:n,worldDeploy:r,modules:t}){return t.length?(await P({client:e,deployerAddress:o,contracts:t.map(s=>({bytecode:s.prepareDeploy(o,n).bytecode,deployedBytecodeSize:s.deployedBytecodeSize,debugLabel:`${s.name} module`}))}),p("installing modules:",t.map(s=>s.name).join(", ")),(await Promise.all(t.map(s=>Br(async()=>{try{let i=[...C,...s.abi],a=s.prepareDeploy(o,n).address,l=s.installAsRoot?{functionName:"installRootModule",args:[a,s.installData]}:{functionName:"installModule",args:[a,s.installData]};return Mr(e,{chain:e.chain??null,address:r.address,abi:i,...l})}catch(i){if(i instanceof kr&&i.message.includes("Module_AlreadyInstalled")){p(`module ${s.name} already installed`);return}if(s.optional){p(`optional module ${s.name} install failed, skipping`),p(i);return}throw i}},{retries:3,onFailedAttempt:()=>p(`failed to install module ${s.name}, retrying...`)})))).filter(Or)):[]}import{getAddress as eo}from"viem";import{hexToResource as oo,resourceToHex as to,writeContract as Ir}from"@latticexyz/common";import Wr from"@latticexyz/world/mud.config";async function ro({client:e,worldDeploy:o,resourceIds:n}){let r=Array.from(new Set(n.map(c=>oo(c).namespace))),t=await oe({client:e,worldDeploy:o}),s=new Set(t.map(c=>oo(c).namespace));s.size&&p("found",s.size,"existing namespaces:",Array.from(s).map(c=>c===""?"<root>":c).join(", "));let i=r.filter(c=>s.has(c)),l=(await Promise.all(i.map(async c=>{let{owner:y}=await R({client:e,worldDeploy:o,table:Wr.namespaces.world.tables.NamespaceOwner,key:{namespaceId:to({type:"namespace",namespace:c,name:""})}});return[c,y]}))).filter(([,c])=>eo(c)!==eo(e.account.address)).map(([c])=>c);if(l.length)throw new Error(`You are attempting to deploy to namespaces you do not own: ${l.join(", ")}`);let d=r.filter(c=>!s.has(c));return d.length>0&&p("registering namespaces:",Array.from(d).join(", ")),Promise.all(d.map(c=>Ir(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerNamespace",args:[to({namespace:c,type:"namespace",name:""})]})))}import{resourceToLabel as en}from"@latticexyz/common";import{randomBytes as on}from"crypto";import{stringToHex as ao,BaseError as Kr}from"viem";import{hexToResource as Jr,writeContract as qr}from"@latticexyz/common";import{identity as Yr,isDefined as io}from"@latticexyz/common/utils";import Gr from"@latticexyz/world-module-metadata/mud.config";import Qr from"@latticexyz/world-module-metadata/out/IMetadataSystem.sol/IMetadataSystem.abi.json"assert{type:"json"};import{decodeValueArgs as Rr,getKeyTuple as Hr,getSchemaTypes as jr,getValueSchema as $r}from"@latticexyz/protocol-parser/internal";import{readContract as Er}from"viem/actions";import{mapObject as Fr}from"@latticexyz/common/utils";async function no({client:e,worldDeploy:o,table:n,key:r}){let[t,s,i]=await Er(e,{blockNumber:o.stateBlock,address:o.address,abi:C,functionName:"getRecord",args:[n.tableId,Hr(n,r)]}),a={...r,...Rr(jr($r(n)),{staticData:t,encodedLengths:s,dynamicData:i})};return Fr(n.schema,(l,d)=>a[d])}import Zr from"@latticexyz/world-module-metadata/out/MetadataModule.sol/MetadataModule.json"assert{type:"json"};import{isHex as zr,size as Lr}from"viem";function ne(e){return Object.entries(e).flatMap(([o,n])=>Object.entries(n).flatMap(([r,t])=>t.map(s=>({path:o,name:r,start:s.start,length:s.length}))))}import{z as k}from"zod";import{Abi as Nr}from"abitype/zod";var so=k.object({object:k.string().refine(zr),linkReferences:k.record(k.record(k.array(k.object({start:k.number(),length:k.number()}))))}),Vr=k.object({bytecode:so,deployedBytecode:so,abi:Nr});function se(e){let o=Vr.parse(e),n=ne(o.bytecode.linkReferences);return{abi:o.abi,bytecode:o.bytecode.object,placeholders:n,deployedBytecodeSize:Lr(o.deployedBytecode.object)}}import{spliceHex as Ur}from"@latticexyz/common";import{getCreate2Address as _r}from"viem";function I(e,o){return function(r,t){let s=e;for(let i of o){let a=t.find(l=>l.path===i.path&&l.name===i.name);if(!a)throw new Error(`Could not find library for bytecode placeholder ${i.path}:${i.name}`);s=Ur(s,i.start,i.length,a.prepareDeploy(r,t).address)}return{bytecode:s,address:_r({from:r,bytecode:s,salt:x})}}}var ae=se(Zr);async function lo({client:e,deployerAddress:o,libraries:n,worldDeploy:r,tags:t,valueToHex:s=Yr}){let i=(await Promise.all(t.map(async l=>{let{value:d}=await no({client:e,worldDeploy:r,table:Gr.tables.metadata__ResourceTag,key:{resource:l.resourceId,tag:ao(l.tag,{size:32})}});if(d!==s(l.value))return l}))).filter(io);if(i.length===0)return[];let a=await re({client:e,deployerAddress:o,worldDeploy:r,libraries:n,modules:[{optional:!0,name:"MetadataModule",installAsRoot:!1,installData:"0x",prepareDeploy:I(ae.bytecode,ae.placeholders),deployedBytecodeSize:ae.deployedBytecodeSize,abi:ae.abi}]});return await M({client:e,hashes:a,debugLabel:"metadata module installation"}),p("setting",i.length,"resource tags"),(await Promise.all(i.map(async l=>{let d=Jr(l.resourceId),f=`${d.type}:${d.namespace}:${d.name}`;p(`tagging ${f} with ${l.tag}: ${JSON.stringify(l.value)}`);try{return await qr(e,{chain:e.chain??null,address:r.address,abi:Qr,functionName:"metadata__setResourceTag",args:[l.resourceId,ao(l.tag,{size:32}),s(l.value)]})}catch(c){p(`failed to set resource tag for ${f}, skipping
|
13
|
+
`),p("deploying",t,"at",s),[await bt(()=>gt(e,{chain:e.chain??null,to:o,data:ft([x,n])}),{retries:3,onFailedAttempt:()=>p(`failed to deploy ${t}, retrying...`)})])}import{uniqueBy as wt}from"@latticexyz/common/utils";import{waitForTransactionReceipt as ht}from"viem/actions";async function M({client:e,hashes:o,debugLabel:n="transactions"}){if(o.length){p(`waiting for ${n} to confirm`);for(let r of o)if((await ht(e,{hash:r})).status==="reverted")throw new Error(`Transaction reverted: ${r}`)}}async function P({client:e,deployerAddress:o,contracts:n}){let r=wt(n,s=>s.bytecode),t=(await Promise.all(r.map(s=>Be({client:e,deployerAddress:o,...s})))).flat();return await M({client:e,hashes:t,debugLabel:"contract deploys"}),t}import $e from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.json"assert{type:"json"};import St from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json"assert{type:"json"};import{getCreate2Address as vt,encodeDeployData as At,size as Dt}from"viem";import Ie from"@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json"assert{type:"json"};import We from"@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json"assert{type:"json"};import Re from"@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json"assert{type:"json"};import He from"@latticexyz/world/out/RegistrationSystem.sol/RegistrationSystem.json"assert{type:"json"};import je from"@latticexyz/world/out/InitModule.sol/InitModule.json"assert{type:"json"};import xt from"@latticexyz/world/out/InitModule.sol/InitModule.abi.json"assert{type:"json"};import{getCreate2Address as z,encodeDeployData as Ct,size as L}from"viem";function G(e){let o=L(Ie.deployedBytecode.object),n=Ie.bytecode.object,r=z({from:e,bytecode:n,salt:x}),t=L(We.deployedBytecode.object),s=We.bytecode.object,i=z({from:e,bytecode:s,salt:x}),a=L(Re.deployedBytecode.object),l=Re.bytecode.object,d=z({from:e,bytecode:l,salt:x}),f=L(He.deployedBytecode.object),c=He.bytecode.object,y=z({from:e,bytecode:c,salt:x}),g=L(je.deployedBytecode.object),h=Ct({bytecode:je.bytecode.object,abi:xt,args:[r,i,d,y]}),w=z({from:e,bytecode:h,salt:x});return{AccessManagementSystem:{bytecode:n,deployedBytecodeSize:o,debugLabel:"access management system",address:r},BalanceTransferSystem:{bytecode:s,deployedBytecodeSize:t,debugLabel:"balance transfer system",address:i},BatchCallSystem:{bytecode:l,deployedBytecodeSize:a,debugLabel:"batch call system",address:d},RegistrationSystem:{bytecode:c,deployedBytecodeSize:f,debugLabel:"core registration system",address:y},InitModule:{bytecode:h,deployedBytecodeSize:g,debugLabel:"core module",address:w}}}function Q(e){let o=G(e),n=Dt($e.deployedBytecode.object),r=At({bytecode:$e.bytecode.object,abi:St,args:[o.InitModule.address]}),t=vt({from:e,bytecode:r,salt:x});return{...o,WorldFactory:{bytecode:r,deployedBytecodeSize:n,debugLabel:"world factory",address:t}}}import Ee from"@latticexyz/world/out/WorldProxyFactory.sol/WorldProxyFactory.json"assert{type:"json"};import Tt from"@latticexyz/world/out/WorldProxyFactory.sol/WorldProxyFactory.abi.json"assert{type:"json"};import{getCreate2Address as Pt,encodeDeployData as kt,size as Mt}from"viem";function Z(e){let o=G(e),n=Mt(Ee.deployedBytecode.object),r=kt({bytecode:Ee.bytecode.object,abi:Tt,args:[o.InitModule.address]}),t=Pt({from:e,bytecode:r,salt:x});return{...o,WorldProxyFactory:{bytecode:r,deployedBytecodeSize:n,debugLabel:"world proxy factory",address:t}}}async function X(e,o,n){if(n){let t=Z(o);return await P({client:e,deployerAddress:o,contracts:Object.values(t)}),t.WorldProxyFactory.address}let r=Q(o);return await P({client:e,deployerAddress:o,contracts:Object.values(r)}),r.WorldFactory.address}import Ht from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json"assert{type:"json"};import{writeContract as jt}from"@latticexyz/common";import{AbiEventSignatureNotFoundError as Ot,decodeEventLog as Bt,hexToString as Fe,parseAbi as It}from"viem";import{isDefined as Wt}from"@latticexyz/common/utils";function ee(e){let o=e.map(i=>{try{return{...i,...Bt({strict:!0,abi:It(Y),topics:i.topics,data:i.data})}}catch(a){if(a instanceof Ot)return;throw a}}).filter(Wt),{address:n,deployBlock:r,worldVersion:t,storeVersion:s}=o.reduce((i,a)=>({...i,address:a.address,deployBlock:a.blockNumber,...a.eventName==="HelloWorld"?{worldVersion:Fe(a.args.worldVersion).replace(/\0+$/,"")}:null,...a.eventName==="HelloStore"?{storeVersion:Fe(a.args.storeVersion).replace(/\0+$/,"")}:null}),{});if(n==null)throw new Error("could not find world address");if(r==null)throw new Error("could not find world deploy block number");if(t==null)throw new Error("could not find world version");if(s==null)throw new Error("could not find store version");return{address:n,deployBlock:r,worldVersion:t,storeVersion:s}}async function ze(e,o,n,r){let t=await X(e,o,r);p("deploying world");let s=await jt(e,{chain:e.chain??null,address:t,abi:Ht,functionName:"deployWorld",args:[n]});p("waiting for world deploy");let i=await Rt(e,{hash:s});if(i.status!=="success")throw console.error("world deploy failed",i),new Error("world deploy failed");let a=ee(i.logs);return p("deployed world to",a.address,"at block",a.deployBlock),{...a,stateBlock:a.deployBlock}}import{resourceToLabel as pe,writeContract as _t}from"@latticexyz/common";import{valueSchemaToFieldLayoutHex as Kt,keySchemaToHex as Jt,valueSchemaToHex as qt,getSchemaTypes as Ke,getValueSchema as Yt,getKeySchema as Gt}from"@latticexyz/protocol-parser/internal";import{parseAbiItem as $t,decodeAbiParameters as Le,parseAbiParameters as Ne}from"viem";import{hexToResource as Et}from"@latticexyz/common";import{storeSetRecordEvent as Ft}from"@latticexyz/store";import{getLogs as zt}from"viem/actions";import{decodeKey as Lt,decodeValueArgs as Nt,getKeySchema as Vt,getSchemaTypes as Ve,getValueSchema as Ut,hexToSchema as Ue}from"@latticexyz/protocol-parser/internal";import me from"@latticexyz/store/mud.config";async function _e({client:e,worldDeploy:o}){p("looking up tables for",o.address);let r=(await zt(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:$t(Ft),args:{tableId:me.namespaces.store.tables.Tables.tableId}})).map(t=>{let{tableId:s}=Lt(Ve(Vt(me.namespaces.store.tables.Tables)),t.args.keyTuple),{type:i,namespace:a,name:l}=Et(s),d=Nt(Ve(Ut(me.namespaces.store.tables.Tables)),t.args),f=Ue(d.keySchema),c=Ue(d.valueSchema),y=Le(Ne("string[]"),d.abiEncodedKeyNames)[0],g=Le(Ne("string[]"),d.abiEncodedFieldNames)[0],h=[...c.staticFields,...c.dynamicFields],w=Object.fromEntries(f.staticFields.map((u,S)=>[y[S],{type:u,internalType:u}])),v=Object.fromEntries(h.map((u,S)=>[g[S],{type:u,internalType:u}]));return{type:i,namespace:a,name:l,tableId:s,schema:{...w,...v},key:Object.keys(w)}});return p("found",r.length,"tables for",o.address),r}import Qt from"p-retry";async function Je({client:e,worldDeploy:o,tables:n}){let t=(await _e({client:e,worldDeploy:o})).map(a=>a.tableId),s=n.filter(a=>t.includes(a.tableId));s.length&&p("existing tables:",s.map(pe).join(", "));let i=n.filter(a=>!t.includes(a.tableId));return i.length?(p("registering tables:",i.map(pe).join(", ")),await Promise.all(i.map(a=>{let l=Ke(Gt(a)),d=Ke(Yt(a));return Qt(()=>_t(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerTable",args:[a.tableId,Kt(d),Jt(l),qt(d),Object.keys(l),Object.keys(d)]}),{retries:3,onFailedAttempt:()=>p(`failed to register table ${pe(a)}, retrying...`)})}))):[]}import{getAddress as O}from"viem";import{writeContract as ye,resourceToLabel as N}from"@latticexyz/common";import{hexToResource as gr,resourceToLabel as br}from"@latticexyz/common";import{getFunctions as hr}from"@latticexyz/world/internal";import{parseAbiItem as Zt,HttpRequestError as Xt}from"viem";import{getLogs as er}from"viem/actions";import{storeSpliceStaticDataEvent as or}from"@latticexyz/store";import tr from"p-retry";import rr from"@latticexyz/store/mud.config";async function oe({client:e,worldDeploy:o}){p("looking up resource IDs for",o.address);let r=(await tr(()=>er(e,{strict:!0,address:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock,event:Zt(or),args:{tableId:rr.namespaces.store.tables.ResourceIds.tableId}}),{retries:3,onFailedAttempt:async t=>{if(!(t instanceof Xt&&t.status===400&&t.message.includes("block is out of range")))throw t}})).map(t=>t.args.keyTuple[0]);return p("found",r.length,"resource IDs for",o.address),r}import{decodeValueArgs as nr,encodeKey as sr,getKeySchema as ar,getSchemaTypes as qe,getValueSchema as ir}from"@latticexyz/protocol-parser/internal";import{readContract as dr}from"viem/actions";async function R({client:e,worldDeploy:o,table:n,key:r}){let[t,s,i]=await dr(e,{blockNumber:o.stateBlock,address:o.address,abi:C,functionName:"getRecord",args:[n.tableId,sr(qe(ar(n)),r)]});return nr(qe(ir(n)),{staticData:t,encodedLengths:s,dynamicData:i})}import{parseAbiItem as lr,getAddress as cr}from"viem";import{storeSpliceStaticDataEvent as mr}from"@latticexyz/store";import{getLogs as pr}from"viem/actions";import{decodeKey as fr,getKeySchema as yr,getSchemaTypes as ur}from"@latticexyz/protocol-parser/internal";import fe from"@latticexyz/world/mud.config";async function te({client:e,worldDeploy:o}){p("looking up resource access for",o.address);let r=(await pr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:lr(mr),args:{tableId:fe.namespaces.world.tables.ResourceAccess.tableId}})).map(s=>fr(ur(yr(fe.namespaces.world.tables.ResourceAccess)),s.args.keyTuple)),t=(await Promise.all(r.map(async s=>[s,await R({client:e,worldDeploy:o,table:fe.namespaces.world.tables.ResourceAccess,key:s})]))).filter(([,s])=>s.access).map(([s])=>({resourceId:s.resourceId,address:cr(s.caller)}));return p("found",t.length,"resource<>address access pairs"),t}import wr from"@latticexyz/world/mud.config";async function Ye({client:e,worldDeploy:o}){let[n,r,t]=await Promise.all([oe({client:e,worldDeploy:o}),hr({client:e,worldAddress:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock}),te({client:e,worldDeploy:o})]),s=n.map(gr).filter(i=>i.type==="system");return p("looking up systems:",s.map(br).join(", ")),await Promise.all(s.map(async i=>{let{system:a,publicAccess:l}=await R({client:e,worldDeploy:o,table:wr.namespaces.world.tables.Systems,key:{systemId:i.resourceId}}),d=r.filter(f=>f.systemId===i.resourceId);return{address:a,namespace:i.namespace,name:i.name,systemId:i.resourceId,allowAll:l,allowedAddresses:t.filter(({resourceId:f})=>f===i.resourceId).map(({address:f})=>f),worldFunctions:d}}))}import ue from"p-retry";async function Ge({client:e,deployerAddress:o,libraries:n,worldDeploy:r,systems:t}){let[s,i]=await Promise.all([Ye({client:e,worldDeploy:r}),te({client:e,worldDeploy:r})]),a=t.filter(m=>s.some(b=>b.systemId===m.systemId&&O(b.address)===O(m.prepareDeploy(o,n).address)));a.length&&p("existing systems:",a.map(N).join(", "));let l=a.map(m=>m.systemId),d=t.filter(m=>!l.includes(m.systemId));if(!d.length)return[];let f=d.filter(m=>s.some(b=>b.systemId===m.systemId&&O(b.address)!==O(m.prepareDeploy(o,n).address)));f.length&&p("upgrading systems:",f.map(N).join(", "));let c=d.filter(m=>!s.some(b=>b.systemId===m.systemId));c.length&&p("registering new systems:",c.map(N).join(", ")),await P({client:e,deployerAddress:o,contracts:d.map(m=>({bytecode:m.prepareDeploy(o,n).bytecode,deployedBytecodeSize:m.deployedBytecodeSize,debugLabel:`${N(m)} system`}))});let y=await Promise.all(d.map(m=>ue(()=>ye(e,{chain:e.chain??null,address:r.address,abi:C,functionName:"registerSystem",args:[m.systemId,m.prepareDeploy(o,n).address,m.allowAll]}),{retries:3,onFailedAttempt:()=>p(`failed to register system ${N(m)}, retrying...`)}))),g=t.map(m=>m.systemId),h=i.filter(({resourceId:m})=>g.includes(m)),w=[...t.flatMap(m=>m.allowedAddresses.map(b=>({resourceId:m.systemId,address:b}))),...t.flatMap(m=>m.allowedSystemIds.map(b=>({resourceId:m.systemId,address:s.find(T=>T.systemId===b)?.address??t.find(T=>T.systemId===b)?.prepareDeploy(o,n).address})).filter(b=>b.address!=null))],v=w.filter(m=>!h.some(({resourceId:b,address:T})=>b===m.resourceId&&O(T)===O(m.address))),u=h.filter(m=>!w.some(({resourceId:b,address:T})=>b===m.resourceId&&O(T)===O(m.address)));u.length&&p("revoking",u.length,"access grants"),v.length&&p("adding",v.length,"access grants");let S=await Promise.all([...u.map(m=>ue(()=>ye(e,{chain:e.chain??null,address:r.address,abi:C,functionName:"revokeAccess",args:[m.resourceId,m.address]}),{retries:3,onFailedAttempt:()=>p("failed to revoke access, retrying...")})),...v.map(m=>ue(()=>ye(e,{chain:e.chain??null,address:r.address,abi:C,functionName:"grantAccess",args:[m.resourceId,m.address]}),{retries:3,onFailedAttempt:()=>p("failed to grant access, retrying...")}))]);return[...y,...S]}import{getAddress as xr,parseAbi as Cr}from"viem";import{getBlockNumber as Sr,getLogs as vr}from"viem/actions";var Qe=new Map;async function Ze(e,o){let n=xr(o),r=Qe.get(n);if(r!=null)return r;p("looking up world deploy for",n);let t=await Sr(e),s=await vr(e,{strict:!0,address:n,events:Cr(Y),fromBlock:"earliest",toBlock:t});return r={...ee(s),stateBlock:t},Qe.set(n,r),p("found world deploy for",n,"at block",r.deployBlock),r}import{hexToResource as Ar,writeContract as Dr}from"@latticexyz/common";import{getFunctions as Tr}from"@latticexyz/world/internal";import Pr from"p-retry";async function Xe({client:e,worldDeploy:o,functions:n}){let r=await Tr({client:e,worldAddress:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock}),t=Object.fromEntries(r.map(a=>[a.selector,a])),s=n.filter(a=>t[a.selector]),i=n.filter(a=>!s.includes(a));if(s.length){p("functions already registered:",s.map(l=>l.signature).join(", "));let a=s.filter(l=>l.systemId!==t[l.selector]?.systemId);a.length&&console.warn("found",a.length,"functions already registered but pointing at a different system ID:",a.map(l=>l.signature).join(", "))}return i.length?(p("registering functions:",i.map(a=>a.signature).join(", ")),Promise.all(i.map(a=>{let{namespace:l}=Ar(a.systemId),d=l===""?{functionName:"registerRootFunctionSelector",args:[a.systemId,a.systemFunctionSignature,a.systemFunctionSignature]}:{functionName:"registerFunctionSelector",args:[a.systemId,a.systemFunctionSignature]};return Pr(()=>Dr(e,{chain:e.chain??null,address:o.address,abi:C,...d}),{retries:3,onFailedAttempt:()=>p(`failed to register function ${a.signature}, retrying...`)})}))):[]}import{BaseError as kr}from"viem";import{writeContract as Mr}from"@latticexyz/common";import{isDefined as Or}from"@latticexyz/common/utils";import Br from"p-retry";async function re({client:e,deployerAddress:o,libraries:n,worldDeploy:r,modules:t}){return t.length?(await P({client:e,deployerAddress:o,contracts:t.map(s=>({bytecode:s.prepareDeploy(o,n).bytecode,deployedBytecodeSize:s.deployedBytecodeSize,debugLabel:`${s.name} module`}))}),p("installing modules:",t.map(s=>s.name).join(", ")),(await Promise.all(t.map(s=>Br(async()=>{try{let i=[...C,...s.abi],a=s.prepareDeploy(o,n).address,l=s.installAsRoot?{functionName:"installRootModule",args:[a,s.installData]}:{functionName:"installModule",args:[a,s.installData]};return await Mr(e,{chain:e.chain??null,address:r.address,abi:i,...l})}catch(i){if(i instanceof kr&&i.message.includes("Module_AlreadyInstalled")){p(`module ${s.name} already installed`);return}if(s.optional){p(`optional module ${s.name} install failed, skipping`),p(i);return}throw i}},{retries:3,onFailedAttempt:()=>p(`failed to install module ${s.name}, retrying...`)})))).filter(Or)):[]}import{getAddress as eo}from"viem";import{hexToResource as oo,resourceToHex as to,writeContract as Ir}from"@latticexyz/common";import Wr from"@latticexyz/world/mud.config";async function ro({client:e,worldDeploy:o,resourceIds:n}){let r=Array.from(new Set(n.map(c=>oo(c).namespace))),t=await oe({client:e,worldDeploy:o}),s=new Set(t.map(c=>oo(c).namespace));s.size&&p("found",s.size,"existing namespaces:",Array.from(s).map(c=>c===""?"<root>":c).join(", "));let i=r.filter(c=>s.has(c)),l=(await Promise.all(i.map(async c=>{let{owner:y}=await R({client:e,worldDeploy:o,table:Wr.namespaces.world.tables.NamespaceOwner,key:{namespaceId:to({type:"namespace",namespace:c,name:""})}});return[c,y]}))).filter(([,c])=>eo(c)!==eo(e.account.address)).map(([c])=>c);if(l.length)throw new Error(`You are attempting to deploy to namespaces you do not own: ${l.join(", ")}`);let d=r.filter(c=>!s.has(c));return d.length>0&&p("registering namespaces:",Array.from(d).join(", ")),Promise.all(d.map(c=>Ir(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerNamespace",args:[to({namespace:c,type:"namespace",name:""})]})))}import{resourceToLabel as en}from"@latticexyz/common";import{randomBytes as on}from"crypto";import{stringToHex as ao,BaseError as Kr}from"viem";import{hexToResource as Jr,writeContract as qr}from"@latticexyz/common";import{identity as Yr,isDefined as io}from"@latticexyz/common/utils";import Gr from"@latticexyz/world-module-metadata/mud.config";import Qr from"@latticexyz/world-module-metadata/out/IMetadataSystem.sol/IMetadataSystem.abi.json"assert{type:"json"};import{decodeValueArgs as Rr,getKeyTuple as Hr,getSchemaTypes as jr,getValueSchema as $r}from"@latticexyz/protocol-parser/internal";import{readContract as Er}from"viem/actions";import{mapObject as Fr}from"@latticexyz/common/utils";async function no({client:e,worldDeploy:o,table:n,key:r}){let[t,s,i]=await Er(e,{blockNumber:o.stateBlock,address:o.address,abi:C,functionName:"getRecord",args:[n.tableId,Hr(n,r)]}),a={...r,...Rr(jr($r(n)),{staticData:t,encodedLengths:s,dynamicData:i})};return Fr(n.schema,(l,d)=>a[d])}import Zr from"@latticexyz/world-module-metadata/out/MetadataModule.sol/MetadataModule.json"assert{type:"json"};import{isHex as zr,size as Lr}from"viem";function ne(e){return Object.entries(e).flatMap(([o,n])=>Object.entries(n).flatMap(([r,t])=>t.map(s=>({path:o,name:r,start:s.start,length:s.length}))))}import{z as k}from"zod";import{Abi as Nr}from"abitype/zod";var so=k.object({object:k.string().refine(zr),linkReferences:k.record(k.record(k.array(k.object({start:k.number(),length:k.number()}))))}),Vr=k.object({bytecode:so,deployedBytecode:so,abi:Nr});function se(e){let o=Vr.parse(e),n=ne(o.bytecode.linkReferences);return{abi:o.abi,bytecode:o.bytecode.object,placeholders:n,deployedBytecodeSize:Lr(o.deployedBytecode.object)}}import{spliceHex as Ur}from"@latticexyz/common";import{getCreate2Address as _r}from"viem";function I(e,o){return function(r,t){let s=e;for(let i of o){let a=t.find(l=>l.path===i.path&&l.name===i.name);if(!a)throw new Error(`Could not find library for bytecode placeholder ${i.path}:${i.name}`);s=Ur(s,i.start,i.length,a.prepareDeploy(r,t).address)}return{bytecode:s,address:_r({from:r,bytecode:s,salt:x})}}}var ae=se(Zr);async function lo({client:e,deployerAddress:o,libraries:n,worldDeploy:r,tags:t,valueToHex:s=Yr}){let i=(await Promise.all(t.map(async l=>{let{value:d}=await no({client:e,worldDeploy:r,table:Gr.tables.metadata__ResourceTag,key:{resource:l.resourceId,tag:ao(l.tag,{size:32})}});if(d!==s(l.value))return l}))).filter(io);if(i.length===0)return[];let a=await re({client:e,deployerAddress:o,worldDeploy:r,libraries:n,modules:[{optional:!0,name:"MetadataModule",installAsRoot:!1,installData:"0x",prepareDeploy:I(ae.bytecode,ae.placeholders),deployedBytecodeSize:ae.deployedBytecodeSize,abi:ae.abi}]});return await M({client:e,hashes:a,debugLabel:"metadata module installation"}),p("setting",i.length,"resource tags"),(await Promise.all(i.map(async l=>{let d=Jr(l.resourceId),f=`${d.type}:${d.namespace}:${d.name}`;p(`tagging ${f} with ${l.tag}: ${JSON.stringify(l.value)}`);try{return await qr(e,{chain:e.chain??null,address:r.address,abi:Qr,functionName:"metadata__setResourceTag",args:[l.resourceId,ao(l.tag,{size:32}),s(l.value)]})}catch(c){p(`failed to set resource tag for ${f}, skipping
|
14
14
|
${c instanceof Kr?c.shortMessage:c}`)}}))).filter(io)}async function co({client:e,tables:o,systems:n,libraries:r,modules:t=[],salt:s,worldAddress:i,deployerAddress:a,withWorldProxy:l}){let d=a??await ke(e);await X(e,d,l),await P({client:e,deployerAddress:d,contracts:[...r.map(m=>({bytecode:m.prepareDeploy(d,r).bytecode,deployedBytecodeSize:m.deployedBytecodeSize,debugLabel:`${m.path}:${m.name} library`})),...n.map(m=>({bytecode:m.prepareDeploy(d,r).bytecode,deployedBytecodeSize:m.deployedBytecodeSize,debugLabel:`${en(m)} system`})),...t.map(m=>({bytecode:m.prepareDeploy(d,r).bytecode,deployedBytecodeSize:m.deployedBytecodeSize,debugLabel:`${m.name} module`}))]});let f=i?await Ze(e,i):await ze(e,d,s??`0x${on(32).toString("hex")}`,l);if(!Me.includes(f.storeVersion))throw new Error(`Unsupported Store version: ${f.storeVersion}`);if(!Oe.includes(f.worldVersion))throw new Error(`Unsupported World version: ${f.worldVersion}`);let c=await ro({client:e,worldDeploy:f,resourceIds:[...o.map(({tableId:m})=>m),...n.map(({systemId:m})=>m)]});await M({client:e,hashes:c,debugLabel:"namespace registrations"});let y=await Je({client:e,worldDeploy:f,tables:o}),g=await Ge({client:e,deployerAddress:d,libraries:r,worldDeploy:f,systems:n});await M({client:e,hashes:[...y,...g],debugLabel:"table and system registrations"});let h=await Xe({client:e,worldDeploy:f,functions:n.flatMap(m=>m.worldFunctions)}),w=await re({client:e,deployerAddress:d,libraries:r,worldDeploy:f,modules:t}),v=o.map(({tableId:m,label:b})=>({resourceId:m,tag:"label",value:b})),u=n.flatMap(({systemId:m,label:b,abi:T,worldAbi:Ho})=>[{resourceId:m,tag:"label",value:b},{resourceId:m,tag:"abi",value:T.join(`
|
15
15
|
`)},{resourceId:m,tag:"worldAbi",value:Ho.join(`
|
16
16
|
`)}]),S=await lo({client:e,deployerAddress:d,libraries:r,worldDeploy:f,tags:[...v,...u],valueToHex:Xr});return await M({client:e,hashes:[...h,...w,...S],debugLabel:"remaining transactions"}),p("deploy complete"),f}import{createWalletClient as Pn,http as kn,isHex as Mn}from"viem";import{privateKeyToAccount as On}from"viem/accounts";import{loadConfig as Bn,resolveConfigPath as In}from"@latticexyz/config/node";import{getOutDirectory as Wn,getRpcUrl as Rn}from"@latticexyz/common/foundry";import j from"chalk";import{MUDError as be}from"@latticexyz/common/errors";import ln from"path";import{loadSystemsManifest as cn,resolveSystems as mn}from"@latticexyz/world/node";import{isHex as fo,toFunctionSelector as yo,toFunctionSignature as uo}from"viem";import{readFileSync as tn}from"fs";import rn from"path";import{MUDError as ie}from"@latticexyz/common/errors";import{size as nn}from"viem";function H(e,o,n){let r,t=rn.join(n,e,o+".json");try{r=JSON.parse(tn(t,"utf8"))}catch{throw new ie(`Error reading file at ${t}`)}let s=r?.bytecode?.object;if(!s)throw new ie(`No bytecode found in ${t}`);let i=r?.deployedBytecode?.object;if(!i)throw new ie(`No deployed bytecode found in ${t}`);let a=r?.abi;if(!a)throw new ie(`No ABI found in ${t}`);let l=ne(r?.bytecode?.linkReferences??{});return{abi:a,bytecode:s,placeholders:l,deployedBytecodeSize:nn(i)}}import{groupBy as pn}from"@latticexyz/common/utils";import{readFileSync as an}from"fs";import{globSync as dn}from"glob";import sn from"toposort";function mo(e,o,n){let r=sn(e.flatMap(t=>n(t).map(s=>[o(t),s])));return[...e].sort((t,s)=>r.indexOf(o(t))-r.indexOf(o(s)))}function po(e){let n=dn(`${e}/**/*.json`,{ignore:"**/*.abi.json"}).sort().map(r=>JSON.parse(an(r,"utf8"))).flatMap(r=>{if(!r.metadata)return[];let t=Object.keys(r.metadata.settings.compilationTarget)[0],s=r.metadata.settings.compilationTarget[t],i=r.bytecode.linkReferences;return Object.entries(i).flatMap(([a,l])=>Object.keys(l).map(d=>({path:a,name:d,dependentPath:t,dependentName:s})))});return mo(n,r=>`${r.path}:${r.name}`,r=>[`${r.dependentPath}:${r.dependentName}`])}async function go({rootDir:e,config:o,forgeOutDir:n}){let r=po(n).map(c=>{let y=H(ln.basename(c.path),c.name,n);return{path:c.path,name:c.name,abi:y.abi,prepareDeploy:I(y.bytecode,y.placeholders),deployedBytecodeSize:y.deployedBytecodeSize}}),s=H("System.sol","System",n).abi.filter(c=>c.type==="function").map(uo),i=await mn({rootDir:e,config:o}),a=await cn({rootDir:e,config:o}),l=i.filter(c=>!c.deploy.disabled).map(c=>{let y=a.systems.find(({systemId:u})=>u===c.systemId);if(!y)throw new Error(`System "${c.label}" not found in systems manifest. Run \`mud build\` before trying again.`);let g=H(`${c.label}.sol`,c.label,n),h=c.deploy.registerWorldFunctions?g.abi.filter(u=>u.type==="function").map(uo).filter(u=>!s.includes(u)).map(u=>{let S=c.namespace===""?u:`${c.namespace}__${u}`;return{signature:S,selector:yo(S),systemId:c.systemId,systemFunctionSignature:u,systemFunctionSelector:yo(u)}}):[],w=c.accessList.filter(u=>fo(u)),v=c.accessList.filter(u=>!fo(u)).map(u=>i.find(m=>m.label===u).systemId);return{...c,allowAll:c.openAccess,allowedAddresses:w,allowedSystemIds:v,prepareDeploy:I(g.bytecode,g.placeholders),deployedBytecodeSize:g.deployedBytecodeSize,worldFunctions:h,abi:y.abi,worldAbi:y.worldAbi}}),d=pn(l,c=>c.systemId),f=Array.from(d.values()).filter(c=>c.length>1).flat();if(f.length){let c=f.map(y=>y.name);throw new Error(`Found systems with overlapping system ID: ${c.join(", ")}.
|
@@ -39,4 +39,4 @@ Waiting for file changes\u2026
|
|
39
39
|
`))}}),Rs(Hs)).subscribe()}},Oo=$s;import{getCreate2Address as Bo,sliceHex as Fs,zeroHash as zs}from"viem";import{forge as Es}from"@latticexyz/common/foundry";async function W(e){let o=["verify-contract",e.address,e.name,"--rpc-url",e.rpc];e.verifier&&o.push("--verifier",e.verifier),e.verifierUrl&&o.push("--verifier-url",e.verifierUrl),await Es(o,{cwd:e.cwd})}import Ls from"p-queue";import{MUDError as Ns}from"@latticexyz/common/errors";import{getStorageAt as Vs}from"viem/actions";import{execa as xe}from"execa";var Us="0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";async function Io({client:e,rpc:o,systems:n,modules:r,worldAddress:t,deployerAddress:s,verifier:i,verifierUrl:a}){let l=s??await q(e);if(!l)throw new Ns("No deployer address provided or found.");let d=await Vs(e,{address:t,slot:Us}),f=d&&d!==zs,c=new Ls({concurrency:4});if(n.map(({name:y,bytecode:g})=>c.add(()=>W({name:y,rpc:o,verifier:i,verifierUrl:a,address:Bo({from:l,bytecode:g,salt:x})}).catch(h=>{console.error(`Error verifying system contract ${y}:`,h)}))),i==="sourcify")if(await xe("npm",["install"],{cwd:"node_modules/@latticexyz/store"}),await xe("npm",["install"],{cwd:"node_modules/@latticexyz/world"}),await xe("npm",["install"],{cwd:"node_modules/@latticexyz/world-modules"}),Object.entries(f?Z(l):Q(l)).map(([y,{bytecode:g}])=>c.add(()=>W({cwd:"node_modules/@latticexyz/world",name:y,rpc:o,verifier:i,verifierUrl:a,address:Bo({from:l,bytecode:g,salt:x})}).catch(h=>{console.error(`Error verifying world factory contract ${y}:`,h)}))),r.map(({name:y,prepareDeploy:g})=>{let{address:h}=g(l,[]);return c.add(()=>W({cwd:"node_modules/@latticexyz/world-modules",name:y,rpc:o,verifier:i,verifierUrl:a,address:h}).catch(w=>{console.error(`Error verifying module contract ${y}:`,w)}))}),f){let y=Fs(d,-20);c.add(()=>W({cwd:"node_modules/@latticexyz/world",name:"WorldProxy",rpc:o,verifier:i,verifierUrl:a,address:t}).catch(g=>{console.error("Error verifying WorldProxy contract:",g)})),c.add(()=>W({cwd:"node_modules/@latticexyz/world",name:"World",rpc:o,verifier:i,verifierUrl:a,address:y}).catch(g=>{console.error("Error verifying World contract:",g)}))}else c.add(()=>W({cwd:"node_modules/@latticexyz/world",name:"World",rpc:o,verifier:i,verifierUrl:a,address:t}).catch(y=>{console.error("Error verifying World contract:",y)}));else console.log(""),console.log(`Note: MUD is currently unable to verify store, world, and world-modules contracts with ${i}. We are planning to expand support in a future version.`),console.log("")}import{loadConfig as _s,resolveConfigPath as Ks}from"@latticexyz/config/node";import{resolveSystems as Js}from"@latticexyz/world/node";import{getOutDirectory as qs,getRpcUrl as Ys}from"@latticexyz/common/foundry";import{createWalletClient as Gs,http as Qs}from"viem";import Wo from"chalk";import Zs from"node:path";var Xs={deployerAddress:{type:"string",desc:"Deploy using an existing deterministic deployer (https://github.com/Arachnid/deterministic-deployment-proxy)"},worldAddress:{type:"string",required:!0,desc:"Verify an existing World at the given address"},configPath:{type:"string",desc:"Path to the MUD config file"},profile:{type:"string",desc:"The foundry profile to use"},rpc:{type:"string",desc:"The RPC URL to use. Defaults to the RPC url from the local foundry.toml"},rpcBatch:{type:"boolean",desc:"Enable batch processing of RPC requests in viem client (defaults to batch size of 100 and wait of 1s)"},verifier:{type:"string",desc:"The verifier to use. Defaults to blockscout",default:"blockscout"},verifierUrl:{type:"string",desc:"The verification provider."}},ea={command:"verify",describe:"Verify contracts",builder(e){return e.options(Xs)},async handler(e){let o=e.profile??process.env.FOUNDRY_PROFILE,n=await Ks(e.configPath),r=Zs.dirname(n),t=await _s(n),s=await qs(o),i=e.rpc??await Ys(o);console.log(Wo.bgBlue(Wo.whiteBright(`
|
40
40
|
Verifying MUD contracts${o?" with profile "+o:""} to RPC ${i}
|
41
41
|
`)));let a=Gs({transport:Qs(i,{batch:e.rpcBatch?{batchSize:100,wait:1e3}:void 0})}),d=(await Js({rootDir:r,config:t})).map(c=>{let y=H(`${c.name}.sol`,c.name,s);return{name:c.name,bytecode:y.bytecode}}),f=await de(t,s);await Io({client:a,rpc:i,systems:d,modules:f,deployerAddress:e.deployerAddress,worldAddress:e.worldAddress,verifier:e.verifier,verifierUrl:e.verifierUrl})}},Ro=ea;var fy=[Ce,xo,Se,oa,ve,Ae,Co,Do,To,Mo,Oo,ta,Ro];export{fy as commands};
|
42
|
-
//# sourceMappingURL=commands-
|
42
|
+
//# sourceMappingURL=commands-W3KPYFWX.js.map
|