1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^ 0.8.9 ;
4
+
5
+ import "@openzeppelin/contracts/access/Ownable.sol " ;
6
+ import "https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPool.sol " ;
7
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol " ;
8
+ import "./interfaces/IVault.sol " ;
9
+
10
+ contract Vault is Ownable , IVault {
11
+ address public GHO_TOKEN_ADDRESS = 0xc4bF5CbDaBE595361438F8c6a187bDc330539c60 ;
12
+ address public AAVE_POOL_ADDRESS = 0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf ;
13
+
14
+ address public WETH_TOKEN_ADDRESS = 0xc558dbdd856501fcd9aaf1e62eae57a9f0629a3c ;
15
+ address public USDC_TOKEN_ADDRESS = 0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8 ;
16
+ address public EURS_TOKEN_ADDRESS = 0x6d906e526a4e2ca02097ba9d0caa3c382f52278e ;
17
+ address public LINK_TOKEN_ADDRESS = 0xf8fb3713d459d7c1018bd0a49d19b4c44290ebe5 ;
18
+
19
+ IPool internal constant aaveV3Pool = IPool (0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951 );
20
+
21
+ mapping (address => uint256 ) public pointsBalances;
22
+
23
+ boolean public withdrawAllowed = false ;
24
+
25
+ address [] listOfAllowedTokens;
26
+
27
+ constructor (
28
+ address _USDC_TOKEN_ADDRESS ,
29
+ address _EURS_TOKEN_ADDRESS ,
30
+ address _LINK_TOKEN_ADDRESS ,
31
+ address _WETH_TOKEN_ADDRESS
32
+ ) Ownable (msg .sender ) {
33
+ listOfAllowedTokens.push (_USDC_TOKEN_ADDRESS);
34
+ listOfAllowedTokens.push (_EURS_TOKEN_ADDRESS);
35
+ listOfAllowedTokens.push (_LINK_TOKEN_ADDRESS);
36
+ listOfAllowedTokens.push (_WETH_TOKEN_ADDRESS);
37
+ }
38
+
39
+ function setGHOAddress (address _tokenAddress ) external onlyOwner {
40
+ GHO_TOKEN_ADDRESS = _tokenAddress;
41
+ }
42
+
43
+ function setAAVEPoolAddress (address _poolAddress ) external onlyOwner {
44
+ AAVE_POOL_ADDRESS = _poolAddress;
45
+ }
46
+
47
+ // Risk Management
48
+ function setWithdrawAllowed (bool _withdrawAllowed ) external onlyOwner {
49
+ withdrawAllowed = _withdrawAllowed;
50
+ }
51
+
52
+ function addCollateral (address _token , uint256 _amount ) external {
53
+ aaveV3Pool.deposit (_token, _amount, address (this ), 0 );
54
+ }
55
+
56
+ // Todo: Use WETHGateway to send non weth tokens to AAVE
57
+ function addCollateralToAAVEPool (uint256 _amount , address _tokenAddress ) external {
58
+ require (_amount > 0 , "Amount must be greater than 0 " );
59
+ require (isTokenAllowed (_tokenAddress), "Token not allowed " );
60
+ require (IERC20 (_tokenAddress).balanceOf (msg .sender ) >= _amount, "Not enough balance " );
61
+ require (IERC20 (_tokenAddress).allowance (msg .sender , address (this )) >= _amount, "Not enough allowance " );
62
+
63
+ IERC20 (_tokenAddress).transferFrom (msg .sender , address (this ), _amount);
64
+ IERC20 (_tokenAddress).approve (AAVE_POOL_ADDRESS, _amount);
65
+
66
+ aaveV3Pool.deposit (_tokenAddress, _amount, address (this ), 0 );
67
+ }
68
+
69
+ function exchangePointsForGHO (uint256 _amount ) external {
70
+ require (pointsBalances[msg .sender ] >= _amount, "Not enough points " );
71
+ pointsBalances[msg .sender ] -= _amount;
72
+ IERC20 (GHO_TOKEN_ADDRESS).transfer (msg .sender , _amount);
73
+ }
74
+
75
+ // function depositETH() external payable {
76
+ // IWETH(WETH_TOKEN_ADDRESS).deposit{value: msg.value}();
77
+ // }
78
+
79
+ function borrowAaveGHO (
80
+ uint256 amount
81
+ ) internal {
82
+ // use interest rate as 1 for stable
83
+ aaveV3Pool.borrow (GHO_TOKEN_ADDRESS, amount, 1 , 0 , address (this ));
84
+ }
85
+
86
+ function withdrawGHOFromContract (uint256 _amount ) external onlyOwner {
87
+ IERC20 (GHO_TOKEN_ADDRESS).transfer (msg .sender , _amount);
88
+ }
89
+
90
+ function getGHOBalance () external view returns (uint256 ) {
91
+ return IERC20 (GHO_TOKEN_ADDRESS).balanceOf (address (this ));
92
+ }
93
+
94
+ function getWETHBalance () external view returns (uint256 ) {
95
+ return IERC20 (WETH_TOKEN_ADDRESS).balanceOf (address (this ));
96
+ }
97
+
98
+ function getAAVEPoolAddress () external view returns (address ) {
99
+ return AAVE_POOL_ADDRESS;
100
+ }
101
+
102
+ function getUserBalance (address _user ) external view returns (uint256 ) {
103
+ return pointsBalances[_user];
104
+ }
105
+
106
+ function getGHOAddress () external view returns (address ) {
107
+ return GHO_TOKEN_ADDRESS;
108
+ }
109
+
110
+ function isTokenAllowed (address _tokenAddress ) internal view returns (bool ) {
111
+ for (uint i = 0 ; i < listOfAllowedTokens.length ; i++ ) {
112
+ if (listOfAllowedTokens[i] == _tokenAddress) {
113
+ return true ;
114
+ }
115
+ }
116
+ return false ;
117
+ }
118
+ }
0 commit comments