@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
package/README.md
ADDED
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
# Diamonds Module
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/@geniusventures%2Fdiamonds)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](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,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"}
|