Skip to content

Commit

Permalink
feat: introduce zodiac-core and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
juliopavila committed Aug 12, 2024
1 parent b29f5d8 commit 974728f
Show file tree
Hide file tree
Showing 18 changed files with 3,286 additions and 7,874 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
RINKEBY_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY>
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1
INFURA_KEY=
19 changes: 10 additions & 9 deletions contracts/ConnextModule.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.15;

import "@gnosis.pm/zodiac/contracts/core/Module.sol";
import "zodiac-core/contracts/core/Module.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IXReceiver} from "./interfaces/IXReceiver.sol";

contract ConnextModule is Module, IXReceiver {
using SafeERC20 for IERC20;

event ModuleSetUp(
address owner,
address avatar,
Expand Down Expand Up @@ -54,7 +54,6 @@ contract ConnextModule is Module, IXReceiver {
/// @param initializeParams ABI encoded initialization params, in the same order as the parameters for this contract's constructor.
/// @notice Only callable once.
function setUp(bytes memory initializeParams) public override initializer {
__Ownable_init();
(
address _owner,
address _avatar,
Expand All @@ -64,12 +63,16 @@ contract ConnextModule is Module, IXReceiver {
address _connext
) = abi.decode(initializeParams, (address, address, address, address, uint32, address));

require(_avatar != address(0), "Avatar can not be zero address");
require(_target != address(0), "Target can not be zero address");

__Ownable_init(msg.sender);
setAvatar(_avatar);
setTarget(_target);
setOriginSender(_originSender);
setOrigin(_origin);
setConnext(_connext);
transferOwnership(_owner);
_transferOwnership(_owner);

emit ModuleSetUp(owner(), avatar, target, originSender, origin, connext);
}
Expand Down Expand Up @@ -98,9 +101,7 @@ contract ConnextModule is Module, IXReceiver {
address _originSender,
uint32 _origin,
bytes memory _callData
)
external override onlyConnext(_originSender, _origin)
returns (bytes memory) {
) external override onlyConnext(_originSender, _origin) returns (bytes memory) {
// Decode message
(address _to, uint256 _value, bytes memory _data, Enum.Operation _operation) = abi.decode(
_callData,
Expand All @@ -109,11 +110,11 @@ contract ConnextModule is Module, IXReceiver {

// Approve token transfer if tokens were passed in
IERC20 _token = IERC20(_asset);
if(_amount > 0) _token.safeTransfer(avatar, _amount);
if (_amount > 0) _token.safeTransfer(avatar, _amount);

// Execute transaction against target
(bool success, bytes memory returnData) = execAndReturnData(_to, _value, _data, _operation);
if(!success) revert ModuleTransactionFailed();
if (!success) revert ModuleTransactionFailed();
return returnData;
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/test/Button.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.15;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract Button is Ownable {
event ButtonPushed(uint8 pushes, address pusher);

uint8 public pushes;

constructor() Ownable(msg.sender) {}

// UpdateGreeting updates the public greeting variable if test tokens are paid to the contract
function push() public {
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";
22 changes: 22 additions & 0 deletions 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 })
},
}
}
41 changes: 41 additions & 0 deletions deploy/deploy_module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { deployMastercopy } from "zodiac-core"
import { DeployFunction } from "hardhat-deploy/types"
import { HardhatRuntimeEnvironment } from "hardhat/types"
import createAdapter from "./createEIP1193"
import "@nomicfoundation/hardhat-ethers"

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

const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre
const { deployer: deployerAddress } = await getNamedAccounts()
const [signer] = await hre.ethers.getSigners()
const eip1193Provider = createAdapter({
provider: hre.network.provider,
signer: signer,
})
const provider = new hre.ethers.BrowserProvider(eip1193Provider)
const deployer = await provider.getSigner(deployerAddress)
const ConnextModule = await hre.ethers.getContractFactory("ConnextModule")
const args = [FirstAddress, FirstAddress, FirstAddress, FirstAddress, 0, FirstAddress]

const { noop, address } = await deployMastercopy({
bytecode: ConnextModule.bytecode,
constructorArgs: {
types: ["address", "address", "address", "address", "uint32", "address"],
values: args,
},
salt: SaltZero,
provider: eip1193Provider,
})

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

deploy.tags = ["connect-module"]
export default deploy
32 changes: 32 additions & 0 deletions deploy/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { TASK_ETHERSCAN_VERIFY } from "hardhat-deploy";

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

if (!process.env.INFURA_KEY) {
console.log(
`Could not find Infura key in env, unable to connect to network ${hre.network.name}`
);
return;
}

console.log("Verification of Connext Module in etherscan...");
console.log("Waiting for 1 minute before verifying contracts...");
// Etherscan needs some time to process before trying to verify.
await new Promise((resolve) => setTimeout(resolve, 60000));

console.log("Starting to verify now");

await run(TASK_ETHERSCAN_VERIFY, {
apiKey: process.env.ETHERSCAN_KEY_API,
license: "GPL-3.0",
solcInput: true,
forceLicense: true, // we need this because contracts license is LGPL-3.0-only
});
};
export default func;
42 changes: 30 additions & 12 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
import * as dotenv from "dotenv"
import { HardhatUserConfig } from "hardhat/config"
import "@nomiclabs/hardhat-etherscan"
import "@nomiclabs/hardhat-ethers"
import "@nomiclabs/hardhat-waffle"
import "@nomicfoundation/hardhat-toolbox"
import "@nomicfoundation/hardhat-verify"
import "@nomicfoundation/hardhat-ethers"
import "@typechain/hardhat"
import "hardhat-gas-reporter"
import "solidity-coverage"
import "hardhat-deploy"
// import "solidity-coverage"
import "./tasks/mastercopy-extract"
import "./tasks/mastercopy-deploy"
import "./tasks/mastercopy-verify"
import "./tasks/setup"
import type { HttpNetworkUserConfig } from "hardhat/types"

dotenv.config()

const sharedNetworkConfig: HttpNetworkUserConfig = {}
if (process.env.PRIVATE_KEY) {
sharedNetworkConfig.accounts = [process.env.PRIVATE_KEY]
}

const config: HardhatUserConfig = {
solidity: "0.8.15",
paths: {
artifacts: "build/artifacts",
cache: "build/cache",
deploy: "deploy/raw", // normal deployment
sources: "contracts",
},
solidity: {
compilers: [{ version: "0.8.20" }, { version: "0.8.15" }, { version: "0.8.0" }],
},
networks: {
rinkeby: {
url: process.env.RINKEBY_URL || "",
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
deploy: ["deploy/mastercopy-proxy"], // deploy via mastercopy and a proxy
hardhat: {
allowUnlimitedContractSize: true,
blockGasLimit: 100000000,
gas: 100000000,
},
sepolia: {
...sharedNetworkConfig,
url: `https://sepolia.infura.io/v3/${process.env.INFURA_KEY}`,
},
},
namedAccounts: {
Expand All @@ -32,9 +53,6 @@ const config: HardhatUserConfig = {
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
paths: {
deploy: "deploy/raw", // normal deployment
},
}

export default config
602 changes: 602 additions & 0 deletions mastercopies.json

Large diffs are not rendered by default.

61 changes: 34 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"build": "hardhat compile",
"coverage": "hardhat coverage",
"deployMasterCopy": "hardhat deployMasterCopy",
"extract-mastercopy": "yarn run build && yarn hardhat mastercopy:extract",
"deploy-mastercopy": "yarn hardhat mastercopy:deploy --network",
"verify-mastercopy": "yarn hardhat mastercopy:verify --network",
"test": "hardhat test",
"setup": "hardhat setup"
},
Expand All @@ -25,40 +28,44 @@
},
"homepage": "https://github.com/gnosis/zodiac-module-connext",
"devDependencies": {
"@gnosis.pm/zodiac": "^2.0.1",
"@nomiclabs/hardhat-ethers": "^2.2.0",
"@nomiclabs/hardhat-etherscan": "^3.1.1",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@typechain/ethers-v5": "^10.1.1",
"@typechain/hardhat": "^6.1.4",
"@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.0",
"@types/node": "^18.8.5",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.16.0",
"chai": "^4.3.6",
"@types/mocha": "^10.0.7",
"@types/node": "^22.1.0",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"chai": "^4.3.7",
"dotenv": "^16.0.3",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.0.0",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.7.1",
"hardhat": "^2.9.2",
"hardhat-deploy": "^0.11.4",
"hardhat-gas-reporter": "^1.0.8",
"prettier": "^2.6.1",
"prettier-plugin-solidity": "^1.0.0-beta.19",
"solhint": "^3.3.7",
"solidity-coverage": "^0.7.20",
"ts-node": "^10.7.0",
"typechain": "^8.0.0",
"typescript": "^4.6.3"
"ethers": "^6.13.2",
"hardhat": "^2.22.8",
"hardhat-deploy": "^0.12.4",
"hardhat-gas-reporter": "^2.2.0",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^5.0.3",
"solidity-coverage": "^0.8.12",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.5.4",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"zodiac-core": "file:../zodiac-core"
},
"dependencies": {
"@openzeppelin/contracts": "^4.3.2"
"@openzeppelin/contracts": "^5.0.2"
}
}
35 changes: 35 additions & 0 deletions tasks/mastercopy-deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Signer } from "ethers"
import { task } from "hardhat/config"
import { EthereumProvider } from "hardhat/types"
import "@nomicfoundation/hardhat-ethers"
import { EIP1193Provider, deployMastercopiesFromArtifact } from "zodiac-core"
import createAdapter from "../deploy/createEIP1193"

task(
"mastercopy:deploy",
"For every version entry on the artifacts file, deploys a mastercopy into the current network",
).setAction(async (_, hre) => {
const [deployer] = await hre.ethers.getSigners()
const eip1193Provider = createAdapter({
provider: hre.network.provider,
signer: deployer,
})
const provider = new hre.ethers.BrowserProvider(eip1193Provider)
const signer = await provider.getSigner()
await deployMastercopiesFromArtifact({
provider: createEIP1193(hre.network.provider, signer),
})
})

function createEIP1193(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 })
},
}
}
Loading

0 comments on commit 974728f

Please sign in to comment.