Skip to content

Commit

Permalink
chore upgrade ethers to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom committed Jan 12, 2024
1 parent a8d3ca2 commit 918f94b
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 276 deletions.
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"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",
Expand All @@ -49,13 +49,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 Down Expand Up @@ -90,6 +92,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"
}
}
}
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

0 comments on commit 918f94b

Please sign in to comment.