Update COMP connector with new mapping

This commit is contained in:
Mubaris NK 2021-04-21 21:37:57 +05:30
parent 53e92dbac3
commit b8042a54c6
No known key found for this signature in database
GPG Key ID: 9AC09AD0F8D68561
3 changed files with 43 additions and 24 deletions

View File

@ -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;
}
}
}
}

View File

@ -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);
}

View File

@ -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);