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

Modernize Contract Environment #27

Merged
merged 16 commits into from
Nov 4, 2023
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
34 changes: 0 additions & 34 deletions .eslintrc.js

This file was deleted.

32 changes: 32 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": { "project": "./tsconfig.json", "sourceType": "module" },
"env": { "es6": true },
"ignorePatterns": [
"node_modules",
"build",
"typechain-types",
"coverage",
"*.config.js"
],
"plugins": ["import", "eslint-comments"],
"extends": [
"eslint:recommended",
"plugin:eslint-comments/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"prettier"
],
"rules": {
"import/order": [
"error",
{ "newlines-between": "always", "alphabetize": { "order": "asc" } }
],
"sort-imports": [
"error",
{ "ignoreDeclarationSort": true, "ignoreCase": true }
],
"@typescript-eslint/no-this-alias": "off"
}
}
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

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
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions .husky/pre-commit

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.0.0
v20.9.0
19 changes: 19 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"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,
"trailingComma": "es5"
}
8 changes: 2 additions & 6 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = {
skipFiles: ['test/Imports.sol', 'test/TestAvatar.sol', 'test/Mock.sol'],
mocha: {
grep: "@skip-on-coverage", // Find everything with this tag
invert: true // Run the grep's inverse set.
}
};
skipFiles: ["test"],
};
35 changes: 17 additions & 18 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"extends": "solhint:recommended",
"plugins": [
"prettier"
"extends": "solhint:recommended",
"plugins": [],
"rules": {
"compiler-version": "off",
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
],
"rules": {
"compiler-version": "off",
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
],
"prettier/prettier": "error",
"not-rely-on-time": "off",
"reason-string": "off",
"no-empty-blocks": "off",
"avoid-low-level-calls": "off"
}
}
"avoid-low-level-calls": "off",
"custom-errors": "off",
"no-empty-blocks": "off",
"no-inline-assembly": "off",
"not-rely-on-time": "off",
"reason-string": "off"
}
}
52 changes: 25 additions & 27 deletions contracts/Delay.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;

import "@gnosis.pm/zodiac/contracts/core/Modifier.sol";
import {Enum, Modifier} from "@gnosis.pm/zodiac/contracts/core/Modifier.sol";

contract Delay is Modifier {
event DelaySetup(
Expand All @@ -10,6 +10,9 @@ contract Delay is Modifier {
address indexed avatar,
address target
);
event TxCooldownSet(uint256 cooldown);
event TxExpirationSet(uint256 expiration);
event TxNonceSet(uint256 nonce);
event TransactionAdded(
uint256 indexed queueNonce,
bytes32 indexed txHash,
Expand Down Expand Up @@ -51,7 +54,7 @@ contract Delay is Modifier {
setUp(initParams);
}

function setUp(bytes memory initParams) public override {
function setUp(bytes memory initParams) public override initializer {
(
address _owner,
address _avatar,
Expand All @@ -62,62 +65,57 @@ contract Delay is Modifier {
initParams,
(address, address, address, uint256, uint256)
);
__Ownable_init();
require(_avatar != address(0), "Avatar can not be zero address");
require(_target != address(0), "Target can not be zero address");
require(
_expiration == 0 || _expiration >= 60,
"Expiratition must be 0 or at least 60 seconds"
"Expiration must be 0 or at least 60 seconds"
);

_transferOwnership(_owner);
avatar = _avatar;
target = _target;
txExpiration = _expiration;
txCooldown = _cooldown;

transferOwnership(_owner);
setupModules();

emit DelaySetup(msg.sender, _owner, _avatar, _target);
}

function setupModules() internal {
require(
modules[SENTINEL_MODULES] == address(0),
"setUpModules has already been called"
);
modules[SENTINEL_MODULES] = SENTINEL_MODULES;
emit AvatarSet(address(0), _avatar);
emit TargetSet(address(0), _target);
}

/// @dev Sets the cooldown before a transaction can be executed.
/// @param cooldown Cooldown in seconds that should be required before the transaction can be executed
/// @param _txCooldown Cooldown in seconds that should be required before the transaction can be executed
/// @notice This can only be called by the owner
function setTxCooldown(uint256 cooldown) public onlyOwner {
txCooldown = cooldown;
function setTxCooldown(uint256 _txCooldown) public onlyOwner {
txCooldown = _txCooldown;
emit TxCooldownSet(_txCooldown);
}

/// @dev Sets the duration for which a transaction is valid.
/// @param expiration Duration that a transaction is valid in seconds (or 0 if valid forever) after the cooldown
/// @param _txExpiration Duration that a transaction is valid in seconds (or 0 if valid forever) after the cooldown
/// @notice There need to be at least 60 seconds between end of cooldown and expiration
/// @notice This can only be called by the owner
function setTxExpiration(uint256 expiration) public onlyOwner {
function setTxExpiration(uint256 _txExpiration) public onlyOwner {
require(
expiration == 0 || expiration >= 60,
"Expiratition must be 0 or at least 60 seconds"
_txExpiration == 0 || _txExpiration >= 60,
"Expiration must be 0 or at least 60 seconds"
);
txExpiration = expiration;
txExpiration = _txExpiration;
emit TxExpirationSet(_txExpiration);
}

/// @dev Sets transaction nonce. Used to invalidate or skip transactions in queue.
/// @param _nonce New transaction nonce
/// @param _txNonce New transaction nonce
/// @notice This can only be called by the owner
function setTxNonce(uint256 _nonce) public onlyOwner {
function setTxNonce(uint256 _txNonce) public onlyOwner {
require(
_nonce > txNonce,
_txNonce > txNonce,
"New nonce must be higher than current txNonce"
);
require(_nonce <= queueNonce, "Cannot be higher than queueNonce");
txNonce = _nonce;
require(_txNonce <= queueNonce, "Cannot be higher than queueNonce");
txNonce = _txNonce;
emit TxNonceSet(_txNonce);
}

/// @dev Adds a transaction to the queue (same as avatar interface so that this can be placed between other modules and the avatar).
Expand Down
6 changes: 0 additions & 6 deletions contracts/test/Imports.sol

This file was deleted.

19 changes: 0 additions & 19 deletions contracts/test/Mock.sol

This file was deleted.

26 changes: 15 additions & 11 deletions contracts/test/TestAvatar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ contract TestAvatar {
module = _module;
}

function exec(address payable to, uint256 value, bytes calldata data) external {
function exec(
address payable to,
uint256 value,
bytes calldata data
) external {
bool success;
bytes memory response;
(success, response) = to.call{value: value}(data);
if(!success) {
if (!success) {
assembly {
revert(add(response, 0x20), mload(response))
}
}
}

function execTransactionFromModule(address payable to, uint256 value, bytes calldata data, uint8 operation)
external
returns (bool success)
{
function execTransactionFromModule(
address payable to,
uint256 value,
bytes calldata data,
uint8 operation
) external returns (bool success) {
require(msg.sender == module, "Not authorized");
if (operation == 1)
(success,) = to.delegatecall(data);
else
(success,) = to.call{value: value}(data);
if (operation == 1) (success, ) = to.delegatecall(data);
else (success, ) = to.call{value: value}(data);
}
}
}
4 changes: 3 additions & 1 deletion contracts/test/TestFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;

import "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol";
import {ModuleProxyFactory} from "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol";

contract TestFactory is ModuleProxyFactory {}
Loading
Loading