Skip to content

Commit

Permalink
upgrade defender and add support to tx overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
MCarlomagno committed Dec 20, 2023
1 parent 6a89da4 commit d3dd070
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"dependencies": {
"@openzeppelin/defender-admin-client": "^1.52.0",
"@openzeppelin/defender-base-client": "^1.52.0",
"@openzeppelin/defender-sdk-base-client": "^1.5.0",
"@openzeppelin/defender-sdk-deploy-client": "^1.5.0",
"@openzeppelin/defender-sdk-base-client": "^1.8.0",
"@openzeppelin/defender-sdk-deploy-client": "^1.8.0",
"@openzeppelin/upgrades-core": "^1.32.0",
"chalk": "^4.1.0",
"debug": "^4.1.1",
Expand Down
14 changes: 12 additions & 2 deletions packages/plugin-hardhat/src/defender/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ethers, ContractFactory } from 'ethers';
import type { ethers, ContractFactory, Overrides } from 'ethers';

Check warning on line 1 in packages/plugin-hardhat/src/defender/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

'Overrides' is defined but never used
import { CompilerInput, CompilerOutputContract, HardhatRuntimeEnvironment } from 'hardhat/types';

import { parseFullyQualifiedName } from 'hardhat/utils/contract-names';
Expand All @@ -18,7 +18,7 @@ import BeaconProxy from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/con
import UpgradeableBeacon from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts-v5/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.json';
import TransparentUpgradeableProxy from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts-v5/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json';

import { getNetwork, getDeployClient } from './utils';
import { getNetwork, getDeployClient, bigNumberishToHex, bigNumberishToNumber } from './utils';
import { DeployTransaction, DefenderDeployOptions, UpgradeOptions } from '../utils';
import debug from '../utils/debug';
import { getDeployData } from '../utils/deploy-impl';
Expand Down Expand Up @@ -73,6 +73,15 @@ export async function defenderDeploy(
debug(`Salt: ${opts.salt}`);
}

// TODO add TxOverrides type from defender
const txOverrides = opts.txOverrides ? {

Check warning on line 77 in packages/plugin-hardhat/src/defender/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎···`
gasLimit: bigNumberishToNumber(opts.txOverrides.gasLimit),

Check warning on line 78 in packages/plugin-hardhat/src/defender/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `····`
gasPrice: bigNumberishToHex(opts.txOverrides.gasPrice),

Check warning on line 79 in packages/plugin-hardhat/src/defender/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `····`
maxFeePerGas: bigNumberishToHex(opts.txOverrides.maxFeePerGas),

Check warning on line 80 in packages/plugin-hardhat/src/defender/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `········`
maxPriorityFeePerGas: bigNumberishToHex(opts.txOverrides.maxPriorityFeePerGas),

Check warning on line 81 in packages/plugin-hardhat/src/defender/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `····`
} : undefined;

Check warning on line 82 in packages/plugin-hardhat/src/defender/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `}·:·undefined;⏎` with `····}⏎····:·undefined;`


const deploymentRequest: DeployContractRequest = {
contractName: contractInfo.contractName,
contractPath: contractInfo.sourceName,
Expand All @@ -84,6 +93,7 @@ export async function defenderDeploy(
relayerId: opts.relayerId,
salt: opts.salt,
createFactoryAddress: opts.createFactoryAddress,
txOverrides,
};

let deploymentResponse: DeploymentResponse;
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-hardhat/src/defender/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DeployClient } from '@openzeppelin/defender-sdk-deploy-client';
import { HardhatDefenderConfig } from '../type-extensions';
import { DefenderDeploy } from '../utils';
import debug from '../utils/debug';
import { BigNumberish } from 'ethers';

import { promisify } from 'util';
const sleep = promisify(setTimeout);
Expand Down Expand Up @@ -145,3 +146,17 @@ export async function waitForDeployment(
}
return lastKnownTxHash;
}

export function bigNumberishToHex(value?: BigNumberish | null): string | undefined {
if (typeof value === 'string' && !!value) return value;

Check warning on line 151 in packages/plugin-hardhat/src/defender/utils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected { after 'if' condition
if (typeof value === 'number') return `0x${value.toString(16)}`;

Check warning on line 152 in packages/plugin-hardhat/src/defender/utils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected { after 'if' condition
if (typeof value === 'bigint') return `0x${Number(value).toString(16)}`;

Check warning on line 153 in packages/plugin-hardhat/src/defender/utils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected { after 'if' condition
return undefined;
}

export function bigNumberishToNumber(value?: BigNumberish | null): number | undefined {
if (typeof value === 'string' && !!value) return Number(value);
if (typeof value === 'bigint') return Number(value);
if (typeof value === 'number') return value;
return undefined;
}
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2417,21 +2417,21 @@
lodash "^4.17.19"
node-fetch "^2.6.0"

"@openzeppelin/defender-sdk-base-client@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-base-client/-/defender-sdk-base-client-1.5.0.tgz#82d2b45c84822dfadaba8b7cfe215df7ac3c4bec"
integrity sha512-8aN4sEE15/6LctA14ADr8c6QvEzEXfAtFlxo/Ys0N6UVfp8lRAYqDOpHd4mb8dMfkRzq5izMCuMYgAjC9GFflQ==
"@openzeppelin/defender-sdk-base-client@^1.8.0":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-base-client/-/defender-sdk-base-client-1.8.0.tgz#2209a060ce61b4dfc44c7ac0c2b1d86e18b69f7d"
integrity sha512-XIJat6BW2CTM74AwG5IL0Q/aE6RXj8x7smnVKmBql4wMvmirVW+njfwzZCLhUTiBXg9AlHxIInEF14SabfIisg==
dependencies:
amazon-cognito-identity-js "^6.3.6"
async-retry "^1.3.3"

"@openzeppelin/defender-sdk-deploy-client@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-deploy-client/-/defender-sdk-deploy-client-1.5.0.tgz#b0bdadc0f00a44c49a3f96e85673394f94f99d6c"
integrity sha512-DbE4Rpa90vSN7o5/sim5qzAVVsSWkZBJ+Z9yjkc8qPRheh2dRk6oe2GhVoQfXI/04XwMb2uNvtfU1VAH8AzgaQ==
"@openzeppelin/defender-sdk-deploy-client@^1.8.0":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-deploy-client/-/defender-sdk-deploy-client-1.8.0.tgz#1e186d2b3ff176c6a4c03e8207bad8022528975f"
integrity sha512-/tNS2EnHuA5l095wzMbIkGMDNHZLcZQ2eLUP8z+AeKaAUeR2z4qzZ1ul21kR3EJURAyoy8aULFZanLggoBWHrA==
dependencies:
"@ethersproject/abi" "^5.7.0"
"@openzeppelin/defender-sdk-base-client" "^1.5.0"
"@openzeppelin/defender-sdk-base-client" "^1.8.0"
axios "^1.4.0"
lodash "^4.17.21"

Expand Down

0 comments on commit d3dd070

Please sign in to comment.