@latticexyz/cli 2.0.0-alpha.1.233 → 2.0.0-alpha.1.235
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-QN5DEFJQ.js +30 -0
- package/dist/chunk-QN5DEFJQ.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/mud.js +11 -11
- package/dist/mud.js.map +1 -1
- package/package.json +11 -10
- package/src/commands/index.ts +2 -0
- package/src/commands/trace.ts +108 -0
- package/src/commands/worldgen.ts +3 -7
- package/src/utils/deploy.ts +2 -3
- package/src/utils/deployHandler.ts +5 -8
- package/src/utils/getExistingContracts.ts +12 -0
- package/src/utils/index.ts +4 -2
- package/dist/chunk-MFCUIDZS.js +0 -30
- package/dist/chunk-MFCUIDZS.js.map +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import{SchemaType as e}from"@latticexyz/schema-type";var ne={[e.UINT8]:"RecsType.Number",[e.UINT16]:"RecsType.Number",[e.UINT24]:"RecsType.Number",[e.UINT32]:"RecsType.Number",[e.UINT40]:"RecsType.Number",[e.UINT48]:"RecsType.Number",[e.UINT56]:"RecsType.BigInt",[e.UINT64]:"RecsType.BigInt",[e.UINT72]:"RecsType.BigInt",[e.UINT80]:"RecsType.BigInt",[e.UINT88]:"RecsType.BigInt",[e.UINT96]:"RecsType.BigInt",[e.UINT104]:"RecsType.BigInt",[e.UINT112]:"RecsType.BigInt",[e.UINT120]:"RecsType.BigInt",[e.UINT128]:"RecsType.BigInt",[e.UINT136]:"RecsType.BigInt",[e.UINT144]:"RecsType.BigInt",[e.UINT152]:"RecsType.BigInt",[e.UINT160]:"RecsType.BigInt",[e.UINT168]:"RecsType.BigInt",[e.UINT176]:"RecsType.BigInt",[e.UINT184]:"RecsType.BigInt",[e.UINT192]:"RecsType.BigInt",[e.UINT200]:"RecsType.BigInt",[e.UINT208]:"RecsType.BigInt",[e.UINT216]:"RecsType.BigInt",[e.UINT224]:"RecsType.BigInt",[e.UINT232]:"RecsType.BigInt",[e.UINT240]:"RecsType.BigInt",[e.UINT248]:"RecsType.BigInt",[e.UINT256]:"RecsType.BigInt",[e.INT8]:"RecsType.Number",[e.INT16]:"RecsType.Number",[e.INT24]:"RecsType.Number",[e.INT32]:"RecsType.Number",[e.INT40]:"RecsType.Number",[e.INT48]:"RecsType.Number",[e.INT56]:"RecsType.BigInt",[e.INT64]:"RecsType.BigInt",[e.INT72]:"RecsType.BigInt",[e.INT80]:"RecsType.BigInt",[e.INT88]:"RecsType.BigInt",[e.INT96]:"RecsType.BigInt",[e.INT104]:"RecsType.BigInt",[e.INT112]:"RecsType.BigInt",[e.INT120]:"RecsType.BigInt",[e.INT128]:"RecsType.BigInt",[e.INT136]:"RecsType.BigInt",[e.INT144]:"RecsType.BigInt",[e.INT152]:"RecsType.BigInt",[e.INT160]:"RecsType.BigInt",[e.INT168]:"RecsType.BigInt",[e.INT176]:"RecsType.BigInt",[e.INT184]:"RecsType.BigInt",[e.INT192]:"RecsType.BigInt",[e.INT200]:"RecsType.BigInt",[e.INT208]:"RecsType.BigInt",[e.INT216]:"RecsType.BigInt",[e.INT224]:"RecsType.BigInt",[e.INT232]:"RecsType.BigInt",[e.INT240]:"RecsType.BigInt",[e.INT248]:"RecsType.BigInt",[e.INT256]:"RecsType.BigInt",[e.BYTES1]:"RecsType.String",[e.BYTES2]:"RecsType.String",[e.BYTES3]:"RecsType.String",[e.BYTES4]:"RecsType.String",[e.BYTES5]:"RecsType.String",[e.BYTES6]:"RecsType.String",[e.BYTES7]:"RecsType.String",[e.BYTES8]:"RecsType.String",[e.BYTES9]:"RecsType.String",[e.BYTES10]:"RecsType.String",[e.BYTES11]:"RecsType.String",[e.BYTES12]:"RecsType.String",[e.BYTES13]:"RecsType.String",[e.BYTES14]:"RecsType.String",[e.BYTES15]:"RecsType.String",[e.BYTES16]:"RecsType.String",[e.BYTES17]:"RecsType.String",[e.BYTES18]:"RecsType.String",[e.BYTES19]:"RecsType.String",[e.BYTES20]:"RecsType.String",[e.BYTES21]:"RecsType.String",[e.BYTES22]:"RecsType.String",[e.BYTES23]:"RecsType.String",[e.BYTES24]:"RecsType.String",[e.BYTES25]:"RecsType.String",[e.BYTES26]:"RecsType.String",[e.BYTES27]:"RecsType.String",[e.BYTES28]:"RecsType.String",[e.BYTES29]:"RecsType.String",[e.BYTES30]:"RecsType.String",[e.BYTES31]:"RecsType.String",[e.BYTES32]:"RecsType.String",[e.BOOL]:"RecsType.Boolean",[e.ADDRESS]:"RecsType.String",[e.UINT8_ARRAY]:"RecsType.NumberArray",[e.UINT16_ARRAY]:"RecsType.NumberArray",[e.UINT24_ARRAY]:"RecsType.NumberArray",[e.UINT32_ARRAY]:"RecsType.NumberArray",[e.UINT40_ARRAY]:"RecsType.NumberArray",[e.UINT48_ARRAY]:"RecsType.NumberArray",[e.UINT56_ARRAY]:"RecsType.BigIntArray",[e.UINT64_ARRAY]:"RecsType.BigIntArray",[e.UINT72_ARRAY]:"RecsType.BigIntArray",[e.UINT80_ARRAY]:"RecsType.BigIntArray",[e.UINT88_ARRAY]:"RecsType.BigIntArray",[e.UINT96_ARRAY]:"RecsType.BigIntArray",[e.UINT104_ARRAY]:"RecsType.BigIntArray",[e.UINT112_ARRAY]:"RecsType.BigIntArray",[e.UINT120_ARRAY]:"RecsType.BigIntArray",[e.UINT128_ARRAY]:"RecsType.BigIntArray",[e.UINT136_ARRAY]:"RecsType.BigIntArray",[e.UINT144_ARRAY]:"RecsType.BigIntArray",[e.UINT152_ARRAY]:"RecsType.BigIntArray",[e.UINT160_ARRAY]:"RecsType.BigIntArray",[e.UINT168_ARRAY]:"RecsType.BigIntArray",[e.UINT176_ARRAY]:"RecsType.BigIntArray",[e.UINT184_ARRAY]:"RecsType.BigIntArray",[e.UINT192_ARRAY]:"RecsType.BigIntArray",[e.UINT200_ARRAY]:"RecsType.BigIntArray",[e.UINT208_ARRAY]:"RecsType.BigIntArray",[e.UINT216_ARRAY]:"RecsType.BigIntArray",[e.UINT224_ARRAY]:"RecsType.BigIntArray",[e.UINT232_ARRAY]:"RecsType.BigIntArray",[e.UINT240_ARRAY]:"RecsType.BigIntArray",[e.UINT248_ARRAY]:"RecsType.BigIntArray",[e.UINT256_ARRAY]:"RecsType.BigIntArray",[e.INT8_ARRAY]:"RecsType.NumberArray",[e.INT16_ARRAY]:"RecsType.NumberArray",[e.INT24_ARRAY]:"RecsType.NumberArray",[e.INT32_ARRAY]:"RecsType.NumberArray",[e.INT40_ARRAY]:"RecsType.NumberArray",[e.INT48_ARRAY]:"RecsType.NumberArray",[e.INT56_ARRAY]:"RecsType.BigIntArray",[e.INT64_ARRAY]:"RecsType.BigIntArray",[e.INT72_ARRAY]:"RecsType.BigIntArray",[e.INT80_ARRAY]:"RecsType.BigIntArray",[e.INT88_ARRAY]:"RecsType.BigIntArray",[e.INT96_ARRAY]:"RecsType.BigIntArray",[e.INT104_ARRAY]:"RecsType.BigIntArray",[e.INT112_ARRAY]:"RecsType.BigIntArray",[e.INT120_ARRAY]:"RecsType.BigIntArray",[e.INT128_ARRAY]:"RecsType.BigIntArray",[e.INT136_ARRAY]:"RecsType.BigIntArray",[e.INT144_ARRAY]:"RecsType.BigIntArray",[e.INT152_ARRAY]:"RecsType.BigIntArray",[e.INT160_ARRAY]:"RecsType.BigIntArray",[e.INT168_ARRAY]:"RecsType.BigIntArray",[e.INT176_ARRAY]:"RecsType.BigIntArray",[e.INT184_ARRAY]:"RecsType.BigIntArray",[e.INT192_ARRAY]:"RecsType.BigIntArray",[e.INT200_ARRAY]:"RecsType.BigIntArray",[e.INT208_ARRAY]:"RecsType.BigIntArray",[e.INT216_ARRAY]:"RecsType.BigIntArray",[e.INT224_ARRAY]:"RecsType.BigIntArray",[e.INT232_ARRAY]:"RecsType.BigIntArray",[e.INT240_ARRAY]:"RecsType.BigIntArray",[e.INT248_ARRAY]:"RecsType.BigIntArray",[e.INT256_ARRAY]:"RecsType.BigIntArray",[e.BYTES1_ARRAY]:"RecsType.StringArray",[e.BYTES2_ARRAY]:"RecsType.StringArray",[e.BYTES3_ARRAY]:"RecsType.StringArray",[e.BYTES4_ARRAY]:"RecsType.StringArray",[e.BYTES5_ARRAY]:"RecsType.StringArray",[e.BYTES6_ARRAY]:"RecsType.StringArray",[e.BYTES7_ARRAY]:"RecsType.StringArray",[e.BYTES8_ARRAY]:"RecsType.StringArray",[e.BYTES9_ARRAY]:"RecsType.StringArray",[e.BYTES10_ARRAY]:"RecsType.StringArray",[e.BYTES11_ARRAY]:"RecsType.StringArray",[e.BYTES12_ARRAY]:"RecsType.StringArray",[e.BYTES13_ARRAY]:"RecsType.StringArray",[e.BYTES14_ARRAY]:"RecsType.StringArray",[e.BYTES15_ARRAY]:"RecsType.StringArray",[e.BYTES16_ARRAY]:"RecsType.StringArray",[e.BYTES17_ARRAY]:"RecsType.StringArray",[e.BYTES18_ARRAY]:"RecsType.StringArray",[e.BYTES19_ARRAY]:"RecsType.StringArray",[e.BYTES20_ARRAY]:"RecsType.StringArray",[e.BYTES21_ARRAY]:"RecsType.StringArray",[e.BYTES22_ARRAY]:"RecsType.StringArray",[e.BYTES23_ARRAY]:"RecsType.StringArray",[e.BYTES24_ARRAY]:"RecsType.StringArray",[e.BYTES25_ARRAY]:"RecsType.StringArray",[e.BYTES26_ARRAY]:"RecsType.StringArray",[e.BYTES27_ARRAY]:"RecsType.StringArray",[e.BYTES28_ARRAY]:"RecsType.StringArray",[e.BYTES29_ARRAY]:"RecsType.StringArray",[e.BYTES30_ARRAY]:"RecsType.StringArray",[e.BYTES31_ARRAY]:"RecsType.StringArray",[e.BYTES32_ARRAY]:"RecsType.StringArray",[e.BOOL_ARRAY]:"RecsType.T",[e.ADDRESS_ARRAY]:"RecsType.StringArray",[e.BYTES]:"RecsType.String",[e.STRING]:"RecsType.String"};import{resolveAbiOrUserType as Ye}from"@latticexyz/store/codegen";function oe(n){let a=[];for(let i of Object.keys(n.tables)){let T=n.tables[i],m=Object.keys(T.schema).map(c=>{let U=T.schema[c],{schemaType:$}=Ye(U,n);return{recsTypeString:ne[$],name:c}});if(T.tableIdArgument)continue;let x={namespace:n.namespace,name:T.name};a.push({tableName:i,fields:m,staticResourceData:x})}return{tables:a}}function se(n){let{tables:a}=n;return`/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
|
|
3
|
+
import { TableId } from "@latticexyz/utils";
|
|
4
|
+
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";
|
|
5
|
+
|
|
6
|
+
export function defineContractComponents(world: World) {
|
|
7
|
+
return {
|
|
8
|
+
${a.map(i=>`${i.tableName}: ${we(i)},`).join("")}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
`}function we(n){let{namespace:a,name:i}=n.staticResourceData;return`
|
|
12
|
+
(() => {
|
|
13
|
+
const tableId = new TableId("${a}", "${i}");
|
|
14
|
+
return defineComponent(world, {
|
|
15
|
+
${n.fields.map(({name:T,recsTypeString:m})=>`${T}: ${m},`).join("")}
|
|
16
|
+
}, {
|
|
17
|
+
metadata: { contractId: tableId.toHexString(), tableId: tableId.toString() },
|
|
18
|
+
});
|
|
19
|
+
})()
|
|
20
|
+
`}import _e from"path";import{formatAndWriteTypescript as Ee}from"@latticexyz/common/codegen";async function ct(n,a){let i=_e.join(a,"contractComponents.ts"),T=oe(n),m=se(T);Ee(m,i,"Generated ts definition files")}import v from"chalk";import q from"path";import{MUDError as Ve}from"@latticexyz/common/errors";import{loadConfig as Ke}from"@latticexyz/config/node";import{existsSync as he,readFileSync as Ue}from"fs";import ie from"path";import p from"chalk";import{ethers as P}from"ethers";import{defaultAbiCoder as $e}from"ethers/lib/utils.js";import{getOutDirectory as Ce,getScriptDirectory as De,cast as Pe,forge as xe}from"@latticexyz/common/foundry";import{resolveWithContext as Fe}from"@latticexyz/config";import{MUDError as Y}from"@latticexyz/common/errors";import{encodeSchema as ae}from"@latticexyz/schema-type";import{resolveAbiOrUserType as ce}from"@latticexyz/store/codegen";import{resolveWorldConfig as ve}from"@latticexyz/world";import Oe from"@latticexyz/world/abi/World.sol/World.json"assert{type:"json"};import ye from"@latticexyz/world/abi/IBaseWorld.sol/IBaseWorld.json"assert{type:"json"};import pe from"@latticexyz/world/abi/CoreModule.sol/CoreModule.json"assert{type:"json"};import Te from"@latticexyz/world/abi/KeysWithValueModule.sol/KeysWithValueModule.json"assert{type:"json"};import Re from"@latticexyz/world/abi/KeysInTableModule.sol/KeysInTableModule.json"assert{type:"json"};import le from"@latticexyz/world/abi/UniqueEntityModule.sol/UniqueEntityModule.json"assert{type:"json"};import ge from"@latticexyz/world/abi/SnapSyncModule.sol/SnapSyncModule.json"assert{type:"json"};async function Ie(n,a,i){let T=ve(n,a),m=Date.now(),{worldContractName:x,namespace:c,postDeployScript:U}=n,{profile:$,rpc:u,privateKey:O,priorityFeeMultiplier:B,debug:w,worldAddress:_,disableTxWait:d,pollInterval:F}=i,de=await Ce($),k=new P.providers.StaticJsonRpcProvider(u);k.pollingInterval=F;let C=new P.Wallet(O,k),E=await C.getTransactionCount();console.log("Initial nonce",E);let j,W;await L(B);let g=[],H=Number(await Pe(["block-number","--rpc-url",u],{profile:$}));console.log("Start deployment at block",H);let fe={World:_?Promise.resolve(_):x?K(x,d):h(ye.abi,Oe.bytecode,d,"World")},Be=Object.keys(T.systems).reduce((t,r)=>(t[r]=K(r,d),t),{}),Q={CoreModule:h(pe.abi,pe.bytecode,d,"CoreModule"),KeysWithValueModule:h(Te.abi,Te.bytecode,d,"KeysWithValueModule"),KeysInTableModule:h(Re.abi,Re.bytecode,d,"KeysInTableModule"),UniqueEntityModule:h(le.abi,le.bytecode,d,"UniqueEntityModule"),SnapSyncModule:h(ge.abi,ge.bytecode,d,"SnapSyncModule")},X=n.modules.filter(t=>!Q[t.name]).reduce((t,r)=>(t[r.name]=K(r.name,d),t),Q),D={...fe,...Be,...X},S=new P.Contract(await D.World,ye.abi,C),b=d?0:1;_||(console.log(p.blue("Installing core World modules")),await f(S,"installRootModule",[await X.CoreModule,"0x"],b),console.log(p.green("Installed core World modules"))),c&&await f(S,"registerNamespace",[A(c)],b);let Z={};g=[...g,...Object.entries(n.tables).map(async([t,{name:r,schema:o,keySchema:y}])=>{console.log(p.blue(`Registering table ${t} at ${c}/${r}`)),Z[t]=je(c,r);let l=Object.values(o).map(R=>{let{schemaType:I}=ce(R,n);return I}),s=Object.values(y).map(R=>{let{schemaType:I}=ce(R,n);return I});await f(S,"registerTable",[A(c),A(r),ae(l),ae(s)],b),await f(S,"setMetadata(bytes16,bytes16,string,string[])",[A(c),A(r),t,Object.keys(o)],b),console.log(p.green(`Registered table ${t} at ${r}`))})],g=[...g,...Object.entries(T.systems).map(async([t,{name:r,openAccess:o,registerFunctionSelectors:y}])=>{if(console.log(p.blue(`Registering system ${t} at ${c}/${r}`)),await f(S,"registerSystem",[A(c),A(r),await D[t],o],b),console.log(p.green(`Registered system ${t} at ${c}/${r}`)),y){let l=await Se(t),s=c==="";await Promise.all(l.map(async({functionName:R,functionArgs:I})=>{let N=s?R+I:`${c}_${r}_${R}${I}`;if(console.log(p.blue(`Registering function "${N}"`)),s){let be=Ae(N===""?{functionName:t,functionArgs:I}:{functionName:R,functionArgs:I}),Ne=Ae({functionName:R,functionArgs:I});await f(S,"registerRootFunctionSelector",[A(c),A(r),be,Ne],b)}else await f(S,"registerFunctionSelector",[A(c),A(r),R,I],b);console.log(p.green(`Registered function "${N}"`))}))}})],await Promise.all(g),g=[];for(let[t,{name:r,accessListAddresses:o,accessListSystems:y}]of Object.entries(T.systems)){let l=`${c}/${r}`;g=[...g,...o.map(async s=>{console.log(p.blue(`Grant ${s} access to ${t} (${l})`)),await f(S,"grantAccess",[A(c),A(r),s],b),console.log(p.green(`Granted ${s} access to ${t} (${c}/${r})`))})],g=[...g,...y.map(async s=>{console.log(p.blue(`Grant ${s} access to ${t} (${l})`)),await f(S,"grantAccess",[A(c),A(r),await D[s]],b),console.log(p.green(`Granted ${s} access to ${t} (${l})`))})]}await Promise.all(g),g=[],g=[...g,...n.modules.map(async t=>{console.log(p.blue(`Installing${t.root?" root ":" "}module ${t.name}`));let r=await Promise.all(t.args.map(s=>Fe(s,{tableIds:Z,systemAddresses:D}))),o=r.map(s=>s.value),y=r.map(s=>s.type),l=await D[t.name];if(!l)throw new Error(`Module ${t.name} not found`);await f(S,t.root?"installRootModule":"installModule",[l,$e.encode(y,o)],b),console.log(p.green(`Installed${t.root?" root ":" "}module ${t.name}`))})],await Promise.all(g);let M=await C.getTransactionCount(),G=0,ee=100;for(;M!==E&&G<ee;)console.log(p.gray(`Waiting for transactions to be included before executing ${U} (local nonce: ${E}, remote nonce: ${M}, retry number ${G}/${ee})`)),await new Promise(t=>setTimeout(t,F)),G++,M=await C.getTransactionCount();if(M!==E)throw new Y("Remote nonce doesn't match local nonce, indicating that not all deploy transactions were included.");g=[];let V=ie.join(await De(),U+".s.sol");return he(V)?(console.log(p.blue(`Executing post deploy script at ${V}`)),await xe(["script",U,"--sig","run(address)",await D.World,"--broadcast","--rpc-url",u,"-vvv"],{profile:$})):console.log(`No script at ${V}, skipping post deploy hook`),console.log(p.green("Deployment completed in",(Date.now()-m)/1e3,"seconds")),{worldAddress:await D.World,blockNumber:H};async function K(t,r){console.log(p.blue("Deploying",t));let{abi:o,bytecode:y}=await re(t);return h(o,y,r,t)}async function h(t,r,o,y,l=0){try{let s=new P.ContractFactory(t,r,C);console.log(p.gray(`executing deployment of ${y} with nonce ${E}`));let R=s.deploy({nonce:E++,maxPriorityFeePerGas:j,maxFeePerGas:W}).then(N=>o?N:N.deployed());g.push(R);let{address:I}=await R;return console.log(p.green("Deployed",y,"to",I)),I}catch(s){if(w&&console.error(s),l===0&&s?.message.includes("transaction already imported"))return L(B*1.1),h(t,r,o,y,l++);throw s?.message.includes("invalid bytecode")?new Y(`Error deploying ${y}: invalid bytecode. Note that linking of public libraries is not supported yet, make sure none of your libraries use "external" functions.`):s?.message.includes("CreateContractLimit")?new Y(`Error deploying ${y}: CreateContractLimit exceeded.`):s}}async function Se(t){let{abi:r}=await re(t);return r.filter(o=>["fallback","function"].includes(o.type)).map(o=>o.type==="fallback"?{functionName:"",functionArgs:""}:{functionName:o.name,functionArgs:te(o.inputs)})}function te(t){return`(${t.map(o=>{let y=o.type.match(/tuple(.*)/);return y?te(o.components)+y[1]:o.type})})`}async function f(t,r,o,y=1,l=0){let s=`${r}(${o.map(R=>`'${R}'`).join(",")})`;try{let R=await t.estimateGas[r].apply(null,o);console.log(p.gray(`executing transaction: ${s} with nonce ${E}`));let I=t[r].apply(null,[...o,{gasLimit:R,nonce:E++,maxPriorityFeePerGas:j,maxFeePerGas:W}]).then(N=>y===0?N:N.wait(y));return g.push(I),I}catch(R){if(w&&console.error(R),l===0&&R?.message.includes("transaction already imported"))return L(B*1.1),f(t,r,o,y,l++);throw new Y(`Gas estimation error for ${s}: ${R?.reason}`)}}async function re(t){let r,o=ie.join(de,t+".sol",t+".json");try{r=JSON.parse(Ue(o,"utf8"))}catch{throw new Y(`Error reading file at ${o}`)}let y=r?.bytecode?.object;if(!y)throw new Y(`No bytecode found in ${o}`);let l=r?.abi;if(!l)throw new Y(`No ABI found in ${o}`);return{abi:l,bytecode:y}}async function L(t){let r=await k.getFeeData();if(!r.lastBaseFeePerGas)throw new Y("Can not fetch lastBaseFeePerGas from RPC");if(!r.lastBaseFeePerGas.eq(0)&&(await C.getBalance()).eq(0))throw new Y(`Attempting to deploy to a chain with non-zero base fee with an account that has no balance.
|
|
21
|
+
If you're deploying to the Lattice testnet, you can fund your account by running 'pnpm mud faucet --address ${await C.getAddress()}'`);j=r.lastBaseFeePerGas.eq(0)?0:Math.floor(15e8*t),W=r.lastBaseFeePerGas.mul(2).add(j)}}function A(n){if(n.length>16)throw new Error("String does not fit into 16 bytes");let a=new Uint8Array(16);for(let i=0;i<n.length;i++)a[i]=n.charCodeAt(i);for(let i=n.length;i<16;i++)a[i]=0;return a}function je(n,a){let i=A(n),T=A(a),m=new Uint8Array(32);return m.set(i),m.set(T,16),m}function Ae({functionName:n,functionArgs:a}){let i=n+a;return i===""?"0x":Me(i)}function Me(n){return P.utils.hexDataSlice(P.utils.keccak256(P.utils.toUtf8Bytes(n)),0,4)}import{cast as Le,forge as ue,getRpcUrl as Je,getSrcDirectory as qe}from"@latticexyz/common/foundry";import{existsSync as ze,mkdirSync as He,readFileSync as Qe,writeFileSync as z}from"fs";import{ethers as ke}from"ethers";async function J(n){let{result:a}=await ke.utils.fetchJson(n,'{ "id": 42, "jsonrpc": "2.0", "method": "eth_chainId", "params": [ ] }');return Number(a)}import We from"glob";import{basename as Ge}from"path";function me(n){return We.sync(`${n}/**/*.sol`).map(a=>({path:a,basename:Ge(a,".sol")}))}async function er(n){n.profile??=process.env.FOUNDRY_PROFILE;let{configPath:a,printConfig:i,profile:T,clean:m,skipBuild:x}=n,c=n.rpc??await Je(T);console.log(v.bgBlue(v.whiteBright(`
|
|
22
|
+
Deploying MUD contracts${T?" with profile "+T:""} to RPC ${c}
|
|
23
|
+
`))),m&&await ue(["clean"],{profile:T}),x||await ue(["build"],{profile:T});let U=n?.srcDir??await qe(),$=me(U).map(({basename:w})=>w),u=await Ke(a);i&&console.log(v.green(`
|
|
24
|
+
Resolved config:
|
|
25
|
+
`),JSON.stringify(u,null,2));let O=process.env.PRIVATE_KEY;if(!O)throw new Ve(`Missing PRIVATE_KEY environment variable.
|
|
26
|
+
Run 'echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" > .env'
|
|
27
|
+
in your contracts directory to use the default anvil private key.`);let B=await Ie(u,$,{...n,rpc:c,privateKey:O});if(n.saveDeployment){let w=await J(c),_=q.join(u.deploysDirectory,w.toString());He(_,{recursive:!0}),z(q.join(_,"latest.json"),JSON.stringify(B,null,2)),z(q.join(_,Date.now()+".json"),JSON.stringify(B,null,2));let d=[1337,31337],F=ze(u.worldsFile)?JSON.parse(Qe(u.worldsFile,"utf-8")):{};F[w]={address:B.worldAddress,blockNumber:d.includes(w)?void 0:B.blockNumber},z(u.worldsFile,JSON.stringify(F,null,2)),console.log(v.bgGreen(v.whiteBright(`
|
|
28
|
+
Deployment result (written to ${u.worldsFile} and ${_}):
|
|
29
|
+
`))),await J(c)===31337&&Le(["rpc","anvil_setNextBlockBaseFeePerGas","0"])}return console.log(B),B}export{ne as a,oe as b,se as c,ct as d,J as e,me as f,er as g};
|
|
30
|
+
//# sourceMappingURL=chunk-QN5DEFJQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/render-ts/schemaTypesToRecsTypeStrings.ts","../src/render-ts/recsV1TableOptions.ts","../src/render-ts/renderRecsV1Tables.ts","../src/render-ts/tsgen.ts","../src/utils/deployHandler.ts","../src/utils/deploy.ts","../src/utils/getChainId.ts","../src/utils/getExistingContracts.ts"],"sourcesContent":["import { SchemaType } from \"@latticexyz/schema-type\";\n\nexport const schemaTypesToRecsTypeStrings: Record<SchemaType, string> = {\n [SchemaType.UINT8]: \"RecsType.Number\",\n [SchemaType.UINT16]: \"RecsType.Number\",\n [SchemaType.UINT24]: \"RecsType.Number\",\n [SchemaType.UINT32]: \"RecsType.Number\",\n [SchemaType.UINT40]: \"RecsType.Number\",\n [SchemaType.UINT48]: \"RecsType.Number\",\n [SchemaType.UINT56]: \"RecsType.BigInt\",\n [SchemaType.UINT64]: \"RecsType.BigInt\",\n [SchemaType.UINT72]: \"RecsType.BigInt\",\n [SchemaType.UINT80]: \"RecsType.BigInt\",\n [SchemaType.UINT88]: \"RecsType.BigInt\",\n [SchemaType.UINT96]: \"RecsType.BigInt\",\n [SchemaType.UINT104]: \"RecsType.BigInt\",\n [SchemaType.UINT112]: \"RecsType.BigInt\",\n [SchemaType.UINT120]: \"RecsType.BigInt\",\n [SchemaType.UINT128]: \"RecsType.BigInt\",\n [SchemaType.UINT136]: \"RecsType.BigInt\",\n [SchemaType.UINT144]: \"RecsType.BigInt\",\n [SchemaType.UINT152]: \"RecsType.BigInt\",\n [SchemaType.UINT160]: \"RecsType.BigInt\",\n [SchemaType.UINT168]: \"RecsType.BigInt\",\n [SchemaType.UINT176]: \"RecsType.BigInt\",\n [SchemaType.UINT184]: \"RecsType.BigInt\",\n [SchemaType.UINT192]: \"RecsType.BigInt\",\n [SchemaType.UINT200]: \"RecsType.BigInt\",\n [SchemaType.UINT208]: \"RecsType.BigInt\",\n [SchemaType.UINT216]: \"RecsType.BigInt\",\n [SchemaType.UINT224]: \"RecsType.BigInt\",\n [SchemaType.UINT232]: \"RecsType.BigInt\",\n [SchemaType.UINT240]: \"RecsType.BigInt\",\n [SchemaType.UINT248]: \"RecsType.BigInt\",\n [SchemaType.UINT256]: \"RecsType.BigInt\",\n [SchemaType.INT8]: \"RecsType.Number\",\n [SchemaType.INT16]: \"RecsType.Number\",\n [SchemaType.INT24]: \"RecsType.Number\",\n [SchemaType.INT32]: \"RecsType.Number\",\n [SchemaType.INT40]: \"RecsType.Number\",\n [SchemaType.INT48]: \"RecsType.Number\",\n [SchemaType.INT56]: \"RecsType.BigInt\",\n [SchemaType.INT64]: \"RecsType.BigInt\",\n [SchemaType.INT72]: \"RecsType.BigInt\",\n [SchemaType.INT80]: \"RecsType.BigInt\",\n [SchemaType.INT88]: \"RecsType.BigInt\",\n [SchemaType.INT96]: \"RecsType.BigInt\",\n [SchemaType.INT104]: \"RecsType.BigInt\",\n [SchemaType.INT112]: \"RecsType.BigInt\",\n [SchemaType.INT120]: \"RecsType.BigInt\",\n [SchemaType.INT128]: \"RecsType.BigInt\",\n [SchemaType.INT136]: \"RecsType.BigInt\",\n [SchemaType.INT144]: \"RecsType.BigInt\",\n [SchemaType.INT152]: \"RecsType.BigInt\",\n [SchemaType.INT160]: \"RecsType.BigInt\",\n [SchemaType.INT168]: \"RecsType.BigInt\",\n [SchemaType.INT176]: \"RecsType.BigInt\",\n [SchemaType.INT184]: \"RecsType.BigInt\",\n [SchemaType.INT192]: \"RecsType.BigInt\",\n [SchemaType.INT200]: \"RecsType.BigInt\",\n [SchemaType.INT208]: \"RecsType.BigInt\",\n [SchemaType.INT216]: \"RecsType.BigInt\",\n [SchemaType.INT224]: \"RecsType.BigInt\",\n [SchemaType.INT232]: \"RecsType.BigInt\",\n [SchemaType.INT240]: \"RecsType.BigInt\",\n [SchemaType.INT248]: \"RecsType.BigInt\",\n [SchemaType.INT256]: \"RecsType.BigInt\",\n [SchemaType.BYTES1]: \"RecsType.String\",\n [SchemaType.BYTES2]: \"RecsType.String\",\n [SchemaType.BYTES3]: \"RecsType.String\",\n [SchemaType.BYTES4]: \"RecsType.String\",\n [SchemaType.BYTES5]: \"RecsType.String\",\n [SchemaType.BYTES6]: \"RecsType.String\",\n [SchemaType.BYTES7]: \"RecsType.String\",\n [SchemaType.BYTES8]: \"RecsType.String\",\n [SchemaType.BYTES9]: \"RecsType.String\",\n [SchemaType.BYTES10]: \"RecsType.String\",\n [SchemaType.BYTES11]: \"RecsType.String\",\n [SchemaType.BYTES12]: \"RecsType.String\",\n [SchemaType.BYTES13]: \"RecsType.String\",\n [SchemaType.BYTES14]: \"RecsType.String\",\n [SchemaType.BYTES15]: \"RecsType.String\",\n [SchemaType.BYTES16]: \"RecsType.String\",\n [SchemaType.BYTES17]: \"RecsType.String\",\n [SchemaType.BYTES18]: \"RecsType.String\",\n [SchemaType.BYTES19]: \"RecsType.String\",\n [SchemaType.BYTES20]: \"RecsType.String\",\n [SchemaType.BYTES21]: \"RecsType.String\",\n [SchemaType.BYTES22]: \"RecsType.String\",\n [SchemaType.BYTES23]: \"RecsType.String\",\n [SchemaType.BYTES24]: \"RecsType.String\",\n [SchemaType.BYTES25]: \"RecsType.String\",\n [SchemaType.BYTES26]: \"RecsType.String\",\n [SchemaType.BYTES27]: \"RecsType.String\",\n [SchemaType.BYTES28]: \"RecsType.String\",\n [SchemaType.BYTES29]: \"RecsType.String\",\n [SchemaType.BYTES30]: \"RecsType.String\",\n [SchemaType.BYTES31]: \"RecsType.String\",\n [SchemaType.BYTES32]: \"RecsType.String\",\n [SchemaType.BOOL]: \"RecsType.Boolean\",\n [SchemaType.ADDRESS]: \"RecsType.String\",\n [SchemaType.UINT8_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT16_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT24_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT32_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT40_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT48_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT56_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT64_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT72_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT80_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT88_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT96_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT104_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT112_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT120_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT128_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT136_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT144_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT152_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT160_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT168_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT176_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT184_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT192_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT200_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT208_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT216_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT224_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT232_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT240_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT248_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT256_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT8_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT16_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT24_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT32_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT40_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT48_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT56_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT64_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT72_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT80_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT88_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT96_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT104_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT112_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT120_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT128_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT136_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT144_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT152_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT160_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT168_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT176_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT184_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT192_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT200_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT208_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT216_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT224_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT232_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT240_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT248_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT256_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES1_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES2_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES3_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES4_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES5_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES6_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES7_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES8_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES9_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES10_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES11_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES12_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES13_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES14_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES15_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES16_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES17_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES18_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES19_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES20_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES21_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES22_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES23_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES24_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES25_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES26_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES27_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES28_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES29_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES30_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES31_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES32_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BOOL_ARRAY]: \"RecsType.T\", // no boolean array\n [SchemaType.ADDRESS_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES]: \"RecsType.String\",\n [SchemaType.STRING]: \"RecsType.String\",\n};\n","import { StoreConfig } from \"@latticexyz/store\";\nimport { resolveAbiOrUserType } from \"@latticexyz/store/codegen\";\nimport { schemaTypesToRecsTypeStrings } from \"./schemaTypesToRecsTypeStrings\";\nimport { RecsV1TableOptions } from \"./types\";\n\nexport function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions {\n const tableOptions = [];\n for (const tableName of Object.keys(config.tables)) {\n const tableData = config.tables[tableName];\n\n const fields = Object.keys(tableData.schema).map((name) => {\n const abiOrUserType = tableData.schema[name];\n const { schemaType } = resolveAbiOrUserType(abiOrUserType, config);\n\n const recsTypeString = schemaTypesToRecsTypeStrings[schemaType];\n\n return {\n recsTypeString,\n name,\n };\n });\n\n // WARNING: skip tables without a static tableId\n if (tableData.tableIdArgument) continue;\n const staticResourceData = {\n namespace: config.namespace,\n name: tableData.name,\n };\n\n tableOptions.push({\n tableName,\n fields,\n staticResourceData,\n });\n }\n return {\n tables: tableOptions,\n };\n}\n","import { RecsV1TableOptions } from \"./types\";\n\nexport function renderRecsV1Tables(options: RecsV1TableOptions) {\n const { tables } = options;\n\n return `/* Autogenerated file. Do not edit manually. */\n\nimport { TableId } from \"@latticexyz/utils\";\nimport { defineComponent, Type as RecsType, World } from \"@latticexyz/recs\";\n\nexport function defineContractComponents(world: World) {\n return {\n ${tables.map((table) => `${table.tableName}: ${renderDefineComponent(table)},`).join(\"\")}\n }\n}\n`;\n}\n\nfunction renderDefineComponent(table: RecsV1TableOptions[\"tables\"][number]) {\n const { namespace, name } = table.staticResourceData;\n return `\n (() => {\n const tableId = new TableId(\"${namespace}\", \"${name}\");\n return defineComponent(world, {\n ${table.fields.map(({ name, recsTypeString }) => `${name}: ${recsTypeString},`).join(\"\")}\n }, {\n metadata: { contractId: tableId.toHexString(), tableId: tableId.toString() },\n });\n })()\n `;\n}\n","import path from \"path\";\nimport { StoreConfig } from \"@latticexyz/store\";\nimport { formatAndWriteTypescript } from \"@latticexyz/common/codegen\";\nimport { getRecsV1TableOptions } from \"../render-ts/recsV1TableOptions\";\nimport { renderRecsV1Tables } from \"../render-ts/renderRecsV1Tables\";\n\nexport async function tsgen(config: StoreConfig, outDirectory: string) {\n const fullOutputPath = path.join(outDirectory, `contractComponents.ts`);\n const options = getRecsV1TableOptions(config);\n const output = renderRecsV1Tables(options);\n formatAndWriteTypescript(output, fullOutputPath, \"Generated ts definition files\");\n}\n","import chalk from \"chalk\";\nimport path from \"path\";\nimport { MUDError } from \"@latticexyz/common/errors\";\nimport { loadConfig } from \"@latticexyz/config/node\";\nimport { StoreConfig } from \"@latticexyz/store\";\nimport { WorldConfig } from \"@latticexyz/world\";\nimport { deploy } from \"../utils/deploy\";\nimport { cast, forge, getRpcUrl, getSrcDirectory } from \"@latticexyz/common/foundry\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { getChainId } from \"../utils/getChainId\";\nimport { getExistingContracts } from \"./getExistingContracts\";\n\nexport type DeployOptions = {\n configPath?: string;\n printConfig?: boolean;\n profile?: string;\n priorityFeeMultiplier: number;\n clean?: boolean;\n debug?: boolean;\n saveDeployment: boolean;\n rpc?: string;\n worldAddress?: string;\n srcDir?: string;\n disableTxWait: boolean;\n pollInterval: number;\n skipBuild?: boolean;\n};\n\nexport async function deployHandler(args: DeployOptions) {\n args.profile ??= process.env.FOUNDRY_PROFILE;\n const { configPath, printConfig, profile, clean, skipBuild } = args;\n\n const rpc = args.rpc ?? (await getRpcUrl(profile));\n console.log(\n chalk.bgBlue(\n chalk.whiteBright(`\\n Deploying MUD contracts${profile ? \" with profile \" + profile : \"\"} to RPC ${rpc} \\n`)\n )\n );\n\n if (clean) await forge([\"clean\"], { profile });\n\n // Run forge build\n if (!skipBuild) await forge([\"build\"], { profile });\n\n // Get a list of all contract names\n const srcDir = args?.srcDir ?? (await getSrcDirectory());\n const existingContractNames = getExistingContracts(srcDir).map(({ basename }) => basename);\n\n // Load the config\n const mudConfig = (await loadConfig(configPath)) as StoreConfig & WorldConfig;\n\n if (printConfig) console.log(chalk.green(\"\\nResolved config:\\n\"), JSON.stringify(mudConfig, null, 2));\n\n const privateKey = process.env.PRIVATE_KEY;\n if (!privateKey)\n throw new MUDError(\n `Missing PRIVATE_KEY environment variable.\nRun 'echo \"PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80\" > .env'\nin your contracts directory to use the default anvil private key.`\n );\n const deploymentInfo = await deploy(mudConfig, existingContractNames, { ...args, rpc, privateKey });\n\n if (args.saveDeployment) {\n // Write deployment result to file (latest and timestamp)\n const chainId = await getChainId(rpc);\n const outputDir = path.join(mudConfig.deploysDirectory, chainId.toString());\n mkdirSync(outputDir, { recursive: true });\n writeFileSync(path.join(outputDir, \"latest.json\"), JSON.stringify(deploymentInfo, null, 2));\n writeFileSync(path.join(outputDir, Date.now() + \".json\"), JSON.stringify(deploymentInfo, null, 2));\n\n const localChains = [1337, 31337];\n const deploys = existsSync(mudConfig.worldsFile) ? JSON.parse(readFileSync(mudConfig.worldsFile, \"utf-8\")) : {};\n deploys[chainId] = {\n address: deploymentInfo.worldAddress,\n // We expect the worlds file to be committed and since local deployments are often a consistent address but different block number, we'll ignore the block number.\n blockNumber: localChains.includes(chainId) ? undefined : deploymentInfo.blockNumber,\n };\n writeFileSync(mudConfig.worldsFile, JSON.stringify(deploys, null, 2));\n\n console.log(\n chalk.bgGreen(chalk.whiteBright(`\\n Deployment result (written to ${mudConfig.worldsFile} and ${outputDir}): \\n`))\n );\n\n // Reset base fee back to 0 if deploying to a local chain.\n // This is a temporary workaround until the issue is fixed upstream,\n // see https://github.com/foundry-rs/foundry/issues/5161\n if ((await getChainId(rpc)) === 31337) {\n cast([\"rpc\", \"anvil_setNextBlockBaseFeePerGas\", \"0\"]);\n }\n }\n\n console.log(deploymentInfo);\n return deploymentInfo;\n}\n","import { existsSync, readFileSync } from \"fs\";\nimport path from \"path\";\nimport chalk from \"chalk\";\nimport { BigNumber, ContractInterface, ethers } from \"ethers\";\nimport { defaultAbiCoder as abi, Fragment, ParamType } from \"ethers/lib/utils.js\";\n\nimport { getOutDirectory, getScriptDirectory, cast, forge } from \"@latticexyz/common/foundry\";\nimport { resolveWithContext } from \"@latticexyz/config\";\nimport { MUDError } from \"@latticexyz/common/errors\";\nimport { encodeSchema } from \"@latticexyz/schema-type\";\nimport { StoreConfig } from \"@latticexyz/store\";\nimport { resolveAbiOrUserType } from \"@latticexyz/store/codegen\";\nimport { WorldConfig, resolveWorldConfig } from \"@latticexyz/world\";\nimport { IBaseWorld } from \"@latticexyz/world/types/ethers-contracts/IBaseWorld\";\nimport WorldData from \"@latticexyz/world/abi/World.sol/World.json\" assert { type: \"json\" };\nimport IBaseWorldData from \"@latticexyz/world/abi/IBaseWorld.sol/IBaseWorld.json\" assert { type: \"json\" };\nimport CoreModuleData from \"@latticexyz/world/abi/CoreModule.sol/CoreModule.json\" assert { type: \"json\" };\nimport KeysWithValueModuleData from \"@latticexyz/world/abi/KeysWithValueModule.sol/KeysWithValueModule.json\" assert { type: \"json\" };\nimport KeysInTableModuleData from \"@latticexyz/world/abi/KeysInTableModule.sol/KeysInTableModule.json\" assert { type: \"json\" };\nimport UniqueEntityModuleData from \"@latticexyz/world/abi/UniqueEntityModule.sol/UniqueEntityModule.json\" assert { type: \"json\" };\nimport SnapSyncModuleData from \"@latticexyz/world/abi/SnapSyncModule.sol/SnapSyncModule.json\" assert { type: \"json\" };\n\nexport interface DeployConfig {\n profile?: string;\n rpc: string;\n privateKey: string;\n priorityFeeMultiplier: number;\n debug?: boolean;\n worldAddress?: string;\n disableTxWait: boolean;\n pollInterval: number;\n}\n\nexport interface DeploymentInfo {\n blockNumber: number;\n worldAddress: string;\n}\n\nexport async function deploy(\n mudConfig: StoreConfig & WorldConfig,\n existingContractNames: string[],\n deployConfig: DeployConfig\n): Promise<DeploymentInfo> {\n const resolvedConfig = resolveWorldConfig(mudConfig, existingContractNames);\n\n const startTime = Date.now();\n const { worldContractName, namespace, postDeployScript } = mudConfig;\n const { profile, rpc, privateKey, priorityFeeMultiplier, debug, worldAddress, disableTxWait, pollInterval } =\n deployConfig;\n const forgeOutDirectory = await getOutDirectory(profile);\n\n // Set up signer for deployment\n const provider = new ethers.providers.StaticJsonRpcProvider(rpc);\n provider.pollingInterval = pollInterval;\n const signer = new ethers.Wallet(privateKey, provider);\n\n // Manual nonce handling to allow for faster sending of transactions without waiting for previous transactions\n let nonce = await signer.getTransactionCount();\n console.log(\"Initial nonce\", nonce);\n\n // Compute maxFeePerGas and maxPriorityFeePerGas like ethers, but allow for a multiplier to allow replacing pending transactions\n let maxPriorityFeePerGas: number;\n let maxFeePerGas: BigNumber;\n await setInternalFeePerGas(priorityFeeMultiplier);\n\n // Catch all to await any promises before exiting the script\n let promises: Promise<unknown>[] = [];\n\n // Get block number before deploying\n const blockNumber = Number(await cast([\"block-number\", \"--rpc-url\", rpc], { profile }));\n console.log(\"Start deployment at block\", blockNumber);\n\n // Deploy World\n const worldPromise = {\n World: worldAddress\n ? Promise.resolve(worldAddress)\n : worldContractName\n ? deployContractByName(worldContractName, disableTxWait)\n : deployContract(IBaseWorldData.abi, WorldData.bytecode, disableTxWait, \"World\"),\n };\n\n // Deploy Systems\n const systemPromises = Object.keys(resolvedConfig.systems).reduce<Record<string, Promise<string>>>(\n (acc, systemName) => {\n acc[systemName] = deployContractByName(systemName, disableTxWait);\n return acc;\n },\n {}\n );\n\n // Deploy default World modules\n const defaultModules: Record<string, Promise<string>> = {\n // TODO: these only need to be deployed once per chain, add a check if they exist already\n CoreModule: deployContract(CoreModuleData.abi, CoreModuleData.bytecode, disableTxWait, \"CoreModule\"),\n KeysWithValueModule: deployContract(\n KeysWithValueModuleData.abi,\n KeysWithValueModuleData.bytecode,\n disableTxWait,\n \"KeysWithValueModule\"\n ),\n KeysInTableModule: deployContract(\n KeysInTableModuleData.abi,\n KeysInTableModuleData.bytecode,\n disableTxWait,\n \"KeysInTableModule\"\n ),\n UniqueEntityModule: deployContract(\n UniqueEntityModuleData.abi,\n UniqueEntityModuleData.bytecode,\n disableTxWait,\n \"UniqueEntityModule\"\n ),\n SnapSyncModule: deployContract(\n SnapSyncModuleData.abi,\n SnapSyncModuleData.bytecode,\n disableTxWait,\n \"SnapSyncModule\"\n ),\n };\n\n // Deploy user Modules\n const modulePromises = mudConfig.modules\n .filter((module) => !defaultModules[module.name]) // Only deploy user modules here, not default modules\n .reduce<Record<string, Promise<string>>>((acc, module) => {\n acc[module.name] = deployContractByName(module.name, disableTxWait);\n return acc;\n }, defaultModules);\n\n // Combine all contracts into one object\n const contractPromises: Record<string, Promise<string>> = { ...worldPromise, ...systemPromises, ...modulePromises };\n\n // Create World contract instance from deployed address\n const WorldContract = new ethers.Contract(await contractPromises.World, IBaseWorldData.abi, signer) as IBaseWorld;\n\n const confirmations = disableTxWait ? 0 : 1;\n\n // Install core Modules\n if (!worldAddress) {\n console.log(chalk.blue(\"Installing core World modules\"));\n await fastTxExecute(WorldContract, \"installRootModule\", [await modulePromises.CoreModule, \"0x\"], confirmations);\n console.log(chalk.green(\"Installed core World modules\"));\n }\n\n // Register namespace\n if (namespace) await fastTxExecute(WorldContract, \"registerNamespace\", [toBytes16(namespace)], confirmations);\n\n // Register tables\n const tableIds: { [tableName: string]: Uint8Array } = {};\n promises = [\n ...promises,\n ...Object.entries(mudConfig.tables).map(async ([tableName, { name, schema, keySchema }]) => {\n console.log(chalk.blue(`Registering table ${tableName} at ${namespace}/${name}`));\n\n // Store the tableId for later use\n tableIds[tableName] = toResourceSelector(namespace, name);\n\n // Register table\n const schemaTypes = Object.values(schema).map((abiOrUserType) => {\n const { schemaType } = resolveAbiOrUserType(abiOrUserType, mudConfig);\n return schemaType;\n });\n\n const keyTypes = Object.values(keySchema).map((abiOrUserType) => {\n const { schemaType } = resolveAbiOrUserType(abiOrUserType, mudConfig);\n return schemaType;\n });\n\n await fastTxExecute(\n WorldContract,\n \"registerTable\",\n [toBytes16(namespace), toBytes16(name), encodeSchema(schemaTypes), encodeSchema(keyTypes)],\n confirmations\n );\n\n // Register table metadata\n await fastTxExecute(\n WorldContract,\n \"setMetadata(bytes16,bytes16,string,string[])\",\n [toBytes16(namespace), toBytes16(name), tableName, Object.keys(schema)],\n confirmations\n );\n\n console.log(chalk.green(`Registered table ${tableName} at ${name}`));\n }),\n ];\n\n // Register systems (using forEach instead of for..of to avoid blocking on async calls)\n promises = [\n ...promises,\n ...Object.entries(resolvedConfig.systems).map(\n async ([systemName, { name, openAccess, registerFunctionSelectors }]) => {\n // Register system at route\n console.log(chalk.blue(`Registering system ${systemName} at ${namespace}/${name}`));\n await fastTxExecute(\n WorldContract,\n \"registerSystem\",\n [toBytes16(namespace), toBytes16(name), await contractPromises[systemName], openAccess],\n confirmations\n );\n console.log(chalk.green(`Registered system ${systemName} at ${namespace}/${name}`));\n\n // Register function selectors for the system\n if (registerFunctionSelectors) {\n const functionSignatures: FunctionSignature[] = await loadFunctionSignatures(systemName);\n const isRoot = namespace === \"\";\n // Using Promise.all to avoid blocking on async calls\n await Promise.all(\n functionSignatures.map(async ({ functionName, functionArgs }) => {\n const functionSignature = isRoot\n ? functionName + functionArgs\n : `${namespace}_${name}_${functionName}${functionArgs}`;\n\n console.log(chalk.blue(`Registering function \"${functionSignature}\"`));\n if (isRoot) {\n const worldFunctionSelector = toFunctionSelector(\n functionSignature === \"\"\n ? { functionName: systemName, functionArgs } // Register the system's fallback function as `<systemName>(<args>)`\n : { functionName, functionArgs }\n );\n const systemFunctionSelector = toFunctionSelector({ functionName, functionArgs });\n await fastTxExecute(\n WorldContract,\n \"registerRootFunctionSelector\",\n [toBytes16(namespace), toBytes16(name), worldFunctionSelector, systemFunctionSelector],\n confirmations\n );\n } else {\n await fastTxExecute(\n WorldContract,\n \"registerFunctionSelector\",\n [toBytes16(namespace), toBytes16(name), functionName, functionArgs],\n confirmations\n );\n }\n console.log(chalk.green(`Registered function \"${functionSignature}\"`));\n })\n );\n }\n }\n ),\n ];\n\n // Wait for resources to be registered before granting access to them\n await Promise.all(promises); // ----------------------------------------------------------------------------------------------\n promises = [];\n\n // Grant access to systems\n for (const [systemName, { name, accessListAddresses, accessListSystems }] of Object.entries(resolvedConfig.systems)) {\n const resourceSelector = `${namespace}/${name}`;\n\n // Grant access to addresses\n promises = [\n ...promises,\n ...accessListAddresses.map(async (address) => {\n console.log(chalk.blue(`Grant ${address} access to ${systemName} (${resourceSelector})`));\n await fastTxExecute(\n WorldContract,\n \"grantAccess\",\n [toBytes16(namespace), toBytes16(name), address],\n confirmations\n );\n console.log(chalk.green(`Granted ${address} access to ${systemName} (${namespace}/${name})`));\n }),\n ];\n\n // Grant access to other systems\n promises = [\n ...promises,\n ...accessListSystems.map(async (granteeSystem) => {\n console.log(chalk.blue(`Grant ${granteeSystem} access to ${systemName} (${resourceSelector})`));\n await fastTxExecute(\n WorldContract,\n \"grantAccess\",\n [toBytes16(namespace), toBytes16(name), await contractPromises[granteeSystem]],\n confirmations\n );\n console.log(chalk.green(`Granted ${granteeSystem} access to ${systemName} (${resourceSelector})`));\n }),\n ];\n }\n\n // Wait for access to be granted before installing modules\n await Promise.all(promises); // ----------------------------------------------------------------------------------------------\n promises = [];\n\n // Install modules\n promises = [\n ...promises,\n ...mudConfig.modules.map(async (module) => {\n console.log(chalk.blue(`Installing${module.root ? \" root \" : \" \"}module ${module.name}`));\n // Resolve arguments\n const resolvedArgs = await Promise.all(\n module.args.map((arg) => resolveWithContext(arg, { tableIds, systemAddresses: contractPromises }))\n );\n const values = resolvedArgs.map((arg) => arg.value);\n const types = resolvedArgs.map((arg) => arg.type);\n const moduleAddress = await contractPromises[module.name];\n if (!moduleAddress) throw new Error(`Module ${module.name} not found`);\n\n // Send transaction to install module\n await fastTxExecute(\n WorldContract,\n module.root ? \"installRootModule\" : \"installModule\",\n [moduleAddress, abi.encode(types, values)],\n confirmations\n );\n\n console.log(chalk.green(`Installed${module.root ? \" root \" : \" \"}module ${module.name}`));\n }),\n ];\n\n // Await all promises before executing PostDeploy script\n await Promise.all(promises); // ----------------------------------------------------------------------------------------------\n\n // Confirm the current nonce is the expected nonce to make sure all transactions have been included\n let remoteNonce = await signer.getTransactionCount();\n let retryCount = 0;\n const maxRetries = 100;\n while (remoteNonce !== nonce && retryCount < maxRetries) {\n console.log(\n chalk.gray(\n `Waiting for transactions to be included before executing ${postDeployScript} (local nonce: ${nonce}, remote nonce: ${remoteNonce}, retry number ${retryCount}/${maxRetries})`\n )\n );\n await new Promise((resolve) => setTimeout(resolve, pollInterval));\n retryCount++;\n remoteNonce = await signer.getTransactionCount();\n }\n if (remoteNonce !== nonce) {\n throw new MUDError(\n \"Remote nonce doesn't match local nonce, indicating that not all deploy transactions were included.\"\n );\n }\n\n promises = [];\n\n // Execute postDeploy forge script\n const postDeployPath = path.join(await getScriptDirectory(), postDeployScript + \".s.sol\");\n if (existsSync(postDeployPath)) {\n console.log(chalk.blue(`Executing post deploy script at ${postDeployPath}`));\n await forge(\n [\n \"script\",\n postDeployScript,\n \"--sig\",\n \"run(address)\",\n await contractPromises.World,\n \"--broadcast\",\n \"--rpc-url\",\n rpc,\n \"-vvv\",\n ],\n {\n profile,\n }\n );\n } else {\n console.log(`No script at ${postDeployPath}, skipping post deploy hook`);\n }\n\n console.log(chalk.green(\"Deployment completed in\", (Date.now() - startTime) / 1000, \"seconds\"));\n\n return { worldAddress: await contractPromises.World, blockNumber };\n\n // ------------------- INTERNAL FUNCTIONS -------------------\n // (Inlined to avoid having to pass around nonce, signer and forgeOutDir)\n\n /**\n * Deploy a contract and return the address\n * @param contractName Name of the contract to deploy (must exist in the file system)\n * @param disableTxWait Disable waiting for contract deployment\n * @returns Address of the deployed contract\n */\n async function deployContractByName(contractName: string, disableTxWait: boolean): Promise<string> {\n console.log(chalk.blue(\"Deploying\", contractName));\n\n const { abi, bytecode } = await getContractData(contractName);\n return deployContract(abi, bytecode, disableTxWait, contractName);\n }\n\n /**\n * Deploy a contract and return the address\n * @param abi The contract interface\n * @param bytecode The contract bytecode\n * @param disableTxWait Disable waiting for contract deployment\n * @param contractName The contract name (optional, used for logs)\n * @param retryCount\n * @returns Address of the deployed contract\n */\n async function deployContract(\n abi: ContractInterface,\n bytecode: string | { object: string },\n disableTxWait: boolean,\n contractName?: string,\n retryCount = 0\n ): Promise<string> {\n try {\n const factory = new ethers.ContractFactory(abi, bytecode, signer);\n console.log(chalk.gray(`executing deployment of ${contractName} with nonce ${nonce}`));\n const deployPromise = factory\n .deploy({\n nonce: nonce++,\n maxPriorityFeePerGas,\n maxFeePerGas,\n })\n .then((c) => (disableTxWait ? c : c.deployed()));\n\n promises.push(deployPromise);\n const { address } = await deployPromise;\n\n console.log(chalk.green(\"Deployed\", contractName, \"to\", address));\n return address;\n } catch (error: any) {\n if (debug) console.error(error);\n if (retryCount === 0 && error?.message.includes(\"transaction already imported\")) {\n // If the deployment failed because the transaction was already imported,\n // retry with a higher priority fee\n setInternalFeePerGas(priorityFeeMultiplier * 1.1);\n return deployContract(abi, bytecode, disableTxWait, contractName, retryCount++);\n } else if (error?.message.includes(\"invalid bytecode\")) {\n throw new MUDError(\n `Error deploying ${contractName}: invalid bytecode. Note that linking of public libraries is not supported yet, make sure none of your libraries use \"external\" functions.`\n );\n } else if (error?.message.includes(\"CreateContractLimit\")) {\n throw new MUDError(`Error deploying ${contractName}: CreateContractLimit exceeded.`);\n } else throw error;\n }\n }\n\n /**\n * Deploy a contract and return the address\n * @param contractName Name of the contract to deploy (must exist in the file system)\n * @returns Address of the deployed contract\n *\n * NOTE: Forge deploy seems to be slightly slower than ethers\n * (probably due to the extra overhead spawning a child process to run forge),\n * so we mostly use ethersDeployContract here.\n * However, for contracts not in the user directory (eg. the vanilla World contract),\n * using forge is more convenient because it automatically finds the contract in the @latticexyz/world package.\n */\n // async function forgeDeployContract(contractName: string): Promise<string> {\n // console.log(chalk.blue(\"Deploying\", contractName));\n\n // const { deployedTo } = JSON.parse(\n // await forge(\n // [\"create\", contractName, \"--rpc-url\", rpc, \"--private-key\", privateKey, \"--json\", \"--nonce\", String(nonce++)],\n // { profile, silent: true }\n // )\n // );\n // return deployedTo;\n // }\n\n async function loadFunctionSignatures(contractName: string): Promise<FunctionSignature[]> {\n const { abi } = await getContractData(contractName);\n\n return abi\n .filter((item) => [\"fallback\", \"function\"].includes(item.type))\n .map((item) => {\n if (item.type === \"fallback\") return { functionName: \"\", functionArgs: \"\" };\n\n return {\n functionName: item.name,\n functionArgs: parseComponents(item.inputs),\n };\n });\n }\n\n /**\n * Recursively turn (nested) structs in signatures into tuples\n */\n function parseComponents(params: ParamType[]): string {\n const components = params.map((param) => {\n const tupleMatch = param.type.match(/tuple(.*)/);\n if (tupleMatch) {\n // there can be arrays of tuples,\n // `tupleMatch[1]` preserves the array brackets (or is empty string for non-arrays)\n return parseComponents(param.components) + tupleMatch[1];\n } else {\n return param.type;\n }\n });\n return `(${components})`;\n }\n\n /**\n * Only await gas estimation (for speed), only execute if gas estimation succeeds (for safety)\n */\n async function fastTxExecute<C extends { estimateGas: any; [key: string]: any }, F extends keyof C>(\n contract: C,\n func: F,\n args: Parameters<C[F]>,\n confirmations = 1,\n retryCount = 0\n ): Promise<Awaited<ReturnType<Awaited<ReturnType<C[F]>>[\"wait\"]>>> {\n const functionName = `${func as string}(${args.map((arg) => `'${arg}'`).join(\",\")})`;\n try {\n const gasLimit = await contract.estimateGas[func].apply(null, args);\n console.log(chalk.gray(`executing transaction: ${functionName} with nonce ${nonce}`));\n const txPromise = contract[func]\n .apply(null, [...args, { gasLimit, nonce: nonce++, maxPriorityFeePerGas, maxFeePerGas }])\n .then((tx: any) => (confirmations === 0 ? tx : tx.wait(confirmations)));\n promises.push(txPromise);\n return txPromise;\n } catch (error: any) {\n if (debug) console.error(error);\n if (retryCount === 0 && error?.message.includes(\"transaction already imported\")) {\n // If the deployment failed because the transaction was already imported,\n // retry with a higher priority fee\n setInternalFeePerGas(priorityFeeMultiplier * 1.1);\n return fastTxExecute(contract, func, args, confirmations, retryCount++);\n } else throw new MUDError(`Gas estimation error for ${functionName}: ${error?.reason}`);\n }\n }\n\n /**\n * Load the contract's abi and bytecode from the file system\n * @param contractName: Name of the contract to load\n */\n async function getContractData(contractName: string): Promise<{ bytecode: string; abi: Fragment[] }> {\n let data: any;\n const contractDataPath = path.join(forgeOutDirectory, contractName + \".sol\", contractName + \".json\");\n try {\n data = JSON.parse(readFileSync(contractDataPath, \"utf8\"));\n } catch (error: any) {\n throw new MUDError(`Error reading file at ${contractDataPath}`);\n }\n\n const bytecode = data?.bytecode?.object;\n if (!bytecode) throw new MUDError(`No bytecode found in ${contractDataPath}`);\n\n const abi = data?.abi;\n if (!abi) throw new MUDError(`No ABI found in ${contractDataPath}`);\n\n return { abi, bytecode };\n }\n\n /**\n * Set the maxFeePerGas and maxPriorityFeePerGas based on the current base fee and the given multiplier.\n * The multiplier is used to allow replacing pending transactions.\n * @param multiplier Multiplier to apply to the base fee\n */\n async function setInternalFeePerGas(multiplier: number) {\n // Compute maxFeePerGas and maxPriorityFeePerGas like ethers, but allow for a multiplier to allow replacing pending transactions\n const feeData = await provider.getFeeData();\n if (!feeData.lastBaseFeePerGas) throw new MUDError(\"Can not fetch lastBaseFeePerGas from RPC\");\n if (!feeData.lastBaseFeePerGas.eq(0) && (await signer.getBalance()).eq(0)) {\n throw new MUDError(`Attempting to deploy to a chain with non-zero base fee with an account that has no balance.\nIf you're deploying to the Lattice testnet, you can fund your account by running 'pnpm mud faucet --address ${await signer.getAddress()}'`);\n }\n\n // Set the priority fee to 0 for development chains with no base fee, to allow transactions from unfunded wallets\n maxPriorityFeePerGas = feeData.lastBaseFeePerGas.eq(0) ? 0 : Math.floor(1_500_000_000 * multiplier);\n maxFeePerGas = feeData.lastBaseFeePerGas.mul(2).add(maxPriorityFeePerGas);\n }\n}\n\n// TODO: use stringToBytes16 from utils as soon as utils are usable inside cli\n// (see https://github.com/latticexyz/mud/issues/499)\nfunction toBytes16(input: string) {\n if (input.length > 16) throw new Error(\"String does not fit into 16 bytes\");\n\n const result = new Uint8Array(16);\n // Set ascii bytes\n for (let i = 0; i < input.length; i++) {\n result[i] = input.charCodeAt(i);\n }\n // Set the remaining bytes to 0\n for (let i = input.length; i < 16; i++) {\n result[i] = 0;\n }\n return result;\n}\n\n// TODO: use TableId from utils as soon as utils are usable inside cli\n// (see https://github.com/latticexyz/mud/issues/499)\nfunction toResourceSelector(namespace: string, file: string): Uint8Array {\n const namespaceBytes = toBytes16(namespace);\n const fileBytes = toBytes16(file);\n const result = new Uint8Array(32);\n result.set(namespaceBytes);\n result.set(fileBytes, 16);\n return result;\n}\n\ninterface FunctionSignature {\n functionName: string;\n functionArgs: string;\n}\n\n// TODO: move this to utils as soon as utils are usable inside cli\n// (see https://github.com/latticexyz/mud/issues/499)\nfunction toFunctionSelector({ functionName, functionArgs }: FunctionSignature): string {\n const functionSignature = functionName + functionArgs;\n if (functionSignature === \"\") return \"0x\";\n return sigHash(functionSignature);\n}\n\n// TODO: move this to utils as soon as utils are usable inside cli\n// (see https://github.com/latticexyz/mud/issues/499)\nfunction sigHash(signature: string) {\n return ethers.utils.hexDataSlice(ethers.utils.keccak256(ethers.utils.toUtf8Bytes(signature)), 0, 4);\n}\n","import { ethers } from \"ethers\";\n\n// TODO: Use viem's getChainId\nexport async function getChainId(rpc: string) {\n const { result: chainId } = await ethers.utils.fetchJson(\n rpc,\n '{ \"id\": 42, \"jsonrpc\": \"2.0\", \"method\": \"eth_chainId\", \"params\": [ ] }'\n );\n return Number(chainId);\n}\n","import glob from \"glob\";\nimport { basename } from \"path\";\n\n/**\n * Get a list of all contract paths/names within the provided src directory\n */\nexport function getExistingContracts(srcDir: string) {\n return glob.sync(`${srcDir}/**/*.sol`).map((path) => ({\n path,\n basename: basename(path, \".sol\"),\n }));\n}\n"],"mappings":"AAAA,OAAS,cAAAA,MAAkB,0BAEpB,IAAMC,GAA2D,CACtE,CAACD,EAAW,KAAK,EAAG,kBACpB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,MAAM,EAAG,kBACrB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAAO,EAAG,kBACtB,CAACA,EAAW,OAA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SchemaType","schemaTypesToRecsTypeStrings","resolveAbiOrUserType","getRecsV1TableOptions","config","tableOptions","tableName","tableData","fields","name","abiOrUserType","schemaType","resolveAbiOrUserType","schemaTypesToRecsTypeStrings","staticResourceData","renderRecsV1Tables","options","tables","table","renderDefineComponent","namespace","name","recsTypeString","path","formatAndWriteTypescript","tsgen","config","outDirectory","fullOutputPath","path","options","getRecsV1TableOptions","output","renderRecsV1Tables","formatAndWriteTypescript","chalk","path","MUDError","loadConfig","existsSync","readFileSync","path","chalk","ethers","abi","getOutDirectory","getScriptDirectory","cast","forge","resolveWithContext","MUDError","encodeSchema","resolveAbiOrUserType","resolveWorldConfig","WorldData","IBaseWorldData","CoreModuleData","KeysWithValueModuleData","KeysInTableModuleData","UniqueEntityModuleData","SnapSyncModuleData","deploy","mudConfig","existingContractNames","deployConfig","resolvedConfig","startTime","worldContractName","namespace","postDeployScript","profile","rpc","privateKey","priorityFeeMultiplier","debug","worldAddress","disableTxWait","pollInterval","forgeOutDirectory","provider","signer","nonce","maxPriorityFeePerGas","maxFeePerGas","setInternalFeePerGas","promises","blockNumber","worldPromise","deployContractByName","deployContract","systemPromises","acc","systemName","defaultModules","modulePromises","module","contractPromises","WorldContract","confirmations","fastTxExecute","toBytes16","tableIds","tableName","name","schema","keySchema","toResourceSelector","schemaTypes","abiOrUserType","schemaType","keyTypes","openAccess","registerFunctionSelectors","functionSignatures","loadFunctionSignatures","isRoot","functionName","functionArgs","functionSignature","worldFunctionSelector","toFunctionSelector","systemFunctionSelector","accessListAddresses","accessListSystems","resourceSelector","address","granteeSystem","resolvedArgs","arg","values","types","moduleAddress","remoteNonce","retryCount","maxRetries","resolve","postDeployPath","contractName","bytecode","getContractData","factory","deployPromise","c","error","item","parseComponents","params","param","tupleMatch","contract","func","args","gasLimit","txPromise","tx","data","contractDataPath","multiplier","feeData","input","result","file","namespaceBytes","fileBytes","sigHash","signature","cast","forge","getRpcUrl","getSrcDirectory","existsSync","mkdirSync","readFileSync","writeFileSync","ethers","getChainId","rpc","chainId","glob","basename","getExistingContracts","srcDir","path","deployHandler","args","configPath","printConfig","profile","clean","skipBuild","rpc","getRpcUrl","chalk","forge","srcDir","getSrcDirectory","existingContractNames","getExistingContracts","basename","mudConfig","loadConfig","privateKey","MUDError","deploymentInfo","deploy","chainId","getChainId","outputDir","path","mkdirSync","writeFileSync","localChains","deploys","existsSync","readFileSync","cast"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as o,b as r,c as e,d as f,
|
|
1
|
+
import{a as o,b as r,c as e,d as f,g as m}from"./chunk-QN5DEFJQ.js";export{m as deployHandler,r as getRecsV1TableOptions,e as renderRecsV1Tables,o as schemaTypesToRecsTypeStrings,f as tsgen};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/mud.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{d as
|
|
3
|
-
gracefully shutting down from SIGINT (Crtl-C)`),
|
|
4
|
-
uint256 _gasreport;`)}let i=new RegExp(/\/\/ !gasreport (.*)\n(.*)/g),
|
|
2
|
+
import{d as O,e as $,f as S,g as w}from"./chunk-QN5DEFJQ.js";import No from"yargs";import{hideBin as zo}from"yargs/helpers";import{rmSync as ue}from"fs";import{homedir as ye}from"os";import he from"path";import{execa as be}from"execa";var we={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=ye();ue(he.join(o,".foundry","anvil","tmp"),{recursive:!0,force:!0});let t=["-b",String(e),"--block-base-fee-per-gas","0"];console.log(`Running: anvil ${t.join(" ")}`);let r=be("anvil",t,{stdio:["inherit","inherit","inherit"]});process.on("SIGINT",()=>{console.log(`
|
|
3
|
+
gracefully shutting down from SIGINT (Crtl-C)`),r.kill(),process.exit()}),await r}},W=we;import{FaucetServiceDefinition as ve}from"@latticexyz/services/faucet";import{createChannel as Ce,createClient as De}from"nice-grpc-web";import I from"chalk";import{NodeHttpTransport as xe}from"@improbable-eng/grpc-web-node-http-transport";function ke(e){return De(ve,Ce(e,xe()))}var Me={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:t}){let r=ke(o);e&&(console.log(I.yellow("Dripping to",t)),await r.dripDev({address:t}),console.log(I.yellow("Success"))),process.exit(0)}},j=Me;import{readFileSync as A,writeFileSync as F,rmSync as G}from"fs";import{execa as Oe}from"execa";import p from"chalk";import{table as Se,getBorderCharacters as Re}from"table";var T="MudGasReport",Ue={command:"gas-report",describe:"Create a gas report",builder(e){return e.options({path:{type:"array",string:!0,default:["Gas.t.sol"],desc:"File containing the gas tests"},save:{type:"string",desc:"Save the gas report to a file"},compare:{type:"string",desc:"Compare to an existing gas report"}})},async handler({path:e,save:o,compare:t}){let r=e.filter(n=>n.endsWith(".t.sol")),s=await Promise.all(r.map(n=>Pe(n)));process.once("SIGINT",()=>{console.log("caught sigint, deleting temp files"),s.forEach(n=>G(n))});let i;try{i=await Ee()}catch{setTimeout(()=>process.exit());return}finally{s.forEach(n=>G(n))}if(t)try{let n=JSON.parse(A(t,"utf8"));i=i.map(l=>{let m=n.find(c=>c.name===l.name&&c.functionCall===l.functionCall);return{...l,prevGasUsed:m?.gasUsed}})}catch{console.log(p.red(`Gas report to compare not found: ${t}`)),t=void 0}$e(i,t),o&&We(i,o),process.exit(0)}},N=Ue;async function Pe(e){console.log("Creating gas report for",p.bold(e));let o=A(e,"utf8"),t=o,r=new RegExp(/function (.*){/g),s;for(;(s=r.exec(o))!==null;){let m=s[0];t=t.replace(m,`${m}
|
|
4
|
+
uint256 _gasreport;`)}let i=new RegExp(/\/\/ !gasreport (.*)\n(.*)/g),n;for(;(n=i.exec(o))!==null;){let m=n[1],c=n[2].trim();t=t.replace(n[0],`
|
|
5
5
|
_gasreport = gasleft();
|
|
6
6
|
${c}
|
|
7
7
|
_gasreport = _gasreport - gasleft();
|
|
8
|
-
console.log("GAS REPORT(${e}): ${m} [${c.replaceAll('"','\\"')}]:", _gasreport);`)}t=t.replace(/pure/g,"view");let l=e.replace(/\.t\.sol$/,`${
|
|
8
|
+
console.log("GAS REPORT(${e}): ${m} [${c.replaceAll('"','\\"')}]:", _gasreport);`)}t=t.replace(/pure/g,"view");let l=e.replace(/\.t\.sol$/,`${T}.t.sol`);return F(l,t),l}async function Ee(){console.log("Running gas report");let e=[],o="";try{o=(await Oe("forge",["test","--match-path",`*${T}*`,"-vvv"],{stdio:["inherit","pipe","inherit"]})).stdout}catch(s){throw console.log(s.stdout??s),console.log(p.red(`
|
|
9
9
|
-----------
|
|
10
|
-
Error while running the gas report (see above)`)),s}let t=new RegExp(/GAS REPORT\((.*)\): (.*) \[(.*)\]: (.*)/g),
|
|
11
|
-
`)}var
|
|
10
|
+
Error while running the gas report (see above)`)),s}let t=new RegExp(/GAS REPORT\((.*)\): (.*) \[(.*)\]: (.*)/g),r;for(;(r=t.exec(o))!==null;){let s=r[1],i=r[2],n=r[3].replace(";",""),l=parseInt(r[4]);e.push({source:s,name:i,functionCall:n,gasUsed:l})}return e.sort((s,i)=>s.source.localeCompare(i.source)),e}function $e(e,o){o&&console.log(p.bold(`Gas report compared to ${o}`));let t=[p.bold("Source"),p.bold("Name"),p.bold("Function call"),p.bold("Gas used"),...o?[p.bold("Prev gas used"),p.bold("Difference")]:[]],r=e.map(i=>{let n=i.prevGasUsed?i.gasUsed-i.prevGasUsed:0,l=n>0?p.red(`+${n}`):n<0?p.green(`${n}`):n,m=o?[i.prevGasUsed??"n/a",l]:[],c=n>0?p.red(i.gasUsed):n<0?p.green(i.gasUsed):i.gasUsed;return[i.source,i.name,i.functionCall,c,...m]}),s=[t,...r];console.log(Se(s,{border:Re("norc")}))}function We(e,o){console.log(p.bold(`Saving gas report to ${o}`)),F(o,`${JSON.stringify(e,null,2)}
|
|
11
|
+
`)}var Ie={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)}},z=Ie;import je from"path";import{loadConfig as Ge}from"@latticexyz/config/node";import{tablegen as Ae}from"@latticexyz/store/codegen";import{getSrcDirectory as Fe}from"@latticexyz/common/foundry";var Te={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 Ge(e),t=await Fe();await Ae(o,je.join(t,o.codegenDirectory)),process.exit(0)}},_=Te;import{loadConfig as Ne}from"@latticexyz/config/node";var ze={command:"tsgen",describe:"Autogenerate MUD typescript definitions based on the config file",builder(e){return e.options({configPath:{type:"string",demandOption:!0,desc:"Path to the config file"},out:{type:"string",demandOption:!0,desc:"Directory to output MUD typescript definition files"}})},async handler(e){let{configPath:o,out:t}=e,r=await Ne(o);await O(r,t),process.exit(0)}},B=ze;import D from"chalk";import{ZodError as _e}from"zod";import{fromZodError as Be,ValidationError as Je}from"zod-validation-error";import{NotInsideProjectError as Ve}from"@latticexyz/config";import{MUDError as He}from"@latticexyz/common/errors";function y(e){if(e instanceof Je)console.log(D.redBright(e.message));else if(e instanceof _e){let o=Be(e,{prefixSeparator:`
|
|
12
12
|
- `,issueSeparator:`
|
|
13
|
-
- `});console.log(D.redBright(o.message))}else e instanceof
|
|
13
|
+
- `});console.log(D.redBright(o.message))}else e instanceof Ve?(console.log(D.red(e.message)),console.log(""),console.log(D.blue("To learn more about MUD's configuration, please go to https://mud.dev/packages/cli/"))):e instanceof He?console.log(D.red(e)):console.log(e)}import Le from"chalk";function J(){console.log(Le.yellow(`
|
|
14
14
|
.------..------..------.
|
|
15
15
|
|M.--. ||U.--. ||D.--. |
|
|
16
16
|
| (\\/) || (\\/) || :/\\: |
|
|
17
17
|
| :\\/: || :\\/: || (__) |
|
|
18
18
|
| '--'M|| '--'U|| '--'D|
|
|
19
19
|
'------''------''------'
|
|
20
|
-
`))}var
|
|
21
|
-
Use --force to overwrite it or --restore to restore it.`);let c=
|
|
22
|
-
`),console.log(`Updating ${e}`),
|
|
23
|
-
`)),f
|
|
20
|
+
`))}import{getOutDirectory as qe}from"@latticexyz/common/foundry";import Ze from"path";import{runTypeChain as Ke}from"typechain";async function V(){let e=process.cwd(),o=await qe(),t=Ze.join(process.cwd(),o,"IWorld.sol/IWorld.json");await Ke({cwd:e,filesToProcess:[t],allFiles:[t],target:"ethers-v5"}),console.log("Typechain generated IWorld interface")}var P={configPath:{type:"string",desc:"Path to the config file"},clean:{type:"boolean",desc:"Remove the build forge artifacts and cache directories before building"},printConfig:{type:"boolean",desc:"Print the resolved config"},profile:{type:"string",desc:"The foundry profile to use"},debug:{type:"boolean",desc:"Print debug logs, like full error messages"},priorityFeeMultiplier:{type:"number",desc:"Multiply the estimated priority fee by the provided factor",default:1},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"},worldAddress:{type:"string",desc:"Deploy to an existing World at the given address"},srcDir:{type:"string",desc:"Source directory. Defaults to foundry src directory."},disableTxWait:{type:"boolean",desc:"Disable waiting for transactions to be confirmed.",default:!1},pollInterval:{type:"number",desc:"Interval in miliseconds to use to poll for transaction receipts / block inclusion",default:1e3},skipBuild:{type:"boolean",desc:"Skip rebuilding the contracts before deploying"}},Xe={command:"deploy",describe:"Deploy MUD contracts",builder(e){return e.options(P)},async handler(e){try{await w(e)}catch(o){y(o),process.exit(1)}process.exit(0)}},H=Xe;import{loadConfig as Ye}from"@latticexyz/config/node";import{worldgen as Qe}from"@latticexyz/world/node";import{getSrcDirectory as eo}from"@latticexyz/common/foundry";import L from"path";import{rmSync as oo}from"fs";var to={command:"worldgen",describe:"Autogenerate interfaces for Systems and World based on existing contracts and the config file",builder(e){return e.options({configPath:{type:"string",desc:"Path to the config file"},clean:{type:"boolean",desc:"Clear the worldgen directory before generating new interfaces"}})},async handler(e){await E(e),process.exit(0)}};async function E(e){let o=e.srcDir??await eo(),t=S(o),r=e.config??await Ye(e.configPath),s=L.join(o,r.codegenDirectory);e.clean&&oo(L.join(s,r.worldgenDirectory),{recursive:!0,force:!0}),await Qe(r,t,s)}var q=to;import C from"chalk";import{existsSync as no,readFileSync as so,rmSync as io,writeFileSync as K}from"fs";import v from"path";import{MUDError as k}from"@latticexyz/common/errors";var Z={name:"@latticexyz/cli",version:"1.42.0",description:"Command line interface for mud",repository:{type:"git",url:"https://github.com/latticexyz/mud.git",directory:"packages/cli"},license:"MIT",type:"module",exports:{".":"./dist/index.js"},types:"src/index.ts",bin:{mud:"./dist/mud.js"},scripts:{build:"pnpm run build:js","build:js":"tsup && chmod +x ./dist/mud.js",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch","generate-test-tables":"tsx ./scripts/generate-test-tables.ts",lint:"eslint . --ext .ts",test:"tsc --noEmit && pnpm run generate-test-tables && forge test"},dependencies:{"@ethersproject/abi":"^5.7.0","@ethersproject/providers":"^5.7.2","@improbable-eng/grpc-web":"^0.15.0","@improbable-eng/grpc-web-node-http-transport":"^0.15.0","@latticexyz/common":"workspace:*","@latticexyz/config":"workspace:*","@latticexyz/schema-type":"workspace:*","@latticexyz/services":"workspace:*","@latticexyz/solecs":"workspace:*","@latticexyz/std-contracts":"workspace:*","@latticexyz/store":"workspace:*","@latticexyz/utils":"workspace:*","@latticexyz/world":"workspace:*","@typechain/ethers-v5":"^10.2.0",chalk:"^5.0.1",chokidar:"^3.5.3",dotenv:"^16.0.3",ejs:"^3.1.8",ethers:"^5.7.2",execa:"^7.0.0",glob:"^8.0.3","nice-grpc-web":"^2.0.1",openurl:"^1.1.1",path:"^0.12.7",table:"^6.8.1","throttle-debounce":"^5.0.0",typechain:"^8.1.1",typescript:"^4.9.5",yargs:"^17.7.1",zod:"^3.21.4","zod-validation-error":"^1.3.0"},devDependencies:{"@types/ejs":"^3.1.1","@types/glob":"^7.2.0","@types/node":"^18.15.11","@types/openurl":"^1.0.0","@types/throttle-debounce":"^5.0.0","@types/yargs":"^17.0.10","ds-test":"https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084","forge-std":"https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3",tsup:"^6.7.0",tsx:"^3.12.6",vitest:"0.31.4"},gitHead:"914a1e0ae4a573d685841ca2ea921435057deb8f"};var R=".mudbackup",x="@latticexyz",ao={command:"set-version",describe:"Install a custom MUD version and optionally backup the previously installed version",builder(e){return e.options({backup:{type:"boolean",description:`Back up the current MUD versions to "${R}"`},force:{type:"boolean",description:`Backup fails if a "${R}" file is found, unless --force is provided`},restore:{type:"boolean",description:`Restore the previous MUD versions from "${R}"`},mudVersion:{alias:"v",type:"string",description:"The MUD version to install"},link:{alias:"l",type:"string",description:"Relative path to the local MUD root directory to link"}})},async handler(e){try{if(!e.mudVersion&&!e.link&&!e.restore)throw new k("`--mudVersion` or `--link` is required unless --restore is provided.");if(e.link&&e.mudVersion)throw new k("Options `--link` and `--mudVersion` are mutually exclusive");e.mudVersion=e.mudVersion==="canary"?await co(Z.name):e.mudVersion;let o="./package.json",{workspaces:t}=X(o,e);if(t)for(let r of t){let s=v.join(r,"/package.json");X(s,e)}}catch(o){y(o)}finally{process.exit(0)}}};function X(e,o){let{restore:t,force:r,link:s}=o,{backup:i,mudVersion:n}=o,l=v.join(v.dirname(e),R),m=no(l);if(s&&!m&&(i=!0),i&&!r&&m)throw new k(`A backup file already exists at ${l}.
|
|
21
|
+
Use --force to overwrite it or --restore to restore it.`);let c=Y(e),h=t?Y(l):void 0,g={};for(let a in c.dependencies)a.startsWith(x)&&(g[a]=c.dependencies[a]);let b={};for(let a in c.devDependencies)a.startsWith(x)&&(b[a]=c.devDependencies[a]);i&&(K(l,JSON.stringify({dependencies:g,devDependencies:b},null,2)),console.log(C.green(`Backed up MUD dependencies from ${e} to ${l}`)));for(let a in c.dependencies)a.startsWith(x)&&(c.dependencies[a]=d(a,"dependencies"));for(let a in c.devDependencies)a.startsWith(x)&&(c.devDependencies[a]=d(a,"devDependencies"));return K(e,JSON.stringify(c,null,2)+`
|
|
22
|
+
`),console.log(`Updating ${e}`),Q(g,c.dependencies),Q(b,c.devDependencies),t&&!i&&(io(l),console.log(C.green(`Cleaned up ${l}`))),c;function d(a,f){return t&&h?h[f][a]:(s&&(n=lo(e,s,a)),n||c[f][a])}}function Y(e){try{let o=so(e,"utf8");return JSON.parse(o)}catch{throw new k("Could not read JSON at "+e)}}async function co(e){try{console.log(C.blue("fetching MUD canary version..."));let t=(await(await fetch(`https://registry.npmjs.org/${e}`)).json())["dist-tags"].canary;return console.log(C.green("MUD canary version:",t)),t}catch{throw new k(`Could not fetch canary version of ${e}`)}}function Q(e,o){for(let t in e)e[t]!==o[t]&&console.log(`${t}: ${C.red(e[t])} -> ${C.green(o[t])}`)}function lo(e,o,t){let r=t.replace(x,""),s=v.relative(v.dirname(e),process.cwd());return"link:"+v.join(s,o,"packages",r)}var ee=ao;import{anvil as po,forge as mo,getRpcUrl as fo}from"@latticexyz/common/foundry";import go from"chalk";import{rmSync as uo,writeFileSync as yo}from"fs";var oe=".mudtest",ho={command:"test",describe:"Run tests in MUD contracts",builder(e){return e.options({...P,port:{type:"number",description:"Port to run internal node for fork testing on",default:4242},worldAddress:{type:"string",description:"Address of an existing world contract. If provided, deployment is skipped and the RPC provided in the foundry.toml is used for fork testing."},forgeOptions:{type:"string",description:"Options to pass to forge test"}})},async handler(e){if(!e.worldAddress){let s=["--block-base-fee-per-gas","0","--port",String(e.port)];po(s)}let o=e.worldAddress?await fo(e.profile):`http://127.0.0.1:${e.port}`,t=e.worldAddress??(await w({...e,saveDeployment:!1,rpc:o})).worldAddress;console.log(go.blue("World address",t)),yo(oe,t);let r=e.forgeOptions?.replaceAll("\\","").split(" ")??[];try{let s=await mo(["test","--fork-url",o,...r],{profile:e.profile});console.log(s)}catch(s){console.error(s)}uo(oe),process.exit(0)}},te=ho;import{existsSync as bo,readFileSync as wo}from"fs";import{ethers as re}from"ethers";import{loadConfig as vo}from"@latticexyz/config/node";import{MUDError as ne}from"@latticexyz/common/errors";import{cast as Co,getRpcUrl as Do,getSrcDirectory as xo}from"@latticexyz/common/foundry";import{TableId as se}from"@latticexyz/utils";import{resolveWorldConfig as ko}from"@latticexyz/world";import Mo from"@latticexyz/world/abi/IBaseWorld.sol/IBaseWorld.json"assert{type:"json"};var Oo=new se("","Systems"),So={command:"trace",describe:"Display the trace of a transaction",builder(e){return e.options({tx:{type:"string",required:!0,description:"Transaction hash to replay"},worldAddress:{type:"string",description:"World contract address. Defaults to the value from worlds.json, based on rpc's chainId"},configPath:{type:"string",description:"Path to the config file"},profile:{type:"string",description:"The foundry profile to use"},srcDir:{type:"string",description:"Source directory. Defaults to foundry src directory."},rpc:{type:"string",description:"json rpc endpoint. Defaults to foundry's configured eth_rpc_url"}})},async handler(e){e.profile??=process.env.FOUNDRY_PROFILE;let{profile:o}=e;e.srcDir??=await xo(o),e.rpc??=await Do(o);let{tx:t,configPath:r,srcDir:s,rpc:i}=e,n=S(s),l=await vo(r),m=ko(l,n.map(({basename:u})=>u)),c=e.worldAddress??await Ro(l.worldsFile,i),h=new re.providers.StaticJsonRpcProvider(i),g=new re.Contract(c,Mo.abi,h),b=l.namespace,d=Object.values(m.systems).map(({name:u})=>u),a=[];for(let u of d){let U=new se(b,u),ge=await g.getField(Oo.toHexString(),[U.toHexString()],0);a.push({name:u,address:ge})}let f=await Co(["run","--label",`${c}:World`,...a.map(({name:u,address:U})=>["--label",`${U}:${u}`]).flat(),`${t}`]);console.log(f),process.exit(0)}},ie=So;async function Ro(e,o){if(bo(e)){let t=await $(o),r=JSON.parse(wo(e,"utf-8"));if(!r[t])throw new ne(`chainId ${t} is missing in worldsFile "${e}"`);return r[t].address}else throw new ne("worldAddress is not specified and worldsFile is missing")}import{anvil as Uo,forge as ae,getRpcUrl as Po,getScriptDirectory as Eo,getSrcDirectory as $o}from"@latticexyz/common/foundry";import M from"chalk";import Wo from"chokidar";import{loadConfig as ce,resolveConfigPath as Io}from"@latticexyz/config/node";import{tablegen as jo}from"@latticexyz/store/codegen";import le from"path";import{debounce as Go}from"throttle-debounce";import{homedir as Ao}from"os";import{rmSync as Fo}from"fs";var To={command:"dev-contracts",describe:"Start a development server for MUD contracts",builder(e){return e.options({rpc:{type:"string",decs:"RPC endpoint of the development node. If none is provided, an anvil instance is spawned in the background on port 8545."},configPath:{type:"string",decs:"Path to MUD config"},tsgenOutput:{type:"string",demandOption:!0,desc:"Directory to output MUD typescript definition files"}})},async handler(e){e.tsgenOutputDir||console.error("No output provided"),await ae(["clean"]);let o=e.rpc??await Po(),t=e.configPath??await Io(e.configPath),r=await $o(),s=await Eo(),i=await ce(t);if(await h(i),await g(i),!e.rpc){console.log(M.gray("Cleaning devnode cache"));let d=Ao();Fo(le.join(d,".foundry","anvil","tmp"),{recursive:!0,force:!0}),Uo(["--block-time","1","--block-base-fee-per-gas","0"])}let n={config:!1,contracts:!1},l={current:!1};Wo.watch([t,r]).on("all",async(d,a)=>{if(a.includes(t)&&(n.config=!0,n.contracts=!0),a.includes(r)||a.includes(s)){if(a.includes(i.codegenDirectory))return;n.contracts=!0}c()});let c=Go(100,async()=>{if(l.current)return;l.current=!0;let{config:d,contracts:a}=n;n.config=!1,n.contracts=!1;try{let f=await ce(t);d&&await h(f),a&&await g(f),await b()}catch(f){console.error(M.red(`MUD dev-contracts watcher failed to deploy config or contracts changes
|
|
23
|
+
`)),y(f)}l.current=!1,(n.config||n.contracts)&&(console.log("Detected change while handling the previous change"),c()),J(),console.log("MUD watching for changes...")});async function h(d){console.log(M.blue("mud.config.ts changed - regenerating tables and recs types"));let a=le.join(r,d.codegenDirectory);await jo(d,a),await O(d,e.tsgenOutput)}async function g(d){console.log(M.blue("contracts changed - regenerating interfaces and contract types")),await E({config:d,clean:!0,srcDir:r}),await ae(["build"]),await V()}async function b(){console.log(M.blue("redeploying World")),await w({configPath:t,skipBuild:!0,priorityFeeMultiplier:1,disableTxWait:!0,pollInterval:1e3,saveDeployment:!0,srcDir:r,rpc:o})}}},de=To;var pe=[H,W,j,N,z,_,B,q,ee,te,ie,de];import*as fe from"dotenv";import me from"chalk";fe.config();No(zo(process.argv)).scriptName("mud").command(pe).strict().fail((e,o)=>{console.error(me.red(e)),e.includes("Missing required argument")&&console.log(me.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`)),console.log(""),y(o),console.log(""),process.exit(1)}).alias({h:"help"}).argv;
|
|
24
24
|
//# sourceMappingURL=mud.js.map
|