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

Feat: Migration to Zodiac Core and Task Improvements in the Reality Mod #81

Merged
merged 6 commits into from
Sep 12, 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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: 20
- uses: actions/cache@v2
with:
path: '**/node_modules'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ env/
coverage*
deployments
.vscode/*
typechain-types
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.0.0
v20.0.0
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}
],
"tabWidth": 2,
"singleQuote": true,
"semi": false
}
6 changes: 3 additions & 3 deletions contracts/DeterministicDeploymentHelper.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;
pragma solidity >=0.8.20;

import "@gnosis.pm/zodiac/contracts/core/Module.sol";
import "@gnosis-guild/zodiac-core/contracts/core/Module.sol";
import "./interfaces/RealitioV3.sol";
import "./RealityModule.sol";
import "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol";
import "@gnosis-guild/zodiac-core/contracts/factory/ModuleProxyFactory.sol";

/**
* @title Deterministic Deployment Helper
Expand Down
65 changes: 30 additions & 35 deletions contracts/RealityModule.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;
pragma solidity >=0.8.20;

import "@gnosis.pm/zodiac/contracts/core/Module.sol";
import "@gnosis-guild/zodiac-core/contracts/core/Module.sol";
import "./interfaces/RealitioV3.sol";

abstract contract RealityModule is Module {
Expand Down Expand Up @@ -91,7 +90,7 @@ abstract contract RealityModule 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 @@ -118,7 +117,7 @@ abstract contract RealityModule is Module {
address
)
);
__Ownable_init();
__Ownable_init(msg.sender);
require(_avatar != address(0), "Avatar can not be zero address");
require(_target != address(0), "Target can not be zero address");
setAvatar(_avatar);
Expand Down Expand Up @@ -150,7 +149,7 @@ abstract contract RealityModule is Module {
/// @notice Timeout must be greater than `0`
function setQuestionTimeout(uint32 timeout) public onlyOwner {
require(timeout > 0, "Timeout has to be greater 0");
require(timeout < 365 days, "timeout must be less than 365 days");
require(timeout < 365 days, "timeout must be less than 365 days");
questionTimeout = timeout;
emit SetQuestionTimeout(timeout);
}
Expand Down Expand Up @@ -212,9 +211,10 @@ abstract contract RealityModule is Module {
/// @param proposalId Id that should identify the proposal uniquely
/// @param txHashes EIP-712 hashes of the transactions that should be executed
/// @notice The nonce used for the question by this function is always `0`
function addProposal(string memory proposalId, bytes32[] memory txHashes)
public
{
function addProposal(
string memory proposalId,
bytes32[] memory txHashes
) public {
addProposalWithNonce(proposalId, txHashes, 0);
}

Expand Down Expand Up @@ -256,10 +256,10 @@ abstract contract RealityModule is Module {
emit ProposalQuestionCreated(questionId, proposalId);
}

function askQuestion(string memory question, uint256 nonce)
internal
virtual
returns (bytes32);
function askQuestion(
string memory question,
uint256 nonce
) internal virtual returns (bytes32);

/// @dev Marks a proposal as invalid, preventing execution of the connected transactions
/// @param proposalId Id that should identify the proposal uniquely
Expand All @@ -277,18 +277,17 @@ abstract contract RealityModule is Module {
/// @dev Marks a question hash as invalid, preventing execution of the connected transactions
/// @param questionHash Question hash calculated based on the proposal id and txHashes
/// @notice This can only be called by the owner
function markProposalAsInvalidByHash(bytes32 questionHash)
public
onlyOwner
{
function markProposalAsInvalidByHash(
bytes32 questionHash
) public onlyOwner {
questionIds[questionHash] = INVALIDATED;
}

/// @dev Marks a proposal with an expired answer as invalid, preventing execution of the connected transactions
/// @param questionHash Question hash calculated based on the proposal id and txHashes
function markProposalWithExpiredAnswerAsInvalid(bytes32 questionHash)
public
{
function markProposalWithExpiredAnswerAsInvalid(
bytes32 questionHash
) public {
uint32 expirationDuration = answerExpiration;
require(expirationDuration > 0, "Answers are valid forever");
bytes32 questionId = questionIds[questionHash];
Expand Down Expand Up @@ -420,11 +419,10 @@ abstract contract RealityModule is Module {
/// @dev Build the question by combining the proposalId and the hex string of the hash of the txHashes
/// @param proposalId Id of the proposal that proposes to execute the transactions represented by the txHashes
/// @param txHashes EIP-712 Hashes of the transactions that should be executed
function buildQuestion(string memory proposalId, bytes32[] memory txHashes)
public
pure
returns (string memory)
{
function buildQuestion(
string memory proposalId,
bytes32[] memory txHashes
) public pure returns (string memory) {
string memory txsHash = bytes32ToAsciiString(
keccak256(abi.encodePacked(txHashes))
);
Expand All @@ -433,11 +431,10 @@ abstract contract RealityModule is Module {

/// @dev Generate the question id.
/// @notice It is required that this is the same as for the oracle implementation used.
function getQuestionId(string memory question, uint256 nonce)
public
view
returns (bytes32)
{
function getQuestionId(
string memory question,
uint256 nonce
) public view returns (bytes32) {
// Ask the question with a starting time of 0, so that it can be immediately answered
bytes32 contentHash = keccak256(
abi.encodePacked(template, uint32(0), question)
Expand Down Expand Up @@ -510,11 +507,9 @@ abstract contract RealityModule is Module {
);
}

function bytes32ToAsciiString(bytes32 _bytes)
internal
pure
returns (string memory)
{
function bytes32ToAsciiString(
bytes32 _bytes
) internal pure returns (string memory) {
bytes memory s = new bytes(64);
for (uint256 i = 0; i < 32; i++) {
uint8 b = uint8(bytes1(_bytes << (i * 8)));
Expand Down
2 changes: 1 addition & 1 deletion contracts/RealityModuleERC20.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;
pragma solidity >=0.8.20;

import "./RealityModule.sol";
import "./interfaces/RealitioV3.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/RealityModuleETH.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;
pragma solidity >=0.8.20;

import "./RealityModule.sol";
import "./interfaces/RealitioV3.sol";
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 "@gnosis-guild/zodiac-core/contracts/factory/ModuleProxyFactory.sol";
85 changes: 47 additions & 38 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,93 @@
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "solidity-coverage";
import "hardhat-deploy";
import dotenv from "dotenv";
import type { HttpNetworkUserConfig } from "hardhat/types";
import yargs from "yargs";
import "./src/tasks/deployDeterministicDeploymentHelper";
import "hardhat-contract-sizer";
import '@nomicfoundation/hardhat-toolbox'
import '@nomicfoundation/hardhat-verify'
import 'hardhat-gas-reporter'
import 'solidity-coverage'
import dotenv from 'dotenv'
import type { HttpNetworkUserConfig } from 'hardhat/types'
import yargs from 'yargs'
import 'hardhat-contract-sizer'

const argv = yargs
.option("network", {
type: "string",
default: "hardhat",
.option('network', {
type: 'string',
default: 'hardhat',
})
.help(false)
.version(false).argv;
.version(false).argv

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

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

import "./src/tasks/setup";
import "./src/tasks/proposals";

const DEFAULT_MNEMONIC =
"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'

const sharedNetworkConfig: HttpNetworkUserConfig = {};
const sharedNetworkConfig: HttpNetworkUserConfig = {}
if (PK) {
sharedNetworkConfig.accounts = [PK];
sharedNetworkConfig.accounts = [PK]
} else {
sharedNetworkConfig.accounts = {
mnemonic: MNEMONIC || DEFAULT_MNEMONIC,
};
}
}

if (["mainnet", "goerli"].includes(argv.network) && INFURA_KEY === undefined) {
if (['mainnet', 'sepolia'].includes(argv.network) && INFURA_KEY === undefined) {
throw new Error(
`Could not find Infura key in env, unable to connect to network ${argv.network}`
);
`Could not find Infura key in env, unable to connect to network ${argv.network}`,
)
}

export default {
paths: {
artifacts: "build/artifacts",
cache: "build/cache",
deploy: "src/deploy",
sources: "contracts",
artifacts: 'build/artifacts',
cache: 'build/cache',
deploy: 'src/deploy',
sources: 'contracts',
},
solidity: {
compilers: [{ version: "0.8.0" }, { version: "0.6.12" }],
compilers: [
{ version: '0.8.20' },
{ version: '0.8.4' },
{ version: '0.8.2' },
{ version: '0.8.1' },
{ version: '0.8.0' },
{ version: '0.6.12' },
],
},
networks: {
mainnet: {
...sharedNetworkConfig,
url: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
},
goerli: {
sepolia: {
...sharedNetworkConfig,
url: `https://goerli.infura.io/v3/${INFURA_KEY}`,
url: `https://sepolia.infura.io/v3/${INFURA_KEY}`,
},
arbitrum: {
...sharedNetworkConfig,
url: `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
},
xdai: {
...sharedNetworkConfig,
url: "https://xdai.poanetwork.dev",
url: 'https://xdai.poanetwork.dev',
},
matic: {
...sharedNetworkConfig,
url: "https://polygon-rpc.com",
url: 'https://polygon-rpc.com',
},
bsc: {
...sharedNetworkConfig,
url: "https://bsc-dataseed.binance.org",
url: 'https://bsc-dataseed.binance.org',
},
"truffle-dashboard": {
url: "http://localhost:24012/rpc",
'truffle-dashboard': {
url: 'http://localhost:24012/rpc',
timeout: 100000000,
},
},
Expand All @@ -91,4 +100,4 @@ export default {
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
};
}
4,134 changes: 4,134 additions & 0 deletions mastercopies.json

Large diffs are not rendered by default.

Loading
Loading