Skip to content

Commit

Permalink
Defender: Add txOverrides option (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau authored May 2, 2024
1 parent e08fb9f commit 7552dab
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 2 additions & 0 deletions DEFENDER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions docs/modules/api/pages/api-foundry-upgrades.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```

Expand Down
2 changes: 2 additions & 0 deletions docs/modules/pages/foundry-defender.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions src/Options.sol
Original file line number Diff line number Diff line change
@@ -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".
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The following options can be used with some of the below functions. See https://

{{DefenderOptions}}

{{TxOverrides}}

== Foundry Upgrades

{{Upgrades}}
Expand Down
16 changes: 16 additions & 0 deletions src/internal/DefenderDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/internal/Versions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
8 changes: 6 additions & 2 deletions test/Defender.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
6 changes: 5 additions & 1 deletion test/internal/DefenderDeploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.2.tgz#b1d03075e49290d06570b2fd42154d76c2a5d210"
integrity sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA==

"@openzeppelin/[email protected].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/[email protected].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"
Expand Down

0 comments on commit 7552dab

Please sign in to comment.