-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
265 lines (195 loc) · 5.33 KB
/
conftest.py
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import time
from brownie import (
MyStrategy,
TheVault,
MockRewardDistributor,
MockBribesProcessor,
interface,
accounts,
chain,
Contract
)
from _setup.config import (
WANT,
WHALE_ADDRESS,
BAL_WHALE,
PERFORMANCE_FEE_GOVERNANCE,
PERFORMANCE_FEE_STRATEGIST,
WITHDRAWAL_FEE,
MANAGEMENT_FEE,
)
from helpers.constants import MaxUint256
from rich.console import Console
console = Console()
from dotmap import DotMap
import pytest
## Accounts ##
@pytest.fixture
def deployer():
return accounts[0]
@pytest.fixture
def user():
return accounts[9]
@pytest.fixture
def delegation_registry():
return Contract.from_explorer("0x469788fE6E9E9681C6ebF3bF78e7Fd26Fc015446")
## Fund the account
@pytest.fixture
def want(deployer):
"""
TODO: Customize this so you have the token you need for the strat
"""
TOKEN_ADDRESS = WANT
token = interface.IERC20Detailed(TOKEN_ADDRESS)
WHALE = accounts.at(WHALE_ADDRESS, force=True) ## Address with tons of token
token.transfer(deployer, token.balanceOf(WHALE), {"from": WHALE})
return token
@pytest.fixture
def strategist():
return accounts[1]
@pytest.fixture
def keeper():
return accounts[2]
@pytest.fixture
def guardian():
return accounts[3]
@pytest.fixture
def governance():
return accounts[4]
@pytest.fixture
def treasury():
return accounts[5]
@pytest.fixture
def proxyAdmin():
return accounts[6]
@pytest.fixture
def randomUser():
return accounts[7]
@pytest.fixture
def badgerTree():
return accounts[8]
@pytest.fixture
def deployed(
want,
deployer,
strategist,
keeper,
guardian,
governance,
proxyAdmin,
randomUser,
badgerTree,
):
"""
Deploys, vault and test strategy, mock token and wires them up.
"""
want = want
vault = TheVault.deploy({"from": deployer})
vault.initialize(
want,
governance,
keeper,
guardian,
governance,
strategist,
badgerTree,
"",
"",
[
PERFORMANCE_FEE_GOVERNANCE,
PERFORMANCE_FEE_STRATEGIST,
WITHDRAWAL_FEE,
MANAGEMENT_FEE,
],
)
strategy = MyStrategy.deploy({"from": deployer})
strategy.initialize(vault)
# NOTE: Strategy starts unpaused
vault.setStrategy(strategy, {"from": governance})
return DotMap(
deployer=deployer,
vault=vault,
strategy=strategy,
want=want,
governance=governance,
proxyAdmin=proxyAdmin,
randomUser=randomUser,
performanceFeeGovernance=PERFORMANCE_FEE_GOVERNANCE,
performanceFeeStrategist=PERFORMANCE_FEE_STRATEGIST,
withdrawalFee=WITHDRAWAL_FEE,
managementFee=MANAGEMENT_FEE,
badgerTree=badgerTree,
)
## Contracts ##
@pytest.fixture
def vault(deployed):
return deployed.vault
@pytest.fixture
def strategy(deployed):
return deployed.strategy
@pytest.fixture
def tokens(deployed):
return [deployed.want]
@pytest.fixture
def locker(strategy):
return interface.IAuraLocker(strategy.LOCKER())
### Fees ###
@pytest.fixture
def performanceFeeGovernance(deployed):
return deployed.performanceFeeGovernance
@pytest.fixture
def performanceFeeStrategist(deployed):
return deployed.performanceFeeStrategist
@pytest.fixture
def withdrawalFee(deployed):
return deployed.withdrawalFee
@pytest.fixture
def auraStakingProxy():
return interface.IAuraStakingProxy("0xd9e863B7317a66fe0a4d2834910f604Fd6F89C6c")
@pytest.fixture
def setup_share_math(deployer, vault, want, governance):
depositAmount = int(want.balanceOf(deployer) * 0.5)
assert depositAmount > 0
want.approve(vault.address, MaxUint256, {"from": deployer})
vault.deposit(depositAmount, {"from": deployer})
vault.earn({"from": governance})
return DotMap(depositAmount=depositAmount)
@pytest.fixture
def setup_strat(governance, deployer, vault, strategy, want):
"""
Convenience fixture that depoists and harvests for us
"""
# Setup
startingBalance = want.balanceOf(deployer)
depositAmount = startingBalance // 2
assert startingBalance >= depositAmount
assert startingBalance >= 0
# End Setup
# Deposit
assert want.balanceOf(vault) == 0
want.approve(vault, MaxUint256, {"from": deployer})
vault.deposit(depositAmount, {"from": deployer})
available = vault.available()
assert available > 0
vault.earn({"from": governance})
chain.sleep(1000 * 13) # Mine so we get some interest
return strategy
@pytest.fixture(autouse=True)
def distribute_auraBal(strategy, auraStakingProxy):
bal = interface.IERC20Detailed(strategy.BAL())
bal.transfer(auraStakingProxy, 10e18, {"from": BAL_WHALE})
# auraStakingProxy.setKeeper(keeper, {"from": })
# auraStakingProxy.distribute(1, {'from': keeper})
auraStakingProxy.distribute({'from': auraStakingProxy.keeper()})
@pytest.fixture
def reward_distributor(deployer):
return MockRewardDistributor.deploy({"from": deployer})
@pytest.fixture
def bribes_processor(deployer, strategy, governance):
processor = MockBribesProcessor.deploy({"from": deployer})
strategy.setBribesProcessor(processor, {"from": governance})
return processor
## Forces reset before each test
@pytest.fixture(autouse=True)
def isolation(fn_isolation):
pass