Upgradable
Inherits: AxlOwnable, Implementation, IUpgradable
Title: Upgradable Contract
This contract provides an interface for upgradable smart contracts and includes the functionality to perform upgrades.
State Variables
_IMPLEMENTATION_SLOT
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
Functions
constructor
Constructor sets the implementation address to the address of the contract itself
This is used in the onlyProxy modifier to prevent certain functions from being called directly on the implementation contract itself.
The owner is initially set as address(1) because the actual owner is set within the proxy. It is not set as the zero address because Ownable is designed to throw an error for ownership transfers to the zero address.
constructor() AxlOwnable(address(1));
implementation
Returns the address of the current implementation
function implementation() public view returns (address implementation_);
Returns
| Name | Type | Description |
|---|---|---|
implementation_ | address | Address of the current implementation |
upgrade
Upgrades the contract to a new implementation
This function is only callable by the owner.
function upgrade(address newImplementation, bytes32 newImplementationCodeHash, bytes calldata params)
external
override
onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
newImplementation | address | The address of the new implementation contract |
newImplementationCodeHash | bytes32 | The codehash of the new implementation contract |
params | bytes | Optional setup parameters for the new implementation contract |
setup
Sets up the contract with initial data
This function is only callable by the proxy contract.
function setup(bytes calldata data) external override(IImplementation, Implementation) onlyProxy;
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | Initialization data for the contract |
_setup
Internal function to set up the contract with initial data
This function should be implemented in derived contracts.
function _setup(bytes calldata data) internal virtual;
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | Initialization data for the contract |