-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrategy.sol
80 lines (55 loc) · 2.66 KB
/
Strategy.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
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol";
import {IPoolAddressesProvider} from "@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol";
import {IPool} from "@aave/core-v3/contracts/interfaces/IPool.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
// Address provider 0xeb7A892BB04A8f836bDEeBbf60897A7Af1Bf5d7F
contract Strategy is ERC4626 {
IPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
IPool public immutable aave;
IERC20 public bondasset;
constructor(ERC20 _asset, string memory _name, string memory _symbol,address _addressProvider,address _bondasset)ERC4626(_asset, _name, _symbol){
ADDRESSES_PROVIDER = IPoolAddressesProvider(_addressProvider);
aave = IPool(ADDRESSES_PROVIDER.getPool());
bondasset=IERC20(_bondasset);
}
function totalAssets() public view override returns(uint256){
return bondasset.balanceOf(address(this));
}
function sendDaiToAave(uint256 amount) internal {
aave.supply(address(asset),amount,address(this),0);
}
function _withdrawDaiFromAave(uint256 _amount) internal {
aave.withdraw(address(asset), _amount, msg.sender);
}
function approveDai(uint256 amount) internal{
asset.approve(address(aave),amount);
}
function deposit(uint256 assets, address receiver) public override returns (uint256 shares){
require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");
asset.transferFrom(msg.sender, address(this), assets);
approveDai(assets);
sendDaiToAave(assets);
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, assets, shares);
afterDeposit(assets, shares);
}
function redeem(
uint256 shares,
address receiver,
address owner
) public override returns (uint256 assets) {
if (msg.sender != owner) {
uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares;
}
require((assets = previewRedeem(shares)) != 0, "ZERO_ASSETS");
beforeWithdraw(assets, shares);
_withdrawDaiFromAave(assets);
_burn(owner, shares);
emit Withdraw(msg.sender, receiver, owner, assets, shares);
}
}