@everyprotocol/every-cli 0.1.15 → 0.1.16

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/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
- mint: [
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
- create: [
38
- ...parseAbi(["function create(address to, uint64 id0, bytes calldata data) payable"]),
37
+ setMint: [
38
+ ...parseAbi(["function mint(address to, uint64 id0, bytes calldata data) payable"]),
39
39
  ...loadNonFuncAbiItems("ISet"),
40
40
  ],
41
41
  relation: [
@@ -1,175 +1,330 @@
1
- import { Argument, Command } from "commander";
2
- import { createPublicClient, http, parseUnits } from "viem";
1
+ import { Argument, Option, Command } from "commander";
3
2
  import { parseAbiItem, erc1155Abi, erc721Abi } from "viem";
4
3
  import { abi } from "../abi.js";
5
4
  import { submitSimulation } from "../ethereum.js";
6
5
  import { Logger } from "../logger.js";
7
- import { parseBigInt, parseNode3, parseNode4, parseSID } from "../parsers.js";
8
- import { CommandGenDefaults, getCommandGen } from "../cmdgen.js";
6
+ import { parseAddress, parseBigInt, parseEther, parseHexData, parseInt, parseNode3, parseNode4, parseSID, } from "../parsers.js";
9
7
  import { FromOpts } from "../from-opts.js";
10
8
  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(",");
9
+ import { outputOptions, universe as universeOption, writeOptions } from "../commander-patch.js";
10
+ const sidArg = new Argument("<sid>", "Object SID, in form of {set}.{id}").argParser(parseSID);
11
+ const tailArg = new Argument("<tail>", "Tail object, in form of [[data.]grant.]set.id").argParser(parseNode4);
12
+ const relArg = new Argument("<rel>", "Relation ID").argParser(parseBigInt);
13
+ const headArg = new Argument("<head>", "Head object, in form of [grant.]set.id").argParser(parseNode3);
78
14
  export const objectCmd = new Command("object")
79
15
  .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,
16
+ .addCommand(genMintCmd())
17
+ .addCommand(genUpgradeCmd())
18
+ .addCommand(genTouchCmd())
19
+ .addCommand(genTransferCmd())
20
+ .addCommand(genSendCmd())
21
+ .addCommand(genRelateCmd())
22
+ .addCommand(genUnrelateCmd())
23
+ .addCommand(genOwnerCmd())
24
+ .addCommand(genDescriptorCmd())
25
+ .addCommand(genSnapshotCmd())
26
+ .addCommand(genUriCmd());
27
+ function genUpgradeCmd() {
28
+ const cmdArgs = [sidArg];
29
+ const cmdOpts = [
30
+ new Option("--krev <rev>", "Upgrade kind to specified revison ").argParser(parseInt),
31
+ new Option("--srev <rev>", "Upgrade set to specified revison").argParser(parseInt),
32
+ ...writeOptions,
33
+ ...outputOptions,
34
+ ];
35
+ async function action() {
36
+ const opts = this.opts();
37
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
38
+ const { set, id } = this.processedArgs[0];
39
+ const address = await getSetContract(set, publicClient, conf);
40
+ const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
41
+ const functionName = "upgrade";
42
+ const args = [id, opts.krev ?? 0, opts.srev ?? 0];
43
+ const account = walletClient.account;
44
+ const simulation = { address, abi: abi_, functionName, args, account };
45
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
46
+ }
47
+ return new Command("upgrade")
48
+ .description("Upgrade an object")
49
+ .addArguments(cmdArgs)
50
+ .addOptions(cmdOpts)
51
+ .action(action);
52
+ }
53
+ function genTouchCmd() {
54
+ const cmdArgs = [sidArg];
55
+ const cmdOpts = [...writeOptions, ...outputOptions];
56
+ async function action() {
57
+ const opts = this.opts();
58
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
59
+ const { set, id } = this.processedArgs[0];
60
+ const address = await getSetContract(set, publicClient, conf);
61
+ const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
62
+ const functionName = "touch";
63
+ const args = [id];
64
+ const account = walletClient.account;
65
+ const simulation = { address, abi: abi_, functionName, args, account };
66
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
67
+ }
68
+ return new Command("touch").description("Touch an object").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
69
+ }
70
+ function genTransferCmd() {
71
+ const cmdArgs = [sidArg, new Argument("<to>", "Recipient address")];
72
+ const cmdOpts = [...writeOptions, ...outputOptions];
73
+ async function action() {
74
+ const opts = this.opts();
75
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
76
+ const { set, id } = this.processedArgs[0];
77
+ const address = await getSetContract(set, publicClient, conf);
78
+ const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
79
+ const functionName = "transfer";
80
+ const args = [id, this.processedArgs[1]];
81
+ const account = walletClient.account;
82
+ const simulation = { address, abi: abi_, functionName, args, account };
83
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
84
+ }
85
+ return new Command("transfer")
86
+ .description("Transfer an object")
87
+ .addArguments(cmdArgs)
88
+ .addOptions(cmdOpts)
89
+ .action(action);
90
+ }
91
+ function genMintCmd() {
92
+ const cmdArgs = [new Argument("<sid0>", "Object SID, in form of {set}.{id0}").argParser(parseSID)];
93
+ const cmdOpts = [
94
+ new Option("--to <address>", "Recipient address").argParser(parseAddress),
95
+ new Option("--data <data>", "Extra mint data").argParser(parseHexData),
96
+ new Option("--value <amount>", "Send an amount of ETH").argParser(parseEther),
97
+ new Option("--minter", "Via ObjectMinter instead"),
98
+ new Option("--policy <index>", "Index of the mint policy to search afterward").argParser(parseInt),
99
+ new Option("--auth <data>", "Authorization data for permission").argParser(parseHexData),
100
+ ...writeOptions,
101
+ ...outputOptions,
102
+ ];
103
+ async function action() {
104
+ const opts = this.opts();
105
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
106
+ const { set, id } = this.processedArgs[0];
107
+ const account = walletClient.account;
108
+ const to = opts.to ?? account?.address;
109
+ const value = opts.value ?? 0;
110
+ const data = opts.data ?? "0x";
111
+ const functionName = "mint";
112
+ let simulation;
113
+ if (!opts.minter) {
114
+ const address = await getSetContract(set, publicClient, conf);
115
+ const args = [to, id, data];
116
+ simulation = { address, abi: abi.setMint, functionName, args, value, account };
117
+ }
118
+ else {
119
+ const setAddress = await getSetContract(set, publicClient, conf);
120
+ const address = conf.contracts.ObjectMinter;
121
+ const authData = opts.auth ?? "0x";
122
+ const policy = opts.policy ?? 0;
123
+ const args = [to, setAddress, id, data, authData, policy];
124
+ simulation = { address, abi: abi.minterMint, functionName, args, value, account };
110
125
  }
111
- : {
112
- address: setContract,
113
- abi: abi.create,
114
- functionName: "create",
115
- args: [recipientAddress, BigInt(id), mintData],
126
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
127
+ }
128
+ return new Command("mint").description("Mint an object").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
129
+ }
130
+ function genSendCmd() {
131
+ const cmdArgs = [
132
+ new Argument("<sig>", "Signature, e.g. 'transfer(address,uint256)'"),
133
+ new Argument("[args...]", "Arguments"),
134
+ ];
135
+ const cmdOpts = [
136
+ new Option("--value <amount>", "the amount of ETH to send").argParser(parseEther),
137
+ ...writeOptions,
138
+ ...outputOptions,
139
+ ];
140
+ async function action() {
141
+ const opts = this.opts();
142
+ const sig = this.processedArgs[0];
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
+ const args0 = this.args.slice(0);
149
+ if (args0.length !== params.length)
150
+ throw new Error(`Invalid argument count: expected ${params.length}, got ${args0.length}`);
151
+ const sidPos = params.findIndex((p) => p.type == "uint64");
152
+ if (sidPos == -1)
153
+ throw new Error("No uint64 found in signature");
154
+ const { set, id } = parseSID(args0[sidPos]);
155
+ args0[sidPos] = id.toString();
156
+ const args = args0.map((a, i) => coerceValue(a, params[i]));
157
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
158
+ const address = await getSetContract(set, publicClient, conf);
159
+ const account = walletClient.account;
160
+ const value = opts.value ?? 0;
161
+ const simulation = {
162
+ address,
163
+ abi: [abiFunc, ...abi.nonFuncs.setContract, ...erc1155Abi, ...erc721Abi],
164
+ functionName: abiFunc.name,
165
+ args,
116
166
  account,
117
167
  value,
118
168
  };
119
- await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
169
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
170
+ }
171
+ return new Command("send")
172
+ .description("Send a transaction to set contract")
173
+ .addArguments(cmdArgs)
174
+ .addOptions(cmdOpts)
175
+ .action(action);
120
176
  }
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));
177
+ function genOwnerCmd() {
178
+ const cmdName = "owner";
179
+ const cmdArgs = [sidArg];
180
+ const cmdOpts = [universeOption, ...outputOptions];
181
+ async function action() {
182
+ const opts = this.opts();
183
+ const { set, id } = this.processedArgs[0];
184
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
185
+ const address = await getSetContract(set, publicClient, conf);
186
+ const args = [id];
187
+ const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
188
+ const result = await publicClient.readContract({ address, abi: abi_, functionName: cmdName, args });
189
+ const console = new Logger(opts);
190
+ console.log(result);
191
+ console.result(result);
192
+ }
193
+ return new Command("owner").description("Get object owner").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
194
+ }
195
+ function genDescriptorCmd() {
196
+ const cmdName = "descriptor";
197
+ const cmdArgs = [sidArg];
198
+ const cmdOpts = [
199
+ new Option("--rev <rev>", "At the specified revision").argParser(parseInt),
200
+ universeOption,
201
+ ...outputOptions,
202
+ ];
203
+ async function action() {
204
+ const opts = this.opts();
205
+ const { set, id } = this.processedArgs[0];
206
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
207
+ const address = await getSetContract(set, publicClient, conf);
208
+ 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 });
211
+ const console = new Logger(opts);
212
+ console.log(result);
213
+ console.result(result);
214
+ }
215
+ return new Command("descriptor")
216
+ .description("Get object descriptor")
217
+ .addArguments(cmdArgs)
218
+ .addOptions(cmdOpts)
219
+ .action(action);
220
+ }
221
+ function genSnapshotCmd() {
222
+ const cmdName = "snapshot";
223
+ const cmdArgs = [sidArg];
224
+ const cmdOpts = [
225
+ new Option("--rev <rev>", "At the specified revision").argParser(parseInt),
226
+ universeOption,
227
+ ...outputOptions,
228
+ ];
229
+ async function action() {
230
+ const opts = this.opts();
231
+ const { set, id } = this.processedArgs[0];
232
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
233
+ const address = await getSetContract(set, publicClient, conf);
234
+ 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 });
237
+ const console = new Logger(opts);
238
+ console.log(result);
239
+ console.result(result);
240
+ }
241
+ return new Command("snapshot")
242
+ .description("Get object snapshot")
243
+ .addArguments(cmdArgs)
244
+ .addOptions(cmdOpts)
245
+ .action(action);
246
+ }
247
+ function genUriCmd() {
248
+ const cmdName = "uri";
249
+ const cmdArgs = [sidArg];
250
+ const cmdOpts = [
251
+ new Option("--rev <rev>", "At the specified revision").argParser(parseInt),
252
+ universeOption,
253
+ ...outputOptions,
254
+ ];
255
+ async function action() {
256
+ const opts = this.opts();
257
+ const { set, id } = this.processedArgs[0];
258
+ const { conf, publicClient } = FromOpts.toReadEthereum(opts);
259
+ const address = await getSetContract(set, publicClient, conf);
260
+ const args = []; // eslint-disable-line @typescript-eslint/no-explicit-any
261
+ const abi_ = [...abi.funcs.setContract, ...abi.nonFuncs.setContract];
262
+ const result0 = (await publicClient.readContract({
263
+ address,
264
+ abi: abi_,
265
+ functionName: cmdName,
266
+ args,
267
+ })); // eslint-disable-line @typescript-eslint/no-explicit-any
268
+ const result = opts.rev ? interpolate(result0, id, opts.rev) : result0;
269
+ const console = new Logger(opts);
270
+ console.log(result);
271
+ console.result(result);
272
+ }
273
+ return new Command("uri").description("Get object URI").addArguments(cmdArgs).addOptions(cmdOpts).action(action);
133
274
  }
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;
275
+ function genRelateCmd() {
276
+ const cmdArgs = [tailArg, relArg, headArg];
277
+ const cmdOpts = [...writeOptions, ...outputOptions];
278
+ async function action() {
279
+ const opts = this.opts();
280
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
281
+ const simulation = {
282
+ address: conf.contracts.OmniRegistry,
283
+ abi: abi.relation,
284
+ functionName: "relate",
285
+ args: this.processedArgs,
286
+ account: walletClient.account,
287
+ };
288
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
289
+ }
290
+ return new Command()
291
+ .name("relate")
292
+ .description("Link a tail object to a head object")
293
+ .addArguments(cmdArgs)
294
+ .addOptions(cmdOpts)
295
+ .action(action);
296
+ }
297
+ function genUnrelateCmd() {
298
+ const cmdArgs = [tailArg, relArg, headArg];
299
+ const cmdOpts = [...writeOptions, ...outputOptions];
300
+ async function action() {
301
+ const opts = this.opts();
302
+ const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
303
+ const simulation = {
304
+ address: conf.contracts.OmniRegistry,
305
+ abi: abi.relation,
306
+ functionName: "unrelate",
307
+ args: this.processedArgs,
308
+ account: walletClient.account,
309
+ };
310
+ await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
142
311
  }
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,
312
+ return new Command()
313
+ .name("unrelate")
314
+ .description("Unlink a tail object from a head object")
315
+ .addArguments(cmdArgs)
316
+ .addOptions(cmdOpts)
317
+ .action(action);
318
+ }
319
+ function interpolate(tmpl, id, rev) {
320
+ return tmpl.replace(/\{id\}/g, String(id)).replace(/\{rev\}/g, String(rev));
321
+ }
322
+ async function getSetContract(set, publicClient, conf) {
323
+ const address = await publicClient.readContract({
324
+ address: conf.contracts.SetRegistry,
325
+ abi: abi.setContract,
162
326
  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));
327
+ args: [set],
328
+ });
329
+ return address;
175
330
  }
package/dist/cmds/set.js CHANGED
@@ -37,12 +37,12 @@ export const setCmd = new Command("set")
37
37
  .addCommands(adminCmds.map(getCommandGen(adminCmdConfig)))
38
38
  .addCommands(userCmds.map(getCommandGen(userCmdConfig)));
39
39
  function genDeployCmd() {
40
- const args = [
41
- new Argument(`<contract>`, "Artifact ID of the contract"),
40
+ const cmdArgs = [
41
+ new Argument(`<artifact>`, "Artifact path of the contract"),
42
42
  new Argument(`[args...]`, "Constructor arguments"),
43
43
  ];
44
- const options = [
45
- new Option("--artifact-dir <dir>", "Artifact directory").default("./out"),
44
+ const cmdOpts = [
45
+ new Option("-o, --out <dir>", "Artifact output directory").default("./out"),
46
46
  ...writeOptions,
47
47
  ...outputOptions,
48
48
  ];
@@ -104,8 +104,8 @@ function genDeployCmd() {
104
104
  console.result(result);
105
105
  }
106
106
  return new Command("deploy")
107
- .description("Deploy a set contract")
108
- .addOptions(options)
109
- .addArguments(args)
107
+ .description("Deploy a contract")
108
+ .addOptions(cmdOpts)
109
+ .addArguments(cmdArgs)
110
110
  .action(action);
111
111
  }
package/dist/parsers.js CHANGED
@@ -1,12 +1,21 @@
1
1
  import { u8aFixLength } from "@polkadot/util";
2
2
  import { decodeAddress } from "@polkadot/util-crypto";
3
3
  import { InvalidArgumentError } from "commander";
4
+ import { getAddress, hexToBytes, isHex, parseUnits } from "viem";
4
5
  export function parseBigInt(arg) {
5
6
  try {
6
7
  return BigInt(arg);
7
8
  }
8
9
  catch (e /* eslint-disable-line */) {
9
- throw new InvalidArgumentError("invalid bigint");
10
+ throw new InvalidArgumentError("Invalid bigint");
11
+ }
12
+ }
13
+ export function parseInt(arg) {
14
+ try {
15
+ return Number.parseInt(arg);
16
+ }
17
+ catch (e /* eslint-disable-line */) {
18
+ throw new InvalidArgumentError("Invalid integer");
10
19
  }
11
20
  }
12
21
  export function parseSID(arg) {
@@ -17,16 +26,44 @@ export function parseSID(arg) {
17
26
  return { set, id };
18
27
  }
19
28
  catch (e /* eslint-disable-line */) {
20
- throw new InvalidArgumentError(`invalid SID: ${arg}`);
29
+ throw new InvalidArgumentError(`Invalid SID: ${arg}`);
30
+ }
31
+ }
32
+ export function parseEther(arg) {
33
+ try {
34
+ return parseUnits(arg, 18);
35
+ }
36
+ catch (e /* eslint-disable-line */) {
37
+ throw new InvalidArgumentError(`Invalid ether amount: ${arg}`);
21
38
  }
22
39
  }
23
- export function parseAccountId(address) {
40
+ export function parseAccountId(arg) {
24
41
  try {
25
- return u8aFixLength(decodeAddress(address), 256);
42
+ return u8aFixLength(decodeAddress(arg), 256);
26
43
  }
27
44
  catch (e /* eslint-disable-line */) {
28
- throw new InvalidArgumentError("invalid account ID");
45
+ throw new InvalidArgumentError("Invalid account ID");
46
+ }
47
+ }
48
+ export function parseAddress(arg) {
49
+ try {
50
+ return getAddress(arg);
51
+ }
52
+ catch (e /* eslint-disable-line */) {
53
+ throw new InvalidArgumentError("Invalid address");
54
+ }
55
+ }
56
+ export function parseBytes32(arg) {
57
+ if (isHex(arg, { strict: true }) && hexToBytes(arg).length == 32) {
58
+ return arg;
59
+ }
60
+ throw new InvalidArgumentError("Invalid bytes32");
61
+ }
62
+ export function parseHexData(arg) {
63
+ if (isHex(arg, { strict: true })) {
64
+ return arg;
29
65
  }
66
+ throw new InvalidArgumentError("Invalid hex data");
30
67
  }
31
68
  export function parseNode4(arg) {
32
69
  const parts = arg.split(".");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@everyprotocol/every-cli",
3
3
  "type": "module",
4
- "version": "0.1.15",
4
+ "version": "0.1.16",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/everyprotocol/cli.git"