LegacyUpgrades
Smart contract LegacyUpgrades utilities and implementations
import "@openzeppelin/src/LegacyUpgrades.sol";
Library for managing upgradeable contracts from Forge scripts or tests.
NOTE: Only for upgrading existing deployments using OpenZeppelin Contracts v4. For new deployments, use OpenZeppelin Contracts v5 and Upgrades.sol.
Functions
- upgradeProxy(proxy, contractName, data, opts)
- upgradeProxy(proxy, contractName, data)
- upgradeProxy(proxy, contractName, data, opts, tryCaller)
- upgradeProxy(proxy, contractName, data, tryCaller)
- upgradeBeacon(beacon, contractName, opts)
- upgradeBeacon(beacon, contractName)
- upgradeBeacon(beacon, contractName, opts, tryCaller)
- upgradeBeacon(beacon, contractName, tryCaller)
- validateUpgrade(contractName, opts)
- prepareUpgrade(contractName, opts)
- getAdminAddress(proxy)
- getImplementationAddress(proxy)
- getBeaconAddress(proxy)
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.
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.
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/LegacyUpgrades.sol";
Library for 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: Only for upgrading existing deployments using OpenZeppelin Contracts v4. For new deployments, use OpenZeppelin Contracts v5 and Upgrades.sol.
Functions
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.
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.
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.