forked from yearn/brownie-strategy-mix
-
Notifications
You must be signed in to change notification settings - Fork 9
/
MyStrategy.sol
201 lines (165 loc) · 6.89 KB
/
MyStrategy.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.11;
pragma experimental ABIEncoderV2;
import "../deps/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../deps/@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
import "../deps/@openzeppelin/contracts-upgradeable/math/MathUpgradeable.sol";
import "../deps/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "../deps/@openzeppelin/contracts-upgradeable/token/ERC20/SafeERC20Upgradeable.sol";
import "../interfaces/badger/IController.sol";
import {BaseStrategy} from "../deps/BaseStrategy.sol";
contract MyStrategy is BaseStrategy {
using SafeERC20Upgradeable for IERC20Upgradeable;
using AddressUpgradeable for address;
using SafeMathUpgradeable for uint256;
// address public want // Inherited from BaseStrategy, the token the strategy wants, swaps into and tries to grow
address public lpComponent; // Token we provide liquidity with
address public reward; // Token we farm and swap to want / lpComponent
// Used to signal to the Badger Tree that rewards where sent to it
event TreeDistribution(
address indexed token,
uint256 amount,
uint256 indexed blockNumber,
uint256 timestamp
);
function initialize(
address _governance,
address _strategist,
address _controller,
address _keeper,
address _guardian,
address[3] memory _wantConfig,
uint256[3] memory _feeConfig
) public initializer {
__BaseStrategy_init(
_governance,
_strategist,
_controller,
_keeper,
_guardian
);
/// @dev Add config here
want = _wantConfig[0];
lpComponent = _wantConfig[1];
reward = _wantConfig[2];
performanceFeeGovernance = _feeConfig[0];
performanceFeeStrategist = _feeConfig[1];
withdrawalFee = _feeConfig[2];
/// @dev do one off approvals here
// IERC20Upgradeable(want).safeApprove(gauge, type(uint256).max);
}
/// ===== View Functions =====
// @dev Specify the name of the strategy
function getName() external pure override returns (string memory) {
return "StrategyName";
}
// @dev Specify the version of the Strategy, for upgrades
function version() external pure returns (string memory) {
return "1.0";
}
/// @dev Balance of want currently held in strategy positions
function balanceOfPool() public view override returns (uint256) {
return 0;
}
/// @dev Returns true if this strategy requires tending
function isTendable() public view override returns (bool) {
return true;
}
// @dev These are the tokens that cannot be moved except by the vault
function getProtectedTokens()
public
view
override
returns (address[] memory)
{
address[] memory protectedTokens = new address[](3);
protectedTokens[0] = want;
protectedTokens[1] = lpComponent;
protectedTokens[2] = reward;
return protectedTokens;
}
/// ===== Internal Core Implementations =====
/// @dev security check to avoid moving tokens that would cause a rugpull, edit based on strat
function _onlyNotProtectedTokens(address _asset) internal override {
address[] memory protectedTokens = getProtectedTokens();
for (uint256 x = 0; x < protectedTokens.length; x++) {
require(
address(protectedTokens[x]) != _asset,
"Asset is protected"
);
}
}
/// @dev invest the amount of want
/// @notice When this function is called, the controller has already sent want to this
/// @notice Just get the current balance and then invest accordingly
function _deposit(uint256 _amount) internal override {}
/// @dev utility function to withdraw everything for migration
function _withdrawAll() internal override {}
/// @dev withdraw the specified amount of want, liquidate from lpComponent to want, paying off any necessary debt for the conversion
function _withdrawSome(uint256 _amount)
internal
override
returns (uint256)
{
return _amount;
}
/// @dev Harvest from strategy mechanics, realizing increase in underlying position
function harvest() external whenNotPaused returns (uint256 harvested) {
_onlyAuthorizedActors();
uint256 _before = IERC20Upgradeable(want).balanceOf(address(this));
// Write your code here
uint256 earned =
IERC20Upgradeable(want).balanceOf(address(this)).sub(_before);
/// @notice Keep this in so you get paid!
(uint256 governancePerformanceFee, uint256 strategistPerformanceFee) =
_processRewardsFees(earned, want);
// TODO: If you are harvesting a reward token you're not compounding
// You probably still want to capture fees for it
// // Process Sushi rewards if existing
// if (sushiAmount > 0) {
// // Process fees on Sushi Rewards
// // NOTE: Use this to receive fees on the reward token
// _processRewardsFees(sushiAmount, SUSHI_TOKEN);
// // Transfer balance of Sushi to the Badger Tree
// // NOTE: Send reward to badgerTree
// uint256 sushiBalance = IERC20Upgradeable(SUSHI_TOKEN).balanceOf(address(this));
// IERC20Upgradeable(SUSHI_TOKEN).safeTransfer(badgerTree, sushiBalance);
//
// // NOTE: Signal the amount of reward sent to the badger tree
// emit TreeDistribution(SUSHI_TOKEN, sushiBalance, block.number, block.timestamp);
// }
/// @dev Harvest event that every strategy MUST have, see BaseStrategy
emit Harvest(earned, block.number);
/// @dev Harvest must return the amount of want increased
return earned;
}
// Alternative Harvest with Price received from harvester, used to avoid exessive front-running
function harvest(uint256 price)
external
whenNotPaused
returns (uint256 harvested)
{}
/// @dev Rebalance, Compound or Pay off debt here
function tend() external whenNotPaused {
_onlyAuthorizedActors();
}
/// ===== Internal Helper Functions =====
/// @dev used to manage the governance and strategist fee on earned rewards, make sure to use it to get paid!
function _processRewardsFees(uint256 _amount, address _token)
internal
returns (uint256 governanceRewardsFee, uint256 strategistRewardsFee)
{
governanceRewardsFee = _processFee(
_token,
_amount,
performanceFeeGovernance,
IController(controller).rewards()
);
strategistRewardsFee = _processFee(
_token,
_amount,
performanceFeeStrategist,
strategist
);
}
}