mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
commit
7a35ef6d14
|
@ -11,7 +11,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 returns (string memory _eventName, bytes memory _eventParam) {
|
||||
function ClaimComp(uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
TokenInterface _compToken = TokenInterface(address(compToken));
|
||||
uint intialBal = _compToken.balanceOf(address(this));
|
||||
troller.claimComp(address(this));
|
||||
|
@ -29,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 returns (string memory _eventName, bytes memory _eventParam) {
|
||||
function ClaimCompTwo(address[] calldata tokens, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _len = tokens.length;
|
||||
address[] memory ctokens = new address[](_len);
|
||||
for (uint i = 0; i < _len; i++) {
|
||||
|
@ -54,7 +54,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 returns (string memory _eventName, bytes memory _eventParam) {
|
||||
function ClaimCompThree(address[] calldata supplyTokens, address[] calldata borrowTokens, uint256 setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
(address[] memory ctokens, bool isBorrow, bool isSupply) = mergeTokenArr(supplyTokens, borrowTokens);
|
||||
|
||||
address[] memory holders = new address[](1);
|
||||
|
@ -87,5 +87,5 @@ abstract contract CompResolver is Events, Helpers {
|
|||
}
|
||||
|
||||
contract ConnectV2COMP is CompResolver {
|
||||
string public name = "COMP-v1";
|
||||
string public constant name = "COMP-v1";
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function deposit(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
@ -52,9 +52,9 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function withdraw(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
AaveCoreInterface aaveCore = AaveCoreInterface(aaveProvider.getLendingPoolCore());
|
||||
|
@ -81,9 +81,9 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function borrow(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
@ -103,9 +103,9 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function payback(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
@ -155,5 +155,5 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
}
|
||||
|
||||
contract ConnectV2AaveV1 is AaveResolver {
|
||||
string public name = "AaveV1-v1";
|
||||
string constant public name = "AaveV1-v1";
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function deposit(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
|
@ -59,9 +59,9 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function withdraw(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
|
@ -95,10 +95,10 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function borrow(
|
||||
address token,
|
||||
uint amt,
|
||||
uint rateMode,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 rateMode,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
|
@ -126,10 +126,10 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
*/
|
||||
function payback(
|
||||
address token,
|
||||
uint amt,
|
||||
uint rateMode,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 rateMode,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
|
@ -179,5 +179,5 @@ abstract contract AaveResolver is Events, Helpers {
|
|||
}
|
||||
|
||||
contract ConnectV2AaveV2 is AaveResolver {
|
||||
string public name = "AaveV2-v1";
|
||||
string constant public name = "AaveV2-v1";
|
||||
}
|
||||
|
|
|
@ -12,63 +12,63 @@ abstract contract BasicResolver is Events, DSMath, Basic {
|
|||
|
||||
/**
|
||||
* @dev Deposit Assets To Smart Account.
|
||||
* @param erc20 Token Address.
|
||||
* @param tokenAmt Token Amount.
|
||||
* @param token Token Address.
|
||||
* @param amt Token Amount.
|
||||
* @param getId Get Storage ID.
|
||||
* @param setId Set Storage ID.
|
||||
*/
|
||||
function deposit(
|
||||
address erc20,
|
||||
uint tokenAmt,
|
||||
uint getId,
|
||||
uint setId
|
||||
address token,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint amt = getUint(getId, tokenAmt);
|
||||
if (erc20 != ethAddr) {
|
||||
IERC20 token = IERC20(erc20);
|
||||
amt = amt == uint(-1) ? token.balanceOf(msg.sender) : amt;
|
||||
token.safeTransferFrom(msg.sender, address(this), amt);
|
||||
uint _amt = getUint(getId, amt);
|
||||
if (token != ethAddr) {
|
||||
IERC20 tokenContract = IERC20(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(msg.sender) : _amt;
|
||||
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
||||
} else {
|
||||
require(msg.value == amt || amt == uint(-1), "invalid-ether-amount");
|
||||
amt = msg.value;
|
||||
require(msg.value == _amt || _amt == uint(-1), "invalid-ether-amount");
|
||||
_amt = msg.value;
|
||||
}
|
||||
setUint(setId, amt);
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(erc20, amt, getId, setId);
|
||||
_eventParam = abi.encode(token, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw Assets To Smart Account.
|
||||
* @param erc20 Token Address.
|
||||
* @param tokenAmt Token Amount.
|
||||
* @param token Token Address.
|
||||
* @param amt Token Amount.
|
||||
* @param to Withdraw token address.
|
||||
* @param getId Get Storage ID.
|
||||
* @param setId Set Storage ID.
|
||||
*/
|
||||
function withdraw(
|
||||
address erc20,
|
||||
uint tokenAmt,
|
||||
address token,
|
||||
uint amt,
|
||||
address payable to,
|
||||
uint getId,
|
||||
uint setId
|
||||
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint amt = getUint(getId, tokenAmt);
|
||||
if (erc20 == ethAddr) {
|
||||
amt = amt == uint(-1) ? address(this).balance : amt;
|
||||
to.transfer(amt);
|
||||
uint _amt = getUint(getId, amt);
|
||||
if (token == ethAddr) {
|
||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||
to.call{value: _amt}("");
|
||||
} else {
|
||||
IERC20 token = IERC20(erc20);
|
||||
amt = amt == uint(-1) ? token.balanceOf(address(this)) : amt;
|
||||
token.safeTransfer(to, amt);
|
||||
IERC20 tokenContract = IERC20(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.safeTransfer(to, _amt);
|
||||
}
|
||||
setUint(setId, amt);
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogWithdraw(address,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(erc20, amt, to, getId, setId);
|
||||
_eventParam = abi.encode(token, _amt, to, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2Basic is BasicResolver {
|
||||
string public constant name = "Basic-v1";
|
||||
string constant public name = "Basic-v1";
|
||||
}
|
||||
|
|
|
@ -1,13 +1,45 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogWithdraw(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogBorrow(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogPayback(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogDeposit(
|
||||
address indexed token,
|
||||
string tokenId,
|
||||
address cToken,
|
||||
uint256 tokenAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogWithdraw(
|
||||
address indexed token,
|
||||
string tokenId,
|
||||
address cToken,
|
||||
uint256 tokenAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogBorrow(
|
||||
address indexed token,
|
||||
string tokenId,
|
||||
address cToken,
|
||||
uint256 tokenAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogPayback(
|
||||
address indexed token,
|
||||
string tokenId,
|
||||
address cToken,
|
||||
uint256 tokenAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogDepositCToken(
|
||||
address indexed token,
|
||||
string tokenId,
|
||||
address cToken,
|
||||
uint256 tokenAmt,
|
||||
uint256 cTokenAmt,
|
||||
|
@ -17,6 +49,7 @@ contract Events {
|
|||
|
||||
event LogWithdrawCToken(
|
||||
address indexed token,
|
||||
string tokenId,
|
||||
address cToken,
|
||||
uint256 tokenAmt,
|
||||
uint256 cTokenAmt,
|
||||
|
|
|
@ -2,7 +2,7 @@ pragma solidity ^0.7.0;
|
|||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { ComptrollerInterface } from "./interface.sol";
|
||||
import { ComptrollerInterface, CompoundMappingInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
/**
|
||||
|
@ -10,6 +10,11 @@ abstract contract Helpers is DSMath, Basic {
|
|||
*/
|
||||
ComptrollerInterface internal constant troller = ComptrollerInterface(0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B);
|
||||
|
||||
/**
|
||||
* @dev Compound Mapping
|
||||
*/
|
||||
CompoundMappingInterface internal constant compMapping = CompoundMappingInterface(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88); // Update the address
|
||||
|
||||
/**
|
||||
* @dev enter compound market
|
||||
*/
|
||||
|
|
|
@ -29,3 +29,16 @@ interface ComptrollerInterface {
|
|||
function getAccountLiquidity(address account) external view returns (uint, uint, uint);
|
||||
function claimComp(address) external;
|
||||
}
|
||||
|
||||
interface CompoundMappingInterface {
|
||||
function cTokenMapping(string calldata tokenId) external view returns (address);
|
||||
function getMapping(string calldata tokenId) external view returns (address, address);
|
||||
}
|
||||
|
||||
struct LiquidateData {
|
||||
address tokenToPay;
|
||||
address tokenInReturn;
|
||||
address cTokenPay;
|
||||
address cTokenColl;
|
||||
CTokenInterface cTokenContract;
|
||||
}
|
|
@ -1,27 +1,31 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
import { CETHInterface, CTokenInterface } from "./interface.sol";
|
||||
import { CETHInterface, CTokenInterface, LiquidateData } from "./interface.sol";
|
||||
|
||||
abstract contract CompoundResolver is Events, Helpers {
|
||||
/**
|
||||
* @dev Deposit ETH/ERC20_Token.
|
||||
* @param token token address to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenId token id of the token to deposit.(For eg: ETH-A)
|
||||
* @param amt token amount to deposit.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function deposit(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
string calldata tokenId,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
address cToken = instaMapping.cTokenMapping(token);
|
||||
|
||||
(address token, address cToken) = compMapping.getMapping(tokenId);
|
||||
require(token != address(0) && cToken != address(0), "ctoken mapping not found");
|
||||
|
||||
enterMarket(cToken);
|
||||
if (token == ethAddr) {
|
||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||
|
@ -34,25 +38,28 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
}
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogDeposit(address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
_eventName = "LogDeposit(address,string,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, tokenId, cToken, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw ETH/ERC20_Token.
|
||||
* @param token token address to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenId token id of the token to withdraw.(For eg: ETH-A)
|
||||
* @param amt token amount to withdraw.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function withdraw(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
string calldata tokenId,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
address cToken = instaMapping.cTokenMapping(token);
|
||||
|
||||
(address token, address cToken) = compMapping.getMapping(tokenId);
|
||||
require(token != address(0) && cToken != address(0), "ctoken mapping not found");
|
||||
|
||||
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
||||
if (_amt == uint(-1)) {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
|
@ -65,48 +72,52 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
}
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogWithdraw(address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
_eventName = "LogWithdraw(address,string,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, tokenId, cToken, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Borrow ETH/ERC20_Token.
|
||||
* @param token token address to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenId token id of the token to borrow.(For eg: DAI-A)
|
||||
* @param amt token amount to borrow.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function borrow(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
string calldata tokenId,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
address cToken = instaMapping.cTokenMapping(token);
|
||||
(address token, address cToken) = compMapping.getMapping(tokenId);
|
||||
require(token != address(0) && cToken != address(0), "ctoken mapping not found");
|
||||
|
||||
enterMarket(cToken);
|
||||
require(CTokenInterface(cToken).borrow(_amt) == 0, "borrow-failed");
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogBorrow(address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
_eventName = "LogBorrow(address,string,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, tokenId, cToken, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Payback borrowed ETH/ERC20_Token.
|
||||
* @param token token address to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenId token id of the token to payback.(For eg: COMP-A)
|
||||
* @param amt token amount to payback.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function payback(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
string calldata tokenId,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
address cToken = instaMapping.cTokenMapping(token);
|
||||
(address token, address cToken) = compMapping.getMapping(tokenId);
|
||||
require(token != address(0) && cToken != address(0), "ctoken mapping not found");
|
||||
|
||||
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
||||
_amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(address(this)) : _amt;
|
||||
|
||||
|
@ -121,25 +132,27 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
}
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogPayback(address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
_eventName = "LogPayback(address,string,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, tokenId, cToken, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Deposit ETH/ERC20_Token.
|
||||
* @param token token address to depositCToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenId token id of the token to depositCToken.(For eg: DAI-A)
|
||||
* @param amt token amount to depositCToken.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function depositCToken(
|
||||
address token,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
string calldata tokenId,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
address cToken = instaMapping.cTokenMapping(token);
|
||||
(address token, address cToken) = compMapping.getMapping(tokenId);
|
||||
require(token != address(0) && cToken != address(0), "ctoken mapping not found");
|
||||
|
||||
enterMarket(cToken);
|
||||
|
||||
CTokenInterface ctokenContract = CTokenInterface(cToken);
|
||||
|
@ -155,89 +168,102 @@ abstract contract CompoundResolver is Events, Helpers {
|
|||
require(ctokenContract.mint(_amt) == 0, "deposit-ctoken-failed.");
|
||||
}
|
||||
|
||||
uint finalBal = ctokenContract.balanceOf(address(this));
|
||||
uint _cAmt = finalBal - initialBal;
|
||||
setUint(setId, _cAmt);
|
||||
uint _cAmt;
|
||||
|
||||
_eventName = "LogDepositCToken(address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, cToken, _amt, _cAmt, getId, setId);
|
||||
{
|
||||
uint finalBal = ctokenContract.balanceOf(address(this));
|
||||
finalBal - initialBal;
|
||||
setUint(setId, _cAmt);
|
||||
}
|
||||
|
||||
_eventName = "LogDepositCToken(address,string,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, tokenId, cToken, _amt, _cAmt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw CETH/CERC20_Token using cToken Amt.
|
||||
* @param token token address to withdraw CToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenId token id of the token to withdraw CToken.(For eg: ETH-A)
|
||||
* @param cTokenAmt ctoken amount to withdrawCToken.
|
||||
* @param getId Get ctoken amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function withdrawCToken(
|
||||
address token,
|
||||
string calldata tokenId,
|
||||
uint cTokenAmt,
|
||||
uint getId,
|
||||
uint setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _cAmt = getUint(getId, cTokenAmt);
|
||||
address cToken = instaMapping.cTokenMapping(token);
|
||||
(address token, address cToken) = compMapping.getMapping(tokenId);
|
||||
require(token != address(0) && cToken != address(0), "ctoken mapping not found");
|
||||
|
||||
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_cAmt = _cAmt == uint(-1) ? cTokenContract.balanceOf(address(this)) : _cAmt;
|
||||
|
||||
uint initialBal = token != ethAddr ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||
require(cTokenContract.redeem(_cAmt) == 0, "redeem-failed");
|
||||
uint finalBal = token != ethAddr ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||
uint withdrawAmt;
|
||||
{
|
||||
uint initialBal = token != ethAddr ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||
require(cTokenContract.redeem(_cAmt) == 0, "redeem-failed");
|
||||
uint finalBal = token != ethAddr ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||
|
||||
withdrawAmt = sub(finalBal, initialBal);
|
||||
}
|
||||
|
||||
uint withdrawAmt = sub(finalBal, initialBal);
|
||||
setUint(setId, withdrawAmt);
|
||||
|
||||
_eventName = "LogWithdrawCToken(address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, cToken, withdrawAmt, _cAmt, getId, setId);
|
||||
_eventName = "LogWithdrawCToken(address,string,address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, tokenId, cToken, withdrawAmt, _cAmt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Liquidate a position.
|
||||
* @param borrower Borrower's Address.
|
||||
* @param tokenToPay token address to pay for liquidation.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenInReturn token address to return for liquidation.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param tokenIdToPay token id of the token to pay for liquidation.(For eg: ETH-A)
|
||||
* @param tokenIdInReturn token id of the token to return for liquidation.(For eg: USDC-A)
|
||||
* @param amt token amount to pay for liquidation.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function liquidate(
|
||||
address borrower,
|
||||
address tokenToPay,
|
||||
address tokenInReturn,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
string calldata tokenIdToPay,
|
||||
string calldata tokenIdInReturn,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
address cTokenPay = instaMapping.cTokenMapping(tokenToPay);
|
||||
address cTokenColl = instaMapping.cTokenMapping(tokenInReturn);
|
||||
CTokenInterface cTokenContract = CTokenInterface(cTokenPay);
|
||||
|
||||
LiquidateData memory data;
|
||||
|
||||
(data.tokenToPay, data.cTokenPay) = compMapping.getMapping(tokenIdToPay);
|
||||
(data.tokenInReturn, data.cTokenColl) = compMapping.getMapping(tokenIdInReturn);
|
||||
data.cTokenContract = CTokenInterface(data.cTokenPay);
|
||||
|
||||
{
|
||||
(,, uint shortfal) = troller.getAccountLiquidity(borrower);
|
||||
require(shortfal != 0, "account-cannot-be-liquidated");
|
||||
_amt = _amt == uint(-1) ? data.cTokenContract.borrowBalanceCurrent(borrower) : _amt;
|
||||
}
|
||||
|
||||
_amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(borrower) : _amt;
|
||||
if (tokenToPay == ethAddr) {
|
||||
if (data.tokenToPay == ethAddr) {
|
||||
require(address(this).balance >= _amt, "not-enought-eth");
|
||||
CETHInterface(cTokenPay).liquidateBorrow{value: _amt}(borrower, cTokenColl);
|
||||
CETHInterface(data.cTokenPay).liquidateBorrow{value: _amt}(borrower, data.cTokenColl);
|
||||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(tokenToPay);
|
||||
TokenInterface tokenContract = TokenInterface(data.tokenToPay);
|
||||
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
||||
tokenContract.approve(cTokenPay, _amt);
|
||||
require(cTokenContract.liquidateBorrow(borrower, _amt, cTokenColl) == 0, "liquidate-failed");
|
||||
tokenContract.approve(data.cTokenPay, _amt);
|
||||
require(data.cTokenContract.liquidateBorrow(borrower, _amt, data.cTokenColl) == 0, "liquidate-failed");
|
||||
}
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogLiquidate(address,address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventName = "LogLiquidate(address,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
address(this),
|
||||
tokenToPay,
|
||||
tokenInReturn,
|
||||
data.tokenToPay,
|
||||
data.tokenInReturn,
|
||||
_amt,
|
||||
getId,
|
||||
setId
|
||||
|
|
|
@ -23,7 +23,7 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @dev Close Vault
|
||||
* @param vault Vault ID to close.
|
||||
*/
|
||||
function close(uint vault) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
function close(uint256 vault) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _vault = getVault(vault);
|
||||
(bytes32 ilk, address urn) = getVaultData(_vault);
|
||||
(uint ink, uint art) = VatLike(managerContract.vat()).urns(ilk, urn);
|
||||
|
@ -45,10 +45,10 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function deposit(
|
||||
uint vault,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 vault,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
uint _vault = getVault(vault);
|
||||
|
@ -91,10 +91,10 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function withdraw(
|
||||
uint vault,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 vault,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
uint _vault = getVault(vault);
|
||||
|
@ -146,10 +146,10 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function borrow(
|
||||
uint vault,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 vault,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
uint _vault = getVault(vault);
|
||||
|
@ -194,10 +194,10 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function payback(
|
||||
uint vault,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 vault,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
uint _vault = getVault(vault);
|
||||
|
@ -239,10 +239,10 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function withdrawLiquidated(
|
||||
uint vault,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 vault,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
(bytes32 ilk, address urn) = getVaultData(vault);
|
||||
|
@ -294,13 +294,13 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setIdBorrow Set borrow token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function depositAndBorrow(
|
||||
uint vault,
|
||||
uint depositAmt,
|
||||
uint borrowAmt,
|
||||
uint getIdDeposit,
|
||||
uint getIdBorrow,
|
||||
uint setIdDeposit,
|
||||
uint setIdBorrow
|
||||
uint256 vault,
|
||||
uint256 depositAmt,
|
||||
uint256 borrowAmt,
|
||||
uint256 getIdDeposit,
|
||||
uint256 getIdBorrow,
|
||||
uint256 setIdDeposit,
|
||||
uint256 setIdBorrow
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
MakerData memory makerData;
|
||||
uint _amtDeposit = getUint(getIdDeposit, depositAmt);
|
||||
|
@ -350,10 +350,6 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
setUint(setIdDeposit, _amtDeposit);
|
||||
setUint(setIdBorrow, _amtBorrow);
|
||||
|
||||
emit LogDeposit(makerData._vault, ilk, _amtDeposit, getIdDeposit, setIdDeposit);
|
||||
|
||||
emit LogBorrow(makerData._vault, ilk, _amtBorrow, getIdBorrow, setIdBorrow);
|
||||
|
||||
_eventName = "LogDepositAndBorrow(uint256,bytes32,uint256,uint256,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
makerData._vault,
|
||||
|
@ -375,10 +371,10 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function exitDai(
|
||||
uint vault,
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 vault,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
uint _vault = getVault(vault);
|
||||
|
@ -415,9 +411,9 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function depositDai(
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
|
@ -448,9 +444,9 @@ abstract contract MakerResolver is Helpers, Events {
|
|||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function withdrawDai(
|
||||
uint amt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
|
|
|
@ -4,21 +4,21 @@ contract Events {
|
|||
event LogDepositLiquidity(
|
||||
address indexed tokenA,
|
||||
address indexed tokenB,
|
||||
uint amtA,
|
||||
uint amtB,
|
||||
uint uniAmount,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amtA,
|
||||
uint256 amtB,
|
||||
uint256 uniAmount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogWithdrawLiquidity(
|
||||
address indexed tokenA,
|
||||
address indexed tokenB,
|
||||
uint amountA,
|
||||
uint amountB,
|
||||
uint uniAmount,
|
||||
uint getId,
|
||||
uint[] setId
|
||||
uint256 amountA,
|
||||
uint256 amountB,
|
||||
uint256 uniAmount,
|
||||
uint256 getId,
|
||||
uint256[] setId
|
||||
);
|
||||
|
||||
event LogBuy(
|
||||
|
|
|
@ -18,11 +18,11 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
function deposit(
|
||||
address tokenA,
|
||||
address tokenB,
|
||||
uint amtA,
|
||||
uint unitAmt,
|
||||
uint slippage,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 amtA,
|
||||
uint256 unitAmt,
|
||||
uint256 slippage,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amtA);
|
||||
|
||||
|
@ -32,10 +32,10 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
_amt,
|
||||
unitAmt,
|
||||
slippage
|
||||
);
|
||||
);
|
||||
setUint(setId, _uniAmt);
|
||||
|
||||
_eventName = "LogDepositLiquidity(address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventName = "LogDepositLiquidity(address,address,uint256,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(tokenA, tokenB, _amtA, _amtB, _uniAmt, getId, setId);
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,11 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
function withdraw(
|
||||
address tokenA,
|
||||
address tokenB,
|
||||
uint uniAmt,
|
||||
uint unitAmtA,
|
||||
uint unitAmtB,
|
||||
uint getId,
|
||||
uint[] calldata setIds
|
||||
uint256 uniAmt,
|
||||
uint256 unitAmtA,
|
||||
uint256 unitAmtB,
|
||||
uint256 getId,
|
||||
uint256[] calldata setIds
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, uniAmt);
|
||||
|
||||
|
@ -71,7 +71,7 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
setUint(setIds[0], _amtA);
|
||||
setUint(setIds[1], _amtB);
|
||||
|
||||
_eventName = "LogWithdrawLiquidity(address,address,uint256,uint256,uint256,uint256[])";
|
||||
_eventName = "LogWithdrawLiquidity(address,address,uint256,uint256,uint256,uint256,uint256[])";
|
||||
_eventParam = abi.encode(tokenA, tokenB, _amtA, _amtB, _uniAmt, getId, setIds);
|
||||
}
|
||||
|
||||
|
@ -87,17 +87,18 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
function buy(
|
||||
address buyAddr,
|
||||
address sellAddr,
|
||||
uint buyAmt,
|
||||
uint unitAmt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 buyAmt,
|
||||
uint256 unitAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _buyAmt = getUint(getId, buyAmt);
|
||||
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeEthAddress(buyAddr, sellAddr);
|
||||
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
||||
|
||||
uint _slippageAmt = convert18ToDec(_sellAddr.decimals(),
|
||||
wmul(unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt)));
|
||||
wmul(unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt))
|
||||
);
|
||||
|
||||
checkPair(paths);
|
||||
uint _expectedAmt = getExpectedSellAmt(paths, _buyAmt);
|
||||
|
@ -136,21 +137,24 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
function sell(
|
||||
address buyAddr,
|
||||
address sellAddr,
|
||||
uint sellAmt,
|
||||
uint unitAmt,
|
||||
uint getId,
|
||||
uint setId
|
||||
uint256 sellAmt,
|
||||
uint256 unitAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _sellAmt = getUint(getId, sellAmt);
|
||||
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeEthAddress(buyAddr, sellAddr);
|
||||
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
|
||||
|
||||
if (_sellAmt == uint(-1)) {
|
||||
_sellAmt = sellAddr == ethAddr ? address(this).balance : _sellAddr.balanceOf(address(this));
|
||||
_sellAmt = sellAddr == ethAddr ?
|
||||
address(this).balance :
|
||||
_sellAddr.balanceOf(address(this));
|
||||
}
|
||||
|
||||
uint _slippageAmt = convert18ToDec(_buyAddr.decimals(),
|
||||
wmul(unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt)));
|
||||
wmul(unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt))
|
||||
);
|
||||
|
||||
checkPair(paths);
|
||||
uint _expectedAmt = getExpectedBuyAmt(paths, _sellAmt);
|
||||
|
@ -179,5 +183,5 @@ abstract contract UniswapResolver is Helpers, Events {
|
|||
}
|
||||
|
||||
contract ConnectV2UniswapV2 is UniswapResolver {
|
||||
string public name = "UniswapV2-v1";
|
||||
string public constant name = "UniswapV2-v1";
|
||||
}
|
||||
|
|
137
contracts/mapping/compound.sol
Normal file
137
contracts/mapping/compound.sol
Normal file
|
@ -0,0 +1,137 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface IndexInterface {
|
||||
function master() external view returns (address);
|
||||
}
|
||||
|
||||
interface ConnectorsInterface {
|
||||
function chief(address) external view returns (bool);
|
||||
}
|
||||
|
||||
interface CTokenInterface {
|
||||
function isCToken() external view returns (bool);
|
||||
function underlying() external view returns (address);
|
||||
}
|
||||
|
||||
abstract contract Helpers {
|
||||
|
||||
struct TokenMap {
|
||||
address ctoken;
|
||||
address token;
|
||||
}
|
||||
|
||||
event LogCTokenAdded(string indexed name, address indexed token, address indexed ctoken);
|
||||
event LogCTokenUpdated(string indexed name, address indexed token, address indexed ctoken);
|
||||
|
||||
ConnectorsInterface public immutable connectors;
|
||||
|
||||
// InstaIndex Address.
|
||||
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
||||
|
||||
address public constant ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
|
||||
mapping (string => TokenMap) public cTokenMapping;
|
||||
|
||||
modifier isChief {
|
||||
require(msg.sender == instaIndex.master() || connectors.chief(msg.sender), "not-an-chief");
|
||||
_;
|
||||
}
|
||||
|
||||
constructor(address _connectors) {
|
||||
connectors = ConnectorsInterface(_connectors);
|
||||
}
|
||||
|
||||
function _addCtokenMapping(
|
||||
string[] memory _names,
|
||||
address[] memory _tokens,
|
||||
address[] memory _ctokens
|
||||
) internal {
|
||||
require(_names.length == _tokens.length, "addCtokenMapping: not same length");
|
||||
require(_names.length == _ctokens.length, "addCtokenMapping: not same length");
|
||||
|
||||
for (uint i = 0; i < _ctokens.length; i++) {
|
||||
TokenMap memory _data = cTokenMapping[_names[i]];
|
||||
|
||||
require(_data.ctoken == address(0), "addCtokenMapping: mapping added already");
|
||||
require(_data.token == address(0), "addCtokenMapping: mapping added already");
|
||||
|
||||
require(_tokens[i] != address(0), "addCtokenMapping: _tokens address not vaild");
|
||||
require(_ctokens[i] != address(0), "addCtokenMapping: _ctokens address not vaild");
|
||||
|
||||
CTokenInterface _ctokenContract = CTokenInterface(_ctokens[i]);
|
||||
|
||||
require(_ctokenContract.isCToken(), "addCtokenMapping: not a cToken");
|
||||
if (_tokens[i] != ethAddr) {
|
||||
require(_ctokenContract.underlying() == _tokens[i], "addCtokenMapping: mapping mismatch");
|
||||
}
|
||||
|
||||
cTokenMapping[_names[i]] = TokenMap(
|
||||
_ctokens[i],
|
||||
_tokens[i]
|
||||
);
|
||||
emit LogCTokenAdded(_names[i], _tokens[i], _ctokens[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function updateCtokenMapping(
|
||||
string[] calldata _names,
|
||||
address[] memory _tokens,
|
||||
address[] calldata _ctokens
|
||||
) external {
|
||||
require(msg.sender == instaIndex.master(), "not-master");
|
||||
|
||||
require(_names.length == _tokens.length, "updateCtokenMapping: not same length");
|
||||
require(_names.length == _ctokens.length, "updateCtokenMapping: not same length");
|
||||
|
||||
for (uint i = 0; i < _ctokens.length; i++) {
|
||||
TokenMap memory _data = cTokenMapping[_names[i]];
|
||||
|
||||
require(_data.ctoken != address(0), "updateCtokenMapping: mapping does not exist");
|
||||
require(_data.token != address(0), "updateCtokenMapping: mapping does not exist");
|
||||
|
||||
require(_tokens[i] != address(0), "updateCtokenMapping: _tokens address not vaild");
|
||||
require(_ctokens[i] != address(0), "updateCtokenMapping: _ctokens address not vaild");
|
||||
|
||||
CTokenInterface _ctokenContract = CTokenInterface(_ctokens[i]);
|
||||
|
||||
require(_ctokenContract.isCToken(), "updateCtokenMapping: not a cToken");
|
||||
if (_tokens[i] != ethAddr) {
|
||||
require(_ctokenContract.underlying() == _tokens[i], "addCtokenMapping: mapping mismatch");
|
||||
}
|
||||
|
||||
cTokenMapping[_names[i]] = TokenMap(
|
||||
_ctokens[i],
|
||||
_tokens[i]
|
||||
);
|
||||
emit LogCTokenUpdated(_names[i], _tokens[i], _ctokens[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function addCtokenMapping(
|
||||
string[] memory _names,
|
||||
address[] memory _tokens,
|
||||
address[] memory _ctokens
|
||||
) external isChief {
|
||||
_addCtokenMapping(_names, _tokens, _ctokens);
|
||||
}
|
||||
|
||||
function getMapping(string memory _tokenId) external view returns (address, address) {
|
||||
TokenMap memory _data = cTokenMapping[_tokenId];
|
||||
return (_data.token, _data.ctoken);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract InstaCompoundMapping is Helpers {
|
||||
string constant public name = "Compound-Mapping-v1.1";
|
||||
|
||||
constructor(
|
||||
address _connectors,
|
||||
string[] memory _ctokenNames,
|
||||
address[] memory _tokens,
|
||||
address[] memory _ctokens
|
||||
) Helpers(_connectors) {
|
||||
_addCtokenMapping(_ctokenNames, _tokens, _ctokens);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@ require("@tenderly/hardhat-tenderly");
|
|||
require("@nomiclabs/hardhat-etherscan");
|
||||
require('dotenv').config();
|
||||
|
||||
const { utils } = require("ethers");
|
||||
|
||||
const PRIVATE_KEY = process.env.PRIVATE_KEY;
|
||||
const ALCHEMY_ID = process.env.ALCHEMY_ID;
|
||||
|
||||
|
@ -37,20 +39,19 @@ module.exports = {
|
|||
url: `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_ID}`,
|
||||
accounts: [`0x${PRIVATE_KEY}`]
|
||||
},
|
||||
tenderlyMainnet: {
|
||||
url: 'https://mainnet.tenderly.co',
|
||||
mainnet: {
|
||||
url: `https://eth.alchemyapi.io/v2/${ALCHEMY_ID}`,
|
||||
accounts: [`0x${PRIVATE_KEY}`],
|
||||
chainId: 1,
|
||||
gasPrice: 25120000000,
|
||||
timeout: 500000
|
||||
timeout: 150000,
|
||||
gasPrice: parseInt(utils.parseUnits("161", "gwei"))
|
||||
},
|
||||
hardhat: {
|
||||
forking: {
|
||||
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
|
||||
blockNumber: 12070498,
|
||||
},
|
||||
blockGasLimit: 12000000,
|
||||
},
|
||||
tenderlyKovan: {
|
||||
url: 'https://kovan.tenderly.co',
|
||||
accounts: [`0x${PRIVATE_KEY}`],
|
||||
chainId: 42,
|
||||
gasPrice: 40000000000,
|
||||
timeout: 50000
|
||||
}
|
||||
},
|
||||
etherscan: {
|
||||
apiKey: process.env.ETHERSCAN_API_KEY
|
||||
|
|
19610
package-lock.json
generated
19610
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -26,10 +26,11 @@
|
|||
"@openzeppelin/upgrades": "^2.8.0",
|
||||
"@truffle/artifactor": "^4.0.45",
|
||||
"chalk": "^4.0.0",
|
||||
"commander": "^7.1.0",
|
||||
"dotenv": "^7.0.0",
|
||||
"ethereumjs-abi": "^0.6.8",
|
||||
"minimist": "^1.2.5",
|
||||
"solc": "^0.6.0",
|
||||
"solc": "^0.7.0",
|
||||
"truffle-assertions": "^0.9.2",
|
||||
"truffle-hdwallet-provider": "^1.0.17",
|
||||
"truffle-plugin-verify": "^0.3.10",
|
||||
|
@ -50,6 +51,6 @@
|
|||
"sol-merger": "^2.0.1",
|
||||
"solidity-coverage": "0.5.11",
|
||||
"solium": "1.2.3",
|
||||
"web3": "^1.2.9"
|
||||
"web3": "^1.2.6"
|
||||
}
|
||||
}
|
||||
|
|
70
scripts/deployCompoundMapping.js
Normal file
70
scripts/deployCompoundMapping.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
const hre = require("hardhat");
|
||||
const { ethers } = hre;
|
||||
|
||||
async function main() {
|
||||
|
||||
const CONNECTORS_V2 = "0xFE2390DAD597594439f218190fC2De40f9Cf1179";
|
||||
|
||||
const ctokenMapping = {
|
||||
"ETH-A": "0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5",
|
||||
"BAT-A": "0x6c8c6b02e7b2be14d4fa6022dfd6d75921d90e4e",
|
||||
"COMP-A": "0x70e36f6bf80a52b3b46b3af8e106cc0ed743e8e4",
|
||||
"DAI-A": "0x5d3a536e4d6dbd6114cc1ead35777bab948e3643",
|
||||
"REP-A": "0x158079ee67fce2f58472a96584a73c7ab9ac95c1",
|
||||
"UNI-A": "0x35a18000230da775cac24873d00ff85bccded550",
|
||||
"USDC-A": "0x39aa39c021dfbae8fac545936693ac917d5e7563",
|
||||
"USDT-A": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9",
|
||||
"WBTC-A": "0xc11b1268c1a384e55c48c2391d8d480264a3a7f4",
|
||||
"WBTC-B": "0xccF4429DB6322D5C611ee964527D42E5d685DD6a",
|
||||
"ZRX-A": "0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407"
|
||||
}
|
||||
|
||||
const tokenMapping = {
|
||||
"ETH-A": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
"BAT-A": "0x0D8775F648430679A709E98d2b0Cb6250d2887EF",
|
||||
"COMP-A": "0xc00e94cb662c3520282e6f5717214004a7f26888",
|
||||
"DAI-A": "0x6b175474e89094c44da98b954eedeac495271d0f",
|
||||
"REP-A": "0x1985365e9f78359a9B6AD760e32412f4a445E862",
|
||||
"UNI-A": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
|
||||
"USDC-A": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
||||
"USDT-A": "0xdac17f958d2ee523a2206206994597c13d831ec7",
|
||||
"WBTC-A": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
||||
"WBTC-B": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
||||
"ZRX-A": "0xe41d2489571d322189246dafa5ebde1f4699f498"
|
||||
}
|
||||
|
||||
const Mapping = await ethers.getContractFactory("InstaCompoundMapping");
|
||||
const mapping = await Mapping.deploy(
|
||||
CONNECTORS_V2,
|
||||
Object.keys(ctokenMapping),
|
||||
Object.values(tokenMapping),
|
||||
Object.values(ctokenMapping)
|
||||
);
|
||||
await mapping.deployed();
|
||||
|
||||
console.log(`InstaCompoundMapping Deployed: ${mapping.address}`);
|
||||
|
||||
try {
|
||||
await hre.run("verify:verify", {
|
||||
address: mapping.address,
|
||||
constructorArguments: [
|
||||
CONNECTORS_V2,
|
||||
Object.keys(ctokenMapping),
|
||||
Object.values(tokenMapping),
|
||||
Object.values(ctokenMapping)
|
||||
]
|
||||
}
|
||||
)
|
||||
} catch (error) {
|
||||
console.log(`Failed to verify: InstaCompoundMapping@${mapping.address}`)
|
||||
console.log(error)
|
||||
console.log()
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
Loading…
Reference in New Issue
Block a user