yield-contract/contracts/registry.sol

250 lines
7.8 KiB
Solidity
Raw Normal View History

2020-08-22 03:07:55 +00:00
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.8;
pragma experimental ABIEncoderV2;
interface IndexInterface {
function master() external view returns (address);
}
contract Registry {
event LogAddChief(address indexed chief);
event LogRemoveChief(address indexed chief);
2020-08-24 01:15:28 +00:00
event LogAddSigner(address indexed signer);
event LogRemoveSigner(address indexed signer);
2020-09-06 15:19:39 +00:00
event LogUpdatePoolLogic(address token, address newLogic);
2020-09-06 21:11:23 +00:00
event LogUpdateFlusherLogic(address token, address newLogic);
2020-09-06 15:19:39 +00:00
event LogUpdateFee(address token, uint newFee);
2020-09-06 16:01:27 +00:00
event LogUpdateCap(address token, uint newFee);
event LogAddPool(address indexed token, address indexed pool);
event LogRemovePool(address indexed token, address indexed pool);
2020-09-06 15:19:39 +00:00
event LogAddSettleLogic(address indexed token, address indexed logic);
event LogRemoveSettleLogic(address indexed token, address indexed logic);
2020-09-07 16:17:21 +00:00
event LogFlusherConnectorsEnable(address indexed connector);
2020-09-08 09:48:50 +00:00
event LogFlusherConnectorsDisable(address indexed connector);
2020-08-22 03:07:55 +00:00
2020-08-24 00:40:01 +00:00
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
2020-08-22 03:07:55 +00:00
mapping (address => bool) public chief;
2020-08-24 01:15:28 +00:00
mapping (address => bool) public signer;
2020-08-25 14:21:21 +00:00
mapping (address => address) public poolToken;
2020-08-24 00:40:01 +00:00
mapping (address => address) public poolLogic;
2020-09-06 21:11:23 +00:00
mapping (address => address) public flusherLogic;
2020-08-24 00:40:01 +00:00
mapping (address => uint) public poolCap;
2020-09-06 15:19:39 +00:00
mapping (address => uint) public fee;
2020-09-06 12:08:29 +00:00
mapping (address => mapping(address => bool)) public settleLogic;
2020-09-08 09:48:50 +00:00
mapping (address => bool) public flusherConnectors;
2020-08-22 03:07:55 +00:00
modifier isMaster() {
require(msg.sender == instaIndex.master(), "not-master");
_;
}
2020-08-24 00:40:01 +00:00
modifier isChief() {
2020-08-22 03:07:55 +00:00
require(chief[msg.sender] || msg.sender == instaIndex.master(), "not-chief");
_;
}
/**
* @dev Enable New Chief.
* @param _chief Address of the new chief.
*/
function enableChief(address _chief) external isMaster {
2020-08-24 00:40:01 +00:00
require(_chief != address(0), "address-not-valid");
require(!chief[_chief], "chief-already-enabled");
chief[_chief] = true;
emit LogAddChief(_chief);
2020-08-22 03:07:55 +00:00
}
/**
* @dev Disable Chief.
* @param _chief Address of the existing chief.
*/
function disableChief(address _chief) external isMaster {
2020-08-24 00:40:01 +00:00
require(_chief != address(0), "address-not-valid");
require(chief[_chief], "chief-already-disabled");
delete chief[_chief];
emit LogRemoveChief(_chief);
}
2020-08-24 01:15:28 +00:00
/**
* @dev Enable New Signer.
* @param _signer Address of the new signer.
*/
function enableSigner(address _signer) external isChief {
2020-09-08 11:43:54 +00:00
require(_signer != address(0), "invalid-address");
require(!signer[_signer], "signer-already-enabled");
signer[_signer] = true;
emit LogAddSigner(_signer);
2020-08-24 01:15:28 +00:00
}
/**
* @dev Disable Signer.
* @param _signer Address of the existing signer.
*/
function disableSigner(address _signer) external isChief {
2020-09-08 11:43:54 +00:00
require(_signer != address(0), "invalid-address");
require(signer[_signer], "signer-already-disabled");
delete signer[_signer];
emit LogRemoveSigner(_signer);
2020-08-24 01:15:28 +00:00
}
/**
* @dev Add New Pool
2020-09-06 15:19:39 +00:00
* @param _token ERC20 token address
* @param pool pool address
*/
2020-09-06 15:19:39 +00:00
function addPool(address _token, address pool) external isMaster {
require(_token != address(0) && pool != address(0), "invalid-token-address");
require(poolToken[_token] == address(0), "pool-already-added");
poolToken[_token] = pool;
emit LogAddPool(_token, pool);
}
/**
* @dev Remove Pool
2020-09-06 15:19:39 +00:00
* @param _token ERC20 token address
2020-08-30 13:27:03 +00:00
*/
2020-09-06 15:19:39 +00:00
function removePool(address _token) external isMaster {
require(_token != address(0), "invalid-token-address");
require(poolToken[_token] != address(0), "pool-already-removed");
address poolAddr = poolToken[_token];
delete poolToken[_token];
emit LogRemovePool(_token, poolAddr);
2020-08-24 00:40:01 +00:00
}
2020-08-30 19:12:23 +00:00
/**
* @dev update pool rate logic
2020-09-07 04:51:20 +00:00
* @param _token token address
2020-08-30 19:12:23 +00:00
* @param _newLogic new rate logic address
*/
2020-09-06 15:19:39 +00:00
function updatePoolLogic(address _token, address _newLogic) external isMaster {
address _pool = poolToken[_token];
require(_pool != address(0), "invalid-pool");
2020-08-24 17:33:44 +00:00
require(_newLogic != address(0), "invalid-address");
2020-09-06 16:01:27 +00:00
require(poolLogic[_pool] != _newLogic, "same-pool-logic");
2020-08-24 00:40:01 +00:00
poolLogic[_pool] = _newLogic;
emit LogUpdatePoolLogic(_pool, _newLogic);
}
2020-09-06 21:11:23 +00:00
/**
* @dev update flusher logic
2020-09-07 04:51:20 +00:00
* @param _token token address
2020-09-06 21:11:23 +00:00
* @param _newLogic new flusher logic address
*/
function updateFlusherLogic(address _token, address _newLogic) external isMaster {
address _pool = poolToken[_token];
require(_pool != address(0), "invalid-pool");
require(_newLogic != address(0), "invalid-address");
require(flusherLogic[_pool] != _newLogic, "same-pool-logic");
flusherLogic[_pool] = _newLogic;
emit LogUpdateFlusherLogic(_pool, _newLogic);
}
2020-08-30 19:12:23 +00:00
/**
2020-09-06 15:19:39 +00:00
* @dev update pool fee
2020-09-07 04:51:20 +00:00
* @param _token token address
2020-09-06 15:19:39 +00:00
* @param _newFee new fee amount
2020-08-30 19:12:23 +00:00
*/
2020-09-06 15:19:39 +00:00
function updateFee(address _token, uint _newFee) external isMaster {
address _pool = poolToken[_token];
require(_pool != address(0), "invalid-pool");
require(_newFee < 3 * 10 ** 17, "insure-fee-limit-reached");
require(fee[_pool] != _newFee, "same-pool-fee");
fee[_pool] = _newFee;
emit LogUpdateFee(_pool, _newFee);
}
2020-09-06 16:01:27 +00:00
/**
* @dev update pool fee
2020-09-07 04:51:20 +00:00
* @param _token token address
2020-09-06 16:01:27 +00:00
* @param _newCap new fee amount
*/
function updateCap(address _token, uint _newCap) external isMaster {
address _pool = poolToken[_token];
require(_pool != address(0), "invalid-pool");
poolCap[_pool] = _newCap;
emit LogUpdateCap(_pool, _newCap);
}
2020-09-07 04:51:20 +00:00
/**
* @dev adding settlement logic
* @param _token token address
* @param _logic logic proxy
*/
2020-09-06 15:19:39 +00:00
function addSettleLogic(address _token, address _logic) external isMaster {
address _pool = poolToken[_token];
require(_pool != address(0), "invalid-pool");
2020-09-06 12:08:29 +00:00
settleLogic[_pool][_logic] = true;
emit LogAddSettleLogic(_pool, _logic);
}
2020-09-07 04:51:20 +00:00
/**
* @dev removing settlement logic
* @param _token token address
* @param _logic logic proxy
*/
2020-09-06 15:19:39 +00:00
function removeSettleLogic(address _token, address _logic) external isMaster {
address _pool = poolToken[_token];
require(_pool != address(0), "invalid-pool");
2020-09-06 12:08:29 +00:00
delete settleLogic[_pool][_logic];
emit LogRemoveSettleLogic(_pool, _logic);
}
2020-09-07 04:51:20 +00:00
/**
* @dev enable pool connector
* @param _connector logic proxy
*/
2020-09-06 22:05:09 +00:00
function enableConnector(address _connector) external isChief {
2020-09-07 16:17:21 +00:00
require(!flusherConnectors[_connector], "already-enabled");
2020-09-06 22:05:09 +00:00
require(_connector != address(0), "invalid-connector");
2020-09-07 16:17:21 +00:00
flusherConnectors[_connector] = true;
2020-09-08 09:48:50 +00:00
emit LogFlusherConnectorsEnable(_connector);
2020-09-06 22:05:09 +00:00
}
2020-09-07 04:51:20 +00:00
/**
* @dev disable pool connector
* @param _connector logic proxy
*/
2020-09-06 22:05:09 +00:00
function disableConnector(address _connector) external isChief {
2020-09-07 16:17:21 +00:00
require(flusherConnectors[_connector], "already-disabled");
delete flusherConnectors[_connector];
2020-09-08 09:48:50 +00:00
emit LogFlusherConnectorsDisable(_connector);
2020-09-06 22:05:09 +00:00
}
2020-09-07 04:51:20 +00:00
/**
2020-09-07 10:09:51 +00:00
* @dev check if settle logics are enabled
* @param _pool token pool address
* @param _logics array of logic proxy
2020-09-07 04:51:20 +00:00
*/
2020-09-06 22:05:09 +00:00
function checkSettleLogics(address _pool, address[] calldata _logics) external view returns(bool isOk) {
isOk = true;
2020-09-06 12:08:29 +00:00
for (uint i = 0; i < _logics.length; i++) {
if (!settleLogic[_pool][_logics[i]]) {
2020-09-06 22:05:09 +00:00
isOk = false;
break;
}
}
}
2020-09-07 04:51:20 +00:00
/**
* @dev check if connectors are enabled
* @param _connectors array of logic proxy
*/
2020-09-06 22:05:09 +00:00
function isConnector(address[] calldata _connectors) external view returns (bool isOk) {
isOk = true;
for (uint i = 0; i < _connectors.length; i++) {
2020-09-07 16:17:21 +00:00
if (!flusherConnectors[_connectors[i]]) {
2020-09-06 22:05:09 +00:00
isOk = false;
break;
2020-09-06 12:08:29 +00:00
}
}
}
2020-08-24 00:40:01 +00:00
constructor(address _chief) public {
chief[_chief] = true;
emit LogAddChief(_chief);
2020-08-24 01:15:28 +00:00
}
2020-08-22 03:07:55 +00:00
}