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

94 lines
3.7 KiB
Solidity
Raw Normal View History

2021-02-07 15:31:36 +00:00
pragma solidity ^0.7.0;
2021-02-05 17:07:07 +00:00
2021-02-07 16:40:28 +00:00
import { TokenInterface , MemoryInterface, InstaMapping } 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 { ComptrollerInterface, COMPInterface } from "./interface.sol";
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.
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
*/
2021-02-07 18:18:38 +00:00
function ClaimComp(uint setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-02-05 17:07:07 +00:00
TokenInterface compToken = TokenInterface(getCompTokenAddress());
uint intialBal = compToken.balanceOf(address(this));
ComptrollerInterface(getComptrollerAddress()).claimComp(address(this));
uint finalBal = compToken.balanceOf(address(this));
uint amt = sub(finalBal, intialBal);
setUint(setId, amt);
2021-02-07 18:18:38 +00:00
eventName = "LogClaimedComp(uint256,uint256)";
_eventParam = abi.encode(amt, setId);
2021-02-05 17:07:07 +00:00
}
/**
* @dev Claim Accrued COMP Token.
* @param tokens Array of tokens supplied and borrowed.
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
*/
2021-02-07 18:18:38 +00:00
function ClaimCompTwo(address[] calldata tokens, uint setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-02-05 17:07:07 +00:00
uint _len = tokens.length;
address[] memory ctokens = new address[](_len);
for (uint i = 0; i < _len; i++) {
ctokens[i] = InstaMapping(getMappingAddr()).cTokenMapping(tokens[i]);
}
TokenInterface compToken = TokenInterface(getCompTokenAddress());
uint intialBal = compToken.balanceOf(address(this));
ComptrollerInterface(getComptrollerAddress()).claimComp(address(this), ctokens);
uint finalBal = compToken.balanceOf(address(this));
uint amt = sub(finalBal, intialBal);
setUint(setId, amt);
2021-02-07 18:18:38 +00:00
eventName = "LogClaimedComp(uint256,uint256)";
_eventParam = abi.encode(amt, setId);
2021-02-05 17:07:07 +00:00
}
/**
* @dev Claim Accrued COMP Token.
* @param supplyTokens Array of tokens supplied.
* @param borrowTokens Array of tokens borrowed.
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
*/
2021-02-07 18:18:38 +00:00
function ClaimCompThree(address[] calldata supplyTokens, address[] calldata borrowTokens, uint setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-02-05 17:07:07 +00:00
(address[] memory ctokens, bool isBorrow, bool isSupply) = mergeTokenArr(supplyTokens, borrowTokens);
address[] memory holders = new address[](1);
holders[0] = address(this);
TokenInterface compToken = TokenInterface(getCompTokenAddress());
uint intialBal = compToken.balanceOf(address(this));
ComptrollerInterface(getComptrollerAddress()).claimComp(holders, ctokens, isBorrow, isSupply);
uint finalBal = compToken.balanceOf(address(this));
uint amt = sub(finalBal, intialBal);
setUint(setId, amt);
2021-02-07 18:18:38 +00:00
eventName = "LogClaimedComp(uint256,uint256)";
_eventParam = abi.encode(amt, setId);
2021-02-05 17:07:07 +00:00
}
/**
* @dev Delegate votes.
* @param delegatee The address to delegate votes to.
*/
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
COMPInterface compToken = COMPInterface(getCompTokenAddress());
require(compToken.delegates(address(this)) != delegatee, "Already delegated to same delegatee.");
compToken.delegate(delegatee);
2021-02-07 18:18:38 +00:00
eventName = "LogClaimedComp(uint256,uint256)";
_eventParam = abi.encode(amt, setId);
2021-02-05 17:07:07 +00:00
}
}
contract ConnectCOMP is CompResolver {
string public name = "COMP-v1";
}