@everyprotocol/every-cli 0.1.3 → 0.1.5
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/.every.toml +6 -6
- package/dist/abi.js +1 -0
- package/dist/cmdgen.js +51 -139
- package/dist/cmds/balance.js +43 -0
- package/dist/cmds/config.js +46 -0
- package/dist/cmds/kind.js +14 -0
- package/dist/cmds/matter.js +432 -0
- package/dist/cmds/minter.js +31 -0
- package/dist/cmds/object.js +175 -0
- package/dist/cmds/relation.js +16 -0
- package/dist/cmds/set.js +31 -0
- package/dist/cmds/unique.js +14 -0
- package/dist/cmds/universe.js +21 -0
- package/dist/cmds/value.js +14 -0
- package/dist/{wallet.js → cmds/wallet.js} +19 -19
- package/dist/commander-patch.js +64 -0
- package/dist/config.js +18 -93
- package/dist/ethereum.js +33 -0
- package/dist/from-opts.js +161 -0
- package/dist/index.js +3 -2
- package/dist/logger.js +39 -0
- package/dist/parsers.js +70 -0
- package/dist/program.js +28 -39
- package/dist/substrate.js +24 -18
- package/dist/utils.js +131 -184
- package/package.json +5 -1
- package/dist/cmds.js +0 -132
- package/dist/matter.js +0 -96
- package/dist/mint.js +0 -78
- package/dist/options.js +0 -26
- package/dist/relate.js +0 -104
package/.every.toml
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[universes.anvil]
|
|
2
2
|
id = 31337
|
|
3
|
-
rpc = "http://
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
rpc = "http://localhost:8545"
|
|
4
|
+
observer = "dev"
|
|
5
|
+
explorer = "http://localhost"
|
|
6
6
|
|
|
7
7
|
[universes.anvil.contracts]
|
|
8
8
|
SetRegistry = "0x854C35Fd2b65fE9fcE71dddE91De8c3e1A7Dc8Ae"
|
|
@@ -11,7 +11,7 @@ KindRegistry = "0x7A8B3E5A9c227858C5917b7de8ba1684Cd868630"
|
|
|
11
11
|
ElementRegistry = "0x8De1EE1dbAE2Ffd1CAe1e6bA83E6cAede1461507"
|
|
12
12
|
ObjectMinter = "0x12CaBC370b316F247126F3Fab529Ee25e03aE226"
|
|
13
13
|
|
|
14
|
-
[observers.
|
|
14
|
+
[observers.dev]
|
|
15
15
|
rpc = "ws://localhost:9944"
|
|
16
|
-
gateway = "http://every.
|
|
17
|
-
explorer = "
|
|
16
|
+
gateway = "http://every.lo"
|
|
17
|
+
explorer = "https://portal.every.fun/?rpc=ws://localhost:9944#/explorer"
|
package/dist/abi.js
CHANGED
|
@@ -11,6 +11,7 @@ export const abi = {
|
|
|
11
11
|
omniRegistry: loadNonFuncAbiItems("OmniRegistry"),
|
|
12
12
|
kindRegistry: loadNonFuncAbiItems("KindRegistry"),
|
|
13
13
|
setRegistry: loadNonFuncAbiItems("SetRegistry"),
|
|
14
|
+
setContract: loadNonFuncAbiItems("ISet"),
|
|
14
15
|
},
|
|
15
16
|
funcs: {
|
|
16
17
|
kindRegistry: loadFuncAbiItems("IKindRegistry"),
|
package/dist/cmdgen.js
CHANGED
|
@@ -1,144 +1,56 @@
|
|
|
1
|
+
import { Argument, Command } from "commander";
|
|
1
2
|
import { createPublicClient, http } from "viem";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const relation = abi.funcs.omniRegistry
|
|
19
|
-
.filter(startsWith("relation"))
|
|
20
|
-
.map(AbiToCommand({
|
|
21
|
-
contract: "OmniRegistry",
|
|
22
|
-
nonFuncs: abi.nonFuncs.omniRegistry,
|
|
23
|
-
cmdName: lstrip("relation"),
|
|
24
|
-
}))
|
|
25
|
-
.sort(byPreferredOrder);
|
|
26
|
-
const unique = abi.funcs.elemRegistry
|
|
27
|
-
.filter(startsWith("unique"))
|
|
28
|
-
.map(AbiToCommand({ contract: "ElementRegistry", nonFuncs: abi.nonFuncs.elemRegistry, cmdName: lstrip("unique") }))
|
|
29
|
-
.sort(byPreferredOrder);
|
|
30
|
-
const value = abi.funcs.elemRegistry
|
|
31
|
-
.filter(startsWith("value"))
|
|
32
|
-
.map(AbiToCommand({ contract: "ElementRegistry", nonFuncs: abi.nonFuncs.elemRegistry, cmdName: lstrip("value") }))
|
|
33
|
-
.sort(byPreferredOrder);
|
|
34
|
-
const object = [
|
|
35
|
-
genMintCommand(),
|
|
36
|
-
genRelateCommand(),
|
|
37
|
-
genUnrelateCommand(),
|
|
38
|
-
// write functions
|
|
39
|
-
...abi.funcs.setContract
|
|
40
|
-
.filter(includes("update,upgrade,touch,transfer".split(",")))
|
|
41
|
-
.map(AbiToCommand(setContractObjectCmdConfig)),
|
|
42
|
-
// read functions
|
|
43
|
-
...abi.funcs.setContract
|
|
44
|
-
.filter(excludes("update,upgrade,touch,transfer,uri,supportsInterface".split(",")))
|
|
45
|
-
.map(AbiToCommand(setContractObjectCmdConfig)),
|
|
46
|
-
...abi.funcs.setContract
|
|
47
|
-
.filter(includes("uri".split(",")))
|
|
48
|
-
.map(AbiToCommand({ ...setContractObjectCmdConfig, txnPrepare: objectUriTxnPrepare })),
|
|
49
|
-
].sort(byPreferredOrder);
|
|
50
|
-
const mintpolicy = [
|
|
51
|
-
...abi.funcs.objectMinterAdmin.map(AbiToCommand(objectMinterAdminCmdConfig)),
|
|
52
|
-
...abi.funcs.objectMinter
|
|
53
|
-
.filter(startsWith("mintPolicy"))
|
|
54
|
-
.filter(excludes("mintPolicyAdd,mintPolicyEnable,mintPolicyDisable".split(",")))
|
|
55
|
-
.map(AbiToCommand({ contract: "ObjectMinter", nonFuncs: abi.nonFuncs.objectMinter, cmdName: lstrip("mintPolicy") })),
|
|
56
|
-
].sort(byPreferredOrder);
|
|
57
|
-
return { kind, set, relation, unique, value, mintpolicy, object };
|
|
58
|
-
}
|
|
59
|
-
const setContractObjectCmdConfig = {
|
|
60
|
-
contract: "ISet",
|
|
61
|
-
nonFuncs: [],
|
|
62
|
-
cmdAbi: function (txnAbi) {
|
|
63
|
-
return replaceAbiParamAt(txnAbi, 0, {
|
|
64
|
-
name: "sid",
|
|
65
|
-
type: "string",
|
|
66
|
-
doc: "Scoped Object ID (in form of set.id, e.g., 17.1)",
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
txnPrepare: async function (ctx) {
|
|
71
|
-
const rawArgs = checkArguments(ctx.cmd.args, ctx.cmdAbi);
|
|
72
|
-
const [set, id] = rawArgs[0].split(".");
|
|
73
|
-
const args = [JSON5.parse(id), ...rawArgs.slice(1)];
|
|
74
|
-
const publicClient = createPublicClient({ transport: http(ctx.conf.rpc) });
|
|
75
|
-
const address = (await publicClient.readContract({
|
|
76
|
-
address: ctx.conf.contracts["SetRegistry"],
|
|
77
|
-
abi: abi.setContract,
|
|
78
|
-
functionName: "setContract",
|
|
79
|
-
args: [set],
|
|
80
|
-
}));
|
|
81
|
-
return { address: address, tag: ctx.contract, args };
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
const objectUriTxnPrepare = async function (ctx) {
|
|
85
|
-
const rawArgs = checkArguments(ctx.cmd.args, ctx.cmdAbi);
|
|
86
|
-
// const [set, id] = rawArgs[0].split(".");
|
|
87
|
-
const set = rawArgs[0].split(".")[0];
|
|
88
|
-
const publicClient = createPublicClient({ transport: http(ctx.conf.rpc) });
|
|
89
|
-
const address = (await publicClient.readContract({
|
|
90
|
-
address: ctx.conf.contracts["SetRegistry"],
|
|
91
|
-
abi: abi.setContract,
|
|
92
|
-
functionName: "setContract",
|
|
93
|
-
args: [set],
|
|
94
|
-
}));
|
|
95
|
-
return { address: address, tag: ctx.contract, args: [] };
|
|
3
|
+
import { submitSimulation } from "./ethereum.js";
|
|
4
|
+
import { Logger } from "./logger.js";
|
|
5
|
+
import { outputOptions, universe, writeOptions } from "./commander-patch.js";
|
|
6
|
+
import { FromOpts } from "./from-opts.js";
|
|
7
|
+
import { coerceValue } from "./utils.js";
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const getReadAction = (config, funName, abiFunc, abi) => async function readAction() {
|
|
10
|
+
const opts = this.opts();
|
|
11
|
+
const conf = FromOpts.getUniverseConfig(opts);
|
|
12
|
+
const address = await config.getContract(conf, this.processedArgs, abiFunc);
|
|
13
|
+
const args = (config.getFuncArgs ?? CommandGenDefaults.getFuncArgs)(this.processedArgs, abiFunc);
|
|
14
|
+
const console = new Logger(opts);
|
|
15
|
+
const publicClient = createPublicClient({ transport: http(conf.rpc) });
|
|
16
|
+
const result = await publicClient.readContract({ address, abi, functionName: funName, args });
|
|
17
|
+
console.log(result);
|
|
18
|
+
console.result(result);
|
|
96
19
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
|
-
txnPrepare: async function (ctx) {
|
|
110
|
-
const raw = checkArguments(ctx.cmd.args, ctx.cmdAbi);
|
|
111
|
-
const address = raw[0];
|
|
112
|
-
const args = raw.slice(1);
|
|
113
|
-
return { address, tag: ctx.contract, args };
|
|
114
|
-
},
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
const getWriteAction = (config, funcName, abiFunc, abi) => async function writeAction() {
|
|
22
|
+
const opts = this.opts();
|
|
23
|
+
const args = (config.getFuncArgs ?? CommandGenDefaults.getFuncArgs)(this.args, abiFunc);
|
|
24
|
+
const { publicClient, walletClient, conf } = await FromOpts.toWriteEthereum(opts);
|
|
25
|
+
const address = config.getContract(conf, this.args, abiFunc);
|
|
26
|
+
const account = walletClient.account;
|
|
27
|
+
const simulation = { address, abi, functionName: funcName, args, account };
|
|
28
|
+
await submitSimulation(simulation, publicClient, walletClient, new Logger(opts));
|
|
115
29
|
};
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
},
|
|
30
|
+
export const getCommandGen = (config) => function genCmd(cmdName) {
|
|
31
|
+
const { getFuncName, getAbiFuncs, getAbiNonFuncs } = config;
|
|
32
|
+
const funcName = getFuncName(cmdName);
|
|
33
|
+
const abiFuncs = getAbiFuncs(funcName);
|
|
34
|
+
const abiNonFuncs = getAbiNonFuncs(funcName);
|
|
35
|
+
// console.log(funcName, abiFuncs);
|
|
36
|
+
const abiFuncDoc = abiFuncs[0];
|
|
37
|
+
const description = abiFuncDoc._metadata?.notice || "";
|
|
38
|
+
const isRead = abiFuncDoc.stateMutability == "view" || abiFuncDoc.stateMutability == "pure";
|
|
39
|
+
const options = isRead ? [universe, ...outputOptions] : [...writeOptions, ...outputOptions];
|
|
40
|
+
const args = (config.getCmdArgs ?? CommandGenDefaults.getCmdArgs)(abiFuncDoc);
|
|
41
|
+
const abiContract = [...abiFuncs, ...abiNonFuncs];
|
|
42
|
+
const action = isRead
|
|
43
|
+
? getReadAction(config, funcName, abiFuncDoc, abiContract)
|
|
44
|
+
: getWriteAction(config, funcName, abiFuncDoc, abiContract);
|
|
45
|
+
return new Command(cmdName).description(description).addOptions(options).addArguments(args).action(action);
|
|
133
46
|
};
|
|
134
|
-
function
|
|
135
|
-
return (
|
|
136
|
-
}
|
|
137
|
-
function byPreferredOrder(a, b) {
|
|
138
|
-
const ORDER_MAP = new Map("mint,register,update,upgrade,touch,transfer,relate,unrelate,owner,descriptor,elements,revision,sota,snapshot,status,admint,contract,rule,uri"
|
|
139
|
-
.split(",")
|
|
140
|
-
.map((name, index) => [name, index]));
|
|
141
|
-
const aIndex = ORDER_MAP.get(a.name()) ?? Infinity;
|
|
142
|
-
const bIndex = ORDER_MAP.get(b.name()) ?? Infinity;
|
|
143
|
-
return aIndex - bIndex;
|
|
47
|
+
export function makeFuncName(cmdName, prefix) {
|
|
48
|
+
return `${prefix}${cmdName[0].toUpperCase()}${cmdName.slice(1)}`;
|
|
144
49
|
}
|
|
50
|
+
export const CommandGenDefaults = {
|
|
51
|
+
getFuncArgs: (args, abiFunc) => args.map((arg, i) => coerceValue(arg, abiFunc.inputs[i])),
|
|
52
|
+
getCmdArgs: (abiFunc) => abiFunc.inputs.map((input) => {
|
|
53
|
+
const desc = abiFunc._metadata?.params?.[input.name] || `${input.type} parameter`;
|
|
54
|
+
return new Argument(`<${input.name}>`, desc);
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import "@polkadot/api-augment/substrate";
|
|
3
|
+
import * as JSON11 from "json11";
|
|
4
|
+
import columify from "columnify";
|
|
5
|
+
import { u8aFixLength } from "@polkadot/util";
|
|
6
|
+
import { decodeAddress } from "@polkadot/util-crypto";
|
|
7
|
+
import { submitSubTxUI } from "../substrate.js";
|
|
8
|
+
import { network } from "../commander-patch.js";
|
|
9
|
+
import { Logger } from "../logger.js";
|
|
10
|
+
const balanceQueryCmd = new Command("query")
|
|
11
|
+
.description("Query account balance")
|
|
12
|
+
.argument("<address>", "Account address (SS58 or 0x hex)")
|
|
13
|
+
.addOption(network)
|
|
14
|
+
.addOutputOptions()
|
|
15
|
+
.subReadAction(async function (api, address) {
|
|
16
|
+
const accountId = u8aFixLength(decodeAddress(address), 256);
|
|
17
|
+
const accountInfo = (await api.query.system.account(accountId));
|
|
18
|
+
const symbol = api.registry.chainTokens[0];
|
|
19
|
+
const free = accountInfo.data.free.toBigInt();
|
|
20
|
+
const reserved = accountInfo.data.reserved.toBigInt();
|
|
21
|
+
const frozen = accountInfo.data.frozen.toBigInt();
|
|
22
|
+
const balance = { free, reserved, frozen };
|
|
23
|
+
const result = { address, symbol, balance };
|
|
24
|
+
const console = new Logger(this.opts());
|
|
25
|
+
console.log(columify([[symbol, JSON11.stringify(balance)]], { showHeaders: false }));
|
|
26
|
+
console.result(result);
|
|
27
|
+
});
|
|
28
|
+
const balanceTransferCmd = new Command("transfer")
|
|
29
|
+
.description("Transfer balance to account")
|
|
30
|
+
.argument("<address>", "Recipient account address (SS58 or 0x hex)")
|
|
31
|
+
.argument("<amount>", "Amount in base units")
|
|
32
|
+
.addOption(network)
|
|
33
|
+
.addKeystoreOptions()
|
|
34
|
+
.addOutputOptions()
|
|
35
|
+
.subWriteAction(async function (api, pair, address, amount) {
|
|
36
|
+
const tx = api.tx.balances.transferKeepAlive(address, amount);
|
|
37
|
+
const console = new Logger(this.opts());
|
|
38
|
+
await submitSubTxUI(api, tx, pair, console);
|
|
39
|
+
});
|
|
40
|
+
export const balanceCmd = new Command("balance")
|
|
41
|
+
.description("manage balances")
|
|
42
|
+
.addCommand(balanceQueryCmd)
|
|
43
|
+
.addCommand(balanceTransferCmd);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { _loadMergedConfig } from "../config.js";
|
|
3
|
+
const configShowCmd = new Command("show")
|
|
4
|
+
.description("show mreged configuration")
|
|
5
|
+
.option("-u, --universe <universe>", "Show config of this universe only")
|
|
6
|
+
.option("-n, --network <network>", "Show config of this network only")
|
|
7
|
+
.action(async (opts) => {
|
|
8
|
+
const [config] = _loadMergedConfig();
|
|
9
|
+
const universe = opts.universe
|
|
10
|
+
? (config.universes?.[opts.universe] ??
|
|
11
|
+
(() => {
|
|
12
|
+
throw new Error(`config for universe ${opts.universe} not found`);
|
|
13
|
+
})())
|
|
14
|
+
: undefined;
|
|
15
|
+
const network = opts.network
|
|
16
|
+
? (config.observers?.[opts.network] ??
|
|
17
|
+
(() => {
|
|
18
|
+
throw new Error(`config for network ${opts.network} not found`);
|
|
19
|
+
})())
|
|
20
|
+
: undefined;
|
|
21
|
+
let result;
|
|
22
|
+
if (universe && !network) {
|
|
23
|
+
result = universe;
|
|
24
|
+
}
|
|
25
|
+
else if (network && !universe) {
|
|
26
|
+
result = network;
|
|
27
|
+
}
|
|
28
|
+
else if (universe && network) {
|
|
29
|
+
result = {
|
|
30
|
+
[opts.universe]: universe,
|
|
31
|
+
[opts.network]: network,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
result = config;
|
|
36
|
+
}
|
|
37
|
+
console.log(JSON.stringify(result, null, 2));
|
|
38
|
+
});
|
|
39
|
+
const configFilesCmd = new Command("files").description("list configuration files searched").action(async () => {
|
|
40
|
+
const [, files] = _loadMergedConfig();
|
|
41
|
+
files.forEach((f) => console.log(f));
|
|
42
|
+
});
|
|
43
|
+
export const configCmd = new Command("config")
|
|
44
|
+
.description("view merged configuration and source files")
|
|
45
|
+
.addCommand(configShowCmd)
|
|
46
|
+
.addCommand(configFilesCmd);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { abi } from "../abi.js";
|
|
3
|
+
import { getCommandGen, makeFuncName } from "../cmdgen.js";
|
|
4
|
+
const cmdGenConfig = {
|
|
5
|
+
getFuncName: (cmdName) => makeFuncName(cmdName, `kind`),
|
|
6
|
+
getAbiFuncs: (funcName) => abi.funcs.kindRegistry.filter((i) => i.name == funcName),
|
|
7
|
+
// eslint-disable-next-line
|
|
8
|
+
getAbiNonFuncs: (funcName) => abi.nonFuncs.kindRegistry,
|
|
9
|
+
// eslint-disable-next-line
|
|
10
|
+
getContract: (conf, args, abiFunc) => conf.contracts.KindRegistry,
|
|
11
|
+
};
|
|
12
|
+
const cmdGen = getCommandGen(cmdGenConfig);
|
|
13
|
+
const subCmds = "register,upgrade,touch,transfer,owner,descriptor,snapshot".split(",");
|
|
14
|
+
export const kindCmd = new Command("kind").description("manage kinds").addCommands(subCmds.map(cmdGen));
|