Upgradeable Proxy
An Upgradeable Proxy is designed to allow changing the logic of a contract after it has been deployed, while keeping the same address and state.
Key Idea
-
Suppose you deploy a Wallet contract.
-
Later, you discover a bug or want to add a new feature (e.g., a new function fun()).
-
Normally, you'd have to deploy a new contract with the updated logic.
But this would give a new contract address, which is a problem because:
- Users or DApps interacting with the old address would break.
- All old state data would be lost.
Solution:
- Use a Proxy Contract that holds:
- The storage (state).
- A pointer (address) to the Implementation Contract (logic).
- When you call the proxy, it delegates the call to the logic contract using
DELEGATECALL.
- If you need to upgrade, you simply deploy a new Implementation Contract and point the proxy to it.
- The address of the proxy remains the same, so all users still interact with the same contract address.
Why Upgradeable Proxy?
- Upgradability: You can fix bugs or add features without changing the contract address.
- Persistent State: The proxy’s state remains intact across upgrades.
- Use Case: DeFi protocols, DAOs, and complex contracts that need continuous improvements.