diff --git a/CHANGELOG.md b/CHANGELOG.md index f76702b..7e25257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.2.3 (2024-05-02) + +- Defender: Add `txOverrides` option. ([#49](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/pull/49)) + ## 0.2.2 (2024-04-17) - Defender: Fix handling of license types for block explorer verification, support `licenseType` and `skipLicenseType` options. ([#43](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/pull/43)) diff --git a/DEFENDER.md b/DEFENDER.md index c4601bf..547eebd 100644 --- a/DEFENDER.md +++ b/DEFENDER.md @@ -142,6 +142,8 @@ pragma solidity ^0.8.20; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; +import {MyContract} from "../src/MyContract.sol"; + import {Defender} from "openzeppelin-foundry-upgrades/Defender.sol"; contract DefenderScript is Script { diff --git a/docs/modules/api/pages/api-foundry-upgrades.adoc b/docs/modules/api/pages/api-foundry-upgrades.adoc index 54e24ea..c008dba 100644 --- a/docs/modules/api/pages/api-foundry-upgrades.adoc +++ b/docs/modules/api/pages/api-foundry-upgrades.adoc @@ -74,6 +74,24 @@ struct DefenderOptions { string upgradeApprovalProcessId; string licenseType; bool skipLicenseType; + struct TxOverrides txOverrides; +} +``` + +[[TxOverrides]] +=== `++TxOverrides++` link:https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/blob/main/src/Options.sol[{github-icon},role=heading-link] + +[.hljs-theme-light.nopadding] +```solidity +import { TxOverrides } from "openzeppelin-foundry-upgrades/Options.sol"; +``` + +```solidity +struct TxOverrides { + uint256 gasLimit; + uint256 gasPrice; + uint256 maxFeePerGas; + uint256 maxPriorityFeePerGas; } ``` diff --git a/docs/modules/pages/foundry-defender.adoc b/docs/modules/pages/foundry-defender.adoc index fd6b314..2eece4f 100644 --- a/docs/modules/pages/foundry-defender.adoc +++ b/docs/modules/pages/foundry-defender.adoc @@ -149,6 +149,8 @@ pragma solidity ^0.8.20; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; +import {MyContract} from "../src/MyContract.sol"; + import {Defender} from "openzeppelin-foundry-upgrades/Defender.sol"; contract DefenderScript is Script { diff --git a/package.json b/package.json index 14f4c1d..52625d6 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "devDependencies": { "@nomicfoundation/hardhat-foundry": "^1.1.1", "@openzeppelin/contracts": "^5.0.2", - "@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.6", + "@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.7", "@openzeppelin/upgrades-core": "^1.32.3", "hardhat": "^2.21.0", "prettier": "^3.0.0", diff --git a/src/Options.sol b/src/Options.sol index 5aa4826..09d5fc1 100644 --- a/src/Options.sol +++ b/src/Options.sol @@ -1,6 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; +/** + * Common options. + */ struct Options { /** * The reference contract to use for storage layout comparisons, e.g. "ContractV1.sol" or "ContractV1.sol:ContractV1". @@ -36,6 +39,9 @@ struct Options { DefenderOptions defender; } +/** + * Options for OpenZeppelin Defender deployments. + */ struct DefenderOptions { /** * Deploys contracts using OpenZeppelin Defender instead of broadcasting deployments through Forge. Defaults to `false`. See DEFENDER.md. @@ -79,4 +85,30 @@ struct DefenderOptions { * Defaults to `false`. */ bool skipLicenseType; + /** + * Transaction overrides for OpenZeppelin Defender deployments. + */ + TxOverrides txOverrides; +} + +/** + * Transaction overrides for OpenZeppelin Defender deployments. + */ +struct TxOverrides { + /** + * Maximum amount of gas to allow the deployment transaction to use. + */ + uint256 gasLimit; + /** + * Gas price for legacy transactions, in wei. + */ + uint256 gasPrice; + /** + * Maximum total fee per gas, in wei. + */ + uint256 maxFeePerGas; + /** + * Maximum priority fee per gas, in wei. + */ + uint256 maxPriorityFeePerGas; } diff --git a/src/README.adoc b/src/README.adoc index f2c3c4d..ac26760 100644 --- a/src/README.adoc +++ b/src/README.adoc @@ -8,6 +8,8 @@ The following options can be used with some of the below functions. See https:// {{DefenderOptions}} +{{TxOverrides}} + == Foundry Upgrades {{Upgrades}} diff --git a/src/internal/DefenderDeploy.sol b/src/internal/DefenderDeploy.sol index de46b75..27063f7 100644 --- a/src/internal/DefenderDeploy.sol +++ b/src/internal/DefenderDeploy.sol @@ -102,6 +102,22 @@ library DefenderDeploy { inputBuilder[i++] = "--salt"; inputBuilder[i++] = vm.toString(defenderOpts.salt); } + if (defenderOpts.txOverrides.gasLimit != 0) { + inputBuilder[i++] = "--gasLimit"; + inputBuilder[i++] = Strings.toString(defenderOpts.txOverrides.gasLimit); + } + if (defenderOpts.txOverrides.gasPrice != 0) { + inputBuilder[i++] = "--gasPrice"; + inputBuilder[i++] = Strings.toString(defenderOpts.txOverrides.gasPrice); + } + if (defenderOpts.txOverrides.maxFeePerGas != 0) { + inputBuilder[i++] = "--maxFeePerGas"; + inputBuilder[i++] = Strings.toString(defenderOpts.txOverrides.maxFeePerGas); + } + if (defenderOpts.txOverrides.maxPriorityFeePerGas != 0) { + inputBuilder[i++] = "--maxPriorityFeePerGas"; + inputBuilder[i++] = Strings.toString(defenderOpts.txOverrides.maxPriorityFeePerGas); + } // Create a copy of inputs but with the correct length string[] memory inputs = new string[](i); diff --git a/src/internal/Versions.sol b/src/internal/Versions.sol index 77183ac..67cf4a9 100644 --- a/src/internal/Versions.sol +++ b/src/internal/Versions.sol @@ -4,5 +4,5 @@ pragma solidity ^0.8.20; library Versions { // TODO add a workflow to update this automatically based on package.json string constant UPGRADES_CORE = "^1.32.3"; - string constant DEFENDER_DEPLOY_CLIENT_CLI = "0.0.1-alpha.6"; + string constant DEFENDER_DEPLOY_CLIENT_CLI = "0.0.1-alpha.7"; } diff --git a/test/Defender.s.sol b/test/Defender.s.sol index 646fbe0..1c2e75f 100644 --- a/test/Defender.s.sol +++ b/test/Defender.s.sol @@ -4,7 +4,9 @@ pragma solidity ^0.8.20; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {Defender} from "openzeppelin-foundry-upgrades/Defender.sol"; +import {WithConstructor} from "./contracts/WithConstructor.sol"; + +import {Defender, DefenderOptions} from "openzeppelin-foundry-upgrades/Defender.sol"; /** * @dev Sample script to deploy a contract using Defender. @@ -13,7 +15,9 @@ contract DefenderScript is Script { function setUp() public {} function run() public { - address deployed = Defender.deployContract("WithConstructor.sol", abi.encode(123)); + DefenderOptions memory opts; + // Add options here + address deployed = Defender.deployContract("WithConstructor.sol", abi.encode(123), opts); console.log("Deployed contract to address", deployed); } } diff --git a/test/internal/DefenderDeploy.t.sol b/test/internal/DefenderDeploy.t.sol index d9cc08b..68d8293 100644 --- a/test/internal/DefenderDeploy.t.sol +++ b/test/internal/DefenderDeploy.t.sol @@ -95,6 +95,10 @@ contract DefenderDeployTest is Test { opts.relayerId = "my-relayer-id"; opts.salt = 0xabc0000000000000000000000000000000000000000000000000000000000123; opts.licenseType = "My License Type"; // not a valid type, but this just sets the option + opts.txOverrides.gasLimit = 100000; + opts.txOverrides.gasPrice = 1 gwei; + opts.txOverrides.maxFeePerGas = 2 gwei; + opts.txOverrides.maxPriorityFeePerGas = 0.5 gwei; string memory commandString = _toString( DefenderDeploy.buildDeployCommand(contractInfo, buildInfoFile, constructorData, opts) @@ -107,7 +111,7 @@ contract DefenderDeployTest is Test { Versions.DEFENDER_DEPLOY_CLIENT_CLI, " deploy --contractName WithConstructor --contractPath test/contracts/WithConstructor.sol --chainId 31337 --buildInfoFile ", buildInfoFile, - ' --constructorBytecode 0x000000000000000000000000000000000000000000000000000000000000007b --licenseType "My License Type" --relayerId my-relayer-id --salt 0xabc0000000000000000000000000000000000000000000000000000000000123' + ' --constructorBytecode 0x000000000000000000000000000000000000000000000000000000000000007b --licenseType "My License Type" --relayerId my-relayer-id --salt 0xabc0000000000000000000000000000000000000000000000000000000000123 --gasLimit 100000 --gasPrice 1000000000 --maxFeePerGas 2000000000 --maxPriorityFeePerGas 500000000' ) ); } diff --git a/yarn.lock b/yarn.lock index 9086f9a..0d2d378 100644 --- a/yarn.lock +++ b/yarn.lock @@ -428,10 +428,10 @@ resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.2.tgz#b1d03075e49290d06570b2fd42154d76c2a5d210" integrity sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA== -"@openzeppelin/defender-deploy-client-cli@0.0.1-alpha.6": - version "0.0.1-alpha.6" - resolved "https://registry.yarnpkg.com/@openzeppelin/defender-deploy-client-cli/-/defender-deploy-client-cli-0.0.1-alpha.6.tgz#73a7671cc8343883ad8b462784e3ce5a41d9d150" - integrity sha512-yye4SGdaRFRo3BVSJEsJQzguBAYFIX7x9O6KRrCTKR8pcPsNn+tSBokk4qDMKKYmdMcAfZVCvGxwG3F3ZjXcmg== +"@openzeppelin/defender-deploy-client-cli@0.0.1-alpha.7": + version "0.0.1-alpha.7" + resolved "https://registry.yarnpkg.com/@openzeppelin/defender-deploy-client-cli/-/defender-deploy-client-cli-0.0.1-alpha.7.tgz#177f8c027f97f5e03a71fcda18b4c742ade2e870" + integrity sha512-BHJc45sES8X5r6N4YuLb6TFoglTDbPWBCYmHcqajMsrhkWMQj0relIH0e9YK68shGpYXJHKskjJmG6W3EHEh1w== dependencies: "@openzeppelin/defender-sdk-base-client" "^1.10.0" "@openzeppelin/defender-sdk-deploy-client" "^1.10.0"