@everyprotocol/every-cli 0.1.16 → 0.1.18

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/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 getAbi(artifact) {
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 { abi } from "../abi.js";
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
- const genKindCmd = getCommandGen({
11
- getFuncName: (cmdName) => makeFuncName(cmdName, `kind`),
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 otherCmds = "upgrade,touch,transfer,owner,descriptor,snapshot".split(",").map(genKindCmd);
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 = abi.funcs.kindRegistry.filter((i) => i.name == funcName);
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: [...abiFuncs, ...abiNonFuncs],
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
- const abiFunc = abiFuncs.filter((f) => f._metadata.signature == sig)[0];
110
- return [args, abiFunc];
119
+ return args;
111
120
  }
112
121
  async function getCmdAction() {
113
122
  const opts = this.opts();
114
- const [args, abiFunc] = getFuncArgs(this);
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: [abiFunc, ...abiNonFuncs],
129
+ abi: getAbi("IKindRegistry"),
121
130
  functionName: "kindUpdate",
122
131
  args,
123
132
  account,
@@ -1,13 +1,14 @@
1
- import { Command } from "commander";
1
+ import { Command, Option } from "commander";
2
2
  import "@polkadot/api-augment/substrate";
3
3
  import * as fs from "fs";
4
4
  import path from "path";
5
5
  import columify from "columnify";
6
6
  import { j11String, loadBinary, loadJson } from "../utils.js";
7
7
  import { submitTransaction } from "../substrate.js";
8
- import { network, universe } from "../commander-patch.js";
9
8
  import { Logger } from "../logger.js";
10
9
  import { compileEnumCsv, compilePermCsv, computeHash, parseFileSpec, specToInput, } from "../matter.js";
10
+ const universe = new Option("-u, --universe <universe>", "Universe name");
11
+ const network = new Option("-n, --network <network>", "Network name");
11
12
  const matterRegisterCmd = new Command("register")
12
13
  .description("Register matters")
13
14
  .argument("<files...>", "Paths of matter blob files")
@@ -1,6 +1,7 @@
1
1
  import { Argument, Option, Command } from "commander";
2
- import { parseAbiItem, erc1155Abi, erc721Abi } from "viem";
3
- import { abi } from "../abi.js";
2
+ import { parseAbi } from "viem";
3
+ import { parseAbiItem } from "viem";
4
+ import { getAbi, getNonFuncs } from "../abi2.js";
4
5
  import { submitSimulation } from "../ethereum.js";
5
6
  import { Logger } from "../logger.js";
6
7
  import { parseAddress, parseBigInt, parseEther, parseHexData, parseInt, parseNode3, parseNode4, parseSID, } from "../parsers.js";
@@ -11,6 +12,15 @@ const sidArg = new Argument("<sid>", "Object SID, in form of {set}.{id}").argPar
11
12
  const tailArg = new Argument("<tail>", "Tail object, in form of [[data.]grant.]set.id").argParser(parseNode4);
12
13
  const relArg = new Argument("<rel>", "Relation ID").argParser(parseBigInt);
13
14
  const headArg = new Argument("<head>", "Head object, in form of [grant.]set.id").argParser(parseNode3);
15
+ const otherAbi = [
16
+ ...parseAbi([
17
+ "function mint(address to, address set, uint64 id, bytes memory data, bytes memory auth, uint32 policy) payable",
18
+ "function mint(address to, uint64 id0, bytes calldata data) payable",
19
+ "function relate(uint256 tail, uint64 rel, uint256 head)",
20
+ "function unrelate(uint256 tail, uint64 rel, uint256 head)",
21
+ ]),
22
+ ...getNonFuncs(),
23
+ ];
14
24
  export const objectCmd = new Command("object")
15
25
  .description("manage objects")
16
26
  .addCommand(genMintCmd())
@@ -37,11 +47,11 @@ function genUpgradeCmd() {
37
47
  const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
38
48
  const { set, id } = this.processedArgs[0];
39
49
  const address = await getSetContract(set, publicClient, conf);
40
- const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
41
50
  const functionName = "upgrade";
42
51
  const args = [id, opts.krev ?? 0, opts.srev ?? 0];
43
52
  const account = walletClient.account;
44
- const simulation = { address, abi: abi_, functionName, args, account };
53
+ const abi = getAbi("ISet");
54
+ const simulation = { address, abi, functionName, args, account };
45
55
  await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
46
56
  }
47
57
  return new Command("upgrade")
@@ -58,11 +68,11 @@ function genTouchCmd() {
58
68
  const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
59
69
  const { set, id } = this.processedArgs[0];
60
70
  const address = await getSetContract(set, publicClient, conf);
61
- const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
62
71
  const functionName = "touch";
63
72
  const args = [id];
64
73
  const account = walletClient.account;
65
- const simulation = { address, abi: abi_, functionName, args, account };
74
+ const abi = getAbi("ISet");
75
+ const simulation = { address, abi, functionName, args, account };
66
76
  await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
67
77
  }
68
78
  return new Command("touch").description("Touch an object").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
@@ -75,11 +85,11 @@ function genTransferCmd() {
75
85
  const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
76
86
  const { set, id } = this.processedArgs[0];
77
87
  const address = await getSetContract(set, publicClient, conf);
78
- const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
79
88
  const functionName = "transfer";
80
89
  const args = [id, this.processedArgs[1]];
81
90
  const account = walletClient.account;
82
- const simulation = { address, abi: abi_, functionName, args, account };
91
+ const abi = getAbi("ISet");
92
+ const simulation = { address, abi, functionName, args, account };
83
93
  await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
84
94
  }
85
95
  return new Command("transfer")
@@ -113,7 +123,7 @@ function genMintCmd() {
113
123
  if (!opts.minter) {
114
124
  const address = await getSetContract(set, publicClient, conf);
115
125
  const args = [to, id, data];
116
- simulation = { address, abi: abi.setMint, functionName, args, value, account };
126
+ simulation = { address, abi: otherAbi, functionName, args, value, account };
117
127
  }
118
128
  else {
119
129
  const setAddress = await getSetContract(set, publicClient, conf);
@@ -121,7 +131,14 @@ function genMintCmd() {
121
131
  const authData = opts.auth ?? "0x";
122
132
  const policy = opts.policy ?? 0;
123
133
  const args = [to, setAddress, id, data, authData, policy];
124
- simulation = { address, abi: abi.minterMint, functionName, args, value, account };
134
+ simulation = {
135
+ address,
136
+ abi: otherAbi,
137
+ functionName,
138
+ args,
139
+ value,
140
+ account,
141
+ };
125
142
  }
126
143
  await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
127
144
  }
@@ -145,7 +162,7 @@ function genSendCmd() {
145
162
  throw new Error(`Not a function signature: ${sig}`);
146
163
  const abiFunc = item;
147
164
  const params = abiFunc.inputs ?? [];
148
- const args0 = this.args.slice(0);
165
+ const args0 = this.args.slice(1);
149
166
  if (args0.length !== params.length)
150
167
  throw new Error(`Invalid argument count: expected ${params.length}, got ${args0.length}`);
151
168
  const sidPos = params.findIndex((p) => p.type == "uint64");
@@ -160,7 +177,7 @@ function genSendCmd() {
160
177
  const value = opts.value ?? 0;
161
178
  const simulation = {
162
179
  address,
163
- abi: [abiFunc, ...abi.nonFuncs.setContract, ...erc1155Abi, ...erc721Abi],
180
+ abi: [abiFunc, ...getNonFuncs()],
164
181
  functionName: abiFunc.name,
165
182
  args,
166
183
  account,
@@ -184,8 +201,8 @@ function genOwnerCmd() {
184
201
  const { conf, publicClient } = FromOpts.toReadEthereum(opts);
185
202
  const address = await getSetContract(set, publicClient, conf);
186
203
  const args = [id];
187
- const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
188
- const result = await publicClient.readContract({ address, abi: abi_, functionName: cmdName, args });
204
+ const abi = getAbi("ISet");
205
+ const result = await publicClient.readContract({ address, abi, functionName: cmdName, args });
189
206
  const console = new Logger(opts);
190
207
  console.log(result);
191
208
  console.result(result);
@@ -206,8 +223,8 @@ function genDescriptorCmd() {
206
223
  const { conf, publicClient } = FromOpts.toReadEthereum(opts);
207
224
  const address = await getSetContract(set, publicClient, conf);
208
225
  const args = [id, opts.rev ?? 0];
209
- const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
210
- const result = await publicClient.readContract({ address, abi: abi_, functionName: cmdName, args });
226
+ const abi = getAbi("ISet");
227
+ const result = await publicClient.readContract({ address, abi, functionName: cmdName, args });
211
228
  const console = new Logger(opts);
212
229
  console.log(result);
213
230
  console.result(result);
@@ -232,8 +249,8 @@ function genSnapshotCmd() {
232
249
  const { conf, publicClient } = FromOpts.toReadEthereum(opts);
233
250
  const address = await getSetContract(set, publicClient, conf);
234
251
  const args = [id, opts.rev ?? 0];
235
- const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
236
- const result = await publicClient.readContract({ address, abi: abi_, functionName: cmdName, args });
252
+ const abi = getAbi("ISet");
253
+ const result = await publicClient.readContract({ address, abi, functionName: cmdName, args });
237
254
  const console = new Logger(opts);
238
255
  console.log(result);
239
256
  console.result(result);
@@ -258,10 +275,10 @@ function genUriCmd() {
258
275
  const { conf, publicClient } = FromOpts.toReadEthereum(opts);
259
276
  const address = await getSetContract(set, publicClient, conf);
260
277
  const args = []; // eslint-disable-line @typescript-eslint/no-explicit-any
261
- const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
278
+ const abi = getAbi("ISet");
262
279
  const result0 = (await publicClient.readContract({
263
280
  address,
264
- abi: abi_,
281
+ abi,
265
282
  functionName: cmdName,
266
283
  args,
267
284
  })); // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -280,7 +297,7 @@ function genRelateCmd() {
280
297
  const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
281
298
  const simulation = {
282
299
  address: conf.contracts.OmniRegistry,
283
- abi: abi.relation,
300
+ abi: otherAbi,
284
301
  functionName: "relate",
285
302
  args: this.processedArgs,
286
303
  account: walletClient.account,
@@ -302,7 +319,7 @@ function genUnrelateCmd() {
302
319
  const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
303
320
  const simulation = {
304
321
  address: conf.contracts.OmniRegistry,
305
- abi: abi.relation,
322
+ abi: otherAbi,
306
323
  functionName: "unrelate",
307
324
  args: this.processedArgs,
308
325
  account: walletClient.account,
@@ -320,9 +337,10 @@ function interpolate(tmpl, id, rev) {
320
337
  return tmpl.replace(/\{id\}/g, String(id)).replace(/\{rev\}/g, String(rev));
321
338
  }
322
339
  async function getSetContract(set, publicClient, conf) {
340
+ const abi = getAbi("ISetRegistry");
323
341
  const address = await publicClient.readContract({
324
342
  address: conf.contracts.SetRegistry,
325
- abi: abi.setContract,
343
+ abi,
326
344
  functionName: "setContract",
327
345
  args: [set],
328
346
  });
package/dist/cmds/set.js CHANGED
@@ -1,41 +1,81 @@
1
1
  import { Argument, Command, Option } from "commander";
2
- import { abi } from "../abi.js";
3
- import { CommandGenDefaults, getCommandGen, makeFuncName } from "../cmdgen.js";
4
2
  import { outputOptions, writeOptions } from "../commander-patch.js";
5
3
  import { FromOpts } from "../from-opts.js";
6
4
  import { coerceValue, loadJson } from "../utils.js";
7
- import { getAbi, getArtifactPath, getCreationCode } from "../artifact.js";
5
+ import { getAbiFromArtifact, getArtifactPath, getCreationCode } from "../artifact.js";
8
6
  import { Logger } from "../logger.js";
9
- const adminCmdConfig = {
10
- getFuncName: (cmdName) => `${cmdName}Set`,
11
- getAbiFuncs: (funcName) => abi.funcs.setRegistryAdmin.filter((i) => i.name == funcName),
12
- // eslint-disable-next-line
13
- getAbiNonFuncs: (funcName) => abi.nonFuncs.setRegistry,
14
- // eslint-disable-next-line
15
- getContract: (conf, args, abiFunc) => args[0],
16
- // eslint-disable-next-line
17
- getFuncArgs: (args, abiFunc) => args.slice(1),
18
- getCmdArgs: (abiFunc) => [
19
- new Argument(`<contract>`, "address of the set contract"),
20
- ...CommandGenDefaults.getCmdArgs(abiFunc),
21
- ],
22
- };
23
- const userCmdConfig = {
24
- getFuncName: (cmdName) => makeFuncName(cmdName, `set`),
25
- getAbiFuncs: (funcName) => abi.funcs.setRegistry.filter((i) => i.name == funcName),
26
- // eslint-disable-next-line
27
- getAbiNonFuncs: (funcName) => abi.nonFuncs.setRegistry,
7
+ import { genAbiCommand } from "../abicmd.js";
8
+ import { getFuncs, getAbi } from "../abi2.js";
9
+ import { parseAddress } from "../parsers.js";
10
+ import { makeFuncName } from "../cmdgen.js";
11
+ const abiFuncs = getFuncs("ISetRegistry");
12
+ const abiFuncsAdmin = getFuncs("SetRegistryAdmin");
13
+ async function getAbc(conf, client,
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ args, id, altFuncName
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ ) {
18
+ if (id >= 17) {
19
+ const addr = await getSetContract(id, client, conf);
20
+ return [addr, args, undefined];
21
+ }
22
+ else {
23
+ const abiFunc = abiFuncs.filter((i) => i.name == altFuncName)[0];
24
+ return [conf.contracts.SetRegistry, args, abiFunc];
25
+ }
26
+ }
27
+ const cmdConfig = {
28
+ descs: {
29
+ upgradeSet: "Upgrade an existing set",
30
+ },
31
+ params: {
32
+ ".rev0": () => new Option(`--rev <rev0>`).default(0),
33
+ ".krev0": () => new Option(`--krev <rev0>`).default(0),
34
+ ".krev": () => new Option(`--krev <rev0>`).default(0),
35
+ ".srev0": () => new Option(`--srev <rev0>`).default(0),
36
+ ".srev": () => new Option(`--srev <rev0>`).default(0),
37
+ ".kindRev": () => new Option(`--krev <rev0>`).default(0),
38
+ ".setRev": () => new Option(`--srev <rev0>`).default(0),
39
+ ".kindRev0": () => new Option(`--krev <rev0>`, "New kind revision").default(0),
40
+ ".setRev0": () => new Option(`--srev <rev0>`, "New set revision").default(0),
41
+ "registerSet.PREPEND": () => new Argument(`<contract>`, "Contract address").argParser(parseAddress),
42
+ },
28
43
  // eslint-disable-next-line
29
- getContract: (conf, args, abiFunc) => conf.contracts.SetRegistry,
44
+ prepare: async (conf, client, args, funcName) => {
45
+ if (funcName == "registerSet") {
46
+ return [args[0], args.slice(1), undefined];
47
+ }
48
+ else if (funcName == "updateSet") {
49
+ return await getAbc(conf, client, args, args[0], "setUpdate");
50
+ }
51
+ else if (funcName == "upgradeSet") {
52
+ return await getAbc(conf, client, args, args[0], "setUpgrade");
53
+ }
54
+ else if (funcName == "touchSet") {
55
+ return await getAbc(conf, client, args, args[0], "setTouch");
56
+ }
57
+ else {
58
+ return [conf.contracts.SetRegistry, args, undefined];
59
+ }
60
+ },
30
61
  };
31
- const userCmds = "owner,descriptor,snapshot".split(",");
32
- const adminCmds = "register,update,upgrade,touch".split(",");
62
+ const adminCmds = "register,update,upgrade,touch".split(",").map((name) => {
63
+ const funcName = `${name}Set`;
64
+ const abiFunc = abiFuncsAdmin.filter((i) => i.name == funcName)[0];
65
+ return genAbiCommand(name, abiFunc, cmdConfig);
66
+ });
67
+ const readCmds = "owner,descriptor,snapshot".split(",").map((name) => {
68
+ const funcName = makeFuncName(name, "set");
69
+ const abiFunc = abiFuncs.filter((i) => i.name == funcName)[0];
70
+ return genAbiCommand(name, abiFunc, cmdConfig);
71
+ });
33
72
  const deployCmd = genDeployCmd();
34
73
  export const setCmd = new Command("set")
35
74
  .description("manage sets")
36
75
  .addCommand(deployCmd)
37
- .addCommands(adminCmds.map(getCommandGen(adminCmdConfig)))
38
- .addCommands(userCmds.map(getCommandGen(userCmdConfig)));
76
+ // .addCommands(adminCmds.map(getCommandGen(adminCmdConfig)))
77
+ .addCommands(adminCmds)
78
+ .addCommands(readCmds);
39
79
  function genDeployCmd() {
40
80
  const cmdArgs = [
41
81
  new Argument(`<artifact>`, "Artifact path of the contract"),
@@ -51,7 +91,7 @@ function genDeployCmd() {
51
91
  const artifactInfo = getArtifactPath(cmd.args[0], opts.artifactDir);
52
92
  const userArgs = cmd.args.slice(1);
53
93
  const artifact = loadJson(artifactInfo.file);
54
- const abi = getAbi(artifact);
94
+ const abi = getAbiFromArtifact(artifact);
55
95
  const bytecode = getCreationCode(artifact);
56
96
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
97
  const ctor = abi.find((i) => i.type === "constructor");
@@ -104,8 +144,18 @@ function genDeployCmd() {
104
144
  console.result(result);
105
145
  }
106
146
  return new Command("deploy")
107
- .description("Deploy a contract")
147
+ .description("Deploy a set contract")
108
148
  .addOptions(cmdOpts)
109
149
  .addArguments(cmdArgs)
110
150
  .action(action);
111
151
  }
152
+ async function getSetContract(set, publicClient, conf) {
153
+ const abi = getAbi("ISetRegistry");
154
+ const address = await publicClient.readContract({
155
+ address: conf.contracts.SetRegistry,
156
+ abi,
157
+ functionName: "setContract",
158
+ args: [set],
159
+ });
160
+ return address;
161
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@everyprotocol/every-cli",
3
3
  "type": "module",
4
- "version": "0.1.16",
4
+ "version": "0.1.18",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/everyprotocol/cli.git"
@@ -9,6 +9,7 @@
9
9
  "files": [
10
10
  "dist/",
11
11
  "abis/",
12
+ "abis2/",
12
13
  ".every.toml",
13
14
  "LICENSE",
14
15
  "README.md"