-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_live.py
63 lines (52 loc) · 1.76 KB
/
test_live.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
import pytest
import brownie
from brownie import Wei, Contract, accounts
@pytest.mark.require_network("mainnet-fork")
def test_lending(
chain,
gov,
router,
vault,
bob,
alice,
weth,
protocolProvider,
lendingPool,
usdc,
weth_whale,
):
lp = lendingPool
# Approve delegation
variableToken = Contract(
protocolProvider.getReserveTokensAddresses(weth).dict()[
"variableDebtTokenAddress"
]
)
# Bob is all in!
variableToken.approveDelegation(router, 2 ** 256 - 1, {"from": bob})
# Alice is smarter. She doesn't trust us so much
variableToken.approveDelegation(router, Wei("1 ether"), {"from": alice})
# Add delegators
router.addDelegator(alice, {"from": gov})
router.addDelegator(bob, {"from": gov})
assert alice in router.delegators()
assert bob in router.delegators()
# Check our borrowing power!
print(f"Borrowing power is {router.ethBorrowingPower()/1e18}")
assert router.ethBorrowingPower() > Wei("2.70 ether")
# Invest the money
router.invest(Wei("2 ether"), {"from": gov})
# Travel to the future! 1W just in case
chain.sleep(604_800)
chain.mine(1)
# Harvest the strategy to make sure there are profits
vault = Contract("0xdCD90C7f6324cfa40d7169ef80b12031770B4325")
vault_gov = accounts.at(vault.governance(), force=True)
strategy = Contract(vault.withdrawalQueue(0))
print(f"Price per share before harvest: {vault.pricePerShare()}")
strategy.harvest({"from": vault_gov})
print(f"Price per share after harvest: {vault.pricePerShare()}")
# Stop the investment
router.withdraw({"from": gov})
# Make sure we made some money after returning the loan
assert router.profit() > Wei("0.001 ether")