Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to ethers v6 #152

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.0.0
v18.0.0
26 changes: 15 additions & 11 deletions package.json
compojoom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/zodiac",
"version": "3.5.2",
"version": "4.0.0",
"description": "Zodiac is a composable design philosophy and collection of standards for building DAO ecosystem tooling.",
"author": "Auryn Macmillan <auryn.macmillan@gnosis.io>",
"license": "LGPL-3.0+",
Expand Down Expand Up @@ -35,11 +35,12 @@
"format": "yarn format:sol && yarn format:ts",
"format:sol": "prettier --write --plugin=prettier-plugin-solidity ./contracts/**/*.sol",
"format:ts": "prettier --write ./sdk/**/*.ts ./test/**/*.ts ./*.ts",
"generate:types": "rm -rf src/types && typechain --target ethers-v5 --out-dir sdk/types './sdk/abi/*.json'",
"generate:types": "rm -rf src/types && typechain --target ethers-v6 --out-dir sdk/types './sdk/abi/*.json'",
"prepare": "yarn generate:types && yarn build",
"prerelease": "yarn clean && yarn build && yarn build:sdk",
"release": "yarn publish --access public",
"verify": "yarn hardhat verify --network"
"verify": "yarn hardhat verify --network",
"postinstall": "patch-package"
},
"directories": {
"test": "test"
Expand All @@ -49,13 +50,15 @@
"url": "https://github.com/gnosis/zodiac.git"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.7",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "2.2.3",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "3.1.7",
"@typechain/ethers-v5": "^11.1.0",
"@typechain/hardhat": "^6.1.5",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.3",
"@types/mocha": "^10.0.0",
"@types/node": "^18.8.5",
Expand All @@ -74,14 +77,15 @@
"hardhat-deploy": "^0.11.28",
"hardhat-gas-reporter": "^1.0.9",
"husky": "^8.0.1",
"patch-package": "^8.0.0",
"prettier": "^3.0.3",
"prettier-plugin-solidity": "^1.1.3",
"rimraf": "^5.0.1",
"solhint": "^4.0.0",
"solhint-plugin-prettier": "^0.1.0",
"solidity-coverage": "^0.8.4",
"ts-node": "^10.9.1",
"typechain": "^8.3.0",
"typechain": "^8.3.2",
"typescript": "^5.2.2",
"yargs": "^17.6.0"
},
Expand All @@ -90,6 +94,6 @@
"@gnosis.pm/safe-contracts": "1.3.0",
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "^5.0.0",
"ethers": "^5.7.1"
"ethers": "^6.9.2"
}
}
}
61 changes: 61 additions & 0 deletions patches/@typechain+ethers-v6+0.5.1.patch

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions sdk/factory/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ describe("Factory JS functions ", () => {
KnownContracts.REALITY_ETH,
args,
hre.ethers.provider,
chainId,
Number(chainId),
saltNonce
);

const transaction = await signer.sendTransaction(deployTx);

const receipt = await transaction.wait();
expect(receipt.transactionHash).to.be.a("string");

expect(receipt.hash).to.be.a("string");
expect(receipt.status).to.be.eq(1);
expect(expectedModuleAddress).to.a("string");
});
Expand Down Expand Up @@ -99,7 +100,8 @@ describe("Factory JS functions ", () => {
],
};

const chainContracts = ContractAddresses[chainId as SupportedNetworks];
const chainContracts =
ContractAddresses[Number(chainId) as SupportedNetworks];
const masterCopyAddress = chainContracts[KnownContracts.REALITY_ETH];
const abi = ContractAbis[KnownContracts.REALITY_ETH];

Expand All @@ -109,14 +111,14 @@ describe("Factory JS functions ", () => {
abi,
args,
hre.ethers.provider,
chainId,
Number(chainId),
saltNonce
);

const transaction = await signer.sendTransaction(deployTx);

const receipt = await transaction.wait();
expect(receipt.transactionHash).to.be.a("string");
expect(receipt.hash).to.be.a("string");
expect(receipt.status).to.be.eq(1);
expect(expectedModuleAddress).to.a("string");
});
Expand All @@ -126,11 +128,11 @@ describe("Factory JS functions ", () => {

const module = await getModuleInstance(
KnownContracts.REALITY_ETH,
mock.address,
await mock.getAddress(),
hre.ethers.provider
);
await mock.givenMethodReturnBool(
module.interface.getSighash("owner"),
module.interface.getFunction("owner").selector,
true
);

Expand All @@ -146,7 +148,7 @@ describe("Factory JS functions ", () => {
await getModuleFactoryAndMasterCopy(
KnownContracts.REALITY_ETH,
hre.ethers.provider,
chainId
Number(chainId)
);
expect(moduleFactory).to.be.instanceOf(Contract);
expect(moduleMastercopy).to.be.instanceOf(Contract);
Expand Down
12 changes: 7 additions & 5 deletions sdk/factory/deployModuleFactory.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import assert from "assert";

import { constants as ethersConstants, ethers } from "ethers";
import { ZeroAddress, JsonRpcSigner } from "ethers";

import { MasterCopyInitData } from "../contracts";

import { getSingletonFactory } from "./singletonFactory";
import { KnownContracts } from "./types";

const { AddressZero } = ethersConstants;
const AddressZero = ZeroAddress;

const FactoryInitData = MasterCopyInitData[KnownContracts.FACTORY];

Expand All @@ -21,7 +21,7 @@ assert(FactoryInitData);
* @returns The address of the deployed Module Proxy Factory, or the zero address if it was already deployed
*/
export const deployModuleFactory = async (
signer: ethers.providers.JsonRpcSigner
signer: JsonRpcSigner
): Promise<string> => {
console.log("Deploying the Module Proxy Factory...");
const singletonFactory = await getSingletonFactory(signer);
Expand All @@ -30,13 +30,15 @@ export const deployModuleFactory = async (
singletonFactory.address
);

const targetAddress = await singletonFactory.callStatic.deploy(
const targetAddress = await singletonFactory.deploy.staticCall(
FactoryInitData.initCode,
FactoryInitData.salt
);
if (targetAddress === AddressZero) {
console.log(
` ✔ Module Proxy Factory already deployed to target address on ${signer.provider.network.name}.`
` ✔ Module Proxy Factory already deployed to target address on ${
(await signer.provider.getNetwork()).name
}.`
);
return AddressZero;
}
Expand Down
34 changes: 20 additions & 14 deletions sdk/factory/mastercopyDeployer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import {
BytesLike,
ContractFactory,
constants as ethersConstants,
ethers,
ZeroAddress,
JsonRpcSigner,
keccak256,
getAddress,
getCreate2Address,
} from "ethers";
import { keccak256, getCreate2Address, getAddress } from "ethers/lib/utils";

import { getSingletonFactory } from "./singletonFactory";

const { AddressZero } = ethersConstants;
const AddressZero = ZeroAddress;

/**
* Deploy a module's mastercopy via the singleton factory.
Expand All @@ -20,12 +22,14 @@ const { AddressZero } = ethersConstants;
* @returns The address of the deployed module mastercopy or the zero address if it was already deployed
*/
export const deployMastercopy = async (
signer: ethers.providers.JsonRpcSigner,
signer: JsonRpcSigner,
mastercopyContractFactory: ContractFactory,
args: Array<any>,
salt: string
): Promise<string> => {
const deploymentTx = mastercopyContractFactory.getDeployTransaction(...args);
const deploymentTx = await mastercopyContractFactory.getDeployTransaction(
...args
);

if (!deploymentTx.data) {
throw new Error("Unable to create the deployment data (no init code).");
Expand All @@ -45,12 +49,14 @@ export const deployMastercopy = async (
* }
*/
export const computeTargetAddress = async (
signer: ethers.providers.JsonRpcSigner,
signer: JsonRpcSigner,
mastercopyContractFactory: ContractFactory,
args: Array<any>,
salt: string
): Promise<{ address: string; isDeployed: boolean }> => {
const deploymentTx = mastercopyContractFactory.getDeployTransaction(...args);
const deploymentTx = await mastercopyContractFactory.getDeployTransaction(
...args
);
const singletonFactory = await getSingletonFactory(signer);

if (!deploymentTx.data) {
Expand All @@ -60,13 +66,13 @@ export const computeTargetAddress = async (
const initCodeHash = keccak256(deploymentTx.data);

const computedAddress = getCreate2Address(
singletonFactory.address,
await singletonFactory.getAddress(),
salt,
initCodeHash
);

const targetAddress = getAddress(
(await singletonFactory.callStatic.deploy(
(await singletonFactory.deploy.staticCall(
deploymentTx.data,
salt
)) as string
Expand All @@ -86,21 +92,21 @@ export const computeTargetAddress = async (
};

export const deployMastercopyWithInitData = async (
signer: ethers.providers.JsonRpcSigner,
signer: JsonRpcSigner,
initCode: BytesLike,
salt: string
): Promise<string> => {
const singletonFactory = await getSingletonFactory(signer);

// throws if this for some reason is not a valid address
const targetAddress = getAddress(
(await singletonFactory.callStatic.deploy(initCode, salt)) as string
(await singletonFactory.deploy.staticCall(initCode, salt)) as string
);

const initCodeHash = keccak256(initCode);

const computedTargetAddress = getCreate2Address(
singletonFactory.address,
await singletonFactory.address(),
salt,
initCodeHash
);
Expand All @@ -118,7 +124,7 @@ export const deployMastercopyWithInitData = async (
}

let gasLimit;
switch (signer.provider.network.name) {
switch ((await signer.provider.getNetwork()).name) {
case "optimism":
gasLimit = 6000000;
break;
Expand Down
Loading
Loading