A modular, upgradeable smart contract system built on the ERC-2535 Diamond Proxy Standard, providing a flexible foundation for decentralized autonomous organization (DAO) functionality.
- π Diamond Proxy Architecture: Implements ERC-2535 for unlimited contract size and modularity
- π Seamless Upgrades: Add, replace, or remove functionality without changing the main contract address
- ποΈ Modular Design: Organized facet system for clear separation of concerns
- π‘οΈ Enterprise Security: OpenZeppelin Defender integration for production deployments
- π§ͺ Comprehensive Testing: Multi-chain testing environment with extensive test coverage
- β‘ TypeScript Integration: Full type safety with auto-generated TypeScript bindings
- π Multi-Network Support: Deploy across multiple EVM-compatible networks
- π Advanced Monitoring: Real-time deployment tracking and status monitoring
βββββββββββββββββββ
β Diamond β β Main contract (never changes address)
β (Proxy) β
βββββββββββ¬ββββββββ
β
βββββββΌββββββ
β Diamond β
β Storage β
βββββββ¬ββββββ
β
βββββββΌββββββββββββββββββββββββββββββ
β Facets β
βββββββββββββββ¬ββββββββββββββββββββββ€
β Ownership β Access Control β
β Facet β Facet β
βββββββββββββββΌββββββββββββββββββββββ€
β Diamond β Diamond β
β Cut Facet β Loupe Facet β
βββββββββββββββΌββββββββββββββββββββββ€
β Init β Custom β
β Facet β Facets β
βββββββββββββββ΄ββββββββββββββββββββββ- DiamondCutFacet: Handles diamond upgrades (add/replace/remove facets)
- DiamondLoupeFacet: Inspection functions for facets and selectors
- ExampleOwnershipFacet: Ownership management and access control
- ExampleAccessControlFacet: Role-based access control system
- ExampleInitFacet: Initialization and upgrade logic
- Node.js >= 20.0.0
- Yarn (recommended) or npm
- Git
# Clone the repository
git clone https://github.com/GeniusVentures/diamonds-base.git
cd diamonds-base
# Install dependencies
yarn install
# Copy environment template
cp .env.example .envSet up your environment variables in .env:
# Network Configuration
MAINNET_RPC=https://mainnet.infura.io/v3/your-key
SEPOLIA_RPC=https://sepolia.infura.io/v3/your-key
POLYGON_RPC=https://polygon-mainnet.g.alchemy.com/v2/your-key
# Deployment Keys
PRIVATE_KEY=your_private_key_here
TEST_PRIVATE_KEY=your_test_private_key_here
# API Keys for Verification
ETHERSCAN_API_KEY=your_etherscan_api_key
POLYGONSCAN_API_KEY=your_polygonscan_api_key# Compile all contracts and generate Diamond ABI with TypeScript types
yarn compile
# Build TypeScript and compile contracts with Diamond ABI generation
yarn build
# Clean compiled artifacts
yarn clean# Run all tests
yarn test
# Run tests with coverage
yarn coverage
# Run specific test file
yarn test test/unit/diamond-abi-generator.test.tsThe project includes the following yarn scripts defined in package.json:
# Development Scripts
yarn clean # Clean compiled artifacts
yarn compile # Compile contracts and generate Diamond ABI
yarn build # Build TypeScript, compile contracts, and generate ABI (β οΈ currently has TypeScript errors)
yarn test # Run all tests
yarn coverage # Run tests with coverage report
# ABI Generation Scripts
yarn generate-diamond-abi # Generate Diamond ABI
yarn generate-diamond-abi-typechain # Generate Diamond ABI with TypeChain typesNote: The
yarn buildcommand currently has TypeScript compilation errors that need to be resolved. For development, useyarn compilewhich works correctly.
For deployment, you'll need to use the deployment scripts directly:
# Example: Deploy using TypeScript scripts
npx ts-node scripts/deploy/rpc/deploy-rpc.ts ExampleDiamond sepolia
# Example: Deploy using Defender
npx ts-node scripts/deploy/defender/deploy-defender.ts ExampleDiamond mainnetThe project includes several deployment strategies using TypeScript scripts:
# Basic deployment
npx ts-node scripts/deploy/rpc/deploy-rpc.ts ExampleDiamond sepolia
# With custom options (if supported by script)
npx ts-node scripts/deploy/rpc/deploy-rpc.ts ExampleDiamond sepolia --verbose
# Manual step-by-step deployment
npx ts-node scripts/deploy/rpc/deploy-rpc-manual.ts ExampleDiamond sepolia# Deploy via OpenZeppelin Defender
npx ts-node scripts/deploy/defender/deploy-defender.ts ExampleDiamond mainnet
# Check deployment status
npx ts-node scripts/deploy/defender/status-defender.ts ExampleDiamond mainnet# Check deployment status
npx ts-node scripts/deploy/rpc/status-rpc.ts ExampleDiamond sepolia --detailed
# Verify deployment integrity
npx ts-node scripts/deploy/rpc/verify-rpc.ts ExampleDiamond sepolia --etherscan
# Upgrade diamond (add new facets or update existing ones)
npx ts-node scripts/deploy/rpc/upgrade-rpc.ts ExampleDiamond sepoliaThe project automatically generates a combined Diamond ABI with TypeScript types:
# Generate Diamond ABI
yarn generate-diamond-abi
# Generate with TypeChain types
yarn generate-diamond-abi-typechain
# Build everything (compile + generate ABI)
yarn build# Run all tests
yarn test
# Run tests with coverage
yarn coverage
# Run specific test files
yarn test test/unit/diamond-abi-generator.test.ts
yarn test test/integration/defender/DefenderDeployment.test.tsdiamonds-base/
βββ contracts/ # Solidity smart contracts
β βββ examplediamond/ # Diamond facet contracts
β βββ facets/ # Individual facet implementations
β βββ interfaces/ # Solidity interfaces
β βββ libraries/ # Shared libraries
β βββ upgradeInitializers/ # Upgrade initialization contracts
βββ diamonds/ # Diamond configuration
β βββ ExampleDiamond/ # Diamond-specific config
β βββ deployments/ # Deployment records
β βββ callbacks/ # Post-deployment callbacks
β βββ examplediamond.config.json # Facet configuration
βββ scripts/ # Deployment and utility scripts
β βββ deploy/ # Deployment strategies
β β βββ rpc/ # Direct RPC deployment
β β βββ defender/ # OpenZeppelin Defender deployment
β βββ setup/ # Deployment infrastructure
β βββ utils/ # Utility functions
βββ test/ # Test suite
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
β βββ deployment/ # Deployment tests
βββ typechain-types/ # Generated TypeScript types
βββ diamond-typechain-types/ # Diamond-specific TypeScript types
βββ diamond-abi/ # Generated Diamond ABI artifactsThe diamond configuration is defined in diamonds/ExampleDiamond/examplediamond.config.json:
{
"protocolVersion": 1.0,
"protocolInitFacet": "ExampleInitFacet",
"facets": {
"DiamondCutFacet": {
"priority": 10,
"versions": { "0.0": {} }
},
"DiamondLoupeFacet": {
"priority": 20,
"versions": { "0.0": {} }
},
"ExampleOwnershipFacet": {
"priority": 30,
"versions": { "0.0": {} }
}
}
}Key configurations in hardhat.config.ts:
- Multi-chain support via
hardhat-multichain - Diamond configuration via
hardhat-diamonds - Network settings for multiple EVM chains
- Compiler optimization for gas efficiency
- Unit Tests: Individual facet testing
- Integration Tests: Cross-facet functionality
- Deployment Tests: End-to-end deployment validation
- Multi-chain Tests: Cross-network compatibility
# Run tests with Hardhat
yarn test
# Test with coverage
yarn coverage
# Test specific files
yarn test test/specific-test-file.test.ts- Diamond test helpers: Load and interact with deployed diamonds
- Network utilities: Multi-chain test orchestration
- Mock contracts: Isolated testing environments
- Multi-signature support via OpenZeppelin Defender
- Role-based access control with granular permissions
- Upgrade authorization with ownership verification
- Function selector collision prevention
- Comprehensive test coverage including edge cases
- Slither: Static analysis for vulnerability detection
- OpenZeppelin Defender: Production-grade security monitoring
- Coverage reports: Ensure comprehensive testing
- Gas optimization: Efficient contract execution
- Instant deployment and testing
- Full upgrade simulation
- Development-focused tooling
- Direct blockchain interaction
- Custom gas strategies
- Retry mechanisms for reliability
- Multi-signature workflow
- Automated monitoring
- Enterprise security features
// Example: Create a new facet
pragma solidity ^0.8.9;
import "../libraries/LibDiamond.sol";
contract CustomFacet {
function customFunction() external {
LibDiamond.enforceIsContractOwner();
// Your logic here
}
}# Add new facet
npx ts-node scripts/deploy/rpc/upgrade-rpc.ts ExampleDiamond sepolia
# Dry run upgrade (see what will change, if supported by script)
npx ts-node scripts/deploy/rpc/upgrade-rpc.ts ExampleDiamond sepolia --dry-runimport { ExampleDiamond } from '../diamond-typechain-types';
import { ethers } from 'hardhat';
// Type-safe contract interaction
const diamond = await ethers.getContractAt(
'ExampleDiamond',
diamondAddress
) as ExampleDiamond;
// All functions are typed and auto-completed
await diamond.transferOwnership(newOwner);We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run the test suite:
yarn test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Solidity: Follow official style guide
- TypeScript: ESLint + Prettier configuration
- Testing: Minimum 80% coverage required
- Documentation: Comprehensive inline documentation
- Diamond Standard (EIP-2535)
- OpenZeppelin Defender Docs
- Hardhat Documentation
- TypeChain Documentation
# The yarn build command currently has TypeScript compilation errors
# Use yarn compile instead for development:
yarn clean
yarn compile# Clean and regenerate
yarn clean
yarn compile
# OR
yarn build# Clean all artifacts and rebuild
yarn clean
yarn compile# Some tests may fail due to missing contract artifacts
# Ensure contracts are compiled first:
yarn compile
yarn testThis project is licensed under the MIT License - see the LICENSE file for details.
- EIP-2535 Diamond Standard by Nick Mudge
- OpenZeppelin for security standards
- Hardhat for development framework
- TypeChain for TypeScript integration