@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.
- package/README.md +618 -0
- package/diamonds/README.md +3 -0
- package/dist/core/CallbackManager.d.ts +13 -0
- package/dist/core/CallbackManager.d.ts.map +1 -0
- package/dist/core/CallbackManager.js +95 -0
- package/dist/core/CallbackManager.js.map +1 -0
- package/dist/core/DeploymentManager.d.ts +10 -0
- package/dist/core/DeploymentManager.d.ts.map +1 -0
- package/dist/core/DeploymentManager.js +50 -0
- package/dist/core/DeploymentManager.js.map +1 -0
- package/dist/core/Diamond.d.ts +58 -0
- package/dist/core/Diamond.d.ts.map +1 -0
- package/dist/core/Diamond.js +146 -0
- package/dist/core/Diamond.js.map +1 -0
- package/dist/core/DiamondDeployer.d.ts +10 -0
- package/dist/core/DiamondDeployer.d.ts.map +1 -0
- package/dist/core/DiamondDeployer.js +33 -0
- package/dist/core/DiamondDeployer.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/repositories/DBDeploymentRepository.d.ts +1 -0
- package/dist/repositories/DBDeploymentRepository.d.ts.map +1 -0
- package/dist/repositories/DBDeploymentRepository.js +20 -0
- package/dist/repositories/DBDeploymentRepository.js.map +1 -0
- package/dist/repositories/DeploymentRepository.d.ts +8 -0
- package/dist/repositories/DeploymentRepository.d.ts.map +1 -0
- package/dist/repositories/DeploymentRepository.js +7 -0
- package/dist/repositories/DeploymentRepository.js.map +1 -0
- package/dist/repositories/FileDeploymentRepository.d.ts +18 -0
- package/dist/repositories/FileDeploymentRepository.d.ts.map +1 -0
- package/dist/repositories/FileDeploymentRepository.js +58 -0
- package/dist/repositories/FileDeploymentRepository.js.map +1 -0
- package/dist/repositories/databaseHandler.d.ts +1 -0
- package/dist/repositories/databaseHandler.d.ts.map +1 -0
- package/dist/repositories/databaseHandler.js +13 -0
- package/dist/repositories/databaseHandler.js.map +1 -0
- package/dist/repositories/index.d.ts +4 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +20 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/jsonFileHandler.d.ts +81 -0
- package/dist/repositories/jsonFileHandler.d.ts.map +1 -0
- package/dist/repositories/jsonFileHandler.js +223 -0
- package/dist/repositories/jsonFileHandler.js.map +1 -0
- package/dist/repositories/prismaDBHandler.d.ts +1 -0
- package/dist/repositories/prismaDBHandler.d.ts.map +1 -0
- package/dist/repositories/prismaDBHandler.js +11 -0
- package/dist/repositories/prismaDBHandler.js.map +1 -0
- package/dist/schemas/DeploymentSchema.d.ts +309 -0
- package/dist/schemas/DeploymentSchema.d.ts.map +1 -0
- package/dist/schemas/DeploymentSchema.js +56 -0
- package/dist/schemas/DeploymentSchema.js.map +1 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +18 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/strategies/BaseDeploymentStrategy.d.ts +41 -0
- package/dist/strategies/BaseDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/BaseDeploymentStrategy.js +545 -0
- package/dist/strategies/BaseDeploymentStrategy.js.map +1 -0
- package/dist/strategies/DeploymentStrategy.d.ts +19 -0
- package/dist/strategies/DeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/DeploymentStrategy.js +3 -0
- package/dist/strategies/DeploymentStrategy.js.map +1 -0
- package/dist/strategies/LocalDeploymentStrategy.d.ts +4 -0
- package/dist/strategies/LocalDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/LocalDeploymentStrategy.js +8 -0
- package/dist/strategies/LocalDeploymentStrategy.js.map +1 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.d.ts +62 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.js +757 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.js.map +1 -0
- package/dist/strategies/RPCDeploymentStrategy.d.ts +139 -0
- package/dist/strategies/RPCDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/RPCDeploymentStrategy.js +710 -0
- package/dist/strategies/RPCDeploymentStrategy.js.map +1 -0
- package/dist/strategies/index.d.ts +6 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +12 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/types/config.d.ts +26 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +3 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/defender.d.ts +22 -0
- package/dist/types/defender.d.ts.map +1 -0
- package/dist/types/defender.js +3 -0
- package/dist/types/defender.js.map +1 -0
- package/dist/types/deployments.d.ts +71 -0
- package/dist/types/deployments.d.ts.map +1 -0
- package/dist/types/deployments.js +20 -0
- package/dist/types/deployments.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/rpc.d.ts +35 -0
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/rpc.js +3 -0
- package/dist/types/rpc.js.map +1 -0
- package/dist/utils/common.d.ts +20 -0
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +45 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/configurationResolver.d.ts +30 -0
- package/dist/utils/configurationResolver.d.ts.map +1 -0
- package/dist/utils/configurationResolver.js +151 -0
- package/dist/utils/configurationResolver.js.map +1 -0
- package/dist/utils/contractMapping.d.ts +29 -0
- package/dist/utils/contractMapping.d.ts.map +1 -0
- package/dist/utils/contractMapping.js +224 -0
- package/dist/utils/contractMapping.js.map +1 -0
- package/dist/utils/defenderClients.d.ts +5 -0
- package/dist/utils/defenderClients.d.ts.map +1 -0
- package/dist/utils/defenderClients.js +21 -0
- package/dist/utils/defenderClients.js.map +1 -0
- package/dist/utils/defenderStore.d.ts +14 -0
- package/dist/utils/defenderStore.d.ts.map +1 -0
- package/dist/utils/defenderStore.js +92 -0
- package/dist/utils/defenderStore.js.map +1 -0
- package/dist/utils/diamondAbiGenerator.d.ts +113 -0
- package/dist/utils/diamondAbiGenerator.d.ts.map +1 -0
- package/dist/utils/diamondAbiGenerator.js +415 -0
- package/dist/utils/diamondAbiGenerator.js.map +1 -0
- package/dist/utils/diffDeployedFacets.d.ts +26 -0
- package/dist/utils/diffDeployedFacets.d.ts.map +1 -0
- package/dist/utils/diffDeployedFacets.js +106 -0
- package/dist/utils/diffDeployedFacets.js.map +1 -0
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/loupe.d.ts +44 -0
- package/dist/utils/loupe.d.ts.map +1 -0
- package/dist/utils/loupe.js +128 -0
- package/dist/utils/loupe.js.map +1 -0
- package/dist/utils/rpcStore.d.ts +36 -0
- package/dist/utils/rpcStore.d.ts.map +1 -0
- package/dist/utils/rpcStore.js +166 -0
- package/dist/utils/rpcStore.js.map +1 -0
- package/dist/utils/signer.d.ts +36 -0
- package/dist/utils/signer.d.ts.map +1 -0
- package/dist/utils/signer.js +91 -0
- package/dist/utils/signer.js.map +1 -0
- package/dist/utils/txlogging.d.ts +13 -0
- package/dist/utils/txlogging.d.ts.map +1 -0
- package/dist/utils/txlogging.js +87 -0
- package/dist/utils/txlogging.js.map +1 -0
- package/dist/utils/workspaceSetup.d.ts +32 -0
- package/dist/utils/workspaceSetup.d.ts.map +1 -0
- package/dist/utils/workspaceSetup.js +311 -0
- package/dist/utils/workspaceSetup.js.map +1 -0
- package/docs/DIAMOND_ABI_CONFIGURATION_SUMMARY.md +40 -0
- package/docs/DIAMOND_ABI_GENERATION.md +220 -0
- package/docs/DIAMOND_ABI_GENERATOR_EXAMPLES.md +1204 -0
- package/docs/DIAMOND_ABI_GENERATOR_IMPLEMENTATION.md +947 -0
- package/docs/DIAMOND_ABI_GENERATOR_QUICK_REFERENCE.md +336 -0
- package/docs/README-DEFENDER.md +394 -0
- package/docs/README_DIAMOND_ABI_GENERATOR.md +303 -0
- package/docs/ROADMAP.md +250 -0
- package/docs/assets/image.png +0 -0
- package/docs/defender-integration.md +451 -0
- package/docs/diamond_module-BaseStrategy_design-v2.uxf +247 -0
- package/docs/diamond_module-BaseStrategy_design.uxf +272 -0
- package/docs/monitoring-troubleshooting.md +556 -0
- package/docs/testing-guide.md +713 -0
- package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/callbacks/ERC20ProxyFacet.ts +31 -0
- package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/proxydiamond.config.json +27 -0
- package/examples/Local_Hardhat_Deployer_Script_example/LocalDiamondDeployer.ts +180 -0
- package/examples/OZ_Defender_Deployer_Script_example/OZDiamondDeployer.ts +107 -0
- package/examples/OZ_Defender_Deployer_Script_example/run-oz-deploy.ts +17 -0
- package/examples/Test_examples/ProxyDiamondDeployment.test.ts +202 -0
- package/examples/defender-deployment/.env.example +35 -0
- package/examples/defender-deployment/README.md +415 -0
- package/examples/defender-deployment/contracts/ExampleDiamond.sol +41 -0
- package/examples/defender-deployment/contracts/ExampleFacet1.sol +84 -0
- package/examples/defender-deployment/contracts/ExampleFacet2.sol +104 -0
- package/examples/defender-deployment/contracts/UpgradeFacet.sol +92 -0
- package/examples/defender-deployment/deploy-script.ts +170 -0
- package/examples/defender-deployment/diamond-config.json +36 -0
- package/examples/defender-deployment/upgrade-script.ts +237 -0
- package/examples/hardhat-diamonds-config.example.ts +41 -0
- package/package.json +228 -0
- package/src/core/CallbackManager.ts +70 -0
- package/src/core/DeploymentManager.ts +64 -0
- package/src/core/Diamond.ts +197 -0
- package/src/core/DiamondDeployer.ts +36 -0
- package/src/core/index.ts +4 -0
- package/src/index.ts +5 -0
- package/src/repositories/DBDeploymentRepository.ts +22 -0
- package/src/repositories/DeploymentRepository.ts +12 -0
- package/src/repositories/FileDeploymentRepository.ts +67 -0
- package/src/repositories/databaseHandler.ts +14 -0
- package/src/repositories/index.ts +4 -0
- package/src/repositories/jsonFileHandler.ts +252 -0
- package/src/repositories/prismaDBHandler.ts +10 -0
- package/src/schemas/DeploymentSchema.ts +71 -0
- package/src/schemas/index.ts +1 -0
- package/src/strategies/BaseDeploymentStrategy.ts +649 -0
- package/src/strategies/DeploymentStrategy.ts +25 -0
- package/src/strategies/LocalDeploymentStrategy.ts +5 -0
- package/src/strategies/OZDefenderDeploymentStrategy.ts +849 -0
- package/src/strategies/RPCDeploymentStrategy.ts +881 -0
- package/src/strategies/index.ts +5 -0
- package/src/types/config.ts +34 -0
- package/src/types/defender.ts +24 -0
- package/src/types/deployments.ts +102 -0
- package/src/types/index.ts +4 -0
- package/src/types/rpc.ts +37 -0
- package/src/utils/common.ts +54 -0
- package/src/utils/configurationResolver.ts +141 -0
- package/src/utils/contractMapping.ts +220 -0
- package/src/utils/defenderClients.ts +22 -0
- package/src/utils/defenderStore.ts +62 -0
- package/src/utils/diamondAbiGenerator.ts +523 -0
- package/src/utils/diffDeployedFacets.ts +131 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/loupe.ts +159 -0
- package/src/utils/rpcStore.ts +152 -0
- package/src/utils/signer.ts +93 -0
- package/src/utils/txlogging.ts +97 -0
- package/src/utils/workspaceSetup.ts +315 -0
- 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.
|