mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
updated with new connectors & updates
This commit is contained in:
parent
994fb1dd31
commit
9d2a61e40f
|
@ -82,6 +82,7 @@ contract BasicResolver is AaveHelpers {
|
|||
event LogWithdraw(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogBorrow(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogPayback(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogEnableCollateral(address[] tokens);
|
||||
|
||||
/**
|
||||
* @dev Deposit ETH/ERC20_Token.
|
||||
|
@ -111,9 +112,6 @@ contract BasicResolver is AaveHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogDeposit(token, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogDeposit(address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, _amt, getId, setId);
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,9 +135,6 @@ contract BasicResolver is AaveHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogWithdraw(token, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, _amt, getId, setId);
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,9 +151,6 @@ contract BasicResolver is AaveHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogBorrow(token, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogBorrow(address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, _amt, getId, setId);
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,12 +181,29 @@ contract BasicResolver is AaveHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogPayback(token, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogPayback(address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, _amt, getId, setId);
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Enable collateral
|
||||
* @param tokens Array of tokens to enable collateral
|
||||
*/
|
||||
function enableCollateral(address[] calldata tokens) external payable {
|
||||
uint _length = tokens.length;
|
||||
require(_length > 0, "0-tokens-not-allowed");
|
||||
|
||||
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
|
||||
|
||||
for (uint i = 0; i < _length; i++) {
|
||||
address token = tokens[i];
|
||||
if (getWithdrawBalance(token) > 0 && !getIsColl(aave, token)) {
|
||||
aave.setUserUseReserveAsCollateral(token, true);
|
||||
}
|
||||
}
|
||||
|
||||
emit LogEnableCollateral(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectAave is BasicResolver {
|
||||
string public name = "Aave-v1";
|
||||
}
|
||||
string public name = "Aave-v1.1";
|
||||
}
|
||||
|
|
266
contracts/connectors_old/aave_v2.sol
Normal file
266
contracts/connectors_old/aave_v2.sol
Normal file
|
@ -0,0 +1,266 @@
|
|||
pragma solidity ^0.6.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
// import files from common directory
|
||||
import { TokenInterface , MemoryInterface} from "../common/interfaces.sol";
|
||||
import { Stores } from "../common/stores.sol";
|
||||
import { DSMath } from "../common/math.sol";
|
||||
|
||||
interface AaveInterface {
|
||||
function deposit(address _asset, uint256 _amount, address _onBehalfOf, uint16 _referralCode) external;
|
||||
function withdraw(address _asset, uint256 _amount, address _to) external;
|
||||
function borrow(
|
||||
address _asset,
|
||||
uint256 _amount,
|
||||
uint256 _interestRateMode,
|
||||
uint16 _referralCode,
|
||||
address _onBehalfOf
|
||||
) external;
|
||||
function repay(address _asset, uint256 _amount, uint256 _rateMode, address _onBehalfOf) external;
|
||||
function setUserUseReserveAsCollateral(address _asset, bool _useAsCollateral) external;
|
||||
}
|
||||
|
||||
interface AaveLendingPoolProviderInterface {
|
||||
function getLendingPool() external view returns (address);
|
||||
}
|
||||
|
||||
// Aave Protocol Data Provider
|
||||
interface AaveDataProviderInterface {
|
||||
function getReserveTokensAddresses(address _asset) external view returns (
|
||||
address aTokenAddress,
|
||||
address stableDebtTokenAddress,
|
||||
address variableDebtTokenAddress
|
||||
);
|
||||
function getUserReserveData(address _asset, address _user) external view returns (
|
||||
uint256 currentATokenBalance,
|
||||
uint256 currentStableDebt,
|
||||
uint256 currentVariableDebt,
|
||||
uint256 principalStableDebt,
|
||||
uint256 scaledVariableDebt,
|
||||
uint256 stableBorrowRate,
|
||||
uint256 liquidityRate,
|
||||
uint40 stableRateLastUpdated,
|
||||
bool usageAsCollateralEnabled
|
||||
);
|
||||
}
|
||||
|
||||
interface AaveAddressProviderRegistryInterface {
|
||||
function getAddressesProvidersList() external view returns (address[] memory);
|
||||
}
|
||||
|
||||
interface ATokenInterface {
|
||||
function balanceOf(address _user) external view returns(uint256);
|
||||
}
|
||||
|
||||
contract AaveHelpers is DSMath, Stores {
|
||||
/**
|
||||
* @dev get Aave Lending Pool Provider
|
||||
*/
|
||||
function getAaveProvider() internal pure returns (AaveLendingPoolProviderInterface) {
|
||||
return AaveLendingPoolProviderInterface(0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5); //mainnet
|
||||
// return AaveLendingPoolProviderInterface(0x652B2937Efd0B5beA1c8d54293FC1289672AFC6b); //kovan
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get Aave Protocol Data Provider
|
||||
*/
|
||||
function getAaveDataProvider() internal pure returns (AaveDataProviderInterface) {
|
||||
return AaveDataProviderInterface(0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d); //mainnet
|
||||
// return AaveDataProviderInterface(0x744C1aaA95232EeF8A9994C4E0b3a89659D9AB79); //kovan
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return Weth address
|
||||
*/
|
||||
function getWethAddr() internal pure returns (address) {
|
||||
return 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; // Mainnet WETH Address
|
||||
// return 0xd0A1E359811322d97991E03f863a0C30C2cF029C; // Kovan WETH Address
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get Referral Code
|
||||
*/
|
||||
function getReferralCode() internal pure returns (uint16) {
|
||||
return 3228;
|
||||
}
|
||||
|
||||
function getIsColl(AaveDataProviderInterface aaveData, address token, address user) internal view returns (bool isCol) {
|
||||
(, , , , , , , , isCol) = aaveData.getUserReserveData(token, user);
|
||||
}
|
||||
|
||||
function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal {
|
||||
if(isEth) token.deposit.value(amount)();
|
||||
}
|
||||
|
||||
function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal {
|
||||
if(isEth) {
|
||||
token.approve(address(token), amount);
|
||||
token.withdraw(amount);
|
||||
}
|
||||
}
|
||||
|
||||
function getPaybackBalance(AaveDataProviderInterface aaveData, address token, uint rateMode) internal view returns (uint) {
|
||||
(, uint stableDebt, uint variableDebt, , , , , , ) = aaveData.getUserReserveData(token, address(this));
|
||||
return rateMode == 1 ? stableDebt : variableDebt;
|
||||
}
|
||||
|
||||
function getCollateralBalance(AaveDataProviderInterface aaveData, address token) internal view returns (uint bal) {
|
||||
(bal, , , , , , , ,) = aaveData.getUserReserveData(token, address(this));
|
||||
}
|
||||
}
|
||||
|
||||
contract BasicResolver is AaveHelpers {
|
||||
event LogDeposit(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogWithdraw(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogBorrow(address indexed token, uint256 tokenAmt, uint256 indexed rateMode, uint256 getId, uint256 setId);
|
||||
event LogPayback(address indexed token, uint256 tokenAmt, uint256 indexed rateMode, uint256 getId, uint256 setId);
|
||||
event LogEnableCollateral(address[] tokens);
|
||||
|
||||
/**
|
||||
* @dev Deposit ETH/ERC20_Token.
|
||||
* @param token token address to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @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) external payable {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
|
||||
AaveDataProviderInterface aaveData = getAaveDataProvider();
|
||||
|
||||
bool isEth = token == getEthAddr();
|
||||
address _token = isEth ? getWethAddr() : token;
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
if (isEth) {
|
||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
} else {
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
}
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
|
||||
aave.deposit(_token, _amt, address(this), getReferralCode());
|
||||
|
||||
if (!getIsColl(aaveData, _token, address(this))) {
|
||||
aave.setUserUseReserveAsCollateral(_token, true);
|
||||
}
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
emit LogDeposit(token, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw ETH/ERC20_Token.
|
||||
* @param token token address to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @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) external payable {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
|
||||
bool isEth = token == getEthAddr();
|
||||
address _token = isEth ? getWethAddr() : token;
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
uint initialBal = tokenContract.balanceOf(address(this));
|
||||
aave.withdraw(_token, _amt, address(this));
|
||||
uint finalBal = tokenContract.balanceOf(address(this));
|
||||
|
||||
_amt = sub(finalBal, initialBal);
|
||||
|
||||
convertWethToEth(isEth, tokenContract, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
emit LogWithdraw(token, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Borrow ETH/ERC20_Token.
|
||||
* @param token token address to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt token amount to borrow.
|
||||
* @param rateMode type of borrow debt.(For Stable: 1, Variable: 2)
|
||||
* @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 rateMode, uint getId, uint setId) external payable {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
|
||||
|
||||
bool isEth = token == getEthAddr();
|
||||
address _token = isEth ? getWethAddr() : token;
|
||||
|
||||
aave.borrow(_token, _amt, rateMode, getReferralCode(), address(this));
|
||||
convertWethToEth(isEth, TokenInterface(_token), _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
emit LogBorrow(token, _amt, rateMode, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Payback borrowed ETH/ERC20_Token.
|
||||
* @param token token address to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt token amount to payback.
|
||||
* @param rateMode type of borrow debt.(For Stable: 1, Variable: 2)
|
||||
* @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 rateMode, uint getId, uint setId) external payable {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
|
||||
AaveDataProviderInterface aaveData = getAaveDataProvider();
|
||||
|
||||
bool isEth = token == getEthAddr();
|
||||
address _token = isEth ? getWethAddr() : token;
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
_amt = _amt == uint(-1) ? getPaybackBalance(aaveData, _token, rateMode) : _amt;
|
||||
|
||||
if (isEth) convertEthToWeth(isEth, tokenContract, _amt);
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
|
||||
aave.repay(_token, _amt, rateMode, address(this));
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
emit LogPayback(token, _amt, rateMode, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Enable collateral
|
||||
* @param tokens Array of tokens to enable collateral
|
||||
*/
|
||||
function enableCollateral(address[] calldata tokens) external payable {
|
||||
uint _length = tokens.length;
|
||||
require(_length > 0, "0-tokens-not-allowed");
|
||||
|
||||
AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
|
||||
AaveDataProviderInterface aaveData = getAaveDataProvider();
|
||||
|
||||
for (uint i = 0; i < _length; i++) {
|
||||
address token = tokens[i];
|
||||
if (getCollateralBalance(aaveData, token) > 0 && !getIsColl(aaveData, token, address(this))) {
|
||||
aave.setUserUseReserveAsCollateral(token, true);
|
||||
}
|
||||
}
|
||||
|
||||
emit LogEnableCollateral(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectAaveV2 is BasicResolver {
|
||||
string public name = "AaveV2-v1.1";
|
||||
}
|
|
@ -63,7 +63,7 @@ contract BasicResolver is Stores {
|
|||
uint getId,
|
||||
uint setId
|
||||
) public payable {
|
||||
require(AccountInterface(address(this)).isAuth(to), "invalid-to-address");
|
||||
// require(AccountInterface(address(this)).isAuth(to), "invalid-to-address");
|
||||
uint amt = getUint(getId, tokenAmt);
|
||||
if (erc20 == getEthAddr()) {
|
||||
amt = amt == uint(-1) ? address(this).balance : amt;
|
||||
|
|
|
@ -47,10 +47,6 @@ interface MemoryInterface {
|
|||
function setUint(uint _id, uint _val) external;
|
||||
}
|
||||
|
||||
interface EventInterface {
|
||||
function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external;
|
||||
}
|
||||
|
||||
contract DSMath {
|
||||
|
||||
function add(uint x, uint y) internal pure returns (uint z) {
|
||||
|
@ -93,12 +89,12 @@ contract Helpers is DSMath {
|
|||
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return InstaEvent Address.
|
||||
*/
|
||||
function getEventAddr() internal pure returns (address) {
|
||||
return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; // InstaEvent Address
|
||||
}
|
||||
// /**
|
||||
// * @dev Return InstaEvent Address.
|
||||
// */
|
||||
// function getEventAddr() internal pure returns (address) {
|
||||
// return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; // InstaEvent Address
|
||||
// }
|
||||
|
||||
/**
|
||||
* @dev Get Uint value from InstaMemory Contract.
|
||||
|
@ -118,7 +114,7 @@ contract Helpers is DSMath {
|
|||
* @dev Connector Details
|
||||
*/
|
||||
function connectorID() public pure returns(uint _type, uint _id) {
|
||||
(_type, _id) = (1, 24);
|
||||
(_type, _id) = (1, 57);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,15 +186,11 @@ contract BasicResolver is CompoundHelpers {
|
|||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.approve(cToken, _amt);
|
||||
require(CTokenInterface(cToken).mint(_amt) == 0, "borrow-failed");
|
||||
require(CTokenInterface(cToken).mint(_amt) == 0, "deposit-failed");
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
||||
emit LogDeposit(token, cToken, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogDeposit(address,address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,10 +216,6 @@ contract BasicResolver is CompoundHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogWithdraw(token, cToken, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogWithdraw(address,address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,10 +233,6 @@ contract BasicResolver is CompoundHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogBorrow(token, cToken, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogBorrow(address,address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,17 +260,13 @@ contract BasicResolver is CompoundHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogPayback(token, cToken, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogPayback(address,address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
contract ExtraResolver is BasicResolver {
|
||||
event LogClaimedComp(uint256 compAmt, uint256 setId);
|
||||
event LogDepositCToken(address indexed token, address cToken, uint256 tokenAmt, uint256 cTokenAmt,uint256 getId, uint256 setId);
|
||||
event LogWithdrawCToken(address indexed token, address cToken, uint256 cTokenAmt, uint256 getId, uint256 setId);
|
||||
event LogWithdrawCToken(address indexed token, address cToken, uint256 tokenAmt, uint256 cTokenAmt, uint256 getId, uint256 setId);
|
||||
event LogLiquidate(
|
||||
address indexed borrower,
|
||||
address indexed tokenToPay,
|
||||
|
@ -296,26 +276,6 @@ contract ExtraResolver is BasicResolver {
|
|||
uint256 setId
|
||||
);
|
||||
|
||||
/**
|
||||
* @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 Deposit ETH/ERC20_Token.
|
||||
* @param token token address to depositCToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
|
@ -346,10 +306,6 @@ contract ExtraResolver is BasicResolver {
|
|||
setUint(setId, _cAmt);
|
||||
|
||||
emit LogDepositCToken(token, cToken, _amt, _cAmt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogDepositCToken(address,address,uint256,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, cToken, _amt, _cAmt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -357,22 +313,23 @@ contract ExtraResolver is BasicResolver {
|
|||
* @param token token address to withdraw CToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param cTokenAmt ctoken amount to withdrawCToken.
|
||||
* @param getId Get ctoken amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function withdrawCToken(address token, uint cTokenAmt, uint getId, uint setId) external payable {
|
||||
uint _amt = getUint(getId, cTokenAmt);
|
||||
uint _cAmt = getUint(getId, cTokenAmt);
|
||||
address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token);
|
||||
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
||||
_amt = _amt == uint(-1) ? cTokenContract.balanceOf(address(this)) : _amt;
|
||||
require(cTokenContract.redeem(_amt) == 0, "redeem-failed");
|
||||
setUint(setId, _amt);
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
_cAmt = _cAmt == uint(-1) ? cTokenContract.balanceOf(address(this)) : _cAmt;
|
||||
|
||||
emit LogWithdrawCToken(token, cToken, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogWithdrawCToken(address,address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(token, cToken, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
uint initialBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||
require(cTokenContract.redeem(_cAmt) == 0, "redeem-failed");
|
||||
uint finalBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||
|
||||
uint withdrawAmt = sub(finalBal, initialBal);
|
||||
setUint(setId, withdrawAmt);
|
||||
|
||||
emit LogWithdrawCToken(token, cToken, withdrawAmt, _cAmt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -421,22 +378,10 @@ contract ExtraResolver is BasicResolver {
|
|||
getId,
|
||||
setId
|
||||
);
|
||||
bytes32 _eventCode = keccak256("LogLiquidate(address,address,address,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(
|
||||
address(this),
|
||||
tokenToPay,
|
||||
tokenInReturn,
|
||||
_amt,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract ConnectCompound is ExtraResolver {
|
||||
string public name = "Compound-v1.2";
|
||||
string public name = "Compound-v1.3";
|
||||
}
|
78
contracts/connectors_old/fee.sol
Normal file
78
contracts/connectors_old/fee.sol
Normal file
|
@ -0,0 +1,78 @@
|
|||
pragma solidity ^0.6.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface MemoryInterface {
|
||||
function getUint(uint _id) external returns (uint _num);
|
||||
function setUint(uint _id, uint _val) external;
|
||||
}
|
||||
|
||||
contract DSMath {
|
||||
uint256 constant WAD = 10 ** 18;
|
||||
|
||||
function add(uint x, uint y) internal pure returns (uint z) {
|
||||
require((z = x + y) >= x, "math-not-safe");
|
||||
}
|
||||
|
||||
function mul(uint x, uint y) internal pure returns (uint z) {
|
||||
require(y == 0 || (z = x * y) / y == x, "math-not-safe");
|
||||
}
|
||||
|
||||
function wmul(uint x, uint y) internal pure returns (uint z) {
|
||||
z = add(mul(x, y), WAD / 2) / WAD;
|
||||
}
|
||||
}
|
||||
|
||||
contract Setup is DSMath {
|
||||
|
||||
/**
|
||||
* @dev Return InstAaMemory Address.
|
||||
*/
|
||||
function getMemoryAddr() internal pure returns (address) {
|
||||
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get Uint value from InstaMemory Contract.
|
||||
*/
|
||||
function getUint(uint getId, uint val) internal returns (uint returnVal) {
|
||||
returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Set Uint value in InstaMemory Contract.
|
||||
*/
|
||||
function setUint(uint setId, uint val) internal {
|
||||
if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Connector ID and Type. TODO: change.
|
||||
*/
|
||||
function connectorID() public pure returns(uint _type, uint _id) {
|
||||
(_type, _id) = (1, 37);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
contract FeeResolver is Setup {
|
||||
|
||||
/**
|
||||
* @dev Calculate fee
|
||||
*/
|
||||
function calculateFee(uint amount, uint fee, uint getId, uint setId, uint setIdFee) external payable {
|
||||
uint _amt = getUint(getId, amount);
|
||||
|
||||
uint feeAmt = wmul(_amt, fee);
|
||||
|
||||
uint totalAmt = add(_amt, feeAmt);
|
||||
|
||||
setUint(setId, totalAmt);
|
||||
setUint(setIdFee, feeAmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract ConnectFee is FeeResolver {
|
||||
string public constant name = "Fee-v1";
|
||||
}
|
|
@ -3,7 +3,6 @@ pragma solidity ^0.6.0;
|
|||
interface TokenInterface {
|
||||
function approve(address, uint) external;
|
||||
function transfer(address, uint) external;
|
||||
function transferFrom(address, address, uint) external;
|
||||
function deposit() external payable;
|
||||
function withdraw(uint) external;
|
||||
function balanceOf(address) external view returns (uint);
|
||||
|
@ -40,7 +39,6 @@ interface VatLike {
|
|||
function hope(address) external;
|
||||
function move(address, address, uint) external;
|
||||
function gem(bytes32, address) external view returns (uint);
|
||||
|
||||
}
|
||||
|
||||
interface TokenJoinInterface {
|
||||
|
@ -184,7 +182,7 @@ contract Helpers is DSMath {
|
|||
* @dev Connector Details
|
||||
*/
|
||||
function connectorID() public pure returns(uint _type, uint _id) {
|
||||
(_type, _id) = (1, 40);
|
||||
(_type, _id) = (1, 61);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,7 +331,7 @@ contract MakerHelpers is MakerMCDAddresses {
|
|||
}
|
||||
}
|
||||
|
||||
contract EventHelper is MakerHelpers {
|
||||
contract BasicResolver is MakerHelpers {
|
||||
event LogOpen(uint256 indexed vault, bytes32 indexed ilk);
|
||||
event LogClose(uint256 indexed vault, bytes32 indexed ilk);
|
||||
event LogTransfer(uint256 indexed vault, bytes32 indexed ilk, address newOwner);
|
||||
|
@ -342,24 +340,6 @@ contract EventHelper is MakerHelpers {
|
|||
event LogBorrow(uint256 indexed vault, bytes32 indexed ilk, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogPayback(uint256 indexed vault, bytes32 indexed ilk, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
|
||||
function emitLogDeposit(uint256 vault, bytes32 ilk, uint256 tokenAmt, uint256 getId, uint256 setId) internal {
|
||||
emit LogDeposit(vault, ilk, tokenAmt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogDeposit(uint256,bytes32,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(vault, ilk, tokenAmt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
function emitLogBorrow(uint256 vault, bytes32 ilk, uint256 tokenAmt, uint256 getId, uint256 setId) internal {
|
||||
emit LogBorrow(vault, ilk, tokenAmt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogBorrow(uint256,bytes32,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(vault, ilk, tokenAmt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
contract BasicResolver is EventHelper {
|
||||
|
||||
/**
|
||||
* @dev Open Vault
|
||||
|
@ -371,10 +351,6 @@ contract BasicResolver is EventHelper {
|
|||
vault = ManagerLike(getMcdManager()).open(ilk, address(this));
|
||||
|
||||
emit LogOpen(vault, ilk);
|
||||
bytes32 _eventCode = keccak256("LogOpen(uint256,bytes32)");
|
||||
bytes memory _eventParam = abi.encode(vault, ilk);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,10 +370,6 @@ contract BasicResolver is EventHelper {
|
|||
managerContract.give(_vault, getGiveAddress());
|
||||
|
||||
emit LogClose(_vault, ilk);
|
||||
bytes32 _eventCode = keccak256("LogClose(uint256,bytes32)");
|
||||
bytes memory _eventParam = abi.encode(_vault, ilk);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,7 +417,7 @@ contract BasicResolver is EventHelper {
|
|||
|
||||
setUint(setId, _amt);
|
||||
|
||||
emitLogDeposit(_vault, ilk, _amt, getId, setId);
|
||||
emit LogDeposit(vault, ilk, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -502,10 +474,6 @@ contract BasicResolver is EventHelper {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogWithdraw(_vault, ilk, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogWithdraw(uint256,bytes32,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(_vault, ilk, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -556,7 +524,7 @@ contract BasicResolver is EventHelper {
|
|||
|
||||
setUint(setId, _amt);
|
||||
|
||||
emitLogBorrow(_vault, ilk, _amt, getId, setId);
|
||||
emit LogBorrow(vault, ilk, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -603,10 +571,6 @@ contract BasicResolver is EventHelper {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogPayback(_vault, ilk, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogPayback(uint256,bytes32,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(_vault, ilk, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -640,7 +604,7 @@ contract BasicExtraResolver is BasicResolver {
|
|||
uint _amt18;
|
||||
if (_amt == uint(-1)) {
|
||||
_amt18 = VatLike(managerContract.vat()).gem(ilk, urn);
|
||||
_amt = convert18ToDec(tokenJoinContract.dec(), _amt);
|
||||
_amt = convert18ToDec(tokenJoinContract.dec(), _amt18);
|
||||
} else {
|
||||
_amt18 = convertTo18(tokenJoinContract.dec(), _amt);
|
||||
}
|
||||
|
@ -660,10 +624,6 @@ contract BasicExtraResolver is BasicResolver {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogWithdrawLiquidated(vault, ilk, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogWithdrawLiquidated(uint256,bytes32,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(vault, ilk, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
struct MakerData {
|
||||
|
@ -745,9 +705,9 @@ contract BasicExtraResolver is BasicResolver {
|
|||
setUint(setIdDeposit, _amtDeposit);
|
||||
setUint(setIdBorrow, _amtBorrow);
|
||||
|
||||
emitLogDeposit(makerData._vault, ilk, _amtDeposit, getIdDeposit, setIdDeposit);
|
||||
emit LogDeposit(makerData._vault, ilk, _amtDeposit, getIdDeposit, setIdDeposit);
|
||||
|
||||
emitLogBorrow(makerData._vault, ilk, _amtBorrow, getIdBorrow, setIdBorrow);
|
||||
emit LogBorrow(makerData._vault, ilk, _amtBorrow, getIdBorrow, setIdBorrow);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -792,10 +752,6 @@ contract BasicExtraResolver is BasicResolver {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogExitDai(_vault, ilk, _amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogExitDai(uint256,bytes32,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(_vault, ilk, _amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -838,10 +794,6 @@ contract DsrResolver is BasicExtraResolver {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogDepositDai(_amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogDepositDai(uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(_amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -886,13 +838,9 @@ contract DsrResolver is BasicExtraResolver {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogWithdrawDai(_amt, getId, setId);
|
||||
bytes32 _eventCode = keccak256("LogWithdrawDai(uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(_amt, getId, setId);
|
||||
(uint _type, uint _id) = connectorID();
|
||||
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectMaker is DsrResolver {
|
||||
string public constant name = "MakerDao-v1.3";
|
||||
string public constant name = "MakerDao-v1.4";
|
||||
}
|
Loading…
Reference in New Issue
Block a user