From b8042a54c607be625fca86bc0fbbc53c896e6ef5 Mon Sep 17 00:00:00 2001 From: Mubaris NK Date: Wed, 21 Apr 2021 21:37:57 +0530 Subject: [PATCH] Update COMP connector with new mapping --- contracts/mainnet/connectors/COMP/helpers.sol | 42 ++++++++++++------- .../mainnet/connectors/COMP/interface.sol | 5 +++ contracts/mainnet/connectors/COMP/main.sol | 20 +++++---- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/contracts/mainnet/connectors/COMP/helpers.sol b/contracts/mainnet/connectors/COMP/helpers.sol index 8536099a..43aaddbb 100644 --- a/contracts/mainnet/connectors/COMP/helpers.sol +++ b/contracts/mainnet/connectors/COMP/helpers.sol @@ -1,8 +1,9 @@ pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; import { DSMath } from "../../common/math.sol"; import { Basic } from "../../common/basic.sol"; -import { ComptrollerInterface, COMPInterface } from "./interface.sol"; +import { ComptrollerInterface, COMPInterface, CompoundMappingInterface } from "./interface.sol"; abstract contract Helpers is DSMath, Basic { /** @@ -15,29 +16,38 @@ abstract contract Helpers is DSMath, Basic { */ COMPInterface internal constant compToken = COMPInterface(0xc00e94Cb662C3520282E6f5717214004A7f26888); - function mergeTokenArr(address[] memory supplyTokens, address[] memory borrowTokens) - internal - view - returns (address[] memory ctokens, bool isBorrow, bool isSupply) - { - uint _supplyLen = supplyTokens.length; - uint _borrowLen = borrowTokens.length; + /** + * @dev Compound Mapping + */ + CompoundMappingInterface internal constant compMapping = CompoundMappingInterface(0xA8F9D4aA7319C54C04404765117ddBf9448E2082); + + function getMergedCTokens( + string[] memory supplyIds, + string[] memory borrowIds + ) internal view returns (address[] memory ctokens, bool isBorrow, bool isSupply) { + uint _supplyLen = supplyIds.length; + uint _borrowLen = borrowIds.length; uint _totalLen = add(_supplyLen, _borrowLen); ctokens = new address[](_totalLen); - isBorrow; - isSupply; + if(_supplyLen > 0) { - for (uint i = 0; i < _supplyLen; i++) { - ctokens[i] = instaMapping.cTokenMapping(supplyTokens[i]); - } isSupply = true; + for (uint i = 0; i < _supplyLen; i++) { + (address token, address cToken) = compMapping.getMapping(supplyIds[i]); + require(token != address(0) && cToken != address(0), "invalid token/ctoken address"); + + ctokens[i] = cToken; + } } if(_borrowLen > 0) { - for (uint i = 0; i < _borrowLen; i++) { - ctokens[_supplyLen + i] = instaMapping.cTokenMapping(borrowTokens[i]); - } isBorrow = true; + for (uint i = 0; i < _borrowLen; i++) { + (address token, address cToken) = compMapping.getMapping(supplyIds[i]); + require(token != address(0) && cToken != address(0), "invalid token/ctoken address"); + + ctokens[_supplyLen + i] = cToken; + } } } } \ No newline at end of file diff --git a/contracts/mainnet/connectors/COMP/interface.sol b/contracts/mainnet/connectors/COMP/interface.sol index a1fb9a80..72ea3ebb 100644 --- a/contracts/mainnet/connectors/COMP/interface.sol +++ b/contracts/mainnet/connectors/COMP/interface.sol @@ -10,3 +10,8 @@ interface COMPInterface { function delegate(address delegatee) external; function delegates(address) external view returns(address); } + +interface CompoundMappingInterface { + function cTokenMapping(string calldata tokenId) external view returns (address); + function getMapping(string calldata tokenId) external view returns (address, address); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/COMP/main.sol b/contracts/mainnet/connectors/COMP/main.sol index e2c74806..14d316ee 100644 --- a/contracts/mainnet/connectors/COMP/main.sol +++ b/contracts/mainnet/connectors/COMP/main.sol @@ -1,4 +1,5 @@ pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; import { TokenInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; @@ -28,14 +29,17 @@ abstract contract CompResolver is Events, Helpers { /** * @dev Claim Accrued COMP Token. * @notice Claim Accrued COMP Token. - * @param tokens Array of tokens supplied and borrowed. + * @param tokenIds Array of supplied and borrowed token IDs. * @param setId ID stores the amount of COMP claimed. */ - function ClaimCompTwo(address[] calldata tokens, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _len = tokens.length; + function ClaimCompTwo(string[] calldata tokenIds, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) { + uint _len = tokenIds.length; address[] memory ctokens = new address[](_len); for (uint i = 0; i < _len; i++) { - ctokens[i] = instaMapping.cTokenMapping(tokens[i]); + (address token, address cToken) = compMapping.getMapping(tokenIds[i]); + require(token != address(0) && cToken != address(0), "invalid token/ctoken address"); + + ctokens[i] = cToken; } TokenInterface _compToken = TokenInterface(address(compToken)); @@ -53,12 +57,12 @@ abstract contract CompResolver is Events, Helpers { /** * @dev Claim Accrued COMP Token. * @notice Claim Accrued COMP Token. - * @param supplyTokens Array of tokens supplied. - * @param borrowTokens Array of tokens borrowed. + * @param supplyTokenIds Array of supplied tokenIds. + * @param borrowTokenIds Array of borrowed tokenIds. * @param setId ID stores the amount of COMP claimed. */ - function ClaimCompThree(address[] calldata supplyTokens, address[] calldata borrowTokens, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) { - (address[] memory ctokens, bool isBorrow, bool isSupply) = mergeTokenArr(supplyTokens, borrowTokens); + function ClaimCompThree(string[] calldata supplyTokenIds, string[] calldata borrowTokenIds, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) { + (address[] memory ctokens, bool isBorrow, bool isSupply) = getMergedCTokens(supplyTokenIds, borrowTokenIds); address[] memory holders = new address[](1); holders[0] = address(this);