@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,336 @@
|
|
|
1
|
+
# Diamond ABI Generator - Quick Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Quick reference guide for the Diamond ABI Generator. Use this as a cheat sheet for common operations and configurations.
|
|
6
|
+
|
|
7
|
+
## Quick Start Commands
|
|
8
|
+
|
|
9
|
+
### Basic Usage
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Generate ABI for your diamond
|
|
13
|
+
npm run diamond-abi generate --diamond YourDiamond
|
|
14
|
+
|
|
15
|
+
# Generate with full options
|
|
16
|
+
npm run diamond-abi generate --diamond YourDiamond --network localhost --verbose --include-source
|
|
17
|
+
|
|
18
|
+
# Preview changes before deployment
|
|
19
|
+
npm run diamond-abi preview --diamond YourDiamond --verbose
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### With TypeChain
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Generate ABI and TypeChain types
|
|
26
|
+
npm run diamond-abi generate --diamond YourDiamond
|
|
27
|
+
npx typechain --target ethers-v5 --out-dir typechain-types artifacts/diamond-abi/*.json
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API Reference
|
|
31
|
+
|
|
32
|
+
### generateDiamondAbi()
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { generateDiamondAbi } from 'diamonds';
|
|
36
|
+
|
|
37
|
+
const result = await generateDiamondAbi(diamond, {
|
|
38
|
+
outputDir: './artifacts/diamond-abi', // Output directory
|
|
39
|
+
includeSourceInfo: true, // Include source metadata
|
|
40
|
+
validateSelectors: true, // Validate selector uniqueness
|
|
41
|
+
verbose: true // Enable verbose logging
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### DiamondAbiGenerator Class
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { DiamondAbiGenerator } from 'diamonds';
|
|
49
|
+
|
|
50
|
+
const generator = new DiamondAbiGenerator({
|
|
51
|
+
diamond: diamond,
|
|
52
|
+
outputDir: './artifacts/diamond-abi',
|
|
53
|
+
includeSourceInfo: true,
|
|
54
|
+
validateSelectors: true,
|
|
55
|
+
verbose: true
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const result = await generator.generateAbi();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Configuration Options
|
|
62
|
+
|
|
63
|
+
### DiamondAbiGenerationOptions
|
|
64
|
+
|
|
65
|
+
| Option | Type | Default | Description |
|
|
66
|
+
|--------|------|---------|-------------|
|
|
67
|
+
| `diamond` | `Diamond` | Required | Diamond instance |
|
|
68
|
+
| `outputDir` | `string` | `'artifacts/diamond-abi'` | Output directory |
|
|
69
|
+
| `includeSourceInfo` | `boolean` | `true` | Include source metadata |
|
|
70
|
+
| `validateSelectors` | `boolean` | `true` | Validate selector uniqueness |
|
|
71
|
+
| `verbose` | `boolean` | `false` | Enable verbose logging |
|
|
72
|
+
| `customFacetCuts` | `FacetCuts` | `undefined` | Custom facet cuts for preview |
|
|
73
|
+
|
|
74
|
+
### CLI Options
|
|
75
|
+
|
|
76
|
+
| Option | Short | Description | Default |
|
|
77
|
+
|--------|-------|-------------|---------|
|
|
78
|
+
| `--diamond` | `-d` | Diamond name | `'GeniusDiamond'` |
|
|
79
|
+
| `--network` | `-n` | Network name | `'localhost'` |
|
|
80
|
+
| `--chain-id` | `-c` | Chain ID | `'31337'` |
|
|
81
|
+
| `--output` | `-o` | Output directory | `'artifacts/diamond-abi'` |
|
|
82
|
+
| `--include-source` | | Include source info | `false` |
|
|
83
|
+
| `--validate-selectors` | | Validate selectors | `true` |
|
|
84
|
+
| `--verbose` | `-v` | Verbose output | `false` |
|
|
85
|
+
|
|
86
|
+
## Common Patterns
|
|
87
|
+
|
|
88
|
+
### Basic Integration
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { generateDiamondAbi, Diamond } from 'diamonds';
|
|
92
|
+
import { FileDeploymentRepository } from 'diamonds/repositories';
|
|
93
|
+
|
|
94
|
+
// Setup
|
|
95
|
+
const config = {
|
|
96
|
+
diamondName: 'GameDiamond',
|
|
97
|
+
networkName: 'localhost',
|
|
98
|
+
chainId: 31337,
|
|
99
|
+
deploymentsPath: './diamonds',
|
|
100
|
+
contractsPath: './contracts'
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const repository = new FileDeploymentRepository(config);
|
|
104
|
+
const diamond = new Diamond(config, repository);
|
|
105
|
+
|
|
106
|
+
// Generate ABI
|
|
107
|
+
const result = await generateDiamondAbi(diamond);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### With Error Handling
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
try {
|
|
114
|
+
const result = await generateDiamondAbi(diamond, {
|
|
115
|
+
validateSelectors: true,
|
|
116
|
+
verbose: true
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
console.log(`✅ Generated ABI with ${result.stats.totalFunctions} functions`);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('❌ ABI generation failed:', error);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Preview Mode
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
const plannedCuts = [
|
|
129
|
+
{
|
|
130
|
+
name: 'NewFacet',
|
|
131
|
+
facetAddress: '0x...',
|
|
132
|
+
action: 0, // Add
|
|
133
|
+
functionSelectors: ['0x12345678']
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
const preview = await previewDiamondAbi(diamond, plannedCuts);
|
|
138
|
+
console.log(`Preview: ${preview.stats.totalFunctions} functions`);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Frontend Integration
|
|
142
|
+
|
|
143
|
+
### React Hook
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { useEffect, useState } from 'react';
|
|
147
|
+
import { ethers } from 'ethers';
|
|
148
|
+
import DiamondABI from './artifacts/diamond-abi/GameDiamond.json';
|
|
149
|
+
|
|
150
|
+
export function useDiamond(address: string, provider: ethers.providers.Provider) {
|
|
151
|
+
const [contract, setContract] = useState<ethers.Contract | null>(null);
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
const diamondContract = new ethers.Contract(address, DiamondABI.abi, provider);
|
|
155
|
+
setContract(diamondContract);
|
|
156
|
+
}, [address, provider]);
|
|
157
|
+
|
|
158
|
+
return contract;
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Viem Integration
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { createPublicClient, http } from 'viem';
|
|
166
|
+
import { mainnet } from 'viem/chains';
|
|
167
|
+
import DiamondABI from './artifacts/diamond-abi/GameDiamond.json';
|
|
168
|
+
|
|
169
|
+
const client = createPublicClient({
|
|
170
|
+
chain: mainnet,
|
|
171
|
+
transport: http()
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const result = await client.readContract({
|
|
175
|
+
address: '0x...',
|
|
176
|
+
abi: DiamondABI.abi,
|
|
177
|
+
functionName: 'someFunction'
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Output Structure
|
|
182
|
+
|
|
183
|
+
### Generated Files
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
artifacts/diamond-abi/
|
|
187
|
+
├── YourDiamond.json # Complete diamond artifact
|
|
188
|
+
├── YourDiamond.d.ts # TypeScript interface
|
|
189
|
+
└── metadata.json # Generation metadata
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Artifact Structure
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
{
|
|
196
|
+
"_format": "hh-sol-artifact-1",
|
|
197
|
+
"contractName": "YourDiamond",
|
|
198
|
+
"abi": [...], // Combined ABI
|
|
199
|
+
"_diamondMetadata": {
|
|
200
|
+
"generatedAt": "2024-01-01T00:00:00.000Z",
|
|
201
|
+
"diamondName": "YourDiamond",
|
|
202
|
+
"selectorMap": { // Selector to facet mapping
|
|
203
|
+
"0x01ffc9a7": "DiamondLoupeFacet"
|
|
204
|
+
},
|
|
205
|
+
"stats": { // Generation statistics
|
|
206
|
+
"totalFunctions": 15,
|
|
207
|
+
"totalEvents": 5,
|
|
208
|
+
"totalErrors": 2,
|
|
209
|
+
"facetCount": 4
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Common Use Cases
|
|
216
|
+
|
|
217
|
+
### 1. Development Workflow
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# 1. Compile contracts
|
|
221
|
+
npm run compile
|
|
222
|
+
|
|
223
|
+
# 2. Generate ABI
|
|
224
|
+
npm run diamond-abi generate --diamond YourDiamond --verbose
|
|
225
|
+
|
|
226
|
+
# 3. Generate types
|
|
227
|
+
npx typechain --target ethers-v5 --out-dir typechain-types artifacts/diamond-abi/*.json
|
|
228
|
+
|
|
229
|
+
# 4. Use in frontend
|
|
230
|
+
import { YourDiamond } from './typechain-types/YourDiamond';
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 2. CI/CD Pipeline
|
|
234
|
+
|
|
235
|
+
```yaml
|
|
236
|
+
- name: Generate Diamond ABI
|
|
237
|
+
run: |
|
|
238
|
+
npm run diamond-abi generate --diamond ${{ matrix.diamond }} --network ${{ matrix.network }}
|
|
239
|
+
npx typechain --target ethers-v5 --out-dir typechain-types artifacts/diamond-abi/*.json
|
|
240
|
+
|
|
241
|
+
- name: Upload artifacts
|
|
242
|
+
uses: actions/upload-artifact@v3
|
|
243
|
+
with:
|
|
244
|
+
name: diamond-abi
|
|
245
|
+
path: artifacts/diamond-abi/
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 3. Testing
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
describe('Diamond ABI', () => {
|
|
252
|
+
it('should generate valid ABI', async () => {
|
|
253
|
+
const result = await generateDiamondAbi(diamond);
|
|
254
|
+
expect(result.abi).to.be.an('array');
|
|
255
|
+
expect(result.stats.totalFunctions).to.be.greaterThan(0);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### 4. Multi-Network Deployment
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
const networks = ['localhost', 'sepolia', 'mainnet'];
|
|
264
|
+
const diamonds = ['GameDiamond', 'TradingDiamond'];
|
|
265
|
+
|
|
266
|
+
for (const network of networks) {
|
|
267
|
+
for (const diamondName of diamonds) {
|
|
268
|
+
await generateDiamondAbi(diamond, {
|
|
269
|
+
outputDir: `./artifacts/diamond-abi/${network}`
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Package.json Scripts
|
|
276
|
+
|
|
277
|
+
Add these scripts to your `package.json`:
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
{
|
|
281
|
+
"scripts": {
|
|
282
|
+
"diamond:abi": "npm run diamond-abi generate",
|
|
283
|
+
"diamond:types": "npm run diamond:abi && npx typechain --target ethers-v5 --out-dir typechain-types artifacts/diamond-abi/*.json",
|
|
284
|
+
"diamond:preview": "npm run diamond-abi preview --verbose",
|
|
285
|
+
"diamond:validate": "npm run diamond-abi validate artifacts/diamond-abi/*.json",
|
|
286
|
+
"diamond:clean": "rimraf artifacts/diamond-abi typechain-types"
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Environment Variables
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Optional environment variables
|
|
295
|
+
DIAMOND_ABI_OUTPUT_DIR=./artifacts/diamond-abi
|
|
296
|
+
DIAMOND_ABI_VERBOSE=true
|
|
297
|
+
DIAMOND_ABI_VALIDATE_SELECTORS=true
|
|
298
|
+
DIAMOND_ABI_INCLUDE_SOURCE=true
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Troubleshooting
|
|
302
|
+
|
|
303
|
+
### Common Issues
|
|
304
|
+
|
|
305
|
+
| Issue | Solution |
|
|
306
|
+
|-------|----------|
|
|
307
|
+
| "No artifacts found" | Run `npm run compile` first |
|
|
308
|
+
| "Function selector collision" | Enable `validateSelectors: true` |
|
|
309
|
+
| "Missing deployment data" | Check `diamonds/` directory |
|
|
310
|
+
| "TypeChain generation fails" | Validate ABI with `npm run diamond-abi validate` |
|
|
311
|
+
|
|
312
|
+
### Debug Mode
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# Enable verbose logging
|
|
316
|
+
npm run diamond-abi generate --verbose
|
|
317
|
+
|
|
318
|
+
# Or programmatically
|
|
319
|
+
const result = await generateDiamondAbi(diamond, { verbose: true });
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Best Practices
|
|
323
|
+
|
|
324
|
+
1. **Always validate selectors** in production
|
|
325
|
+
2. **Use caching** for better performance
|
|
326
|
+
3. **Generate types** for TypeScript projects
|
|
327
|
+
4. **Include in CI/CD** pipeline
|
|
328
|
+
5. **Version control** generated ABIs
|
|
329
|
+
6. **Test integration** with contracts
|
|
330
|
+
|
|
331
|
+
## Links
|
|
332
|
+
|
|
333
|
+
- [Main Implementation Guide](./DIAMOND_ABI_GENERATOR_IMPLEMENTATION.md)
|
|
334
|
+
- [Practical Examples](./DIAMOND_ABI_GENERATOR_EXAMPLES.md)
|
|
335
|
+
- [API Documentation](../src/utils/diamondAbiGenerator.ts)
|
|
336
|
+
- [CLI Source](../scripts/diamond-abi-cli.ts)
|