Skip to content

Commit

Permalink
feat: use zodiac core and upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
juliopavila committed Aug 9, 2024
1 parent b137fbe commit fc7e059
Show file tree
Hide file tree
Showing 19 changed files with 4,288 additions and 8,212 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ env/
.env
.history
coverage*
deployments
deployments
typechain-types
12 changes: 6 additions & 6 deletions contracts/AMBModule.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;

import "@gnosis.pm/zodiac/contracts/core/Module.sol";
import "zodiac-core/contracts/core/Module.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

interface IAMB {
function messageSender() external view returns (address);
Expand Down Expand Up @@ -42,7 +43,7 @@ contract AMBModule is Module {
IAMB _amb,
address _controller,
bytes32 _chainId
) {
) {
bytes memory initParams = abi.encode(
_owner,
_avatar,
Expand All @@ -54,7 +55,7 @@ contract AMBModule is Module {
setUp(initParams);
}

function setUp(bytes memory initParams) public override {
function setUp(bytes memory initParams) public override initializer {
(
address _owner,
address _avatar,
Expand All @@ -65,8 +66,7 @@ contract AMBModule is Module {
) = abi.decode(
initParams,
(address, address, address, IAMB, address, bytes32)
);
__Ownable_init();
);

require(_avatar != address(0), "Avatar can not be zero address");
require(_target != address(0), "Target can not be zero address");
Expand All @@ -76,7 +76,7 @@ contract AMBModule is Module {
controller = _controller;
chainId = _chainId;

transferOwnership(_owner);
_transferOwnership(_owner);

emit AmbModuleSetup(msg.sender, _owner, _avatar, _target);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/TestFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;

import "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol";
import "zodiac-core/contracts/factory/ModuleProxyFactory.sol";
70 changes: 56 additions & 14 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "solidity-coverage";
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-verify";
import "@nomicfoundation/hardhat-ethers";
import "hardhat-gas-reporter";
import "hardhat-deploy";
import dotenv from "dotenv";
import type { HttpNetworkUserConfig } from "hardhat/types";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import type { HttpNetworkUserConfig } from "hardhat/types";

const argv = yargs
const argv = yargs(hideBin(process.argv))
.option("network", {
type: "string",
default: "hardhat",
describe: "The network to connect to",
})
.help(false)
.version(false).argv;
.version(false)
.parseSync();

// Load environment variables.
dotenv.config();
const { INFURA_KEY, MNEMONIC, ETHERSCAN_API_KEY, PK } = process.env;

import "./src/tasks/mastercopy-extract";
import "./src/tasks/mastercopy-deploy";
import "./src/tasks/mastercopy-verify";
import "./src/tasks/setup";
import "./src/tasks/encodeTx";

Expand All @@ -33,7 +40,7 @@ if (PK) {
};
}

if (["rinkeby", "mainnet"].includes(argv.network) && INFURA_KEY === undefined) {
if (["sepolia", "mainnet"].includes(argv.network) && INFURA_KEY === undefined) {
throw new Error(
`Could not find Infura key in env, unable to connect to network ${argv.network}`
);
Expand All @@ -47,20 +54,31 @@ export default {
sources: "contracts",
},
solidity: {
compilers: [{ version: "0.8.0" }, { version: "0.6.12" }],
compilers: [
{ version: "0.8.20" },
{ version: "0.8.0" },
{ version: "0.6.12" },
],
settings: {
optimizer: {
enabled: true,
runs: 100,
},
},
},
networks: {
hardhat: {
allowUnlimitedContractSize: true,
blockGasLimit: 100000000,
gas: 100000000,
},
mainnet: {
...sharedNetworkConfig,
url: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
},
rinkeby: {
sepolia: {
...sharedNetworkConfig,
url: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
},
goerli: {
...sharedNetworkConfig,
url: `https://goerli.infura.io/v3/${INFURA_KEY}`,
url: `https://sepolia.infura.io/v3/${INFURA_KEY}`,
},
xdai: {
...sharedNetworkConfig,
Expand All @@ -70,6 +88,30 @@ export default {
...sharedNetworkConfig,
url: "https://rpc-mainnet.maticvigil.com",
},
mumbai: {
...sharedNetworkConfig,
url: `https://polygon-mumbai.infura.io/v3/${INFURA_KEY}`,
},
polygon: {
...sharedNetworkConfig,
url: `https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`,
},
volta: {
...sharedNetworkConfig,
url: `https://volta-rpc.energyweb.org`,
},
bsc: {
...sharedNetworkConfig,
url: `https://bsc-dataseed.binance.org/`,
},
arbitrum: {
...sharedNetworkConfig,
url: `https://arb1.arbitrum.io/rpc`,
},
avalanche: {
...sharedNetworkConfig,
url: `https://api.avax.network/ext/bc/C/rpc`,
},
},
namedAccounts: {
deployer: 0,
Expand Down
462 changes: 462 additions & 0 deletions mastercopies.json

Large diffs are not rendered by default.

78 changes: 43 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"build": "hardhat compile",
"test": "hardhat test",
"deploy": "hardhat deploy --network",
"extract-mastercopy": "yarn run build && yarn hardhat mastercopy:extract",
"deploy-mastercopy": "yarn hardhat mastercopy:deploy --network",
"verify-mastercopy": "yarn hardhat mastercopy:verify --network",
"coverage": "hardhat coverage",
"lint": "yarn lint:sol && yarn lint:ts",
"lint:sol": "solhint 'contracts/**/*.sol'",
Expand All @@ -24,45 +27,50 @@
"author": "richard@gnosis.io",
"license": "MIT",
"devDependencies": {
"@gnosis.pm/zodiac": "1.0.1",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^2.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@types/chai": "^4.2.14",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.21",
"@types/yargs": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"chai": "^4.2.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/ignition-core": "^0.15.5",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.3",
"@types/mocha": "^10.0.7",
"@types/node": "^22.1.0",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"chai": "^4.3.7",
"debug": "^4.2.0",
"eslint": "^7.13.0",
"eslint-config-prettier": "^8.0.0",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-prettier": "^3.1.4",
"ethereum-waffle": "^3.2.0",
"hardhat": "2.6.4",
"hardhat-deploy": "^0.7.0-beta.38",
"husky": "^5.1.3",
"prettier": "^2.1.2",
"prettier-plugin-solidity": "^1.0.0-alpha.60",
"solhint": "^3.3.2",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.7.17",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.2.1",
"hardhat": "^2.22.8",
"hardhat-deploy": "^0.12.4",
"hardhat-gas-reporter": "^2.2.0",
"husky": "^9.1.4",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^5.0.3",
"solhint-plugin-prettier": "^0.1.0",
"solidity-coverage": "^0.8.12",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.5.4",
"zodiac-core": "file:../zodiac-core"
},
"dependencies": {
"@gnosis.pm/mock-contract": "^4.0.0",
"@openzeppelin/contracts": "^4.3.1",
"argv": "^0.0.2",
"dotenv": "^8.0.0",
"ethers": "^5.0.19",
"solc": "0.8.1",
"yargs": "^16.1.1"
},
"resolutions": {
"bitcore-lib": "8.25.0"
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@openzeppelin/contracts": "^5.0.2",
"argv": "^0.0.3",
"dotenv": "^16.4.5",
"ethers": "^6.13.2",
"solc": "^0.8.26",
"yargs": "^17.7.2"
}
}
22 changes: 22 additions & 0 deletions src/deploy/createEIP1193.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Signer } from "ethers";
import { EIP1193Provider } from "zodiac-core";
import { EthereumProvider } from "hardhat/types";

export default function createAdapter({
provider,
signer,
}: {
provider: EthereumProvider;
signer: Signer;
}): EIP1193Provider {
return {
request: async ({ method, params }) => {
if (method == "eth_sendTransaction") {
const { hash } = await signer.sendTransaction((params as any[])[0]);
return hash;
}

return provider.request({ method, params });
},
};
}
37 changes: 27 additions & 10 deletions src/deploy/deploy_module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { formatBytes32String } from "ethers/lib/utils";
import { encodeBytes32String } from "ethers";
import { deployMastercopy } from "zodiac-core";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import createAdapter from "./createEIP1193";

const FirstAddress = "0x0000000000000000000000000000000000000001";
const SaltZero =
"0x0000000000000000000000000000000000000000000000000000000000000000";

const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deployer } = await getNamedAccounts();
const { deploy } = deployments;
const chainId = formatBytes32String("0");
const { getNamedAccounts } = hre;
const { deployer: deployerAddress } = await getNamedAccounts();
const deployer = await hre.ethers.provider.getSigner(deployerAddress);
const chainId = encodeBytes32String("0");
const AMBModule = await hre.ethers.getContractFactory("AMBModule");
const args = [
FirstAddress,
FirstAddress,
Expand All @@ -18,12 +23,24 @@ const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
chainId,
];

await deploy("AMBModule", {
from: deployer,
args,
log: true,
deterministicDeployment: true,
const { noop, address } = await deployMastercopy({
bytecode: AMBModule.bytecode,
constructorArgs: {
types: ["address", "address", "address", "address", "address", "bytes32"],
values: args,
},
salt: SaltZero,
provider: createAdapter({
provider: hre.network.provider,
signer: deployer,
}),
});

if (noop) {
console.log("AMBModule already deployed to:", address);
} else {
console.log("AMBModule was deployed to:", address);
}
};

deploy.tags = ["amb-module"];
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TASK_ETHERSCAN_VERIFY } from "hardhat-deploy";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { run } = hre;
if (!["rinkeby", "mainnet"].includes(hre.network.name)) {
if (!["sepolia", "mainnet"].includes(hre.network.name)) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/tasks/encodeTx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "hardhat-deploy";
import "@nomiclabs/hardhat-ethers";
import "@nomicfoundation/hardhat-ethers";
import { task, types } from "hardhat/config";

task(
Expand Down Expand Up @@ -27,7 +27,7 @@ task(
"BridgeModule",
"0x0000000000000000000000000000000000000000"
);
const moduleTx = await module.populateTransaction.executeTransaction(
const moduleTx = await module.executeTransaction.populateTransaction(
taskArgs.to,
`${taskArgs.value}`,
taskArgs.data,
Expand Down Expand Up @@ -56,7 +56,7 @@ task(
"IAMB",
"0x0000000000000000000000000000000000000000"
);
const ambTx = await amb.populateTransaction.requireToPassMessage(
const ambTx = await amb.requireToPassMessage.populateTransaction(
taskArgs.to,
taskArgs.data,
`${taskArgs.gas}`
Expand Down
Loading

0 comments on commit fc7e059

Please sign in to comment.