Skip to content

Commit e1208a6

Browse files
committed
Adding the vault contract
1 parent 158db84 commit e1208a6

File tree

2 files changed

+135
-19
lines changed

2 files changed

+135
-19
lines changed

contracts/contracts/Vault.sol

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
}
Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
32

4-
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5-
import "@openzeppelin/contracts/access/Ownable.sol";
6-
import "./ILeaderboard.sol";
7-
8-
interface IVault is ILeaderboard, IERC20, Ownable {
9-
event PoolCreated(address indexed token, uint256 amount, uint256 poolAmount);
10-
11-
function depositToVault(address _token, uint256 _amount) external;
12-
13-
function createPool(address _token, address eventAddress, uint256 _amount) external;
14-
15-
function withdrawFromVault(address _token, uint256 _amount, address eventAddress) external;
3+
pragma solidity ^0.8.9;
164

17-
function withdrawFromPool(address _token, address eventAddress) external;
18-
19-
function getPoolAmount(address eventAddress) external view returns (uint256);
20-
21-
function getAllPools() external view returns (address[] memory);
5+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
226

23-
function addPaymentToken(IERC20 _token) external;
7+
interface IVault {
8+
function setGHOAddress(address _tokenAddress) external;
9+
function setAAVEPoolAddress(address _poolAddress) external;
10+
function setWithdrawAllowed(bool _withdrawAllowed) external;
11+
function addCollateral(address _token, uint256 _amount) external;
12+
function addCollateralToAAVEPool(uint256 _amount, address _tokenAddress) external;
13+
function exchangePointsForGHO(uint256 _amount) external;
14+
// function depositETH() external payable;
15+
function withdrawGHOFromContract(uint256 _amount) external;
16+
function getGHOBalance() external view returns (uint256);
17+
function getWETHBalance() external view returns (uint256);
18+
function getAAVEPoolAddress() external view returns (address);
19+
function getUserBalance(address _user) external view returns (uint256);
20+
function getGHOAddress() external view returns (address);
2421
}
22+

0 commit comments

Comments
 (0)