Upgrades

Smart contract Upgrades utilities and implementations

import "@openzeppelin/src/Upgrades.sol";

Library for deploying and managing upgradeable contracts from Forge scripts or tests.

NOTE: Requires OpenZeppelin Contracts v5 or higher.

deployUUPSProxy(string contractName, bytes initializerData, struct Options opts) → address

internal

#

Deploys a UUPS proxy using the given contract as the implementation.

deployUUPSProxy(string contractName, bytes initializerData) → address

internal

#

Deploys a UUPS proxy using the given contract as the implementation.

deployTransparentProxy(string contractName, address initialOwner, bytes initializerData, struct Options opts) → address

internal

#

Deploys a transparent proxy using the given contract as the implementation.

deployTransparentProxy(string contractName, address initialOwner, bytes initializerData) → address

internal

#

Deploys a transparent proxy using the given contract as the implementation.

upgradeProxy(address proxy, string contractName, bytes data, struct Options opts)

internal

#

Upgrades a proxy to a new implementation contract. Only supported for UUPS or transparent proxies.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

upgradeProxy(address proxy, string contractName, bytes data)

internal

#

Upgrades a proxy to a new implementation contract. Only supported for UUPS or transparent proxies.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

upgradeProxy(address proxy, string contractName, bytes data, struct Options opts, address tryCaller)

internal

#

Upgrades a proxy to a new implementation contract. Only supported for UUPS or transparent proxies.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

This function provides an additional tryCaller parameter to test an upgrade using a specific caller address. Use this if you encounter OwnableUnauthorizedAccount errors in your tests.

upgradeProxy(address proxy, string contractName, bytes data, address tryCaller)

internal

#

Upgrades a proxy to a new implementation contract. Only supported for UUPS or transparent proxies.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

This function provides an additional tryCaller parameter to test an upgrade using a specific caller address. Use this if you encounter OwnableUnauthorizedAccount errors in your tests.

deployBeacon(string contractName, address initialOwner, struct Options opts) → address

internal

#

Deploys an upgradeable beacon using the given contract as the implementation.

deployBeacon(string contractName, address initialOwner) → address

internal

#

Deploys an upgradeable beacon using the given contract as the implementation.

upgradeBeacon(address beacon, string contractName, struct Options opts)

internal

#

Upgrades a beacon to a new implementation contract.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

upgradeBeacon(address beacon, string contractName)

internal

#

Upgrades a beacon to a new implementation contract.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

upgradeBeacon(address beacon, string contractName, struct Options opts, address tryCaller)

internal

#

Upgrades a beacon to a new implementation contract.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

This function provides an additional tryCaller parameter to test an upgrade using a specific caller address. Use this if you encounter OwnableUnauthorizedAccount errors in your tests.

upgradeBeacon(address beacon, string contractName, address tryCaller)

internal

#

Upgrades a beacon to a new implementation contract.

Requires that either the referenceContract option is set, or the new implementation contract has a @custom:oz-upgrades-from <reference> annotation.

This function provides an additional tryCaller parameter to test an upgrade using a specific caller address. Use this if you encounter OwnableUnauthorizedAccount errors in your tests.

deployBeaconProxy(address beacon, bytes data) → address

internal

#

Deploys a beacon proxy using the given beacon and call data.

deployBeaconProxy(address beacon, bytes data, struct Options opts) → address

internal

#

Deploys a beacon proxy using the given beacon and call data.

validateImplementation(string contractName, struct Options opts)

internal

#

Validates an implementation contract, but does not deploy it.

deployImplementation(string contractName, struct Options opts) → address

internal

#

Validates and deploys an implementation contract, and returns its address.

validateUpgrade(string contractName, struct Options opts)

internal

#

Validates a new implementation contract in comparison with a reference contract, but does not deploy it.

Requires that either the referenceContract option is set, or the contract has a @custom:oz-upgrades-from <reference> annotation.

prepareUpgrade(string contractName, struct Options opts) → address

internal

#

Validates a new implementation contract in comparison with a reference contract, deploys the new implementation contract, and returns its address.

Requires that either the referenceContract option is set, or the contract has a @custom:oz-upgrades-from <reference> annotation.

Use this method to prepare an upgrade to be run from an admin address you do not control directly or cannot use from your deployment environment.

getAdminAddress(address proxy) → address

internal

#

Gets the admin address of a transparent proxy from its ERC1967 admin storage slot.

getImplementationAddress(address proxy) → address

internal

#

Gets the implementation address of a transparent or UUPS proxy from its ERC1967 implementation storage slot.

getBeaconAddress(address proxy) → address

internal

#

Gets the beacon address of a beacon proxy from its ERC1967 beacon storage slot.

import "@openzeppelin/src/Upgrades.sol";

Library for deploying and managing upgradeable contracts from Forge tests, without validations.

Can be used with forge coverage. Requires implementation contracts to be instantiated first. Does not require --ffi and does not require a clean compilation before each run.

Not supported for OpenZeppelin Defender deployments.

Not recommended for use in Forge scripts.

UnsafeUpgrades does not validate whether your contracts are upgrade safe or whether new implementations are compatible with previous ones. Use Upgrades if you want validations to be run.

NOTE: Requires OpenZeppelin Contracts v5 or higher.

deployUUPSProxy(address impl, bytes initializerData) → address

internal

#

Deploys a UUPS proxy using the given contract address as the implementation.

deployTransparentProxy(address impl, address initialOwner, bytes initializerData) → address

internal

#

Deploys a transparent proxy using the given contract address as the implementation.

upgradeProxy(address proxy, address newImpl, bytes data)

internal

#

Upgrades a proxy to a new implementation contract address. Only supported for UUPS or transparent proxies.

upgradeProxy(address proxy, address newImpl, bytes data, address tryCaller)

internal

#

Upgrades a proxy to a new implementation contract address. Only supported for UUPS or transparent proxies.

This function provides an additional tryCaller parameter to test an upgrade using a specific caller address. Use this if you encounter OwnableUnauthorizedAccount errors in your tests.

deployBeacon(address impl, address initialOwner) → address

internal

#

Deploys an upgradeable beacon using the given contract address as the implementation.

upgradeBeacon(address beacon, address newImpl)

internal

#

Upgrades a beacon to a new implementation contract address.

upgradeBeacon(address beacon, address newImpl, address tryCaller)

internal

#

Upgrades a beacon to a new implementation contract address.

This function provides an additional tryCaller parameter to test an upgrade using a specific caller address. Use this if you encounter OwnableUnauthorizedAccount errors in your tests.

deployBeaconProxy(address beacon, bytes data) → address

internal

#

Deploys a beacon proxy using the given beacon and call data.

getAdminAddress(address proxy) → address

internal

#

Gets the admin address of a transparent proxy from its ERC1967 admin storage slot.

getImplementationAddress(address proxy) → address

internal

#

Gets the implementation address of a transparent or UUPS proxy from its ERC1967 implementation storage slot.

getBeaconAddress(address proxy) → address

internal

#

Gets the beacon address of a beacon proxy from its ERC1967 beacon storage slot.