@diamondslab/diamonds 1.0.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.
Files changed (229) hide show
  1. package/README.md +618 -0
  2. package/diamonds/README.md +3 -0
  3. package/dist/core/CallbackManager.d.ts +13 -0
  4. package/dist/core/CallbackManager.d.ts.map +1 -0
  5. package/dist/core/CallbackManager.js +95 -0
  6. package/dist/core/CallbackManager.js.map +1 -0
  7. package/dist/core/DeploymentManager.d.ts +10 -0
  8. package/dist/core/DeploymentManager.d.ts.map +1 -0
  9. package/dist/core/DeploymentManager.js +50 -0
  10. package/dist/core/DeploymentManager.js.map +1 -0
  11. package/dist/core/Diamond.d.ts +58 -0
  12. package/dist/core/Diamond.d.ts.map +1 -0
  13. package/dist/core/Diamond.js +146 -0
  14. package/dist/core/Diamond.js.map +1 -0
  15. package/dist/core/DiamondDeployer.d.ts +10 -0
  16. package/dist/core/DiamondDeployer.d.ts.map +1 -0
  17. package/dist/core/DiamondDeployer.js +33 -0
  18. package/dist/core/DiamondDeployer.js.map +1 -0
  19. package/dist/core/index.d.ts +5 -0
  20. package/dist/core/index.d.ts.map +1 -0
  21. package/dist/core/index.js +12 -0
  22. package/dist/core/index.js.map +1 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +22 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/repositories/DBDeploymentRepository.d.ts +1 -0
  28. package/dist/repositories/DBDeploymentRepository.d.ts.map +1 -0
  29. package/dist/repositories/DBDeploymentRepository.js +20 -0
  30. package/dist/repositories/DBDeploymentRepository.js.map +1 -0
  31. package/dist/repositories/DeploymentRepository.d.ts +8 -0
  32. package/dist/repositories/DeploymentRepository.d.ts.map +1 -0
  33. package/dist/repositories/DeploymentRepository.js +7 -0
  34. package/dist/repositories/DeploymentRepository.js.map +1 -0
  35. package/dist/repositories/FileDeploymentRepository.d.ts +18 -0
  36. package/dist/repositories/FileDeploymentRepository.d.ts.map +1 -0
  37. package/dist/repositories/FileDeploymentRepository.js +58 -0
  38. package/dist/repositories/FileDeploymentRepository.js.map +1 -0
  39. package/dist/repositories/databaseHandler.d.ts +1 -0
  40. package/dist/repositories/databaseHandler.d.ts.map +1 -0
  41. package/dist/repositories/databaseHandler.js +13 -0
  42. package/dist/repositories/databaseHandler.js.map +1 -0
  43. package/dist/repositories/index.d.ts +4 -0
  44. package/dist/repositories/index.d.ts.map +1 -0
  45. package/dist/repositories/index.js +20 -0
  46. package/dist/repositories/index.js.map +1 -0
  47. package/dist/repositories/jsonFileHandler.d.ts +81 -0
  48. package/dist/repositories/jsonFileHandler.d.ts.map +1 -0
  49. package/dist/repositories/jsonFileHandler.js +223 -0
  50. package/dist/repositories/jsonFileHandler.js.map +1 -0
  51. package/dist/repositories/prismaDBHandler.d.ts +1 -0
  52. package/dist/repositories/prismaDBHandler.d.ts.map +1 -0
  53. package/dist/repositories/prismaDBHandler.js +11 -0
  54. package/dist/repositories/prismaDBHandler.js.map +1 -0
  55. package/dist/schemas/DeploymentSchema.d.ts +309 -0
  56. package/dist/schemas/DeploymentSchema.d.ts.map +1 -0
  57. package/dist/schemas/DeploymentSchema.js +56 -0
  58. package/dist/schemas/DeploymentSchema.js.map +1 -0
  59. package/dist/schemas/index.d.ts +2 -0
  60. package/dist/schemas/index.d.ts.map +1 -0
  61. package/dist/schemas/index.js +18 -0
  62. package/dist/schemas/index.js.map +1 -0
  63. package/dist/strategies/BaseDeploymentStrategy.d.ts +41 -0
  64. package/dist/strategies/BaseDeploymentStrategy.d.ts.map +1 -0
  65. package/dist/strategies/BaseDeploymentStrategy.js +545 -0
  66. package/dist/strategies/BaseDeploymentStrategy.js.map +1 -0
  67. package/dist/strategies/DeploymentStrategy.d.ts +19 -0
  68. package/dist/strategies/DeploymentStrategy.d.ts.map +1 -0
  69. package/dist/strategies/DeploymentStrategy.js +3 -0
  70. package/dist/strategies/DeploymentStrategy.js.map +1 -0
  71. package/dist/strategies/LocalDeploymentStrategy.d.ts +4 -0
  72. package/dist/strategies/LocalDeploymentStrategy.d.ts.map +1 -0
  73. package/dist/strategies/LocalDeploymentStrategy.js +8 -0
  74. package/dist/strategies/LocalDeploymentStrategy.js.map +1 -0
  75. package/dist/strategies/OZDefenderDeploymentStrategy.d.ts +62 -0
  76. package/dist/strategies/OZDefenderDeploymentStrategy.d.ts.map +1 -0
  77. package/dist/strategies/OZDefenderDeploymentStrategy.js +757 -0
  78. package/dist/strategies/OZDefenderDeploymentStrategy.js.map +1 -0
  79. package/dist/strategies/RPCDeploymentStrategy.d.ts +139 -0
  80. package/dist/strategies/RPCDeploymentStrategy.d.ts.map +1 -0
  81. package/dist/strategies/RPCDeploymentStrategy.js +710 -0
  82. package/dist/strategies/RPCDeploymentStrategy.js.map +1 -0
  83. package/dist/strategies/index.d.ts +6 -0
  84. package/dist/strategies/index.d.ts.map +1 -0
  85. package/dist/strategies/index.js +12 -0
  86. package/dist/strategies/index.js.map +1 -0
  87. package/dist/types/config.d.ts +26 -0
  88. package/dist/types/config.d.ts.map +1 -0
  89. package/dist/types/config.js +3 -0
  90. package/dist/types/config.js.map +1 -0
  91. package/dist/types/defender.d.ts +22 -0
  92. package/dist/types/defender.d.ts.map +1 -0
  93. package/dist/types/defender.js +3 -0
  94. package/dist/types/defender.js.map +1 -0
  95. package/dist/types/deployments.d.ts +71 -0
  96. package/dist/types/deployments.d.ts.map +1 -0
  97. package/dist/types/deployments.js +20 -0
  98. package/dist/types/deployments.js.map +1 -0
  99. package/dist/types/index.d.ts +5 -0
  100. package/dist/types/index.d.ts.map +1 -0
  101. package/dist/types/index.js +21 -0
  102. package/dist/types/index.js.map +1 -0
  103. package/dist/types/rpc.d.ts +35 -0
  104. package/dist/types/rpc.d.ts.map +1 -0
  105. package/dist/types/rpc.js +3 -0
  106. package/dist/types/rpc.js.map +1 -0
  107. package/dist/utils/common.d.ts +20 -0
  108. package/dist/utils/common.d.ts.map +1 -0
  109. package/dist/utils/common.js +45 -0
  110. package/dist/utils/common.js.map +1 -0
  111. package/dist/utils/configurationResolver.d.ts +30 -0
  112. package/dist/utils/configurationResolver.d.ts.map +1 -0
  113. package/dist/utils/configurationResolver.js +151 -0
  114. package/dist/utils/configurationResolver.js.map +1 -0
  115. package/dist/utils/contractMapping.d.ts +29 -0
  116. package/dist/utils/contractMapping.d.ts.map +1 -0
  117. package/dist/utils/contractMapping.js +224 -0
  118. package/dist/utils/contractMapping.js.map +1 -0
  119. package/dist/utils/defenderClients.d.ts +5 -0
  120. package/dist/utils/defenderClients.d.ts.map +1 -0
  121. package/dist/utils/defenderClients.js +21 -0
  122. package/dist/utils/defenderClients.js.map +1 -0
  123. package/dist/utils/defenderStore.d.ts +14 -0
  124. package/dist/utils/defenderStore.d.ts.map +1 -0
  125. package/dist/utils/defenderStore.js +92 -0
  126. package/dist/utils/defenderStore.js.map +1 -0
  127. package/dist/utils/diamondAbiGenerator.d.ts +113 -0
  128. package/dist/utils/diamondAbiGenerator.d.ts.map +1 -0
  129. package/dist/utils/diamondAbiGenerator.js +415 -0
  130. package/dist/utils/diamondAbiGenerator.js.map +1 -0
  131. package/dist/utils/diffDeployedFacets.d.ts +26 -0
  132. package/dist/utils/diffDeployedFacets.d.ts.map +1 -0
  133. package/dist/utils/diffDeployedFacets.js +106 -0
  134. package/dist/utils/diffDeployedFacets.js.map +1 -0
  135. package/dist/utils/index.d.ts +16 -0
  136. package/dist/utils/index.d.ts.map +1 -0
  137. package/dist/utils/index.js +35 -0
  138. package/dist/utils/index.js.map +1 -0
  139. package/dist/utils/loupe.d.ts +44 -0
  140. package/dist/utils/loupe.d.ts.map +1 -0
  141. package/dist/utils/loupe.js +128 -0
  142. package/dist/utils/loupe.js.map +1 -0
  143. package/dist/utils/rpcStore.d.ts +36 -0
  144. package/dist/utils/rpcStore.d.ts.map +1 -0
  145. package/dist/utils/rpcStore.js +166 -0
  146. package/dist/utils/rpcStore.js.map +1 -0
  147. package/dist/utils/signer.d.ts +36 -0
  148. package/dist/utils/signer.d.ts.map +1 -0
  149. package/dist/utils/signer.js +91 -0
  150. package/dist/utils/signer.js.map +1 -0
  151. package/dist/utils/txlogging.d.ts +13 -0
  152. package/dist/utils/txlogging.d.ts.map +1 -0
  153. package/dist/utils/txlogging.js +87 -0
  154. package/dist/utils/txlogging.js.map +1 -0
  155. package/dist/utils/workspaceSetup.d.ts +32 -0
  156. package/dist/utils/workspaceSetup.d.ts.map +1 -0
  157. package/dist/utils/workspaceSetup.js +311 -0
  158. package/dist/utils/workspaceSetup.js.map +1 -0
  159. package/docs/DIAMOND_ABI_CONFIGURATION_SUMMARY.md +40 -0
  160. package/docs/DIAMOND_ABI_GENERATION.md +220 -0
  161. package/docs/DIAMOND_ABI_GENERATOR_EXAMPLES.md +1204 -0
  162. package/docs/DIAMOND_ABI_GENERATOR_IMPLEMENTATION.md +947 -0
  163. package/docs/DIAMOND_ABI_GENERATOR_QUICK_REFERENCE.md +336 -0
  164. package/docs/README-DEFENDER.md +394 -0
  165. package/docs/README_DIAMOND_ABI_GENERATOR.md +303 -0
  166. package/docs/ROADMAP.md +250 -0
  167. package/docs/assets/image.png +0 -0
  168. package/docs/defender-integration.md +451 -0
  169. package/docs/diamond_module-BaseStrategy_design-v2.uxf +247 -0
  170. package/docs/diamond_module-BaseStrategy_design.uxf +272 -0
  171. package/docs/monitoring-troubleshooting.md +556 -0
  172. package/docs/testing-guide.md +713 -0
  173. package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/callbacks/ERC20ProxyFacet.ts +31 -0
  174. package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/proxydiamond.config.json +27 -0
  175. package/examples/Local_Hardhat_Deployer_Script_example/LocalDiamondDeployer.ts +180 -0
  176. package/examples/OZ_Defender_Deployer_Script_example/OZDiamondDeployer.ts +107 -0
  177. package/examples/OZ_Defender_Deployer_Script_example/run-oz-deploy.ts +17 -0
  178. package/examples/Test_examples/ProxyDiamondDeployment.test.ts +202 -0
  179. package/examples/defender-deployment/.env.example +35 -0
  180. package/examples/defender-deployment/README.md +415 -0
  181. package/examples/defender-deployment/contracts/ExampleDiamond.sol +41 -0
  182. package/examples/defender-deployment/contracts/ExampleFacet1.sol +84 -0
  183. package/examples/defender-deployment/contracts/ExampleFacet2.sol +104 -0
  184. package/examples/defender-deployment/contracts/UpgradeFacet.sol +92 -0
  185. package/examples/defender-deployment/deploy-script.ts +170 -0
  186. package/examples/defender-deployment/diamond-config.json +36 -0
  187. package/examples/defender-deployment/upgrade-script.ts +237 -0
  188. package/examples/hardhat-diamonds-config.example.ts +41 -0
  189. package/package.json +228 -0
  190. package/src/core/CallbackManager.ts +70 -0
  191. package/src/core/DeploymentManager.ts +64 -0
  192. package/src/core/Diamond.ts +197 -0
  193. package/src/core/DiamondDeployer.ts +36 -0
  194. package/src/core/index.ts +4 -0
  195. package/src/index.ts +5 -0
  196. package/src/repositories/DBDeploymentRepository.ts +22 -0
  197. package/src/repositories/DeploymentRepository.ts +12 -0
  198. package/src/repositories/FileDeploymentRepository.ts +67 -0
  199. package/src/repositories/databaseHandler.ts +14 -0
  200. package/src/repositories/index.ts +4 -0
  201. package/src/repositories/jsonFileHandler.ts +252 -0
  202. package/src/repositories/prismaDBHandler.ts +10 -0
  203. package/src/schemas/DeploymentSchema.ts +71 -0
  204. package/src/schemas/index.ts +1 -0
  205. package/src/strategies/BaseDeploymentStrategy.ts +649 -0
  206. package/src/strategies/DeploymentStrategy.ts +25 -0
  207. package/src/strategies/LocalDeploymentStrategy.ts +5 -0
  208. package/src/strategies/OZDefenderDeploymentStrategy.ts +849 -0
  209. package/src/strategies/RPCDeploymentStrategy.ts +881 -0
  210. package/src/strategies/index.ts +5 -0
  211. package/src/types/config.ts +34 -0
  212. package/src/types/defender.ts +24 -0
  213. package/src/types/deployments.ts +102 -0
  214. package/src/types/index.ts +4 -0
  215. package/src/types/rpc.ts +37 -0
  216. package/src/utils/common.ts +54 -0
  217. package/src/utils/configurationResolver.ts +141 -0
  218. package/src/utils/contractMapping.ts +220 -0
  219. package/src/utils/defenderClients.ts +22 -0
  220. package/src/utils/defenderStore.ts +62 -0
  221. package/src/utils/diamondAbiGenerator.ts +523 -0
  222. package/src/utils/diffDeployedFacets.ts +131 -0
  223. package/src/utils/index.ts +15 -0
  224. package/src/utils/loupe.ts +159 -0
  225. package/src/utils/rpcStore.ts +152 -0
  226. package/src/utils/signer.ts +93 -0
  227. package/src/utils/txlogging.ts +97 -0
  228. package/src/utils/workspaceSetup.ts +315 -0
  229. package/test/README.md +136 -0
package/README.md ADDED
@@ -0,0 +1,618 @@
1
+ # Diamonds Module
2
+
3
+ [![npm version](https://badge.fury.io/js/@geniusventures%2Fdiamonds.svg)](https://badge.fury.io/js/@geniusventures%2Fdiamonds)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
+ [![Hardhat](https://img.shields.io/badge/Hardhat-2.19+-orange.svg)](https://hardhat.org/)
7
+
8
+ A comprehensive TypeScript framework for deploying, upgrading, and managing ERC-2535 Diamond Proxy contracts with enterprise-grade features including OpenZeppelin Defender integration, sophisticated version management, and flexible deployment strategies.
9
+
10
+ ## ✨ Key Features
11
+
12
+ ### 🏗️ **Complete Diamond Implementation**
13
+
14
+ - Full ERC-2535 Diamond Proxy Standard support
15
+ - Modular facet architecture with automated function selector management
16
+ - Smart collision detection and resolution
17
+ - Comprehensive state management and validation
18
+
19
+ ### 🛡️ **Enterprise Security**
20
+
21
+ - **OpenZeppelin Defender Integration**: Secure deployments through Defender's infrastructure
22
+ - **Multi-signature Support**: Gnosis Safe and custom multisig workflows
23
+ - **Automated Verification**: Contract verification on Etherscan and other explorers
24
+ - **Access Control**: Role-based deployment permissions
25
+
26
+ ### 🔄 **Advanced Deployment Management**
27
+
28
+ - **Strategy Pattern**: Pluggable deployment strategies (Local, Defender, Custom)
29
+ - **Version Control**: Sophisticated versioning for facets and protocols
30
+ - **Upgrade Automation**: Intelligent upgrade detection and execution
31
+ - **Rollback Support**: Safe rollback mechanisms
32
+
33
+ ### 🏭 **Production Ready**
34
+
35
+ - **Repository Pattern**: Flexible data persistence (File-based, Database-ready)
36
+ - **Configuration Management**: JSON-based configuration with validation
37
+ - **Comprehensive Testing**: Unit, integration, and end-to-end test suites
38
+ - **CLI Tools**: Command-line interface for deployment operations
39
+
40
+ ## 🚀 Quick Start
41
+
42
+ ### Installation
43
+
44
+ ```bash
45
+ npm install @geniusventures/diamonds
46
+ ```
47
+
48
+ ### Basic Usage
49
+
50
+ ```typescript
51
+ import { Diamond, DiamondDeployer, FileDeploymentRepository } from '@geniusventures/diamonds';
52
+ import { LocalDeploymentStrategy } from '@geniusventures/diamonds/strategies';
53
+ import { ethers } from 'hardhat';
54
+
55
+ // Create diamond configuration
56
+ const config = {
57
+ diamondName: 'MyDiamond',
58
+ networkName: 'localhost',
59
+ chainId: 31337,
60
+ deploymentsPath: './diamonds',
61
+ contractsPath: './contracts'
62
+ };
63
+
64
+ // Setup diamond and deployment components
65
+ const repository = new FileDeploymentRepository(config);
66
+ const diamond = new Diamond(config, repository);
67
+
68
+ // Set provider and signer
69
+ diamond.setProvider(ethers.provider);
70
+ diamond.setSigner(await ethers.getSigners()[0]);
71
+
72
+ // Deploy using local strategy
73
+ const strategy = new LocalDeploymentStrategy(true); // verbose logging
74
+ const deployer = new DiamondDeployer(diamond, strategy);
75
+
76
+ await deployer.deployDiamond();
77
+ ```
78
+
79
+ ## 📋 Project Structure
80
+
81
+ ```bash
82
+ diamonds/
83
+ ├── src/ # Source code
84
+ │ ├── core/ # Core classes
85
+ │ │ ├── Diamond.ts # Main diamond management
86
+ │ │ ├── DiamondDeployer.ts # Deployment orchestration
87
+ │ │ ├── DeploymentManager.ts # Deployment lifecycle
88
+ │ │ └── CallbackManager.ts # Post-deployment callbacks
89
+ │ ├── strategies/ # Deployment strategies
90
+ │ │ ├── BaseDeploymentStrategy.ts
91
+ │ │ ├── LocalDeploymentStrategy.ts
92
+ │ │ └── OZDefenderDeploymentStrategy.ts
93
+ │ ├── repositories/ # Data persistence
94
+ │ │ ├── DeploymentRepository.ts
95
+ │ │ ├── FileDeploymentRepository.ts
96
+ │ │ └── jsonFileHandler.ts
97
+ │ ├── schemas/ # Zod validation schemas
98
+ │ │ └── DeploymentSchema.ts
99
+ │ ├── types/ # TypeScript definitions
100
+ │ ├── utils/ # Utility functions
101
+ │ └── helpers/ # Helper functions
102
+ ├── docs/ # Documentation
103
+ ├── examples/ # Usage examples
104
+ ├── test/ # Test suites
105
+ └── scripts/ # CLI and utility scripts
106
+ ```
107
+
108
+ ## 🔧 Configuration
109
+
110
+ ### Diamond Configuration
111
+
112
+ Create a diamond configuration file (`myDiamond.config.json`):
113
+
114
+ ```json
115
+ {
116
+ "protocolVersion": 1.0,
117
+ "protocolInitFacet": "MyProtocolFacet",
118
+ "facets": {
119
+ "DiamondCutFacet": {
120
+ "priority": 10,
121
+ "versions": {
122
+ "1.0": {}
123
+ }
124
+ },
125
+ "DiamondLoupeFacet": {
126
+ "priority": 20,
127
+ "versions": {
128
+ "1.0": {}
129
+ }
130
+ },
131
+ "MyCustomFacet": {
132
+ "priority": 30,
133
+ "versions": {
134
+ "1.0": {
135
+ "deployInit": "initialize()",
136
+ "upgradeInit": "upgradeToV1()",
137
+ "callbacks": ["postDeployCallback"],
138
+ "deployInclude": ["0x12345678"],
139
+ "deployExclude": ["0x87654321"]
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ### Environment Configuration
148
+
149
+ ```bash
150
+ # Network Configuration
151
+ NETWORK_NAME=sepolia
152
+ CHAIN_ID=11155111
153
+ RPC_URL=https://sepolia.infura.io/v3/YOUR_KEY
154
+
155
+ # OpenZeppelin Defender (Optional)
156
+ DEFENDER_API_KEY=your_api_key
157
+ DEFENDER_API_SECRET=your_api_secret
158
+ DEFENDER_RELAYER_ADDRESS=0x...
159
+ DEFENDER_SAFE_ADDRESS=0x...
160
+
161
+ # Deployment Options
162
+ AUTO_APPROVE_DEFENDER_PROPOSALS=false
163
+ VERBOSE_DEPLOYMENT=true
164
+ ```
165
+
166
+ ## 🛡️ OpenZeppelin Defender Integration
167
+
168
+ The Diamonds module provides seamless integration with OpenZeppelin Defender for enterprise-grade deployments.
169
+
170
+ ### Setup Defender
171
+
172
+ 1. **Create Defender Account**: Visit [OpenZeppelin Defender](https://defender.openzeppelin.com/)
173
+ 2. **Generate API Credentials**: Create API keys with Deploy and Admin permissions
174
+ 3. **Configure Environment**: Set your API credentials in `.env`
175
+
176
+ ### Deploy with Defender
177
+
178
+ ```typescript
179
+ import { OZDefenderDeploymentStrategy } from '@geniusventures/diamonds/strategies';
180
+
181
+ const strategy = new OZDefenderDeploymentStrategy(
182
+ process.env.DEFENDER_API_KEY!,
183
+ process.env.DEFENDER_API_SECRET!,
184
+ process.env.DEFENDER_RELAYER_ADDRESS!,
185
+ false, // manual approval for production
186
+ process.env.DEFENDER_SAFE_ADDRESS!,
187
+ 'Safe'
188
+ );
189
+
190
+ const deployer = new DiamondDeployer(diamond, strategy);
191
+ await deployer.deployDiamond();
192
+ ```
193
+
194
+ ### Features
195
+
196
+ - **Secure Deployments**: All deployments go through Defender's secure infrastructure
197
+ - **Multi-signature Support**: Integrate with Gnosis Safe for production deployments
198
+ - **Automated Monitoring**: Real-time deployment tracking and status updates
199
+ - **Gas Optimization**: Automatic gas price optimization and retry logic
200
+
201
+ ## 🔄 Deployment Strategies
202
+
203
+ ### Local Strategy
204
+
205
+ For development and testing:
206
+
207
+ ```typescript
208
+ import { LocalDeploymentStrategy } from '@geniusventures/diamonds/strategies';
209
+
210
+ const strategy = new LocalDeploymentStrategy(true); // verbose logging
211
+ ```
212
+
213
+ ### Defender Strategy
214
+
215
+ For production deployments:
216
+
217
+ ```typescript
218
+ import { OZDefenderDeploymentStrategy } from '@geniusventures/diamonds/strategies';
219
+
220
+ const strategy = new OZDefenderDeploymentStrategy(
221
+ apiKey,
222
+ apiSecret,
223
+ relayerAddress,
224
+ autoApprove,
225
+ viaAddress,
226
+ viaType,
227
+ verbose
228
+ );
229
+ ```
230
+
231
+ ### Custom Strategy
232
+
233
+ Implement your own deployment strategy:
234
+
235
+ ```typescript
236
+ import { BaseDeploymentStrategy } from '@geniusventures/diamonds/strategies';
237
+
238
+ export class CustomDeploymentStrategy extends BaseDeploymentStrategy {
239
+ protected async deployDiamondTasks(diamond: Diamond): Promise<void> {
240
+ // Custom deployment logic
241
+ }
242
+
243
+ protected async performDiamondCutTasks(diamond: Diamond): Promise<void> {
244
+ // Custom diamond cut logic
245
+ }
246
+ }
247
+ ```
248
+
249
+ ## 📊 Advanced Features
250
+
251
+ ### Version Management
252
+
253
+ The Diamonds module provides sophisticated version management:
254
+
255
+ ```json
256
+ {
257
+ "facets": {
258
+ "MyFacet": {
259
+ "priority": 100,
260
+ "versions": {
261
+ "1.0": {
262
+ "deployInit": "initialize()",
263
+ "upgradeInit": "upgradeToV1()"
264
+ },
265
+ "2.0": {
266
+ "deployInit": "initialize()",
267
+ "upgradeInit": "upgradeToV2()",
268
+ "fromVersions": [1.0]
269
+ }
270
+ }
271
+ }
272
+ }
273
+ }
274
+ ```
275
+
276
+ ### Function Selector Management
277
+
278
+ Automatic function selector management with collision detection:
279
+
280
+ - **Priority-based Resolution**: Higher priority facets take precedence
281
+ - **Include/Exclude Lists**: Fine-grained control over function selectors
282
+ - **Collision Detection**: Automatic detection and resolution of selector conflicts
283
+ - **Orphaned Selector Prevention**: Validation to prevent deployment issues
284
+
285
+ ### Post-Deployment Callbacks
286
+
287
+ Execute custom logic after deployment:
288
+
289
+ ```typescript
290
+ // In your callbacks directory
291
+ export async function postDeployCallback(args: CallbackArgs) {
292
+ const { diamond } = args;
293
+ console.log(`Post-deployment callback executed for ${diamond.diamondName}`);
294
+
295
+ // Custom post-deployment logic
296
+ await customInitialization();
297
+ }
298
+ ```
299
+
300
+ ## 🧪 Testing
301
+
302
+ ### Running Tests
303
+
304
+ ```bash
305
+ # Install dependencies
306
+ npm install
307
+
308
+ # Run all tests
309
+ npm test
310
+
311
+ # Run unit tests only
312
+ npm run test:unit
313
+
314
+ # Run integration tests
315
+ npm run test:integration
316
+
317
+ # Run with coverage
318
+ npm run test:coverage
319
+
320
+ # Test specific network
321
+ TEST_NETWORK=sepolia npm test
322
+ ```
323
+
324
+ ### Test Categories
325
+
326
+ - **Unit Tests**: Individual component testing
327
+ - **Integration Tests**: Component interaction testing
328
+ - **Defender Integration**: End-to-end Defender testing
329
+ - **Performance Tests**: Deployment speed and resource usage
330
+
331
+ ### Example Test
332
+
333
+ ```typescript
334
+ describe('Diamond Deployment', () => {
335
+ let diamond: Diamond;
336
+ let strategy: LocalDeploymentStrategy;
337
+
338
+ beforeEach(() => {
339
+ const config = {
340
+ diamondName: 'TestDiamond',
341
+ networkName: 'hardhat',
342
+ chainId: 31337,
343
+ deploymentsPath: './test-diamonds',
344
+ contractsPath: './contracts'
345
+ };
346
+
347
+ const repository = new FileDeploymentRepository(config);
348
+ diamond = new Diamond(config, repository);
349
+ strategy = new LocalDeploymentStrategy();
350
+ });
351
+
352
+ it('should deploy diamond successfully', async () => {
353
+ const deployer = new DiamondDeployer(diamond, strategy);
354
+ await deployer.deployDiamond();
355
+
356
+ const deployedData = diamond.getDeployedDiamondData();
357
+ expect(deployedData.DiamondAddress).to.not.be.undefined;
358
+ });
359
+ });
360
+ ```
361
+
362
+ ## 🛠️ CLI Tools
363
+
364
+ The Diamonds module includes a comprehensive CLI for deployment management:
365
+
366
+ ```bash
367
+ # Install CLI globally
368
+ npm install -g @geniusventures/diamonds
369
+
370
+ # Deploy a diamond
371
+ diamonds deploy --diamond MyDiamond --network sepolia
372
+
373
+ # Upgrade a diamond
374
+ diamonds upgrade --diamond MyDiamond
375
+
376
+ # Check deployment status
377
+ diamonds status --diamond MyDiamond
378
+
379
+ # Verify contracts
380
+ diamonds verify --diamond MyDiamond
381
+
382
+ # Initialize new project
383
+ diamonds init --diamond MyNewDiamond --network mainnet
384
+ ```
385
+
386
+ ### CLI Options
387
+
388
+ - `--diamond <name>`: Diamond name
389
+ - `--network <name>`: Target network
390
+ - `--config <path>`: Configuration file path
391
+ - `--auto-approve`: Auto-approve Defender proposals
392
+ - `--verbose`: Verbose output
393
+ - `--batch <path>`: Batch deployment configuration
394
+
395
+ ## 📖 Examples
396
+
397
+ ### Basic Diamond Deployment
398
+
399
+ ```typescript
400
+ import { Diamond, DiamondDeployer, FileDeploymentRepository } from '@geniusventures/diamonds';
401
+ import { LocalDeploymentStrategy } from '@geniusventures/diamonds/strategies';
402
+
403
+ async function deployBasicDiamond() {
404
+ const config = {
405
+ diamondName: 'BasicDiamond',
406
+ networkName: 'localhost',
407
+ chainId: 31337,
408
+ deploymentsPath: './diamonds',
409
+ contractsPath: './contracts'
410
+ };
411
+
412
+ const repository = new FileDeploymentRepository(config);
413
+ const diamond = new Diamond(config, repository);
414
+
415
+ diamond.setProvider(ethers.provider);
416
+ diamond.setSigner(await ethers.getSigners()[0]);
417
+
418
+ const strategy = new LocalDeploymentStrategy();
419
+ const deployer = new DiamondDeployer(diamond, strategy);
420
+
421
+ await deployer.deployDiamond();
422
+ console.log('Diamond deployed successfully!');
423
+ }
424
+ ```
425
+
426
+ ### Production Deployment with Defender
427
+
428
+ ```typescript
429
+ import { OZDefenderDeploymentStrategy } from '@geniusventures/diamonds/strategies';
430
+
431
+ async function deployProductionDiamond() {
432
+ const config = {
433
+ diamondName: 'ProductionDiamond',
434
+ networkName: 'mainnet',
435
+ chainId: 1,
436
+ deploymentsPath: './diamonds',
437
+ contractsPath: './contracts'
438
+ };
439
+
440
+ const repository = new FileDeploymentRepository(config);
441
+ const diamond = new Diamond(config, repository);
442
+
443
+ // Setup provider and signer for mainnet
444
+ diamond.setProvider(mainnetProvider);
445
+ diamond.setSigner(productionSigner);
446
+
447
+ const strategy = new OZDefenderDeploymentStrategy(
448
+ process.env.DEFENDER_API_KEY!,
449
+ process.env.DEFENDER_API_SECRET!,
450
+ process.env.DEFENDER_RELAYER_ADDRESS!,
451
+ false, // manual approval for production
452
+ process.env.DEFENDER_SAFE_ADDRESS!,
453
+ 'Safe'
454
+ );
455
+
456
+ const deployer = new DiamondDeployer(diamond, strategy);
457
+ await deployer.deployDiamond();
458
+ }
459
+ ```
460
+
461
+ ### Complex Multi-Facet Upgrade
462
+
463
+ ```typescript
464
+ async function performComplexUpgrade() {
465
+ // Load existing diamond
466
+ const diamond = await loadExistingDiamond('MyDiamond');
467
+
468
+ // Update configuration for new version
469
+ const config = diamond.repository.loadDeployConfig();
470
+ config.protocolVersion = 2.0;
471
+
472
+ // Add new facet
473
+ config.facets.NewFeatureFacet = {
474
+ priority: 150,
475
+ versions: {
476
+ "2.0": {
477
+ deployInit: "initialize()",
478
+ callbacks: ["setupNewFeature"]
479
+ }
480
+ }
481
+ };
482
+
483
+ // Upgrade existing facet
484
+ config.facets.ExistingFacet.versions["2.0"] = {
485
+ upgradeInit: "upgradeToV2()",
486
+ fromVersions: [1.0]
487
+ };
488
+
489
+ await diamond.repository.saveDeployConfig(config);
490
+
491
+ // Execute upgrade
492
+ const strategy = new OZDefenderDeploymentStrategy(/* config */);
493
+ const deployer = new DiamondDeployer(diamond, strategy);
494
+ await deployer.deployDiamond();
495
+ }
496
+ ```
497
+
498
+ ## 🔍 Monitoring and Debugging
499
+
500
+ ### Enable Verbose Logging
501
+
502
+ ```typescript
503
+ const strategy = new LocalDeploymentStrategy(true); // Enable verbose mode
504
+ ```
505
+
506
+ ### Debug Function Selectors
507
+
508
+ ```typescript
509
+ import { getSighash } from '@geniusventures/diamonds/utils';
510
+
511
+ // Get function selector
512
+ const selector = getSighash('transfer(address,uint256)');
513
+ console.log('Selector:', selector);
514
+
515
+ // Check if selector is registered
516
+ const isRegistered = diamond.isFunctionSelectorRegistered(selector);
517
+ console.log('Is registered:', isRegistered);
518
+ ```
519
+
520
+ ### Monitor Deployment State
521
+
522
+ ```typescript
523
+ // Check deployment status
524
+ const deployedData = diamond.getDeployedDiamondData();
525
+ console.log('Diamond address:', deployedData.DiamondAddress);
526
+ console.log('Deployed facets:', Object.keys(deployedData.DeployedFacets || {}));
527
+
528
+ // Validate on-chain state
529
+ import { diffDeployedFacets } from '@geniusventures/diamonds/utils';
530
+ const isConsistent = await diffDeployedFacets(deployedData, ethers.provider, true);
531
+ ```
532
+
533
+ ## 🔐 Security Considerations
534
+
535
+ ### Production Best Practices
536
+
537
+ 1. **Use Multi-signature Wallets**: Always use multi-sig for mainnet deployments
538
+ 2. **Test Thoroughly**: Test all upgrades on testnets first
539
+ 3. **Verify Contracts**: Ensure all contracts are verified on Etherscan
540
+ 4. **Monitor Deployments**: Use Defender monitoring for production systems
541
+ 5. **Access Control**: Implement proper role-based access controls
542
+
543
+ ### Secure Configuration
544
+
545
+ ```typescript
546
+ // Production configuration example
547
+ const productionConfig = {
548
+ diamondName: 'ProductionDiamond',
549
+ networkName: 'mainnet',
550
+ chainId: 1,
551
+ deploymentsPath: './production-diamonds',
552
+ contractsPath: './contracts',
553
+ writeDeployedDiamondData: true
554
+ };
555
+
556
+ const strategy = new OZDefenderDeploymentStrategy(
557
+ process.env.PROD_DEFENDER_API_KEY!,
558
+ process.env.PROD_DEFENDER_API_SECRET!,
559
+ process.env.PROD_RELAYER_ADDRESS!,
560
+ false, // Never auto-approve in production
561
+ process.env.PROD_SAFE_ADDRESS!,
562
+ 'Safe'
563
+ );
564
+ ```
565
+
566
+ ## 🤝 Contributing
567
+
568
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
569
+
570
+ ### Development Setup
571
+
572
+ ```bash
573
+ # Clone the repository
574
+ git clone https://github.com/geniusventures/diamonds.git
575
+ cd diamonds
576
+
577
+ # Install dependencies
578
+ npm install
579
+
580
+ # Run tests
581
+ npm test
582
+
583
+ # Build the project
584
+ npm run build
585
+
586
+ # Run linting
587
+ npm run lint
588
+ ```
589
+
590
+ ### Coding Standards
591
+
592
+ - Follow TypeScript best practices
593
+ - Maintain 90%+ test coverage
594
+ - Use conventional commit messages
595
+ - Update documentation for new features
596
+ - Add comprehensive tests for new functionality
597
+
598
+ ## 📄 License
599
+
600
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
601
+
602
+ ## 🙏 Acknowledgments
603
+
604
+ - [OpenZeppelin](https://openzeppelin.com/) for Defender platform and security tools
605
+ - [ERC-2535 Diamond Standard](https://eips.ethereum.org/EIPS/eip-2535) authors
606
+ - [Hardhat](https://hardhat.org/) development framework
607
+ - The Ethereum community for continuous innovation
608
+
609
+ ## 📞 Support
610
+
611
+ - **Documentation**: [Full Documentation](https://docs.geniusventures.com/diamonds)
612
+ - **GitHub Issues**: [Report Issues](https://github.com/geniusventures/diamonds/issues)
613
+ - **Discord**: [Join our Community](https://discord.gg/geniusventures)
614
+ - **Email**: <support@geniusventures.com>
615
+
616
+ ---
617
+
618
+ **Built with ❤️ for the Ethereum ecosystem by [Genius Ventures](https://geniusventures.com)**
@@ -0,0 +1,3 @@
1
+ # diamonds directory
2
+
3
+ >> THIS DIRECTORY IS USED FOR TEST CONFIGURATION AND DEPLOYMENTS
@@ -0,0 +1,13 @@
1
+ import { CallbackArgs } from "../types";
2
+ export declare class CallbackManager {
3
+ private callbacksPath;
4
+ private static instances;
5
+ private callbacks;
6
+ private constructor();
7
+ static getInstance(diamondName: string, deploymentsPath: string): CallbackManager;
8
+ static clearInstances(): void;
9
+ static clearInstance(diamondName: string): void;
10
+ private loadCallbacks;
11
+ executeCallback(facetName: string, callbacks: string[], args: CallbackArgs): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=CallbackManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallbackManager.d.ts","sourceRoot":"","sources":["../../src/core/CallbackManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,qBAAa,eAAe;IAKN,OAAO,CAAC,aAAa;IAJzC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2C;IAEnE,OAAO,CAAC,SAAS,CAA6E;IAE9F,OAAO;WAIO,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,eAAe;WAQ1E,cAAc,IAAI,IAAI;WAItB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAItD,OAAO,CAAC,aAAa;IAyBR,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAexG"}