-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest_sdvt_splitter_rewards_distribution.py
138 lines (97 loc) · 4.35 KB
/
test_sdvt_splitter_rewards_distribution.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
import pytest
from brownie import ZERO_ADDRESS
from utils.config import contracts
from utils.test.reward_wrapper_helpers import deploy_reward_wrapper, wrap_and_split_rewards
from utils.test.split_helpers import (
deploy_split_wallet,
get_split_percent_allocation,
get_split_percentage_scale,
split_and_withdraw_wsteth_rewards,
)
WEI_TOLERANCE = 5 # wei tolerance to avoid rounding issue
# fixtures
@pytest.fixture(scope="module")
def cluster_participants(accounts):
CLUSTER_PARTICIPANTS = 5
return sorted(map(lambda participant: participant.address, accounts[0:CLUSTER_PARTICIPANTS]))
@pytest.fixture(scope="module")
def split_percentage_scale():
return get_split_percentage_scale()
@pytest.fixture(scope="module")
def split_percent_allocation(cluster_participants, split_percentage_scale):
return get_split_percent_allocation(len(cluster_participants), split_percentage_scale)
@pytest.fixture(scope="module")
def split_wallet(cluster_participants, split_percent_allocation):
(deployed_contract, _) = deploy_split_wallet(
cluster_participants, split_percent_allocation, cluster_participants[0]
)
return deployed_contract
@pytest.fixture(scope="module")
def reward_wrapper(split_wallet, cluster_participants):
(deployed_contract, _) = deploy_reward_wrapper(split_wallet, cluster_participants[0])
return deployed_contract
def test_reward_wrapper_deploy(reward_wrapper, split_wallet):
"""
Test reward wrapper contract deployment
"""
connected_split_wallet = reward_wrapper.splitWallet()
assert connected_split_wallet == split_wallet.address
steth = reward_wrapper.stETH()
assert steth == contracts.lido.address
wsteth = reward_wrapper.wstETH()
assert wsteth == contracts.wsteth.address
fee_share = reward_wrapper.feeShare()
fee_recipient = reward_wrapper.feeRecipient()
with_fee = fee_share > 0 and fee_recipient != ZERO_ADDRESS
without_fee = fee_share == 0 and fee_recipient == ZERO_ADDRESS
assert with_fee or without_fee
def test_split_wallet_deploy(split_wallet):
"""
Test split wallet contract deployment
"""
assert split_wallet.splitMain() == contracts.split_main.address
# rewards wrapping tests
def test_wrap_rewards(accounts, reward_wrapper):
"""
Test rewards wrapping logic
Should wrap steth rewards to wsteth and split between dvt provider and split wallet
"""
steth = contracts.lido
steth_to_distribute = 1 * 10 ** contracts.lido.decimals()
stranger = accounts[0]
# get steth to distribute
eth_to_submit = steth_to_distribute + WEI_TOLERANCE
steth.submit(ZERO_ADDRESS, {"from": stranger, "value": eth_to_submit})
assert steth.balanceOf(stranger) >= steth_to_distribute
# transfer steth to wrapper contract
assert steth.balanceOf(reward_wrapper.address) == 0
steth.transfer(reward_wrapper.address, steth_to_distribute, {"from": stranger})
assert steth.balanceOf(reward_wrapper.address) >= steth_to_distribute - WEI_TOLERANCE
# wrap rewards and split between dvt provider and split wallet
wrap_and_split_rewards(reward_wrapper, stranger)
def test_split_rewards(accounts, split_wallet, cluster_participants, split_percent_allocation, split_percentage_scale):
"""
Test separate split wallet (instance of 0xSplit protocol) contract distribution logic
Should distribute wsteth rewards between participants according to split wallet shares
"""
wsteth = contracts.wsteth
stranger = accounts[0]
wsteth_to_distribute = 1 * 10 ** contracts.wsteth.decimals()
# check split wallet balance initial state
split_wallet_balance_before = wsteth.balanceOf(split_wallet)
assert split_wallet_balance_before == 0
# get required wsteth
eth_to_submit = wsteth.getStETHByWstETH(wsteth_to_distribute) + WEI_TOLERANCE
stranger.transfer(wsteth.address, eth_to_submit)
assert wsteth.balanceOf(stranger) >= wsteth_to_distribute
# transfer wsteth to split wallet contract
wsteth.transfer(split_wallet.address, wsteth_to_distribute, {"from": stranger})
assert wsteth.balanceOf(split_wallet.address) == wsteth_to_distribute
# split wsteth rewards between participants and withdraw
split_and_withdraw_wsteth_rewards(
split_wallet.address,
cluster_participants,
split_percent_allocation,
split_percentage_scale,
stranger,
)