@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/cmds/object.js
CHANGED
|
@@ -1,175 +1,348 @@
|
|
|
1
|
-
import { Argument, Command } from "commander";
|
|
2
|
-
import {
|
|
3
|
-
import { parseAbiItem
|
|
4
|
-
import {
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
.
|
|
81
|
-
.addCommand(
|
|
82
|
-
.addCommand(
|
|
83
|
-
.addCommand(
|
|
84
|
-
.addCommand(
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
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
|
-
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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: [
|
|
164
|
-
})
|
|
165
|
-
|
|
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 {
|
|
5
|
+
import { getAbiFromArtifact, getArtifactPath, getCreationCode } from "../artifact.js";
|
|
8
6
|
import { Logger } from "../logger.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
|
32
|
-
const
|
|
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(
|
|
76
|
+
// .addCommands(adminCmds.map(getCommandGen(adminCmdConfig)))
|
|
77
|
+
.addCommands(adminCmds)
|
|
78
|
+
.addCommands(readCmds);
|
|
39
79
|
function genDeployCmd() {
|
|
40
|
-
const
|
|
41
|
-
new Argument(`<
|
|
80
|
+
const cmdArgs = [
|
|
81
|
+
new Argument(`<artifact>`, "Artifact path of the contract"),
|
|
42
82
|
new Argument(`[args...]`, "Constructor arguments"),
|
|
43
83
|
];
|
|
44
|
-
const
|
|
45
|
-
new Option("
|
|
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 =
|
|
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(
|
|
109
|
-
.addArguments(
|
|
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
|
+
}
|