Upgrades

This crate provides interfaces and utilities related to upgradeability.

Core

IUpgradeable

use openzeppelin_upgrades::interface::IUpgradeable;

Interface of an upgradeable contract.

Functions

upgrade(new_class_hash: ClassHash) external

Upgrades the contract code by updating its class hash.

This function is usually protected by an Access Control mechanism.

IUpgradeAndCall

use openzeppelin::upgrades::interface::IUpgradeAndCall;

Interface for an upgradeable contract that couples an upgrade with a function call in the upgraded context.

Functions

upgrade_and_call(new_class_hash: ClassHash, selector: felt252, calldata: Span<felt252>) → Span<felt252> external

Upgrades the contract code by updating its class hash and calls selector with the upgraded context.

This function is usually protected by an Access Control mechanism.

UpgradeableComponent

use openzeppelin_upgrades::upgradeable::UpgradeableComponent;

Upgradeable component.

Internal Functions

upgrade(ref self: ContractState, new_class_hash: ClassHash) internal

Upgrades the contract by updating the contract class hash.

Requirements:

  • new_class_hash must be different from zero.

Emits an Upgraded event.

upgrade_and_call(ref self: ContractState, new_class_hash: ClassHash, selector: felt252, calldata: Span<felt252>) → Span<felt252> internal

Replaces the contract’s class hash with new_class_hash and then calls selector from the upgraded context. This function returns the unwrapped call_contract_syscall return value(s), if available, of the selector call.

Requirements:

  • new_class_hash must be different from zero.

The function call comes from the upgraded contract itself and not the account.
A similar behavior to upgrade_and_call can also be achieved with a list of calls from an account since the SNIP-6 account standard supports multicall. An account can execute a list of calls with upgrade being the first element in the list and the extra function call as the second. With this approach, the calls will execute from the account’s context and can’t be front-ran.

Emits an Upgraded event.

Events

Upgraded(class_hash: ClassHash) event

Emitted when the class hash is upgraded.