ProxyAdmin is typically a contract that acts as an administrator for upgradeable proxy contracts. The concept of proxy contracts and the ProxyAdmin contract is part of the upgradeable smart contract pattern, which allows for the logic of smart contracts to be upgraded after deployment, despite the blockchain's immutable nature.
Benefits
- Upgradability: The primary benefit of using proxy contracts is upgrading the contract's logic without changing the contract's address. This is crucial because smart contracts are immutable once deployed, but proxy contracts allow developers to fix bugs, add features, or modify the contract's logic by simply pointing the proxy to a new implementation contract.
- Data Preservation: Proxy contracts enable the preservation of the contract's state (data) across upgrades. Since the proxy contract holds the state and delegates calls to an implementation contract for the logic, upgrading the logic does not affect the stored data.
- Gas Efficiency: Deploying a new contract with significant logic can be gas-intensive. Proxy contracts can reduce deployment costs because only the proxy contract needs to be deployed initially, and the implementation contract can be simpler and require less gas to deploy.
- Transparency and Trust: Using well-known proxy patterns, such as OpenZeppelin's Transparent Proxy Pattern, can help make the contract's behaviour more predictable and trustworthy to users and developers, as these patterns are widely reviewed and tested.
Patterns
- Transparent Proxy Pattern: This pattern involves two contracts - a proxy and an implementation contract. The proxy contract holds the storage and delegates calls to the implementation contract, which contains the logic. A key feature of this pattern is the addition of an admin address that has the exclusive right to upgrade the proxy. To prevent confusion between admin functions and user functions, the proxy contract rejects calls to the admin functions made through the proxy, ensuring they can only be called directly on the admin contract.
- Universal Upgradeable Proxy Standard (UUPS): The UUPS pattern is an optimization of the proxy pattern that embeds the upgrade logic within the implementation contract itself, rather than in the proxy. This reduces the overall gas cost for deployments and upgrades. However, it requires that each implementation contract includes the upgrade function, making it crucial for developers to include this functionality in every new version.
- Diamond (EIP-2535): The Diamond pattern, or Multi-facet Proxy, allows for a contract to implement any number of interfaces and for these interfaces to be added, replaced, or removed. This pattern addresses the limitation of maximum contract size by enabling a contract to have its functionality spread out over several contracts. A diamond is controlled by a "diamondCut" function, which is used to add, replace, or remove functions. This pattern is highly flexible and powerful but also complex to implement and understand.
- Beacon Proxy Pattern: This pattern uses a beacon contract that holds the address of the current implementation contract. Each proxy contract then points to the beacon contract to find the current implementation address. When the implementation needs to be upgraded, only the beacon contract is updated. This pattern is useful when you have many instances of the same contract and want to upgrade them all at once without having to upgrade each proxy individually.