mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Add token mapping as well to compound
This commit is contained in:
parent
ba57f14984
commit
73d3bef659
|
@ -15,8 +15,8 @@ interface CTokenInterface {
|
|||
|
||||
abstract contract Helpers {
|
||||
|
||||
event LogCTokensAdded(string[] names, address[] ctokens);
|
||||
event LogCTokensUpdated(string[] names, address[] ctokens);
|
||||
event LogCTokensAdded(string[] names, address[] tokens, address[] ctokens);
|
||||
event LogCTokensUpdated(string[] names, address[] tokens, address[] ctokens);
|
||||
|
||||
ConnectorsInterface public immutable connectors;
|
||||
|
||||
|
@ -24,6 +24,7 @@ abstract contract Helpers {
|
|||
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
||||
|
||||
mapping (string => address) public cTokenMapping;
|
||||
mapping (string => address) public tokenMapping;
|
||||
|
||||
modifier isChief {
|
||||
require(msg.sender == instaIndex.master() || connectors.chief(msg.sender), "not-an-chief");
|
||||
|
@ -34,34 +35,65 @@ abstract contract Helpers {
|
|||
connectors = ConnectorsInterface(_connectors);
|
||||
}
|
||||
|
||||
function _addCtokenMapping(string[] memory _names, address[] memory _ctokens) internal {
|
||||
function _addCtokenMapping(
|
||||
string[] memory _names,
|
||||
address[] memory _tokens,
|
||||
address[] memory _ctokens
|
||||
) internal {
|
||||
require(_names.length == _tokens.length, "addCtokenMapping: not same length");
|
||||
require(_names.length == _ctokens.length, "addCtokenMapping: not same length");
|
||||
|
||||
for (uint i = 0; i < _ctokens.length; i++) {
|
||||
require(tokenMapping[_names[i]] == address(0), "addCtokenMapping: mapping added already");
|
||||
require(cTokenMapping[_names[i]] == address(0), "addCtokenMapping: mapping added already");
|
||||
|
||||
require(_tokens[i] != address(0), "addCtokenMapping: _tokens address not vaild");
|
||||
require(_ctokens[i] != address(0), "addCtokenMapping: _ctokens address not vaild");
|
||||
|
||||
require(CTokenInterface(_ctokens[i]).isCToken(), "addCtokenMapping: not a cToken");
|
||||
|
||||
tokenMapping[_names[i]] = _tokens[i];
|
||||
cTokenMapping[_names[i]] = _ctokens[i];
|
||||
// emit LogCTokenAdded(_names[i], _ctokens[i]);
|
||||
}
|
||||
emit LogCTokensAdded(_names, _ctokens);
|
||||
emit LogCTokensAdded(_names, _tokens, _ctokens);
|
||||
}
|
||||
|
||||
function updateCtokenMapping(string[] calldata _names, address[] calldata _ctokens) external {
|
||||
function updateCtokenMapping(
|
||||
string[] calldata _names,
|
||||
address[] memory _tokens,
|
||||
address[] calldata _ctokens
|
||||
) external {
|
||||
require(msg.sender == instaIndex.master(), "not-master");
|
||||
|
||||
require(_names.length == _tokens.length, "updateCtokenMapping: not same length");
|
||||
require(_names.length == _ctokens.length, "updateCtokenMapping: not same length");
|
||||
|
||||
for (uint i = 0; i < _ctokens.length; i++) {
|
||||
require(tokenMapping[_names[i]] != address(0), "updateCtokenMapping: mapping does not exist");
|
||||
require(cTokenMapping[_names[i]] != address(0), "updateCtokenMapping: mapping does not exist");
|
||||
|
||||
require(_tokens[i] != address(0), "updateCtokenMapping: _tokens address not vaild");
|
||||
require(_ctokens[i] != address(0), "updateCtokenMapping: _ctokens address not vaild");
|
||||
|
||||
require(CTokenInterface(_ctokens[i]).isCToken(), "updateCtokenMapping: not a cToken");
|
||||
|
||||
tokenMapping[_names[i]] = _tokens[i];
|
||||
cTokenMapping[_names[i]] = _ctokens[i];
|
||||
}
|
||||
emit LogCTokensUpdated(_names, _ctokens);
|
||||
emit LogCTokensUpdated(_names, _tokens, _ctokens);
|
||||
}
|
||||
|
||||
function addCtokenMapping(string[] memory _names, address[] memory _ctokens) external isChief {
|
||||
_addCtokenMapping(_names, _ctokens);
|
||||
function addCtokenMapping(
|
||||
string[] memory _names,
|
||||
address[] memory _tokens,
|
||||
address[] memory _ctokens
|
||||
) external isChief {
|
||||
_addCtokenMapping(_names, _tokens, _ctokens);
|
||||
}
|
||||
|
||||
function getMapping(string memory _tokenId) external view returns (address _token, address _ctoken) {
|
||||
_token = tokenMapping[_tokenId];
|
||||
_ctoken = cTokenMapping[_tokenId];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,8 +104,9 @@ contract InstaCompoundMapping is Helpers {
|
|||
constructor(
|
||||
address _connectors,
|
||||
string[] memory _ctokenNames,
|
||||
address[] memory _tokens,
|
||||
address[] memory _ctokens
|
||||
) Helpers(_connectors) {
|
||||
_addCtokenMapping(_ctokenNames, _ctokens);
|
||||
_addCtokenMapping(_ctokenNames, _tokens, _ctokens);
|
||||
}
|
||||
}
|
|
@ -19,10 +19,24 @@ async function main() {
|
|||
"ZRX-A": "0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407"
|
||||
}
|
||||
|
||||
const tokenMapping = {
|
||||
"ETH-A": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
"BAT-A": "0x0D8775F648430679A709E98d2b0Cb6250d2887EF",
|
||||
"COMP-A": "0xc00e94cb662c3520282e6f5717214004a7f26888",
|
||||
"DAI-A": "0x6b175474e89094c44da98b954eedeac495271d0f",
|
||||
"REP-A": "0x1985365e9f78359a9B6AD760e32412f4a445E862",
|
||||
"UNI-A": "0x221657776846890989a759ba2973e427dff5c9bb",
|
||||
"USDC-A": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
||||
"USDT-A": "0xdac17f958d2ee523a2206206994597c13d831ec7",
|
||||
"WBTC-A": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
||||
"ZRX-A": "0xe41d2489571d322189246dafa5ebde1f4699f498"
|
||||
}
|
||||
|
||||
const Mapping = await ethers.getContractFactory("InstaCompoundMapping");
|
||||
const mapping = await Mapping.deploy(
|
||||
CONNECTORS_V2,
|
||||
Object.keys(ctokenMapping),
|
||||
Object.values(tokenMapping),
|
||||
Object.values(ctokenMapping)
|
||||
);
|
||||
await mapping.deployed();
|
||||
|
@ -35,6 +49,7 @@ async function main() {
|
|||
constructorArguments: [
|
||||
CONNECTORS_V2,
|
||||
Object.keys(ctokenMapping),
|
||||
Object.values(tokenMapping),
|
||||
Object.values(ctokenMapping)
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user