@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
@@ -0,0 +1,394 @@
1
+ # Diamonds Module - OpenZeppelin Defender Integration
2
+
3
+ ## Project Overview
4
+
5
+ This project provides a comprehensive implementation of the ERC-2535 Diamond Proxy Standard with full OpenZeppelin Defender integration for enterprise-grade smart contract deployment and management.
6
+
7
+ ## โœจ Key Features
8
+
9
+ ### Core Functionality
10
+
11
+ - **ERC-2535 Diamond Proxy**: Full implementation of the Diamond standard
12
+ - **Modular Facet System**: Add, replace, and remove functionality without changing the main contract
13
+ - **Version Management**: Sophisticated versioning system for facets and protocols
14
+ - **Strategy Pattern**: Pluggable deployment strategies (Local, Defender, Custom)
15
+ - **Repository Pattern**: Flexible data persistence (File-based, Database-ready)
16
+
17
+ ### OpenZeppelin Defender Integration
18
+
19
+ - **Secure Deployments**: Deploy contracts through Defender's secure infrastructure
20
+ - **Multi-signature Support**: Integrate with Gnosis Safe and other multi-sig wallets
21
+ - **Automated Execution**: Optional auto-approval for streamlined deployments
22
+ - **Transaction Monitoring**: Real-time deployment tracking and status updates
23
+ - **Contract Verification**: Automatic contract verification through Defender
24
+ - **Robust Error Handling**: Comprehensive retry logic and error recovery
25
+
26
+ ### Enterprise Features
27
+
28
+ - **TypeScript**: Full type safety with strict TypeScript configuration
29
+ - **Comprehensive Testing**: Unit, integration, and end-to-end test suites
30
+ - **Documentation**: Extensive documentation and examples
31
+ - **CI/CD Ready**: GitHub Actions integration and automated testing
32
+ - **Security Focused**: Best practices for production deployments
33
+
34
+ ## ๐Ÿš€ Quick Start
35
+
36
+ ### Prerequisites
37
+
38
+ ```bash
39
+ # Node.js 18+ and npm
40
+ node --version # v18.0.0 or higher
41
+ npm --version # 8.0.0 or higher
42
+
43
+ # Git
44
+ git --version
45
+ ```
46
+
47
+ ### Installation
48
+
49
+ ```bash
50
+ # Clone the repository
51
+ git clone https://github.com/your-org/diamonds.git
52
+ cd diamonds
53
+
54
+ # Install dependencies
55
+ npm install
56
+
57
+ # Setup environment
58
+ cp .env.example .env
59
+ # Edit .env with your configuration
60
+ ```
61
+
62
+ ### Basic Usage
63
+
64
+ ```typescript
65
+ import { Diamond, DiamondDeployer, FileDeploymentRepository } from '@diamonds/core';
66
+ import { OZDefenderDeploymentStrategy } from '@diamonds/strategies';
67
+
68
+ // Create diamond configuration
69
+ const config = {
70
+ diamondName: 'MyDiamond',
71
+ networkName: 'sepolia',
72
+ chainId: 11155111,
73
+ deploymentsPath: './deployments',
74
+ contractsPath: './contracts'
75
+ // ... other configuration
76
+ };
77
+
78
+ // Setup diamond and strategy
79
+ const repository = new FileDeploymentRepository(config);
80
+ const diamond = new Diamond(config, repository);
81
+ const strategy = new OZDefenderDeploymentStrategy(
82
+ process.env.DEFENDER_API_KEY!,
83
+ process.env.DEFENDER_API_SECRET!,
84
+ process.env.DEFENDER_RELAYER_ADDRESS!,
85
+ false, // manual approval
86
+ process.env.DEFENDER_SAFE_ADDRESS!,
87
+ 'Safe'
88
+ );
89
+
90
+ // Deploy diamond
91
+ const deployer = new DiamondDeployer(diamond, strategy);
92
+ await deployer.deployDiamond();
93
+ ```
94
+
95
+ ## ๐Ÿ“ Project Structure
96
+
97
+ ```bash
98
+ diamonds/
99
+ โ”œโ”€โ”€ src/ # Source code
100
+ โ”‚ โ”œโ”€โ”€ core/ # Core classes (Diamond, DiamondDeployer, etc.)
101
+ โ”‚ โ”œโ”€โ”€ strategies/ # Deployment strategies
102
+ โ”‚ โ”œโ”€โ”€ repositories/ # Data persistence layer
103
+ โ”‚ โ”œโ”€โ”€ schemas/ # Zod validation schemas
104
+ โ”‚ โ”œโ”€โ”€ types/ # TypeScript type definitions
105
+ โ”‚ โ””โ”€โ”€ utils/ # Utility functions
106
+ โ”œโ”€โ”€ test/ # Test suites
107
+ โ”‚ โ”œโ”€โ”€ unit/ # Unit tests
108
+ โ”‚ โ”œโ”€โ”€ integration/ # Integration tests
109
+ โ”‚ โ””โ”€โ”€ helpers/ # Test utilities
110
+ โ”œโ”€โ”€ examples/ # Complete examples
111
+ โ”‚ โ””โ”€โ”€ defender-deployment/ # Defender integration example
112
+ โ”œโ”€โ”€ docs/ # Documentation
113
+ โ”‚ โ”œโ”€โ”€ defender-integration.md # Defender setup guide
114
+ โ”‚ โ””โ”€โ”€ testing-guide.md # Testing documentation
115
+ โ””โ”€โ”€ artifacts/ # Compiled contracts
116
+ ```
117
+
118
+ ## ๐Ÿ›ก๏ธ OpenZeppelin Defender Setup
119
+
120
+ ### 1. Create Defender Account
121
+
122
+ 1. Visit [OpenZeppelin Defender](https://defender.openzeppelin.com/)
123
+ 2. Sign up or log in
124
+ 3. Generate API credentials with Deploy and Admin permissions
125
+
126
+ ### 2. Configure Environment
127
+
128
+ ```bash
129
+ # Copy environment template
130
+ cp .env.example .env
131
+
132
+ # Edit with your credentials
133
+ DEFENDER_API_KEY=your_api_key_here
134
+ DEFENDER_API_SECRET=your_api_secret_here
135
+ DEFENDER_RELAYER_ADDRESS=0x1234567890123456789012345678901234567890
136
+ DEFENDER_SAFE_ADDRESS=0x0987654321098765432109876543210987654321
137
+ ```
138
+
139
+ ### 3. Deploy with Defender
140
+
141
+ ```bash
142
+ # Run the complete example
143
+ cd examples/defender-deployment
144
+ npm install
145
+ npm run deploy:sepolia
146
+ ```
147
+
148
+ ## ๐Ÿงช Testing
149
+
150
+ ### Running Tests
151
+
152
+ ```bash
153
+ # Run all tests
154
+ npm test
155
+
156
+ # Run unit tests only
157
+ npm run test:unit
158
+
159
+ # Run integration tests only
160
+ npm run test:integration
161
+
162
+ # Run with coverage
163
+ npm run test:coverage
164
+
165
+ # Test specific environment
166
+ TEST_NETWORK=sepolia npm test
167
+ ```
168
+
169
+ ### Test Categories
170
+
171
+ - **Unit Tests**: Individual component testing
172
+ - **Integration Tests**: Component interaction testing
173
+ - **Defender Integration**: End-to-end Defender testing
174
+ - **Network Fork Tests**: Real network state testing
175
+ - **Performance Tests**: Deployment speed and resource usage
176
+ - **Error Handling Tests**: Failure scenario testing
177
+
178
+ ## ๐Ÿ“– Documentation
179
+
180
+ ### Core Documentation
181
+
182
+ - [Defender Integration Guide](docs/defender-integration.md) - Complete setup and usage guide
183
+ - [Testing Guide](docs/testing-guide.md) - Comprehensive testing documentation
184
+
185
+ ### Examples
186
+
187
+ - [Defender Deployment Example](examples/defender-deployment/) - Complete working example
188
+ - [Local Deployment Example](examples/local-deployment/) - Local development setup
189
+
190
+ ### API Reference
191
+
192
+ - [Core Classes](src/core/) - Diamond, DiamondDeployer, DeploymentManager
193
+ - [Strategies](src/strategies/) - Deployment strategy implementations
194
+ - [Repositories](src/repositories/) - Data persistence implementations
195
+ - [Utilities](src/utils/) - Helper functions and utilities
196
+
197
+ ## ๐Ÿ”ง Configuration
198
+
199
+ ### Diamond Configuration
200
+
201
+ ```json
202
+ {
203
+ "protocolVersion": 1.0,
204
+ "protocolInitFacet": "MyProtocolFacet",
205
+ "facets": {
206
+ "DiamondCutFacet": {
207
+ "priority": 10,
208
+ "versions": { "1.0": {} }
209
+ },
210
+ "DiamondLoupeFacet": {
211
+ "priority": 20,
212
+ "versions": { "1.0": {} }
213
+ },
214
+ "MyFacet": {
215
+ "priority": 30,
216
+ "versions": {
217
+ "1.0": {
218
+ "deployInit": "initialize()",
219
+ "upgradeInit": "upgradeToV1()",
220
+ "callbacks": ["postDeployCallback"]
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ ```
227
+
228
+ ### Deployment Strategies
229
+
230
+ ```typescript
231
+ // Local deployment
232
+ const localStrategy = new LocalDeploymentStrategy(true);
233
+
234
+ // Defender deployment with auto-approval
235
+ const defenderStrategy = new OZDefenderDeploymentStrategy(
236
+ apiKey,
237
+ apiSecret,
238
+ relayerAddress,
239
+ true, // auto-approve
240
+ safeAddress,
241
+ 'Safe'
242
+ );
243
+
244
+ // Defender deployment with manual approval
245
+ const manualDefenderStrategy = new OZDefenderDeploymentStrategy(
246
+ apiKey,
247
+ apiSecret,
248
+ relayerAddress,
249
+ false, // manual approval required
250
+ safeAddress,
251
+ 'Safe'
252
+ );
253
+ ```
254
+
255
+ ## ๐Ÿš€ Deployment Workflows
256
+
257
+ ### Initial Deployment
258
+
259
+ 1. Deploy DiamondCutFacet through Defender
260
+ 2. Deploy main Diamond contract
261
+ 3. Deploy all configured facets
262
+ 4. Create Defender proposal for diamond cut
263
+ 5. Execute proposal (auto or manual approval)
264
+ 6. Run post-deployment callbacks
265
+
266
+ ### Upgrade Process
267
+
268
+ 1. Update diamond configuration with new versions
269
+ 2. Deploy only modified/new facets
270
+ 3. Create diamond cut proposal with changes
271
+ 4. Execute upgrade proposal
272
+ 5. Run upgrade callbacks and validation
273
+
274
+ ### Monitoring and Management
275
+
276
+ - Real-time status tracking through Defender dashboard
277
+ - Automated transaction monitoring
278
+ - Gas optimization recommendations
279
+ - Error logging and alerting
280
+
281
+ ## ๐Ÿ”’ Security Features
282
+
283
+ ### Access Control
284
+
285
+ - Multi-signature support for critical operations
286
+ - Role-based deployment permissions
287
+ - API key security and rotation
288
+ - Network-specific configurations
289
+
290
+ ### Best Practices
291
+
292
+ - Comprehensive input validation
293
+ - State corruption protection
294
+ - Transaction replay protection
295
+ - Gas optimization and limits
296
+
297
+ ### Audit Trail
298
+
299
+ - Complete deployment history
300
+ - Transaction logging and monitoring
301
+ - Error tracking and recovery
302
+ - Verification and compliance reporting
303
+
304
+ ## ๐Ÿค Contributing
305
+
306
+ ### Development Setup
307
+
308
+ ```bash
309
+ # Clone and setup
310
+ git clone https://github.com/geniusventures/diamonds.git
311
+ cd diamonds
312
+ npm install
313
+
314
+ # Run tests
315
+ npm test
316
+
317
+ # Build project
318
+ npm run build
319
+
320
+ # Lint code
321
+ npm run lint
322
+ ```
323
+
324
+ ### Contribution Guidelines
325
+
326
+ 1. Follow TypeScript best practices
327
+ 2. Maintain 90%+ test coverage
328
+ 3. Update documentation for new features
329
+ 4. Follow conventional commit messages
330
+ 5. Add comprehensive tests for new functionality
331
+
332
+ ## ๐Ÿ“‹ Roadmap
333
+
334
+ ### Current Version (1.0)
335
+
336
+ - โœ… Core Diamond implementation
337
+ - โœ… OpenZeppelin Defender integration
338
+ - โœ… Comprehensive testing suite
339
+ - โœ… Documentation and examples
340
+
341
+ ### Upcoming Features (1.1)
342
+
343
+ - ๐Ÿ”„ Defender Autotasks integration
344
+ - ๐Ÿ”„ Defender Sentinel monitoring
345
+ - ๐Ÿ”„ Multi-network deployment support
346
+ - ๐Ÿ”„ Advanced upgrade patterns
347
+
348
+ ### Future Enhancements (2.0)
349
+
350
+ - ๐Ÿ“… Database repository implementation
351
+ - ๐Ÿ“… GraphQL API for deployment data
352
+ - ๐Ÿ“… Web dashboard for deployment management
353
+ - ๐Ÿ“… Advanced analytics and reporting
354
+
355
+ ## ๐Ÿ› Troubleshooting
356
+
357
+ ### Common Issues
358
+
359
+ 1. **API Authentication Errors**
360
+ - Verify Defender API credentials
361
+ - Check API key permissions
362
+ - Ensure network connectivity
363
+
364
+ 2. **Deployment Failures**
365
+ - Check gas prices and limits
366
+ - Verify contract compilation
367
+ - Review Defender dashboard logs
368
+
369
+ 3. **Network Issues**
370
+ - Validate RPC endpoints
371
+ - Check network connectivity
372
+ - Verify chain ID configuration
373
+
374
+ ### Getting Help
375
+
376
+ - Check [Documentation](docs/)
377
+ - Review [Examples](examples/)
378
+ - Open [GitHub Issue](https://github.com/genius/diamonds/issues)
379
+ - Join [Telegram Community](https://t.me/geniustokens)
380
+
381
+ ## ๐Ÿ“„ License
382
+
383
+ MIT License - see [LICENSE](LICENSE) file for details.
384
+
385
+ ## ๐Ÿ™ Acknowledgments
386
+
387
+ - [OpenZeppelin](https://openzeppelin.com/) for Defender platform
388
+ - [ERC-2535 Standard](https://eips.ethereum.org/EIPS/eip-2535) authors
389
+ - [Hardhat](https://hardhat.org/) development framework
390
+ - Diamond standard community and contributors
391
+
392
+ ---
393
+
394
+ Built with โค๏ธ for the Ethereum ecosystem
@@ -0,0 +1,303 @@
1
+ # Diamond ABI Generator Documentation
2
+
3
+ ## Overview
4
+
5
+ The Diamond ABI Generator is a comprehensive tool for generating unified Application Binary Interface (ABI) files for ERC-2535 Diamond Proxy contracts. This documentation provides everything you need to implement and utilize the Diamond ABI Generator in your projects.
6
+
7
+ ## ๐Ÿ“š Documentation Structure
8
+
9
+ ### 1. [Implementation Guide](./DIAMOND_ABI_GENERATOR_IMPLEMENTATION.md)
10
+
11
+ Complete implementation guide covering all aspects of the Diamond ABI Generator
12
+
13
+ - โœ… Installation and setup
14
+ - โœ… Command-line interface usage
15
+ - โœ… Programmatic API integration
16
+ - โœ… TypeChain integration for type generation
17
+ - โœ… Viem integration for modern Ethereum development
18
+ - โœ… AbityPe integration for type-safe ABI handling
19
+ - โœ… Configuration options and advanced features
20
+ - โœ… Best practices and troubleshooting
21
+
22
+ ### 2. [Practical Examples](./DIAMOND_ABI_GENERATOR_EXAMPLES.md)
23
+
24
+ Real-world examples and patterns for common use cases
25
+
26
+ - โœ… Integration patterns for different project types
27
+ - โœ… Frontend framework integration (React, Next.js, Vue.js)
28
+ - โœ… Testing strategies and patterns
29
+ - โœ… CI/CD pipeline integration
30
+ - โœ… Performance optimization techniques
31
+ - โœ… Custom tooling and extensions
32
+ - โœ… Migration strategies
33
+
34
+ ### 3. [Quick Reference](./DIAMOND_ABI_GENERATOR_QUICK_REFERENCE.md)
35
+
36
+ Cheat sheet for common operations and configurations
37
+
38
+ - โœ… Command reference
39
+ - โœ… API quick reference
40
+ - โœ… Configuration options
41
+ - โœ… Common patterns
42
+ - โœ… Troubleshooting guide
43
+ - โœ… Best practices checklist
44
+
45
+ ## ๐Ÿš€ Quick Start
46
+
47
+ ### Prerequisites
48
+
49
+ - Node.js 16+ and npm/yarn
50
+ - Hardhat project with compiled contracts
51
+ - Diamonds module setup with deployment configuration
52
+
53
+ ### Basic Usage
54
+
55
+ ```bash
56
+ # Generate ABI for your diamond
57
+ npm run diamond-abi generate --diamond YourDiamond --network localhost
58
+
59
+ # Generate with TypeChain types
60
+ npm run diamond-abi generate --diamond YourDiamond
61
+ npx typechain --target ethers-v5 --out-dir typechain-types artifacts/diamond-abi/*.json
62
+
63
+ # Preview ABI changes before deployment
64
+ npm run diamond-abi preview --diamond YourDiamond --verbose
65
+ ```
66
+
67
+ ## ๐Ÿ”ง Key Features
68
+
69
+ ### Core Functionality
70
+
71
+ - **Unified ABI Generation**: Combine all facet ABIs into a single, cohesive interface
72
+ - **Function Selector Registry**: Seamless integration with diamond deployment system
73
+ - **Preview Mode**: Preview ABI changes before applying diamond cuts
74
+ - **Source Information**: Optional inclusion of source code metadata
75
+ - **Validation**: Function selector uniqueness validation
76
+
77
+ ### Development Integration
78
+
79
+ - **TypeChain Support**: Generate type-safe TypeScript interfaces
80
+ - **Viem Integration**: Modern Ethereum development with type safety
81
+ - **AbityPe Support**: Type-safe ABI handling and validation
82
+ - **CLI Tools**: Professional command-line interface
83
+ - **Watch Mode**: Automatic regeneration during development
84
+
85
+ ### Production Features
86
+
87
+ - **Performance Optimization**: Efficient processing of large diamond deployments
88
+ - **Caching**: Intelligent caching for improved performance
89
+ - **Error Handling**: Comprehensive error handling and recovery
90
+ - **CI/CD Integration**: Automated workflows for deployment pipelines
91
+ - **Multi-Network Support**: Support for different networks and chain IDs
92
+
93
+ ## ๐Ÿ—๏ธ Architecture
94
+
95
+ ### Core Components
96
+
97
+ ```typescript
98
+ // Core ABI Generation
99
+ import { generateDiamondAbi, Diamond } from 'diamonds';
100
+
101
+ // Setup
102
+ const diamond = new Diamond(config, repository);
103
+ const result = await generateDiamondAbi(diamond, options);
104
+
105
+ // Advanced Usage
106
+ const generator = new DiamondAbiGenerator(options);
107
+ const result = await generator.generateAbi();
108
+ ```
109
+
110
+ ### Output Structure
111
+
112
+ ```text
113
+ artifacts/diamond-abi/
114
+ โ”œโ”€โ”€ YourDiamond.json # Complete diamond artifact
115
+ โ”œโ”€โ”€ YourDiamond.d.ts # TypeScript interface
116
+ โ””โ”€โ”€ metadata.json # Generation metadata
117
+ ```
118
+
119
+ ## ๐Ÿ› ๏ธ Integration Examples
120
+
121
+ ### Frontend Integration
122
+
123
+ ```typescript
124
+ // React Hook
125
+ import { useDiamond } from './hooks/useDiamond';
126
+ import DiamondABI from './artifacts/diamond-abi/GameDiamond.json';
127
+
128
+ function GameComponent() {
129
+ const { contract } = useDiamond(diamondAddress, provider);
130
+ // Use contract with full ABI
131
+ }
132
+ ```
133
+
134
+ ### Viem Integration
135
+
136
+ ```typescript
137
+ import { createPublicClient, http } from 'viem';
138
+ import DiamondABI from './artifacts/diamond-abi/GameDiamond.json';
139
+
140
+ const client = createPublicClient({
141
+ chain: mainnet,
142
+ transport: http()
143
+ });
144
+
145
+ const result = await client.readContract({
146
+ address: diamondAddress,
147
+ abi: DiamondABI.abi,
148
+ functionName: 'someFunction'
149
+ });
150
+ ```
151
+
152
+ ### Testing Integration
153
+
154
+ ```typescript
155
+ describe('Diamond ABI', () => {
156
+ it('should generate valid ABI', async () => {
157
+ const result = await generateDiamondAbi(diamond);
158
+ expect(result.abi).to.be.an('array');
159
+ expect(result.stats.totalFunctions).to.be.greaterThan(0);
160
+ });
161
+ });
162
+ ```
163
+
164
+ ## ๐Ÿ“‹ Configuration
165
+
166
+ ### Basic Configuration
167
+
168
+ ```typescript
169
+ const options = {
170
+ outputDir: './artifacts/diamond-abi',
171
+ includeSourceInfo: true,
172
+ validateSelectors: true,
173
+ verbose: true
174
+ };
175
+ ```
176
+
177
+ ### CLI Configuration
178
+
179
+ ```bash
180
+ npm run diamond-abi generate \
181
+ --diamond YourDiamond \
182
+ --network localhost \
183
+ --output ./artifacts/diamond-abi \
184
+ --include-source \
185
+ --validate-selectors \
186
+ --verbose
187
+ ```
188
+
189
+ ## ๐Ÿงช Testing
190
+
191
+ ### Unit Tests
192
+
193
+ ```bash
194
+ # Run ABI generation tests
195
+ npm run test:unit -- --grep "Diamond ABI"
196
+
197
+ # Run integration tests
198
+ npm run test:integration -- --grep "diamondAbiGeneration"
199
+ ```
200
+
201
+ ### Validation
202
+
203
+ ```bash
204
+ # Validate generated ABI
205
+ npm run diamond-abi validate artifacts/diamond-abi/YourDiamond.json
206
+
207
+ # Compare ABIs
208
+ npm run diamond-abi compare old-abi.json new-abi.json
209
+ ```
210
+
211
+ ## ๐Ÿšฆ CI/CD Integration
212
+
213
+ ### GitHub Actions
214
+
215
+ ```yaml
216
+ - name: Generate Diamond ABI
217
+ run: |
218
+ npm run diamond-abi generate --diamond ${{ matrix.diamond }} --network ${{ matrix.network }}
219
+ npx typechain --target ethers-v5 --out-dir typechain-types artifacts/diamond-abi/*.json
220
+
221
+ - name: Upload artifacts
222
+ uses: actions/upload-artifact@v3
223
+ with:
224
+ name: diamond-abi
225
+ path: artifacts/diamond-abi/
226
+ ```
227
+
228
+ ## ๐Ÿ“ฆ Package.json Scripts
229
+
230
+ Recommended scripts for your project:
231
+
232
+ ```json
233
+ {
234
+ "scripts": {
235
+ "diamond:abi": "npm run diamond-abi generate",
236
+ "diamond:types": "npm run diamond:abi && npx typechain --target ethers-v5 --out-dir typechain-types artifacts/diamond-abi/*.json",
237
+ "diamond:preview": "npm run diamond-abi preview --verbose",
238
+ "diamond:validate": "npm run diamond-abi validate artifacts/diamond-abi/*.json",
239
+ "diamond:clean": "rimraf artifacts/diamond-abi typechain-types"
240
+ }
241
+ }
242
+ ```
243
+
244
+ ## ๐Ÿ”ง Troubleshooting
245
+
246
+ ### Common Issues
247
+
248
+ | Issue | Solution |
249
+ |-------|----------|
250
+ | "No artifacts found" | Run `npm run compile` first |
251
+ | "Function selector collision" | Enable `validateSelectors: true` |
252
+ | "Missing deployment data" | Check `diamonds/` directory exists |
253
+ | "TypeChain generation fails" | Validate ABI first |
254
+
255
+ ### Debug Mode
256
+
257
+ ```bash
258
+ # Enable verbose logging
259
+ npm run diamond-abi generate --verbose
260
+
261
+ # Or programmatically
262
+ const result = await generateDiamondAbi(diamond, { verbose: true });
263
+ ```
264
+
265
+ ## ๐Ÿ“ˆ Performance
266
+
267
+ ### Optimization Tips
268
+
269
+ 1. **Use caching** for repeated operations
270
+ 2. **Enable parallel processing** for multiple diamonds
271
+ 3. **Filter facets** to include only necessary ones
272
+ 4. **Use preview mode** to validate changes before generation
273
+
274
+ ### Benchmarks
275
+
276
+ - **Small diamonds (1-5 facets)**: ~50-200ms
277
+ - **Medium diamonds (10-20 facets)**: ~100-300ms
278
+ - **Large diamonds (50+ facets)**: ~500-1000ms
279
+
280
+ ## ๐Ÿค Best Practices
281
+
282
+ 1. **Always validate selectors** in production
283
+ 2. **Include in CI/CD pipeline** for automated testing
284
+ 3. **Version control generated ABIs** for tracking changes
285
+ 4. **Use TypeScript types** for better development experience
286
+ 5. **Test integration** with actual contracts
287
+ 6. **Monitor performance** for large diamonds
288
+
289
+ ## ๐Ÿ”— Related Documentation
290
+
291
+ - [Main Implementation Summary](./DIAMOND_ABI_GENERATION.md)
292
+ - [ERC-2535 Diamond Standard](https://eips.ethereum.org/EIPS/eip-2535)
293
+ - [TypeChain Documentation](https://github.com/dethcrypto/TypeChain)
294
+ - [Viem Documentation](https://viem.sh/)
295
+ - [AbityPe Documentation](https://abitype.dev/)
296
+
297
+ ## ๐Ÿ“„ License
298
+
299
+ This documentation is part of the diamonds module and is licensed under the MIT License.
300
+
301
+ ---
302
+
303
+ **Need help?** Check the [troubleshooting section](./DIAMOND_ABI_GENERATOR_QUICK_REFERENCE.md#troubleshooting) or open an issue in the repository.