2021-03-16 16:25:39 +00:00
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
|
|
|
interface IndexInterface {
|
|
|
|
function master() external view returns (address);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ConnectorsInterface {
|
|
|
|
function chief(address) external view returns (bool);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CTokenInterface {
|
|
|
|
function isCToken() external view returns (bool);
|
2021-03-18 05:06:35 +00:00
|
|
|
function underlying() external view returns (address);
|
2021-03-16 16:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract contract Helpers {
|
|
|
|
|
2021-03-18 05:06:35 +00:00
|
|
|
struct TokenMap {
|
|
|
|
address ctoken;
|
|
|
|
address token;
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:59:20 +00:00
|
|
|
event LogCTokenAdded(string indexed name, address indexed token, address indexed ctoken);
|
|
|
|
event LogCTokenUpdated(string indexed name, address indexed token, address indexed ctoken);
|
2021-03-16 16:25:39 +00:00
|
|
|
|
|
|
|
ConnectorsInterface public immutable connectors;
|
|
|
|
|
|
|
|
// InstaIndex Address.
|
|
|
|
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
|
|
|
|
2021-03-18 05:06:35 +00:00
|
|
|
address public constant ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
|
|
|
|
|
|
|
mapping (string => TokenMap) public cTokenMapping;
|
2021-03-16 16:25:39 +00:00
|
|
|
|
|
|
|
modifier isChief {
|
|
|
|
require(msg.sender == instaIndex.master() || connectors.chief(msg.sender), "not-an-chief");
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(address _connectors) {
|
|
|
|
connectors = ConnectorsInterface(_connectors);
|
|
|
|
}
|
|
|
|
|
2021-03-16 17:01:15 +00:00
|
|
|
function _addCtokenMapping(
|
|
|
|
string[] memory _names,
|
|
|
|
address[] memory _tokens,
|
|
|
|
address[] memory _ctokens
|
|
|
|
) internal {
|
|
|
|
require(_names.length == _tokens.length, "addCtokenMapping: not same length");
|
2021-03-16 16:25:39 +00:00
|
|
|
require(_names.length == _ctokens.length, "addCtokenMapping: not same length");
|
2021-03-16 17:01:15 +00:00
|
|
|
|
2021-03-16 16:25:39 +00:00
|
|
|
for (uint i = 0; i < _ctokens.length; i++) {
|
2021-03-18 05:06:35 +00:00
|
|
|
TokenMap memory _data = cTokenMapping[_names[i]];
|
|
|
|
|
|
|
|
require(_data.ctoken == address(0), "addCtokenMapping: mapping added already");
|
|
|
|
require(_data.token == address(0), "addCtokenMapping: mapping added already");
|
2021-03-16 17:01:15 +00:00
|
|
|
|
|
|
|
require(_tokens[i] != address(0), "addCtokenMapping: _tokens address not vaild");
|
2021-03-16 16:25:39 +00:00
|
|
|
require(_ctokens[i] != address(0), "addCtokenMapping: _ctokens address not vaild");
|
2021-03-16 17:01:15 +00:00
|
|
|
|
2021-03-18 05:06:35 +00:00
|
|
|
CTokenInterface _ctokenContract = CTokenInterface(_ctokens[i]);
|
2021-03-16 16:25:39 +00:00
|
|
|
|
2021-03-18 05:06:35 +00:00
|
|
|
require(_ctokenContract.isCToken(), "addCtokenMapping: not a cToken");
|
|
|
|
if (_tokens[i] != ethAddr) {
|
|
|
|
require(_ctokenContract.underlying() == _tokens[i], "addCtokenMapping: mapping mismatch");
|
|
|
|
}
|
|
|
|
|
|
|
|
cTokenMapping[_names[i]] = TokenMap(
|
|
|
|
_ctokens[i],
|
|
|
|
_tokens[i]
|
|
|
|
);
|
2021-03-19 16:59:20 +00:00
|
|
|
emit LogCTokenAdded(_names[i], _tokens[i], _ctokens[i]);
|
2021-03-16 16:25:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 17:01:15 +00:00
|
|
|
function updateCtokenMapping(
|
|
|
|
string[] calldata _names,
|
|
|
|
address[] memory _tokens,
|
|
|
|
address[] calldata _ctokens
|
|
|
|
) external {
|
2021-03-16 16:25:39 +00:00
|
|
|
require(msg.sender == instaIndex.master(), "not-master");
|
2021-03-16 17:01:15 +00:00
|
|
|
|
|
|
|
require(_names.length == _tokens.length, "updateCtokenMapping: not same length");
|
2021-03-16 16:25:39 +00:00
|
|
|
require(_names.length == _ctokens.length, "updateCtokenMapping: not same length");
|
2021-03-16 17:01:15 +00:00
|
|
|
|
2021-03-16 16:25:39 +00:00
|
|
|
for (uint i = 0; i < _ctokens.length; i++) {
|
2021-03-18 05:06:35 +00:00
|
|
|
TokenMap memory _data = cTokenMapping[_names[i]];
|
|
|
|
|
|
|
|
require(_data.ctoken != address(0), "updateCtokenMapping: mapping does not exist");
|
|
|
|
require(_data.token != address(0), "updateCtokenMapping: mapping does not exist");
|
2021-03-16 17:01:15 +00:00
|
|
|
|
|
|
|
require(_tokens[i] != address(0), "updateCtokenMapping: _tokens address not vaild");
|
2021-03-16 16:25:39 +00:00
|
|
|
require(_ctokens[i] != address(0), "updateCtokenMapping: _ctokens address not vaild");
|
2021-03-16 17:01:15 +00:00
|
|
|
|
2021-03-18 05:06:35 +00:00
|
|
|
CTokenInterface _ctokenContract = CTokenInterface(_ctokens[i]);
|
|
|
|
|
|
|
|
require(_ctokenContract.isCToken(), "updateCtokenMapping: not a cToken");
|
|
|
|
if (_tokens[i] != ethAddr) {
|
|
|
|
require(_ctokenContract.underlying() == _tokens[i], "addCtokenMapping: mapping mismatch");
|
|
|
|
}
|
2021-03-16 16:25:39 +00:00
|
|
|
|
2021-03-18 05:06:35 +00:00
|
|
|
cTokenMapping[_names[i]] = TokenMap(
|
|
|
|
_ctokens[i],
|
|
|
|
_tokens[i]
|
|
|
|
);
|
2021-03-19 20:37:23 +00:00
|
|
|
emit LogCTokenUpdated(_names[i], _tokens[i], _ctokens[i]);
|
2021-03-16 16:25:39 +00:00
|
|
|
}
|
2021-03-16 17:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function addCtokenMapping(
|
|
|
|
string[] memory _names,
|
|
|
|
address[] memory _tokens,
|
|
|
|
address[] memory _ctokens
|
|
|
|
) external isChief {
|
|
|
|
_addCtokenMapping(_names, _tokens, _ctokens);
|
2021-03-16 16:25:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 05:06:35 +00:00
|
|
|
function getMapping(string memory _tokenId) external view returns (address, address) {
|
|
|
|
TokenMap memory _data = cTokenMapping[_tokenId];
|
|
|
|
return (_data.token, _data.ctoken);
|
2021-03-16 16:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:40:04 +00:00
|
|
|
contract InstaCompoundMapping is Helpers {
|
2021-03-19 16:59:20 +00:00
|
|
|
string constant public name = "Compound-Mapping-v1.1";
|
2021-03-16 16:25:39 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
address _connectors,
|
|
|
|
string[] memory _ctokenNames,
|
2021-03-16 17:01:15 +00:00
|
|
|
address[] memory _tokens,
|
2021-03-16 16:25:39 +00:00
|
|
|
address[] memory _ctokens
|
|
|
|
) Helpers(_connectors) {
|
2021-03-16 17:01:15 +00:00
|
|
|
_addCtokenMapping(_ctokenNames, _tokens, _ctokens);
|
2021-03-16 16:25:39 +00:00
|
|
|
}
|
|
|
|
}
|