Notes: OpenZeppelin, Factory Contracts, and Delegatecall
1. OpenZeppelin Libraries
- OpenZeppelin provides battle-tested Solidity libraries for common patterns (ERC standards, ownership, access control, etc.).
- Key benefits:
- Security (avoids common bugs).
- Reusable components.
- Upgradability support (via proxy contracts).
1.1 Upgradeable Contracts
- Upgradeable contracts separate storage and logic.
- Logic is implemented in a logic contract (V1, V2…).
- Storage is maintained in a proxy contract.
- Proxy uses delegatecall to forward calls to the current logic contract.
- Advantages:
- Users interact with the same address even after upgrades.
- Allows adding/changing functionality without redeploying everything.
Key OpenZeppelin Tools:
@openzeppelin/contracts-upgradeable
ERC1967Proxy (upgradable proxy)
Initializable (replaces constructor for proxies)