@diamondslab/diamonds 1.3.2 → 1.4.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,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=diamond-abi-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diamond-abi-cli.d.ts","sourceRoot":"","sources":["../../src/cli/diamond-abi-cli.ts"],"names":[],"mappings":";AAqeA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,377 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = require("commander");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const fs_1 = require("fs");
10
+ // NOTE: `hardhat` (and, via its config, the hardhat-ethers plugin) is loaded
11
+ // lazily inside `setupDiamondConnection` so commands that don't need a chain
12
+ // connection (`validate`, `compare`) run without booting the Hardhat runtime.
13
+ // Importing `@nomicfoundation/hardhat-ethers` at module scope would call
14
+ // `extendEnvironment` before a Hardhat context exists (HH5), so it is avoided.
15
+ // This CLI formats and inspects arbitrary ABI/JSON artifacts and indexes internal
16
+ // selector maps, so `any` and dynamic property access are intentional below.
17
+ /* eslint-disable @typescript-eslint/no-explicit-any, security/detect-object-injection */
18
+ const program = new commander_1.Command();
19
+ // Keep the CLI version in sync with the package version. The relative path
20
+ // resolves to the package root from both src/cli (dev) and dist/cli (published).
21
+ const { version: pkgVersion } = require('../../package.json');
22
+ program
23
+ .name('diamond-abi')
24
+ .description('Diamond ABI generation utilities')
25
+ .version(pkgVersion);
26
+ // Generate command
27
+ program
28
+ .command('generate')
29
+ .description('Generate ABI for a deployed diamond')
30
+ .option('-d, --diamond <name>', 'Diamond name', 'GeniusDiamond')
31
+ .option('-n, --network <name>', 'Network name', 'localhost')
32
+ .option('-c, --chain-id <id>', 'Chain ID', '31337')
33
+ .option('-o, --output <dir>', 'Output directory (overrides diamond config)', undefined)
34
+ .option('--deployments-path <path>', 'Deployments path', './diamonds')
35
+ .option('--contracts-path <path>', 'Contracts path', './contracts')
36
+ .option('--include-source', 'Include source information in ABI', false)
37
+ .option('--validate-selectors', 'Validate function selector uniqueness', true)
38
+ .option('-v, --verbose', 'Verbose output', false)
39
+ .action(async (options) => {
40
+ try {
41
+ console.log(chalk_1.default.blue('šŸ”§ Generating Diamond ABI...'));
42
+ const { generateDiamondAbi } = await import('../utils/diamondAbiGenerator.js');
43
+ const { Diamond } = await import('../core/Diamond.js');
44
+ const { FileDeploymentRepository } = await import('../repositories/FileDeploymentRepository.js');
45
+ const config = {
46
+ diamondName: options.diamond,
47
+ networkName: options.network,
48
+ chainId: parseInt(options.chainId),
49
+ deploymentsPath: options.deploymentsPath,
50
+ contractsPath: options.contractsPath,
51
+ };
52
+ if (options.verbose) {
53
+ console.log(chalk_1.default.cyan('šŸ“‹ Configuration:'));
54
+ console.log(chalk_1.default.gray(` Diamond: ${config.diamondName}`));
55
+ console.log(chalk_1.default.gray(` Network: ${config.networkName}`));
56
+ console.log(chalk_1.default.gray(` Chain ID: ${config.chainId}`));
57
+ console.log(chalk_1.default.gray(` Output: ${options.output}`));
58
+ }
59
+ // Create diamond instance
60
+ const repository = new FileDeploymentRepository(config);
61
+ const diamond = new Diamond(config, repository);
62
+ // Set provider and signer if available
63
+ await setupDiamondConnection(diamond, options.verbose);
64
+ // Generate ABI using Diamond's configured paths
65
+ const result = await generateDiamondAbi(diamond, {
66
+ outputDir: options.output ?? diamond.getDiamondAbiPath(),
67
+ includeSourceInfo: options.includeSource,
68
+ validateSelectors: options.validateSelectors,
69
+ verbose: options.verbose,
70
+ });
71
+ console.log(chalk_1.default.green('\nāœ… Diamond ABI generation completed!'));
72
+ displayResults(result, options.verbose);
73
+ }
74
+ catch (error) {
75
+ console.error(chalk_1.default.red('āŒ Error generating Diamond ABI:'), error);
76
+ process.exit(1);
77
+ }
78
+ });
79
+ // Preview command
80
+ program
81
+ .command('preview')
82
+ .description('Preview ABI changes for planned diamond cuts')
83
+ .option('-d, --diamond <name>', 'Diamond name', 'GeniusDiamond')
84
+ .option('-n, --network <name>', 'Network name', 'localhost')
85
+ .option('-c, --chain-id <id>', 'Chain ID', '31337')
86
+ .option('--deployments-path <path>', 'Deployments path', './diamonds')
87
+ .option('--contracts-path <path>', 'Contracts path', './contracts')
88
+ .option('-v, --verbose', 'Verbose output', false)
89
+ .action(async (options) => {
90
+ try {
91
+ console.log(chalk_1.default.blue('šŸ” Previewing Diamond ABI changes...'));
92
+ const { generateDiamondAbi, previewDiamondAbi } = await import('../utils/diamondAbiGenerator.js');
93
+ const { Diamond } = await import('../core/Diamond.js');
94
+ const { FileDeploymentRepository } = await import('../repositories/FileDeploymentRepository.js');
95
+ const config = {
96
+ diamondName: options.diamond,
97
+ networkName: options.network,
98
+ chainId: parseInt(options.chainId),
99
+ deploymentsPath: options.deploymentsPath,
100
+ contractsPath: options.contractsPath,
101
+ };
102
+ const repository = new FileDeploymentRepository(config);
103
+ const diamond = new Diamond(config, repository);
104
+ await setupDiamondConnection(diamond, options.verbose);
105
+ // Get current state
106
+ const currentResult = await generateDiamondAbi(diamond, {
107
+ verbose: false,
108
+ includeSourceInfo: false,
109
+ });
110
+ console.log(chalk_1.default.cyan('\nšŸ“‹ Current ABI state:'));
111
+ console.log(chalk_1.default.gray(` Functions: ${currentResult.stats.totalFunctions}`));
112
+ console.log(chalk_1.default.gray(` Events: ${currentResult.stats.totalEvents}`));
113
+ console.log(chalk_1.default.gray(` Facets: ${currentResult.stats.facetCount}`));
114
+ // Check for planned cuts
115
+ const registry = diamond.functionSelectorRegistry;
116
+ const plannedCuts = Array.from(registry.entries())
117
+ .filter(([_, entry]) => entry.action !== 0) // Not deployed
118
+ .map(([selector, entry]) => ({
119
+ facetAddress: entry.address,
120
+ action: entry.action,
121
+ functionSelectors: [selector],
122
+ name: entry.facetName,
123
+ }));
124
+ if (plannedCuts.length === 0) {
125
+ console.log(chalk_1.default.yellow('\nāš ļø No planned cuts found in function selector registry'));
126
+ console.log(chalk_1.default.gray(' Use the diamond deployment system to plan upgrades first.'));
127
+ return;
128
+ }
129
+ console.log(chalk_1.default.cyan(`\nšŸ”„ Found ${plannedCuts.length} planned cuts:`));
130
+ for (const cut of plannedCuts) {
131
+ const actionName = cut.action === 1 ? 'Add' : cut.action === 2 ? 'Remove' : 'Replace';
132
+ console.log(chalk_1.default.gray(` ${actionName}: ${cut.name} (${cut.functionSelectors.length} selectors)`));
133
+ }
134
+ // Preview with planned cuts
135
+ const previewResult = await previewDiamondAbi(diamond, plannedCuts, {
136
+ verbose: options.verbose,
137
+ includeSourceInfo: false,
138
+ });
139
+ console.log(chalk_1.default.green('\nāœ… ABI preview completed!'));
140
+ console.log(chalk_1.default.blue('\nšŸ“Š Preview Results:'));
141
+ console.log(chalk_1.default.cyan(` Functions after cuts: ${previewResult.stats.totalFunctions}`));
142
+ console.log(chalk_1.default.cyan(` Events after cuts: ${previewResult.stats.totalEvents}`));
143
+ console.log(chalk_1.default.cyan(` Facets after cuts: ${previewResult.stats.facetCount}`));
144
+ // Show differences
145
+ const functionDiff = previewResult.stats.totalFunctions - currentResult.stats.totalFunctions;
146
+ const facetDiff = previewResult.stats.facetCount - currentResult.stats.facetCount;
147
+ if (functionDiff !== 0) {
148
+ const color = functionDiff > 0 ? chalk_1.default.green : chalk_1.default.red;
149
+ console.log(color(` Function change: ${functionDiff > 0 ? '+' : ''}${functionDiff}`));
150
+ }
151
+ if (facetDiff !== 0) {
152
+ const color = facetDiff > 0 ? chalk_1.default.green : chalk_1.default.red;
153
+ console.log(color(` Facet change: ${facetDiff > 0 ? '+' : ''}${facetDiff}`));
154
+ }
155
+ if (options.verbose) {
156
+ console.log(chalk_1.default.blue('\nšŸŽÆ Planned Function Changes:'));
157
+ displaySelectorChanges(currentResult.selectorMap, previewResult.selectorMap);
158
+ }
159
+ }
160
+ catch (error) {
161
+ console.error(chalk_1.default.red('āŒ Error previewing Diamond ABI:'), error);
162
+ process.exit(1);
163
+ }
164
+ });
165
+ // Compare command
166
+ program
167
+ .command('compare')
168
+ .description('Compare two diamond ABI files')
169
+ .argument('<file1>', 'First ABI file path')
170
+ .argument('<file2>', 'Second ABI file path')
171
+ .option('-v, --verbose', 'Verbose output', false)
172
+ .action(async (file1, file2, options) => {
173
+ try {
174
+ console.log(chalk_1.default.blue('šŸ” Comparing Diamond ABI files...'));
175
+ if (!(0, fs_1.existsSync)(file1)) {
176
+ throw new Error(`File not found: ${file1}`);
177
+ }
178
+ if (!(0, fs_1.existsSync)(file2)) {
179
+ throw new Error(`File not found: ${file2}`);
180
+ }
181
+ const abi1 = JSON.parse(require('fs').readFileSync(file1, 'utf8'));
182
+ const abi2 = JSON.parse(require('fs').readFileSync(file2, 'utf8'));
183
+ console.log(chalk_1.default.cyan(`\nšŸ“‹ Comparing:`));
184
+ console.log(chalk_1.default.gray(` File 1: ${file1}`));
185
+ console.log(chalk_1.default.gray(` File 2: ${file2}`));
186
+ const result1 = analyzeAbi(abi1);
187
+ const result2 = analyzeAbi(abi2);
188
+ console.log(chalk_1.default.blue('\nšŸ“Š Comparison Results:'));
189
+ // Function comparison
190
+ const funcDiff = result2.functions - result1.functions;
191
+ console.log(chalk_1.default.cyan(`Functions: ${result1.functions} → ${result2.functions} `), funcDiff === 0
192
+ ? chalk_1.default.gray('(no change)')
193
+ : funcDiff > 0
194
+ ? chalk_1.default.green(`(+${funcDiff})`)
195
+ : chalk_1.default.red(`(${funcDiff})`));
196
+ // Event comparison
197
+ const eventDiff = result2.events - result1.events;
198
+ console.log(chalk_1.default.cyan(`Events: ${result1.events} → ${result2.events} `), eventDiff === 0
199
+ ? chalk_1.default.gray('(no change)')
200
+ : eventDiff > 0
201
+ ? chalk_1.default.green(`(+${eventDiff})`)
202
+ : chalk_1.default.red(`(${eventDiff})`));
203
+ // Error comparison
204
+ const errorDiff = result2.errors - result1.errors;
205
+ console.log(chalk_1.default.cyan(`Errors: ${result1.errors} → ${result2.errors} `), errorDiff === 0
206
+ ? chalk_1.default.gray('(no change)')
207
+ : errorDiff > 0
208
+ ? chalk_1.default.green(`(+${errorDiff})`)
209
+ : chalk_1.default.red(`(${errorDiff})`));
210
+ if (options.verbose && abi1._diamondMetadata && abi2._diamondMetadata) {
211
+ console.log(chalk_1.default.blue('\nšŸ” Detailed Selector Comparison:'));
212
+ displaySelectorChanges(abi1._diamondMetadata.selectorMap ?? {}, abi2._diamondMetadata.selectorMap ?? {});
213
+ }
214
+ }
215
+ catch (error) {
216
+ console.error(chalk_1.default.red('āŒ Error comparing ABI files:'), error);
217
+ process.exit(1);
218
+ }
219
+ });
220
+ // Validate command
221
+ program
222
+ .command('validate')
223
+ .description('Validate a diamond ABI file')
224
+ .argument('<file>', 'ABI file path')
225
+ .option('-v, --verbose', 'Verbose output', false)
226
+ .action(async (file, options) => {
227
+ try {
228
+ console.log(chalk_1.default.blue('šŸ” Validating Diamond ABI...'));
229
+ if (!(0, fs_1.existsSync)(file)) {
230
+ throw new Error(`File not found: ${file}`);
231
+ }
232
+ const artifact = JSON.parse(require('fs').readFileSync(file, 'utf8'));
233
+ // Basic structure validation
234
+ const hasRequiredFields = artifact.abi && artifact.contractName;
235
+ if (!hasRequiredFields) {
236
+ throw new Error('Invalid artifact: missing required fields (abi, contractName)');
237
+ }
238
+ // ABI validation with ethers
239
+ const { Interface } = await import('ethers');
240
+ let ethersInterface;
241
+ try {
242
+ ethersInterface = new Interface(artifact.abi);
243
+ }
244
+ catch (error) {
245
+ throw new Error(`Invalid ABI: ${error}`);
246
+ }
247
+ const analysis = analyzeAbi(artifact);
248
+ console.log(chalk_1.default.green('āœ… ABI validation passed!'));
249
+ console.log(chalk_1.default.blue('\nšŸ“Š ABI Analysis:'));
250
+ console.log(chalk_1.default.cyan(` Functions: ${analysis.functions}`));
251
+ console.log(chalk_1.default.cyan(` Events: ${analysis.events}`));
252
+ console.log(chalk_1.default.cyan(` Errors: ${analysis.errors}`));
253
+ console.log(chalk_1.default.cyan(` Total fragments: ${ethersInterface.fragments.length}`));
254
+ if (artifact._diamondMetadata) {
255
+ const metadata = artifact._diamondMetadata;
256
+ console.log(chalk_1.default.blue('\nšŸ’Ž Diamond Metadata:'));
257
+ console.log(chalk_1.default.cyan(` Diamond: ${metadata.diamondName}`));
258
+ console.log(chalk_1.default.cyan(` Network: ${metadata.networkName}`));
259
+ console.log(chalk_1.default.cyan(` Chain ID: ${metadata.chainId}`));
260
+ console.log(chalk_1.default.cyan(` Generated: ${metadata.generatedAt}`));
261
+ if (metadata.selectorMap) {
262
+ const selectorCount = Object.keys(metadata.selectorMap).length;
263
+ const facetCount = new Set(Object.values(metadata.selectorMap)).size;
264
+ console.log(chalk_1.default.cyan(` Function selectors: ${selectorCount}`));
265
+ console.log(chalk_1.default.cyan(` Facets: ${facetCount}`));
266
+ }
267
+ }
268
+ if (options.verbose) {
269
+ console.log(chalk_1.default.blue('\nšŸ” Function Signatures:'));
270
+ ethersInterface.fragments
271
+ .filter((f) => f.type === 'function')
272
+ .slice(0, 10) // Show first 10
273
+ .forEach((f) => {
274
+ console.log(chalk_1.default.gray(` ${f.format()}`));
275
+ });
276
+ if (ethersInterface.fragments.filter((f) => f.type === 'function').length > 10) {
277
+ console.log(chalk_1.default.gray(` ... and ${ethersInterface.fragments.filter((f) => f.type === 'function').length - 10} more`));
278
+ }
279
+ }
280
+ }
281
+ catch (error) {
282
+ console.error(chalk_1.default.red('āŒ ABI validation failed:'), error);
283
+ process.exit(1);
284
+ }
285
+ });
286
+ // Helper functions
287
+ async function setupDiamondConnection(diamond, verbose) {
288
+ try {
289
+ // Typed as `any`: the `hre.ethers` helper is added at runtime by the
290
+ // hardhat-ethers plugin (loaded via the project's hardhat config).
291
+ const hre = (await import('hardhat')).default;
292
+ diamond.setProvider(hre.ethers.provider);
293
+ const signers = await hre.ethers.getSigners();
294
+ if (signers.length > 0) {
295
+ diamond.setSigner(signers[0]);
296
+ }
297
+ if (verbose) {
298
+ console.log(chalk_1.default.gray('āœ… Connected to Hardhat provider'));
299
+ }
300
+ }
301
+ catch (error) {
302
+ if (verbose) {
303
+ console.log(chalk_1.default.yellow('āš ļø Could not connect to provider (running in standalone mode)'));
304
+ }
305
+ }
306
+ }
307
+ function displayResults(result, verbose) {
308
+ console.log(chalk_1.default.blue('\nšŸ“Š Generation Results:'));
309
+ console.log(chalk_1.default.cyan(` Functions: ${result.stats.totalFunctions}`));
310
+ console.log(chalk_1.default.cyan(` Events: ${result.stats.totalEvents}`));
311
+ console.log(chalk_1.default.cyan(` Errors: ${result.stats.totalErrors}`));
312
+ console.log(chalk_1.default.cyan(` Facets: ${result.stats.facetCount}`));
313
+ if (result.outputPath) {
314
+ console.log(chalk_1.default.cyan(` Output: ${result.outputPath}`));
315
+ }
316
+ if (result.stats.duplicateSelectorsSkipped > 0) {
317
+ console.log(chalk_1.default.yellow(` Duplicates skipped: ${result.stats.duplicateSelectorsSkipped}`));
318
+ }
319
+ if (verbose && result.selectorMap) {
320
+ console.log(chalk_1.default.blue('\nšŸŽÆ Function Selector Mapping:'));
321
+ const sortedSelectors = Object.entries(result.selectorMap).sort(([, a], [, b]) => a.localeCompare(b));
322
+ sortedSelectors.slice(0, 20).forEach(([selector, facet]) => {
323
+ console.log(chalk_1.default.gray(` ${selector} → ${facet}`));
324
+ });
325
+ if (sortedSelectors.length > 20) {
326
+ console.log(chalk_1.default.gray(` ... and ${sortedSelectors.length - 20} more`));
327
+ }
328
+ }
329
+ }
330
+ function displaySelectorChanges(oldMap, newMap) {
331
+ const oldSelectors = new Set(Object.keys(oldMap));
332
+ const newSelectors = new Set(Object.keys(newMap));
333
+ const added = Array.from(newSelectors).filter((s) => !oldSelectors.has(s));
334
+ const removed = Array.from(oldSelectors).filter((s) => !newSelectors.has(s));
335
+ const changed = Array.from(oldSelectors).filter((s) => newSelectors.has(s) && oldMap[s] !== newMap[s]);
336
+ if (added.length > 0) {
337
+ console.log(chalk_1.default.green(`\n āž• Added (${added.length}):`));
338
+ added.slice(0, 10).forEach((selector) => {
339
+ console.log(chalk_1.default.gray(` ${selector} → ${newMap[selector]}`));
340
+ });
341
+ if (added.length > 10) {
342
+ console.log(chalk_1.default.gray(` ... and ${added.length - 10} more`));
343
+ }
344
+ }
345
+ if (removed.length > 0) {
346
+ console.log(chalk_1.default.red(`\n āž– Removed (${removed.length}):`));
347
+ removed.slice(0, 10).forEach((selector) => {
348
+ console.log(chalk_1.default.gray(` ${selector} → ${oldMap[selector]}`));
349
+ });
350
+ if (removed.length > 10) {
351
+ console.log(chalk_1.default.gray(` ... and ${removed.length - 10} more`));
352
+ }
353
+ }
354
+ if (changed.length > 0) {
355
+ console.log(chalk_1.default.yellow(`\n šŸ”„ Changed (${changed.length}):`));
356
+ changed.slice(0, 10).forEach((selector) => {
357
+ console.log(chalk_1.default.gray(` ${selector}: ${oldMap[selector]} → ${newMap[selector]}`));
358
+ });
359
+ if (changed.length > 10) {
360
+ console.log(chalk_1.default.gray(` ... and ${changed.length - 10} more`));
361
+ }
362
+ }
363
+ if (added.length === 0 && removed.length === 0 && changed.length === 0) {
364
+ console.log(chalk_1.default.gray(' No selector changes detected'));
365
+ }
366
+ }
367
+ function analyzeAbi(artifact) {
368
+ const abi = artifact.abi ?? [];
369
+ return {
370
+ functions: abi.filter((item) => item.type === 'function').length,
371
+ events: abi.filter((item) => item.type === 'event').length,
372
+ errors: abi.filter((item) => item.type === 'error').length,
373
+ };
374
+ }
375
+ // Parse command line arguments
376
+ program.parse();
377
+ //# sourceMappingURL=diamond-abi-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diamond-abi-cli.js","sourceRoot":"","sources":["../../src/cli/diamond-abi-cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAO1B,2BAAgC;AAChC,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,yEAAyE;AACzE,+EAA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MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,MAAM;KAC/D,CAAC;AACH,CAAC;AAED,+BAA+B;AAC/B,OAAO,CAAC,KAAK,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { Command } from 'commander';\nimport chalk from 'chalk';\n// The diamond/ABI-generator modules transitively import `hardhat` at module\n// scope, so they (and `hardhat` itself) are imported lazily inside the\n// `generate`/`preview` actions. This keeps `validate` and `compare` — which only\n// read ABI JSON files — runnable as a plain `node`/`npx` bin with no Hardhat.\nimport type { Diamond } from '../core/Diamond';\nimport type { DiamondConfig } from '../types';\nimport { existsSync } from 'fs';\n// NOTE: `hardhat` (and, via its config, the hardhat-ethers plugin) is loaded\n// lazily inside `setupDiamondConnection` so commands that don't need a chain\n// connection (`validate`, `compare`) run without booting the Hardhat runtime.\n// Importing `@nomicfoundation/hardhat-ethers` at module scope would call\n// `extendEnvironment` before a Hardhat context exists (HH5), so it is avoided.\n\n// This CLI formats and inspects arbitrary ABI/JSON artifacts and indexes internal\n// selector maps, so `any` and dynamic property access are intentional below.\n/* eslint-disable @typescript-eslint/no-explicit-any, security/detect-object-injection */\n\nconst program = new Command();\n\n// Keep the CLI version in sync with the package version. The relative path\n// resolves to the package root from both src/cli (dev) and dist/cli (published).\nconst { version: pkgVersion } = require('../../package.json');\n\nprogram\n\t.name('diamond-abi')\n\t.description('Diamond ABI generation utilities')\n\t.version(pkgVersion);\n\n// Generate command\nprogram\n\t.command('generate')\n\t.description('Generate ABI for a deployed diamond')\n\t.option('-d, --diamond <name>', 'Diamond name', 'GeniusDiamond')\n\t.option('-n, --network <name>', 'Network name', 'localhost')\n\t.option('-c, --chain-id <id>', 'Chain ID', '31337')\n\t.option('-o, --output <dir>', 'Output directory (overrides diamond config)', undefined)\n\t.option('--deployments-path <path>', 'Deployments path', './diamonds')\n\t.option('--contracts-path <path>', 'Contracts path', './contracts')\n\t.option('--include-source', 'Include source information in ABI', false)\n\t.option('--validate-selectors', 'Validate function selector uniqueness', true)\n\t.option('-v, --verbose', 'Verbose output', false)\n\t.action(async (options) => {\n\t\ttry {\n\t\t\tconsole.log(chalk.blue('šŸ”§ Generating Diamond ABI...'));\n\n\t\t\tconst { generateDiamondAbi } = await import('../utils/diamondAbiGenerator.js');\n\t\t\tconst { Diamond } = await import('../core/Diamond.js');\n\t\t\tconst { FileDeploymentRepository } = await import(\n\t\t\t\t'../repositories/FileDeploymentRepository.js'\n\t\t\t);\n\n\t\t\tconst config: DiamondConfig = {\n\t\t\t\tdiamondName: options.diamond,\n\t\t\t\tnetworkName: options.network,\n\t\t\t\tchainId: parseInt(options.chainId),\n\t\t\t\tdeploymentsPath: options.deploymentsPath,\n\t\t\t\tcontractsPath: options.contractsPath,\n\t\t\t};\n\n\t\t\tif (options.verbose) {\n\t\t\t\tconsole.log(chalk.cyan('šŸ“‹ Configuration:'));\n\t\t\t\tconsole.log(chalk.gray(` Diamond: ${config.diamondName}`));\n\t\t\t\tconsole.log(chalk.gray(` Network: ${config.networkName}`));\n\t\t\t\tconsole.log(chalk.gray(` Chain ID: ${config.chainId}`));\n\t\t\t\tconsole.log(chalk.gray(` Output: ${options.output}`));\n\t\t\t}\n\n\t\t\t// Create diamond instance\n\t\t\tconst repository = new FileDeploymentRepository(config);\n\t\t\tconst diamond: Diamond = new Diamond(config, repository);\n\n\t\t\t// Set provider and signer if available\n\t\t\tawait setupDiamondConnection(diamond, options.verbose);\n\n\t\t\t// Generate ABI using Diamond's configured paths\n\t\t\tconst result = await generateDiamondAbi(diamond, {\n\t\t\t\toutputDir: options.output ?? diamond.getDiamondAbiPath(),\n\t\t\t\tincludeSourceInfo: options.includeSource,\n\t\t\t\tvalidateSelectors: options.validateSelectors,\n\t\t\t\tverbose: options.verbose,\n\t\t\t});\n\n\t\t\tconsole.log(chalk.green('\\nāœ… Diamond ABI generation completed!'));\n\t\t\tdisplayResults(result, options.verbose);\n\t\t} catch (error) {\n\t\t\tconsole.error(chalk.red('āŒ Error generating Diamond ABI:'), error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n\n// Preview command\nprogram\n\t.command('preview')\n\t.description('Preview ABI changes for planned diamond cuts')\n\t.option('-d, --diamond <name>', 'Diamond name', 'GeniusDiamond')\n\t.option('-n, --network <name>', 'Network name', 'localhost')\n\t.option('-c, --chain-id <id>', 'Chain ID', '31337')\n\t.option('--deployments-path <path>', 'Deployments path', './diamonds')\n\t.option('--contracts-path <path>', 'Contracts path', './contracts')\n\t.option('-v, --verbose', 'Verbose output', false)\n\t.action(async (options) => {\n\t\ttry {\n\t\t\tconsole.log(chalk.blue('šŸ” Previewing Diamond ABI changes...'));\n\n\t\t\tconst { generateDiamondAbi, previewDiamondAbi } = await import(\n\t\t\t\t'../utils/diamondAbiGenerator.js'\n\t\t\t);\n\t\t\tconst { Diamond } = await import('../core/Diamond.js');\n\t\t\tconst { FileDeploymentRepository } = await import(\n\t\t\t\t'../repositories/FileDeploymentRepository.js'\n\t\t\t);\n\n\t\t\tconst config: DiamondConfig = {\n\t\t\t\tdiamondName: options.diamond,\n\t\t\t\tnetworkName: options.network,\n\t\t\t\tchainId: parseInt(options.chainId),\n\t\t\t\tdeploymentsPath: options.deploymentsPath,\n\t\t\t\tcontractsPath: options.contractsPath,\n\t\t\t};\n\n\t\t\tconst repository = new FileDeploymentRepository(config);\n\t\t\tconst diamond: Diamond = new Diamond(config, repository);\n\n\t\t\tawait setupDiamondConnection(diamond, options.verbose);\n\n\t\t\t// Get current state\n\t\t\tconst currentResult = await generateDiamondAbi(diamond, {\n\t\t\t\tverbose: false,\n\t\t\t\tincludeSourceInfo: false,\n\t\t\t});\n\n\t\t\tconsole.log(chalk.cyan('\\nšŸ“‹ Current ABI state:'));\n\t\t\tconsole.log(chalk.gray(` Functions: ${currentResult.stats.totalFunctions}`));\n\t\t\tconsole.log(chalk.gray(` Events: ${currentResult.stats.totalEvents}`));\n\t\t\tconsole.log(chalk.gray(` Facets: ${currentResult.stats.facetCount}`));\n\n\t\t\t// Check for planned cuts\n\t\t\tconst registry = diamond.functionSelectorRegistry;\n\t\t\tconst plannedCuts = Array.from(registry.entries())\n\t\t\t\t.filter(([_, entry]) => entry.action !== 0) // Not deployed\n\t\t\t\t.map(([selector, entry]) => ({\n\t\t\t\t\tfacetAddress: entry.address,\n\t\t\t\t\taction: entry.action,\n\t\t\t\t\tfunctionSelectors: [selector],\n\t\t\t\t\tname: entry.facetName,\n\t\t\t\t}));\n\n\t\t\tif (plannedCuts.length === 0) {\n\t\t\t\tconsole.log(\n\t\t\t\t\tchalk.yellow('\\nāš ļø No planned cuts found in function selector registry'),\n\t\t\t\t);\n\t\t\t\tconsole.log(\n\t\t\t\t\tchalk.gray(' Use the diamond deployment system to plan upgrades first.'),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconsole.log(chalk.cyan(`\\nšŸ”„ Found ${plannedCuts.length} planned cuts:`));\n\t\t\tfor (const cut of plannedCuts) {\n\t\t\t\tconst actionName =\n\t\t\t\t\tcut.action === 1 ? 'Add' : cut.action === 2 ? 'Remove' : 'Replace';\n\t\t\t\tconsole.log(\n\t\t\t\t\tchalk.gray(\n\t\t\t\t\t\t` ${actionName}: ${cut.name} (${cut.functionSelectors.length} selectors)`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Preview with planned cuts\n\t\t\tconst previewResult = await previewDiamondAbi(diamond, plannedCuts, {\n\t\t\t\tverbose: options.verbose,\n\t\t\t\tincludeSourceInfo: false,\n\t\t\t});\n\n\t\t\tconsole.log(chalk.green('\\nāœ… ABI preview completed!'));\n\t\t\tconsole.log(chalk.blue('\\nšŸ“Š Preview Results:'));\n\t\t\tconsole.log(\n\t\t\t\tchalk.cyan(` Functions after cuts: ${previewResult.stats.totalFunctions}`),\n\t\t\t);\n\t\t\tconsole.log(chalk.cyan(` Events after cuts: ${previewResult.stats.totalEvents}`));\n\t\t\tconsole.log(chalk.cyan(` Facets after cuts: ${previewResult.stats.facetCount}`));\n\n\t\t\t// Show differences\n\t\t\tconst functionDiff =\n\t\t\t\tpreviewResult.stats.totalFunctions - currentResult.stats.totalFunctions;\n\t\t\tconst facetDiff = previewResult.stats.facetCount - currentResult.stats.facetCount;\n\n\t\t\tif (functionDiff !== 0) {\n\t\t\t\tconst color = functionDiff > 0 ? chalk.green : chalk.red;\n\t\t\t\tconsole.log(\n\t\t\t\t\tcolor(` Function change: ${functionDiff > 0 ? '+' : ''}${functionDiff}`),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (facetDiff !== 0) {\n\t\t\t\tconst color = facetDiff > 0 ? chalk.green : chalk.red;\n\t\t\t\tconsole.log(color(` Facet change: ${facetDiff > 0 ? '+' : ''}${facetDiff}`));\n\t\t\t}\n\n\t\t\tif (options.verbose) {\n\t\t\t\tconsole.log(chalk.blue('\\nšŸŽÆ Planned Function Changes:'));\n\t\t\t\tdisplaySelectorChanges(currentResult.selectorMap, previewResult.selectorMap);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(chalk.red('āŒ Error previewing Diamond ABI:'), error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n\n// Compare command\nprogram\n\t.command('compare')\n\t.description('Compare two diamond ABI files')\n\t.argument('<file1>', 'First ABI file path')\n\t.argument('<file2>', 'Second ABI file path')\n\t.option('-v, --verbose', 'Verbose output', false)\n\t.action(async (file1, file2, options) => {\n\t\ttry {\n\t\t\tconsole.log(chalk.blue('šŸ” Comparing Diamond ABI files...'));\n\n\t\t\tif (!existsSync(file1)) {\n\t\t\t\tthrow new Error(`File not found: ${file1}`);\n\t\t\t}\n\t\t\tif (!existsSync(file2)) {\n\t\t\t\tthrow new Error(`File not found: ${file2}`);\n\t\t\t}\n\n\t\t\tconst abi1 = JSON.parse(require('fs').readFileSync(file1, 'utf8'));\n\t\t\tconst abi2 = JSON.parse(require('fs').readFileSync(file2, 'utf8'));\n\n\t\t\tconsole.log(chalk.cyan(`\\nšŸ“‹ Comparing:`));\n\t\t\tconsole.log(chalk.gray(` File 1: ${file1}`));\n\t\t\tconsole.log(chalk.gray(` File 2: ${file2}`));\n\n\t\t\tconst result1 = analyzeAbi(abi1);\n\t\t\tconst result2 = analyzeAbi(abi2);\n\n\t\t\tconsole.log(chalk.blue('\\nšŸ“Š Comparison Results:'));\n\n\t\t\t// Function comparison\n\t\t\tconst funcDiff = result2.functions - result1.functions;\n\t\t\tconsole.log(\n\t\t\t\tchalk.cyan(`Functions: ${result1.functions} → ${result2.functions} `),\n\t\t\t\tfuncDiff === 0\n\t\t\t\t\t? chalk.gray('(no change)')\n\t\t\t\t\t: funcDiff > 0\n\t\t\t\t\t\t? chalk.green(`(+${funcDiff})`)\n\t\t\t\t\t\t: chalk.red(`(${funcDiff})`),\n\t\t\t);\n\n\t\t\t// Event comparison\n\t\t\tconst eventDiff = result2.events - result1.events;\n\t\t\tconsole.log(\n\t\t\t\tchalk.cyan(`Events: ${result1.events} → ${result2.events} `),\n\t\t\t\teventDiff === 0\n\t\t\t\t\t? chalk.gray('(no change)')\n\t\t\t\t\t: eventDiff > 0\n\t\t\t\t\t\t? chalk.green(`(+${eventDiff})`)\n\t\t\t\t\t\t: chalk.red(`(${eventDiff})`),\n\t\t\t);\n\n\t\t\t// Error comparison\n\t\t\tconst errorDiff = result2.errors - result1.errors;\n\t\t\tconsole.log(\n\t\t\t\tchalk.cyan(`Errors: ${result1.errors} → ${result2.errors} `),\n\t\t\t\terrorDiff === 0\n\t\t\t\t\t? chalk.gray('(no change)')\n\t\t\t\t\t: errorDiff > 0\n\t\t\t\t\t\t? chalk.green(`(+${errorDiff})`)\n\t\t\t\t\t\t: chalk.red(`(${errorDiff})`),\n\t\t\t);\n\n\t\t\tif (options.verbose && abi1._diamondMetadata && abi2._diamondMetadata) {\n\t\t\t\tconsole.log(chalk.blue('\\nšŸ” Detailed Selector Comparison:'));\n\t\t\t\tdisplaySelectorChanges(\n\t\t\t\t\tabi1._diamondMetadata.selectorMap ?? {},\n\t\t\t\t\tabi2._diamondMetadata.selectorMap ?? {},\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(chalk.red('āŒ Error comparing ABI files:'), error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n\n// Validate command\nprogram\n\t.command('validate')\n\t.description('Validate a diamond ABI file')\n\t.argument('<file>', 'ABI file path')\n\t.option('-v, --verbose', 'Verbose output', false)\n\t.action(async (file, options) => {\n\t\ttry {\n\t\t\tconsole.log(chalk.blue('šŸ” Validating Diamond ABI...'));\n\n\t\t\tif (!existsSync(file)) {\n\t\t\t\tthrow new Error(`File not found: ${file}`);\n\t\t\t}\n\n\t\t\tconst artifact = JSON.parse(require('fs').readFileSync(file, 'utf8'));\n\n\t\t\t// Basic structure validation\n\t\t\tconst hasRequiredFields = artifact.abi && artifact.contractName;\n\t\t\tif (!hasRequiredFields) {\n\t\t\t\tthrow new Error('Invalid artifact: missing required fields (abi, contractName)');\n\t\t\t}\n\n\t\t\t// ABI validation with ethers\n\t\t\tconst { Interface } = await import('ethers');\n\t\t\tlet ethersInterface: InstanceType<typeof Interface>;\n\t\t\ttry {\n\t\t\t\tethersInterface = new Interface(artifact.abi);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(`Invalid ABI: ${error}`);\n\t\t\t}\n\n\t\t\tconst analysis = analyzeAbi(artifact);\n\n\t\t\tconsole.log(chalk.green('āœ… ABI validation passed!'));\n\t\t\tconsole.log(chalk.blue('\\nšŸ“Š ABI Analysis:'));\n\t\t\tconsole.log(chalk.cyan(` Functions: ${analysis.functions}`));\n\t\t\tconsole.log(chalk.cyan(` Events: ${analysis.events}`));\n\t\t\tconsole.log(chalk.cyan(` Errors: ${analysis.errors}`));\n\t\t\tconsole.log(chalk.cyan(` Total fragments: ${ethersInterface.fragments.length}`));\n\n\t\t\tif (artifact._diamondMetadata) {\n\t\t\t\tconst metadata = artifact._diamondMetadata;\n\t\t\t\tconsole.log(chalk.blue('\\nšŸ’Ž Diamond Metadata:'));\n\t\t\t\tconsole.log(chalk.cyan(` Diamond: ${metadata.diamondName}`));\n\t\t\t\tconsole.log(chalk.cyan(` Network: ${metadata.networkName}`));\n\t\t\t\tconsole.log(chalk.cyan(` Chain ID: ${metadata.chainId}`));\n\t\t\t\tconsole.log(chalk.cyan(` Generated: ${metadata.generatedAt}`));\n\n\t\t\t\tif (metadata.selectorMap) {\n\t\t\t\t\tconst selectorCount = Object.keys(metadata.selectorMap).length;\n\t\t\t\t\tconst facetCount = new Set(Object.values(metadata.selectorMap)).size;\n\t\t\t\t\tconsole.log(chalk.cyan(` Function selectors: ${selectorCount}`));\n\t\t\t\t\tconsole.log(chalk.cyan(` Facets: ${facetCount}`));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options.verbose) {\n\t\t\t\tconsole.log(chalk.blue('\\nšŸ” Function Signatures:'));\n\t\t\t\tethersInterface.fragments\n\t\t\t\t\t.filter((f: any) => f.type === 'function')\n\t\t\t\t\t.slice(0, 10) // Show first 10\n\t\t\t\t\t.forEach((f: any) => {\n\t\t\t\t\t\tconsole.log(chalk.gray(` ${(f as any).format()}`));\n\t\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\tethersInterface.fragments.filter((f: any) => f.type === 'function').length > 10\n\t\t\t\t) {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\tchalk.gray(\n\t\t\t\t\t\t\t` ... and ${ethersInterface.fragments.filter((f: any) => f.type === 'function').length - 10} more`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(chalk.red('āŒ ABI validation failed:'), error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n\n// Helper functions\nasync function setupDiamondConnection(diamond: Diamond, verbose: boolean): Promise<void> {\n\ttry {\n\t\t// Typed as `any`: the `hre.ethers` helper is added at runtime by the\n\t\t// hardhat-ethers plugin (loaded via the project's hardhat config).\n\t\tconst hre: any = (await import('hardhat')).default;\n\t\tdiamond.setProvider(hre.ethers.provider);\n\t\tconst signers = await hre.ethers.getSigners();\n\t\tif (signers.length > 0) {\n\t\t\tdiamond.setSigner(signers[0]);\n\t\t}\n\n\t\tif (verbose) {\n\t\t\tconsole.log(chalk.gray('āœ… Connected to Hardhat provider'));\n\t\t}\n\t} catch (error) {\n\t\tif (verbose) {\n\t\t\tconsole.log(\n\t\t\t\tchalk.yellow('āš ļø Could not connect to provider (running in standalone mode)'),\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction displayResults(result: any, verbose: boolean): void {\n\tconsole.log(chalk.blue('\\nšŸ“Š Generation Results:'));\n\tconsole.log(chalk.cyan(` Functions: ${result.stats.totalFunctions}`));\n\tconsole.log(chalk.cyan(` Events: ${result.stats.totalEvents}`));\n\tconsole.log(chalk.cyan(` Errors: ${result.stats.totalErrors}`));\n\tconsole.log(chalk.cyan(` Facets: ${result.stats.facetCount}`));\n\n\tif (result.outputPath) {\n\t\tconsole.log(chalk.cyan(` Output: ${result.outputPath}`));\n\t}\n\n\tif (result.stats.duplicateSelectorsSkipped > 0) {\n\t\tconsole.log(\n\t\t\tchalk.yellow(` Duplicates skipped: ${result.stats.duplicateSelectorsSkipped}`),\n\t\t);\n\t}\n\n\tif (verbose && result.selectorMap) {\n\t\tconsole.log(chalk.blue('\\nšŸŽÆ Function Selector Mapping:'));\n\t\tconst sortedSelectors = Object.entries(result.selectorMap).sort(([, a], [, b]) =>\n\t\t\t(a as string).localeCompare(b as string),\n\t\t);\n\t\tsortedSelectors.slice(0, 20).forEach(([selector, facet]) => {\n\t\t\tconsole.log(chalk.gray(` ${selector} → ${facet}`));\n\t\t});\n\n\t\tif (sortedSelectors.length > 20) {\n\t\t\tconsole.log(chalk.gray(` ... and ${sortedSelectors.length - 20} more`));\n\t\t}\n\t}\n}\n\nfunction displaySelectorChanges(\n\toldMap: Record<string, string>,\n\tnewMap: Record<string, string>,\n): void {\n\tconst oldSelectors = new Set(Object.keys(oldMap));\n\tconst newSelectors = new Set(Object.keys(newMap));\n\n\tconst added = Array.from(newSelectors).filter((s) => !oldSelectors.has(s));\n\tconst removed = Array.from(oldSelectors).filter((s) => !newSelectors.has(s));\n\tconst changed = Array.from(oldSelectors).filter(\n\t\t(s) => newSelectors.has(s) && oldMap[s] !== newMap[s],\n\t);\n\n\tif (added.length > 0) {\n\t\tconsole.log(chalk.green(`\\n āž• Added (${added.length}):`));\n\t\tadded.slice(0, 10).forEach((selector) => {\n\t\t\tconsole.log(chalk.gray(` ${selector} → ${newMap[selector]}`));\n\t\t});\n\t\tif (added.length > 10) {\n\t\t\tconsole.log(chalk.gray(` ... and ${added.length - 10} more`));\n\t\t}\n\t}\n\n\tif (removed.length > 0) {\n\t\tconsole.log(chalk.red(`\\n āž– Removed (${removed.length}):`));\n\t\tremoved.slice(0, 10).forEach((selector) => {\n\t\t\tconsole.log(chalk.gray(` ${selector} → ${oldMap[selector]}`));\n\t\t});\n\t\tif (removed.length > 10) {\n\t\t\tconsole.log(chalk.gray(` ... and ${removed.length - 10} more`));\n\t\t}\n\t}\n\n\tif (changed.length > 0) {\n\t\tconsole.log(chalk.yellow(`\\n šŸ”„ Changed (${changed.length}):`));\n\t\tchanged.slice(0, 10).forEach((selector) => {\n\t\t\tconsole.log(chalk.gray(` ${selector}: ${oldMap[selector]} → ${newMap[selector]}`));\n\t\t});\n\t\tif (changed.length > 10) {\n\t\t\tconsole.log(chalk.gray(` ... and ${changed.length - 10} more`));\n\t\t}\n\t}\n\n\tif (added.length === 0 && removed.length === 0 && changed.length === 0) {\n\t\tconsole.log(chalk.gray(' No selector changes detected'));\n\t}\n}\n\nfunction analyzeAbi(artifact: any): { functions: number; events: number; errors: number } {\n\tconst abi = artifact.abi ?? [];\n\treturn {\n\t\tfunctions: abi.filter((item: any) => item.type === 'function').length,\n\t\tevents: abi.filter((item: any) => item.type === 'event').length,\n\t\terrors: abi.filter((item: any) => item.type === 'error').length,\n\t};\n}\n\n// Parse command line arguments\nprogram.parse();\n\nexport {};\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './selectorResolution';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolution/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./selectorResolution"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resolution/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC","sourcesContent":["export * from './selectorResolution';\n"]}
@@ -0,0 +1,65 @@
1
+ import { FunctionSelectorRegistryEntry, NewDeployedFacets } from '../types';
2
+ /**
3
+ * Pure selector-resolution core for ERC-2535 diamond deployments.
4
+ *
5
+ * Extracted from `BaseDeploymentStrategy` (M1-E1) so the resolution semantics can be
6
+ * unit-tested without a chain and later promoted into the shared core used by both the
7
+ * deployment strategy and the planned pre-launch config validator.
8
+ *
9
+ * Lifted from the strategy in M1-E1 (behavior-preserving). Status of the original quirks:
10
+ * - the deploy-time `deployInclude` whitelist — **REMOVED in M2-E1**: `deployInclude` is now
11
+ * **additive** (INV-3); a facet keeps its other selectors (the override is resolved below);
12
+ * - the inverted/dead `registryHigherPrioritySplit` (`entry.priority > priority`) — **REMOVED in
13
+ * M3-E3**: it never matched a real conflict; the cases it nominally handled fall through to the
14
+ * `5b2f7af` Replace branch with the identical result;
15
+ * - the `5b2f7af` `Replace`-instead-of-`Add` branch — **verified correct (M3-E1 S-1)**; kept as-is.
16
+ *
17
+ * The module takes NO Hardhat/provider dependency (only `ethers` for selector math).
18
+ */
19
+ /** Map<functionSelector, registry entry>. Mirrors `Diamond.functionSelectorRegistry`. */
20
+ export type SelectorRegistry = Map<string, FunctionSelectorRegistryEntry>;
21
+ /**
22
+ * Reserved for M3 upgrade/redeploy reconciliation. Today, prior deployed state is carried
23
+ * by the pre-populated `registry` (entries whose action is `Deployed`). Shape aligned to
24
+ * `DeployedDiamondData.DeployedFacets` to minimise adapter code when M3 wires it in.
25
+ */
26
+ export type PriorDeployedState = Record<string, {
27
+ address?: string;
28
+ funcSelectors?: string[];
29
+ version?: number;
30
+ }>;
31
+ /**
32
+ * Compute a facet's candidate selectors: its raw ABI selectors **minus `deployExclude`**.
33
+ *
34
+ * `deployInclude` is **additive** (INV-3, M2-E1) — it does NOT reduce the candidate set; a facet keeps
35
+ * its other selectors. The override (force-ownership over a higher-priority facet) and the additive
36
+ * priority resolution both happen in `resolveFunctionSelectorRegistry`. Pure.
37
+ *
38
+ * @param facetSelectors the facet's raw ABI function selectors (4-byte, `0x…`)
39
+ * @param _deployInclude the facet's `deployInclude` signatures — accepted for API symmetry; additive
40
+ * (not used to filter the candidate set)
41
+ * @param deployExclude function signatures to remove
42
+ * @returns the candidate selector list (a new array; the input is not mutated)
43
+ */
44
+ export declare function computeFacetSelectors(facetSelectors: string[], _deployInclude: string[], deployExclude: string[]): string[];
45
+ export interface ResolveRegistryArgs {
46
+ /** The selector registry to resolve into. Mutated IN PLACE (same contract as before). */
47
+ registry: SelectorRegistry;
48
+ /** The newly-deployed facets (with addresses, priorities, include/exclude, funcSelectors). */
49
+ newDeployedFacets: NewDeployedFacets;
50
+ /** All facet names currently in the deploy config (used to Remove deleted facets). */
51
+ facetNames: string[];
52
+ /**
53
+ * Reserved for M3 upgrade/redeploy reconciliation. Unused today — prior deployed state
54
+ * is carried by the pre-populated `registry` (entries with action `Deployed`).
55
+ */
56
+ priorDeployedState?: PriorDeployedState;
57
+ }
58
+ /**
59
+ * Resolve ownership of every function selector across the newly-deployed facets and write
60
+ * the result (`Add`/`Replace`/`Remove`/`Deployed` actions) into `registry` **in place**.
61
+ * Pure — no Hardhat/provider. Extracted verbatim from
62
+ * `BaseDeploymentStrategy.updateFunctionSelectorRegistryTasks`.
63
+ */
64
+ export declare function resolveFunctionSelectorRegistry(args: ResolveRegistryArgs): void;
65
+ //# sourceMappingURL=selectorResolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectorResolution.d.ts","sourceRoot":"","sources":["../../src/resolution/selectorResolution.ts"],"names":[],"mappings":"AACA,OAAO,EACN,6BAA6B,EAC7B,iBAAiB,EAEjB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;GAgBG;AAEH,yFAAyF;AACzF,MAAM,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CACtC,MAAM,EACN;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAChE,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACpC,cAAc,EAAE,MAAM,EAAE,EACxB,cAAc,EAAE,MAAM,EAAE,EACxB,aAAa,EAAE,MAAM,EAAE,GACrB,MAAM,EAAE,CAaV;AAED,MAAM,WAAW,mBAAmB;IACnC,yFAAyF;IACzF,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,8FAA8F;IAC9F,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,sFAAsF;IACtF,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACxC;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,CA0J/E"}