Breakdown COMP connector

This commit is contained in:
Mubaris NK 2021-02-05 22:37:07 +05:30
parent 7029fbd0c1
commit 1e69cb14b8
No known key found for this signature in database
GPG Key ID: 9AC09AD0F8D68561
8 changed files with 187 additions and 7 deletions

View File

@ -19,6 +19,10 @@ interface EventInterface {
function emitEvent(uint connectorType, uint connectorID, bytes32 eventCode, bytes calldata eventData) external;
}
interface InstaMapping {
function cTokenMapping(address) external view returns (address);
}
struct OneProtoData {
TokenInterface sellToken;
TokenInterface buyToken;

View File

@ -26,6 +26,13 @@ contract Stores {
return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; // InstaEvent Address
}
/**
* @dev Return InstaDApp Mapping Addresses
*/
function getMappingAddr() internal pure returns (address) {
return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; // InstaMapping Address
}
/**
* @dev Get Uint value from InstaMemory Contract.
*/

View File

@ -0,0 +1,8 @@
pragma solidity ^0.6.0;
import { Stores } from "../../common/stores.sol";
contract Events is Stores {
event LogClaimedComp(uint256 compAmt, uint256 setId);
event LogDelegate(address delegatee);
}

View File

@ -0,0 +1,47 @@
pragma solidity ^0.6.0;
import { InstaMapping } from "../../common/interfaces.sol";
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
contract Helpers is DSMath, Basic {
/**
* @dev Return Compound Comptroller Address
*/
function getComptrollerAddress() internal pure returns (address) {
return 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B;
}
/**
* @dev Return COMP Token Address.
*/
function getCompTokenAddress() internal pure returns (address) {
return 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;
uint _totalLen = add(_supplyLen, _borrowLen);
ctokens = new address[](_totalLen);
isBorrow;
isSupply;
if(_supplyLen > 0) {
for (uint i = 0; i < _supplyLen; i++) {
ctokens[i] = InstaMapping(getMappingAddr()).cTokenMapping(supplyTokens[i]);
}
isSupply = true;
}
if(_borrowLen > 0) {
for (uint i = 0; i < _borrowLen; i++) {
ctokens[_supplyLen + i] = InstaMapping(getMappingAddr()).cTokenMapping(borrowTokens[i]);
}
isBorrow = true;
}
}
}

View File

@ -0,0 +1,12 @@
pragma solidity ^0.6.0;
interface ComptrollerInterface {
function claimComp(address holder) external;
function claimComp(address holder, address[] calldata) external;
function claimComp(address[] calldata holders, address[] calldata cTokens, bool borrowers, bool suppliers) external;
}
interface COMPInterface {
function delegate(address delegatee) external;
function delegates(address) external view returns(address);
}

View File

@ -0,0 +1,104 @@
pragma solidity ^0.6.0;
import { TokenInterface , MemoryInterface, EventInterface, InstaMapping } from "../../common/interfaces.sol";
import { ComptrollerInterface, COMPInterface } from "./interface.sol";
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
contract CompResolver is Events, Helpers {
/**
* @dev Claim Accrued COMP Token.
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
*/
function ClaimComp(uint setId) external payable {
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);
emit LogClaimedComp(amt, setId);
bytes32 _eventCode = keccak256("LogClaimedComp(uint256,uint256)");
bytes memory _eventParam = abi.encode(amt, setId);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
/**
* @dev Claim Accrued COMP Token.
* @param tokens Array of tokens supplied and borrowed.
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
*/
function ClaimCompTwo(address[] calldata tokens, uint setId) external payable {
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);
emit LogClaimedComp(amt, setId);
bytes32 _eventCode = keccak256("LogClaimedComp(uint256,uint256)");
bytes memory _eventParam = abi.encode(amt, setId);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
/**
* @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.
*/
function ClaimCompThree(address[] calldata supplyTokens, address[] calldata borrowTokens, uint setId) external payable {
(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);
emit LogClaimedComp(amt, setId);
bytes32 _eventCode = keccak256("LogClaimedComp(uint256,uint256)");
bytes memory _eventParam = abi.encode(amt, setId);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
/**
* @dev Delegate votes.
* @param delegatee The address to delegate votes to.
*/
function delegate(address delegatee) external payable {
COMPInterface compToken = COMPInterface(getCompTokenAddress());
require(compToken.delegates(address(this)) != delegatee, "Already delegated to same delegatee.");
compToken.delegate(delegatee);
emit LogDelegate(delegatee);
bytes32 _eventCode = keccak256("LogDelegate(address)");
bytes memory _eventParam = abi.encode(delegatee);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
}
contract ConnectCOMP is CompResolver {
string public name = "COMP-v1";
}

View File

@ -26,13 +26,6 @@ interface SynthetixMapping {
}
contract StakingHelper is DSMath, Stores {
/**
* @dev Return InstaDApp Staking Mapping Addresses
*/
function getMappingAddr() internal virtual view returns (address) {
return 0x772590F33eD05b0E83553650BF9e75A04b337526; // InstaMapping Address
}
/**
* @dev Convert String to bytes32.
*/

View File

@ -19,6 +19,11 @@ module.exports = {
]
},
networks: {
mainnet: {
url: process.env.ETH_NODE_URL,
chainId: 1,
timeout: 500000,
},
tenderlyMainnet: {
url: 'https://mainnet.tenderly.co',
accounts: [process.env.PRIVATE_KEY],