@diamondslab/diamonds 1.0.0 → 1.1.2

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.
Files changed (71) hide show
  1. package/dist/schemas/DeploymentSchema.d.ts +34 -248
  2. package/dist/schemas/DeploymentSchema.d.ts.map +1 -1
  3. package/package.json +4 -8
  4. package/docs/DIAMOND_ABI_CONFIGURATION_SUMMARY.md +0 -40
  5. package/docs/DIAMOND_ABI_GENERATION.md +0 -220
  6. package/docs/DIAMOND_ABI_GENERATOR_EXAMPLES.md +0 -1204
  7. package/docs/DIAMOND_ABI_GENERATOR_IMPLEMENTATION.md +0 -947
  8. package/docs/DIAMOND_ABI_GENERATOR_QUICK_REFERENCE.md +0 -336
  9. package/docs/README-DEFENDER.md +0 -394
  10. package/docs/README_DIAMOND_ABI_GENERATOR.md +0 -303
  11. package/docs/ROADMAP.md +0 -250
  12. package/docs/assets/image.png +0 -0
  13. package/docs/defender-integration.md +0 -451
  14. package/docs/diamond_module-BaseStrategy_design-v2.uxf +0 -247
  15. package/docs/diamond_module-BaseStrategy_design.uxf +0 -272
  16. package/docs/monitoring-troubleshooting.md +0 -556
  17. package/docs/testing-guide.md +0 -713
  18. package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/callbacks/ERC20ProxyFacet.ts +0 -31
  19. package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/proxydiamond.config.json +0 -27
  20. package/examples/Local_Hardhat_Deployer_Script_example/LocalDiamondDeployer.ts +0 -180
  21. package/examples/OZ_Defender_Deployer_Script_example/OZDiamondDeployer.ts +0 -107
  22. package/examples/OZ_Defender_Deployer_Script_example/run-oz-deploy.ts +0 -17
  23. package/examples/Test_examples/ProxyDiamondDeployment.test.ts +0 -202
  24. package/examples/defender-deployment/.env.example +0 -35
  25. package/examples/defender-deployment/contracts/ExampleDiamond.sol +0 -41
  26. package/examples/defender-deployment/contracts/ExampleFacet1.sol +0 -84
  27. package/examples/defender-deployment/contracts/ExampleFacet2.sol +0 -104
  28. package/examples/defender-deployment/contracts/UpgradeFacet.sol +0 -92
  29. package/examples/defender-deployment/deploy-script.ts +0 -170
  30. package/examples/defender-deployment/diamond-config.json +0 -36
  31. package/examples/defender-deployment/upgrade-script.ts +0 -237
  32. package/examples/hardhat-diamonds-config.example.ts +0 -41
  33. package/src/core/CallbackManager.ts +0 -70
  34. package/src/core/DeploymentManager.ts +0 -64
  35. package/src/core/Diamond.ts +0 -197
  36. package/src/core/DiamondDeployer.ts +0 -36
  37. package/src/core/index.ts +0 -4
  38. package/src/index.ts +0 -5
  39. package/src/repositories/DBDeploymentRepository.ts +0 -22
  40. package/src/repositories/DeploymentRepository.ts +0 -12
  41. package/src/repositories/FileDeploymentRepository.ts +0 -67
  42. package/src/repositories/databaseHandler.ts +0 -14
  43. package/src/repositories/index.ts +0 -4
  44. package/src/repositories/jsonFileHandler.ts +0 -252
  45. package/src/repositories/prismaDBHandler.ts +0 -10
  46. package/src/schemas/DeploymentSchema.ts +0 -71
  47. package/src/schemas/index.ts +0 -1
  48. package/src/strategies/BaseDeploymentStrategy.ts +0 -649
  49. package/src/strategies/DeploymentStrategy.ts +0 -25
  50. package/src/strategies/LocalDeploymentStrategy.ts +0 -5
  51. package/src/strategies/OZDefenderDeploymentStrategy.ts +0 -849
  52. package/src/strategies/RPCDeploymentStrategy.ts +0 -881
  53. package/src/strategies/index.ts +0 -5
  54. package/src/types/config.ts +0 -34
  55. package/src/types/defender.ts +0 -24
  56. package/src/types/deployments.ts +0 -102
  57. package/src/types/index.ts +0 -4
  58. package/src/types/rpc.ts +0 -37
  59. package/src/utils/common.ts +0 -54
  60. package/src/utils/configurationResolver.ts +0 -141
  61. package/src/utils/contractMapping.ts +0 -220
  62. package/src/utils/defenderClients.ts +0 -22
  63. package/src/utils/defenderStore.ts +0 -62
  64. package/src/utils/diamondAbiGenerator.ts +0 -523
  65. package/src/utils/diffDeployedFacets.ts +0 -131
  66. package/src/utils/index.ts +0 -15
  67. package/src/utils/loupe.ts +0 -159
  68. package/src/utils/rpcStore.ts +0 -152
  69. package/src/utils/signer.ts +0 -93
  70. package/src/utils/txlogging.ts +0 -97
  71. package/src/utils/workspaceSetup.ts +0 -315
@@ -1,237 +0,0 @@
1
- import { ethers } from 'hardhat';
2
- import { Diamond } from '../../src/core/Diamond';
3
- import { DiamondDeployer } from '../../src/core/DiamondDeployer';
4
- import { FileDeploymentRepository } from '../../src/repositories/FileDeploymentRepository';
5
- import { OZDefenderDeploymentStrategy } from '../../src/strategies/OZDefenderDeploymentStrategy';
6
- import * as path from 'path';
7
- import * as fs from 'fs-extra';
8
-
9
- async function main() {
10
- console.log('♻️ Starting upgrade process...');
11
-
12
- // Get network information
13
- const network = await ethers.provider.getNetwork();
14
- const signers = await ethers.getSigners();
15
- const deployer = signers[0];
16
-
17
- console.log(`📍 Network: ${network.name} (${network.chainId})`);
18
- console.log(`👤 Deployer: ${deployer.address}`);
19
-
20
- // Load and update configuration
21
- const configPath = path.join(__dirname, 'diamond-config.json');
22
- const deploymentDataPath = path.join(__dirname, 'deployments', `examplediamond-${network.name}-${network.chainId}.json`);
23
-
24
- // Check if initial deployment exists
25
- if (!await fs.pathExists(deploymentDataPath)) {
26
- console.error('❌ No existing deployment found. Please run deploy-script.ts first.');
27
- process.exit(1);
28
- }
29
-
30
- console.log('📄 Loading existing deployment data...');
31
-
32
- // Load current configuration
33
- const config = await fs.readJson(configPath);
34
- const originalVersion = config.protocolVersion;
35
-
36
- console.log(`📊 Current protocol version: ${originalVersion}`);
37
-
38
- // Update configuration for upgrade
39
- config.protocolVersion = 1.0;
40
-
41
- // Add new UpgradeFacet
42
- config.facets['UpgradeFacet'] = {
43
- priority: 50,
44
- versions: {
45
- "1.0": {
46
- deployInit: "initialize()",
47
- callbacks: ["logUpgrade"]
48
- }
49
- }
50
- };
51
-
52
- // Upgrade existing ExampleFacet1 to version 1.0
53
- if (!config.facets['ExampleFacet1'].versions) {
54
- config.facets['ExampleFacet1'].versions = {};
55
- }
56
- config.facets['ExampleFacet1'].versions["1.0"] = {
57
- upgradeInit: "upgradeToV1()",
58
- callbacks: ["validateUpgrade"]
59
- };
60
-
61
- console.log('📝 Updated configuration:');
62
- console.log(` - Protocol version: ${originalVersion} → ${config.protocolVersion}`);
63
- console.log(' - Added UpgradeFacet v1.0');
64
- console.log(' - Upgraded ExampleFacet1 to v1.0');
65
-
66
- // Save updated configuration
67
- await fs.writeJson(configPath, config, { spaces: 2 });
68
-
69
- // Setup diamond configuration
70
- const diamondConfig = {
71
- diamondName: 'ExampleDiamond',
72
- networkName: network.name,
73
- chainId: network.chainId,
74
- deploymentsPath: path.join(__dirname, 'deployments'),
75
- contractsPath: path.join(__dirname, 'contracts'),
76
- callbacksPath: path.join(__dirname, 'callbacks'),
77
- configFilePath: configPath,
78
- deployedDiamondDataFilePath: deploymentDataPath
79
- };
80
-
81
- // Create diamond instance
82
- const repository = new FileDeploymentRepository(diamondConfig);
83
- const diamond = new Diamond(diamondConfig, repository);
84
-
85
- diamond.setProvider(ethers.provider);
86
- diamond.setSigner(deployer);
87
-
88
- // Validate environment variables
89
- const requiredEnvVars = [
90
- 'DEFENDER_API_KEY',
91
- 'DEFENDER_API_SECRET',
92
- 'DEFENDER_RELAYER_ADDRESS',
93
- 'DEFENDER_SAFE_ADDRESS'
94
- ];
95
-
96
- for (const envVar of requiredEnvVars) {
97
- if (!process.env[envVar]) {
98
- console.error(`❌ Missing required environment variable: ${envVar}`);
99
- process.exit(1);
100
- }
101
- }
102
-
103
- // Create Defender strategy
104
- const strategy = new OZDefenderDeploymentStrategy(
105
- process.env.DEFENDER_API_KEY!,
106
- process.env.DEFENDER_API_SECRET!,
107
- process.env.DEFENDER_RELAYER_ADDRESS!,
108
- process.env.AUTO_APPROVE === 'true',
109
- process.env.DEFENDER_SAFE_ADDRESS!,
110
- 'Safe',
111
- true // verbose logging
112
- );
113
-
114
- console.log('🛡️ Defender strategy configured for upgrade');
115
-
116
- // Load existing deployment data to show before state
117
- const existingData = diamond.getDeployedDiamondData();
118
- console.log('\n📊 Pre-upgrade State:');
119
- console.log(`Diamond Address: ${existingData.DiamondAddress}`);
120
- if (existingData.DeployedFacets) {
121
- console.log('Current Facets:');
122
- Object.entries(existingData.DeployedFacets).forEach(([name, facet]) => {
123
- console.log(` ${name}: v${facet.version} at ${facet.address}`);
124
- });
125
- }
126
-
127
- // Execute upgrade
128
- const diamondDeployer = new DiamondDeployer(diamond, strategy);
129
-
130
- try {
131
- console.log('\n🚀 Starting upgrade deployment...');
132
- await diamondDeployer.deployDiamond(); // Automatically detects upgrade scenario
133
-
134
- console.log('\n✅ Upgrade completed successfully!');
135
-
136
- // Output upgrade information
137
- const upgradedData = diamond.getDeployedDiamondData();
138
- console.log('\n📊 Post-upgrade State:');
139
- console.log(`Diamond Address: ${upgradedData.DiamondAddress}`);
140
-
141
- if (upgradedData.DeployedFacets) {
142
- console.log('Updated Facets:');
143
- Object.entries(upgradedData.DeployedFacets).forEach(([name, facet]) => {
144
- const isNew = !existingData.DeployedFacets?.[name];
145
- const isUpgraded = existingData.DeployedFacets?.[name]?.version !== facet.version;
146
-
147
- let status = '';
148
- if (isNew) status = ' [NEW]';
149
- else if (isUpgraded) status = ' [UPGRADED]';
150
-
151
- console.log(` ${name}: v${facet.version} at ${facet.address}${status}`);
152
- });
153
- }
154
-
155
- // Create upgrade summary
156
- const upgradeSummary = {
157
- timestamp: new Date().toISOString(),
158
- network: network.name,
159
- chainId: network.chainId,
160
- deployerAddress: deployer.address,
161
- diamondAddress: upgradedData.DiamondAddress,
162
- upgrade: {
163
- fromVersion: originalVersion,
164
- toVersion: config.protocolVersion,
165
- newFacets: ['UpgradeFacet'],
166
- upgradedFacets: ['ExampleFacet1'],
167
- deploymentMethod: 'OpenZeppelin Defender'
168
- },
169
- facets: upgradedData.DeployedFacets
170
- };
171
-
172
- const summaryPath = path.join(diamondConfig.deploymentsPath, 'upgrade-summary.json');
173
- await fs.writeJson(summaryPath, upgradeSummary, { spaces: 2 });
174
-
175
- console.log(`\n📄 Upgrade summary saved to: ${summaryPath}`);
176
-
177
- // Display next steps
178
- console.log('\n🎯 Next Steps:');
179
- console.log('1. Test new functionality');
180
- console.log('2. Verify upgrade initialization');
181
- console.log('3. Update documentation');
182
- console.log('4. Notify stakeholders');
183
-
184
- if (process.env.AUTO_APPROVE !== 'true') {
185
- console.log('\n⚠️ Note: Auto-approval is disabled. Check your Defender dashboard for pending proposals.');
186
- }
187
-
188
- } catch (error) {
189
- console.error('\n❌ Upgrade failed:', error);
190
-
191
- // Restore original configuration
192
- config.protocolVersion = originalVersion;
193
- delete config.facets['UpgradeFacet'];
194
- if (config.facets['ExampleFacet1'].versions && config.facets['ExampleFacet1'].versions["1.0"]) {
195
- delete config.facets['ExampleFacet1'].versions["1.0"];
196
- }
197
- await fs.writeJson(configPath, config, { spaces: 2 });
198
-
199
- console.log('🔄 Configuration restored to pre-upgrade state');
200
-
201
- // Save error information
202
- const errorInfo = {
203
- timestamp: new Date().toISOString(),
204
- error: error instanceof Error ? {
205
- message: error.message,
206
- stack: error.stack,
207
- name: error.name
208
- } : String(error),
209
- network: network.name,
210
- chainId: network.chainId,
211
- deployerAddress: deployer.address,
212
- attemptedUpgrade: {
213
- fromVersion: originalVersion,
214
- toVersion: 1.0
215
- }
216
- };
217
-
218
- const errorPath = path.join(diamondConfig.deploymentsPath, 'upgrade-error.json');
219
- await fs.writeJson(errorPath, errorInfo, { spaces: 2 });
220
-
221
- console.log(`\n🔍 Error details saved to: ${errorPath}`);
222
-
223
- process.exit(1);
224
- }
225
- }
226
-
227
- // Handle script execution
228
- if (require.main === module) {
229
- main()
230
- .then(() => process.exit(0))
231
- .catch((error) => {
232
- console.error('Unhandled error:', error);
233
- process.exit(1);
234
- });
235
- }
236
-
237
- export { main as upgradeWithDefender };
@@ -1,41 +0,0 @@
1
- // Example hardhat.config.ts extension for hardhat-diamonds integration
2
- // This would be used when the hardhat-diamonds plugin is available
3
-
4
- import { HardhatUserConfig } from "hardhat/config";
5
- import "@nomiclabs/hardhat-waffle";
6
- import "@nomiclabs/hardhat-ethers";
7
- // import "@gnus.ai/hardhat-diamonds"; // When available
8
-
9
- const config: HardhatUserConfig = {
10
- solidity: "0.8.17",
11
-
12
- // Extended configuration for hardhat-diamonds plugin
13
- diamonds: {
14
- // Multiple diamond configurations can be defined
15
- ProxyDiamond: {
16
- deploymentsPath: "./diamonds",
17
- contractsPath: "./contracts",
18
- callbacksPath: "./diamonds/ProxyDiamond/callbacks",
19
- configFilePath: "./diamonds/ProxyDiamond/proxydiamond.config.json",
20
- // Network-specific deployment file paths will be auto-generated
21
- },
22
-
23
- TestDiamond: {
24
- deploymentsPath: "./test-diamonds",
25
- contractsPath: "./test/mocks/contracts",
26
- callbacksPath: "./test-diamonds/TestDiamond/callbacks",
27
- configFilePath: "./test-diamonds/TestDiamond/testdiamond.config.json",
28
- },
29
-
30
- // More diamonds can be configured...
31
- },
32
-
33
- networks: {
34
- hardhat: {
35
- chainId: 31337,
36
- },
37
- // Other networks...
38
- },
39
- };
40
-
41
- export default config;
@@ -1,70 +0,0 @@
1
- import * as fs from "fs-extra";
2
- import { resolve, join } from "path";
3
- import { CallbackArgs } from "../types";
4
-
5
- export class CallbackManager {
6
- private static instances: Map<string, CallbackManager> = new Map();
7
-
8
- private callbacks: Record<string, Record<string, (args: CallbackArgs) => Promise<void>>> = {};
9
-
10
- private constructor(private callbacksPath: string) {
11
- this.loadCallbacks();
12
- }
13
-
14
- public static getInstance(diamondName: string, deploymentsPath: string): CallbackManager {
15
- if (!this.instances.has(diamondName)) {
16
- const callbacksPath = join(deploymentsPath, diamondName, "callbacks");
17
- this.instances.set(diamondName, new CallbackManager(callbacksPath));
18
- }
19
- return this.instances.get(diamondName)!;
20
- }
21
-
22
- public static clearInstances(): void {
23
- this.instances.clear();
24
- }
25
-
26
- public static clearInstance(diamondName: string): void {
27
- this.instances.delete(diamondName);
28
- }
29
-
30
- private loadCallbacks(): void {
31
- if (!fs.existsSync(this.callbacksPath)) {
32
- console.error(`Facet callbacks path "${this.callbacksPath}" does not exist.`);
33
- return;
34
- }
35
-
36
- const files = fs.readdirSync(this.callbacksPath);
37
-
38
- files.forEach(file => {
39
- if (!file.endsWith(".ts") && !file.endsWith(".js")) return;
40
-
41
- const facetName = file.split(".")[0];
42
- const filePath = resolve(this.callbacksPath, file);
43
- const module = require(filePath);
44
-
45
- this.callbacks[facetName] = {};
46
-
47
- Object.entries(module).forEach(([callbackName, callbackFn]) => {
48
- if (typeof callbackFn === 'function') {
49
- this.callbacks[facetName][callbackName] = callbackFn as (args: CallbackArgs) => Promise<void>;
50
- }
51
- });
52
- });
53
- }
54
-
55
- public async executeCallback(facetName: string, callbacks: string[], args: CallbackArgs): Promise<void> {
56
- const registeredCallbacks = this.callbacks[facetName];
57
- for (const callbackName of callbacks) {
58
- if (!registeredCallbacks) {
59
- throw new Error(`Callbacks for facet "${facetName}" not found.`);
60
- }
61
-
62
- const callback = registeredCallbacks[callbackName];
63
- if (!callback) {
64
- throw new Error(`Callback "${callbackName}" for facet "${facetName}" not found.`);
65
- }
66
-
67
- await callback(args);
68
- }
69
- }
70
- }
@@ -1,64 +0,0 @@
1
- import { DeploymentStrategy } from "../strategies/DeploymentStrategy";
2
- import { Diamond } from "./Diamond";
3
-
4
- export class DeploymentManager {
5
- private diamond: Diamond;
6
- private strategy: DeploymentStrategy;
7
-
8
- constructor(diamond: Diamond, strategy: DeploymentStrategy) {
9
- this.diamond = diamond;
10
- this.strategy = strategy;
11
- }
12
-
13
- async deploy(): Promise<void> {
14
- console.log(`🚀 Starting deployment for Diamond: ${this.diamond.diamondName}`);
15
- this.diamond.newDeployment = true;
16
-
17
- await this.strategy.preDeployDiamond(this.diamond);
18
- await this.strategy.deployDiamond(this.diamond);
19
- await this.strategy.postDeployDiamond(this.diamond);
20
-
21
- await this.strategy.preDeployFacets(this.diamond);
22
- await this.strategy.deployFacets(this.diamond);
23
- await this.strategy.postDeployFacets(this.diamond);
24
-
25
- await this.strategy.preUpdateFunctionSelectorRegistry(this.diamond);
26
- await this.strategy.updateFunctionSelectorRegistry(this.diamond);
27
- await this.strategy.postUpdateFunctionSelectorRegistry(this.diamond);
28
-
29
- await this.strategy.prePerformDiamondCut(this.diamond);
30
- await this.strategy.performDiamondCut(this.diamond);
31
- await this.strategy.postPerformDiamondCut(this.diamond);
32
-
33
- await this.strategy.preRunPostDeployCallbacks(this.diamond);
34
- await this.strategy.runPostDeployCallbacks(this.diamond);
35
- await this.strategy.postRunPostDeployCallbacks(this.diamond);
36
-
37
- console.log(`✅ Deployment completed successfully.`);
38
- }
39
-
40
- async upgrade(): Promise<void> {
41
- console.log(`♻️ Starting upgrade for Diamond: ${this.diamond.diamondName}`);
42
-
43
- this.diamond.newDeployment = false;
44
-
45
- await this.strategy.preDeployFacets(this.diamond);
46
- await this.strategy.deployFacets(this.diamond);
47
- await this.strategy.postDeployFacets(this.diamond);
48
-
49
- await this.strategy.preUpdateFunctionSelectorRegistry(this.diamond);
50
- await this.strategy.updateFunctionSelectorRegistry(this.diamond);
51
- await this.strategy.postUpdateFunctionSelectorRegistry(this.diamond);
52
-
53
- await this.strategy.prePerformDiamondCut(this.diamond);
54
- await this.strategy.performDiamondCut(this.diamond);
55
- await this.strategy.postPerformDiamondCut(this.diamond);
56
-
57
- await this.strategy.preRunPostDeployCallbacks(this.diamond);
58
- await this.strategy.runPostDeployCallbacks(this.diamond);
59
- await this.strategy.postRunPostDeployCallbacks(this.diamond);
60
-
61
- console.log(`✅ Upgrade completed successfully.`);
62
- }
63
-
64
- }
@@ -1,197 +0,0 @@
1
- import { join } from "path";
2
- import {
3
- DeployedDiamondData,
4
- DeployedFacets,
5
- DeployedFacet,
6
- DeployConfig,
7
- FacetsConfig
8
- } from "../schemas";
9
- import { CallbackManager } from "./CallbackManager";
10
- import { JsonRpcProvider, Provider } from "@ethersproject/providers";
11
- import { Signer } from "ethers";
12
- import { DeploymentRepository } from "../repositories/DeploymentRepository";
13
- import {
14
- DiamondConfig,
15
- RegistryFacetCutAction,
16
- FunctionSelectorRegistryEntry,
17
- NewDeployedFacets,
18
- NewDeployedFacet
19
- } from "../types";
20
- import { ethers } from "ethers";
21
- import { HardhatEthersProvider } from "@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider";
22
-
23
- export class Diamond {
24
- private static instances: Map<string, Diamond> = new Map();
25
-
26
- public diamondName: string;
27
- public networkName: string;
28
- public chainId: number | bigint;
29
- public deploymentsPath: string;
30
- public contractsPath: string;
31
- public diamondAbiPath: string;
32
- public diamondAbiFileName: string;
33
- public deploymentId: string;
34
- public facetSelectors: string[] = [];
35
- public callbackManager: CallbackManager;
36
- private deployedDiamondData: DeployedDiamondData;
37
- private config: DiamondConfig;
38
- private facetsConfig: FacetsConfig;
39
- private repository: DeploymentRepository;
40
- public signer: Signer | undefined;
41
- public provider: JsonRpcProvider | Provider | HardhatEthersProvider | undefined;
42
- public deployConfig: DeployConfig;
43
- public newDeployment: boolean = true;
44
- public initAddress: string | undefined;
45
-
46
- constructor(config: DiamondConfig, repository: DeploymentRepository) {
47
- this.config = config;
48
- this.diamondName = config.diamondName;
49
- this.networkName = config.networkName || "hardhat";
50
- this.chainId = config.chainId || 31337;
51
- this.deploymentsPath = config.deploymentsPath || "diamonds";
52
- this.contractsPath = config.contractsPath || "contracts";
53
- this.diamondAbiFileName = config.diamondAbiFileName || config.diamondName;
54
-
55
- // Set diamond ABI path - default to diamond-abi subdirectory of configFilePath directory
56
- if (config.diamondAbiPath) {
57
- this.diamondAbiPath = config.diamondAbiPath;
58
- } else {
59
- const configDir = config.configFilePath
60
- ? config.configFilePath.replace(/\/[^\/]*$/, '') // Remove filename from path
61
- : join(this.deploymentsPath, config.diamondName);
62
- this.diamondAbiPath = join(configDir, 'diamond-abi');
63
- }
64
-
65
- this.repository = repository;
66
- this.deploymentId = repository.getDeploymentId();
67
-
68
- // Load existing deployment info
69
- this.deployedDiamondData = this.repository.loadDeployedDiamondData();
70
- this.deployConfig = this.repository.loadDeployConfig();
71
-
72
- this.facetsConfig = this.deployConfig.facets;
73
-
74
- this.callbackManager = CallbackManager.getInstance(
75
- this.diamondName, this.deploymentsPath);
76
-
77
- this._initializeFunctionSelectorRegistry(this);
78
- }
79
-
80
- public functionSelectorRegistry = new Map<string, FunctionSelectorRegistryEntry>();
81
-
82
- private _initializeFunctionSelectorRegistry(
83
- diamond: Diamond
84
- ) {
85
- const diamondConfig: DiamondConfig = diamond.getDiamondConfig();
86
- const deployedDiamondData: DeployedDiamondData = diamond.getDeployedDiamondData();
87
- const deployedFacets: DeployedFacets = deployedDiamondData.DeployedFacets || {};
88
-
89
- for (const [facetName, { address: contractAddress, funcSelectors: selectors }] of Object.entries(deployedFacets)) {
90
- console.log(facetName);
91
- for (const selector of selectors!) {
92
- this.functionSelectorRegistry.set(selector, {
93
- facetName,
94
- priority: this.facetsConfig[facetName]?.priority! || 1000,
95
- address: contractAddress!,
96
- action: RegistryFacetCutAction.Deployed,
97
- });
98
- }
99
- }
100
- }
101
-
102
- public registerFunctionSelectors(selectors: Record<string, Omit<FunctionSelectorRegistryEntry, "selector">>): void {
103
- Object.entries(selectors).forEach(([selector, entry]) => {
104
- this.functionSelectorRegistry.set(selector, entry);
105
- });
106
- }
107
-
108
- public updateFunctionSelectorRegistry(selector: string, entry: FunctionSelectorRegistryEntry): void {
109
- this.functionSelectorRegistry.set(selector, entry);
110
- }
111
-
112
- public isFunctionSelectorRegistered(selector: string): boolean {
113
- return this.functionSelectorRegistry.has(selector);
114
- }
115
-
116
- public newDeployedFacets: NewDeployedFacets = {};
117
-
118
- public getNewDeployedFacets(): NewDeployedFacets {
119
- return this.newDeployedFacets || {};
120
- }
121
-
122
- public updateNewDeployedFacets(facetName: string, facet: NewDeployedFacet): void {
123
- this.newDeployedFacets[facetName] = facet;
124
- }
125
-
126
- getDeployedDiamondData(): DeployedDiamondData {
127
- return this.deployedDiamondData;
128
- }
129
-
130
- setDeployedDiamondData(data: DeployedDiamondData) {
131
- this.deployedDiamondData = data;
132
- }
133
-
134
- updateDeployedDiamondData(data: DeployedDiamondData): void {
135
- this.deployedDiamondData = data;
136
- this.repository.saveDeployedDiamondData(data);
137
- }
138
-
139
- public getDiamondConfig(): DiamondConfig {
140
- return this.config;
141
- }
142
-
143
- public getDeployConfig(): DeployConfig {
144
- return this.deployConfig;
145
- }
146
-
147
- public getFacetsConfig(): FacetsConfig {
148
- return this.facetsConfig;
149
- }
150
-
151
- public setProvider(provider: JsonRpcProvider | Provider | HardhatEthersProvider): void {
152
- this.provider = provider;
153
- }
154
-
155
- public getProvider(): JsonRpcProvider | Provider | HardhatEthersProvider | undefined {
156
- return this.provider;
157
- }
158
-
159
- public setSigner(signer: Signer): void {
160
- this.signer = signer;
161
- }
162
-
163
- public getSigner(): Signer | undefined {
164
- return this.signer;
165
- }
166
-
167
- public isUpgradeDeployment(): boolean {
168
- return !!this.deployedDiamondData.DiamondAddress;
169
- }
170
-
171
- public initializerRegistry: Map<string, string> = new Map();
172
-
173
- public registerInitializers(facetName: string, initFunction: string): void {
174
- this.initializerRegistry.set(facetName, initFunction);
175
- }
176
-
177
- public setInitAddress(initAddress: string): void {
178
- this.initAddress = initAddress;
179
- }
180
- public getInitAddress(): string | undefined {
181
- return this.initAddress;
182
- }
183
-
184
- public getDiamondAbiPath(): string {
185
- return this.diamondAbiPath;
186
- }
187
-
188
- public getDiamondAbiFileName(): string {
189
- return this.diamondAbiFileName;
190
- }
191
-
192
- public getDiamondAbiFilePath(): string {
193
- return join(this.diamondAbiPath, `${this.diamondAbiFileName}.json`);
194
- }
195
- }
196
-
197
- export default Diamond;
@@ -1,36 +0,0 @@
1
- import { Diamond } from './Diamond';
2
- import { DeploymentManager } from './DeploymentManager';
3
- import { DeploymentStrategy } from '../strategies';
4
- import { DeployedDiamondData } from '../schemas';
5
-
6
- export class DiamondDeployer {
7
- // private provider: JsonRpcProvider;
8
- private diamond: Diamond;
9
- private strategy: DeploymentStrategy;
10
-
11
- constructor(
12
- diamond: Diamond,
13
- strategy: DeploymentStrategy
14
- ) {
15
- this.diamond = diamond;
16
- this.strategy = strategy;;
17
- }
18
-
19
- async deployDiamond(): Promise<void> {
20
- const manager = new DeploymentManager(this.diamond, this.strategy);
21
- let deployedDiamondData: DeployedDiamondData;
22
- const deployedData = this.diamond.getDeployedDiamondData();
23
- if (deployedData && deployedData.DiamondAddress) {
24
- deployedDiamondData = deployedData;
25
- console.log(`Diamond already deployed at ${deployedDiamondData.DiamondAddress}. Performing upgrade...`);
26
- await manager.upgrade();
27
- } else {
28
- console.log(`Diamond not previously deployed. Performing initial deployment...`);
29
- await manager.deploy();
30
- }
31
- }
32
-
33
- public getDiamond(): Diamond {
34
- return this.diamond;
35
- }
36
- }
package/src/core/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export { Diamond } from "./Diamond";
2
- export { DiamondDeployer } from "./DiamondDeployer";
3
- export { DeploymentManager } from "./DeploymentManager";
4
- export { CallbackManager } from "./CallbackManager";
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./core";
2
- export * from "./types";
3
- export * from "./strategies";
4
- export * from "./schemas";
5
- export * from "./utils";
@@ -1,22 +0,0 @@
1
- // import {
2
- // readDeployedDiamondData,
3
- // saveDeploymentInfo,
4
- // getDeployConfigData
5
- // } from './databaseHandler';
6
-
7
- // import { DeploymentRepository } from './DeploymentRepository';
8
- // import { DeployedDiamondData, DeployConfig } from '../schemas';
9
-
10
- // export class DbDeploymentRepository implements DeploymentRepository {
11
- // async loadDeployInfo(key: { network: string; diamond: string }): Promise<DeployedDiamondData> {
12
- // return await readDeployedDiamondData(key.network, key.diamond);
13
- // }
14
-
15
- // async saveDeployInfo(key: { network: string; diamond: string }, info: DeployedDiamondData): Promise<void> {
16
- // await saveDeploymentInfo(key.network, key.diamond, info);
17
- // }
18
-
19
- // async loadDeployConfig(key: { projectId: string }): Promise<DeployConfig> {
20
- // return await getDeployConfigData(key.projectId);
21
- // }
22
- // }
@@ -1,12 +0,0 @@
1
- // DeploymentRepository.ts
2
- import { DeployedDiamondData, DeployConfig } from "../schemas";
3
-
4
- export abstract class DeploymentRepository {
5
- abstract loadDeployedDiamondData(): DeployedDiamondData;
6
-
7
- abstract saveDeployedDiamondData(info: DeployedDiamondData): void;
8
-
9
- abstract loadDeployConfig(): DeployConfig;
10
-
11
- abstract getDeploymentId(): string;
12
- }