From beaa67232e259cb9ba866fc383c26ea18074ffbb Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Sat, 12 Sep 2020 20:12:37 +1000 Subject: [PATCH] moved signers to deployed contracts --- contracts/deployer.sol | 27 +++++++++++++++++++++++---- contracts/flusher.sol | 8 ++++---- contracts/registry.sol | 25 ------------------------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/contracts/deployer.sol b/contracts/deployer.sol index 228a332..0616112 100644 --- a/contracts/deployer.sol +++ b/contracts/deployer.sol @@ -8,10 +8,13 @@ contract Controller { event LogUpdateMaster(address indexed master); event LogEnableConnector(address indexed connector); event LogDisableConnector(address indexed connector); + event LogAddSigner(address indexed signer); + event LogRemoveSigner(address indexed signer); address private newMaster; address public master; mapping (address => bool) public connectors; + mapping (address => bool) public signer; modifier isMaster() { require(msg.sender == master, "not-master"); @@ -36,21 +39,37 @@ contract Controller { emit LogUpdateMaster(master); } - // enable flusher connector - function enableConnector(address _connector) external isChief { + // enable connector + function enableConnector(address _connector) external isMaster { require(!connectors[_connector], "already-enabled"); require(_connector != address(0), "invalid-connector"); connectors[_connector] = true; emit LogEnableConnector(_connector); } - // disable flusher connector - function disableConnector(address _connector) external isChief { + // disable connector + function disableConnector(address _connector) external isMaster { require(connectors[_connector], "already-disabled"); delete connectors[_connector]; emit LogDisableConnector(_connector); } + // enable signer + function enableSigner(address _signer) external isMaster { + require(_signer != address(0), "invalid-address"); + require(!signer[_signer], "signer-already-enabled"); + signer[_signer] = true; + emit LogAddSigner(_signer); + } + + // disable signer + function disableSigner(address _signer) external isMaster { + require(_signer != address(0), "invalid-address"); + require(signer[_signer], "signer-already-disabled"); + delete signer[_signer]; + emit LogRemoveSigner(_signer); + } + // check if connectors[] are enabled function isConnector(address[] calldata _connectors) external view returns (bool isOk) { isOk = true; diff --git a/contracts/flusher.sol b/contracts/flusher.sol index 115118f..3535b8a 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -3,7 +3,7 @@ pragma solidity ^0.6.8; pragma experimental ABIEncoderV2; -interface RegistryInterface { +interface DeployerInterface { function signer(address) external view returns (bool); function isConnector(address[] calldata) external view returns (bool); } @@ -13,7 +13,7 @@ contract Flusher { string constant public name = "Flusher-v1"; - RegistryInterface public constant registry = RegistryInterface(address(0)); // TODO - Change while deploying + DeployerInterface public constant deployer = DeployerInterface(address(0)); // TODO - Change while deploying function spell(address _target, bytes memory _data) internal { require(_target != address(0), "target-invalid"); @@ -29,9 +29,9 @@ contract Flusher { } function cast(address[] calldata _targets, bytes[] calldata _datas) external payable { - require(registry.signer(msg.sender), "not-signer"); + require(deployer.signer(msg.sender), "not-signer"); require(_targets.length == _datas.length , "invalid-array-length"); - require(registry.isConnector(_targets), "not-connector"); + require(deployer.isConnector(_targets), "not-connector"); for (uint i = 0; i < _targets.length; i++) { spell(_targets[i], _datas[i]); } diff --git a/contracts/registry.sol b/contracts/registry.sol index bc0d63b..fb7fffa 100644 --- a/contracts/registry.sol +++ b/contracts/registry.sol @@ -11,8 +11,6 @@ contract Registry { event LogAddChief(address indexed chief); event LogRemoveChief(address indexed chief); - event LogAddSigner(address indexed signer); - event LogRemoveSigner(address indexed signer); event LogUpdatePoolLogic(address token, address newLogic); event LogUpdateFee(address token, uint newFee); event LogUpdateCap(address token, uint newFee); @@ -22,7 +20,6 @@ contract Registry { IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723); mapping (address => bool) public chief; - mapping (address => bool) public signer; mapping (address => address) public poolLogic; mapping (address => uint) public poolCap; mapping (address => uint) public fee; @@ -60,28 +57,6 @@ contract Registry { emit LogRemoveChief(_chief); } - /** - * @dev Enable New Signer. - * @param _signer Address of the new signer. - */ - function enableSigner(address _signer) external isChief { - require(_signer != address(0), "invalid-address"); - require(!signer[_signer], "signer-already-enabled"); - signer[_signer] = true; - emit LogAddSigner(_signer); - } - - /** - * @dev Disable Signer. - * @param _signer Address of the existing signer. - */ - function disableSigner(address _signer) external isChief { - require(_signer != address(0), "invalid-address"); - require(signer[_signer], "signer-already-disabled"); - delete signer[_signer]; - emit LogRemoveSigner(_signer); - } - /** * @dev update pool rate logic * @param _pool pool address