@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,315 +0,0 @@
1
- import * as fs from 'fs-extra';
2
- import * as path from 'path';
3
- import { ConfigurationResolver } from './configurationResolver';
4
-
5
- /**
6
- * Workspace setup utility for diamonds module
7
- * Supports both standalone and hardhat-diamonds plugin configurations
8
- */
9
- export class WorkspaceSetup {
10
-
11
- /**
12
- * Initialize a new diamond workspace with default structure
13
- */
14
- static async initializeWorkspace(
15
- diamondName: string,
16
- options: {
17
- useHardhatPlugin?: boolean;
18
- contractsPath?: string;
19
- deploymentsPath?: string;
20
- createExampleConfig?: boolean;
21
- } = {}
22
- ): Promise<void> {
23
- const {
24
- useHardhatPlugin = false,
25
- contractsPath = './contracts',
26
- deploymentsPath = './diamonds',
27
- createExampleConfig = true
28
- } = options;
29
-
30
- console.log(`Initializing ${diamondName} workspace...`);
31
-
32
- // Create basic directory structure
33
- const diamondsDir = path.join(process.cwd(), deploymentsPath);
34
- const diamondDir = path.join(diamondsDir, diamondName);
35
- const deploymentsDir = path.join(diamondDir, 'deployments');
36
- const callbacksDir = path.join(diamondDir, 'callbacks');
37
- const contractsDir = path.join(process.cwd(), contractsPath);
38
-
39
- await fs.ensureDir(diamondsDir);
40
- await fs.ensureDir(diamondDir);
41
- await fs.ensureDir(deploymentsDir);
42
- await fs.ensureDir(callbacksDir);
43
- await fs.ensureDir(contractsDir);
44
-
45
- console.log(`✅ Created directory structure for ${diamondName}`);
46
-
47
- // Create default configuration file
48
- if (createExampleConfig) {
49
- await this.createDefaultConfig(diamondName, diamondDir);
50
- }
51
-
52
- // Create example callback file
53
- await this.createExampleCallback(diamondName, callbacksDir);
54
-
55
- // Create example contracts if they don't exist
56
- await this.createExampleContracts(contractsDir);
57
-
58
- // Create hardhat config extension example if requested
59
- if (useHardhatPlugin) {
60
- await this.createHardhatConfigExample(diamondName);
61
- }
62
-
63
- console.log(`✅ ${diamondName} workspace initialized successfully!`);
64
- console.log(`
65
- Configuration files created:
66
- - Diamond config: ${path.join(diamondDir, `${diamondName.toLowerCase()}.config.json`)}
67
- - Callbacks: ${path.join(callbacksDir, 'ExampleFacet.ts')}
68
- - Contracts: ${contractsDir}
69
-
70
- ${useHardhatPlugin ?
71
- '- Hardhat config example: ./hardhat-diamonds-config.example.ts' :
72
- '- Using standalone mode (no hardhat plugin required)'
73
- }
74
-
75
- Next steps:
76
- 1. Customize your diamond configuration in the config file
77
- 2. Add your facet contracts to ${contractsPath}
78
- 3. Implement callback functions in ${path.join(callbacksDir)}
79
- 4. Deploy using: DiamondDeployer with your chosen strategy
80
- `);
81
- }
82
-
83
- /**
84
- * Create a default diamond configuration file
85
- */
86
- private static async createDefaultConfig(diamondName: string, diamondDir: string): Promise<void> {
87
- const configPath = path.join(diamondDir, `${diamondName.toLowerCase()}.config.json`);
88
-
89
- if (await fs.pathExists(configPath)) {
90
- console.log(`⚠️ Configuration file already exists: ${configPath}`);
91
- return;
92
- }
93
-
94
- const defaultConfig = {
95
- protocolVersion: 0.0,
96
- facets: {
97
- DiamondCutFacet: {
98
- priority: 10,
99
- versions: {
100
- "0.0": {}
101
- }
102
- },
103
- DiamondLoupeFacet: {
104
- priority: 20,
105
- versions: {
106
- "0.0": {}
107
- }
108
- },
109
- ExampleFacet: {
110
- priority: 30,
111
- versions: {
112
- "0.0": {
113
- callbacks: ["exampleCallback"],
114
- deployInit: "initialize()",
115
- upgradeInit: "reinitialize()"
116
- }
117
- }
118
- }
119
- }
120
- };
121
-
122
- await fs.writeJson(configPath, defaultConfig, { spaces: 2 });
123
- console.log(`✅ Created default configuration: ${configPath}`);
124
- }
125
-
126
- /**
127
- * Create an example callback file
128
- */
129
- private static async createExampleCallback(diamondName: string, callbacksDir: string): Promise<void> {
130
- const callbackPath = path.join(callbacksDir, 'ExampleFacet.ts');
131
-
132
- if (await fs.pathExists(callbackPath)) {
133
- console.log(`⚠️ Callback file already exists: ${callbackPath}`);
134
- return;
135
- }
136
-
137
- const callbackContent = `import { CallbackArgs } from "../../../src/types";
138
-
139
- /**
140
- * Example callback function for ExampleFacet
141
- * This function will be called after the facet is deployed
142
- */
143
- export async function exampleCallback(args: CallbackArgs) {
144
- const { diamond } = args;
145
-
146
- console.log(\`Running example callback for \${diamond.diamondName} on \${diamond.networkName}\`);
147
-
148
- // Add your post-deployment logic here
149
- // For example:
150
- // - Initialize contract state
151
- // - Set up permissions
152
- // - Configure parameters
153
-
154
- console.log('Example callback completed successfully');
155
- }
156
-
157
- /**
158
- * Initialize function called during initial deployment
159
- */
160
- export async function initialize(args: CallbackArgs) {
161
- const { diamond } = args;
162
- console.log(\`Initializing \${diamond.diamondName}...\`);
163
- // Add initialization logic here
164
- }
165
-
166
- /**
167
- * Reinitialize function called during upgrades
168
- */
169
- export async function reinitialize(args: CallbackArgs) {
170
- const { diamond } = args;
171
- console.log(\`Reinitializing \${diamond.diamondName}...\`);
172
- // Add reinitialization logic here
173
- }
174
- `;
175
-
176
- await fs.writeFile(callbackPath, callbackContent);
177
- console.log(`✅ Created example callback: ${callbackPath}`);
178
- }
179
-
180
- /**
181
- * Create example contract files if they don't exist
182
- */
183
- private static async createExampleContracts(contractsDir: string): Promise<void> {
184
- const exampleFacetPath = path.join(contractsDir, 'ExampleFacet.sol');
185
-
186
- if (await fs.pathExists(exampleFacetPath)) {
187
- console.log(`⚠️ Example contract already exists: ${exampleFacetPath}`);
188
- return;
189
- }
190
-
191
- const exampleFacetContent = `// SPDX-License-Identifier: MIT
192
- pragma solidity ^0.8.0;
193
-
194
- /**
195
- * @title ExampleFacet
196
- * @dev Example facet contract for diamond pattern
197
- */
198
- contract ExampleFacet {
199
- // State variables
200
- uint256 private value;
201
- bool private initialized;
202
-
203
- // Events
204
- event ValueSet(uint256 newValue);
205
- event Initialized();
206
-
207
- /**
208
- * @dev Initialize the facet
209
- */
210
- function initialize() external {
211
- require(!initialized, "Already initialized");
212
- initialized = true;
213
- value = 0;
214
- emit Initialized();
215
- }
216
-
217
- /**
218
- * @dev Reinitialize during upgrades
219
- */
220
- function reinitialize() external {
221
- initialized = true;
222
- emit Initialized();
223
- }
224
-
225
- /**
226
- * @dev Set a value
227
- */
228
- function setValue(uint256 _value) external {
229
- require(initialized, "Not initialized");
230
- value = _value;
231
- emit ValueSet(_value);
232
- }
233
-
234
- /**
235
- * @dev Get the current value
236
- */
237
- function getValue() external view returns (uint256) {
238
- return value;
239
- }
240
-
241
- /**
242
- * @dev Check if initialized
243
- */
244
- function isInitialized() external view returns (bool) {
245
- return initialized;
246
- }
247
- }
248
- `;
249
-
250
- await fs.writeFile(exampleFacetPath, exampleFacetContent);
251
- console.log(`✅ Created example contract: ${exampleFacetPath}`);
252
- }
253
-
254
- /**
255
- * Create hardhat config example for hardhat-diamonds plugin
256
- */
257
- private static async createHardhatConfigExample(diamondName: string): Promise<void> {
258
- const configPath = path.join(process.cwd(), 'hardhat-diamonds-config.example.ts');
259
-
260
- if (await fs.pathExists(configPath)) {
261
- console.log(`⚠️ Hardhat config example already exists: ${configPath}`);
262
- return;
263
- }
264
-
265
- const configContent = `// Example hardhat.config.ts extension for hardhat-diamonds
266
- // Copy this configuration to your hardhat.config.ts when using the hardhat-diamonds plugin
267
-
268
- import { HardhatUserConfig } from "hardhat/config";
269
- import "@nomiclabs/hardhat-waffle";
270
- import "@nomiclabs/hardhat-ethers";
271
- // import "@gnus.ai/hardhat-diamonds"; // Uncomment when plugin is available
272
-
273
- declare module "hardhat/types/config" {
274
- interface HardhatUserConfig {
275
- diamonds?: {
276
- [diamondName: string]: {
277
- deploymentsPath?: string;
278
- contractsPath?: string;
279
- callbacksPath?: string;
280
- configFilePath?: string;
281
- };
282
- };
283
- }
284
- }
285
-
286
- const config: HardhatUserConfig = {
287
- solidity: "0.8.17",
288
-
289
- // Diamond configurations
290
- diamonds: {
291
- ${diamondName}: {
292
- deploymentsPath: "./diamonds",
293
- contractsPath: "./contracts",
294
- callbacksPath: "./diamonds/${diamondName}/callbacks",
295
- configFilePath: "./diamonds/${diamondName}/${diamondName.toLowerCase()}.config.json",
296
- },
297
-
298
- // Add more diamond configurations as needed
299
- },
300
-
301
- networks: {
302
- hardhat: {
303
- chainId: 31337,
304
- },
305
- // Add other networks as needed
306
- },
307
- };
308
-
309
- export default config;
310
- `;
311
-
312
- await fs.writeFile(configPath, configContent);
313
- console.log(`✅ Created Hardhat config example: ${configPath}`);
314
- }
315
- }