dsa-connectors/contracts/mainnet/connectors/COMP/helpers.sol

53 lines
1.9 KiB
Solidity
Raw Normal View History

2021-02-07 15:31:36 +00:00
pragma solidity ^0.7.0;
2021-04-21 16:07:57 +00:00
pragma experimental ABIEncoderV2;
2021-02-05 17:07:07 +00:00
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
2021-04-21 16:07:57 +00:00
import { ComptrollerInterface, COMPInterface, CompoundMappingInterface } from "./interface.sol";
2021-02-05 17:07:07 +00:00
2021-02-05 18:33:49 +00:00
abstract contract Helpers is DSMath, Basic {
2021-02-05 17:07:07 +00:00
/**
2021-02-08 15:27:45 +00:00
* @dev Compound Comptroller
2021-02-05 17:07:07 +00:00
*/
2021-02-08 15:27:45 +00:00
ComptrollerInterface internal constant troller = ComptrollerInterface(0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B);
2021-02-05 17:07:07 +00:00
/**
2021-02-08 15:27:45 +00:00
* @dev COMP Token
2021-02-05 17:07:07 +00:00
*/
2021-02-08 15:27:45 +00:00
COMPInterface internal constant compToken = COMPInterface(0xc00e94Cb662C3520282E6f5717214004A7f26888);
2021-02-05 17:07:07 +00:00
2021-04-21 16:07:57 +00:00
/**
* @dev Compound Mapping
*/
CompoundMappingInterface internal constant compMapping = CompoundMappingInterface(0xA8F9D4aA7319C54C04404765117ddBf9448E2082);
function getMergedCTokens(
2021-04-22 00:42:08 +00:00
string[] calldata supplyIds,
string[] calldata borrowIds
2021-04-21 16:07:57 +00:00
) internal view returns (address[] memory ctokens, bool isBorrow, bool isSupply) {
uint _supplyLen = supplyIds.length;
uint _borrowLen = borrowIds.length;
2021-02-05 17:07:07 +00:00
uint _totalLen = add(_supplyLen, _borrowLen);
ctokens = new address[](_totalLen);
2021-04-21 16:07:57 +00:00
2021-02-05 17:07:07 +00:00
if(_supplyLen > 0) {
2021-04-21 16:07:57 +00:00
isSupply = true;
2021-02-05 17:07:07 +00:00
for (uint i = 0; i < _supplyLen; i++) {
2021-04-21 16:07:57 +00:00
(address token, address cToken) = compMapping.getMapping(supplyIds[i]);
require(token != address(0) && cToken != address(0), "invalid token/ctoken address");
ctokens[i] = cToken;
2021-02-05 17:07:07 +00:00
}
}
if(_borrowLen > 0) {
2021-04-21 16:07:57 +00:00
isBorrow = true;
2021-02-05 17:07:07 +00:00
for (uint i = 0; i < _borrowLen; i++) {
2021-04-22 00:30:26 +00:00
(address token, address cToken) = compMapping.getMapping(borrowIds[i]);
2021-04-21 16:07:57 +00:00
require(token != address(0) && cToken != address(0), "invalid token/ctoken address");
ctokens[_supplyLen + i] = cToken;
2021-02-05 17:07:07 +00:00
}
}
}
}