mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Done wtih aave_v2 connector
This commit is contained in:
parent
56981852ae
commit
e9edaf0ca4
|
@ -2,7 +2,7 @@ pragma solidity ^0.6.0;
|
|||
pragma experimental ABIEncoderV2;
|
||||
|
||||
// import files from common directory
|
||||
import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol";
|
||||
import { TokenInterface , MemoryInterface} from "../common/interfaces.sol";
|
||||
import { Stores } from "../common/stores.sol";
|
||||
import { DSMath } from "../common/math.sol";
|
||||
|
||||
|
@ -18,14 +18,6 @@ interface AaveInterface {
|
|||
) external;
|
||||
function repay(address _asset, uint256 _amount, uint256 _rateMode, address _onBehalfOf) external;
|
||||
function setUserUseReserveAsCollateral(address _asset, bool _useAsCollateral) external;
|
||||
function getUserAccountData(address user) external view returns (
|
||||
uint256 totalCollateralETH,
|
||||
uint256 totalDebtETH,
|
||||
uint256 availableBorrowsETH,
|
||||
uint256 currentLiquidationThreshold,
|
||||
uint256 ltv,
|
||||
uint256 healthFactor
|
||||
);
|
||||
}
|
||||
|
||||
interface AaveLendingPoolProviderInterface {
|
||||
|
@ -57,8 +49,6 @@ interface AaveAddressProviderRegistryInterface {
|
|||
}
|
||||
|
||||
interface ATokenInterface {
|
||||
function scaledBalanceOf(address _user) external view returns (uint256);
|
||||
function isTransferAllowed(address _user, uint256 _amount) external view returns (bool);
|
||||
function balanceOf(address _user) external view returns(uint256);
|
||||
}
|
||||
|
||||
|
@ -67,30 +57,31 @@ contract AaveHelpers is DSMath, Stores {
|
|||
* @dev get Aave Lending Pool Provider
|
||||
*/
|
||||
function getAaveProvider() internal pure returns (AaveLendingPoolProviderInterface) {
|
||||
// return AaveLendingPoolProviderInterface(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8); //mainnet
|
||||
return AaveLendingPoolProviderInterface(0x652B2937Efd0B5beA1c8d54293FC1289672AFC6b); //kovan
|
||||
return AaveLendingPoolProviderInterface(0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5); //mainnet
|
||||
// return AaveLendingPoolProviderInterface(0x652B2937Efd0B5beA1c8d54293FC1289672AFC6b); //kovan
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get Aave Protocol Data Provider
|
||||
*/
|
||||
function getAaveDataProvider() internal pure returns (AaveDataProviderInterface) {
|
||||
// return AaveProtocolDataProviderInterface(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8); //mainnet
|
||||
return AaveDataProviderInterface(0x744C1aaA95232EeF8A9994C4E0b3a89659D9AB79); //kovan
|
||||
return AaveDataProviderInterface(0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d); //mainnet
|
||||
// return AaveDataProviderInterface(0x744C1aaA95232EeF8A9994C4E0b3a89659D9AB79); //kovan
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return Weth address
|
||||
*/
|
||||
function getWethAddr() internal pure returns (address) {
|
||||
return 0xd0A1E359811322d97991E03f863a0C30C2cF029C; // Kovan WETH Address
|
||||
return 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; // Mainnet WETH Address
|
||||
// return 0xd0A1E359811322d97991E03f863a0C30C2cF029C; // Kovan WETH Address
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get Referral Code
|
||||
*/
|
||||
function getReferralCode() internal pure returns (uint16) {
|
||||
return 0;
|
||||
return 3228;
|
||||
}
|
||||
|
||||
function getIsColl(AaveDataProviderInterface aaveData, address token, address user) internal view returns (bool isCol) {
|
||||
|
@ -120,6 +111,13 @@ contract BasicResolver is AaveHelpers {
|
|||
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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
|
@ -149,12 +147,16 @@ 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);
|
||||
}
|
||||
|
||||
function withdraw(address token, uint amt, uint getId, uint setId) external {
|
||||
/**
|
||||
* @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());
|
||||
|
@ -167,18 +169,24 @@ contract BasicResolver is AaveHelpers {
|
|||
aave.withdraw(_token, _amt, address(this));
|
||||
uint finalBal = tokenContract.balanceOf(address(this));
|
||||
|
||||
convertWethToEth(isEth, tokenContract, finalBal);
|
||||
|
||||
_amt = sub(finalBal, initialBal);
|
||||
|
||||
convertWethToEth(isEth, tokenContract, _amt);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function borrow(address token, uint amt, uint rateMode, uint getId, uint setId) external {
|
||||
/**
|
||||
* @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());
|
||||
|
@ -192,11 +200,16 @@ contract BasicResolver is AaveHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogBorrow(token, _amt, rateMode, getId, setId);
|
||||
// bytes32 _eventCode = keccak256("LogBorrow(address,uint256,uint256,uint256,uint256)");
|
||||
// bytes memory _eventParam = abi.encode(token, _amt, rateMode, getId, setId);
|
||||
// emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
|
@ -219,12 +232,10 @@ contract BasicResolver is AaveHelpers {
|
|||
setUint(setId, _amt);
|
||||
|
||||
emit LogPayback(token, _amt, rateMode, getId, setId);
|
||||
// bytes32 _eventCode = keccak256("LogPayback(address,uint256,uint256,uint256,uint256)");
|
||||
// bytes memory _eventParam = abi.encode(token, _amt, rateMode, getId, setId);
|
||||
// emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectAaveV2 is BasicResolver {
|
||||
string public name = "Aave-v2";
|
||||
}
|
||||
string public name = "AaveV2-v1.0";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user