From 9693f5ffb2a6047439e4d46f2f819e90ec94ca7a Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Fri, 16 Apr 2021 21:30:33 +0530 Subject: [PATCH] Update Polygon Token mapping contract --- contracts/receivers/mapping/main.sol | 62 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/contracts/receivers/mapping/main.sol b/contracts/receivers/mapping/main.sol index 8ebabc4..af11e8a 100644 --- a/contracts/receivers/mapping/main.sol +++ b/contracts/receivers/mapping/main.sol @@ -5,42 +5,47 @@ 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); - function underlying() external view returns (address); -} - abstract contract Helpers { - // struct TokenMap { - // address ctoken; - // address token; - // } - - // event LogCTokenAdded(string indexed name, address indexed token, address indexed ctoken); - // event LogCTokenUpdated(string indexed name, address indexed token, address indexed ctoken); - - // ConnectorsInterface public immutable connectors; + event LogTokenMapAdded(address indexed L1_token, address indexed L2_token); + event LogTokenMapUpdated(address indexed L1_token, address indexed L2_token_new, address indexed L2_token_old); // InstaIndex Address. - IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723); + IndexInterface public constant instaIndex = IndexInterface(0xA9B99766E6C676Cf1975c0D3166F96C0848fF5ad); address public constant ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; mapping (address => address) public tokenMapping; - // modifier isChief { - // require(msg.sender == instaIndex.master() || connectors.chief(msg.sender), "not-an-chief"); - // _; - // } + modifier isMaster { + require(msg.sender == instaIndex.master(), "not-a-master"); + _; + } - // constructor(address _connectors) { - // connectors = ConnectorsInterface(_connectors); - // } + function _addTokenMaps(address[] memory L1, address[] memory L2) internal { + uint len = L1.length; + require(len == L2.length, "addTokenMaps: Length not same"); + for (uint256 i = 0; i < len; i++) { + require(tokenMapping[L1[i]] == address(0), "addTokenMaps: Token map already added"); + tokenMapping[L1[i]] = L2[i]; + emit LogTokenMapAdded(L1[i], L2[i]); + } + } + + function addTokenMaps(address[] memory L1, address[] memory L2) external isMaster { + _addTokenMaps(L1, L2); + } + + function updateTokenMaps(address[] memory L1, address[] memory L2) external isMaster { + uint len = L1.length; + require(len == L2.length, "updateTokenMaps: Length not same"); + for (uint256 i = 0; i < len; i++) { + require(tokenMapping[L1[i]] != address(0), "updateTokenMaps: Token map already added"); + require(tokenMapping[L1[i]] != L2[i], "updateTokenMaps: L1 Token is mapped to same L2 Token"); + emit LogTokenMapUpdated(L1[i], tokenMapping[L1[i]], L2[i]); + tokenMapping[L1[i]] = L2[i]; + } + } function getMapping(address L1Address) external view returns (address) { return tokenMapping[L1Address]; @@ -49,10 +54,7 @@ abstract contract Helpers { } contract InstaPolygonTokenMapping is Helpers { - constructor(address[] memory L1, address[] memory L2) { - for (uint256 i = 0; i < L1.length; i++) { - tokenMapping[L1[i]] = L2[i]; - } + _addTokenMaps(L1, L2); } } \ No newline at end of file