-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
212 lines (159 loc) · 5.13 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
import pytest
from brownie import config
from brownie import Contract
@pytest.fixture
def gov(accounts):
yield accounts.at("0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52", force=True)
@pytest.fixture
def user(accounts):
yield accounts[0]
@pytest.fixture
def rewards(accounts):
yield accounts[1]
@pytest.fixture
def guardian(accounts):
yield accounts[2]
@pytest.fixture
def management(accounts):
yield accounts[3]
@pytest.fixture
def strategist(accounts):
yield accounts[4]
@pytest.fixture
def keeper(accounts):
yield accounts[5]
@pytest.fixture
def rando(accounts):
yield accounts[9]
token_addresses = {
"WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", # WBTC
"WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", # WETH
"USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7", # USDT
"DAI": "0x6B175474E89094C44Da98b954EedeAC495271d0F", # DAI
"USDC": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", # USDC
}
# TODO: uncomment those tokens you want to test as want
@pytest.fixture(
params=[
"WBTC", # WBTC
"WETH", # WETH
"USDT", # USDT
"DAI", # DAI
"USDC", # USDC
],
scope="session",
autouse=True,
)
def token(request):
yield Contract(token_addresses[request.param])
whale_addresses = {
"WBTC": "0xbf72da2bd84c5170618fbe5914b0eca9638d5eb5",
"WETH": "0x2f0b23f53734252bda2277357e97e1517d6b042a",
"USDT": "0x47ac0Fb4F2D84898e4D9E7b4DaB3C24507a6D503",
"DAI": "0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7",
"USDC": "0x0a59649758aa4d66e25f08dd01271e891fe52199",
}
@pytest.fixture(scope="session", autouse=True)
def token_whale(accounts, token):
yield accounts.at(whale_addresses[token.symbol()], force=True)
token_prices = {
"WBTC": 35_000,
"WETH": 2_000,
"USDT": 1,
"USDC": 1,
"DAI": 1,
}
@pytest.fixture(autouse=True)
def amount(token, token_whale, user):
# this will get the number of tokens (around $1m worth of token)
amillion = round(1_000_000 / token_prices[token.symbol()])
amount = amillion * 10 ** token.decimals()
# # In order to get some funds for the token you are about to use,
# # it impersonate a whale address
if amount > token.balanceOf(token_whale):
amount = token.balanceOf(token_whale)
token.transfer(user, amount, {"from": token_whale})
yield amount
aave_pool_token_addresses = {
"WBTC": "0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656", # aWBTC
"WETH": "0x030bA81f1c18d280636F32af80b9AAd02Cf0854e", # aWETH
"USDT": "0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811", # aUSDT
"DAI": "0x028171bCA77440897B824Ca71D1c56caC55b68A3", # aDAI
"USDC": "0xBcca60bB61934080951369a648Fb03DF4F96263C", # aUSDC
}
@pytest.fixture(scope="session", autouse=True)
def pool_token(token):
yield aave_pool_token_addresses[token.symbol()]
@pytest.fixture
def trade_factory():
yield Contract("0x7BAF843e06095f68F4990Ca50161C2C4E4e01ec6")
@pytest.fixture
def ymechs_safe():
yield Contract("0x2C01B4AD51a67E2d8F02208F54dF9aC4c0B778B6")
@pytest.fixture
def morpho_token(interface):
token_address = "0x9994E35Db50125E0DF82e4c2dde62496CE330999"
yield interface.IERC20(token_address)
@pytest.fixture
def weth():
yield Contract(token_addresses["WETH"])
@pytest.fixture
def weth_amount(user, weth):
weth_amount = 10 ** weth.decimals()
user.transfer(weth, weth_amount)
yield weth_amount
@pytest.fixture
def usdt():
yield Contract(token_addresses["USDT"])
@pytest.fixture
def usdt_amount(accounts, usdt, user):
amount = 10_000 * 10 ** usdt.decimals()
# In order to get some funds for the token you are about to use,
# it impersonate an exchange address to use it's funds.
reserve = accounts.at(whale_addresses["USDT"], force=True)
usdt.transfer(user, amount, {"from": reserve})
yield amount
@pytest.fixture
def vault(pm, gov, rewards, guardian, management, token):
Vault = pm(config["dependencies"][0]).Vault
vault = guardian.deploy(Vault)
vault.initialize(token, gov, rewards, "", "", guardian, management)
vault.setDepositLimit(2**256 - 1, {"from": gov})
vault.setManagement(management, {"from": gov})
vault.setManagementFee(0, {"from": gov})
yield vault
@pytest.fixture
def strategy(
strategist,
keeper,
vault,
pool_token,
MorphoAaveStrategy,
gov,
trade_factory,
ymechs_safe,
token,
):
strategy = strategist.deploy(
MorphoAaveStrategy,
vault,
pool_token,
"StrategyMorphoAave" + token.symbol(),
)
strategy.setKeeper(keeper)
vault.addStrategy(strategy, 10_000, 0, 2**256 - 1, 1_000, {"from": gov})
trade_factory.grantRole(
trade_factory.STRATEGY(),
strategy.address,
{"from": ymechs_safe, "gas_price": "0 gwei"},
)
strategy.setTradeFactory(trade_factory.address, {"from": gov})
yield strategy
@pytest.fixture(scope="session")
def RELATIVE_APPROX():
yield 1e-5
# Function scoped isolation fixture to enable xdist.
# Snapshots the chain before each test and reverts after test completion.
@pytest.fixture(scope="function", autouse=True)
def shared_setup(fn_isolation):
pass