From da2f8cbc73023409d40cb88be6dd18d8c3354023 Mon Sep 17 00:00:00 2001 From: Drygin Date: Mon, 28 Feb 2022 23:22:40 +0300 Subject: [PATCH] use onlyGovernance instead of onlyOwner --- README.md | 2 +- contracts/InstanceFactory.sol | 46 +++++++++++++++++++++++----- contracts/interfaces/IGovernance.sol | 7 ----- 3 files changed, 39 insertions(+), 16 deletions(-) delete mode 100644 contracts/interfaces/IGovernance.sol diff --git a/README.md b/README.md index b6baf79..9bc3c46 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Check config.js for actual values. With `salt` = `0x0000000000000000000000000000000000000000000000000000000047941987` address must be: -1. `InstanceFactory` - `0x7a6e627DC6F66617b4A74Be097A8f56c622fa24c` +1. `InstanceFactory` - `0xBb3bd4849F88E709Ea6e5dC8F2C4cDc5293a12d5` Check addresses with current config: diff --git a/contracts/InstanceFactory.sol b/contracts/InstanceFactory.sol index a820b59..39527cd 100644 --- a/contracts/InstanceFactory.sol +++ b/contracts/InstanceFactory.sol @@ -8,7 +8,6 @@ import { Address } from "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/proxy/Clones.sol"; import "./ERC20TornadoCloneable.sol"; import "./AddInstanceProposal.sol"; -import "./interfaces/IGovernance.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IERC20Permit } from "@openzeppelin/contracts/drafts/IERC20Permit.sol"; @@ -33,6 +32,14 @@ contract InstanceFactory is Ownable { event NewInstanceCloneCreated(address indexed clone); event NewGovernanceProposalCreated(address indexed proposal); + /** + * @dev Throws if called by any account other than the Governance. + */ + modifier onlyGovernance() { + require(owner() == _msgSender(), "Caller is not the Governance"); + _; + } + constructor( address _verifier, address _hasher, @@ -56,7 +63,12 @@ contract InstanceFactory is Ownable { transferOwnership(_governance); } - function createInstanceClone(uint256 _denomination, address _token) external onlyOwner returns (address) { + /** + * @dev Throws if called by any account other than the Governance. + * @param _denomination denomination of new Tornado instance + * @param _token address of ERC20 token for a new instance + */ + function createInstanceClone(uint256 _denomination, address _token) external onlyGovernance returns (address) { bytes32 salt = keccak256(abi.encodePacked(_denomination, _token)); require(!implementation.predictDeterministicAddress(salt).isContract(), "Instance already exists"); @@ -73,6 +85,15 @@ contract InstanceFactory is Ownable { return implementation.predictDeterministicAddress(salt); } + /** + * @dev Creates AddInstanceProposal with approve. + * @param _token address of ERC20 token for a new instance + * @param _uniswapPoolSwappingFee fee value of Uniswap instance which will be used for `TORN/token` price determination. + * `3000` means 0.3% fee Uniswap pool. + * @param _denominations list of denominations for each new instance + * @param _protocolFees list of protocol fees for each new instance. + * `100` means that instance withdrawal fee is 1% of denomination. + */ function createProposalApprove( address _token, uint24 _uniswapPoolSwappingFee, @@ -83,6 +104,15 @@ contract InstanceFactory is Ownable { return _createProposal(_token, _uniswapPoolSwappingFee, _denominations, _protocolFees); } + /** + * @dev Creates AddInstanceProposal with approve. + * @param _token address of ERC20 token for a new instance + * @param _uniswapPoolSwappingFee fee value of Uniswap instance which will be used for `TORN/token` price determination. + * `3000` means 0.3% fee Uniswap pool. + * @param _denominations list of denominations for each new instance + * @param _protocolFees list of protocol fees for each new instance. + * `100` means that instance withdrawal fee is 1% of denomination. + */ function createProposalPermit( address _token, uint24 _uniswapPoolSwappingFee, @@ -118,32 +148,32 @@ contract InstanceFactory is Ownable { return proposal; } - function setVerifier(address _verifier) external onlyOwner { + function setVerifier(address _verifier) external onlyGovernance { verifier = _verifier; emit NewVerifierSet(verifier); } - function setHasher(address _hasher) external onlyOwner { + function setHasher(address _hasher) external onlyGovernance { hasher = _hasher; emit NewHasherSet(hasher); } - function setMerkleTreeHeight(uint32 _merkleTreeHeight) external onlyOwner { + function setMerkleTreeHeight(uint32 _merkleTreeHeight) external onlyGovernance { merkleTreeHeight = _merkleTreeHeight; emit NewTreeHeightSet(merkleTreeHeight); } - function setCreationFee(uint256 _creationFee) external onlyOwner { + function setCreationFee(uint256 _creationFee) external onlyGovernance { creationFee = _creationFee; emit NewCreationFeeSet(_creationFee); } - function setImplementation(address _newImplementation) external onlyOwner { + function setImplementation(address _newImplementation) external onlyGovernance { implementation = _newImplementation; emit NewImplementationSet(implementation); } - function generateNewImplementation() external onlyOwner { + function generateNewImplementation() external onlyGovernance { implementation = address(new ERC20TornadoCloneable(verifier, hasher)); } } diff --git a/contracts/interfaces/IGovernance.sol b/contracts/interfaces/IGovernance.sol deleted file mode 100644 index c7b16d4..0000000 --- a/contracts/interfaces/IGovernance.sol +++ /dev/null @@ -1,7 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.7.6; - -interface IGovernance { - function propose(address target, string memory description) external returns (uint256); -}