yield-contract/contracts/registry.sol

161 lines
5.1 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);
2020-08-26 16:46:54 +00:00
function build(address _owner, uint accountVersion, address _origin) external returns (address _account);
2020-08-22 03:07:55 +00:00
}
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-08-24 00:40:01 +00:00
event LogSwitchPool(address pool, bool);
event LogUpdatePoolCap(address pool, uint newCap);
event LogUpdatePoolLogic(address pool, address newLogic);
event LogUpdateInsureFee(address pool, uint newFee);
event LogAddPool(address indexed token, address indexed pool);
event LogRemovePool(address indexed token, address indexed pool);
2020-08-26 16:46:54 +00:00
event LogNewDSA(address indexed pool, address indexed dsa);
event LogRemoveDSA(address indexed pool, address indexed dsa);
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-24 00:40:01 +00:00
mapping (address => bool) public isPool;
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;
mapping (address => uint) public poolCap;
mapping (address => uint) public insureFee;
2020-08-26 13:35:10 +00:00
mapping (address => mapping(address => bool)) public isDsa; // Pool => DSA address => true/false
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-08-24 17:33:44 +00:00
require(_signer != address(0), "invalid-address");
2020-08-24 01:15:28 +00:00
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 {
2020-08-24 17:33:44 +00:00
require(_signer != address(0), "invalid-address");
2020-08-24 01:15:28 +00:00
require(signer[_signer], "signer-already-disabled");
delete signer[_signer];
emit LogRemoveSigner(_signer);
}
/**
* @dev Add New Pool
* @param token ERC20 token address
* @param pool pool address
*/
2020-08-25 14:21:21 +00:00
function addPool(address token, address pool) external isMaster {
2020-08-24 17:33:44 +00:00
require(token != address(0) && pool != address(0), "invalid-address");
2020-08-25 14:21:21 +00:00
require(poolToken[token] == address(0), "pool-already-added");
poolToken[token] = pool;
emit LogAddPool(token, pool);
}
/**
* @dev Remove Pool
* @param token ERC20 token address
*/
2020-08-25 14:21:21 +00:00
function removePool(address token) external isMaster {
2020-08-24 17:33:44 +00:00
require(token != address(0), "invalid-address");
2020-08-25 14:21:21 +00:00
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
function switchPool(address _pool) external isMaster {
isPool[_pool] = !isPool[_pool];
emit LogSwitchPool(_pool, isPool[_pool]);
}
2020-08-26 13:35:10 +00:00
function updatePoolCap(address _pool, uint _newCap) external isMaster {
2020-08-24 17:33:44 +00:00
require(isPool[_pool], "not-pool");
2020-08-24 00:40:01 +00:00
poolCap[_pool] = _newCap;
emit LogUpdatePoolCap(_pool, _newCap);
}
function updatePoolLogic(address _pool, address _newLogic) external isMaster {
2020-08-24 17:33:44 +00:00
require(isPool[_pool], "not-pool");
require(_newLogic != address(0), "invalid-address");
2020-08-24 00:40:01 +00:00
poolLogic[_pool] = _newLogic;
emit LogUpdatePoolLogic(_pool, _newLogic);
}
2020-08-26 13:35:10 +00:00
function updateInsureFee(address _pool, uint _newFee) external isMaster {
2020-08-24 17:33:44 +00:00
require(isPool[_pool], "not-pool");
2020-08-25 14:20:00 +00:00
require(_newFee < 10 ** 18, "insure-fee-limit-reached");
2020-08-24 00:40:01 +00:00
insureFee[_pool] = _newFee;
emit LogUpdateInsureFee(_pool, _newFee);
}
function addDsa(address _pool, address _dsa) external isMaster {
2020-08-26 13:35:10 +00:00
require(isPool[_pool], "not-pool");
if (_dsa == address(0)) {
_dsa = instaIndex.build(_pool, 1, address(this));
}
2020-08-26 13:35:10 +00:00
isDsa[_pool][_dsa] = true;
2020-08-26 16:46:54 +00:00
emit LogNewDSA(_pool, _dsa);
2020-08-26 13:35:10 +00:00
}
2020-08-26 16:46:54 +00:00
function removeDsa(address _pool, address _dsa) external isMaster {
require(isPool[_pool], "not-pool");
require(isDsa[_pool][_dsa], "not-dsa-for-pool");
2020-08-26 13:35:10 +00:00
delete isDsa[_pool][_dsa];
2020-08-26 16:46:54 +00:00
emit LogRemoveDSA(_pool, _dsa);
2020-08-26 13:35:10 +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
}