@latticexyz/cli 2.0.0-main-444699a4 → 2.0.0-main-0a61cfac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-22IIKR4S.js → chunk-QXUPZVZL.js} +2 -2
- package/dist/chunk-QXUPZVZL.js.map +1 -0
- package/dist/{commands-GBVL6BUP.js → commands-OLS33STU.js} +3 -3
- package/dist/commands-OLS33STU.js.map +1 -0
- package/dist/errors-MZURIB7V.js +2 -0
- package/dist/mud.js +1 -1
- package/package.json +12 -12
- package/src/deploy/resolveConfig.ts +1 -1
- package/src/utils/errors.ts +1 -1
- package/dist/chunk-22IIKR4S.js.map +0 -1
- package/dist/commands-GBVL6BUP.js.map +0 -1
- package/dist/errors-XGN6V2Y3.js +0 -2
- /package/dist/{errors-XGN6V2Y3.js.map → errors-MZURIB7V.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"chalk";import{ZodError as s}from"zod";import{fromZodError as i,ValidationError as l}from"zod-validation-error";import{NotInsideProjectError as t}from"@latticexyz/config";import{MUDError as r}from"@latticexyz/common/errors";function p(o){if(o instanceof l)console.log(e.redBright(o.message));else if(o instanceof s){let n=i(o,{prefixSeparator:`
|
|
1
|
+
import e from"chalk";import{ZodError as s}from"zod";import{fromZodError as i,ValidationError as l}from"zod-validation-error";import{NotInsideProjectError as t}from"@latticexyz/config/library";import{MUDError as r}from"@latticexyz/common/errors";function p(o){if(o instanceof l)console.log(e.redBright(o.message));else if(o instanceof s){let n=i(o,{prefixSeparator:`
|
|
2
2
|
- `,issueSeparator:`
|
|
3
3
|
- `});console.log(e.redBright(n.message))}else o instanceof t?(console.log(e.red(o.message)),console.log(""),console.log(e.blue("To learn more about MUD's configuration, please go to https://mud.dev/packages/cli/"))):o instanceof r?console.log(e.red(o)):console.log(o)}export{p as a};
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
4
|
+
//# sourceMappingURL=chunk-QXUPZVZL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/errors.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport { ZodError } from \"zod\";\nimport { fromZodError, ValidationError } from \"zod-validation-error\";\nimport { NotInsideProjectError } from \"@latticexyz/config/library\";\nimport { MUDError } from \"@latticexyz/common/errors\";\n\nexport function logError(error: unknown) {\n if (error instanceof ValidationError) {\n console.log(chalk.redBright(error.message));\n } else if (error instanceof ZodError) {\n // TODO currently this error shouldn't happen, use `fromZodErrorCustom`\n // (see https://github.com/latticexyz/mud/issues/438)\n const validationError = fromZodError(error, {\n prefixSeparator: \"\\n- \",\n issueSeparator: \"\\n- \",\n });\n console.log(chalk.redBright(validationError.message));\n } else if (error instanceof NotInsideProjectError) {\n console.log(chalk.red(error.message));\n console.log(\"\");\n // TODO add docs to the website and update the link to the specific page\n // (see https://github.com/latticexyz/mud/issues/445)\n console.log(chalk.blue(`To learn more about MUD's configuration, please go to https://mud.dev/packages/cli/`));\n } else if (error instanceof MUDError) {\n console.log(chalk.red(error));\n } else {\n console.log(error);\n }\n}\n"],"mappings":"AAAA,OAAOA,MAAW,QAClB,OAAS,YAAAC,MAAgB,MACzB,OAAS,gBAAAC,EAAc,mBAAAC,MAAuB,uBAC9C,OAAS,yBAAAC,MAA6B,6BACtC,OAAS,YAAAC,MAAgB,4BAElB,SAASC,EAASC,EAAgB,CACvC,GAAIA,aAAiBJ,EACnB,QAAQ,IAAIH,EAAM,UAAUO,EAAM,OAAO,CAAC,UACjCA,aAAiBN,EAAU,CAGpC,IAAMO,EAAkBN,EAAaK,EAAO,CAC1C,gBAAiB;AAAA,IACjB,eAAgB;AAAA,GAClB,CAAC,EACD,QAAQ,IAAIP,EAAM,UAAUQ,EAAgB,OAAO,CAAC,OAC3CD,aAAiBH,GAC1B,QAAQ,IAAIJ,EAAM,IAAIO,EAAM,OAAO,CAAC,EACpC,QAAQ,IAAI,EAAE,EAGd,QAAQ,IAAIP,EAAM,KAAK,qFAAqF,CAAC,GACpGO,aAAiBF,EAC1B,QAAQ,IAAIL,EAAM,IAAIO,CAAK,CAAC,EAE5B,QAAQ,IAAIA,CAAK,CAErB","names":["chalk","ZodError","fromZodError","ValidationError","NotInsideProjectError","MUDError","logError","error","validationError"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as J}from"./chunk-
|
|
1
|
+
import{a as J}from"./chunk-QXUPZVZL.js";import ms from"@latticexyz/gas-report";import ps from"@latticexyz/abi-ts";import{loadConfig as Ko}from"@latticexyz/config/node";import{getSrcDirectory as Jo}from"@latticexyz/common/foundry";import{existsSync as $o,readFileSync as Wo,writeFileSync as Ho}from"node:fs";import ae from"node:path";import{tablegen as Eo}from"@latticexyz/store/codegen";import{worldgen as No}from"@latticexyz/world/node";import{forge as zo,getForgeConfig as Lo,getRemappings as Uo}from"@latticexyz/common/foundry";import Ro from"glob";import{basename as Mo}from"path";function I(e){return Ro.sync(`${e}/**/*.sol`).map(o=>({path:o,basename:Mo(o,".sol")}))}import he from"debug";var M=he("mud:cli"),Fo=he("mud:cli");M.log=console.debug.bind(console);Fo.log=console.error.bind(console);import{execa as Vo}from"execa";var _o=M.extend("runDeploy");async function q({config:e,srcDir:o,foundryProfile:r=process.env.FOUNDRY_PROFILE}){let t=ae.join(o,e.codegenDirectory),n=await Uo(r);await Promise.all([Eo(e,t,n),No(e,I(o),t)]);let s=await Lo(r);if(s.cache){let i=ae.join(s.cache_path,"solidity-files-cache.json");if($o(i)){_o("Unsetting cached content hash of IWorld.sol to force it to regenerate");let a=JSON.parse(Wo(i,"utf8")),m=ae.join(t,"world","IWorld.sol");a.files[m].contentHash="",Ho(i,JSON.stringify(a,null,2))}}await zo(["build"],{profile:r}),await Vo("mud",["abi-ts"],{stdio:"inherit"})}var qo={command:"build",describe:"Build contracts and generate MUD artifacts (table libraries, world interface, ABI)",builder(e){return e.options({configPath:{type:"string",desc:"Path to the config file"},profile:{type:"string",desc:"The foundry profile to use"}})},async handler({configPath:e,profile:o}){let r=await Ko(e),t=await Jo();await q({config:r,srcDir:t,foundryProfile:o}),process.exit(0)}},we=qo;import{rmSync as Yo}from"fs";import{homedir as Go}from"os";import Zo from"path";import{execa as Qo}from"execa";var Xo={command:"devnode",describe:"Start a local Ethereum node for development",builder(e){return e.options({blocktime:{type:"number",default:1,decs:"Interval in which new blocks are produced"}})},async handler({blocktime:e}){console.log("Clearing devnode history");let o=Go();Yo(Zo.join(o,".foundry","anvil","tmp"),{recursive:!0,force:!0});let r=["-b",String(e),"--block-base-fee-per-gas","0"];console.log(`Running: anvil ${r.join(" ")}`);let t=Qo("anvil",r,{stdio:["inherit","inherit","inherit"]});process.on("SIGINT",()=>{console.log(`
|
|
2
2
|
gracefully shutting down from SIGINT (Crtl-C)`),t.kill(),process.exit()}),await t}},xe=Xo;import{FaucetServiceDefinition as et}from"@latticexyz/services/faucet";import{createChannel as ot,createClient as tt}from"nice-grpc-web";import Se from"chalk";import{NodeHttpTransport as rt}from"@improbable-eng/grpc-web-node-http-transport";function nt(e){return tt(et,ot(e,rt()))}var st={command:"faucet",describe:"Interact with a MUD faucet",builder(e){return e.options({dripDev:{type:"boolean",desc:"Request a drip from the dev endpoint (requires faucet to have dev mode enabled)",default:!0},faucetUrl:{type:"string",desc:"URL of the MUD faucet",default:"https://faucet.testnet-mud-services.linfra.xyz"},address:{type:"string",desc:"Ethereum address to fund",required:!0}})},async handler({dripDev:e,faucetUrl:o,address:r}){let t=nt(o);e&&(console.log(Se.yellow("Dripping to",r)),await t.dripDev({address:r}),console.log(Se.yellow("Success"))),process.exit(0)}},Ce=st;var at={command:"hello <name>",describe:"Greet <name> with Hello",builder(e){return e.options({upper:{type:"boolean"}}).positional("name",{type:"string",demandOption:!0})},handler({name:e}){let o=`Gm, ${e}!`;console.log(o),process.exit(0)}},De=at;import it from"path";import{loadConfig as ct}from"@latticexyz/config/node";import{tablegen as dt}from"@latticexyz/store/codegen";import{getRemappings as lt,getSrcDirectory as mt}from"@latticexyz/common/foundry";var pt={command:"tablegen",describe:"Autogenerate MUD Store table libraries based on the config file",builder(e){return e.options({configPath:{type:"string",desc:"Path to the config file"}})},async handler({configPath:e}){let o=await ct(e),r=await mt(),t=await lt();await dt(o,it.join(r,o.codegenDirectory),t),process.exit(0)}},ve=pt;import fe from"node:path";import{existsSync as Qr,mkdirSync as Xr,readFileSync as en,writeFileSync as ye}from"node:fs";import{getBalance as ut,getBytecode as gt,sendRawTransaction as bt,sendTransaction as Te,waitForTransactionReceipt as Ae}from"viem/actions";var A={gasPrice:1e11,gasLimit:1e5,signerAddress:"3fab184622dc19b6109349b94811493bf2a45362",transaction:"f8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222",address:"4e59b44847b379578588920ca78fbf26c0b4956c",bytecode:"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"};var l=M.extend("deploy"),yt=M.extend("deploy");l.log=console.debug.bind(console);yt.log=console.error.bind(console);var R=`0x${A.address}`,ke=`0x${A.bytecode}`;async function Ie(e){let o=await gt(e,{address:R});if(o)return l("found CREATE2 deployer at",R),o!==ke&&console.warn(`
|
|
3
3
|
\u26A0\uFE0F Bytecode for deployer at ${R} did not match the expected CREATE2 bytecode. You may have unexpected results.
|
|
4
4
|
`),R;let r=BigInt(A.gasLimit)*BigInt(A.gasPrice),t=await ut(e,{address:`0x${A.signerAddress}`}),n=r-t;if(n>0){l("sending gas for CREATE2 deployer to signer at",A.signerAddress);let a=await Te(e,{chain:e.chain??null,to:`0x${A.signerAddress}`,value:n}),m=await Ae(e,{hash:a});if(m.status!=="success")throw console.error("failed to send gas to deployer signer",m),new Error("failed to send gas to deployer signer")}l("deploying CREATE2 deployer at",R);let s=await bt(e,{serializedTransaction:`0x${A.transaction}`}).catch(a=>{if(String(a).includes("only replay-protected (EIP-155) transactions allowed over RPC"))return console.warn(`
|
|
@@ -10,7 +10,7 @@ gracefully shutting down from SIGINT (Crtl-C)`),t.kill(),process.exit()}),await
|
|
|
10
10
|
Bytecode for ${n} (${t} bytes) is over the contract size limit (${U} bytes). Run \`forge build --sizes\` for more info.
|
|
11
11
|
`):t>U*.95&&console.warn(`
|
|
12
12
|
Bytecode for ${n} (${t} bytes) is almost over the contract size limit (${U} bytes). Run \`forge build --sizes\` for more info.
|
|
13
|
-
`),l("deploying",n,"at",s),[await Bt(()=>Pt(e,{chain:e.chain??null,to:o,data:At([v,r])}),{retries:3,onFailedAttempt:async a=>{let m=a.attemptNumber*500;l(`failed to deploy ${n}, retrying in ${m}ms...`),await Ot(m)}})])}import{uniqueBy as Rt}from"@latticexyz/common/utils";async function P({client:e,deployerAddress:o,contracts:r}){let t=Rt(r,s=>s.bytecode),n=(await Promise.all(t.map(s=>je({client:e,deployerAddress:o,...s})))).flat();if(n.length){l("waiting for contracts");for(let s of n)await jt(e,{hash:s})}return n}async function G(e,o){let r=W(Re.deployedBytecode.object),t=Re.bytecode.object,n=$({from:o,bytecode:t,salt:v}),s=W(Me.deployedBytecode.object),i=Me.bytecode.object,a=$({from:o,bytecode:i,salt:v}),m=W(Fe.deployedBytecode.object),c=Fe.bytecode.object,f=$({from:o,bytecode:c,salt:v}),y=W($e.deployedBytecode.object),x=$e.bytecode.object,C=$({from:o,bytecode:x,salt:v}),d=W(We.deployedBytecode.object),u=Ee({bytecode:We.bytecode.object,abi:Mt,args:[n,a,f,C]}),w=$({from:o,bytecode:u,salt:v}),g=W(He.deployedBytecode.object),D=Ee({bytecode:He.bytecode.object,abi:Ft,args:[w]}),p=$({from:o,bytecode:D,salt:v});return await P({client:e,deployerAddress:o,contracts:[{bytecode:t,deployedBytecodeSize:r,label:"access management system"},{bytecode:i,deployedBytecodeSize:s,label:"balance transfer system"},{bytecode:c,deployedBytecodeSize:m,label:"batch call system"},{bytecode:x,deployedBytecodeSize:y,label:"core registration system"},{bytecode:u,deployedBytecodeSize:d,label:"core module"},{bytecode:D,deployedBytecodeSize:g,label:"world factory"}]}),p}import zt from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json"assert{type:"json"};import{writeContract as Lt}from"@latticexyz/common";import{AbiEventSignatureNotFoundError as $t,decodeEventLog as Wt,hexToString as Ne,parseAbi as Ht}from"viem";import{isDefined as Et}from"@latticexyz/common/utils";function Z(e){let o=e.map(i=>{try{return{...i,...Wt({strict:!0,abi:Ht(Y),topics:i.topics,data:i.data})}}catch(a){if(a instanceof $t)return;throw a}}).filter(Et),{address:r,deployBlock:t,worldVersion:n,storeVersion:s}=o.reduce((i,a)=>({...i,address:a.address,deployBlock:a.blockNumber,...a.eventName==="HelloWorld"?{worldVersion:Ne(a.args.worldVersion).replace(/\0+$/,"")}:null,...a.eventName==="HelloStore"?{storeVersion:Ne(a.args.storeVersion).replace(/\0+$/,"")}:null}),{});if(r==null)throw new Error("could not find world address");if(t==null)throw new Error("could not find world deploy block number");if(n==null)throw new Error("could not find world version");if(s==null)throw new Error("could not find store version");return{address:r,deployBlock:t,worldVersion:n,storeVersion:s}}async function ze(e,o,r){let t=await G(e,o);l("deploying world");let n=await Lt(e,{chain:e.chain??null,address:t,abi:zt,functionName:"deployWorld",args:[r]});l("waiting for world deploy");let s=await Nt(e,{hash:n});if(s.status!=="success")throw console.error("world deploy failed",s),new Error("world deploy failed");let i=Z(s.logs.map(a=>a));return l("deployed world to",i.address,"at block",i.deployBlock),{...i,stateBlock:i.deployBlock}}import{resourceToLabel as ie,writeContract as Yt}from"@latticexyz/common";import{valueSchemaToFieldLayoutHex as Gt,keySchemaToHex as Zt,valueSchemaToHex as Qt}from"@latticexyz/protocol-parser";import{parseAbiItem as Ut,decodeAbiParameters as Le,parseAbiParameters as Ue}from"viem";import{hexToResource as Vt}from"@latticexyz/common";import{storeSetRecordEvent as _t}from"@latticexyz/store";import{getLogs as Kt}from"viem/actions";import{decodeKey as Jt,decodeValueArgs as qt,hexToSchema as Ve}from"@latticexyz/protocol-parser";async function _e({client:e,worldDeploy:o}){l("looking up tables for",o.address);let t=(await Kt(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:Ut(_t),args:{tableId:F.store_Tables.tableId}})).map(n=>{let{tableId:s}=Jt(F.store_Tables.keySchema,n.args.keyTuple),{namespace:i,name:a}=Vt(s),m=qt(F.store_Tables.valueSchema,n.args),c=Ve(m.keySchema),f=Ve(m.valueSchema),y=Le(Ue("string[]"),m.abiEncodedKeyNames)[0],x=Le(Ue("string[]"),m.abiEncodedFieldNames)[0],C=[...f.staticFields,...f.dynamicFields],d=Object.fromEntries(c.staticFields.map((w,g)=>[y[g],w])),u=Object.fromEntries(C.map((w,g)=>[x[g],w]));return{namespace:i,name:a,tableId:s,keySchema:d,valueSchema:u}});return l("found",t.length,"tables for",o.address),t}import Xt from"p-retry";import{wait as er}from"@latticexyz/common/utils";async function Ke({client:e,worldDeploy:o,tables:r}){let n=(await _e({client:e,worldDeploy:o})).map(a=>a.tableId),s=r.filter(a=>n.includes(a.tableId));s.length&&l("existing tables",s.map(ie).join(", "));let i=r.filter(a=>!n.includes(a.tableId));return i.length?(l("registering tables",i.map(ie).join(", ")),await Promise.all(i.map(a=>Xt(()=>Yt(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerTable",args:[a.tableId,Gt(a.valueSchema),Zt(a.keySchema),Qt(a.valueSchema),Object.keys(a.keySchema),Object.keys(a.valueSchema)]}),{retries:3,onFailedAttempt:async m=>{let c=m.attemptNumber*500;l(`failed to register table ${ie(a)}, retrying in ${c}ms...`),await er(c)}})))):[]}import{getAddress as O}from"viem";import{writeContract as ce,resourceToLabel as V}from"@latticexyz/common";import{parseAbiItem as or}from"viem";import{getLogs as tr}from"viem/actions";import{storeSpliceStaticDataEvent as rr}from"@latticexyz/store";async function Q({client:e,worldDeploy:o}){l("looking up resource IDs for",o.address);let t=(await tr(e,{strict:!0,address:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock,event:or(rr),args:{tableId:F.store_ResourceIds.tableId}})).map(n=>n.args.keyTuple[0]);return l("found",t.length,"resource IDs for",o.address),t}import{hexToResource as hr,resourceToLabel as wr}from"@latticexyz/common";import{decodeValueArgs as nr,encodeKey as sr}from"@latticexyz/protocol-parser";import{readContract as ar}from"viem/actions";async function B({client:e,worldDeploy:o,table:r,key:t}){let[n,s,i]=await ar(e,{blockNumber:o.stateBlock,address:o.address,abi:S,functionName:"getRecord",args:[r.tableId,sr(r.keySchema,t)]});return nr(r.valueSchema,{staticData:n,encodedLengths:s,dynamicData:i})}import{toFunctionSelector as ir,parseAbiItem as cr}from"viem";import{storeSetRecordEvent as dr}from"@latticexyz/store";import{getLogs as lr}from"viem/actions";import{decodeValueArgs as mr}from"@latticexyz/protocol-parser";import{hexToResource as pr}from"@latticexyz/common";async function X({client:e,worldDeploy:o}){l("looking up function signatures for",o.address);let t=(await lr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:cr(dr),args:{tableId:T.world_FunctionSignatures.tableId}})).map(s=>mr(T.world_FunctionSignatures.valueSchema,s.args).functionSignature);return l("found",t.length,"function signatures for",o.address),await Promise.all(t.map(async s=>{let i=ir(s),{systemId:a,systemFunctionSelector:m}=await B({client:e,worldDeploy:o,table:T.world_FunctionSelectors,key:{worldFunctionSelector:i}}),{namespace:c,name:f}=pr(a),y=c===""?s:s.replace(`${c}_${f}_`,"");return{signature:s,selector:i,systemId:a,systemFunctionSignature:y,systemFunctionSelector:m}}))}import{parseAbiItem as fr,getAddress as yr}from"viem";import{storeSpliceStaticDataEvent as ur}from"@latticexyz/store";import{getLogs as gr}from"viem/actions";import{decodeKey as br}from"@latticexyz/protocol-parser";async function ee({client:e,worldDeploy:o}){l("looking up resource access for",o.address);let t=(await gr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:fr(ur),args:{tableId:T.world_ResourceAccess.tableId}})).map(s=>br(T.world_ResourceAccess.keySchema,s.args.keyTuple)),n=(await Promise.all(t.map(async s=>[s,await B({client:e,worldDeploy:o,table:T.world_ResourceAccess,key:s})]))).filter(([,s])=>s.access).map(([s])=>({resourceId:s.resourceId,address:yr(s.caller)}));return l("found",n.length,"resource<>address access pairs"),n}async function Je({client:e,worldDeploy:o}){let[r,t,n]=await Promise.all([Q({client:e,worldDeploy:o}),X({client:e,worldDeploy:o}),ee({client:e,worldDeploy:o})]),s=r.map(hr).filter(i=>i.type==="system");return l("looking up systems",s.map(wr).join(", ")),await Promise.all(s.map(async i=>{let{system:a,publicAccess:m}=await B({client:e,worldDeploy:o,table:T.world_Systems,key:{systemId:i.resourceId}}),c=t.filter(f=>f.systemId===i.resourceId);return{address:a,namespace:i.namespace,name:i.name,systemId:i.resourceId,allowAll:m,allowedAddresses:n.filter(({resourceId:f})=>f===i.resourceId).map(({address:f})=>f),functions:c}}))}import{wait as de}from"@latticexyz/common/utils";import le from"p-retry";async function qe({client:e,deployerAddress:o,libraries:r,worldDeploy:t,systems:n}){let[s,i]=await Promise.all([Je({client:e,worldDeploy:t}),ee({client:e,worldDeploy:t})]),a=n.filter(p=>s.some(b=>b.systemId===p.systemId&&O(b.address)===O(p.prepareDeploy(o,r).address)));a.length&&l("existing systems",a.map(V).join(", "));let m=a.map(p=>p.systemId),c=n.filter(p=>!m.includes(p.systemId));if(!c.length)return[];let f=c.filter(p=>s.some(b=>b.systemId===p.systemId&&O(b.address)!==O(p.prepareDeploy(o,r).address)));f.length&&l("upgrading systems",f.map(V).join(", "));let y=c.filter(p=>!s.some(b=>b.systemId===p.systemId));y.length&&l("registering new systems",y.map(V).join(", ")),await P({client:e,deployerAddress:o,contracts:c.map(p=>({bytecode:p.prepareDeploy(o,r).bytecode,deployedBytecodeSize:p.deployedBytecodeSize,label:`${V(p)} system`}))});let x=await Promise.all(c.map(p=>le(()=>ce(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"registerSystem",args:[p.systemId,p.prepareDeploy(o,r).address,p.allowAll]}),{retries:3,onFailedAttempt:async b=>{let h=b.attemptNumber*500;l(`failed to register system ${V(p)}, retrying in ${h}ms...`),await de(h)}}))),C=n.map(p=>p.systemId),d=i.filter(({resourceId:p})=>C.includes(p)),u=[...n.flatMap(p=>p.allowedAddresses.map(b=>({resourceId:p.systemId,address:b}))),...n.flatMap(p=>p.allowedSystemIds.map(b=>({resourceId:p.systemId,address:s.find(h=>h.systemId===b)?.address??n.find(h=>h.systemId===b)?.prepareDeploy(o,r).address})).filter(b=>b.address!=null))],w=u.filter(p=>!d.some(({resourceId:b,address:h})=>b===p.resourceId&&O(h)===O(p.address))),g=d.filter(p=>!u.some(({resourceId:b,address:h})=>b===p.resourceId&&O(h)===O(p.address)));g.length&&l("revoking",g.length,"access grants"),w.length&&l("adding",w.length,"access grants");let D=await Promise.all([...g.map(p=>le(()=>ce(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"revokeAccess",args:[p.resourceId,p.address]}),{retries:3,onFailedAttempt:async b=>{let h=b.attemptNumber*500;l(`failed to revoke access, retrying in ${h}ms...`),await de(h)}})),...w.map(p=>le(()=>ce(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"grantAccess",args:[p.resourceId,p.address]}),{retries:3,onFailedAttempt:async b=>{let h=b.attemptNumber*500;l(`failed to grant access, retrying in ${h}ms...`),await de(h)}}))]);return[...x,...D]}import{waitForTransactionReceipt as io}from"viem/actions";import{getAddress as xr,parseAbi as Sr}from"viem";import{getBlockNumber as Cr,getLogs as Dr}from"viem/actions";var Ye=new Map;async function Ge(e,o){let r=xr(o),t=Ye.get(r);if(t!=null)return t;l("looking up world deploy for",r);let n=await Cr(e),s=await Dr(e,{strict:!0,address:r,events:Sr(Y),fromBlock:"earliest",toBlock:n});return t={...Z(s),stateBlock:n},Ye.set(r,t),l("found world deploy for",r,"at block",t.deployBlock),t}import{hexToResource as vr,writeContract as Ze}from"@latticexyz/common";import Qe from"p-retry";import{wait as Xe}from"@latticexyz/common/utils";async function eo({client:e,worldDeploy:o,functions:r}){let t=await X({client:e,worldDeploy:o}),n=Object.fromEntries(t.map(a=>[a.selector,a])),s=r.filter(a=>n[a.selector]),i=r.filter(a=>!s.includes(a));if(s.length){l("functions already registered:",s.map(m=>m.signature).join(", "));let a=s.filter(m=>m.systemId!==n[m.selector]?.systemId);a.length&&console.warn("found",a.length,"functions already registered but pointing at a different system ID:",a.map(m=>m.signature).join(", "))}return i.length?(l("registering functions:",i.map(a=>a.signature).join(", ")),Promise.all(i.map(a=>{let{namespace:m}=vr(a.systemId);return m===""?Qe(()=>Ze(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerRootFunctionSelector",args:[a.systemId,a.systemFunctionSignature,a.systemFunctionSignature]}),{retries:3,onFailedAttempt:async c=>{let f=c.attemptNumber*500;l(`failed to register function ${a.signature}, retrying in ${f}ms...`),await Xe(f)}}):Qe(()=>Ze(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerFunctionSelector",args:[a.systemId,a.systemFunctionSignature]}),{retries:3,onFailedAttempt:async c=>{let f=c.attemptNumber*500;l(`failed to register function ${a.signature}, retrying in ${f}ms...`),await Xe(f)}})}))):[]}import{BaseError as Tr}from"viem";import{writeContract as oo}from"@latticexyz/common";import{isDefined as Ar,wait as kr}from"@latticexyz/common/utils";import Ir from"p-retry";async function to({client:e,deployerAddress:o,libraries:r,worldDeploy:t,modules:n}){return n.length?(await P({client:e,deployerAddress:o,contracts:n.map(s=>({bytecode:s.prepareDeploy(o,r).bytecode,deployedBytecodeSize:s.deployedBytecodeSize,label:`${s.name} module`}))}),l("installing modules:",n.map(s=>s.name).join(", ")),(await Promise.all(n.map(s=>Ir(async()=>{try{let i=s.prepareDeploy(o,r).address;return s.installAsRoot?await oo(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"installRootModule",args:[i,s.installData]}):await oo(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"installModule",args:[i,s.installData]})}catch(i){if(i instanceof Tr&&i.message.includes("Module_AlreadyInstalled")){l(`module ${s.name} already installed`);return}throw i}},{retries:3,onFailedAttempt:async i=>{let a=i.attemptNumber*500;l(`failed to install module ${s.name}, retrying in ${a}ms...`),await kr(a)}})))).filter(Ar)):[]}import{getAddress as ro}from"viem";import{hexToResource as no,resourceToHex as so,writeContract as Pr}from"@latticexyz/common";async function ao({client:e,worldDeploy:o,resourceIds:r}){let t=Array.from(new Set(r.map(y=>no(y).namespace))),n=await Q({client:e,worldDeploy:o}),s=new Set(n.map(y=>no(y).namespace));s.size&&l("found",s.size,"existing namespaces:",Array.from(s).map(y=>y===""?"<root>":y).join(", "));let i=t.filter(y=>s.has(y)),m=(await Promise.all(i.map(async y=>{let{owner:x}=await B({client:e,worldDeploy:o,table:T.world_NamespaceOwner,key:{namespaceId:so({type:"namespace",namespace:y,name:""})}});return[y,x]}))).filter(([,y])=>ro(y)!==ro(e.account.address)).map(([y])=>y);if(m.length)throw new Error(`You are attempting to deploy to namespaces you do not own: ${m.join(", ")}`);let c=t.filter(y=>!s.has(y));return c.length>0&&l("registering namespaces",Array.from(c).join(", ")),Promise.all(c.map(y=>Pr(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerNamespace",args:[so({namespace:y,type:"namespace",name:""})]})))}import{resourceToLabel as Br}from"@latticexyz/common";import{randomBytes as Or}from"crypto";async function co({client:e,config:o,salt:r,worldAddress:t,deployerAddress:n}){let s=Object.values(o.tables),i=n??await Ie(e);await G(e,i),await P({client:e,deployerAddress:i,contracts:[...o.libraries.map(d=>({bytecode:d.prepareDeploy(i,o.libraries).bytecode,deployedBytecodeSize:d.deployedBytecodeSize,label:`${d.path}:${d.name} library`})),...o.systems.map(d=>({bytecode:d.prepareDeploy(i,o.libraries).bytecode,deployedBytecodeSize:d.deployedBytecodeSize,label:`${Br(d)} system`})),...o.modules.map(d=>({bytecode:d.prepareDeploy(i,o.libraries).bytecode,deployedBytecodeSize:d.deployedBytecodeSize,label:`${d.name} module`}))]});let a=t?await Ge(e,t):await ze(e,i,r??`0x${Or(32).toString("hex")}`);if(!Be.includes(a.storeVersion))throw new Error(`Unsupported Store version: ${a.storeVersion}`);if(!Oe.includes(a.worldVersion))throw new Error(`Unsupported World version: ${a.worldVersion}`);let m=await ao({client:e,worldDeploy:a,resourceIds:[...s.map(d=>d.tableId),...o.systems.map(d=>d.systemId)]});l("waiting for all namespace registration transactions to confirm");for(let d of m)await io(e,{hash:d});let c=await Ke({client:e,worldDeploy:a,tables:s}),f=await qe({client:e,deployerAddress:i,libraries:o.libraries,worldDeploy:a,systems:o.systems}),y=await eo({client:e,worldDeploy:a,functions:o.systems.flatMap(d=>d.functions)}),x=await to({client:e,deployerAddress:i,libraries:o.libraries,worldDeploy:a,modules:o.modules}),C=[...c,...f,...y,...x];l("waiting for all transactions to confirm");for(let d of C)await io(e,{hash:d});return l("deploy complete"),a}import{createWalletClient as on,http as tn,isHex as rn}from"viem";import{privateKeyToAccount as nn}from"viem/accounts";import{loadConfig as sn}from"@latticexyz/config/node";import{getOutDirectory as an,getRpcUrl as cn,getSrcDirectory as dn}from"@latticexyz/common/foundry";import E from"chalk";import{MUDError as bo}from"@latticexyz/common/errors";import Nr from"path";import{resolveWorldConfig as zr}from"@latticexyz/world";import{resourceToHex as pe}from"@latticexyz/common";import{resolveWithContext as Lr}from"@latticexyz/config";import{encodeField as Ur}from"@latticexyz/protocol-parser";import{hexToBytes as Vr,bytesToHex as _r,toFunctionSelector as fo,toFunctionSignature as yo}from"viem";import oe from"@latticexyz/world-modules/out/KeysWithValueModule.sol/KeysWithValueModule.json"assert{type:"json"};import te from"@latticexyz/world-modules/out/KeysInTableModule.sol/KeysInTableModule.json"assert{type:"json"};import re from"@latticexyz/world-modules/out/UniqueEntityModule.sol/UniqueEntityModule.json"assert{type:"json"};import{size as me}from"viem";function H(e){return Object.entries(e).flatMap(([o,r])=>Object.entries(r).flatMap(([t,n])=>n.map(s=>({path:o,name:t,start:s.start,length:s.length}))))}var lo=[{name:"KeysWithValueModule",abi:oe.abi,bytecode:oe.bytecode.object,placeholders:H(oe.bytecode.linkReferences),deployedBytecodeSize:me(oe.deployedBytecode.object)},{name:"KeysInTableModule",abi:te.abi,bytecode:te.bytecode.object,placeholders:H(te.bytecode.linkReferences),deployedBytecodeSize:me(te.deployedBytecode.object)},{name:"UniqueEntityModule",abi:re.abi,bytecode:re.bytecode.object,placeholders:H(re.bytecode.linkReferences),deployedBytecodeSize:me(re.deployedBytecode.object)}];import{readFileSync as jr}from"fs";import Rr from"path";import{MUDError as ne}from"@latticexyz/common/errors";import{size as Mr}from"viem";function _(e,o,r){let t,n=Rr.join(r,e,o+".json");try{t=JSON.parse(jr(n,"utf8"))}catch{throw new ne(`Error reading file at ${n}`)}let s=t?.bytecode?.object;if(!s)throw new ne(`No bytecode found in ${n}`);let i=t?.deployedBytecode?.object;if(!i)throw new ne(`No deployed bytecode found in ${n}`);let a=t?.abi;if(!a)throw new ne(`No ABI found in ${n}`);let m=H(t?.bytecode?.linkReferences??{});return{abi:a,bytecode:s,placeholders:m,deployedBytecodeSize:Mr(i)}}import{groupBy as Kr}from"@latticexyz/common/utils";import{readFileSync as $r}from"fs";import Wr from"glob";import Fr from"toposort";function mo(e,o,r){let t=Fr(e.flatMap(n=>r(n).map(s=>[o(n),s])));return[...e].sort((n,s)=>t.indexOf(o(n))-t.indexOf(o(s)))}function po(e){let r=Wr.sync(`${e}/**/*.json`,{ignore:"**/*.abi.json"}).map(t=>JSON.parse($r(t,"utf8"))).flatMap(t=>{if(!t.metadata)return[];let n=Object.keys(t.metadata.settings.compilationTarget)[0],s=t.metadata.settings.compilationTarget[n],i=t.bytecode.linkReferences;return Object.entries(i).flatMap(([a,m])=>Object.keys(m).map(c=>({path:a,name:c,dependentPath:n,dependentName:s})))});return mo(r,t=>`${t.path}:${t.name}`,t=>[`${t.dependentPath}:${t.dependentName}`])}import{spliceHex as Hr}from"@latticexyz/common";import{getCreate2Address as Er}from"viem";function se(e,o){return function(t,n){let s=e;for(let i of o){let a=n.find(m=>m.path===i.path&&m.name===i.name);if(!a)throw new Error(`Could not find library for bytecode placeholder ${i.path}:${i.name}`);s=Hr(s,i.start,i.length,a.prepareDeploy(t,n).address)}return{bytecode:s,address:Er({from:t,bytecode:s,salt:v})}}}function uo({config:e,forgeSourceDir:o,forgeOutDir:r}){let t=po(r).map(d=>{let u=_(Nr.basename(d.path),d.name,r);return{path:d.path,name:d.name,abi:u.abi,prepareDeploy:se(u.bytecode,u.placeholders),deployedBytecodeSize:u.deployedBytecodeSize}}),n=L(e),s=I(o).map(({basename:d})=>d),i=zr(e,s),m=_("System.sol","System",r).abi.filter(d=>d.type==="function").map(yo),c=Object.entries(i.systems).map(([d,u])=>{let w=e.namespace,g=u.name,D=pe({type:"system",namespace:w,name:g}),p=_(`${d}.sol`,d,r),b=p.abi.filter(h=>h.type==="function").map(yo).filter(h=>!m.includes(h)).map(h=>{let be=w===""?h:`${w}__${h}`;return{signature:be,selector:fo(be),systemId:D,systemFunctionSignature:h,systemFunctionSelector:fo(h)}});return{namespace:w,name:g,systemId:D,allowAll:u.openAccess,allowedAddresses:u.accessListAddresses,allowedSystemIds:u.accessListSystems.map(h=>pe({type:"system",namespace:w,name:i.systems[h].name})),prepareDeploy:se(p.bytecode,p.placeholders),deployedBytecodeSize:p.deployedBytecodeSize,abi:p.abi,functions:b}}),f=Kr(c,d=>d.systemId),y=Array.from(f.values()).filter(d=>d.length>1).flat();if(y.length){let d=y.map(u=>u.name);throw new Error(`Found systems with overlapping system ID: ${d.join(", ")}.
|
|
13
|
+
`),l("deploying",n,"at",s),[await Bt(()=>Pt(e,{chain:e.chain??null,to:o,data:At([v,r])}),{retries:3,onFailedAttempt:async a=>{let m=a.attemptNumber*500;l(`failed to deploy ${n}, retrying in ${m}ms...`),await Ot(m)}})])}import{uniqueBy as Rt}from"@latticexyz/common/utils";async function P({client:e,deployerAddress:o,contracts:r}){let t=Rt(r,s=>s.bytecode),n=(await Promise.all(t.map(s=>je({client:e,deployerAddress:o,...s})))).flat();if(n.length){l("waiting for contracts");for(let s of n)await jt(e,{hash:s})}return n}async function G(e,o){let r=W(Re.deployedBytecode.object),t=Re.bytecode.object,n=$({from:o,bytecode:t,salt:v}),s=W(Me.deployedBytecode.object),i=Me.bytecode.object,a=$({from:o,bytecode:i,salt:v}),m=W(Fe.deployedBytecode.object),c=Fe.bytecode.object,f=$({from:o,bytecode:c,salt:v}),y=W($e.deployedBytecode.object),x=$e.bytecode.object,C=$({from:o,bytecode:x,salt:v}),d=W(We.deployedBytecode.object),u=Ee({bytecode:We.bytecode.object,abi:Mt,args:[n,a,f,C]}),w=$({from:o,bytecode:u,salt:v}),g=W(He.deployedBytecode.object),D=Ee({bytecode:He.bytecode.object,abi:Ft,args:[w]}),p=$({from:o,bytecode:D,salt:v});return await P({client:e,deployerAddress:o,contracts:[{bytecode:t,deployedBytecodeSize:r,label:"access management system"},{bytecode:i,deployedBytecodeSize:s,label:"balance transfer system"},{bytecode:c,deployedBytecodeSize:m,label:"batch call system"},{bytecode:x,deployedBytecodeSize:y,label:"core registration system"},{bytecode:u,deployedBytecodeSize:d,label:"core module"},{bytecode:D,deployedBytecodeSize:g,label:"world factory"}]}),p}import zt from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json"assert{type:"json"};import{writeContract as Lt}from"@latticexyz/common";import{AbiEventSignatureNotFoundError as $t,decodeEventLog as Wt,hexToString as Ne,parseAbi as Ht}from"viem";import{isDefined as Et}from"@latticexyz/common/utils";function Z(e){let o=e.map(i=>{try{return{...i,...Wt({strict:!0,abi:Ht(Y),topics:i.topics,data:i.data})}}catch(a){if(a instanceof $t)return;throw a}}).filter(Et),{address:r,deployBlock:t,worldVersion:n,storeVersion:s}=o.reduce((i,a)=>({...i,address:a.address,deployBlock:a.blockNumber,...a.eventName==="HelloWorld"?{worldVersion:Ne(a.args.worldVersion).replace(/\0+$/,"")}:null,...a.eventName==="HelloStore"?{storeVersion:Ne(a.args.storeVersion).replace(/\0+$/,"")}:null}),{});if(r==null)throw new Error("could not find world address");if(t==null)throw new Error("could not find world deploy block number");if(n==null)throw new Error("could not find world version");if(s==null)throw new Error("could not find store version");return{address:r,deployBlock:t,worldVersion:n,storeVersion:s}}async function ze(e,o,r){let t=await G(e,o);l("deploying world");let n=await Lt(e,{chain:e.chain??null,address:t,abi:zt,functionName:"deployWorld",args:[r]});l("waiting for world deploy");let s=await Nt(e,{hash:n});if(s.status!=="success")throw console.error("world deploy failed",s),new Error("world deploy failed");let i=Z(s.logs.map(a=>a));return l("deployed world to",i.address,"at block",i.deployBlock),{...i,stateBlock:i.deployBlock}}import{resourceToLabel as ie,writeContract as Yt}from"@latticexyz/common";import{valueSchemaToFieldLayoutHex as Gt,keySchemaToHex as Zt,valueSchemaToHex as Qt}from"@latticexyz/protocol-parser";import{parseAbiItem as Ut,decodeAbiParameters as Le,parseAbiParameters as Ue}from"viem";import{hexToResource as Vt}from"@latticexyz/common";import{storeSetRecordEvent as _t}from"@latticexyz/store";import{getLogs as Kt}from"viem/actions";import{decodeKey as Jt,decodeValueArgs as qt,hexToSchema as Ve}from"@latticexyz/protocol-parser";async function _e({client:e,worldDeploy:o}){l("looking up tables for",o.address);let t=(await Kt(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:Ut(_t),args:{tableId:F.store_Tables.tableId}})).map(n=>{let{tableId:s}=Jt(F.store_Tables.keySchema,n.args.keyTuple),{namespace:i,name:a}=Vt(s),m=qt(F.store_Tables.valueSchema,n.args),c=Ve(m.keySchema),f=Ve(m.valueSchema),y=Le(Ue("string[]"),m.abiEncodedKeyNames)[0],x=Le(Ue("string[]"),m.abiEncodedFieldNames)[0],C=[...f.staticFields,...f.dynamicFields],d=Object.fromEntries(c.staticFields.map((w,g)=>[y[g],w])),u=Object.fromEntries(C.map((w,g)=>[x[g],w]));return{namespace:i,name:a,tableId:s,keySchema:d,valueSchema:u}});return l("found",t.length,"tables for",o.address),t}import Xt from"p-retry";import{wait as er}from"@latticexyz/common/utils";async function Ke({client:e,worldDeploy:o,tables:r}){let n=(await _e({client:e,worldDeploy:o})).map(a=>a.tableId),s=r.filter(a=>n.includes(a.tableId));s.length&&l("existing tables",s.map(ie).join(", "));let i=r.filter(a=>!n.includes(a.tableId));return i.length?(l("registering tables",i.map(ie).join(", ")),await Promise.all(i.map(a=>Xt(()=>Yt(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerTable",args:[a.tableId,Gt(a.valueSchema),Zt(a.keySchema),Qt(a.valueSchema),Object.keys(a.keySchema),Object.keys(a.valueSchema)]}),{retries:3,onFailedAttempt:async m=>{let c=m.attemptNumber*500;l(`failed to register table ${ie(a)}, retrying in ${c}ms...`),await er(c)}})))):[]}import{getAddress as O}from"viem";import{writeContract as ce,resourceToLabel as V}from"@latticexyz/common";import{parseAbiItem as or}from"viem";import{getLogs as tr}from"viem/actions";import{storeSpliceStaticDataEvent as rr}from"@latticexyz/store";async function Q({client:e,worldDeploy:o}){l("looking up resource IDs for",o.address);let t=(await tr(e,{strict:!0,address:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock,event:or(rr),args:{tableId:F.store_ResourceIds.tableId}})).map(n=>n.args.keyTuple[0]);return l("found",t.length,"resource IDs for",o.address),t}import{hexToResource as hr,resourceToLabel as wr}from"@latticexyz/common";import{decodeValueArgs as nr,encodeKey as sr}from"@latticexyz/protocol-parser";import{readContract as ar}from"viem/actions";async function B({client:e,worldDeploy:o,table:r,key:t}){let[n,s,i]=await ar(e,{blockNumber:o.stateBlock,address:o.address,abi:S,functionName:"getRecord",args:[r.tableId,sr(r.keySchema,t)]});return nr(r.valueSchema,{staticData:n,encodedLengths:s,dynamicData:i})}import{toFunctionSelector as ir,parseAbiItem as cr}from"viem";import{storeSetRecordEvent as dr}from"@latticexyz/store";import{getLogs as lr}from"viem/actions";import{decodeValueArgs as mr}from"@latticexyz/protocol-parser";import{hexToResource as pr}from"@latticexyz/common";async function X({client:e,worldDeploy:o}){l("looking up function signatures for",o.address);let t=(await lr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:cr(dr),args:{tableId:T.world_FunctionSignatures.tableId}})).map(s=>mr(T.world_FunctionSignatures.valueSchema,s.args).functionSignature);return l("found",t.length,"function signatures for",o.address),await Promise.all(t.map(async s=>{let i=ir(s),{systemId:a,systemFunctionSelector:m}=await B({client:e,worldDeploy:o,table:T.world_FunctionSelectors,key:{worldFunctionSelector:i}}),{namespace:c,name:f}=pr(a),y=c===""?s:s.replace(`${c}_${f}_`,"");return{signature:s,selector:i,systemId:a,systemFunctionSignature:y,systemFunctionSelector:m}}))}import{parseAbiItem as fr,getAddress as yr}from"viem";import{storeSpliceStaticDataEvent as ur}from"@latticexyz/store";import{getLogs as gr}from"viem/actions";import{decodeKey as br}from"@latticexyz/protocol-parser";async function ee({client:e,worldDeploy:o}){l("looking up resource access for",o.address);let t=(await gr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:fr(ur),args:{tableId:T.world_ResourceAccess.tableId}})).map(s=>br(T.world_ResourceAccess.keySchema,s.args.keyTuple)),n=(await Promise.all(t.map(async s=>[s,await B({client:e,worldDeploy:o,table:T.world_ResourceAccess,key:s})]))).filter(([,s])=>s.access).map(([s])=>({resourceId:s.resourceId,address:yr(s.caller)}));return l("found",n.length,"resource<>address access pairs"),n}async function Je({client:e,worldDeploy:o}){let[r,t,n]=await Promise.all([Q({client:e,worldDeploy:o}),X({client:e,worldDeploy:o}),ee({client:e,worldDeploy:o})]),s=r.map(hr).filter(i=>i.type==="system");return l("looking up systems",s.map(wr).join(", ")),await Promise.all(s.map(async i=>{let{system:a,publicAccess:m}=await B({client:e,worldDeploy:o,table:T.world_Systems,key:{systemId:i.resourceId}}),c=t.filter(f=>f.systemId===i.resourceId);return{address:a,namespace:i.namespace,name:i.name,systemId:i.resourceId,allowAll:m,allowedAddresses:n.filter(({resourceId:f})=>f===i.resourceId).map(({address:f})=>f),functions:c}}))}import{wait as de}from"@latticexyz/common/utils";import le from"p-retry";async function qe({client:e,deployerAddress:o,libraries:r,worldDeploy:t,systems:n}){let[s,i]=await Promise.all([Je({client:e,worldDeploy:t}),ee({client:e,worldDeploy:t})]),a=n.filter(p=>s.some(b=>b.systemId===p.systemId&&O(b.address)===O(p.prepareDeploy(o,r).address)));a.length&&l("existing systems",a.map(V).join(", "));let m=a.map(p=>p.systemId),c=n.filter(p=>!m.includes(p.systemId));if(!c.length)return[];let f=c.filter(p=>s.some(b=>b.systemId===p.systemId&&O(b.address)!==O(p.prepareDeploy(o,r).address)));f.length&&l("upgrading systems",f.map(V).join(", "));let y=c.filter(p=>!s.some(b=>b.systemId===p.systemId));y.length&&l("registering new systems",y.map(V).join(", ")),await P({client:e,deployerAddress:o,contracts:c.map(p=>({bytecode:p.prepareDeploy(o,r).bytecode,deployedBytecodeSize:p.deployedBytecodeSize,label:`${V(p)} system`}))});let x=await Promise.all(c.map(p=>le(()=>ce(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"registerSystem",args:[p.systemId,p.prepareDeploy(o,r).address,p.allowAll]}),{retries:3,onFailedAttempt:async b=>{let h=b.attemptNumber*500;l(`failed to register system ${V(p)}, retrying in ${h}ms...`),await de(h)}}))),C=n.map(p=>p.systemId),d=i.filter(({resourceId:p})=>C.includes(p)),u=[...n.flatMap(p=>p.allowedAddresses.map(b=>({resourceId:p.systemId,address:b}))),...n.flatMap(p=>p.allowedSystemIds.map(b=>({resourceId:p.systemId,address:s.find(h=>h.systemId===b)?.address??n.find(h=>h.systemId===b)?.prepareDeploy(o,r).address})).filter(b=>b.address!=null))],w=u.filter(p=>!d.some(({resourceId:b,address:h})=>b===p.resourceId&&O(h)===O(p.address))),g=d.filter(p=>!u.some(({resourceId:b,address:h})=>b===p.resourceId&&O(h)===O(p.address)));g.length&&l("revoking",g.length,"access grants"),w.length&&l("adding",w.length,"access grants");let D=await Promise.all([...g.map(p=>le(()=>ce(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"revokeAccess",args:[p.resourceId,p.address]}),{retries:3,onFailedAttempt:async b=>{let h=b.attemptNumber*500;l(`failed to revoke access, retrying in ${h}ms...`),await de(h)}})),...w.map(p=>le(()=>ce(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"grantAccess",args:[p.resourceId,p.address]}),{retries:3,onFailedAttempt:async b=>{let h=b.attemptNumber*500;l(`failed to grant access, retrying in ${h}ms...`),await de(h)}}))]);return[...x,...D]}import{waitForTransactionReceipt as io}from"viem/actions";import{getAddress as xr,parseAbi as Sr}from"viem";import{getBlockNumber as Cr,getLogs as Dr}from"viem/actions";var Ye=new Map;async function Ge(e,o){let r=xr(o),t=Ye.get(r);if(t!=null)return t;l("looking up world deploy for",r);let n=await Cr(e),s=await Dr(e,{strict:!0,address:r,events:Sr(Y),fromBlock:"earliest",toBlock:n});return t={...Z(s),stateBlock:n},Ye.set(r,t),l("found world deploy for",r,"at block",t.deployBlock),t}import{hexToResource as vr,writeContract as Ze}from"@latticexyz/common";import Qe from"p-retry";import{wait as Xe}from"@latticexyz/common/utils";async function eo({client:e,worldDeploy:o,functions:r}){let t=await X({client:e,worldDeploy:o}),n=Object.fromEntries(t.map(a=>[a.selector,a])),s=r.filter(a=>n[a.selector]),i=r.filter(a=>!s.includes(a));if(s.length){l("functions already registered:",s.map(m=>m.signature).join(", "));let a=s.filter(m=>m.systemId!==n[m.selector]?.systemId);a.length&&console.warn("found",a.length,"functions already registered but pointing at a different system ID:",a.map(m=>m.signature).join(", "))}return i.length?(l("registering functions:",i.map(a=>a.signature).join(", ")),Promise.all(i.map(a=>{let{namespace:m}=vr(a.systemId);return m===""?Qe(()=>Ze(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerRootFunctionSelector",args:[a.systemId,a.systemFunctionSignature,a.systemFunctionSignature]}),{retries:3,onFailedAttempt:async c=>{let f=c.attemptNumber*500;l(`failed to register function ${a.signature}, retrying in ${f}ms...`),await Xe(f)}}):Qe(()=>Ze(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerFunctionSelector",args:[a.systemId,a.systemFunctionSignature]}),{retries:3,onFailedAttempt:async c=>{let f=c.attemptNumber*500;l(`failed to register function ${a.signature}, retrying in ${f}ms...`),await Xe(f)}})}))):[]}import{BaseError as Tr}from"viem";import{writeContract as oo}from"@latticexyz/common";import{isDefined as Ar,wait as kr}from"@latticexyz/common/utils";import Ir from"p-retry";async function to({client:e,deployerAddress:o,libraries:r,worldDeploy:t,modules:n}){return n.length?(await P({client:e,deployerAddress:o,contracts:n.map(s=>({bytecode:s.prepareDeploy(o,r).bytecode,deployedBytecodeSize:s.deployedBytecodeSize,label:`${s.name} module`}))}),l("installing modules:",n.map(s=>s.name).join(", ")),(await Promise.all(n.map(s=>Ir(async()=>{try{let i=s.prepareDeploy(o,r).address;return s.installAsRoot?await oo(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"installRootModule",args:[i,s.installData]}):await oo(e,{chain:e.chain??null,address:t.address,abi:S,functionName:"installModule",args:[i,s.installData]})}catch(i){if(i instanceof Tr&&i.message.includes("Module_AlreadyInstalled")){l(`module ${s.name} already installed`);return}throw i}},{retries:3,onFailedAttempt:async i=>{let a=i.attemptNumber*500;l(`failed to install module ${s.name}, retrying in ${a}ms...`),await kr(a)}})))).filter(Ar)):[]}import{getAddress as ro}from"viem";import{hexToResource as no,resourceToHex as so,writeContract as Pr}from"@latticexyz/common";async function ao({client:e,worldDeploy:o,resourceIds:r}){let t=Array.from(new Set(r.map(y=>no(y).namespace))),n=await Q({client:e,worldDeploy:o}),s=new Set(n.map(y=>no(y).namespace));s.size&&l("found",s.size,"existing namespaces:",Array.from(s).map(y=>y===""?"<root>":y).join(", "));let i=t.filter(y=>s.has(y)),m=(await Promise.all(i.map(async y=>{let{owner:x}=await B({client:e,worldDeploy:o,table:T.world_NamespaceOwner,key:{namespaceId:so({type:"namespace",namespace:y,name:""})}});return[y,x]}))).filter(([,y])=>ro(y)!==ro(e.account.address)).map(([y])=>y);if(m.length)throw new Error(`You are attempting to deploy to namespaces you do not own: ${m.join(", ")}`);let c=t.filter(y=>!s.has(y));return c.length>0&&l("registering namespaces",Array.from(c).join(", ")),Promise.all(c.map(y=>Pr(e,{chain:e.chain??null,address:o.address,abi:S,functionName:"registerNamespace",args:[so({namespace:y,type:"namespace",name:""})]})))}import{resourceToLabel as Br}from"@latticexyz/common";import{randomBytes as Or}from"crypto";async function co({client:e,config:o,salt:r,worldAddress:t,deployerAddress:n}){let s=Object.values(o.tables),i=n??await Ie(e);await G(e,i),await P({client:e,deployerAddress:i,contracts:[...o.libraries.map(d=>({bytecode:d.prepareDeploy(i,o.libraries).bytecode,deployedBytecodeSize:d.deployedBytecodeSize,label:`${d.path}:${d.name} library`})),...o.systems.map(d=>({bytecode:d.prepareDeploy(i,o.libraries).bytecode,deployedBytecodeSize:d.deployedBytecodeSize,label:`${Br(d)} system`})),...o.modules.map(d=>({bytecode:d.prepareDeploy(i,o.libraries).bytecode,deployedBytecodeSize:d.deployedBytecodeSize,label:`${d.name} module`}))]});let a=t?await Ge(e,t):await ze(e,i,r??`0x${Or(32).toString("hex")}`);if(!Be.includes(a.storeVersion))throw new Error(`Unsupported Store version: ${a.storeVersion}`);if(!Oe.includes(a.worldVersion))throw new Error(`Unsupported World version: ${a.worldVersion}`);let m=await ao({client:e,worldDeploy:a,resourceIds:[...s.map(d=>d.tableId),...o.systems.map(d=>d.systemId)]});l("waiting for all namespace registration transactions to confirm");for(let d of m)await io(e,{hash:d});let c=await Ke({client:e,worldDeploy:a,tables:s}),f=await qe({client:e,deployerAddress:i,libraries:o.libraries,worldDeploy:a,systems:o.systems}),y=await eo({client:e,worldDeploy:a,functions:o.systems.flatMap(d=>d.functions)}),x=await to({client:e,deployerAddress:i,libraries:o.libraries,worldDeploy:a,modules:o.modules}),C=[...c,...f,...y,...x];l("waiting for all transactions to confirm");for(let d of C)await io(e,{hash:d});return l("deploy complete"),a}import{createWalletClient as on,http as tn,isHex as rn}from"viem";import{privateKeyToAccount as nn}from"viem/accounts";import{loadConfig as sn}from"@latticexyz/config/node";import{getOutDirectory as an,getRpcUrl as cn,getSrcDirectory as dn}from"@latticexyz/common/foundry";import E from"chalk";import{MUDError as bo}from"@latticexyz/common/errors";import Nr from"path";import{resolveWorldConfig as zr}from"@latticexyz/world";import{resourceToHex as pe}from"@latticexyz/common";import{resolveWithContext as Lr}from"@latticexyz/config/library";import{encodeField as Ur}from"@latticexyz/protocol-parser";import{hexToBytes as Vr,bytesToHex as _r,toFunctionSelector as fo,toFunctionSignature as yo}from"viem";import oe from"@latticexyz/world-modules/out/KeysWithValueModule.sol/KeysWithValueModule.json"assert{type:"json"};import te from"@latticexyz/world-modules/out/KeysInTableModule.sol/KeysInTableModule.json"assert{type:"json"};import re from"@latticexyz/world-modules/out/UniqueEntityModule.sol/UniqueEntityModule.json"assert{type:"json"};import{size as me}from"viem";function H(e){return Object.entries(e).flatMap(([o,r])=>Object.entries(r).flatMap(([t,n])=>n.map(s=>({path:o,name:t,start:s.start,length:s.length}))))}var lo=[{name:"KeysWithValueModule",abi:oe.abi,bytecode:oe.bytecode.object,placeholders:H(oe.bytecode.linkReferences),deployedBytecodeSize:me(oe.deployedBytecode.object)},{name:"KeysInTableModule",abi:te.abi,bytecode:te.bytecode.object,placeholders:H(te.bytecode.linkReferences),deployedBytecodeSize:me(te.deployedBytecode.object)},{name:"UniqueEntityModule",abi:re.abi,bytecode:re.bytecode.object,placeholders:H(re.bytecode.linkReferences),deployedBytecodeSize:me(re.deployedBytecode.object)}];import{readFileSync as jr}from"fs";import Rr from"path";import{MUDError as ne}from"@latticexyz/common/errors";import{size as Mr}from"viem";function _(e,o,r){let t,n=Rr.join(r,e,o+".json");try{t=JSON.parse(jr(n,"utf8"))}catch{throw new ne(`Error reading file at ${n}`)}let s=t?.bytecode?.object;if(!s)throw new ne(`No bytecode found in ${n}`);let i=t?.deployedBytecode?.object;if(!i)throw new ne(`No deployed bytecode found in ${n}`);let a=t?.abi;if(!a)throw new ne(`No ABI found in ${n}`);let m=H(t?.bytecode?.linkReferences??{});return{abi:a,bytecode:s,placeholders:m,deployedBytecodeSize:Mr(i)}}import{groupBy as Kr}from"@latticexyz/common/utils";import{readFileSync as $r}from"fs";import Wr from"glob";import Fr from"toposort";function mo(e,o,r){let t=Fr(e.flatMap(n=>r(n).map(s=>[o(n),s])));return[...e].sort((n,s)=>t.indexOf(o(n))-t.indexOf(o(s)))}function po(e){let r=Wr.sync(`${e}/**/*.json`,{ignore:"**/*.abi.json"}).map(t=>JSON.parse($r(t,"utf8"))).flatMap(t=>{if(!t.metadata)return[];let n=Object.keys(t.metadata.settings.compilationTarget)[0],s=t.metadata.settings.compilationTarget[n],i=t.bytecode.linkReferences;return Object.entries(i).flatMap(([a,m])=>Object.keys(m).map(c=>({path:a,name:c,dependentPath:n,dependentName:s})))});return mo(r,t=>`${t.path}:${t.name}`,t=>[`${t.dependentPath}:${t.dependentName}`])}import{spliceHex as Hr}from"@latticexyz/common";import{getCreate2Address as Er}from"viem";function se(e,o){return function(t,n){let s=e;for(let i of o){let a=n.find(m=>m.path===i.path&&m.name===i.name);if(!a)throw new Error(`Could not find library for bytecode placeholder ${i.path}:${i.name}`);s=Hr(s,i.start,i.length,a.prepareDeploy(t,n).address)}return{bytecode:s,address:Er({from:t,bytecode:s,salt:v})}}}function uo({config:e,forgeSourceDir:o,forgeOutDir:r}){let t=po(r).map(d=>{let u=_(Nr.basename(d.path),d.name,r);return{path:d.path,name:d.name,abi:u.abi,prepareDeploy:se(u.bytecode,u.placeholders),deployedBytecodeSize:u.deployedBytecodeSize}}),n=L(e),s=I(o).map(({basename:d})=>d),i=zr(e,s),m=_("System.sol","System",r).abi.filter(d=>d.type==="function").map(yo),c=Object.entries(i.systems).map(([d,u])=>{let w=e.namespace,g=u.name,D=pe({type:"system",namespace:w,name:g}),p=_(`${d}.sol`,d,r),b=p.abi.filter(h=>h.type==="function").map(yo).filter(h=>!m.includes(h)).map(h=>{let be=w===""?h:`${w}__${h}`;return{signature:be,selector:fo(be),systemId:D,systemFunctionSignature:h,systemFunctionSelector:fo(h)}});return{namespace:w,name:g,systemId:D,allowAll:u.openAccess,allowedAddresses:u.accessListAddresses,allowedSystemIds:u.accessListSystems.map(h=>pe({type:"system",namespace:w,name:i.systems[h].name})),prepareDeploy:se(p.bytecode,p.placeholders),deployedBytecodeSize:p.deployedBytecodeSize,abi:p.abi,functions:b}}),f=Kr(c,d=>d.systemId),y=Array.from(f.values()).filter(d=>d.length>1).flat();if(y.length){let d=y.map(u=>u.name);throw new Error(`Found systems with overlapping system ID: ${d.join(", ")}.
|
|
14
14
|
|
|
15
15
|
System IDs are generated from the first 16 bytes of the name, so you may need to rename them to avoid the overlap.`)}let x={tableIds:Object.fromEntries(Object.entries(e.tables).map(([d,u])=>[d,Vr(pe({type:u.offchainOnly?"offchainTable":"table",namespace:e.namespace,name:u.name}))]))},C=e.modules.map(d=>{let u=lo.find(g=>g.name===d.name)??_(`${d.name}.sol`,d.name,r),w=d.args.map(g=>Lr(g,x)).map(g=>{let D=g.value instanceof Uint8Array?_r(g.value):g.value;return Ur(g.type,D)});if(w.length>1)throw new Error(`${d.name} module should only have 0-1 args, but had ${w.length} args.`);return{name:d.name,installAsRoot:d.root,installData:w.length===0?"0x":w[0],prepareDeploy:se(u.bytecode,u.placeholders),deployedBytecodeSize:u.deployedBytecodeSize,abi:u.abi}});return{tables:n,systems:c,modules:C,libraries:t}}import{getChainId as ln}from"viem/actions";import{existsSync as Jr}from"fs";import qr from"path";import Yr from"chalk";import{getScriptDirectory as Gr,forge as Zr}from"@latticexyz/common/foundry";async function go(e,o,r,t){let n=qr.join(await Gr(),e+".s.sol");Jr(n)?(console.log(Yr.blue(`Executing post deploy script at ${n}`)),await Zr(["script",e,"--sig","run(address)",o,"--broadcast","--rpc-url",r,"-vvv"],{profile:t})):console.log(`No script at ${n}, skipping post deploy hook`)}var k={configPath:{type:"string",desc:"Path to the config file"},printConfig:{type:"boolean",desc:"Print the resolved config"},profile:{type:"string",desc:"The foundry profile to use"},saveDeployment:{type:"boolean",desc:"Save the deployment info to a file",default:!0},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)"},deployerAddress:{type:"string",desc:"Deploy using an existing deterministic deployer (https://github.com/Arachnid/deterministic-deployment-proxy)"},worldAddress:{type:"string",desc:"Deploy to an existing World at the given address"},srcDir:{type:"string",desc:"Source directory. Defaults to foundry src directory."},skipBuild:{type:"boolean",desc:"Skip rebuilding the contracts before deploying"},alwaysRunPostDeploy:{type:"boolean",desc:"Always run PostDeploy.s.sol after each deploy (including during upgrades). By default, PostDeploy.s.sol is only run once after a new world is deployed."},salt:{type:"string",desc:"The deployment salt to use. Defaults to a random salt."}};async function N(e){let o=e.salt;if(o!=null&&!rn(o))throw new bo("Expected hex string for salt");let r=e.profile??process.env.FOUNDRY_PROFILE,t=await sn(e.configPath);e.printConfig&&console.log(E.green(`
|
|
16
16
|
Resolved config:
|
|
@@ -33,4 +33,4 @@ Waiting for file changes\u2026
|
|
|
33
33
|
`))),console.error(f),console.log(j.gray(`
|
|
34
34
|
Waiting for file changes\u2026
|
|
35
35
|
`))}}),is(cs)).subscribe()}},jo=ls;var jp=[we,ho,xe,Ce,ms,De,ve,xo,vo,To,Oo,jo,ps];export{jp as commands};
|
|
36
|
-
//# sourceMappingURL=commands-
|
|
36
|
+
//# sourceMappingURL=commands-OLS33STU.js.map
|