-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconftest.py
200 lines (149 loc) · 5.88 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
import pytest
from brownie import config
from brownie import Contract
import rlp
from eth_utils import keccak, to_checksum_address, to_bytes
@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 token():
token_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" # this should be the address of the ERC-20 used by the strategy/vault (wETH)
yield Contract(token_address)
@pytest.fixture
def amount(accounts, token, user, weth_whale):
amount = 10 * 10 ** token.decimals()
# In order to get some funds for the token you are about to use,
# it impersonate the weth whale to use its funds.
token.transfer(user, amount, {"from": weth_whale, "gas_price": "0"})
yield amount
@pytest.fixture
def weth():
token_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
yield Contract(token_address)
@pytest.fixture
def tweth():
token_address = "0xD3D13a578a53685B4ac36A1Bab31912D2B2A2F36"
yield Contract(token_address)
@pytest.fixture
def toke_token():
token_address = "0x2e9d63788249371f1DFC918a52f8d799F4a38C94"
yield Contract(token_address)
@pytest.fixture
def tokemak_manager():
address = "0xA86e412109f77c45a3BC1c5870b880492Fb86A14"
yield Contract(address)
@pytest.fixture
def tokemak_eth_pool():
address = "0xD3D13a578a53685B4ac36A1Bab31912D2B2A2F36"
yield Contract(address)
@pytest.fixture
def weth_whale(accounts):
# AAVE wETH pool
yield accounts.at("0x030bA81f1c18d280636F32af80b9AAd02Cf0854e", force=True)
@pytest.fixture
def toke_whale(accounts):
# tokemak treasury
yield accounts.at("0x8b4334d4812c530574bd4f2763fcd22de94a969b", force=True)
@pytest.fixture
def account_with_tokemak_rollover_role(accounts):
# this account should have the role to allow them to call the Tokemak rollover contract
yield accounts.at("0x9e0bcE7ec474B481492610eB9dd5D69EB03718D5", force=True)
@pytest.fixture
def tokemak_multisig(accounts):
# this account should be the owner of the eth pool
yield accounts.at("0x90b6c61b102ea260131ab48377e143d6eb3a9d4b", force=True)
@pytest.fixture
def weth_amount(user, weth):
weth_amount = 10 ** weth.decimals()
user.transfer(weth, weth_amount)
yield weth_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, {"from": gov})
vault.setDepositLimit(2 ** 256 - 1, {"from": gov})
vault.setManagement(management, {"from": gov})
yield vault
@pytest.fixture
def trade_factory():
yield Contract("0x99d8679bE15011dEAD893EB4F5df474a4e6a8b29")
@pytest.fixture
def ymechs_safe():
yield Contract("0x2C01B4AD51a67E2d8F02208F54dF9aC4c0B778B6")
# @pytest.fixture
# def sushi_swapper(trade_factory, ymechs_safe):
# swapper = Contract("0x55dcee9332848AFcF660CE6a2116D83Dd7a71B60")
# trade_factory.addSwappers([swapper], {"from": ymechs_safe})
#
# yield swapper
@pytest.fixture(scope="module")
def sushiswap_router(Contract):
yield Contract("0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F")
@pytest.fixture(scope="module")
def multicall_swapper(interface):
yield interface.MultiCallOptimizedSwapper(
#"0xceB202F25B50e8fAF212dE3CA6C53512C37a01D2"
"0xB2F65F254Ab636C96fb785cc9B4485cbeD39CDAA"
)
@pytest.fixture
def strategy(standalone_strategy, vault, Strategy, gov):
strategy = standalone_strategy
vault.addStrategy(strategy, 10_000, 0, 2 ** 256 - 1, 1_000, {"from": gov})
yield strategy
# strategy with no debt allocation
@pytest.fixture
def standalone_strategy(strategist, keeper, vault, trade_factory, Strategy, gov, ymechs_safe, utils):
strategy = strategist.deploy(Strategy, vault)
strategy.setKeeper(keeper, {"from": gov})
utils.prepare_trade_factory(strategy, trade_factory, ymechs_safe, gov)
yield strategy
@pytest.fixture(scope="session")
def RELATIVE_APPROX():
yield 1e-5
@pytest.fixture
def tokemak_weth_pool():
yield Contract("0xD3D13a578a53685B4ac36A1Bab31912D2B2A2F36")
@pytest.fixture
def utils(chain, tokemak_manager, account_with_tokemak_rollover_role):
return Utils(chain, tokemak_manager, account_with_tokemak_rollover_role)
class Utils:
def __init__(self, chain, tokemak_manager, account_with_tokemak_rollover_role):
self.chain = chain
self.tokemak_manager = tokemak_manager
self.account_with_tokemak_rollover_role = account_with_tokemak_rollover_role
def mock_one_day_passed(self):
self.chain.sleep(3600 * 24)
cycle_duration = self.tokemak_manager.getCycleDuration()
self.chain.mine(cycle_duration + 100)
self.tokemak_manager.completeRollover("DmTzdi7eC9SM5FaZCzaMpfwpuTt2gXZircVsZUA3DPXWqv", {"from": self.account_with_tokemak_rollover_role})
def make_funds_withdrawable_from_tokemak(self, strategy, amount):
strategy.requestWithdrawal(amount)
# Tokemak has 1 day timelock for withdrawals
self.mock_one_day_passed()
def move_user_funds_to_vault(self, user, vault, token, amount):
token.approve(vault.address, amount, {"from": user})
vault.deposit(amount, {"from": user})
assert token.balanceOf(vault.address) == amount
def prepare_trade_factory(self, strategy, trade_factory, ymechs_safe, gov):
trade_factory.grantRole(trade_factory.STRATEGY(), strategy.address, {"from": ymechs_safe, "gas_price": "0 gwei"})
strategy.setTradeFactory(trade_factory.address, {"from": gov})