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

104 lines
3.8 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
/**
* @title COMP.
* @dev Claim COMP.
*/
2021-02-08 13:58:28 +00:00
import { TokenInterface } from "../../common/interfaces.sol";
2021-02-05 18:33:49 +00:00
import { Stores } from "../../common/stores.sol";
2021-02-05 17:07:07 +00:00
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
2021-02-05 18:33:49 +00:00
abstract contract CompResolver is Events, Helpers {
2021-02-05 17:07:07 +00:00
/**
* @dev Claim Accrued COMP Token.
2021-03-24 12:23:36 +00:00
* @notice Claim Accrued COMP Token.
* @param setId ID stores the amount of COMP claimed.
2021-02-05 17:07:07 +00:00
*/
2021-03-20 19:55:57 +00:00
function ClaimComp(uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-02-08 15:27:45 +00:00
TokenInterface _compToken = TokenInterface(address(compToken));
uint intialBal = _compToken.balanceOf(address(this));
troller.claimComp(address(this));
uint finalBal = _compToken.balanceOf(address(this));
2021-02-05 17:07:07 +00:00
uint amt = sub(finalBal, intialBal);
setUint(setId, amt);
2021-02-08 13:58:28 +00:00
_eventName = "LogClaimedComp(uint256,uint256)";
2021-02-07 18:18:38 +00:00
_eventParam = abi.encode(amt, setId);
2021-02-05 17:07:07 +00:00
}
/**
* @dev Claim Accrued COMP Token.
2021-03-24 12:23:36 +00:00
* @notice Claim Accrued COMP Token.
2021-04-21 16:07:57 +00:00
* @param tokenIds Array of supplied and borrowed token IDs.
2021-03-24 12:23:36 +00:00
* @param setId ID stores the amount of COMP claimed.
2021-02-05 17:07:07 +00:00
*/
2021-04-21 16:07:57 +00:00
function ClaimCompTwo(string[] calldata tokenIds, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _len = tokenIds.length;
2021-02-05 17:07:07 +00:00
address[] memory ctokens = new address[](_len);
for (uint i = 0; i < _len; i++) {
2021-04-21 16:07:57 +00:00
(address token, address cToken) = compMapping.getMapping(tokenIds[i]);
require(token != address(0) && cToken != address(0), "invalid token/ctoken address");
ctokens[i] = cToken;
2021-02-05 17:07:07 +00:00
}
2021-02-08 15:27:45 +00:00
TokenInterface _compToken = TokenInterface(address(compToken));
uint intialBal = _compToken.balanceOf(address(this));
troller.claimComp(address(this), ctokens);
uint finalBal = _compToken.balanceOf(address(this));
2021-02-05 17:07:07 +00:00
uint amt = sub(finalBal, intialBal);
setUint(setId, amt);
2021-02-08 13:58:28 +00:00
_eventName = "LogClaimedComp(uint256,uint256)";
2021-02-07 18:18:38 +00:00
_eventParam = abi.encode(amt, setId);
2021-02-05 17:07:07 +00:00
}
/**
* @dev Claim Accrued COMP Token.
2021-03-24 12:23:36 +00:00
* @notice Claim Accrued COMP Token.
2021-04-21 16:07:57 +00:00
* @param supplyTokenIds Array of supplied tokenIds.
* @param borrowTokenIds Array of borrowed tokenIds.
2021-03-24 12:23:36 +00:00
* @param setId ID stores the amount of COMP claimed.
2021-02-05 17:07:07 +00:00
*/
2021-04-21 16:07:57 +00:00
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);
2021-02-05 17:07:07 +00:00
address[] memory holders = new address[](1);
holders[0] = address(this);
2021-02-08 15:27:45 +00:00
TokenInterface _compToken = TokenInterface(address(compToken));
uint intialBal = _compToken.balanceOf(address(this));
troller.claimComp(holders, ctokens, isBorrow, isSupply);
uint finalBal = _compToken.balanceOf(address(this));
2021-02-05 17:07:07 +00:00
uint amt = sub(finalBal, intialBal);
setUint(setId, amt);
2021-02-08 13:58:28 +00:00
_eventName = "LogClaimedComp(uint256,uint256)";
2021-02-07 18:18:38 +00:00
_eventParam = abi.encode(amt, setId);
2021-02-05 17:07:07 +00:00
}
/**
* @dev Delegate votes.
2021-03-24 12:23:36 +00:00
* @notice Delegate votes.
* @param delegatee The address to delegate the votes to.
2021-02-05 17:07:07 +00:00
*/
2021-02-07 18:18:38 +00:00
function delegate(address delegatee) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-02-05 17:07:07 +00:00
require(compToken.delegates(address(this)) != delegatee, "Already delegated to same delegatee.");
compToken.delegate(delegatee);
2021-02-08 13:58:28 +00:00
_eventName = "LogDelegate(address)";
_eventParam = abi.encode(delegatee);
2021-02-05 17:07:07 +00:00
}
}
2021-03-15 12:26:22 +00:00
contract ConnectV2COMP is CompResolver {
2021-03-20 19:55:57 +00:00
string public constant name = "COMP-v1";
2021-02-05 17:07:07 +00:00
}