Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Upgradable

Git Source

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

NameTypeDescription
implementation_addressAddress 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

NameTypeDescription
newImplementationaddressThe address of the new implementation contract
newImplementationCodeHashbytes32The codehash of the new implementation contract
paramsbytesOptional 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

NameTypeDescription
databytesInitialization 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

NameTypeDescription
databytesInitialization data for the contract