@latticexyz/cli 2.0.0-main-e3fab079 → 2.0.0-main-57d8965d
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/cli",
|
|
3
|
-
"version": "2.0.0-main-
|
|
3
|
+
"version": "2.0.0-main-57d8965d",
|
|
4
4
|
"description": "Command line interface for mud",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,17 +40,17 @@
|
|
|
40
40
|
"yargs": "^17.7.1",
|
|
41
41
|
"zod": "^3.21.4",
|
|
42
42
|
"zod-validation-error": "^1.3.0",
|
|
43
|
-
"@latticexyz/abi-ts": "2.0.0-main-
|
|
44
|
-
"@latticexyz/common": "2.0.0-main-
|
|
45
|
-
"@latticexyz/config": "2.0.0-main-
|
|
46
|
-
"@latticexyz/gas-report": "2.0.0-main-
|
|
47
|
-
"@latticexyz/protocol-parser": "2.0.0-main-
|
|
48
|
-
"@latticexyz/schema-type": "2.0.0-main-
|
|
49
|
-
"@latticexyz/services": "2.0.0-main-
|
|
50
|
-
"@latticexyz/store": "2.0.0-main-
|
|
51
|
-
"@latticexyz/utils": "2.0.0-main-
|
|
52
|
-
"@latticexyz/world": "2.0.0-main-
|
|
53
|
-
"@latticexyz/world-modules": "2.0.0-main-
|
|
43
|
+
"@latticexyz/abi-ts": "2.0.0-main-57d8965d",
|
|
44
|
+
"@latticexyz/common": "2.0.0-main-57d8965d",
|
|
45
|
+
"@latticexyz/config": "2.0.0-main-57d8965d",
|
|
46
|
+
"@latticexyz/gas-report": "2.0.0-main-57d8965d",
|
|
47
|
+
"@latticexyz/protocol-parser": "2.0.0-main-57d8965d",
|
|
48
|
+
"@latticexyz/schema-type": "2.0.0-main-57d8965d",
|
|
49
|
+
"@latticexyz/services": "2.0.0-main-57d8965d",
|
|
50
|
+
"@latticexyz/store": "2.0.0-main-57d8965d",
|
|
51
|
+
"@latticexyz/utils": "2.0.0-main-57d8965d",
|
|
52
|
+
"@latticexyz/world": "2.0.0-main-57d8965d",
|
|
53
|
+
"@latticexyz/world-modules": "2.0.0-main-57d8965d"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/debug": "^4.1.7",
|
|
@@ -1,15 +1,68 @@
|
|
|
1
|
+
import accessManagementSystemBuild from "@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json" assert { type: "json" };
|
|
2
|
+
import balanceTransferSystemBuild from "@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json" assert { type: "json" };
|
|
3
|
+
import batchCallSystemBuild from "@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json" assert { type: "json" };
|
|
4
|
+
import coreRegistrationSystemBuild from "@latticexyz/world/out/CoreRegistrationSystem.sol/CoreRegistrationSystem.json" assert { type: "json" };
|
|
1
5
|
import coreModuleBuild from "@latticexyz/world/out/CoreModule.sol/CoreModule.json" assert { type: "json" };
|
|
6
|
+
import coreModuleAbi from "@latticexyz/world/out/CoreModule.sol/CoreModule.abi.json" assert { type: "json" };
|
|
2
7
|
import worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" };
|
|
3
|
-
import
|
|
8
|
+
import worldFactoryAbi from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json" assert { type: "json" };
|
|
9
|
+
import { Client, Transport, Chain, Account, Hex, getCreate2Address, encodeDeployData, size } from "viem";
|
|
4
10
|
import { deployer } from "./ensureDeployer";
|
|
5
11
|
import { salt } from "./common";
|
|
6
12
|
import { ensureContractsDeployed } from "./ensureContractsDeployed";
|
|
7
13
|
import { Contract } from "./ensureContract";
|
|
8
14
|
|
|
15
|
+
export const accessManagementSystemDeployedBytecodeSize = size(
|
|
16
|
+
accessManagementSystemBuild.deployedBytecode.object as Hex
|
|
17
|
+
);
|
|
18
|
+
export const accessManagementSystemBytecode = encodeDeployData({
|
|
19
|
+
bytecode: accessManagementSystemBuild.bytecode.object as Hex,
|
|
20
|
+
abi: [],
|
|
21
|
+
});
|
|
22
|
+
export const accessManagementSystem = getCreate2Address({
|
|
23
|
+
from: deployer,
|
|
24
|
+
bytecode: accessManagementSystemBytecode,
|
|
25
|
+
salt,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const balanceTransferSystemDeployedBytecodeSize = size(
|
|
29
|
+
balanceTransferSystemBuild.deployedBytecode.object as Hex
|
|
30
|
+
);
|
|
31
|
+
export const balanceTransferSystemBytecode = encodeDeployData({
|
|
32
|
+
bytecode: balanceTransferSystemBuild.bytecode.object as Hex,
|
|
33
|
+
abi: [],
|
|
34
|
+
});
|
|
35
|
+
export const balanceTransferSystem = getCreate2Address({
|
|
36
|
+
from: deployer,
|
|
37
|
+
bytecode: balanceTransferSystemBytecode,
|
|
38
|
+
salt,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const batchCallSystemDeployedBytecodeSize = size(batchCallSystemBuild.deployedBytecode.object as Hex);
|
|
42
|
+
export const batchCallSystemBytecode = encodeDeployData({
|
|
43
|
+
bytecode: batchCallSystemBuild.bytecode.object as Hex,
|
|
44
|
+
abi: [],
|
|
45
|
+
});
|
|
46
|
+
export const batchCallSystem = getCreate2Address({ from: deployer, bytecode: batchCallSystemBytecode, salt });
|
|
47
|
+
|
|
48
|
+
export const coreRegistrationSystemDeployedBytecodeSize = size(
|
|
49
|
+
coreRegistrationSystemBuild.deployedBytecode.object as Hex
|
|
50
|
+
);
|
|
51
|
+
export const coreRegistrationSystemBytecode = encodeDeployData({
|
|
52
|
+
bytecode: coreRegistrationSystemBuild.bytecode.object as Hex,
|
|
53
|
+
abi: [],
|
|
54
|
+
});
|
|
55
|
+
export const coreRegistrationSystem = getCreate2Address({
|
|
56
|
+
from: deployer,
|
|
57
|
+
bytecode: coreRegistrationSystemBytecode,
|
|
58
|
+
salt,
|
|
59
|
+
});
|
|
60
|
+
|
|
9
61
|
export const coreModuleDeployedBytecodeSize = size(coreModuleBuild.deployedBytecode.object as Hex);
|
|
10
62
|
export const coreModuleBytecode = encodeDeployData({
|
|
11
63
|
bytecode: coreModuleBuild.bytecode.object as Hex,
|
|
12
|
-
abi:
|
|
64
|
+
abi: coreModuleAbi,
|
|
65
|
+
args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, coreRegistrationSystem],
|
|
13
66
|
});
|
|
14
67
|
|
|
15
68
|
export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModuleBytecode, salt });
|
|
@@ -17,13 +70,33 @@ export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModu
|
|
|
17
70
|
export const worldFactoryDeployedBytecodeSize = size(worldFactoryBuild.deployedBytecode.object as Hex);
|
|
18
71
|
export const worldFactoryBytecode = encodeDeployData({
|
|
19
72
|
bytecode: worldFactoryBuild.bytecode.object as Hex,
|
|
20
|
-
abi:
|
|
73
|
+
abi: worldFactoryAbi,
|
|
21
74
|
args: [coreModule],
|
|
22
75
|
});
|
|
23
76
|
|
|
24
77
|
export const worldFactory = getCreate2Address({ from: deployer, bytecode: worldFactoryBytecode, salt });
|
|
25
78
|
|
|
26
79
|
export const worldFactoryContracts: readonly Contract[] = [
|
|
80
|
+
{
|
|
81
|
+
bytecode: accessManagementSystemBytecode,
|
|
82
|
+
deployedBytecodeSize: accessManagementSystemDeployedBytecodeSize,
|
|
83
|
+
label: "access management system",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
bytecode: balanceTransferSystemBytecode,
|
|
87
|
+
deployedBytecodeSize: balanceTransferSystemDeployedBytecodeSize,
|
|
88
|
+
label: "balance transfer system",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
bytecode: batchCallSystemBytecode,
|
|
92
|
+
deployedBytecodeSize: batchCallSystemDeployedBytecodeSize,
|
|
93
|
+
label: "batch call system",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
bytecode: coreRegistrationSystemBytecode,
|
|
97
|
+
deployedBytecodeSize: coreRegistrationSystemDeployedBytecodeSize,
|
|
98
|
+
label: "core registration system",
|
|
99
|
+
},
|
|
27
100
|
{
|
|
28
101
|
bytecode: coreModuleBytecode,
|
|
29
102
|
deployedBytecodeSize: coreModuleDeployedBytecodeSize,
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import{a as z}from"./chunk-22IIKR4S.js";import os from"@latticexyz/gas-report";import ts from"@latticexyz/abi-ts";import{loadConfig as No}from"@latticexyz/config/node";import{getSrcDirectory as zo}from"@latticexyz/common/foundry";import{existsSync as Po,readFileSync as jo,writeFileSync as Fo}from"node:fs";import Y from"node:path";import{tablegen as Wo}from"@latticexyz/store/codegen";import{worldgen as Bo}from"@latticexyz/world/node";import{forge as Mo,getForgeConfig as Ro,getRemappings as $o}from"@latticexyz/common/foundry";import ko from"glob";import{basename as Io}from"path";function I(e){return ko.sync(`${e}/**/*.sol`).map(o=>({path:o,basename:Io(o,".sol")}))}import me from"debug";var W=me("mud:cli"),Oo=me("mud:cli");W.log=console.debug.bind(console);Oo.log=console.error.bind(console);import{execa as Eo}from"execa";var Ho=W.extend("runDeploy");async function U({config:e,srcDir:o,foundryProfile:r=process.env.FOUNDRY_PROFILE}){let t=Y.join(o,e.codegenDirectory),n=await $o(r);await Promise.all([Wo(e,t,n),Bo(e,I(o),t)]);let s=await Ro(r);if(s.cache){let c=Y.join(s.cache_path,"solidity-files-cache.json");if(Po(c)){Ho("Unsetting cached content hash of IWorld.sol to force it to regenerate");let i=JSON.parse(jo(c,"utf8")),p=Y.join(t,"world","IWorld.sol");i.files[p].contentHash="",Fo(c,JSON.stringify(i,null,2))}}await Mo(["build"],{profile:r}),await Eo("mud",["abi-ts"],{stdio:"inherit"})}var Uo={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 No(e),t=await zo();await U({config:r,srcDir:t,foundryProfile:o}),process.exit(0)}},pe=Uo;import{rmSync as Vo}from"fs";import{homedir as _o}from"os";import Lo from"path";import{execa as Ko}from"execa";var Jo={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=_o();Vo(Lo.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=Ko("anvil",r,{stdio:["inherit","inherit","inherit"]});process.on("SIGINT",()=>{console.log(`
|
|
2
|
-
gracefully shutting down from SIGINT (Crtl-C)`),t.kill(),process.exit()}),await t}},fe=Jo;import{FaucetServiceDefinition as qo}from"@latticexyz/services/faucet";import{createChannel as Go,createClient as Yo}from"nice-grpc-web";import ue from"chalk";import{NodeHttpTransport as Zo}from"@improbable-eng/grpc-web-node-http-transport";function Qo(e){return Yo(qo,Go(e,Zo()))}var Xo={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=Qo(o);e&&(console.log(ue.yellow("Dripping to",r)),await t.dripDev({address:r}),console.log(ue.yellow("Success"))),process.exit(0)}},ye=Xo;var et={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)}},ge=et;import ot from"path";import{loadConfig as tt}from"@latticexyz/config/node";import{tablegen as rt}from"@latticexyz/store/codegen";import{getRemappings as nt,getSrcDirectory as st}from"@latticexyz/common/foundry";var it={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 tt(e),r=await st(),t=await nt();await rt(o,ot.join(r,o.codegenDirectory),t),process.exit(0)}},be=it;import ie from"node:path";import{existsSync as Ur,mkdirSync as Vr,readFileSync as _r,writeFileSync as ae}from"node:fs";import{getAddress as oo}from"viem";import{getBytecode as dt,sendRawTransaction as lt,sendTransaction as mt,waitForTransactionReceipt as he}from"viem/actions";var F={gasPrice:1e11,gasLimit:1e5,signerAddress:"3fab184622dc19b6109349b94811493bf2a45362",transaction:"f8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222",address:"4e59b44847b379578588920ca78fbf26c0b4956c"};var d=W.extend("deploy"),ct=W.extend("deploy");d.log=console.debug.bind(console);ct.log=console.error.bind(console);var v=`0x${F.address}`;async function we(e){if(await dt(e,{address:v})){d("found create2 deployer at",v);return}d("sending gas for create2 deployer to signer at",F.signerAddress);let r=await mt(e,{chain:e.chain??null,to:`0x${F.signerAddress}`,value:BigInt(F.gasLimit)*BigInt(F.gasPrice)}),t=await he(e,{hash:r});if(t.status!=="success")throw console.error("failed to send gas to deployer signer",t),new Error("failed to send gas to deployer signer");d("deploying create2 deployer at",v);let n=await lt(e,{serializedTransaction:`0x${F.transaction}`}),s=await he(e,{hash:n});if(s.contractAddress!==v)throw console.error("unexpected contract address for deployer",s),new Error("unexpected contract address for deployer")}import{waitForTransactionReceipt as Mt}from"viem/actions";import De from"@latticexyz/world/out/CoreModule.sol/CoreModule.json"assert{type:"json"};import Te from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.json"assert{type:"json"};import{parseAbi as kt,getCreate2Address as Ae,encodeDeployData as ke,size as Ie}from"viem";import{padHex as ft}from"viem";import ut from"@latticexyz/store/mud.config";import yt from"@latticexyz/world/mud.config";import gt from"@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json"assert{type:"json"};import bt from"@latticexyz/world-modules/out/IModule.sol/IModule.abi.json"assert{type:"json"};import{resourceToHex as pt}from"@latticexyz/common";import{resolveUserTypes as xe}from"@latticexyz/store";function E(e){let o={...e.userTypes,...Object.fromEntries(Object.entries(e.enums).map(([r])=>[r,{internalType:"uint8"}]))};return Object.fromEntries(Object.entries(e.tables).map(([r,t])=>[`${e.namespace}_${r}`,{namespace:e.namespace,name:t.name,tableId:pt({type:t.offchainOnly?"offchainTable":"table",namespace:e.namespace,name:t.name}),keySchema:xe(t.keySchema,o),valueSchema:xe(t.valueSchema,o)}]))}import{helloStoreEvent as ht}from"@latticexyz/store";import{helloWorldEvent as wt}from"@latticexyz/world";var T=ft("0x",{size:32}),H=parseInt("6000",16),B=E(ut),D=E(yt),V=[ht,wt],C=[...gt,...bt],Se=["1.0.0-unaudited"],Ce=["1.0.0-unaudited"];import{waitForTransactionReceipt as At}from"viem/actions";import{concatHex as xt,getCreate2Address as St}from"viem";import{getBytecode as Ct}from"viem/actions";import{sendTransaction as vt}from"@latticexyz/common";import Dt from"p-retry";import{wait as Tt}from"@latticexyz/common/utils";async function ve({client:e,bytecode:o,deployedBytecodeSize:r,label:t="contract"}){let n=St({from:v,salt:T,bytecode:o});return await Ct(e,{address:n,blockTag:"pending"})?(d("found",t,"at",n),[]):(r>H?console.warn(`
|
|
3
|
-
Bytecode for ${t} (${r} bytes) is over the contract size limit (${H} bytes). Run \`forge build --sizes\` for more info.
|
|
4
|
-
`):r>H*.95&&console.warn(`
|
|
5
|
-
Bytecode for ${t} (${r} bytes) is almost over the contract size limit (${H} bytes). Run \`forge build --sizes\` for more info.
|
|
6
|
-
`),d("deploying",t,"at",n),[await Dt(()=>vt(e,{chain:e.chain??null,to:v,data:xt([T,o])}),{retries:3,onFailedAttempt:async c=>{let i=c.attemptNumber*500;d(`failed to deploy ${t}, retrying in ${i}ms...`),await Tt(i)}})])}async function O({client:e,contracts:o}){let r=(await Promise.all(o.map(t=>ve({client:e,...t})))).flat();if(r.length){d("waiting for contracts");for(let t of r)await At(e,{hash:t})}return r}var It=Ie(De.deployedBytecode.object),Oe=ke({bytecode:De.bytecode.object,abi:[]}),Ot=Ae({from:v,bytecode:Oe,salt:T}),Pt=Ie(Te.deployedBytecode.object),Pe=ke({bytecode:Te.bytecode.object,abi:kt(["constructor(address)"]),args:[Ot]}),je=Ae({from:v,bytecode:Pe,salt:T}),Z=[{bytecode:Oe,deployedBytecodeSize:It,label:"core module"},{bytecode:Pe,deployedBytecodeSize:Pt,label:"world factory"}];async function Fe(e){return await O({client:e,contracts:Z})}import Rt from"@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json"assert{type:"json"};import{writeContract as $t}from"@latticexyz/common";import{AbiEventSignatureNotFoundError as jt,decodeEventLog as Ft,hexToString as We,parseAbi as Wt,trim as Be}from"viem";import{isDefined as Bt}from"@latticexyz/common/utils";function _(e){let o=e.map(c=>{try{return{...c,...Ft({strict:!0,abi:Wt(V),topics:c.topics,data:c.data})}}catch(i){if(i instanceof jt)return;throw i}}).filter(Bt),{address:r,deployBlock:t,worldVersion:n,storeVersion:s}=o.reduce((c,i)=>({...c,address:i.address,deployBlock:i.blockNumber,...i.eventName==="HelloWorld"?{worldVersion:We(Be(i.args.worldVersion,{dir:"right"}))}:null,...i.eventName==="HelloStore"?{storeVersion:We(Be(i.args.storeVersion,{dir:"right"}))}: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 Me(e){await Fe(e),d("deploying world");let o=await $t(e,{chain:e.chain??null,address:je,abi:Rt,functionName:"deployWorld"});d("waiting for world deploy");let r=await Mt(e,{hash:o});if(r.status!=="success")throw console.error("world deploy failed",r),new Error("world deploy failed");let t=_(r.logs.map(n=>n));return d("deployed world to",t.address,"at block",t.deployBlock),{...t,stateBlock:t.deployBlock}}import{writeContract as _t}from"@latticexyz/common";import{valueSchemaToFieldLayoutHex as Lt,keySchemaToHex as Kt,valueSchemaToHex as Jt}from"@latticexyz/protocol-parser";function S({namespace:e,name:o}){return`${e}:${o}`}import{parseAbiItem as Et,decodeAbiParameters as Re,parseAbiParameters as $e}from"viem";import{hexToResource as Ht}from"@latticexyz/common";import{storeSetRecordEvent as Nt}from"@latticexyz/store";import{getLogs as zt}from"viem/actions";import{decodeKey as Ut,decodeValueArgs as Vt,hexToSchema as Ee}from"@latticexyz/protocol-parser";async function He({client:e,worldDeploy:o}){d("looking up tables for",o.address);let t=(await zt(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:Et(Nt),args:{tableId:B.store_Tables.tableId}})).map(n=>{let{tableId:s}=Ut(B.store_Tables.keySchema,n.args.keyTuple),{namespace:c,name:i}=Ht(s),p=Vt(B.store_Tables.valueSchema,n.args),l=Ee(p.keySchema),f=Ee(p.valueSchema),u=Re($e("string[]"),p.abiEncodedKeyNames)[0],m=Re($e("string[]"),p.abiEncodedFieldNames)[0],y=[...f.staticFields,...f.dynamicFields],w=Object.fromEntries(l.staticFields.map((x,a)=>[u[a],x])),b=Object.fromEntries(y.map((x,a)=>[m[a],x]));return{namespace:c,name:i,tableId:s,keySchema:w,valueSchema:b}});return d("found",t.length,"tables for",o.address),t}import qt from"p-retry";import{wait as Gt}from"@latticexyz/common/utils";async function Ne({client:e,worldDeploy:o,tables:r}){let n=(await He({client:e,worldDeploy:o})).map(i=>i.tableId),s=r.filter(i=>n.includes(i.tableId));s.length&&d("existing tables",s.map(S).join(", "));let c=r.filter(i=>!n.includes(i.tableId));return c.length?(d("registering tables",c.map(S).join(", ")),await Promise.all(c.map(i=>qt(()=>_t(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerTable",args:[i.tableId,Lt(i.valueSchema),Kt(i.keySchema),Jt(i.valueSchema),Object.keys(i.keySchema),Object.keys(i.valueSchema)]}),{retries:3,onFailedAttempt:async p=>{let l=p.attemptNumber*500;d(`failed to register table ${S(i)}, retrying in ${l}ms...`),await Gt(l)}})))):[]}import{getAddress as A}from"viem";import{writeContract as Q}from"@latticexyz/common";import{parseAbiItem as Yt}from"viem";import{getLogs as Zt}from"viem/actions";import{storeSpliceStaticDataEvent as Qt}from"@latticexyz/store";async function L({client:e,worldDeploy:o}){d("looking up resource IDs for",o.address);let t=(await Zt(e,{strict:!0,address:o.address,fromBlock:o.deployBlock,toBlock:o.stateBlock,event:Yt(Qt),args:{tableId:B.store_ResourceIds.tableId}})).map(n=>n.args.keyTuple[0]);return d("found",t.length,"resource IDs for",o.address),t}import{hexToResource as fr}from"@latticexyz/common";import{decodeValueArgs as Xt,encodeKey as er}from"@latticexyz/protocol-parser";import{readContract as or}from"viem/actions";async function P({client:e,worldDeploy:o,table:r,key:t}){let[n,s,c]=await or(e,{blockNumber:o.stateBlock,address:o.address,abi:C,functionName:"getRecord",args:[r.tableId,er(r.keySchema,t)]});return Xt(r.valueSchema,{staticData:n,encodedLengths:s,dynamicData:c})}import{getFunctionSelector as tr,parseAbiItem as rr}from"viem";import{storeSetRecordEvent as nr}from"@latticexyz/store";import{getLogs as sr}from"viem/actions";import{decodeValueArgs as ir}from"@latticexyz/protocol-parser";import{hexToResource as ar}from"@latticexyz/common";async function K({client:e,worldDeploy:o}){d("looking up function signatures for",o.address);let t=(await sr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:rr(nr),args:{tableId:D.world_FunctionSignatures.tableId}})).map(s=>ir(D.world_FunctionSignatures.valueSchema,s.args).functionSignature);return d("found",t.length,"function signatures for",o.address),await Promise.all(t.map(async s=>{let c=tr(s),{systemId:i,systemFunctionSelector:p}=await P({client:e,worldDeploy:o,table:D.world_FunctionSelectors,key:{functionSelector:c}}),{namespace:l,name:f}=ar(i),u=l===""?s:s.replace(`${l}_${f}_`,"");return{signature:s,selector:c,systemId:i,systemFunctionSignature:u,systemFunctionSelector:p}}))}import{parseAbiItem as cr,getAddress as dr}from"viem";import{storeSpliceStaticDataEvent as lr}from"@latticexyz/store";import{getLogs as mr}from"viem/actions";import{decodeKey as pr}from"@latticexyz/protocol-parser";async function J({client:e,worldDeploy:o}){d("looking up resource access for",o.address);let t=(await mr(e,{strict:!0,fromBlock:o.deployBlock,toBlock:o.stateBlock,address:o.address,event:cr(lr),args:{tableId:D.world_ResourceAccess.tableId}})).map(s=>pr(D.world_ResourceAccess.keySchema,s.args.keyTuple)),n=(await Promise.all(t.map(async s=>[s,await P({client:e,worldDeploy:o,table:D.world_ResourceAccess,key:s})]))).filter(([,s])=>s.access).map(([s])=>({resourceId:s.resourceId,address:dr(s.caller)}));return d("found",n.length,"resource<>address access pairs"),n}async function ze({client:e,worldDeploy:o}){let[r,t,n]=await Promise.all([L({client:e,worldDeploy:o}),K({client:e,worldDeploy:o}),J({client:e,worldDeploy:o})]),s=r.map(fr).filter(c=>c.type==="system");return d("looking up systems",s.map(S).join(", ")),await Promise.all(s.map(async c=>{let{system:i,publicAccess:p}=await P({client:e,worldDeploy:o,table:D.world_Systems,key:{systemId:c.resourceId}}),l=t.filter(f=>f.systemId===c.resourceId);return{address:i,namespace:c.namespace,name:c.name,systemId:c.resourceId,allowAll:p,allowedAddresses:n.filter(({resourceId:f})=>f===c.resourceId).map(({address:f})=>f),functions:l}}))}import{uniqueBy as ur,wait as X}from"@latticexyz/common/utils";import ee from"p-retry";async function Ue({client:e,worldDeploy:o,systems:r}){let[t,n]=await Promise.all([ze({client:e,worldDeploy:o}),J({client:e,worldDeploy:o})]),s=r.map(a=>a.systemId),c=n.filter(({resourceId:a})=>s.includes(a)),i=r.flatMap(a=>a.allowedAddresses.map(g=>({resourceId:a.systemId,address:g}))),p=i.filter(a=>!c.some(({resourceId:g,address:h})=>g===a.resourceId&&A(h)===A(a.address))),l=c.filter(a=>!i.some(({resourceId:g,address:h})=>g===a.resourceId&&A(h)===A(a.address)));l.length&&d("revoking",l.length,"access grants"),p.length&&d("adding",p.length,"access grants");let f=[...l.map(a=>ee(()=>Q(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"revokeAccess",args:[a.resourceId,a.address]}),{retries:3,onFailedAttempt:async g=>{let h=g.attemptNumber*500;d(`failed to revoke access, retrying in ${h}ms...`),await X(h)}})),...p.map(a=>ee(()=>Q(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"grantAccess",args:[a.resourceId,a.address]}),{retries:3,onFailedAttempt:async g=>{let h=g.attemptNumber*500;d(`failed to grant access, retrying in ${h}ms...`),await X(h)}}))],u=r.filter(a=>t.some(g=>g.systemId===a.systemId&&A(g.address)===A(a.address)));u.length&&d("existing systems",u.map(S).join(", "));let m=u.map(a=>a.systemId),y=r.filter(a=>!m.includes(a.systemId));if(!y.length)return[];let w=y.filter(a=>t.some(g=>g.systemId===a.systemId&&A(g.address)!==A(a.address)));w.length&&d("upgrading systems",w.map(S).join(", "));let b=y.filter(a=>!t.some(g=>g.systemId===a.systemId));b.length&&d("registering new systems",b.map(S).join(", ")),await O({client:e,contracts:ur(y,a=>A(a.address)).map(a=>({bytecode:a.bytecode,deployedBytecodeSize:a.deployedBytecodeSize,label:`${S(a)} system`}))});let x=y.map(a=>ee(()=>Q(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerSystem",args:[a.systemId,a.address,a.allowAll]}),{retries:3,onFailedAttempt:async g=>{let h=g.attemptNumber*500;d(`failed to register system ${S(a)}, retrying in ${h}ms...`),await X(h)}}));return await Promise.all([...f,...x])}import{waitForTransactionReceipt as to}from"viem/actions";import{getAddress as yr,parseAbi as gr}from"viem";import{getBlockNumber as br,getLogs as hr}from"viem/actions";var Ve=new Map;async function _e(e,o){let r=yr(o),t=Ve.get(r);if(t!=null)return t;d("looking up world deploy for",r);let n=await br(e),s=await hr(e,{strict:!0,address:r,events:gr(V),fromBlock:"earliest",toBlock:n});return t={..._(s),stateBlock:n},Ve.set(r,t),d("found world deploy for",r,"at block",t.deployBlock),t}import{hexToResource as wr,writeContract as Le}from"@latticexyz/common";import Ke from"p-retry";import{wait as Je}from"@latticexyz/common/utils";async function qe({client:e,worldDeploy:o,functions:r}){let t=await K({client:e,worldDeploy:o}),n=Object.fromEntries(t.map(i=>[i.selector,i])),s=r.filter(i=>n[i.selector]),c=r.filter(i=>!s.includes(i));if(s.length){d("functions already registered:",s.map(p=>p.signature).join(", "));let i=s.filter(p=>p.systemId!==n[p.selector]?.systemId);i.length&&console.warn("found",i.length,"functions already registered but pointing at a different system ID:",i.map(p=>p.signature).join(", "))}return c.length?(d("registering functions:",c.map(i=>i.signature).join(", ")),Promise.all(c.map(i=>{let{namespace:p}=wr(i.systemId);return p===""?Ke(()=>Le(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerRootFunctionSelector",args:[i.systemId,i.systemFunctionSignature,i.systemFunctionSelector]}),{retries:3,onFailedAttempt:async l=>{let f=l.attemptNumber*500;d(`failed to register function ${i.signature}, retrying in ${f}ms...`),await Je(f)}}):Ke(()=>Le(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerFunctionSelector",args:[i.systemId,i.systemFunctionSignature]}),{retries:3,onFailedAttempt:async l=>{let f=l.attemptNumber*500;d(`failed to register function ${i.signature}, retrying in ${f}ms...`),await Je(f)}})}))):[]}import{BaseError as xr,getAddress as Sr}from"viem";import{writeContract as Ge}from"@latticexyz/common";import{isDefined as Cr,uniqueBy as vr,wait as Dr}from"@latticexyz/common/utils";import Tr from"p-retry";async function Ye({client:e,worldDeploy:o,modules:r}){return r.length?(await O({client:e,contracts:vr(r,t=>Sr(t.address)).map(t=>({bytecode:t.bytecode,deployedBytecodeSize:t.deployedBytecodeSize,label:`${t.name} module`}))}),d("installing modules:",r.map(t=>t.name).join(", ")),(await Promise.all(r.map(t=>Tr(async()=>{try{return t.installAsRoot?await Ge(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"installRootModule",args:[t.address,t.installData]}):await Ge(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"installModule",args:[t.address,t.installData]})}catch(n){if(n instanceof xr&&n.message.includes("Module_AlreadyInstalled")){d(`module ${t.name} already installed`);return}throw n}},{retries:3,onFailedAttempt:async n=>{let s=n.attemptNumber*500;d(`failed to install module ${t.name}, retrying in ${s}ms...`),await Dr(s)}})))).filter(Cr)):[]}import{getAddress as Ze}from"viem";import{hexToResource as Qe,resourceToHex as Xe,writeContract as Ar}from"@latticexyz/common";async function eo({client:e,worldDeploy:o,resourceIds:r}){let t=Array.from(new Set(r.map(u=>Qe(u).namespace))),n=await L({client:e,worldDeploy:o}),s=new Set(n.map(u=>Qe(u).namespace));s.size&&d("found",s.size,"existing namespaces:",Array.from(s).map(u=>u===""?"<root>":u).join(", "));let c=t.filter(u=>s.has(u)),p=(await Promise.all(c.map(async u=>{let{owner:m}=await P({client:e,worldDeploy:o,table:D.world_NamespaceOwner,key:{namespaceId:Xe({type:"namespace",namespace:u,name:""})}});return[u,m]}))).filter(([,u])=>Ze(u)!==Ze(e.account.address)).map(([u])=>u);if(p.length)throw new Error(`You are attempting to deploy to namespaces you do not own: ${p.join(", ")}`);let l=t.filter(u=>!s.has(u));return l.length>0&&d("registering namespaces",Array.from(l).join(", ")),Promise.all(l.map(u=>Ar(e,{chain:e.chain??null,address:o.address,abi:C,functionName:"registerNamespace",args:[Xe({namespace:u,type:"namespace",name:""})]})))}import{uniqueBy as ro}from"@latticexyz/common/utils";async function no({client:e,config:o,worldAddress:r}){let t=Object.values(o.tables),n=Object.values(o.systems);await we(e),await O({client:e,contracts:[...Z,...ro(n,m=>oo(m.address)).map(m=>({bytecode:m.bytecode,deployedBytecodeSize:m.deployedBytecodeSize,label:`${S(m)} system`})),...ro(o.modules,m=>oo(m.address)).map(m=>({bytecode:m.bytecode,deployedBytecodeSize:m.deployedBytecodeSize,label:`${m.name} module`}))]});let s=r?await _e(e,r):await Me(e);if(!Se.includes(s.storeVersion))throw new Error(`Unsupported Store version: ${s.storeVersion}`);if(!Ce.includes(s.worldVersion))throw new Error(`Unsupported World version: ${s.worldVersion}`);let c=await eo({client:e,worldDeploy:s,resourceIds:[...t.map(m=>m.tableId),...n.map(m=>m.systemId)]});d("waiting for all namespace registration transactions to confirm");for(let m of c)await to(e,{hash:m});let i=await Ne({client:e,worldDeploy:s,tables:t}),p=await Ue({client:e,worldDeploy:s,systems:n}),l=await qe({client:e,worldDeploy:s,functions:n.flatMap(m=>m.functions)}),f=await Ye({client:e,worldDeploy:s,modules:o.modules}),u=[...i,...p,...l,...f];d("waiting for all transactions to confirm");for(let m of u)await to(e,{hash:m});return d("deploy complete"),s}import{createWalletClient as Lr,http as Kr}from"viem";import{privateKeyToAccount as Jr}from"viem/accounts";import{loadConfig as qr}from"@latticexyz/config/node";import{getOutDirectory as Gr,getRpcUrl as Yr,getSrcDirectory as Zr}from"@latticexyz/common/foundry";import M from"chalk";import{MUDError as Qr}from"@latticexyz/common/errors";import{resolveWorldConfig as Pr}from"@latticexyz/world";import{resourceToHex as se,hexToResource as jr}from"@latticexyz/common";import{resolveWithContext as Fr}from"@latticexyz/config";import{encodeField as Wr}from"@latticexyz/protocol-parser";import{getFunctionSelector as io,getCreate2Address as ao,getAddress as Br,hexToBytes as Mr,bytesToHex as Rr,getFunctionSignature as co}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 ne}from"viem";var so=[{name:"KeysWithValueModule",abi:oe.abi,bytecode:oe.bytecode.object,deployedBytecodeSize:ne(oe.deployedBytecode.object)},{name:"KeysInTableModule",abi:te.abi,bytecode:te.bytecode.object,deployedBytecodeSize:ne(te.deployedBytecode.object)},{name:"UniqueEntityModule",abi:re.abi,bytecode:re.bytecode.object,deployedBytecodeSize:ne(re.deployedBytecode.object)}];import{readFileSync as kr}from"fs";import Ir from"path";import{MUDError as q}from"@latticexyz/common/errors";import{size as Or}from"viem";function G(e,o){let r,t=Ir.join(o,e+".sol",e+".json");try{r=JSON.parse(kr(t,"utf8"))}catch{throw new q(`Error reading file at ${t}`)}let n=r?.bytecode?.object;if(!n)throw new q(`No bytecode found in ${t}`);let s=r?.deployedBytecode?.object;if(!s)throw new q(`No deployed bytecode found in ${t}`);let c=r?.abi;if(!c)throw new q(`No ABI found in ${t}`);return{abi:c,bytecode:n,deployedBytecodeSize:Or(s)}}function lo({config:e,forgeSourceDir:o,forgeOutDir:r}){let t=E(e),n=I(o).map(({basename:m})=>m),s=Pr(e,n),i=G("System",r).abi.filter(m=>m.type==="function").map(co),p=Object.entries(s.systems).map(([m,y])=>{let w=e.namespace,b=y.name,x=se({type:"system",namespace:w,name:b}),a=G(m,r),g=a.abi.filter(h=>h.type==="function").map(co).filter(h=>!i.includes(h)).map(h=>{let le=w===""?h:`${w}_${b}_${h}`;return{signature:le,selector:io(le),systemId:x,systemFunctionSignature:h,systemFunctionSelector:io(h)}});return{namespace:w,name:b,systemId:x,allowAll:y.openAccess,allowedAddresses:y.accessListAddresses,allowedSystemIds:y.accessListSystems.map(h=>se({type:"system",namespace:w,name:s.systems[h].name})),address:ao({from:v,bytecode:a.bytecode,salt:T}),bytecode:a.bytecode,deployedBytecodeSize:a.deployedBytecodeSize,abi:a.abi,functions:g}}),l=p.map(({allowedAddresses:m,allowedSystemIds:y,...w})=>{let b=y.map(x=>{let a=p.find(g=>g.systemId===x);if(!a)throw new Error(`System ${S(w)} wanted access to ${S(jr(x))}, but it wasn't found in the config.`);return a.address});return{...w,allowedAddresses:Array.from(new Set([...m,...b].map(x=>Br(x))))}}),f={tableIds:Object.fromEntries(Object.entries(e.tables).map(([m,y])=>[m,Mr(se({type:y.offchainOnly?"offchainTable":"table",namespace:e.namespace,name:y.name}))]))},u=e.modules.map(m=>{let y=so.find(b=>b.name===m.name)??G(m.name,r),w=m.args.map(b=>Fr(b,f)).map(b=>{let x=b.value instanceof Uint8Array?Rr(b.value):b.value;return Wr(b.type,x)});if(w.length>1)throw new Error(`${m.name} module should only have 0-1 args, but had ${w.length} args.`);return{name:m.name,installAsRoot:m.root,installData:w.length===0?"0x":w[0],address:ao({from:v,bytecode:y.bytecode,salt:T}),bytecode:y.bytecode,deployedBytecodeSize:y.deployedBytecodeSize,abi:y.abi}});return{tables:t,systems:l,modules:u}}import{getChainId as Xr}from"viem/actions";import{existsSync as $r}from"fs";import Er from"path";import Hr from"chalk";import{getScriptDirectory as Nr,forge as zr}from"@latticexyz/common/foundry";async function mo(e,o,r,t){let n=Er.join(await Nr(),e+".s.sol");$r(n)?(console.log(Hr.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"},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."}};async function R(e){let o=e.profile??process.env.FOUNDRY_PROFILE,r=await qr(e.configPath);e.printConfig&&console.log(M.green(`
|
|
7
|
-
Resolved config:
|
|
8
|
-
`),JSON.stringify(r,null,2));let t=e.srcDir??await Zr(o),n=await Gr(o),s=e.rpc??await Yr(o);console.log(M.bgBlue(M.whiteBright(`
|
|
9
|
-
Deploying MUD contracts${o?" with profile "+o:""} to RPC ${s}
|
|
10
|
-
`))),e.skipBuild||await U({config:r,srcDir:t,foundryProfile:o});let c=process.env.PRIVATE_KEY;if(!c)throw new Qr(`Missing PRIVATE_KEY environment variable.
|
|
11
|
-
Run 'echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" > .env'
|
|
12
|
-
in your contracts directory to use the default anvil private key.`);let i=lo({config:r,forgeSourceDir:t,forgeOutDir:n}),p=Lr({transport:Kr(s),account:Jr(c)});console.log("Deploying from",p.account.address);let l=Date.now(),f=await no({worldAddress:e.worldAddress,client:p,config:i});(e.worldAddress==null||e.alwaysRunPostDeploy)&&await mo(r.postDeployScript,f.address,s,o),console.log(M.green("Deployment completed in",(Date.now()-l)/1e3,"seconds"));let u={worldAddress:f.address,blockNumber:Number(f.deployBlock)};if(e.saveDeployment){let m=await Xr(p),y=ie.join(r.deploysDirectory,m.toString());Vr(y,{recursive:!0}),ae(ie.join(y,"latest.json"),JSON.stringify(u,null,2)),ae(ie.join(y,Date.now()+".json"),JSON.stringify(u,null,2));let w=[1337,31337],b=Ur(r.worldsFile)?JSON.parse(_r(r.worldsFile,"utf-8")):{};b[m]={address:u.worldAddress,blockNumber:w.includes(m)?void 0:u.blockNumber},ae(r.worldsFile,JSON.stringify(b,null,2)),console.log(M.bgGreen(M.whiteBright(`
|
|
13
|
-
Deployment result (written to ${r.worldsFile} and ${y}):
|
|
14
|
-
`)))}return console.log(u),f}var en={command:"deploy",describe:"Deploy MUD contracts",builder(e){return e.options(k)},async handler(e){try{await R(e)}catch(o){z(o),process.exit(1)}process.exit(0)}},po=en;import{loadConfig as on}from"@latticexyz/config/node";import{worldgen as tn}from"@latticexyz/world/node";import{getSrcDirectory as rn}from"@latticexyz/common/foundry";import fo from"path";import{rmSync as nn}from"fs";var sn={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 (defaults to true)",default:!0}})},async handler(e){await an(e),process.exit(0)}};async function an(e){let o=e.srcDir??await rn(),r=I(o),t=e.config??await on(e.configPath),n=fo.join(o,t.codegenDirectory);e.clean&&nn(fo.join(n,t.worldgenDirectory),{recursive:!0,force:!0}),await tn(t,r,n)}var uo=sn;import N from"chalk";import{readFileSync as pn,writeFileSync as fn}from"fs";import de from"path";import{MUDError as $}from"@latticexyz/common/errors";var yo={name:"@latticexyz/cli",version:"2.0.0-next.15",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 && pnpm run build:test-tables","build:js":"tsup && chmod +x ./dist/mud.js","build:test-tables":"tsx ./scripts/generate-test-tables.ts",clean:"pnpm run clean:js && pnpm run clean:test-tables","clean:js":"rimraf dist","clean:test-tables":"rimraf src/codegen",dev:"tsup --watch",lint:"eslint . --ext .ts",prepare:"mkdir -p ./dist && touch ./dist/mud.js",test:"tsc --noEmit && forge test","test:ci":"pnpm run 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/abi-ts":"workspace:*","@latticexyz/common":"workspace:*","@latticexyz/config":"workspace:*","@latticexyz/gas-report":"workspace:*","@latticexyz/protocol-parser":"workspace:*","@latticexyz/schema-type":"workspace:*","@latticexyz/services":"workspace:*","@latticexyz/store":"workspace:*","@latticexyz/utils":"workspace:*","@latticexyz/world":"workspace:*","@latticexyz/world-modules":"workspace:*",chalk:"^5.0.1",chokidar:"^3.5.3",debug:"^4.3.4",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","p-retry":"^5.1.2",path:"^0.12.7",rxjs:"7.5.5","throttle-debounce":"^5.0.0",typescript:"5.1.6",viem:"1.14.0",yargs:"^17.7.1",zod:"^3.21.4","zod-validation-error":"^1.3.0"},devDependencies:{"@types/debug":"^4.1.7","@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#e282159d5170298eb2455a6c05280ab5a73a4ef0","forge-std":"https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",tsup:"^6.7.0",tsx:"^3.12.6",vitest:"0.31.4"},gitHead:"914a1e0ae4a573d685841ca2ea921435057deb8f"};import un from"glob";import{ZodError as dn,z as go}from"zod";var ln=go.object({MUD_PACKAGES:go.string().transform(e=>JSON.parse(e))});function mn(){try{return ln.parse({MUD_PACKAGES:'{"@latticexyz/abi-ts":{"localPath":"packages/abi-ts"},"@latticexyz/block-logs-stream":{"localPath":"packages/block-logs-stream"},"@latticexyz/cli":{"localPath":"packages/cli"},"@latticexyz/common":{"localPath":"packages/common"},"@latticexyz/config":{"localPath":"packages/config"},"create-mud":{"localPath":"packages/create-mud"},"@latticexyz/dev-tools":{"localPath":"packages/dev-tools"},"@latticexyz/faucet":{"localPath":"packages/faucet"},"@latticexyz/gas-report":{"localPath":"packages/gas-report"},"@latticexyz/noise":{"localPath":"packages/noise"},"@latticexyz/phaserx":{"localPath":"packages/phaserx"},"@latticexyz/protocol-parser":{"localPath":"packages/protocol-parser"},"@latticexyz/react":{"localPath":"packages/react"},"@latticexyz/recs":{"localPath":"packages/recs"},"@latticexyz/schema-type":{"localPath":"packages/schema-type"},"@latticexyz/services":{"localPath":"packages/services"},"solhint-config-mud":{"localPath":"packages/solhint-config-mud"},"solhint-plugin-mud":{"localPath":"packages/solhint-plugin-mud"},"@latticexyz/store-indexer":{"localPath":"packages/store-indexer"},"@latticexyz/store-sync":{"localPath":"packages/store-sync"},"@latticexyz/store":{"localPath":"packages/store"},"@latticexyz/utils":{"localPath":"packages/utils"},"@latticexyz/world-modules":{"localPath":"packages/world-modules"},"@latticexyz/world":{"localPath":"packages/world"}}'})}catch(e){if(e instanceof dn){let{_errors:o,...r}=e.format();console.error(`
|
|
15
|
-
Missing or invalid environment variables:
|
|
16
|
-
|
|
17
|
-
${Object.keys(r).join(`
|
|
18
|
-
`)}
|
|
19
|
-
`),process.exit(1)}throw e}}var ce=mn().MUD_PACKAGES;var yn={command:"set-version",describe:"Set MUD version in all package.json files and optionally backup the previously installed version",builder(e){return e.options({mudVersion:{alias:"v",type:"string",description:"Set MUD to the given version"},tag:{alias:"t",type:"string",description:"Set MUD to the latest version with the given tag from npm"},commit:{alias:"c",type:"string",description:"Set MUD to the version based on a given git commit hash from npm"},link:{alias:"l",type:"string",description:"Relative path to the local MUD root directory to link"}})},async handler(e){try{let o=["mudVersion","link","tag","commit","restore"],r=o.reduce((n,s)=>e[s]?n+1:n,0);if(r===0)throw new $(`You need to provide one these options: ${o.join(", ")}`);if(r>1)throw new $(`These options are mutually exclusive: ${o.join(", ")}`);e.link||(e.mudVersion=await gn(e));let t=un.sync("**/package.json").filter(n=>!n.includes("node_modules"));for(let n of t)bn(n,e)}catch(o){z(o)}finally{process.exit(0)}}};async function gn(e){e.mudVersion==="canary"&&(e.tag="main");let o;try{console.log(N.blue("Fetching available versions")),o=await(await fetch(`https://registry.npmjs.org/${yo.name}`)).json()}catch{throw new $("Could not fetch available MUD versions")}if(e.tag){let r=o["dist-tags"][e.tag];if(!r)throw new $(`Could not find npm version with tag "${e.tag}"`);return console.log(N.green(`Latest version with tag ${e.tag}: ${r}`)),r}if(e.commit){let r=e.commit.substring(0,8),t=Object.keys(o.versions).find(n=>n.includes(r));if(!t)throw new $(`Could not find npm version based on commit "${e.commit}"`);return console.log(N.green(`Version from commit ${e.commit}: ${t}`)),t}return e.mudVersion}function bn(e,o){let{link:r}=o,{mudVersion:t}=o,n=hn(e),s=Object.keys(ce),c={};for(let l in n.dependencies)s.includes(l)&&(c[l]=n.dependencies[l]);let i={};for(let l in n.devDependencies)s.includes(l)&&(i[l]=n.devDependencies[l]);for(let l in n.dependencies)s.includes(l)&&(n.dependencies[l]=p(l,"dependencies"));for(let l in n.devDependencies)s.includes(l)&&(n.devDependencies[l]=p(l,"devDependencies"));return fn(e,JSON.stringify(n,null,2)+`
|
|
20
|
-
`),console.log(`Updating ${e}`),bo(c,n.dependencies),bo(i,n.devDependencies),n;function p(l,f){return r&&(t=wn(e,r,l)),t||n[f][l]}}function hn(e){try{let o=pn(e,"utf8");return JSON.parse(o)}catch{throw new $("Could not read JSON at "+e)}}function bo(e,o){for(let r in e)e[r]!==o[r]&&console.log(`${r}: ${N.red(e[r])} -> ${N.green(o[r])}`)}function wn(e,o,r){let t=de.relative(de.dirname(e),process.cwd());return"link:"+de.join(t,o,ce[r].localPath)}var ho=yn;import{anvil as xn,forge as Sn,getRpcUrl as Cn}from"@latticexyz/common/foundry";import vn from"chalk";var Dn={...k,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"}},Tn={command:"test",describe:"Run tests in MUD contracts",builder(e){return e.options(Dn)},async handler(e){if(!e.worldAddress){let n=["--block-base-fee-per-gas","0","--port",String(e.port)];xn(n)}let o=e.worldAddress?await Cn(e.profile):`http://127.0.0.1:${e.port}`,r=e.worldAddress??(await R({...e,saveDeployment:!1,rpc:o})).address;console.log(vn.blue("World address",r));let t=e.forgeOptions?.replaceAll("\\","").split(" ")??[];try{await Sn(["test","--fork-url",o,...t],{profile:e.profile,env:{WORLD_ADDRESS:r}}),process.exit(0)}catch(n){console.error(n),process.exit(1)}}},wo=Tn;import{existsSync as An,readFileSync as kn}from"fs";import{ethers as xo}from"ethers";import{loadConfig as In}from"@latticexyz/config/node";import{MUDError as So}from"@latticexyz/common/errors";import{cast as On,getRpcUrl as Pn,getSrcDirectory as jn}from"@latticexyz/common/foundry";import{resolveWorldConfig as Fn}from"@latticexyz/world";import Wn from"@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json"assert{type:"json"};import Co from"@latticexyz/world/mud.config";import{resourceToHex as Do}from"@latticexyz/common";import{createClient as Bn,http as Mn}from"viem";import{getChainId as Rn}from"viem/actions";var vo=Do({type:"system",namespace:Co.namespace,name:Co.tables.Systems.name}),$n={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 jn(o),e.rpc??=await Pn(o);let{tx:r,configPath:t,srcDir:n,rpc:s}=e,c=I(n),i=await In(t),p=Fn(i,c.map(({basename:a})=>a)),l=e.worldAddress??await En(i.worldsFile,s),f=new xo.providers.StaticJsonRpcProvider(s),u=new xo.Contract(l,Wn,f),m=i.namespace,y=Object.values(p.systems).map(({name:a})=>a),w=await u.getFieldLayout(vo),b=[];for(let a of y){let g=Do({type:"system",namespace:m,name:a}),h=await u.getField(vo,[g],0,w);b.push({name:a,address:h})}let x=await On(["run","--label",`${l}:World`,...b.map(({name:a,address:g})=>["--label",`${g}:${a}`]).flat(),`${r}`]);console.log(x),process.exit(0)}},To=$n;async function En(e,o){if(An(e)){let r=Bn({transport:Mn(o)}),t=await Rn(r),n=JSON.parse(kn(e,"utf-8"));if(!n[t])throw new So(`chainId ${t} is missing in worldsFile "${e}"`);return n[t].address}else throw new So("worldAddress is not specified and worldsFile is missing")}import{anvil as Hn,getScriptDirectory as Nn,getSrcDirectory as zn}from"@latticexyz/common/foundry";import j from"chalk";import Un from"chokidar";import{loadConfig as Vn,resolveConfigPath as _n}from"@latticexyz/config/node";import Ln from"path";import{homedir as Kn}from"os";import{rmSync as Jn}from"fs";import{BehaviorSubject as qn,debounceTime as Gn,exhaustMap as Yn,filter as Zn}from"rxjs";import{isDefined as Qn}from"@latticexyz/common/utils";var Xn={rpc:k.rpc,configPath:k.configPath,alwaysRunPostDeploy:k.alwaysRunPostDeploy,worldAddress:k.worldAddress},es={command:"dev-contracts",describe:"Start a development server for MUD contracts",builder(e){return e.options(Xn)},async handler(e){let o=e.rpc,r=e.configPath??await _n(e.configPath),t=await zn(),n=await Nn(),s=await Vn(r);if(!e.rpc){console.log(j.gray("Cleaning devnode cache"));let l=Kn();Jn(Ln.join(l,".foundry","anvil","tmp"),{recursive:!0,force:!0}),Hn(["--block-time","1","--block-base-fee-per-gas","0"]),o="http://127.0.0.1:8545"}let c=new qn(Date.now());Un.watch([r,t,n],{ignoreInitial:!0}).on("all",async(l,f)=>{f.includes(r)&&(console.log(j.blue("Config changed, queuing deploy\u2026")),c.next(Date.now())),(f.includes(t)||f.includes(n))&&(f.includes(s.codegenDirectory)||(console.log(j.blue("Contracts changed, queuing deploy\u2026")),c.next(Date.now())))});let i=e.worldAddress;c.pipe(Gn(200),Yn(async l=>{i&&console.log(j.blue("Rebuilding and upgrading world\u2026"));try{let f=await R({...e,configPath:r,rpc:o,skipBuild:!1,printConfig:!1,profile:void 0,saveDeployment:!0,worldAddress:i,srcDir:t});return i=f.address,l<c.value?c.next(c.value):console.log(j.gray(`
|
|
21
|
-
Waiting for file changes\u2026
|
|
22
|
-
`)),f}catch(f){console.error(j.bgRed(j.whiteBright(`
|
|
23
|
-
Error while attempting deploy
|
|
24
|
-
`))),console.error(f),console.log(j.gray(`
|
|
25
|
-
Waiting for file changes\u2026
|
|
26
|
-
`))}}),Zn(Qn)).subscribe()}},Ao=es;var dp=[pe,po,fe,ye,os,ge,be,uo,ho,wo,To,Ao,ts];export{dp as commands};
|
|
27
|
-
//# sourceMappingURL=commands-4F2KXCFX.js.map
|