mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Breakdown COMP connector
This commit is contained in:
parent
7029fbd0c1
commit
1e69cb14b8
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
8
contracts/connectors/COMP/events.sol
Normal file
8
contracts/connectors/COMP/events.sol
Normal 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);
|
||||
}
|
47
contracts/connectors/COMP/helpers.sol
Normal file
47
contracts/connectors/COMP/helpers.sol
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
12
contracts/connectors/COMP/interface.sol
Normal file
12
contracts/connectors/COMP/interface.sol
Normal 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);
|
||||
}
|
104
contracts/connectors/COMP/main.sol
Normal file
104
contracts/connectors/COMP/main.sol
Normal 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";
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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],
|
||||
|
|
Loading…
Reference in New Issue
Block a user