Core
Smart contract Core utilities and implementations
import "@openzeppelin/src/internal/Core.sol";
Internal helper methods to validate/deploy implementations and perform upgrades.
DO NOT USE DIRECTLY. Use Upgrades.sol, LegacyUpgrades.sol or Defender.sol instead.
Modifiers
Functions
- upgradeProxy(proxy, contractName, data, opts)
- upgradeProxy(proxy, contractName, data, opts, tryCaller)
- upgradeProxyTo(proxy, newImpl, data)
- upgradeProxyTo(proxy, newImpl, data, tryCaller)
- upgradeBeacon(beacon, contractName, opts)
- upgradeBeacon(beacon, contractName, opts, tryCaller)
- upgradeBeaconTo(beacon, newImpl)
- upgradeBeaconTo(beacon, newImpl, tryCaller)
- validateImplementation(contractName, opts)
- deployImplementation(contractName, opts)
- validateUpgrade(contractName, opts)
- prepareUpgrade(contractName, opts)
- getAdminAddress(proxy)
- getImplementationAddress(proxy)
- getBeaconAddress(proxy)
- getUpgradeInterfaceVersion(addr)
- inferProxyAdmin(addr)
- buildValidateCommand(contractName, opts, requireReference)
- deploy(contractName, constructorData, opts)
tryPrank(address deployer)
internal
#Runs a function as a prank, or just runs the function normally if the prank could not be started.
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, 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.
upgradeProxyTo(address proxy, address newImpl, bytes data)
internal
#Upgrades a proxy to a new implementation contract. Only supported for UUPS or transparent proxies.
upgradeProxyTo(address proxy, address newImpl, bytes data, address tryCaller)
internal
#Upgrades a proxy to a new implementation contract. 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, 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, 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.
upgradeBeaconTo(address beacon, address newImpl)
internal
#Upgrades a beacon to a new implementation contract address.
upgradeBeaconTo(address beacon, address newImpl, address tryCaller)
internal
#Upgrades a beacon to a new implementation contract.
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.
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.
getUpgradeInterfaceVersion(address addr) → string
internal
#Gets the upgrade interface version string from a proxy or admin contract using the UPGRADE_INTERFACE_VERSION()
getter.
If the contract does not have the getter or the return data does not look like a string, this function returns an empty string.
inferProxyAdmin(address addr) → bool
internal
#Infers whether the address might be a ProxyAdmin contract.
buildValidateCommand(string contractName, struct Options opts, bool requireReference) → string[]
internal
#deploy(string contractName, bytes constructorData, struct Options opts) → address
internal
#