updated new event emitting in comp.sol

This commit is contained in:
Samyak Jain 2021-02-07 21:01:36 +05:30
parent 279452e845
commit e392dd6262
7 changed files with 50 additions and 96 deletions

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.5;
pragma solidity ^0.7.0;
import { TokenInterface } from "./interfaces.sol";
import { Stores } from "./stores.sol";
@ -23,4 +23,8 @@ abstract contract Basic is DSMath, Stores {
sellDec = address(sellAddr) == getEthAddr() ? 18 : sellAddr.decimals();
}
function encodeEvent(string eventName, bytes eventParam) internal pure returns (bytes memory) {
return abi.encode(eventName, eventParam);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.5;
pragma solidity ^0.7.0;
interface TokenInterface {
function approve(address, uint256) external;
@ -15,40 +15,6 @@ interface MemoryInterface {
function setUint(uint id, uint val) external;
}
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;
uint _sellAmt;
uint _buyAmt;
uint unitAmt;
uint[] distribution;
uint disableDexes;
}
struct OneProtoMultiData {
address[] tokens;
TokenInterface sellToken;
TokenInterface buyToken;
uint _sellAmt;
uint _buyAmt;
uint unitAmt;
uint[] distribution;
uint[] disableDexes;
}
struct OneInchData {
TokenInterface sellToken;
TokenInterface buyToken;
uint _sellAmt;
uint _buyAmt;
uint unitAmt;
bytes callData;
}

View File

@ -1,16 +1,10 @@
pragma solidity ^0.6.5;
pragma solidity ^0.7.0;
import { MemoryInterface, EventInterface} from "./interfaces.sol";
import { MemoryInterface } from "./interfaces.sol";
abstract contract Stores {
uint256 internal immutable _id;
constructor(uint256 id) public {
_id = id;
}
/**
* @dev Return ethereum address
*/
@ -25,13 +19,6 @@ abstract contract Stores {
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
}
/**
* @dev Return InstaEvent Address.
*/
function getEventAddr() internal pure returns (address) {
return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; // InstaEvent Address
}
/**
* @dev Return InstaDApp Mapping Addresses
*/
@ -53,19 +40,4 @@ abstract contract Stores {
if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val);
}
/**
* @dev emit event on event contract
*/
function emitEvent(bytes32 eventCode, bytes memory eventData) virtual internal {
(uint model, uint id) = connectorID();
EventInterface(getEventAddr()).emitEvent(model, id, eventCode, eventData);
}
/**
* @dev Connector Details - needs to be changed before deployment
*/
function connectorID() public view returns(uint model, uint id) {
(model, id) = (0, _id);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.5;
pragma solidity ^0.7.0;
import { TokenInterface } from "../../common/interfaces.sol";
@ -55,4 +55,34 @@ interface OneProtoInterface {
interface OneProtoMappingInterface {
function oneProtoAddress() external view returns(address);
}
struct OneProtoData {
TokenInterface sellToken;
TokenInterface buyToken;
uint _sellAmt;
uint _buyAmt;
uint unitAmt;
uint[] distribution;
uint disableDexes;
}
struct OneProtoMultiData {
address[] tokens;
TokenInterface sellToken;
TokenInterface buyToken;
uint _sellAmt;
uint _buyAmt;
uint unitAmt;
uint[] distribution;
uint[] disableDexes;
}
struct OneInchData {
TokenInterface sellToken;
TokenInterface buyToken;
uint _sellAmt;
uint _buyAmt;
uint unitAmt;
bytes callData;
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.5;
pragma solidity ^0.7.0;
import { InstaMapping } from "../../common/interfaces.sol";
import { DSMath } from "../../common/math.sol";

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.5;
pragma solidity ^0.7.0;
import { TokenInterface , MemoryInterface, EventInterface, InstaMapping } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
@ -12,7 +12,7 @@ abstract 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 {
function ClaimComp(uint setId) external payable returns (bytes calldata) {
TokenInterface compToken = TokenInterface(getCompTokenAddress());
uint intialBal = compToken.balanceOf(address(this));
ComptrollerInterface(getComptrollerAddress()).claimComp(address(this));
@ -21,11 +21,7 @@ abstract contract CompResolver is Events, Helpers {
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);
return encodeEvent("LogClaimedComp(uint256,uint256)", abi.encode(amt, setId));
}
/**
@ -33,7 +29,7 @@ abstract contract CompResolver is Events, Helpers {
* @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 {
function ClaimCompTwo(address[] calldata tokens, uint setId) external payable returns (bytes calldata) {
uint _len = tokens.length;
address[] memory ctokens = new address[](_len);
for (uint i = 0; i < _len; i++) {
@ -48,11 +44,7 @@ abstract contract CompResolver is Events, Helpers {
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);
return encodeEvent("LogClaimedComp(uint256,uint256)", abi.encode(amt, setId));
}
/**
@ -61,7 +53,7 @@ abstract contract CompResolver is Events, Helpers {
* @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 {
function ClaimCompThree(address[] calldata supplyTokens, address[] calldata borrowTokens, uint setId) external payable returns (bytes calldata) {
(address[] memory ctokens, bool isBorrow, bool isSupply) = mergeTokenArr(supplyTokens, borrowTokens);
address[] memory holders = new address[](1);
@ -75,33 +67,23 @@ abstract contract CompResolver is Events, Helpers {
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);
return encodeEvent("LogClaimedComp(uint256,uint256)", abi.encode(amt, setId));
}
/**
* @dev Delegate votes.
* @param delegatee The address to delegate votes to.
*/
function delegate(address delegatee) external payable {
function delegate(address delegatee) external payable returns (bytes calldata) {
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);
return encodeEvent("LogDelegate(address)", abi.encode(delegatee));
}
}
contract ConnectCOMP is CompResolver {
string public name = "COMP-v1";
constructor(uint256 _id) Stores(_id) public {}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.0;
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
// import files from common directory