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

Defender

Library for interacting with OpenZeppelin Defender from Forge scripts or tests.

Functions

deployContract

Deploys a contract to the current network using OpenZeppelin Defender. WARNING: Do not use this function directly if you are deploying an upgradeable contract. This function does not validate whether the contract is upgrade safe. NOTE: If using an EOA or Safe to deploy, go to https://defender.openzeppelin.com/v2/#/deploy[Defender deploy] to submit the pending deployment while the script is running. The script waits for the deployment to complete before it continues.

function deployContract(string memory contractName) internal returns (address);

Parameters

NameTypeDescription
contractNamestringName of the contract to deploy, e.g. "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory

Returns

NameTypeDescription
<none>addressAddress of the deployed contract

deployContract

Deploys a contract to the current network using OpenZeppelin Defender. WARNING: Do not use this function directly if you are deploying an upgradeable contract. This function does not validate whether the contract is upgrade safe. NOTE: If using an EOA or Safe to deploy, go to https://defender.openzeppelin.com/v2/#/deploy[Defender deploy] to submit the pending deployment while the script is running. The script waits for the deployment to complete before it continues.

function deployContract(string memory contractName, DefenderOptions memory defenderOpts) internal returns (address);

Parameters

NameTypeDescription
contractNamestringName of the contract to deploy, e.g. "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory
defenderOptsDefenderOptionsDefender deployment options. Note that the useDefenderDeploy option is always treated as true when called from this function.

Returns

NameTypeDescription
<none>addressAddress of the deployed contract

deployContract

Deploys a contract with constructor arguments to the current network using OpenZeppelin Defender. WARNING: Do not use this function directly if you are deploying an upgradeable contract. This function does not validate whether the contract is upgrade safe. NOTE: If using an EOA or Safe to deploy, go to https://defender.openzeppelin.com/v2/#/deploy[Defender deploy] to submit the pending deployment while the script is running. The script waits for the deployment to complete before it continues.

function deployContract(string memory contractName, bytes memory constructorData) internal returns (address);

Parameters

NameTypeDescription
contractNamestringName of the contract to deploy, e.g. "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory
constructorDatabytesEncoded constructor arguments

Returns

NameTypeDescription
<none>addressAddress of the deployed contract

deployContract

Deploys a contract with constructor arguments to the current network using OpenZeppelin Defender. WARNING: Do not use this function directly if you are deploying an upgradeable contract. This function does not validate whether the contract is upgrade safe. NOTE: If using an EOA or Safe to deploy, go to https://defender.openzeppelin.com/v2/#/deploy[Defender deploy] to submit the pending deployment while the script is running. The script waits for the deployment to complete before it continues.

function deployContract(string memory contractName, bytes memory constructorData, DefenderOptions memory defenderOpts)
    internal
    returns (address);

Parameters

NameTypeDescription
contractNamestringName of the contract to deploy, e.g. "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory
constructorDatabytesEncoded constructor arguments
defenderOptsDefenderOptionsDefender deployment options. Note that the useDefenderDeploy option is always treated as true when called from this function.

Returns

NameTypeDescription
<none>addressAddress of the deployed contract

proposeUpgrade

Proposes an upgrade to an upgradeable proxy using OpenZeppelin Defender. This function validates a new implementation contract in comparison with a reference contract, deploys the new implementation contract using Defender, and proposes an upgrade to the new implementation contract using an upgrade approval process on Defender. Supported for UUPS or Transparent proxies. Not currently supported for beacon proxies or beacons. For beacons, use Upgrades.prepareUpgrade along with a transaction proposal on Defender to upgrade the beacon to the deployed implementation. Requires that either the referenceContract option is set, or the contract has a @custom:oz-upgrades-from <reference> annotation. WARNING: Ensure that the reference contract is the same as the current implementation contract that the proxy is pointing to. This function does not validate that the reference contract is the current implementation. NOTE: If using an EOA or Safe to deploy, go to https://defender.openzeppelin.com/v2/#/deploy[Defender deploy] to submit the pending deployment of the new implementation contract while the script is running. The script waits for the deployment to complete before it continues.

function proposeUpgrade(address proxyAddress, string memory newImplementationContractName, Options memory opts)
    internal
    returns (ProposeUpgradeResponse memory);

Parameters

NameTypeDescription
proxyAddressaddressThe proxy address
newImplementationContractNamestringName of the new implementation contract to upgrade to, e.g. "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory
optsOptionsCommon options. Note that the defender.useDefenderDeploy option is always treated as true when called from this function.

Returns

NameTypeDescription
<none>ProposeUpgradeResponseStruct containing the proposal ID and URL for the upgrade proposal

getDeployApprovalProcess

Gets the default deploy approval process configured for your deployment environment on OpenZeppelin Defender.

function getDeployApprovalProcess() internal returns (ApprovalProcessResponse memory);

Returns

NameTypeDescription
<none>ApprovalProcessResponseStruct with the default deploy approval process ID and the associated address, such as a Relayer, EOA, or multisig wallet address.

getUpgradeApprovalProcess

Gets the default upgrade approval process configured for your deployment environment on OpenZeppelin Defender. For example, this is useful for determining the default multisig wallet that you can use in your scripts to assign as the owner of your proxy.

function getUpgradeApprovalProcess() internal returns (ApprovalProcessResponse memory);

Returns

NameTypeDescription
<none>ApprovalProcessResponseStruct with the default upgrade approval process ID and the associated address, such as a multisig or governor contract address.