aavegotchi-cli 0.1.0

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.
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runBootstrapCommand = runBootstrapCommand;
4
+ const args_1 = require("../args");
5
+ const chains_1 = require("../chains");
6
+ const config_1 = require("../config");
7
+ const errors_1 = require("../errors");
8
+ const rpc_1 = require("../rpc");
9
+ const signer_1 = require("../signer");
10
+ function getRequiredProfileName(ctx) {
11
+ const fromFlag = (0, args_1.getFlagString)(ctx.args.flags, "profile");
12
+ const profile = fromFlag || ctx.globals.profile;
13
+ if (!profile) {
14
+ throw new errors_1.CliError("MISSING_PROFILE", "Bootstrap requires --profile <name>.", 2);
15
+ }
16
+ return profile;
17
+ }
18
+ function buildSignerConfig(ctx, signerInput) {
19
+ const signer = (0, signer_1.parseSigner)(signerInput);
20
+ if (signer.type === "remote") {
21
+ const address = (0, args_1.getFlagString)(ctx.args.flags, "signer-address");
22
+ const authEnvVar = (0, args_1.getFlagString)(ctx.args.flags, "signer-auth-env-var");
23
+ return {
24
+ ...signer,
25
+ ...(address ? { address: address } : {}),
26
+ ...(authEnvVar ? { authEnvVar } : {}),
27
+ };
28
+ }
29
+ if (signer.type === "ledger") {
30
+ const address = (0, args_1.getFlagString)(ctx.args.flags, "signer-address");
31
+ const bridgeCommandEnvVar = (0, args_1.getFlagString)(ctx.args.flags, "signer-bridge-env-var");
32
+ return {
33
+ ...signer,
34
+ ...(address ? { address: address } : {}),
35
+ ...(bridgeCommandEnvVar ? { bridgeCommandEnvVar } : {}),
36
+ };
37
+ }
38
+ return signer;
39
+ }
40
+ async function runBootstrapCommand(ctx) {
41
+ const profileName = getRequiredProfileName(ctx);
42
+ const chainInput = (0, args_1.getFlagString)(ctx.args.flags, "chain");
43
+ const rpcFlag = (0, args_1.getFlagString)(ctx.args.flags, "rpc-url");
44
+ const signerInput = (0, args_1.getFlagString)(ctx.args.flags, "signer") || "readonly";
45
+ const policyName = (0, args_1.getFlagString)(ctx.args.flags, "policy") || "default";
46
+ const skipSignerCheck = (0, args_1.getFlagBoolean)(ctx.args.flags, "skip-signer-check");
47
+ const chain = (0, chains_1.resolveChain)(chainInput);
48
+ const rpcUrl = (0, chains_1.resolveRpcUrl)(chain, rpcFlag);
49
+ const preflight = await (0, rpc_1.runRpcPreflight)(chain, rpcUrl);
50
+ const signer = buildSignerConfig(ctx, signerInput);
51
+ let signerSummary = {
52
+ signerType: signer.type,
53
+ backendStatus: "not-checked",
54
+ };
55
+ if (!skipSignerCheck) {
56
+ const signerRuntime = await (0, signer_1.resolveSignerRuntime)(signer, preflight.client, rpcUrl, (0, chains_1.toViemChain)(chain, rpcUrl));
57
+ signerSummary = signerRuntime.summary;
58
+ }
59
+ const now = new Date().toISOString();
60
+ const config = (0, config_1.loadConfig)();
61
+ const existingProfile = config.profiles[profileName];
62
+ const profile = {
63
+ name: profileName,
64
+ chain: chain.key,
65
+ chainId: preflight.chainId,
66
+ rpcUrl,
67
+ signer,
68
+ policy: policyName,
69
+ createdAt: existingProfile?.createdAt || now,
70
+ updatedAt: now,
71
+ };
72
+ const withProfile = (0, config_1.upsertProfile)(config, profile);
73
+ const withPolicy = withProfile.policies[policyName]
74
+ ? withProfile
75
+ : (0, config_1.upsertPolicy)(withProfile, (0, config_1.createDefaultPolicy)(policyName, now));
76
+ // Validate policy existence after potential creation.
77
+ (0, config_1.getPolicyOrThrow)(withPolicy, policyName);
78
+ const activated = (0, config_1.setActiveProfile)(withPolicy, profileName);
79
+ const configPath = (0, config_1.saveConfig)(activated);
80
+ return {
81
+ message: "Bootstrap completed.",
82
+ profile: {
83
+ name: profile.name,
84
+ chain: profile.chain,
85
+ chainId: profile.chainId,
86
+ rpcUrl: profile.rpcUrl,
87
+ signer: profile.signer,
88
+ policy: profile.policy,
89
+ },
90
+ rpc: {
91
+ blockNumber: preflight.blockNumber,
92
+ chainName: preflight.chainName,
93
+ },
94
+ signer: signerSummary,
95
+ configPath,
96
+ };
97
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeCommandPath = exports.executeCommand = void 0;
4
+ var command_runner_1 = require("../command-runner");
5
+ Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return command_runner_1.executeCommand; } });
6
+ Object.defineProperty(exports, "normalizeCommandPath", { enumerable: true, get: function () { return command_runner_1.normalizeCommandPath; } });
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findMappedFunction = findMappedFunction;
4
+ exports.listMappedCommandsForRoot = listMappedCommandsForRoot;
5
+ exports.runMappedDomainCommand = runMappedDomainCommand;
6
+ const errors_1 = require("../errors");
7
+ const onchain_1 = require("./onchain");
8
+ const MAPPED_WRITE_COMMANDS = {
9
+ "lending create": "addGotchiLending",
10
+ "lending agree": "agreeGotchiLending",
11
+ "token approve": "approve",
12
+ "gotchi xp claim-batch": "batchDropClaimXPDrop",
13
+ "baazaar listing batch-execute": "batchExecuteERC1155Listing",
14
+ "realm harvest batch": "batchHarvest",
15
+ "token bridge": "bridge",
16
+ "baazaar buy-now": "buyNow",
17
+ "auction buy-now": "buyNow",
18
+ "auction cancel": "cancelAuction",
19
+ "baazaar cancel-erc1155": "cancelERC1155Listing",
20
+ "baazaar cancel-erc721": "cancelERC721Listing",
21
+ "lending cancel": "cancelGotchiLending",
22
+ "forge claim": "claim",
23
+ "portal claim": "claimAavegotchi",
24
+ "lending claim-end": "claimAndEndGotchiLending",
25
+ "forge queue claim": "claimForgeQueueItems",
26
+ "auction bid": "commitBid",
27
+ "gotchi-points convert-alchemica": "convertAlchemica",
28
+ "auction create": "createAuction",
29
+ "lending whitelist create": "createWhitelist",
30
+ "staking unstake-destroy": "decreaseAndDestroy",
31
+ "staking enter-underlying": "enterWithUnderlying",
32
+ "gotchi equip-delegated": "equipDelegatedWearables",
33
+ "forge craft": "forgeWearables",
34
+ "staking leave-underlying": "leaveToUnderlying",
35
+ "portal open": "openPortals",
36
+ "forge speedup": "reduceQueueTime",
37
+ "inventory transfer": "safeTransferFrom",
38
+ "token set-approval-for-all": "setApprovalForAll",
39
+ "forge smelt": "smeltWearables",
40
+ "gotchi spend-skill-points": "spendSkillPoints",
41
+ "baazaar swap-buy-now": "swapAndBuyNow",
42
+ "auction swap-bid": "swapAndCommitBid",
43
+ "lending transfer-escrow": "transferEscrow",
44
+ "baazaar update-erc1155": "updateERC1155ListingPriceAndQuantity",
45
+ "lending whitelist update": "updateWhitelist",
46
+ "gotchi feed": "useConsumables",
47
+ "staking withdraw-pool": "withdrawFromPool",
48
+ };
49
+ function findMappedFunction(commandPath) {
50
+ const key = commandPath.join(" ");
51
+ return MAPPED_WRITE_COMMANDS[key];
52
+ }
53
+ function listMappedCommandsForRoot(root) {
54
+ return Object.keys(MAPPED_WRITE_COMMANDS).filter((entry) => entry.startsWith(`${root} `));
55
+ }
56
+ async function runMappedDomainCommand(ctx) {
57
+ const key = ctx.commandPath.join(" ");
58
+ const method = MAPPED_WRITE_COMMANDS[key];
59
+ if (!method) {
60
+ const candidates = listMappedCommandsForRoot(ctx.commandPath[0]);
61
+ throw new errors_1.CliError("COMMAND_NOT_IMPLEMENTED", `Mapped command '${key}' is not defined.`, 2, {
62
+ command: key,
63
+ availableForRoot: candidates,
64
+ });
65
+ }
66
+ const result = await (0, onchain_1.runOnchainSendWithFunction)(ctx, method, key);
67
+ return {
68
+ mappedMethod: method,
69
+ result,
70
+ };
71
+ }
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.runOnchainCallCommand = runOnchainCallCommand;
37
+ exports.runOnchainSendWithFunction = runOnchainSendWithFunction;
38
+ exports.runOnchainSendCommand = runOnchainSendCommand;
39
+ const fs = __importStar(require("fs"));
40
+ const viem_1 = require("viem");
41
+ const args_1 = require("../args");
42
+ const chains_1 = require("../chains");
43
+ const config_1 = require("../config");
44
+ const errors_1 = require("../errors");
45
+ const rpc_1 = require("../rpc");
46
+ const tx_engine_1 = require("../tx-engine");
47
+ function requireFlag(value, name) {
48
+ if (!value) {
49
+ throw new errors_1.CliError("MISSING_ARGUMENT", `${name} is required.`, 2);
50
+ }
51
+ return value;
52
+ }
53
+ function parseArgsJson(value) {
54
+ if (!value) {
55
+ return [];
56
+ }
57
+ let parsed;
58
+ try {
59
+ parsed = JSON.parse(value);
60
+ }
61
+ catch {
62
+ throw new errors_1.CliError("INVALID_ARGUMENT", "--args-json must be valid JSON.", 2);
63
+ }
64
+ if (!Array.isArray(parsed)) {
65
+ throw new errors_1.CliError("INVALID_ARGUMENT", "--args-json must be a JSON array.", 2);
66
+ }
67
+ return parsed;
68
+ }
69
+ function parseAbiFile(filePath) {
70
+ if (!fs.existsSync(filePath)) {
71
+ throw new errors_1.CliError("ABI_NOT_FOUND", `ABI file not found: ${filePath}`, 2);
72
+ }
73
+ let parsed;
74
+ try {
75
+ parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
76
+ }
77
+ catch {
78
+ throw new errors_1.CliError("INVALID_ABI", `ABI file is not valid JSON: ${filePath}`, 2);
79
+ }
80
+ if (Array.isArray(parsed)) {
81
+ return parsed;
82
+ }
83
+ if (typeof parsed === "object" && parsed !== null && "abi" in parsed && Array.isArray(parsed.abi)) {
84
+ return parsed.abi;
85
+ }
86
+ throw new errors_1.CliError("INVALID_ABI", `ABI file must be an array or object containing 'abi'.`, 2);
87
+ }
88
+ function parseValueWei(value) {
89
+ if (!value) {
90
+ return undefined;
91
+ }
92
+ if (!/^\d+$/.test(value)) {
93
+ throw new errors_1.CliError("INVALID_ARGUMENT", "--value-wei must be an integer string.", 2, {
94
+ value,
95
+ });
96
+ }
97
+ return BigInt(value);
98
+ }
99
+ function parseTimeoutMs(value) {
100
+ if (!value) {
101
+ return 120000;
102
+ }
103
+ const timeout = Number(value);
104
+ if (!Number.isInteger(timeout) || timeout <= 0) {
105
+ throw new errors_1.CliError("INVALID_ARGUMENT", "--timeout-ms must be a positive integer.", 2, {
106
+ value,
107
+ });
108
+ }
109
+ return timeout;
110
+ }
111
+ function parseAddress(value, flagName) {
112
+ if (!value || !/^0x[a-fA-F0-9]{40}$/.test(value)) {
113
+ throw new errors_1.CliError("INVALID_ARGUMENT", `${flagName} must be an EVM address.`, 2, {
114
+ value,
115
+ });
116
+ }
117
+ return value.toLowerCase();
118
+ }
119
+ async function runOnchainCallCommand(ctx) {
120
+ const config = (0, config_1.loadConfig)();
121
+ const profileName = (0, args_1.getFlagString)(ctx.args.flags, "profile") || ctx.globals.profile;
122
+ const profile = (0, config_1.getProfileOrThrow)(config, profileName);
123
+ const chain = (0, chains_1.resolveChain)(profile.chain);
124
+ const rpcUrl = (0, chains_1.resolveRpcUrl)(chain, (0, args_1.getFlagString)(ctx.args.flags, "rpc-url") || profile.rpcUrl);
125
+ const abiFile = requireFlag((0, args_1.getFlagString)(ctx.args.flags, "abi-file"), "--abi-file");
126
+ const abi = parseAbiFile(abiFile);
127
+ const address = parseAddress((0, args_1.getFlagString)(ctx.args.flags, "address"), "--address");
128
+ const functionName = requireFlag((0, args_1.getFlagString)(ctx.args.flags, "function"), "--function");
129
+ const args = parseArgsJson((0, args_1.getFlagString)(ctx.args.flags, "args-json"));
130
+ const preflight = await (0, rpc_1.runRpcPreflight)(chain, rpcUrl);
131
+ const calldata = (0, viem_1.encodeFunctionData)({
132
+ abi,
133
+ functionName,
134
+ args,
135
+ });
136
+ const callResult = await preflight.client.call({
137
+ to: address,
138
+ data: calldata,
139
+ });
140
+ if (!callResult.data) {
141
+ throw new errors_1.CliError("EMPTY_CALL_RESULT", "Call returned no data.", 2);
142
+ }
143
+ const decoded = (0, viem_1.decodeFunctionResult)({
144
+ abi,
145
+ functionName,
146
+ data: callResult.data,
147
+ });
148
+ return {
149
+ chainId: chain.chainId,
150
+ rpcUrl,
151
+ address,
152
+ functionName,
153
+ args,
154
+ result: decoded,
155
+ };
156
+ }
157
+ async function runOnchainSendWithFunction(ctx, forcedFunctionName, commandOverride) {
158
+ const config = (0, config_1.loadConfig)();
159
+ const profileName = (0, args_1.getFlagString)(ctx.args.flags, "profile") || ctx.globals.profile;
160
+ const profile = (0, config_1.getProfileOrThrow)(config, profileName);
161
+ const policy = (0, config_1.getPolicyOrThrow)(config, profile.policy);
162
+ const chain = (0, chains_1.resolveChain)(profile.chain);
163
+ const rpcUrl = (0, chains_1.resolveRpcUrl)(chain, (0, args_1.getFlagString)(ctx.args.flags, "rpc-url") || profile.rpcUrl);
164
+ const abiFile = requireFlag((0, args_1.getFlagString)(ctx.args.flags, "abi-file"), "--abi-file");
165
+ const abi = parseAbiFile(abiFile);
166
+ const address = parseAddress((0, args_1.getFlagString)(ctx.args.flags, "address"), "--address");
167
+ const functionName = forcedFunctionName || requireFlag((0, args_1.getFlagString)(ctx.args.flags, "function"), "--function");
168
+ const args = parseArgsJson((0, args_1.getFlagString)(ctx.args.flags, "args-json"));
169
+ const valueWei = parseValueWei((0, args_1.getFlagString)(ctx.args.flags, "value-wei"));
170
+ const data = (0, viem_1.encodeFunctionData)({
171
+ abi,
172
+ functionName,
173
+ args,
174
+ });
175
+ const noncePolicyRaw = (0, args_1.getFlagString)(ctx.args.flags, "nonce-policy") || "safe";
176
+ if (!["safe", "replace", "manual"].includes(noncePolicyRaw)) {
177
+ throw new errors_1.CliError("INVALID_NONCE_POLICY", `Unsupported nonce policy '${noncePolicyRaw}'.`, 2);
178
+ }
179
+ const nonceRaw = (0, args_1.getFlagString)(ctx.args.flags, "nonce");
180
+ const nonce = nonceRaw ? Number(nonceRaw) : undefined;
181
+ if (nonceRaw && (!Number.isInteger(nonce) || (nonce !== undefined && nonce < 0))) {
182
+ throw new errors_1.CliError("INVALID_ARGUMENT", "--nonce must be a non-negative integer.", 2, {
183
+ value: nonceRaw,
184
+ });
185
+ }
186
+ const waitForReceipt = (0, args_1.getFlagBoolean)(ctx.args.flags, "wait");
187
+ const intent = {
188
+ idempotencyKey: (0, args_1.getFlagString)(ctx.args.flags, "idempotency-key"),
189
+ profileName: profile.name,
190
+ chainId: profile.chainId,
191
+ rpcUrl,
192
+ signer: profile.signer,
193
+ policy,
194
+ to: address,
195
+ data,
196
+ valueWei,
197
+ noncePolicy: noncePolicyRaw,
198
+ nonce,
199
+ waitForReceipt,
200
+ timeoutMs: parseTimeoutMs((0, args_1.getFlagString)(ctx.args.flags, "timeout-ms")),
201
+ command: commandOverride || `onchain send ${functionName}`,
202
+ };
203
+ const result = await (0, tx_engine_1.executeTxIntent)(intent, chain);
204
+ return {
205
+ profile: profile.name,
206
+ chainId: chain.chainId,
207
+ address,
208
+ functionName,
209
+ args,
210
+ result,
211
+ };
212
+ }
213
+ async function runOnchainSendCommand(ctx) {
214
+ return runOnchainSendWithFunction(ctx);
215
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runPolicyListCommand = runPolicyListCommand;
4
+ exports.runPolicyShowCommand = runPolicyShowCommand;
5
+ exports.runPolicyUpsertCommand = runPolicyUpsertCommand;
6
+ const args_1 = require("../args");
7
+ const config_1 = require("../config");
8
+ const errors_1 = require("../errors");
9
+ function parseIntegerString(value, flag) {
10
+ if (value === undefined) {
11
+ return undefined;
12
+ }
13
+ if (!/^\d+$/.test(value)) {
14
+ throw new errors_1.CliError("INVALID_ARGUMENT", `${flag} must be an integer string.`, 2, {
15
+ value,
16
+ });
17
+ }
18
+ return value;
19
+ }
20
+ function parseAllowlist(value) {
21
+ if (!value) {
22
+ return undefined;
23
+ }
24
+ const addresses = value
25
+ .split(",")
26
+ .map((entry) => entry.trim())
27
+ .filter(Boolean)
28
+ .map((entry) => entry.toLowerCase());
29
+ if (addresses.some((entry) => !/^0x[a-f0-9]{40}$/.test(entry))) {
30
+ throw new errors_1.CliError("INVALID_ARGUMENT", "--allowed-to expects comma-separated EVM addresses.", 2);
31
+ }
32
+ return addresses;
33
+ }
34
+ async function runPolicyListCommand() {
35
+ const config = (0, config_1.loadConfig)();
36
+ return {
37
+ policies: Object.values(config.policies).sort((a, b) => a.name.localeCompare(b.name)),
38
+ };
39
+ }
40
+ async function runPolicyShowCommand(ctx) {
41
+ const config = (0, config_1.loadConfig)();
42
+ const policyName = (0, args_1.getFlagString)(ctx.args.flags, "policy") || "default";
43
+ const policy = config.policies[policyName];
44
+ if (!policy) {
45
+ throw new errors_1.CliError("POLICY_NOT_FOUND", `Policy '${policyName}' does not exist.`, 2);
46
+ }
47
+ return {
48
+ policy,
49
+ };
50
+ }
51
+ async function runPolicyUpsertCommand(ctx) {
52
+ const config = (0, config_1.loadConfig)();
53
+ const policyName = (0, args_1.getFlagString)(ctx.args.flags, "policy") || "default";
54
+ const timestamp = new Date().toISOString();
55
+ const existing = config.policies[policyName] || (0, config_1.createDefaultPolicy)(policyName, timestamp);
56
+ const updated = {
57
+ ...existing,
58
+ name: policyName,
59
+ maxValueWei: parseIntegerString((0, args_1.getFlagString)(ctx.args.flags, "max-value-wei"), "--max-value-wei") ?? existing.maxValueWei,
60
+ maxGasLimit: parseIntegerString((0, args_1.getFlagString)(ctx.args.flags, "max-gas-limit"), "--max-gas-limit") ?? existing.maxGasLimit,
61
+ maxFeePerGasWei: parseIntegerString((0, args_1.getFlagString)(ctx.args.flags, "max-fee-per-gas-wei"), "--max-fee-per-gas-wei") ??
62
+ existing.maxFeePerGasWei,
63
+ maxPriorityFeePerGasWei: parseIntegerString((0, args_1.getFlagString)(ctx.args.flags, "max-priority-fee-per-gas-wei"), "--max-priority-fee-per-gas-wei") ??
64
+ existing.maxPriorityFeePerGasWei,
65
+ allowedTo: parseAllowlist((0, args_1.getFlagString)(ctx.args.flags, "allowed-to")) ?? existing.allowedTo,
66
+ updatedAt: timestamp,
67
+ };
68
+ const merged = (0, config_1.upsertPolicy)(config, updated);
69
+ const configPath = (0, config_1.saveConfig)(merged);
70
+ return {
71
+ message: `Policy '${policyName}' updated.`,
72
+ policy: updated,
73
+ configPath,
74
+ };
75
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runProfileListCommand = runProfileListCommand;
4
+ exports.runProfileShowCommand = runProfileShowCommand;
5
+ exports.runProfileUseCommand = runProfileUseCommand;
6
+ exports.runProfileExportCommand = runProfileExportCommand;
7
+ const args_1 = require("../args");
8
+ const config_1 = require("../config");
9
+ const errors_1 = require("../errors");
10
+ function resolveProfileSelection(ctx) {
11
+ return (0, args_1.getFlagString)(ctx.args.flags, "profile") || ctx.globals.profile;
12
+ }
13
+ async function runProfileListCommand() {
14
+ const config = (0, config_1.loadConfig)();
15
+ const profiles = Object.values(config.profiles)
16
+ .sort((a, b) => a.name.localeCompare(b.name))
17
+ .map((profile) => ({
18
+ name: profile.name,
19
+ chain: profile.chain,
20
+ chainId: profile.chainId,
21
+ rpcUrl: profile.rpcUrl,
22
+ policy: profile.policy,
23
+ signerType: profile.signer.type,
24
+ active: config.activeProfile === profile.name,
25
+ updatedAt: profile.updatedAt,
26
+ }));
27
+ return {
28
+ activeProfile: config.activeProfile || null,
29
+ profiles,
30
+ };
31
+ }
32
+ async function runProfileShowCommand(ctx) {
33
+ const config = (0, config_1.loadConfig)();
34
+ const requestedProfile = resolveProfileSelection(ctx);
35
+ const profile = (0, config_1.getProfileOrThrow)(config, requestedProfile);
36
+ const policy = (0, config_1.getPolicyOrThrow)(config, profile.policy);
37
+ return {
38
+ activeProfile: config.activeProfile || null,
39
+ profile,
40
+ policy,
41
+ };
42
+ }
43
+ async function runProfileUseCommand(ctx) {
44
+ const selectedProfile = resolveProfileSelection(ctx);
45
+ if (!selectedProfile) {
46
+ throw new errors_1.CliError("MISSING_PROFILE", "profile use requires --profile <name>.", 2);
47
+ }
48
+ const config = (0, config_1.loadConfig)();
49
+ const updated = (0, config_1.setActiveProfile)(config, selectedProfile);
50
+ const configPath = (0, config_1.saveConfig)(updated);
51
+ return {
52
+ message: `Active profile set to '${selectedProfile}'.`,
53
+ activeProfile: selectedProfile,
54
+ configPath,
55
+ };
56
+ }
57
+ async function runProfileExportCommand(ctx) {
58
+ const config = (0, config_1.loadConfig)();
59
+ const requestedProfile = resolveProfileSelection(ctx);
60
+ const profile = (0, config_1.getProfileOrThrow)(config, requestedProfile);
61
+ const policy = (0, config_1.getPolicyOrThrow)(config, profile.policy);
62
+ return {
63
+ exportedAt: new Date().toISOString(),
64
+ profile,
65
+ policy,
66
+ };
67
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runRpcCheckCommand = runRpcCheckCommand;
4
+ const args_1 = require("../args");
5
+ const chains_1 = require("../chains");
6
+ const config_1 = require("../config");
7
+ const rpc_1 = require("../rpc");
8
+ const signer_1 = require("../signer");
9
+ async function runRpcCheckCommand(ctx) {
10
+ const profileName = (0, args_1.getFlagString)(ctx.args.flags, "profile") || ctx.globals.profile;
11
+ const skipSignerCheck = (0, args_1.getFlagBoolean)(ctx.args.flags, "skip-signer-check");
12
+ const config = (0, config_1.loadConfig)();
13
+ const profile = (0, config_1.getProfileOrThrow)(config, profileName);
14
+ const chain = (0, chains_1.resolveChain)(profile.chain);
15
+ const rpcUrl = (0, chains_1.resolveRpcUrl)(chain, (0, args_1.getFlagString)(ctx.args.flags, "rpc-url") || profile.rpcUrl);
16
+ const preflight = await (0, rpc_1.runRpcPreflight)(chain, rpcUrl);
17
+ const signer = skipSignerCheck
18
+ ? { signerType: profile.signer.type, backendStatus: "not-checked", canSign: false }
19
+ : (await (0, signer_1.resolveSignerRuntime)(profile.signer, preflight.client, rpcUrl, (0, chains_1.toViemChain)(chain, rpcUrl))).summary;
20
+ return {
21
+ profile: profile.name,
22
+ chain: profile.chain,
23
+ chainId: preflight.chainId,
24
+ chainName: preflight.chainName,
25
+ blockNumber: preflight.blockNumber,
26
+ rpcUrl,
27
+ signer,
28
+ };
29
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSignerCheckCommand = runSignerCheckCommand;
4
+ exports.runSignerKeychainImportCommand = runSignerKeychainImportCommand;
5
+ exports.runSignerKeychainListCommand = runSignerKeychainListCommand;
6
+ exports.runSignerKeychainRemoveCommand = runSignerKeychainRemoveCommand;
7
+ const args_1 = require("../args");
8
+ const chains_1 = require("../chains");
9
+ const config_1 = require("../config");
10
+ const errors_1 = require("../errors");
11
+ const keychain_1 = require("../keychain");
12
+ const rpc_1 = require("../rpc");
13
+ const signer_1 = require("../signer");
14
+ async function runSignerCheckCommand(ctx) {
15
+ const config = (0, config_1.loadConfig)();
16
+ const profileName = (0, args_1.getFlagString)(ctx.args.flags, "profile") || ctx.globals.profile;
17
+ const profile = (0, config_1.getProfileOrThrow)(config, profileName);
18
+ const chain = (0, chains_1.resolveChain)(profile.chain);
19
+ const rpcUrl = (0, chains_1.resolveRpcUrl)(chain, (0, args_1.getFlagString)(ctx.args.flags, "rpc-url") || profile.rpcUrl);
20
+ const preflight = await (0, rpc_1.runRpcPreflight)(chain, rpcUrl);
21
+ const runtime = await (0, signer_1.resolveSignerRuntime)(profile.signer, preflight.client, rpcUrl, (0, chains_1.toViemChain)(chain, rpcUrl));
22
+ return {
23
+ profile: profile.name,
24
+ chainId: chain.chainId,
25
+ signer: runtime.summary,
26
+ };
27
+ }
28
+ async function runSignerKeychainImportCommand(ctx) {
29
+ const accountId = (0, args_1.getFlagString)(ctx.args.flags, "account-id");
30
+ const privateKeyEnv = (0, args_1.getFlagString)(ctx.args.flags, "private-key-env") || "AGCLI_PRIVATE_KEY";
31
+ if (!accountId) {
32
+ throw new errors_1.CliError("MISSING_ARGUMENT", "signer keychain import requires --account-id.", 2);
33
+ }
34
+ const imported = (0, keychain_1.keychainImportFromEnv)(accountId, privateKeyEnv);
35
+ return {
36
+ message: `Imported keychain entry '${imported.accountId}'.`,
37
+ ...imported,
38
+ };
39
+ }
40
+ async function runSignerKeychainListCommand() {
41
+ return {
42
+ entries: (0, keychain_1.keychainList)(),
43
+ };
44
+ }
45
+ async function runSignerKeychainRemoveCommand(ctx) {
46
+ const accountId = (0, args_1.getFlagString)(ctx.args.flags, "account-id");
47
+ if (!accountId) {
48
+ throw new errors_1.CliError("MISSING_ARGUMENT", "signer keychain remove requires --account-id.", 2);
49
+ }
50
+ return (0, keychain_1.keychainRemove)(accountId);
51
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDomainStubRoot = isDomainStubRoot;
4
+ exports.runDomainStubCommand = runDomainStubCommand;
5
+ const errors_1 = require("../errors");
6
+ const SUPPORTED_STUB_ROOTS = [
7
+ "gotchi",
8
+ "portal",
9
+ "wearables",
10
+ "items",
11
+ "inventory",
12
+ "baazaar",
13
+ "auction",
14
+ "lending",
15
+ "staking",
16
+ "gotchi-points",
17
+ "realm",
18
+ "alchemica",
19
+ "forge",
20
+ "token",
21
+ ];
22
+ function isDomainStubRoot(root) {
23
+ return SUPPORTED_STUB_ROOTS.includes(root);
24
+ }
25
+ async function runDomainStubCommand(ctx) {
26
+ const command = ctx.commandPath.join(" ");
27
+ throw new errors_1.CliError("COMMAND_NOT_IMPLEMENTED", `Command '${command}' is planned but not implemented yet.`, 2, {
28
+ command,
29
+ hint: "If this is a mapped onchain write, pass full subcommand plus --abi-file/--address/--args-json.",
30
+ plannedRoots: SUPPORTED_STUB_ROOTS,
31
+ });
32
+ }