@everyprotocol/every-cli 0.1.15 → 0.1.17
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/abis2/IElementRegistry.json +1 -0
- package/abis2/IKindRegistry.json +1 -0
- package/abis2/IOmniRegistry.json +1 -0
- package/abis2/ISet.json +1 -0
- package/abis2/ISetRegistry.json +1 -0
- package/abis2/ObjectMinterAdmin.json +1 -0
- package/abis2/SetRegistryAdmin.json +1 -0
- package/abis2/events-errors.json +4407 -0
- package/dist/abi.js +3 -3
- package/dist/abi2.js +52 -0
- package/dist/abicmd.js +121 -0
- package/dist/artifact.js +1 -1
- package/dist/cmds/kind.js +34 -25
- package/dist/cmds/object.js +333 -160
- package/dist/cmds/set.js +84 -34
- package/dist/parsers.js +42 -5
- package/package.json +2 -1
package/dist/abi.js
CHANGED
|
@@ -27,15 +27,15 @@ export const abi = {
|
|
|
27
27
|
...parseAbi(["function setContract(uint64 id) external view returns (address code)"]),
|
|
28
28
|
...loadNonFuncAbiItems("SetRegistry"),
|
|
29
29
|
],
|
|
30
|
-
|
|
30
|
+
minterMint: [
|
|
31
31
|
...parseAbi([
|
|
32
32
|
"function mint(address to, address set, uint64 id, bytes memory data, bytes memory auth, uint32 policy) payable",
|
|
33
33
|
]),
|
|
34
34
|
...loadNonFuncAbiItems("ObjectMinter"),
|
|
35
35
|
...loadNonFuncAbiItems("ISet"),
|
|
36
36
|
],
|
|
37
|
-
|
|
38
|
-
...parseAbi(["function
|
|
37
|
+
setMint: [
|
|
38
|
+
...parseAbi(["function mint(address to, uint64 id0, bytes calldata data) payable"]),
|
|
39
39
|
...loadNonFuncAbiItems("ISet"),
|
|
40
40
|
],
|
|
41
41
|
relation: [
|
package/dist/abi2.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { toFunctionSignature } from "viem";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { memoize } from "lodash-es";
|
|
5
|
+
import { __dirname } from "./utils.js";
|
|
6
|
+
function getSelectorsInner() {
|
|
7
|
+
return loadAbiFromFile("events-errors");
|
|
8
|
+
}
|
|
9
|
+
// export const getSelectors = memoize(getSelectorsInner);
|
|
10
|
+
export const getNonFuncs = memoize(getSelectorsInner);
|
|
11
|
+
function getFuncsInner(name) {
|
|
12
|
+
return loadFuncAbiItems(name);
|
|
13
|
+
}
|
|
14
|
+
export const getFuncs = memoize(getFuncsInner);
|
|
15
|
+
function getAbiInner(name) {
|
|
16
|
+
return [...getFuncs(name), ...getNonFuncs()];
|
|
17
|
+
}
|
|
18
|
+
export const getAbi = memoize(getAbiInner);
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
export function loadAbiFromFile(name) {
|
|
21
|
+
const file = path.resolve(__dirname, "../abis2", `${name}.json`);
|
|
22
|
+
const content = fs.readFileSync(file, "utf8");
|
|
23
|
+
return JSON.parse(content);
|
|
24
|
+
}
|
|
25
|
+
export function loadNonFuncAbiItems(name) {
|
|
26
|
+
const abi = loadAbiFromFile(name);
|
|
27
|
+
return (abi.abi || []).filter((item) => item.type === "event" || item.type === "error");
|
|
28
|
+
}
|
|
29
|
+
export function loadFuncAbiItems(name) {
|
|
30
|
+
const abi = loadAbiFromFile(name);
|
|
31
|
+
const metadata = abi.metadata?.output || {};
|
|
32
|
+
const userMethods = metadata.userdoc?.methods || {};
|
|
33
|
+
const devMethods = metadata.devdoc?.methods || {};
|
|
34
|
+
return (abi.abi
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
.filter((item) => item.type === "function")
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
.map((item) => {
|
|
39
|
+
const signature = toFunctionSignature(item);
|
|
40
|
+
const userdoc = userMethods[signature] || {};
|
|
41
|
+
const devdoc = devMethods[signature] || {};
|
|
42
|
+
const _metadata = {
|
|
43
|
+
signature,
|
|
44
|
+
...devdoc,
|
|
45
|
+
...userdoc,
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
...item,
|
|
49
|
+
_metadata,
|
|
50
|
+
};
|
|
51
|
+
}));
|
|
52
|
+
}
|
package/dist/abicmd.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Argument, Command, Option } from "commander";
|
|
2
|
+
import { getNonFuncs } from "./abi2.js";
|
|
3
|
+
import { coerceValue } from "./utils.js";
|
|
4
|
+
import { outputOptions, universe, writeOptions } from "./commander-patch.js";
|
|
5
|
+
import { submitSimulation } from "./ethereum.js";
|
|
6
|
+
import { Logger } from "./logger.js";
|
|
7
|
+
import { FromOpts } from "./from-opts.js";
|
|
8
|
+
export function genAbiCommand(cmdName, abiFunc, cmdConf) {
|
|
9
|
+
const { cmdArgs, cmdOpts, argGetters } = genAbiCommandParams(abiFunc, cmdConf.params);
|
|
10
|
+
const desc = cmdConf.descs?.[`${abiFunc.name}`] ?? abiFunc._metadata.notice ?? "";
|
|
11
|
+
return new Command(cmdName)
|
|
12
|
+
.description(desc)
|
|
13
|
+
.addArguments(cmdArgs)
|
|
14
|
+
.addOptions(cmdOpts)
|
|
15
|
+
.action(AbiCommandAction(abiFunc, argGetters, cmdConf.prepare));
|
|
16
|
+
}
|
|
17
|
+
function ArgGetterArg(i) {
|
|
18
|
+
return function (cmd) {
|
|
19
|
+
return cmd.processedArgs[i];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function ArgGetterOpt(name) {
|
|
23
|
+
return function (cmd) {
|
|
24
|
+
return cmd.getOptionValue(name);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function ArgParser(input) {
|
|
28
|
+
// eslint-disable-next-line
|
|
29
|
+
return function (value, previous) {
|
|
30
|
+
return coerceValue(value, input);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function genAbiCommandParams(abiFunc, params) {
|
|
34
|
+
const cmdArgs = [];
|
|
35
|
+
const cmdOpts = [];
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
const argGetters = [];
|
|
38
|
+
{
|
|
39
|
+
const pfn = params?.[`${abiFunc.name}.PREPEND`] ?? params?.[`.PREPEND`];
|
|
40
|
+
if (pfn) {
|
|
41
|
+
const argOrOpt = pfn();
|
|
42
|
+
if (argOrOpt instanceof Option) {
|
|
43
|
+
cmdOpts.push(argOrOpt);
|
|
44
|
+
argGetters.push(ArgGetterOpt(argOrOpt.name()));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const newLen = cmdArgs.push(argOrOpt);
|
|
48
|
+
argGetters.push(ArgGetterArg(newLen - 1));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
abiFunc.inputs.map((input) => {
|
|
53
|
+
const name = input.name;
|
|
54
|
+
const pfn = params?.[`${abiFunc.name}.${name}`] ?? params?.[`.${name}`] ?? (() => new Argument(`<${name}>`));
|
|
55
|
+
const argOrOpt = pfn();
|
|
56
|
+
if (!hasDescription(argOrOpt)) {
|
|
57
|
+
const desc = abiFunc._metadata?.params?.[name] || `parameter ${name}: ${input.type}`;
|
|
58
|
+
argOrOpt.description = desc;
|
|
59
|
+
}
|
|
60
|
+
if (!hasArgParser(argOrOpt)) {
|
|
61
|
+
argOrOpt.argParser(ArgParser(input));
|
|
62
|
+
}
|
|
63
|
+
if (argOrOpt instanceof Option) {
|
|
64
|
+
cmdOpts.push(argOrOpt);
|
|
65
|
+
argGetters.push(ArgGetterOpt(argOrOpt.name()));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const newLen = cmdArgs.push(argOrOpt);
|
|
69
|
+
argGetters.push(ArgGetterArg(newLen - 1));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (abiFunc.stateMutability == "view" || abiFunc.stateMutability == "pure") {
|
|
73
|
+
cmdOpts.push(universe, ...outputOptions);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
cmdOpts.push(...writeOptions, ...outputOptions);
|
|
77
|
+
}
|
|
78
|
+
return { cmdArgs, cmdOpts, argGetters };
|
|
79
|
+
}
|
|
80
|
+
function AbiCommandReadAction(abiFunc, argGetters, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
81
|
+
contractGetter) {
|
|
82
|
+
return async function action() {
|
|
83
|
+
const opts = this.opts();
|
|
84
|
+
const console = new Logger(opts);
|
|
85
|
+
const { conf, publicClient } = FromOpts.toReadEthereum(opts);
|
|
86
|
+
const args0 = argGetters.map((getArg) => getArg(this));
|
|
87
|
+
const [address, args, altAbiFunc] = await contractGetter(conf, publicClient, args0, abiFunc.name);
|
|
88
|
+
const abiFuncFinal = altAbiFunc ?? abiFunc;
|
|
89
|
+
const abi = [abiFuncFinal, ...getNonFuncs()];
|
|
90
|
+
const result = await publicClient.readContract({ address, abi, functionName: abiFuncFinal.name, args });
|
|
91
|
+
console.log(result);
|
|
92
|
+
console.result(result);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function AbiCommandWriteAction(abiFunc, argGetters, prepare) {
|
|
96
|
+
return async function action() {
|
|
97
|
+
const opts = this.opts();
|
|
98
|
+
const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
|
|
99
|
+
const args0 = argGetters.map((getArg) => getArg(this));
|
|
100
|
+
const [address, args, altAbiFunc] = await prepare(conf, publicClient, args0, abiFunc.name);
|
|
101
|
+
const account = walletClient.account;
|
|
102
|
+
const abiFuncFinal = altAbiFunc ?? abiFunc;
|
|
103
|
+
const abi = [abiFuncFinal, ...getNonFuncs()];
|
|
104
|
+
const sim = { address, abi, functionName: abiFuncFinal.name, args, account };
|
|
105
|
+
await submitSimulation(sim, publicClient, walletClient, new Logger(opts));
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function AbiCommandAction(abiFunc, argGetters, prepare) {
|
|
109
|
+
return abiFunc.stateMutability == "view" || abiFunc.stateMutability == "pure"
|
|
110
|
+
? AbiCommandReadAction(abiFunc, argGetters, prepare)
|
|
111
|
+
: AbiCommandWriteAction(abiFunc, argGetters, prepare);
|
|
112
|
+
}
|
|
113
|
+
function hasArgParser(obj) {
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
115
|
+
const anyObj = obj;
|
|
116
|
+
return typeof anyObj._fn === "function" || typeof anyObj._argParser === "function";
|
|
117
|
+
}
|
|
118
|
+
function hasDescription(argOrOpt) {
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
return typeof argOrOpt.description === "string" && argOrOpt.description.trim().length > 0;
|
|
121
|
+
}
|
package/dist/artifact.js
CHANGED
|
@@ -45,7 +45,7 @@ export function getCreationCode(artifact) {
|
|
|
45
45
|
}
|
|
46
46
|
/** Get ABI array from a Foundry/solc artifact JSON object. */
|
|
47
47
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
export function
|
|
48
|
+
export function getAbiFromArtifact(artifact) {
|
|
49
49
|
const abi = artifact?.abi;
|
|
50
50
|
if (!Array.isArray(abi))
|
|
51
51
|
throw new Error("abi missing or not an array");
|
package/dist/cmds/kind.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import { Argument, Command, Option } from "commander";
|
|
2
|
-
import {
|
|
3
|
-
import { getCommandGen, makeFuncName } from "../cmdgen.js";
|
|
2
|
+
import { getAbi, getFuncs } from "../abi2.js";
|
|
4
3
|
import { toHex } from "viem";
|
|
5
4
|
import { coerceValue, readKindElements, toElementType, toRelationId } from "../utils.js";
|
|
6
5
|
import { outputOptions, writeOptions } from "../commander-patch.js";
|
|
7
6
|
import { submitSimulation } from "../ethereum.js";
|
|
8
7
|
import { Logger } from "../logger.js";
|
|
9
8
|
import { FromOpts } from "../from-opts.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
getAbiFuncs: (funcName) => abi.funcs.kindRegistry.filter((i) => i.name == funcName),
|
|
13
|
-
// eslint-disable-next-line
|
|
14
|
-
getAbiNonFuncs: (funcName) => abi.nonFuncs.kindRegistry,
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
getContract: (conf, args, abiFunc) => conf.contracts.KindRegistry,
|
|
17
|
-
});
|
|
9
|
+
import { genAbiCommand } from "../abicmd.js";
|
|
10
|
+
import { makeFuncName } from "../cmdgen.js";
|
|
18
11
|
const registerCmd = genRegisterCmd();
|
|
19
12
|
const updateCmd = genUpdateCmd();
|
|
20
|
-
const
|
|
13
|
+
const cmdConfig = {
|
|
14
|
+
params: {
|
|
15
|
+
".rev0": () => new Option(`--rev <rev0>`).default(0),
|
|
16
|
+
".kindRev": () => new Option(`--krev <rev0>`).default(0),
|
|
17
|
+
".setRev": () => new Option(`--srev <rev0>`).default(0),
|
|
18
|
+
},
|
|
19
|
+
// eslint-disable-next-line
|
|
20
|
+
prepare: (conf, client, args) => [
|
|
21
|
+
conf.contracts.KindRegistry,
|
|
22
|
+
args,
|
|
23
|
+
undefined,
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
const abiFuncs = getFuncs("IKindRegistry");
|
|
27
|
+
const otherCmds = "upgrade,touch,transfer,owner,descriptor,snapshot".split(",").map((name) => {
|
|
28
|
+
const funcName = makeFuncName(name, "kind");
|
|
29
|
+
const abiFunc = abiFuncs.filter((i) => i.name == funcName)[0];
|
|
30
|
+
return genAbiCommand(name, abiFunc, cmdConfig);
|
|
31
|
+
});
|
|
21
32
|
export const kindCmd = new Command("kind")
|
|
22
33
|
.description("manage kinds")
|
|
23
34
|
.addCommand(registerCmd)
|
|
@@ -25,8 +36,7 @@ export const kindCmd = new Command("kind")
|
|
|
25
36
|
.addCommands(otherCmds);
|
|
26
37
|
function genRegisterCmd() {
|
|
27
38
|
const funcName = "kindRegister";
|
|
28
|
-
const abiFuncs =
|
|
29
|
-
const abiNonFuncs = abi.nonFuncs.kindRegistry;
|
|
39
|
+
const abiFuncs = getFuncs("IKindRegistry").filter((i) => i.name == funcName);
|
|
30
40
|
const code = new Argument("<code>", "Matter hash of the kind code");
|
|
31
41
|
const data = new Argument("<data>", "Matter hash of the kind data");
|
|
32
42
|
const etys = new Option("--elements <ety...>", "Element types");
|
|
@@ -56,7 +66,7 @@ function genRegisterCmd() {
|
|
|
56
66
|
const account = walletClient.account;
|
|
57
67
|
const simulation = {
|
|
58
68
|
address,
|
|
59
|
-
abi:
|
|
69
|
+
abi: getAbi("IKindRegistry"),
|
|
60
70
|
functionName: funcName,
|
|
61
71
|
args,
|
|
62
72
|
account,
|
|
@@ -70,9 +80,9 @@ function genRegisterCmd() {
|
|
|
70
80
|
.action(getCmdAction);
|
|
71
81
|
}
|
|
72
82
|
function genUpdateCmd() {
|
|
73
|
-
const funcName = "kindUpdate";
|
|
74
|
-
const abiFuncs = abi.funcs.kindRegistry.filter((i) => i.name == funcName);
|
|
75
|
-
const abiNonFuncs = abi.nonFuncs.kindRegistry;
|
|
83
|
+
// const funcName = "kindUpdate";
|
|
84
|
+
// const abiFuncs = (abi.funcs.kindRegistry as AbiFunctionDoc[]).filter((i) => i.name == funcName);
|
|
85
|
+
// const abiNonFuncs = abi.nonFuncs.kindRegistry;
|
|
76
86
|
const code = new Option("--code <code>", "Matter hash of the kind code");
|
|
77
87
|
const data = new Option("--data <data>", "Matter hash of the kind data");
|
|
78
88
|
const rels = new Option("--relations [rel...]", "IDs of relations supported");
|
|
@@ -83,22 +93,22 @@ function genUpdateCmd() {
|
|
|
83
93
|
const opts = cmd.opts();
|
|
84
94
|
const args = [cmd.args[0]];
|
|
85
95
|
const ZERO32 = toHex(0, { size: 32 });
|
|
86
|
-
let sig;
|
|
96
|
+
// let sig;
|
|
87
97
|
if (opts.relations) {
|
|
88
98
|
if (opts.code || opts.data) {
|
|
89
|
-
sig = "kindUpdate(uint64,bytes32,bytes32,uint64[])";
|
|
99
|
+
// sig = "kindUpdate(uint64,bytes32,bytes32,uint64[])";
|
|
90
100
|
args.push(opts.code ?? ZERO32);
|
|
91
101
|
args.push(opts.data ?? ZERO32);
|
|
92
102
|
args.push(typeof opts.relations == "boolean" ? [] : opts.relations);
|
|
93
103
|
}
|
|
94
104
|
else {
|
|
95
|
-
sig = "kindUpdate(uint64,uint64[])";
|
|
105
|
+
// sig = "kindUpdate(uint64,uint64[])";
|
|
96
106
|
args.push(typeof opts.relations == "boolean" ? [] : opts.relations);
|
|
97
107
|
}
|
|
98
108
|
}
|
|
99
109
|
else {
|
|
100
110
|
if (opts.code || opts.data) {
|
|
101
|
-
sig = "kindUpdate(uint64,bytes32,bytes32)";
|
|
111
|
+
// sig = "kindUpdate(uint64,bytes32,bytes32)";
|
|
102
112
|
args.push(opts.code ?? ZERO32);
|
|
103
113
|
args.push(opts.data ?? ZERO32);
|
|
104
114
|
}
|
|
@@ -106,18 +116,17 @@ function genUpdateCmd() {
|
|
|
106
116
|
throw new Error("");
|
|
107
117
|
}
|
|
108
118
|
}
|
|
109
|
-
|
|
110
|
-
return [args, abiFunc];
|
|
119
|
+
return args;
|
|
111
120
|
}
|
|
112
121
|
async function getCmdAction() {
|
|
113
122
|
const opts = this.opts();
|
|
114
|
-
const
|
|
123
|
+
const args = getFuncArgs(this);
|
|
115
124
|
const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
|
|
116
125
|
const address = conf.contracts.KindRegistry;
|
|
117
126
|
const account = walletClient.account;
|
|
118
127
|
const simulation = {
|
|
119
128
|
address,
|
|
120
|
-
abi:
|
|
129
|
+
abi: getAbi("IKindRegistry"),
|
|
121
130
|
functionName: "kindUpdate",
|
|
122
131
|
args,
|
|
123
132
|
account,
|