Skip to content

Commit

Permalink
Merge branch 'master' into 5.0proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Nov 22, 2023
2 parents ca24455 + 6104d96 commit ca9547a
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 154 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
package:
- core
- plugin-hardhat
- plugin-truffle
- plugin-defender-hardhat

runs-on: ubuntu-latest

Expand Down
6 changes: 6 additions & 0 deletions packages/core/contracts/test/NamespacedToModify.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ contract Example {
uint256 y;
}

/// @custom:storage-location erc7201:example.secondary
struct SecondaryStorage {
uint256 a;
uint256 b;
}

/// @notice some natspec
function foo() public {}

Expand Down
12 changes: 7 additions & 5 deletions packages/core/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ const settings = {
},
};

const settingsWithParisEVM = {
...settings,
evmVersion: 'paris',
};

const proxyCompiler = {
version: require('./src/solidity-version.json'),
settings: {
...settings,
evmVersion: 'paris',
},
settings: settingsWithParisEVM,
};

function getNamespacedOverrides() {
Expand All @@ -37,7 +39,7 @@ function getNamespacedOverrides() {
if (c === 'NamespacedToModify07.sol') {
overrides[`contracts/test/${c}`] = { version: '0.7.6', settings };
} else {
overrides[`contracts/test/${c}`] = { version: '0.8.20', settings };
overrides[`contracts/test/${c}`] = { version: '0.8.20', settings: settingsWithParisEVM };
}
}
return overrides;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"devDependencies": {
"@ava/typescript": "^4.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@openzeppelin/contracts": "5.0.0",
"@types/cbor": "^5.0.0",
"@types/debug": "^4.1.5",
Expand All @@ -56,7 +56,7 @@
"ava": "^5.0.0",
"dotenv": "^16.0.0",
"fgbg": "^0.1.4",
"hardhat": "^2.0.2",
"hardhat": "^2.19.1",
"rimraf": "^5.0.0",
"typescript": "^4.0.0",
"@openzeppelin/upgrades-core-legacy": "npm:@openzeppelin/upgrades-core@1.31.1"
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/utils/make-namespaced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ async function testMakeNamespaced(
function normalizeStateVariableNames(input: SolcInput): void {
for (const source of Object.values(input.sources)) {
if (source.content !== undefined) {
source.content = source.content.replace(/\$MainStorage_\d{1,6};/g, '$MainStorage_random;');
source.content = source.content
.replace(/\$MainStorage_\d{1,6};/g, '$MainStorage_random;')
.replace(/\$SecondaryStorage_\d{1,6}/g, '$SecondaryStorage_random');
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/utils/make-namespaced.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Generated by [AVA](https://avajs.dev).
{
language: 'Solidity',
settings: {
evmVersion: 'paris',
optimizer: {
enabled: true,
runs: 200,
Expand All @@ -37,6 +38,12 @@ Generated by [AVA](https://avajs.dev).
uint256 x;␊
uint256 y;␊
} MainStorage $MainStorage_random;␊
/// @custom:storage-location erc7201:example.secondary␊
struct SecondaryStorage {␊
uint256 a;␊
uint256 b;␊
} SecondaryStorage $SecondaryStorage_random;␊
Expand Down
Binary file modified packages/core/src/utils/make-namespaced.test.ts.snap
Binary file not shown.
13 changes: 13 additions & 0 deletions packages/plugin-hardhat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
- `admin.changeProxyAdmin`: Not supported with admins or proxies from OpenZeppelin Contracts 5.0. Only supported for previously deployed admins and proxies from OpenZeppelin Contracts 4.x or below.
- `admin.transferProxyAdminOwnership`: This function no longer uses the proxy admin from the network file. It now requires a `proxyAddress` argument to be passed in.

## 2.4.1 (2023-11-14)

- Update Defender SDK. ([#924](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/924))
- Throw error if not using a relayer for deployments, until other types of deployments are supported.

**Note**: OpenZeppelin Defender deployments is in beta and its functionality is subject to change.

## 2.4.0 (2023-11-13)

- Add `createFactoryAddress` option for Defender deployments. ([#920](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/920))

**Note**: OpenZeppelin Defender deployments is in beta and its functionality is subject to change.

## 2.3.3 (2023-10-12)

- Update OpenZeppelin Defender deployments to use Defender SDK ([#888](https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/888))
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
"version": "node ../../scripts/bump-changelog.js"
},
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-verify": "^1.1.0",
"@openzeppelin/contracts": "5.0.0",
"@openzeppelin/contracts-upgradeable": "5.0.0",
"@types/mocha": "^7.0.2",
"ava": "^5.0.0",
"fgbg": "^0.1.4",
"hardhat": "^2.0.2",
"hardhat": "^2.19.1",
"promisified": "^0.5.0",
"proxyquire": "^2.1.3",
"rimraf": "^5.0.0",
"sinon": "^17.0.0"
},
"dependencies": {
"@openzeppelin/defender-admin-client": "^1.48.0",
"@openzeppelin/defender-base-client": "^1.48.0",
"@openzeppelin/defender-sdk-base-client": "^1.2.0",
"@openzeppelin/defender-sdk-deploy-client": "^1.2.0",
"@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/upgrades-core": "^1.30.1",
"chalk": "^4.1.0",
"debug": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-hardhat/src/defender-v1/propose-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
isTransparentOrUUPSProxy,
isTransparentProxy,
} from '@openzeppelin/upgrades-core';
import { ProposalResponse } from '@openzeppelin/defender-admin-client';
import { ProposalResponse, CreateProposalRequest } from '@openzeppelin/defender-admin-client';
import { ContractFactory, getCreateAddress, ethers } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { getAdminClient, getNetwork } from './utils';
Expand All @@ -28,7 +28,7 @@ export interface ProposalOptions extends UpgradeOptions {
description?: string;
proxyAdmin?: string;
multisig?: string;
multisigType?: 'Gnosis Safe' | 'Gnosis Multisig' | 'EOA';
multisigType?: CreateProposalRequest['viaType'];
bytecodeVerificationReferenceUrl?: string;
}

Expand Down
43 changes: 31 additions & 12 deletions packages/plugin-hardhat/src/defender/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CompilerInput, CompilerOutputContract, HardhatRuntimeEnvironment } from

import { parseFullyQualifiedName } from 'hardhat/utils/contract-names';

import { DeploymentResponse, SourceCodeLicense } from '@openzeppelin/defender-sdk-deploy-client';
import { DeploymentResponse, SourceCodeLicense, DeployContractRequest } from '@openzeppelin/defender-sdk-deploy-client';
import {
Deployment,
RemoteDeploymentId,
Expand Down Expand Up @@ -73,19 +73,22 @@ export async function defenderDeploy(
debug(`Salt: ${opts.salt}`);
}

const deploymentRequest: DeployContractRequest = {
contractName: contractInfo.contractName,
contractPath: contractInfo.sourceName,
network: network,
artifactPayload: JSON.stringify(contractInfo.buildInfo),
licenseType: license as SourceCodeLicense | undefined, // cast without validation but catch error from API below
constructorInputs: constructorArgs,
verifySourceCode: verifySourceCode,
relayerId: opts.relayerId,
salt: opts.salt,
createFactoryAddress: opts.createFactoryAddress,
};

let deploymentResponse: DeploymentResponse;
try {
deploymentResponse = await client.deployContract({
contractName: contractInfo.contractName,
contractPath: contractInfo.sourceName,
network: network,
artifactPayload: JSON.stringify(contractInfo.buildInfo),
licenseType: license as SourceCodeLicense | undefined, // cast without validation but catch error from API below
constructorInputs: constructorArgs,
verifySourceCode: verifySourceCode,
relayerId: opts.relayerId,
salt: opts.salt,
});
deploymentResponse = await client.deployContract(deploymentRequest);
} catch (e: any) {
if (e.response?.data?.message?.includes('licenseType should be equal to one of the allowed values')) {
throw new UpgradesError(
Expand All @@ -97,6 +100,22 @@ export async function defenderDeploy(
}
}

if (deploymentResponse.address === undefined) {
throw new UpgradesError(
`Deployment response with id ${deploymentResponse.deploymentId} does not include a contract address`,
() =>
'The Hardhat Upgrades plugin is not currently compatible with this type of deployment. Use a relayer for your default deploy approval process in Defender.',
);
}

if (deploymentResponse.txHash === undefined) {
throw new UpgradesError(
`Deployment response with id ${deploymentResponse.deploymentId} does not include a transaction hash`,
() =>
'The Hardhat Upgrades plugin is not currently compatible with this type of deployment. Use a relayer for your default deploy approval process in Defender.',
);
}

const txResponse = (await hre.ethers.provider.getTransaction(deploymentResponse.txHash)) ?? undefined;
const checksumAddress = hre.ethers.getAddress(deploymentResponse.address);
return {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-hardhat/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type DefenderDeployOptions = DefenderDeploy & {
verifySourceCode?: boolean;
relayerId?: string;
salt?: string;
createFactoryAddress?: string;
};

/**
Expand Down
36 changes: 36 additions & 0 deletions packages/plugin-hardhat/test/defender-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const TX_RESPONSE = 'mocked response';
const ETHERSCAN_API_KEY = 'fakeKey';
const RELAYER_ID = '123-abc';
const SALT = 'customsalt';
const CREATE_FACTORY = '0x0000000000000000000000000000000000000010';

const LOGIC_ADDRESS = '0x0000000000000000000000000000000000000003';
const INITIAL_OWNER_ADDRESS = '0x0000000000000000000000000000000000000004';
Expand Down Expand Up @@ -99,6 +100,7 @@ test('calls defender deploy', async t => {
verifySourceCode: true,
relayerId: undefined,
salt: undefined,
createFactoryAddress: undefined,
});

assertResult(t, result);
Expand All @@ -124,6 +126,7 @@ test('calls defender deploy with relayerId', async t => {
verifySourceCode: true,
relayerId: RELAYER_ID,
salt: undefined,
createFactoryAddress: undefined,
});

assertResult(t, result);
Expand All @@ -149,6 +152,33 @@ test('calls defender deploy with salt', async t => {
verifySourceCode: true,
relayerId: undefined,
salt: SALT,
createFactoryAddress: undefined,
});

assertResult(t, result);
});

test('calls defender deploy with createFactoryAddress', async t => {
const { spy, deploy, fakeHre, fakeChainId } = t.context;

const contractPath = 'contracts/Greeter.sol';
const contractName = 'Greeter';

const factory = await ethers.getContractFactory(contractName);
const result = await deploy.defenderDeploy(fakeHre, factory, { createFactoryAddress: CREATE_FACTORY });

const buildInfo = await hre.artifacts.getBuildInfo(`${contractPath}:${contractName}`);
sinon.assert.calledWithExactly(spy, {
contractName: contractName,
contractPath: contractPath,
network: fakeChainId,
artifactPayload: JSON.stringify(buildInfo),
licenseType: 'None',
constructorInputs: [],
verifySourceCode: true,
relayerId: undefined,
salt: undefined,
createFactoryAddress: CREATE_FACTORY,
});

assertResult(t, result);
Expand All @@ -174,6 +204,7 @@ test('calls defender deploy with license', async t => {
verifySourceCode: true,
relayerId: undefined,
salt: undefined,
createFactoryAddress: undefined,
});

assertResult(t, result);
Expand All @@ -199,6 +230,7 @@ test('calls defender deploy with constructor args', async t => {
verifySourceCode: true,
relayerId: undefined,
salt: undefined,
createFactoryAddress: undefined,
});

assertResult(t, result);
Expand All @@ -224,6 +256,7 @@ test('calls defender deploy with verify false', async t => {
verifySourceCode: false,
relayerId: undefined,
salt: undefined,
createFactoryAddress: undefined,
});

assertResult(t, result);
Expand All @@ -249,6 +282,7 @@ test('calls defender deploy with ERC1967Proxy', async t => {
verifySourceCode: true,
relayerId: undefined,
salt: undefined,
createFactoryAddress: undefined,
});
});

Expand All @@ -272,6 +306,7 @@ test('calls defender deploy with BeaconProxy', async t => {
verifySourceCode: true,
relayerId: undefined,
salt: undefined,
createFactoryAddress: undefined,
});
});

Expand All @@ -295,5 +330,6 @@ test('calls defender deploy with TransparentUpgradeableProxy', async t => {
verifySourceCode: true,
relayerId: undefined,
salt: undefined,
createFactoryAddress: undefined,
});
});
3 changes: 2 additions & 1 deletion packages/plugin-hardhat/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"composite": true,
"outDir": "dist",
"rootDir": "src",
"resolveJsonModule": true
"resolveJsonModule": true,
"skipLibCheck": true,
},
"include": [
"src/**/*"
Expand Down
Loading

0 comments on commit ca9547a

Please sign in to comment.