Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new systems pattern #63

Merged
merged 18 commits into from Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 26 additions & 73 deletions packages/cli/build/commands/deploy.js
Expand Up @@ -37,11 +37,8 @@ const builder = (yargs) => yargs.options({
chainSpec: { type: "string" },
chainId: { type: "number" },
rpc: { type: "string" },
personaMirror: { type: "string" },
persona: { type: "string" },
personaAllMinter: { type: "string" },
wsRpc: { type: "string" },
world: { type: "string" },
diamond: { type: "string" },
reuseComponents: { type: "boolean" },
deployerPrivateKey: { type: "string" },
deployClient: { type: "boolean" },
Expand Down Expand Up @@ -74,7 +71,7 @@ function findLog(deployLogLines, log) {
throw new Error("Can not find log");
}
const getDeployInfo = (args) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
const { default: chalk } = yield importChalk;
console.log();
console.log(chalk.bgWhite.black.bold(" == Mud Deployer == "));
Expand All @@ -95,6 +92,7 @@ const getDeployInfo = (args) => __awaiter(void 0, void 0, void 0, function* () {
chainSpec: "chainSpec.json",
chainId: 31337,
rpc: "http://localhost:8545",
wsRpc: "ws://localhost:8545",
reuseComponents: false,
deployClient: false,
clientUrl: "http://localhost:3000",
Expand All @@ -115,6 +113,13 @@ const getDeployInfo = (args) => __awaiter(void 0, void 0, void 0, function* () {
message: "Provide a chainId for the deployment",
when: (answers) => answers.chainSpec == null && args.chainId == null && config.chainSpec == null,
},
{
type: "input",
name: "wsRpc",
default: defaultOptions.wsRpc,
message: "Provide a WebSocket RPC endpoint for your deployment",
when: (answers) => answers.chainSpec == null && args.wsRpc == null && config.wsRpc == null,
},
{
type: "input",
name: "rpc",
Expand All @@ -127,50 +132,6 @@ const getDeployInfo = (args) => __awaiter(void 0, void 0, void 0, function* () {
return "Invalid URL";
},
},
{
type: "input",
name: "personaMirror",
message: "Provide the address of an existing PersonaMirror contract. (If none is given, PersonaMirror will be deployed.)",
when: (answers) => answers.chainSpec == null && args.personaMirror == null && config.personaMirror == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42))
return true;
return "Invalid address";
},
},
{
type: "input",
name: "persona",
message: "Provide the address of an existing Persona contract. (If none is given, Persona will be deployed.)",
when: (answers) => answers.chainSpec == null && args.persona == null && config.persona == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42))
return true;
return "Invalid address";
},
},
{
type: "input",
name: "personaAllMinter",
message: "Provide the address of an existing PersonaAllMinter contract. (If none is given, PersonaAllMinter will be deployed.)",
when: (answers) => answers.chainSpec == null && args.persona == null && config.persona == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42))
return true;
return "Invalid address";
},
},
{
type: "input",
name: "diamond",
message: "Provide the address of an existing Diamond contract that should be updated. (If none is given, a new Diamond will be deployed.)",
when: () => args.diamond == null && config.diamond == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42))
return true;
return "Invalid address";
},
},
{
type: "input",
name: "world",
Expand Down Expand Up @@ -225,8 +186,8 @@ const getDeployInfo = (args) => __awaiter(void 0, void 0, void 0, function* () {
type: "list",
message: "From which netlify account?",
choices: (answers) => __awaiter(void 0, void 0, void 0, function* () {
var _18, _19;
return yield getNetlifyAccounts((_19 = (_18 = args.netlifyPersonalToken) !== null && _18 !== void 0 ? _18 : config.netlifyPersonalToken) !== null && _19 !== void 0 ? _19 : answers.netlifyPersonalToken);
var _11, _12;
return yield getNetlifyAccounts((_12 = (_11 = args.netlifyPersonalToken) !== null && _11 !== void 0 ? _11 : config.netlifyPersonalToken) !== null && _12 !== void 0 ? _12 : answers.netlifyPersonalToken);
}),
name: "netlifySlug",
when: (answers) => answers.deployClient && !args.netlifySlug && !config.netlifySlug,
Expand Down Expand Up @@ -264,17 +225,14 @@ const getDeployInfo = (args) => __awaiter(void 0, void 0, void 0, function* () {
chainSpec: (_e = (_d = (_c = args.chainSpec) !== null && _c !== void 0 ? _c : config.chainSpec) !== null && _d !== void 0 ? _d : answers.chainSpec) !== null && _e !== void 0 ? _e : defaultOptions.chainSpec,
chainId: (_j = (_h = (_g = (_f = args.chainId) !== null && _f !== void 0 ? _f : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.chainId) !== null && _g !== void 0 ? _g : config.chainId) !== null && _h !== void 0 ? _h : answers.chainId) !== null && _j !== void 0 ? _j : defaultOptions.chainId,
rpc: (_o = (_m = (_l = (_k = args.rpc) !== null && _k !== void 0 ? _k : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.rpc) !== null && _l !== void 0 ? _l : config.rpc) !== null && _m !== void 0 ? _m : answers.rpc) !== null && _o !== void 0 ? _o : defaultOptions.rpc,
personaMirror: (_r = (_q = (_p = args.personaMirror) !== null && _p !== void 0 ? _p : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.personaMirrorAddress) !== null && _q !== void 0 ? _q : config.personaMirror) !== null && _r !== void 0 ? _r : answers.personaMirror,
personaAllMinter: (_u = (_t = (_s = args.personaAllMinter) !== null && _s !== void 0 ? _s : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.personaAllMinterAddress) !== null && _t !== void 0 ? _t : config.personaAllMinter) !== null && _u !== void 0 ? _u : answers.personaAllMinter,
persona: (_x = (_w = (_v = args.persona) !== null && _v !== void 0 ? _v : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.personaAddress) !== null && _w !== void 0 ? _w : config.persona) !== null && _x !== void 0 ? _x : answers.persona,
world: (_0 = (_z = (_y = args.world) !== null && _y !== void 0 ? _y : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.world) !== null && _z !== void 0 ? _z : config.world) !== null && _0 !== void 0 ? _0 : answers.world,
diamond: (_2 = (_1 = args.diamond) !== null && _1 !== void 0 ? _1 : config.diamond) !== null && _2 !== void 0 ? _2 : answers.diamond,
reuseComponents: (_5 = (_4 = (_3 = args.reuseComponents) !== null && _3 !== void 0 ? _3 : config.reuseComponents) !== null && _4 !== void 0 ? _4 : answers.reuseComponents) !== null && _5 !== void 0 ? _5 : defaultOptions.reuseComponents,
deployerPrivateKey: (_7 = (_6 = args.deployerPrivateKey) !== null && _6 !== void 0 ? _6 : config.deployerPrivateKey) !== null && _7 !== void 0 ? _7 : answers.deployerPrivateKey,
deployClient: (_10 = (_9 = (_8 = args.deployClient) !== null && _8 !== void 0 ? _8 : config.deployClient) !== null && _9 !== void 0 ? _9 : answers.deployClient) !== null && _10 !== void 0 ? _10 : defaultOptions.deployClient,
clientUrl: (_13 = (_12 = (_11 = args.clientUrl) !== null && _11 !== void 0 ? _11 : config.clientUrl) !== null && _12 !== void 0 ? _12 : answers.clientUrl) !== null && _13 !== void 0 ? _13 : defaultOptions.clientUrl,
netlifySlug: (_15 = (_14 = args.netlifySlug) !== null && _14 !== void 0 ? _14 : config.netlifySlug) !== null && _15 !== void 0 ? _15 : answers.netlifySlug,
netlifyPersonalToken: (_17 = (_16 = args.netlifyPersonalToken) !== null && _16 !== void 0 ? _16 : config.netlifyPersonalToken) !== null && _17 !== void 0 ? _17 : answers.netlifyPersonalToken,
wsRpc: (_s = (_r = (_q = (_p = args.wsRpc) !== null && _p !== void 0 ? _p : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.wsRpc) !== null && _q !== void 0 ? _q : config.wsRpc) !== null && _r !== void 0 ? _r : answers.wsRpc) !== null && _s !== void 0 ? _s : defaultOptions.wsRpc,
world: (_v = (_u = (_t = args.world) !== null && _t !== void 0 ? _t : chainSpec === null || chainSpec === void 0 ? void 0 : chainSpec.world) !== null && _u !== void 0 ? _u : config.world) !== null && _v !== void 0 ? _v : answers.world,
reuseComponents: (_y = (_x = (_w = args.reuseComponents) !== null && _w !== void 0 ? _w : config.reuseComponents) !== null && _x !== void 0 ? _x : answers.reuseComponents) !== null && _y !== void 0 ? _y : defaultOptions.reuseComponents,
deployerPrivateKey: (_0 = (_z = args.deployerPrivateKey) !== null && _z !== void 0 ? _z : config.deployerPrivateKey) !== null && _0 !== void 0 ? _0 : answers.deployerPrivateKey,
deployClient: (_3 = (_2 = (_1 = args.deployClient) !== null && _1 !== void 0 ? _1 : config.deployClient) !== null && _2 !== void 0 ? _2 : answers.deployClient) !== null && _3 !== void 0 ? _3 : defaultOptions.deployClient,
clientUrl: (_6 = (_5 = (_4 = args.clientUrl) !== null && _4 !== void 0 ? _4 : config.clientUrl) !== null && _5 !== void 0 ? _5 : answers.clientUrl) !== null && _6 !== void 0 ? _6 : defaultOptions.clientUrl,
netlifySlug: (_8 = (_7 = args.netlifySlug) !== null && _7 !== void 0 ? _7 : config.netlifySlug) !== null && _8 !== void 0 ? _8 : answers.netlifySlug,
netlifyPersonalToken: (_10 = (_9 = args.netlifyPersonalToken) !== null && _9 !== void 0 ? _9 : config.netlifyPersonalToken) !== null && _10 !== void 0 ? _10 : answers.netlifyPersonalToken,
};
});
const deploy = (options) => __awaiter(void 0, void 0, void 0, function* () {
Expand All @@ -292,7 +250,7 @@ const deploy = (options) => __awaiter(void 0, void 0, void 0, function* () {
const netlifyAPI = options.deployClient && new netlify(options.netlifyPersonalToken);
const id = (0, uuid_1.v4)().substring(0, 6);
let launcherUrl;
let gameContractAddress;
let worldAddress;
try {
const tasks = new listr2_1.Listr([
{
Expand All @@ -310,10 +268,8 @@ const deploy = (options) => __awaiter(void 0, void 0, void 0, function* () {
"--private-keys",
wallet.privateKey,
"--sig",
"deployEmber(address,address,address,address,bool)",
"deployEmber(address,address,bool)",
wallet.address,
options.personaMirror || ethers_1.constants.AddressZero,
options.diamond || ethers_1.constants.AddressZero,
options.world || ethers_1.constants.AddressZero,
options.reuseComponents ? "true" : "false",
"--fork-url",
Expand All @@ -322,11 +278,8 @@ const deploy = (options) => __awaiter(void 0, void 0, void 0, function* () {
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.pipe(task.stdout());
const { stdout } = yield child;
const lines = stdout.split("\n");
ctx.gameContractAddress = gameContractAddress = findLog(lines, "diamond: address");
ctx.personaAddress = findLog(lines, "persona: address");
ctx.personaMirrorAddress = findLog(lines, "personaMirror: address");
ctx.personaAllMinterAddress = findLog(lines, "personaAllMinter: address");
task.output = chalk.yellow(`Game deployed at: ${chalk.bgYellow.black(gameContractAddress)}`);
ctx.worldAddress = worldAddress = findLog(lines, "world: address");
task.output = chalk.yellow(`World deployed at: ${chalk.bgYellow.black(ctx.worldAddress)}`);
}),
options: { bottomBar: 3 },
},
Expand Down Expand Up @@ -389,7 +342,7 @@ const deploy = (options) => __awaiter(void 0, void 0, void 0, function* () {
title: "Open Launcher",
task: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const clientUrl = options.deployClient ? ctx.clientUrl : options.clientUrl;
launcherUrl = `https://play.lattice.xyz?address=${ctx.gameContractAddress || ""}&personaMirrorAddress=${ctx.personaMirrorAddress || ""}&personaAddress=${options.persona || ctx.personaAddress || ""}&personaAllMinterAddress=${options.personaAllMinter || ctx.personaAllMinterAddress || ""}&client=${clientUrl || ""}&rpc=${options.rpc || ""}&chainId=${options.chainId || ""}&dev=${options.chainId === 31337 || ""}`;
launcherUrl = `https://play.lattice.xyz?worldAddress=${ctx.worldAddress || ""}&client=${clientUrl || ""}&rpc=${options.rpc || ""}&wsRpc=${options.wsRpc || ""}&chainId=${options.chainId || ""}&dev=${options.chainId === 31337 || ""}`;
openurl_1.default.open(launcherUrl);
}),
options: { bottomBar: 3 },
Expand All @@ -401,7 +354,7 @@ const deploy = (options) => __awaiter(void 0, void 0, void 0, function* () {
yield tasks.run();
console.log(chalk.bgGreen.black.bold(" Congratulations! Deployment successful"));
console.log();
console.log(chalk.green(`Contract deployed to ${gameContractAddress}`));
console.log(chalk.green(`World address ${worldAddress}`));
console.log(chalk.green(`Open launcher at ${launcherUrl}`));
console.log();
}
Expand Down
90 changes: 90 additions & 0 deletions packages/cli/build/commands/system-types.js
@@ -0,0 +1,90 @@
"use strict";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to commit these generated files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Removed them

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.desc = exports.command = void 0;
const fs_1 = __importDefault(require("fs"));
const glob_1 = __importDefault(require("glob"));
const utils_1 = require("../utils");
const IDregex = new RegExp(/(?<=uint256 constant ID = uint256\(keccak256\(")(.*)(?="\))/);
exports.command = "system-types";
exports.desc = "Generates system type file. Note: assumes ABIs of all systems in ./abi and typechain generated types in ./types/ethers-contracts";
const builder = (yargs) => yargs.options({
include: { type: "array" },
exclude: { type: "array" },
out: { type: "string" },
});
exports.builder = builder;
const handler = () => __awaiter(void 0, void 0, void 0, function* () {
const wd = process.cwd();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let abis = [];
let systems = [];
let ids = [];
let typePaths = [];
const systemsPath = `${wd}/src/systems/*.sol`;
const [resolve, , promise] = (0, utils_1.deferred)();
(0, glob_1.default)(systemsPath, {}, (_, matches) => {
systems = matches.map((path) => {
const fragments = path.split("/");
return fragments[fragments.length - 1].split(".sol")[0];
});
ids = matches
.map((path) => fs_1.default.readFileSync(path).toString())
.map((source, index) => {
const regexResult = IDregex.exec(source);
const id = regexResult && regexResult[0];
if (!id) {
console.log("Source:", source);
console.log("ID:", id);
console.log("Regex:", IDregex, regexResult);
throw new Error("No ID found for" +
matches[index] +
". Make sure your system source file includes a ID definition (uint256 constant ID = uint256(keccak256(<ID>));)");
}
return id;
});
abis = systems.map((system) => `../abi/${system}.json`);
typePaths = systems.map((system) => `./ethers-contracts/${system}.ts`);
resolve();
});
// Make the callback synchronous
yield promise;
console.log("Matches", systems);
console.log("Solidity", ids);
console.log("Type paths", typePaths);
console.log("ABIs", abis);
const SystemTypes = `// Autogenerated using mud system-types
${typePaths.map((path, index) => `import { ${systems[index]} } from "${path.replace(".ts", "")}";`).join("\n")}

export type SystemTypes = {
${systems.map((system, index) => ` "${ids[index]}": ${system};`).join("\n")}
};
`;
const SystemAbis = `// Autogenerated using mud system-types
${abis.map((path, index) => `import { abi as ${systems[index]} } from "${path}";`).join("\n")}

export const SystemAbis = {
${systems.map((system, index) => ` "${ids[index]}": ${system},`).join("\n")}
};
`;
console.log("Generating files:");
console.log("SystemTypes.ts", SystemTypes);
console.log("SystemAbis.ts", SystemAbis);
fs_1.default.writeFileSync("./types/SystemTypes.ts", SystemTypes);
fs_1.default.writeFileSync("./types/SystemAbis.ts", SystemAbis);
// fs.writeFileSync(out, JSON.stringify({ abi }));
// console.log(`Created diamond abi at ${out}`);
// process.exit(0);
});
exports.handler = handler;
3 changes: 2 additions & 1 deletion packages/cli/package.json
Expand Up @@ -50,7 +50,8 @@
"openurl": "^1.1.1",
"path": "^0.12.7",
"uuid": "^8.3.2",
"yargs": "^17.5.1"
"yargs": "^17.5.1",
"typechain": "^8.1.0"
},
"pkg": {
"scripts": "build/**/*.js"
Expand Down