-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAave.sol
68 lines (53 loc) · 2.27 KB
/
Aave.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
pragma solidity ^0.6.0;
import "./IERC20.sol";
import "https://github.com/aave/protocol-v2/blob/master/contracts/interfaces/ILendingPool.sol";
contract Aave {
ILendingPool pool = ILendingPool(0xE0fBa4Fc209b4948668006B2bE61711b7f465bAe);
address payable owner;
constructor() public {
owner = msg.sender;
}
modifier OnlyOwner {
require(msg.sender == owner, "Acesso denegado");
_;
}
function deposit(address asset, uint amount) public OnlyOwner {
IERC20(asset).approve(address(pool), amount);
pool.deposit(asset, amount, address(this), 0);
}
function depositAll(address asset) public OnlyOwner {
uint balance = IERC20(asset).balanceOf(address(this));
IERC20(asset).approve(address(pool), balance);
pool.deposit(asset, balance, address(this), 0);
}
function withdraw(address asset, address aAsset, uint amount) public OnlyOwner {
IERC20(aAsset).approve(address(pool), amount);
pool.withdraw(asset, amount, address(this));
}
function withdrawAll(address asset, address aAsset) public OnlyOwner {
uint balance = IERC20(aAsset).balanceOf(address(this));
IERC20(aAsset).approve(address(pool), balance);
pool.withdraw(asset, balance, address(this));
}
function borrow(address asset, uint amount) public OnlyOwner {
pool.borrow(asset, amount, 1, 0, address(this));
(,,,,,uint healthFactor) = pool.getUserAccountData(address(this));
require(healthFactor >= 2e18);
}
function repay(address asset, uint amount) public OnlyOwner {
IERC20(asset).approve(address(pool), amount);
pool.repay(asset, amount, 1, address(this));
}
function repayAll(address debtAsset, address asset) public OnlyOwner {
uint balance = IERC20(debtAsset).balanceOf(address(this));
IERC20(asset).approve(address(pool), balance);
pool.repay(asset, balance, 1, address(this));
}
function withdrawFunds(address asset, uint amount) public OnlyOwner {
IERC20(asset).transfer(msg.sender, amount);
}
function withdrawAllFunds(address asset) public OnlyOwner {
uint balance = IERC20(asset).balanceOf(address(this));
IERC20(asset).transfer(msg.sender, balance);
}
}