forked from harmony-one-vdao/validator_vote_node_info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoting.py
173 lines (143 loc) · 5.96 KB
/
voting.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
from core.common import *
from core.smartstake_connect import find_smartstakeid
# check a single wallets vote
check_wallet = "one1prz9j6c406h6uhkyurlx9yq9h2e2zrpasr2saf"
def get_validator_voting_info(
fn: str,
vote_address_args: str,
vote_name: str,
grouped_data: dict,
num_pages: int = 100,
save_json_data: bool = False,
check_wallet: bool = False,
) -> None:
vote_address = gov_base.format(*vote_address_args)
vote_address_api = snapshot_api_base.format(*vote_address_args)
log.info(vote_address)
res, voted, voted_results = call_api(vote_address_api, fn=f"{vote_name}-{fn}")
if not res:
log.error("Error Connecting, Shutting Down.. ")
return False
voted_yes_weight = 0
voted_no_weight = 0
voted_abstain_weight = 0
binance_kucoin = 0
binance_controlled_stake = 0
csv_data = []
result = []
display_check = f"Wallet {check_wallet} NOT Found."
for y in yield_data(result, check_wallet=check_wallet, num_pages=num_pages):
result, check_wallet, show, include, v, e = y
eth_add = convert_one_to_hex(v.address)
if v.name in ("Binance Staking", "KuCoin"):
binance_kucoin += e.total_delegation
if v.name == "Binance Staking":
binance_controlled_stake += e.total_delegation
for d in v.delegations:
if d["delegator-address"] == binance_wallet:
binance_controlled_stake += d["amount"]
if e.active_status == "active":
w = {
"Name": v.name,
"Address": v.address,
"Staked": f"{round(float(e.total_delegation) / places):,}",
"Security Contact": v.security_contact,
"Website": v.website,
"Epos Status": e.epos_status,
"Active Status": e.active_status,
}
grouped, app = parse_contact_info(v)
if eth_add not in voted:
include = True
grouped_data[app] += grouped
w.update({"Group": app})
# Already Voted, Check Weight
else:
choices = voted_results[eth_add]["msg"]["payload"]["choice"]
if not isinstance(choices, (dict, list)):
choices = {choices: 100}
# for elections we just want a lst of non voters
if isinstance(choices, list):
if show:
display_check = f"\n\tWallet *- {check_wallet} -* Voted Yes!\n"
else:
for choice, percent in choices.items():
choice = int(choice)
if percent > 100 or percent in (1, 2):
percent = 100
if choice == 1:
voted_yes_weight += e.total_delegation // 100 * percent
if show:
display_check = (
f"\n\tWallet *- {check_wallet} -* Voted Yes!\n"
)
if choice == 2:
voted_no_weight += e.total_delegation // 100 * percent
if show:
display_check = (
f"\n\tWallet *- {check_wallet} -* Voted NO!"
)
if choice == 3:
voted_abstain_weight += e.total_delegation // 100 * percent
if show:
display_check = (
f"\n\tWallet *- {check_wallet} -* Voted to Abstain!"
)
if w["Name"] not in [x["Name"] for x in csv_data] and include:
ss_address, ss_blskeys = find_smartstakeid(
v.address, smartstake_validator_list
)
w.update(
{
"Smartstake Summary": ss_address,
"Smartstake BlsKeys": ss_blskeys,
}
)
(
grouped_data,
social_media_contacts,
) = parse_google_docs_contact_info(v, grouped_data)
w.update(social_media_contacts)
csv_data.append(w)
save_csv(
vote_name,
f"{vote_name}-{fn}",
csv_data,
[x for x in csv_data[0].keys()],
)
display_stats = (
voted_abstain_weight,
voted_no_weight,
voted_yes_weight,
binance_kucoin,
binance_controlled_stake,
display_check,
vote_address,
)
save_and_display(
vote_name,
result,
grouped_data,
display_stats,
display_vote_stats,
save_json_data=save_json_data,
)
if __name__ == "__main__":
votes_to_check = {
"RPC_DAO_Elections": (
"harmony-mainnet.eth",
"0x4e51760f36e580e7ae6d7f95a91ff51e5e310e9da1a0b4619cfdcb4e978a9e18",
),
}
# {"operationName":"Votes","variables":{"id":"0x4e51760f36e580e7ae6d7f95a91ff51e5e310e9da1a0b4619cfdcb4e978a9e18","orderBy":"vp","orderDirection":"desc","first":10,"skip":10},"query":"query Votes($id: String!, $first: Int, $skip: Int, $orderBy: String, $orderDirection: OrderDirection, $voter: String) {\n votes(\n first: $first\n skip: $skip\n where: {proposal: $id, vp_gt: 0, voter: $voter}\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n ipfs\n voter\n choice\n vp\n vp_by_strategy\n }\n}"}
for vote_name, vote_address_args in votes_to_check.items():
create_folders_change_handler(vote_name)
get_validator_voting_info(
vote_fn,
vote_address_args,
vote_name,
grouped_data,
num_pages=100,
save_json_data=True,
check_wallet=check_wallet,
)