@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.
@@ -1,175 +1,348 @@
1
- import { Argument, Command } from "commander";
2
- import { createPublicClient, http, parseUnits } from "viem";
3
- import { parseAbiItem, erc1155Abi, erc721Abi } from "viem";
4
- import { abi } from "../abi.js";
1
+ import { Argument, Option, Command } from "commander";
2
+ import { parseAbi } from "viem";
3
+ import { parseAbiItem } from "viem";
4
+ import { getAbi, getNonFuncs } from "../abi2.js";
5
5
  import { submitSimulation } from "../ethereum.js";
6
6
  import { Logger } from "../logger.js";
7
- import { parseBigInt, parseNode3, parseNode4, parseSID } from "../parsers.js";
8
- import { CommandGenDefaults, getCommandGen } from "../cmdgen.js";
7
+ import { parseAddress, parseBigInt, parseEther, parseHexData, parseInt, parseNode3, parseNode4, parseSID, } from "../parsers.js";
9
8
  import { FromOpts } from "../from-opts.js";
10
9
  import { coerceValue } from "../utils.js";
11
- const objectRelateCmd = new Command()
12
- .name("relate")
13
- .description("Link a tail object to a head object through a relation")
14
- .addWriteOptions()
15
- .argument("<tail>", "tail node, in form of [[data.]grant.]set.id", parseNode4)
16
- .argument("<rel>", "relation ID", parseBigInt)
17
- .argument("<head>", "head node in form of [grant.]set.id, ", parseNode3)
18
- .action(async function () {
19
- await relateAction(this, "relate");
20
- });
21
- const objectUnrelateCmd = new Command()
22
- .name("unrelate")
23
- .description("Unlinks a tail object from a head object")
24
- .addWriteOptions()
25
- .argument("<tail>", "tail node, in form of [[data.]grant.]set.id", parseNode4)
26
- .argument("<rel>", "relation ID", parseBigInt)
27
- .argument("<head>", "head node in form of [grant.]set.id, ", parseNode3)
28
- .action(async function () {
29
- await relateAction(this, "unrelate");
30
- });
31
- const objectMintCmd = new Command()
32
- .name("mint")
33
- .description("Mint an object via the object minter or directly from the set")
34
- .option("--to <address>", "specify the recipient")
35
- .option("--value <amount>", "the amount of ETH to send together", "0")
36
- .option("--auth <data>", "authorization data for a permissioned mint", "0x")
37
- .option("--policy <index>", "the index number of the mint policy", "0")
38
- .option("--no-minter", "mint directly from set contract instead of using ObjectMinter")
39
- .addWriteOptions()
40
- .argument("<sid>", "scoped object ID, in form of set.id (e.g., 17.1)")
41
- .argument("[data]", "additional input data", "0x")
42
- .action(mintAction);
43
- const objectSendCmd = new Command("send")
44
- .description("Call a function by signature (dry-run: prints calldata)")
45
- .option("--sig <sig>", "Function signature, e.g. 'transfer(address,uint256)'")
46
- .argument("<args...>", "Function arguments (arrays/tuples as JSON)")
47
- .addWriteOptions()
48
- .action(sendAction);
49
- const cmdGenConfig = {
50
- getFuncName: (cmdName) => cmdName,
51
- getAbiFuncs: (funcName) => abi.funcs.setContract.filter((i) => i.name == funcName),
52
- // eslint-disable-next-line
53
- getAbiNonFuncs: (funcName) => [...abi.nonFuncs.setContract],
54
- // eslint-disable-next-line
55
- getContract: async function (conf, args, abiFunc) {
56
- const publicClient = createPublicClient({ transport: http(conf.rpc) });
57
- const address = await publicClient.readContract({
58
- address: conf.contracts.SetRegistry,
59
- abi: abi.setContract,
60
- functionName: "setContract",
61
- args: [args[0].set],
62
- });
63
- return address;
64
- },
65
- // eslint-disable-next-line
66
- getFuncArgs: function (args, abiFunc) {
67
- return abiFunc.name == "uri" ? args.slice(1) : [args[0].id, ...args.slice(1)];
68
- },
69
- getCmdArgs: function (abiFunc) {
70
- const sid = new Argument(`<sid>`, "sid of the object").argParser(parseSID);
71
- const args0 = CommandGenDefaults.getCmdArgs(abiFunc);
72
- return abiFunc.name == "uri" ? [sid] : [sid, ...args0.slice(1)];
73
- },
74
- };
75
- const cmdGen = getCommandGen(cmdGenConfig);
76
- const writeCmds = "upgrade,touch,transfer".split(",");
77
- const readCmds = "owner,descriptor,snapshot,uri".split(",");
10
+ import { outputOptions, universe as universeOption, writeOptions } from "../commander-patch.js";
11
+ const sidArg = new Argument("<sid>", "Object SID, in form of {set}.{id}").argParser(parseSID);
12
+ const tailArg = new Argument("<tail>", "Tail object, in form of [[data.]grant.]set.id").argParser(parseNode4);
13
+ const relArg = new Argument("<rel>", "Relation ID").argParser(parseBigInt);
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
+ ];
78
24
  export const objectCmd = new Command("object")
79
25
  .description("manage objects")
80
- .addCommands(writeCmds.map(cmdGen))
81
- .addCommand(objectMintCmd)
82
- .addCommand(objectRelateCmd)
83
- .addCommand(objectUnrelateCmd)
84
- .addCommand(objectSendCmd)
85
- .addCommands(readCmds.map(cmdGen));
86
- async function mintAction() {
87
- const opts = this.opts();
88
- const args0 = this.args;
89
- const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
90
- const setRegistry = conf.contracts["SetRegistry"];
91
- const account = walletClient.account;
92
- const [set, id] = args0[0].split(".");
93
- const setContract = (await publicClient.readContract({
94
- address: setRegistry,
95
- abi: abi.setContract,
96
- functionName: "setContract",
97
- args: [BigInt(set)],
98
- }));
99
- const value = parseUnits(opts.value || "0", 18);
100
- const recipientAddress = (opts.to || account.address);
101
- const mintData = (args0[1] || "0x");
102
- const simulation = opts.minter
103
- ? {
104
- address: conf.contracts["ObjectMinter"],
105
- abi: abi.mint,
106
- functionName: "mint",
107
- args: [recipientAddress, setContract, BigInt(id), mintData, opts.auth || "0x", Number(opts.policy || "0")],
108
- account,
109
- value,
26
+ .addCommand(genMintCmd())
27
+ .addCommand(genUpgradeCmd())
28
+ .addCommand(genTouchCmd())
29
+ .addCommand(genTransferCmd())
30
+ .addCommand(genSendCmd())
31
+ .addCommand(genRelateCmd())
32
+ .addCommand(genUnrelateCmd())
33
+ .addCommand(genOwnerCmd())
34
+ .addCommand(genDescriptorCmd())
35
+ .addCommand(genSnapshotCmd())
36
+ .addCommand(genUriCmd());
37
+ function genUpgradeCmd() {
38
+ const cmdArgs = [sidArg];
39
+ const cmdOpts = [
40
+ new Option("--krev <rev>", "Upgrade kind to specified revison ").argParser(parseInt),
41
+ new Option("--srev <rev>", "Upgrade set to specified revison").argParser(parseInt),
42
+ ...writeOptions,
43
+ ...outputOptions,
44
+ ];
45
+ async function action() {
46
+ const opts = this.opts();
47
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
48
+ const { set, id } = this.processedArgs[0];
49
+ const address = await getSetContract(set, publicClient, conf);
50
+ const functionName = "upgrade";
51
+ const args = [id, opts.krev ?? 0, opts.srev ?? 0];
52
+ const account = walletClient.account;
53
+ const abi = getAbi("ISet");
54
+ const simulation = { address, abi, functionName, args, account };
55
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
56
+ }
57
+ return new Command("upgrade")
58
+ .description("Upgrade an object")
59
+ .addArguments(cmdArgs)
60
+ .addOptions(cmdOpts)
61
+ .action(action);
62
+ }
63
+ function genTouchCmd() {
64
+ const cmdArgs = [sidArg];
65
+ const cmdOpts = [...writeOptions, ...outputOptions];
66
+ async function action() {
67
+ const opts = this.opts();
68
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
69
+ const { set, id } = this.processedArgs[0];
70
+ const address = await getSetContract(set, publicClient, conf);
71
+ const functionName = "touch";
72
+ const args = [id];
73
+ const account = walletClient.account;
74
+ const abi = getAbi("ISet");
75
+ const simulation = { address, abi, functionName, args, account };
76
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
77
+ }
78
+ return new Command("touch").description("Touch an object").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
79
+ }
80
+ function genTransferCmd() {
81
+ const cmdArgs = [sidArg, new Argument("<to>", "Recipient address")];
82
+ const cmdOpts = [...writeOptions, ...outputOptions];
83
+ async function action() {
84
+ const opts = this.opts();
85
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
86
+ const { set, id } = this.processedArgs[0];
87
+ const address = await getSetContract(set, publicClient, conf);
88
+ const functionName = "transfer";
89
+ const args = [id, this.processedArgs[1]];
90
+ const account = walletClient.account;
91
+ const abi = getAbi("ISet");
92
+ const simulation = { address, abi, functionName, args, account };
93
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
94
+ }
95
+ return new Command("transfer")
96
+ .description("Transfer an object")
97
+ .addArguments(cmdArgs)
98
+ .addOptions(cmdOpts)
99
+ .action(action);
100
+ }
101
+ function genMintCmd() {
102
+ const cmdArgs = [new Argument("<sid0>", "Object SID, in form of {set}.{id0}").argParser(parseSID)];
103
+ const cmdOpts = [
104
+ new Option("--to <address>", "Recipient address").argParser(parseAddress),
105
+ new Option("--data <data>", "Extra mint data").argParser(parseHexData),
106
+ new Option("--value <amount>", "Send an amount of ETH").argParser(parseEther),
107
+ new Option("--minter", "Via ObjectMinter instead"),
108
+ new Option("--policy <index>", "Index of the mint policy to search afterward").argParser(parseInt),
109
+ new Option("--auth <data>", "Authorization data for permission").argParser(parseHexData),
110
+ ...writeOptions,
111
+ ...outputOptions,
112
+ ];
113
+ async function action() {
114
+ const opts = this.opts();
115
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
116
+ const { set, id } = this.processedArgs[0];
117
+ const account = walletClient.account;
118
+ const to = opts.to ?? account?.address;
119
+ const value = opts.value ?? 0;
120
+ const data = opts.data ?? "0x";
121
+ const functionName = "mint";
122
+ let simulation;
123
+ if (!opts.minter) {
124
+ const address = await getSetContract(set, publicClient, conf);
125
+ const args = [to, id, data];
126
+ simulation = { address, abi: otherAbi, functionName, args, value, account };
127
+ }
128
+ else {
129
+ const setAddress = await getSetContract(set, publicClient, conf);
130
+ const address = conf.contracts.ObjectMinter;
131
+ const authData = opts.auth ?? "0x";
132
+ const policy = opts.policy ?? 0;
133
+ const args = [to, setAddress, id, data, authData, policy];
134
+ simulation = {
135
+ address,
136
+ abi: otherAbi,
137
+ functionName,
138
+ args,
139
+ value,
140
+ account,
141
+ };
110
142
  }
111
- : {
112
- address: setContract,
113
- abi: abi.create,
114
- functionName: "create",
115
- args: [recipientAddress, BigInt(id), mintData],
143
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
144
+ }
145
+ return new Command("mint").description("Mint an object").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
146
+ }
147
+ function genSendCmd() {
148
+ const cmdArgs = [
149
+ new Argument("<sig>", "Signature, e.g. 'transfer(address,uint256)'"),
150
+ new Argument("[args...]", "Arguments"),
151
+ ];
152
+ const cmdOpts = [
153
+ new Option("--value <amount>", "the amount of ETH to send").argParser(parseEther),
154
+ ...writeOptions,
155
+ ...outputOptions,
156
+ ];
157
+ async function action() {
158
+ const opts = this.opts();
159
+ const sig = this.processedArgs[0];
160
+ const item = parseAbiItem(`function ${sig}`);
161
+ if (item.type !== "function")
162
+ throw new Error(`Not a function signature: ${sig}`);
163
+ const abiFunc = item;
164
+ const params = abiFunc.inputs ?? [];
165
+ const args0 = this.args.slice(1);
166
+ if (args0.length !== params.length)
167
+ throw new Error(`Invalid argument count: expected ${params.length}, got ${args0.length}`);
168
+ const sidPos = params.findIndex((p) => p.type == "uint64");
169
+ if (sidPos == -1)
170
+ throw new Error("No uint64 found in signature");
171
+ const { set, id } = parseSID(args0[sidPos]);
172
+ args0[sidPos] = id.toString();
173
+ const args = args0.map((a, i) => coerceValue(a, params[i]));
174
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
175
+ const address = await getSetContract(set, publicClient, conf);
176
+ const account = walletClient.account;
177
+ const value = opts.value ?? 0;
178
+ const simulation = {
179
+ address,
180
+ abi: [abiFunc, ...getNonFuncs()],
181
+ functionName: abiFunc.name,
182
+ args,
116
183
  account,
117
184
  value,
118
185
  };
119
- await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
186
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
187
+ }
188
+ return new Command("send")
189
+ .description("Send a transaction to set contract")
190
+ .addArguments(cmdArgs)
191
+ .addOptions(cmdOpts)
192
+ .action(action);
120
193
  }
121
- async function relateAction(cmd, functionName) {
122
- const opts = cmd.opts();
123
- const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
124
- const address = conf.contracts["OmniRegistry"];
125
- const simulation = {
126
- address,
127
- abi: abi.relation,
128
- functionName,
129
- args: cmd.args,
130
- account: walletClient.account,
131
- };
132
- await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
194
+ function genOwnerCmd() {
195
+ const cmdName = "owner";
196
+ const cmdArgs = [sidArg];
197
+ const cmdOpts = [universeOption, ...outputOptions];
198
+ async function action() {
199
+ const opts = this.opts();
200
+ const { set, id } = this.processedArgs[0];
201
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
202
+ const address = await getSetContract(set, publicClient, conf);
203
+ const args = [id];
204
+ const abi = getAbi("ISet");
205
+ const result = await publicClient.readContract({ address, abi, functionName: cmdName, args });
206
+ const console = new Logger(opts);
207
+ console.log(result);
208
+ console.result(result);
209
+ }
210
+ return new Command("owner").description("Get object owner").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
211
+ }
212
+ function genDescriptorCmd() {
213
+ const cmdName = "descriptor";
214
+ const cmdArgs = [sidArg];
215
+ const cmdOpts = [
216
+ new Option("--rev <rev>", "At the specified revision").argParser(parseInt),
217
+ universeOption,
218
+ ...outputOptions,
219
+ ];
220
+ async function action() {
221
+ const opts = this.opts();
222
+ const { set, id } = this.processedArgs[0];
223
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
224
+ const address = await getSetContract(set, publicClient, conf);
225
+ const args = [id, opts.rev ?? 0];
226
+ const abi = getAbi("ISet");
227
+ const result = await publicClient.readContract({ address, abi, functionName: cmdName, args });
228
+ const console = new Logger(opts);
229
+ console.log(result);
230
+ console.result(result);
231
+ }
232
+ return new Command("descriptor")
233
+ .description("Get object descriptor")
234
+ .addArguments(cmdArgs)
235
+ .addOptions(cmdOpts)
236
+ .action(action);
133
237
  }
134
- async function sendAction() {
135
- const opts = this.opts();
136
- const args0 = this.args;
137
- const { sig } = this.opts();
138
- if (!sig) {
139
- console.error("Error: --sig is required (e.g. --sig 'transfer(address,uint256)')");
140
- this.exitOverride();
141
- return;
238
+ function genSnapshotCmd() {
239
+ const cmdName = "snapshot";
240
+ const cmdArgs = [sidArg];
241
+ const cmdOpts = [
242
+ new Option("--rev <rev>", "At the specified revision").argParser(parseInt),
243
+ universeOption,
244
+ ...outputOptions,
245
+ ];
246
+ async function action() {
247
+ const opts = this.opts();
248
+ const { set, id } = this.processedArgs[0];
249
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
250
+ const address = await getSetContract(set, publicClient, conf);
251
+ const args = [id, opts.rev ?? 0];
252
+ const abi = getAbi("ISet");
253
+ const result = await publicClient.readContract({ address, abi, functionName: cmdName, args });
254
+ const console = new Logger(opts);
255
+ console.log(result);
256
+ console.result(result);
142
257
  }
143
- const item = parseAbiItem(`function ${sig}`);
144
- if (item.type !== "function")
145
- throw new Error(`Not a function signature: ${sig}`);
146
- const abiFunc = item;
147
- const params = abiFunc.inputs ?? [];
148
- if (args0.length !== params.length)
149
- throw new Error(`Argument count mismatch: expected ${params.length}, got ${args0.length}`);
150
- const sidIndex = params.findIndex((p) => p.type == "uint64");
151
- if (sidIndex == -1)
152
- throw new Error("SID type(uint64) not found in signature");
153
- const [setId, objectId] = args0[sidIndex].split(".");
154
- args0[sidIndex] = objectId;
155
- const args = args0.map((a, i) => coerceValue(a, params[i]));
156
- const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
157
- const setRegistry = conf.contracts["SetRegistry"];
158
- const account = walletClient.account;
159
- const setContract = (await publicClient.readContract({
160
- address: setRegistry,
161
- abi: abi.funcs.setRegistry,
258
+ return new Command("snapshot")
259
+ .description("Get object snapshot")
260
+ .addArguments(cmdArgs)
261
+ .addOptions(cmdOpts)
262
+ .action(action);
263
+ }
264
+ function genUriCmd() {
265
+ const cmdName = "uri";
266
+ const cmdArgs = [sidArg];
267
+ const cmdOpts = [
268
+ new Option("--rev <rev>", "At the specified revision").argParser(parseInt),
269
+ universeOption,
270
+ ...outputOptions,
271
+ ];
272
+ async function action() {
273
+ const opts = this.opts();
274
+ const { set, id } = this.processedArgs[0];
275
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
276
+ const address = await getSetContract(set, publicClient, conf);
277
+ const args = []; // eslint-disable-line @typescript-eslint/no-explicit-any
278
+ const abi = getAbi("ISet");
279
+ const result0 = (await publicClient.readContract({
280
+ address,
281
+ abi,
282
+ functionName: cmdName,
283
+ args,
284
+ })); // eslint-disable-line @typescript-eslint/no-explicit-any
285
+ const result = opts.rev ? interpolate(result0, id, opts.rev) : result0;
286
+ const console = new Logger(opts);
287
+ console.log(result);
288
+ console.result(result);
289
+ }
290
+ return new Command("uri").description("Get object URI").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
291
+ }
292
+ function genRelateCmd() {
293
+ const cmdArgs = [tailArg, relArg, headArg];
294
+ const cmdOpts = [...writeOptions, ...outputOptions];
295
+ async function action() {
296
+ const opts = this.opts();
297
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
298
+ const simulation = {
299
+ address: conf.contracts.OmniRegistry,
300
+ abi: otherAbi,
301
+ functionName: "relate",
302
+ args: this.processedArgs,
303
+ account: walletClient.account,
304
+ };
305
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
306
+ }
307
+ return new Command()
308
+ .name("relate")
309
+ .description("Link a tail object to a head object")
310
+ .addArguments(cmdArgs)
311
+ .addOptions(cmdOpts)
312
+ .action(action);
313
+ }
314
+ function genUnrelateCmd() {
315
+ const cmdArgs = [tailArg, relArg, headArg];
316
+ const cmdOpts = [...writeOptions, ...outputOptions];
317
+ async function action() {
318
+ const opts = this.opts();
319
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
320
+ const simulation = {
321
+ address: conf.contracts.OmniRegistry,
322
+ abi: otherAbi,
323
+ functionName: "unrelate",
324
+ args: this.processedArgs,
325
+ account: walletClient.account,
326
+ };
327
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
328
+ }
329
+ return new Command()
330
+ .name("unrelate")
331
+ .description("Unlink a tail object from a head object")
332
+ .addArguments(cmdArgs)
333
+ .addOptions(cmdOpts)
334
+ .action(action);
335
+ }
336
+ function interpolate(tmpl, id, rev) {
337
+ return tmpl.replace(/\{id\}/g, String(id)).replace(/\{rev\}/g, String(rev));
338
+ }
339
+ async function getSetContract(set, publicClient, conf) {
340
+ const abi = getAbi("ISetRegistry");
341
+ const address = await publicClient.readContract({
342
+ address: conf.contracts.SetRegistry,
343
+ abi,
162
344
  functionName: "setContract",
163
- args: [BigInt(setId)],
164
- }));
165
- const value = parseUnits(opts.value ?? "0", 18);
166
- const simulation = {
167
- address: setContract,
168
- abi: [abiFunc, ...abi.nonFuncs.setContract, ...erc1155Abi, ...erc721Abi],
169
- functionName: abiFunc.name,
170
- args: args,
171
- account,
172
- value,
173
- };
174
- await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
345
+ args: [set],
346
+ });
347
+ return address;
175
348
  }
package/dist/cmds/set.js CHANGED
@@ -1,48 +1,88 @@
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
- const args = [
41
- new Argument(`<contract>`, "Artifact ID of the contract"),
80
+ const cmdArgs = [
81
+ new Argument(`<artifact>`, "Artifact path of the contract"),
42
82
  new Argument(`[args...]`, "Constructor arguments"),
43
83
  ];
44
- const options = [
45
- new Option("--artifact-dir <dir>", "Artifact directory").default("./out"),
84
+ const cmdOpts = [
85
+ new Option("-o, --out <dir>", "Artifact output directory").default("./out"),
46
86
  ...writeOptions,
47
87
  ...outputOptions,
48
88
  ];
@@ -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");
@@ -105,7 +145,17 @@ function genDeployCmd() {
105
145
  }
106
146
  return new Command("deploy")
107
147
  .description("Deploy a set contract")
108
- .addOptions(options)
109
- .addArguments(args)
148
+ .addOptions(cmdOpts)
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
+ }