forked from dudesahn/StrategyCurveTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_simple_harvest.py
132 lines (110 loc) · 3.71 KB
/
test_simple_harvest.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
import brownie
from brownie import Contract
from brownie import config
import math
def test_simple_harvest(
gov,
token,
vault,
strategist,
whale,
strategy,
chain,
strategist_ms,
gauge,
voter,
amount,
):
## deposit to the vault after approving
startingWhale = token.balanceOf(whale)
token.approve(vault, 2 ** 256 - 1, {"from": whale})
vault.deposit(amount, {"from": whale})
newWhale = token.balanceOf(whale)
# this is part of our check into the staking contract balance
stakingBeforeHarvest = gauge.balanceOf(voter)
# harvest, store asset amount
chain.sleep(1)
strategy.harvest({"from": gov})
chain.sleep(1)
old_assets = vault.totalAssets()
assert old_assets > 0
assert token.balanceOf(strategy) == 0
assert strategy.estimatedTotalAssets() > 0
print("\nStarting Assets: ", old_assets / 1e18)
# try and include custom logic here to check that funds are in the staking contract (if needed)
assert gauge.balanceOf(voter) > stakingBeforeHarvest
# simulate 1 day of earnings
chain.sleep(86400)
chain.mine(1)
# harvest, store new asset amount
chain.sleep(1)
strategy.harvest({"from": gov})
chain.sleep(1)
new_assets = vault.totalAssets()
# confirm we made money, or at least that we have about the same
assert new_assets >= old_assets
print("\nAssets after 1 day: ", new_assets / 1e18)
# Display estimated APR
print(
"\nEstimated DAI APR: ",
"{:.2%}".format(
((new_assets - old_assets) * (365)) / (strategy.estimatedTotalAssets())
),
)
# change our optimal deposit asset
strategy.setOptimal(1, {"from": gov})
# store asset amount
before_usdc_assets = vault.totalAssets()
assert token.balanceOf(strategy) == 0
# try and include custom logic here to check that funds are in the staking contract (if needed)
assert gauge.balanceOf(voter) > 0
# simulate 1 day of earnings
chain.sleep(86400)
chain.mine(1)
# harvest, store new asset amount
chain.sleep(1)
strategy.harvest({"from": gov})
chain.sleep(1)
after_usdc_assets = vault.totalAssets()
# confirm we made money, or at least that we have about the same
assert after_usdc_assets >= before_usdc_assets
# Display estimated APR
print(
"\nEstimated USDC APR: ",
"{:.2%}".format(
((after_usdc_assets - before_usdc_assets) * (365))
/ (strategy.estimatedTotalAssets())
),
)
# change our optimal deposit asset
strategy.setOptimal(2, {"from": gov})
# store asset amount
before_usdt_assets = vault.totalAssets()
assert token.balanceOf(strategy) == 0
assert strategy.estimatedTotalAssets() > 0
# try and include custom logic here to check that funds are in the staking contract (if needed)
assert gauge.balanceOf(voter) > 0
# simulate 1 day of earnings
chain.sleep(86400)
chain.mine(1)
# harvest, store new asset amount
chain.sleep(1)
strategy.harvest({"from": gov})
chain.sleep(1)
after_usdt_assets = vault.totalAssets()
# confirm we made money, or at least that we have about the same
assert after_usdt_assets >= before_usdt_assets
# Display estimated APR
print(
"\nEstimated USDT APR: ",
"{:.2%}".format(
((after_usdt_assets - before_usdt_assets) * (365))
/ (strategy.estimatedTotalAssets())
),
)
# simulate a day of waiting for share price to bump back up
chain.sleep(86400)
chain.mine(1)
# withdraw and confirm we made money, or at least that we have about the same
vault.withdraw({"from": whale})
assert token.balanceOf(whale) >= startingWhale