-
Notifications
You must be signed in to change notification settings - Fork 1
/
aaveInteractor.sol
69 lines (59 loc) · 1.88 KB
/
aaveInteractor.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: agpl-3.0
pragma solidity >=0.6.0 <0.8.0;
import "./aave/ILendingPoolAddressesProvider.sol";
import "./aave/ILendingPool.sol";
import "./openzepplin/ERC20.sol";
import "./openzepplin/SafeMath.sol";
contract AaveInteractor {
using SafeMath for uint256;
ILendingPoolAddressesProvider public provider = ILendingPoolAddressesProvider(0xd05e3E715d945B59290df0ae8eF85c1BdB684744);
ILendingPool public aPool = ILendingPool(provider.getLendingPool());
/*
constructor(uint256 _lendingPoolAddress) public {
provider = ILendingPoolAddressesProvider(_lendingPoolAddress);
aPool = ILendingPool(provider.getLendingPool());
}
*/
function aDeposit(ERC20 _token, uint256 _amount) external {
if(_amount != 0) {
_token.approve(address(aPool), _amount);
aPool.deposit(address(_token), _amount, address(this), 0);
}
}
function aWithdraw(
ERC20 _token,
uint256 _amount,
bool _withAll
) external {
if (_withAll) {
aPool.withdraw(address(_token), type(uint256).max, address(this));
} else {
aPool.withdraw(address(_token), _amount, address(this));
}
}
function aBorrow(
ERC20 _token,
uint256 _amount,
uint256 _debtType
) external {
aPool.borrow(address(_token), _amount, _debtType, 0, address(this));
}
function aRepay(
ERC20 _token,
uint256 _amount,
uint256 _debtType,
bool _repayAll
) external {
_token.approve(address(aPool), _amount);
if (_repayAll) {
aPool.repay(
address(aPool),
type(uint256).max,
_debtType,
address(this)
);
} else {
aPool.repay(address(aPool), _amount, _debtType, address(this));
}
}
}