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

UnsafeUpgrades

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. WARNING: 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.

Functions

deployUUPSProxy

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

function deployUUPSProxy(address impl, bytes memory initializerData) internal returns (address);

Parameters

NameTypeDescription
impladdressAddress of the contract to use as the implementation
initializerDatabytesEncoded call data of the initializer function to call during creation of the proxy, or empty if no initialization is required

Returns

NameTypeDescription
<none>addressProxy address

deployTransparentProxy

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

function deployTransparentProxy(address impl, address initialOwner, bytes memory initializerData)
    internal
    returns (address);

Parameters

NameTypeDescription
impladdressAddress of the contract to use as the implementation
initialOwneraddressAddress to set as the owner of the ProxyAdmin contract which gets deployed by the proxy
initializerDatabytesEncoded call data of the initializer function to call during creation of the proxy, or empty if no initialization is required

Returns

NameTypeDescription
<none>addressProxy address

upgradeProxy

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

function upgradeProxy(address proxy, address newImpl, bytes memory data) internal;

Parameters

NameTypeDescription
proxyaddressAddress of the proxy to upgrade
newImpladdressAddress of the new implementation contract to upgrade to
databytesEncoded call data of an arbitrary function to call during the upgrade process, or empty if no function needs to be called during the upgrade

upgradeProxy

For tests only. If broadcasting in scripts, use the --sender <ADDRESS> option with forge script instead.

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.

function upgradeProxy(address proxy, address newImpl, bytes memory data, address tryCaller) internal;

Parameters

NameTypeDescription
proxyaddressAddress of the proxy to upgrade
newImpladdressAddress of the new implementation contract to upgrade to
databytesEncoded call data of an arbitrary function to call during the upgrade process, or empty if no function needs to be called during the upgrade
tryCalleraddressAddress to use as the caller of the upgrade function. This should be the address that owns the proxy or its ProxyAdmin.

deployBeacon

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

function deployBeacon(address impl, address initialOwner) internal returns (address);

Parameters

NameTypeDescription
impladdressAddress of the contract to use as the implementation
initialOwneraddressAddress to set as the owner of the UpgradeableBeacon contract which gets deployed

Returns

NameTypeDescription
<none>addressBeacon address

upgradeBeacon

Upgrades a beacon to a new implementation contract address.

function upgradeBeacon(address beacon, address newImpl) internal;

Parameters

NameTypeDescription
beaconaddressAddress of the beacon to upgrade
newImpladdressAddress of the new implementation contract to upgrade to

upgradeBeacon

For tests only. If broadcasting in scripts, use the --sender <ADDRESS> option with forge script instead.

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.

function upgradeBeacon(address beacon, address newImpl, address tryCaller) internal;

Parameters

NameTypeDescription
beaconaddressAddress of the beacon to upgrade
newImpladdressAddress of the new implementation contract to upgrade to
tryCalleraddressAddress to use as the caller of the upgrade function. This should be the address that owns the beacon.

deployBeaconProxy

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

function deployBeaconProxy(address beacon, bytes memory data) internal returns (address);

Parameters

NameTypeDescription
beaconaddressAddress of the beacon to use
databytesEncoded call data of the initializer function to call during creation of the proxy, or empty if no initialization is required

Returns

NameTypeDescription
<none>addressProxy address

getAdminAddress

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

function getAdminAddress(address proxy) internal view returns (address);

Parameters

NameTypeDescription
proxyaddressAddress of a transparent proxy

Returns

NameTypeDescription
<none>addressAdmin address

getImplementationAddress

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

function getImplementationAddress(address proxy) internal view returns (address);

Parameters

NameTypeDescription
proxyaddressAddress of a transparent or UUPS proxy

Returns

NameTypeDescription
<none>addressImplementation address

getBeaconAddress

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

function getBeaconAddress(address proxy) internal view returns (address);

Parameters

NameTypeDescription
proxyaddressAddress of a beacon proxy

Returns

NameTypeDescription
<none>addressBeacon address