The UpgradeableProxy contract implements a proxy pattern that allows
forwarding calls to a designated withdrawal implementation address. This
implementation address can be updated by the owner, enabling flexible and
upgradeable functionality. The contract also includes initialization logic and
secure delegation.
-
Proxy Functionality:
- Delegates all external calls to the current implementation address.
- Uses inline assembly for efficient delegate calls.
-
Initialization:
- Can be initialized only once with the owner, factory, and withdrawal addresses.
- Ensures secure setup of the proxy.
-
ETH Handling:
- Handles incoming ETH transfers and emits relevant events for tracking.
-
Implementation Updates:
- Enables dynamic updates of the implementation address via secure access controls.
- Initializes the proxy contract with critical parameters:
owner_: Address of the proxy owner.factory_: Address of the factory contract.withdrawal_: Address of the withdrawal implementation.
- Ensures the initialization happens only once via the
initializermodifier. - Emits the
ProxyInitializedevent.
- Forwards all calls to the current withdrawal implementation.
- Validates the implementation address before delegating the call.
- Uses inline assembly for efficiency:
- Copies calldata.
- Performs a
delegatecallto the implementation. - Handles the return data or reverts appropriately.
- Receive Function:
- Accepts incoming ETH transfers and emits a
Receivedevent.
- Accepts incoming ETH transfers and emits a
- Fallback Function:
- Delegates all other calls to the implementation using
_delegate.
- Delegates all other calls to the implementation using
| Dependency | Purpose |
|---|---|
Initializable |
Ensures the proxy can only be initialized once. |
Address |
Provides utility functions for address validation and interaction. |
LibAdmin |
Manages admin roles, access controls, and storage for critical addresses. |
LibErrors |
Handles custom error definitions for better gas efficiency. |
IEvents |
Defines the system-wide events used in the proxy contract. |
| Event | Description |
|---|---|
ProxyInitialized |
Emitted when the proxy is successfully initialized. |
Received |
Emitted when ETH is received by the proxy contract. |
| Error Name | Description |
|---|---|
InvalidAddressWithdrawal |
Thrown if the withdrawal address is invalid (zero address). |
| Event Name | Parameters | Description |
|---|---|---|
ProxyInitialized |
address proxy, address withdrawal, address owner |
Logs the initialization of the proxy contract with relevant addresses. |
Received |
address sender, uint256 value |
Logs the receipt of ETH by the proxy contract. |
| Error Name | Parameters | Description |
|---|---|---|
InvalidAddressWithdrawal |
None | Thrown when the withdrawal implementation address is invalid or missing. |
- Uses inline assembly in
_delegatefor minimal gas overhead during delegate calls. - Relies on immutability for key logic and storage efficiency.
- Employs
initializermodifier to prevent re-initialization.
-
Enhanced Error Handling:
- Include more descriptive error messages for initialization and delegation failures.
-
Event Tracking:
- Emit events for significant updates, such as changes to the withdrawal implementation.
-
Upgradeable Proxy Logic:
- Extend functionality to allow for rollback or backup implementations in case of failure.
- Access Control:
- Uses
LibAdminto enforce secure access to initialization and updates.
- Uses
- Implementation Safety:
- Validates the withdrawal implementation address before delegation.
- ETH Handling:
- Securely manages incoming ETH via the
receivefunction.
- Securely manages incoming ETH via the