forked from Vilijan/AlGoannaStaking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
staking_script.py
81 lines (63 loc) · 2.71 KB
/
staking_script.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
import pandas as pd
from retrieve_latest_data import latest_asset_transfer
from datetime import datetime
def download_latest_stats(staking_period_days: int = 56):
asa_df = pd.read_csv('data/algoanna_asas.csv')
staking_df = pd.read_csv('data/staking_data.csv')
wallet_addresses = staking_df['Wallet Address'].unique()
wallet_addresses = [addr for addr in wallet_addresses if len(str(addr)) == 58]
staking_df = staking_df[staking_df['Wallet Address'].isin(wallet_addresses)].reset_index(drop=True)
staking_df['asa_id'] = staking_df['ASA ID'].apply(lambda x: int(x))
data = []
columns = ['asa_id', 'name', 'latest_transfer_date', 'tx_id', 'staked_date', 'not_moved_days', 'staked_days',
'eligible']
for asa_idx, asa_id in enumerate(asa_df.asa_id.unique()):
latest_txn = latest_asset_transfer(asa_id)
if latest_txn is None:
print(f'BUG for {asa_id}')
continue
asa_name = asa_df[asa_df.asa_id == asa_id].name.values[0]
txn_date = datetime.utcfromtimestamp(latest_txn.round_time)
txn_difference = datetime.now() - txn_date
curr_staking_df = staking_df[staking_df.asa_id == asa_id].reset_index(drop=True)
latest_staking_date = datetime.strptime('10 January 2010', '%d %B %Y')
staked_wallet = 'Not staked'
for _, row in curr_staking_df.iterrows():
try:
staked_date = datetime.strptime(row['Date'] + ' ' + row['Time'], '%d %B %Y %H:%M')
except:
continue
if staked_date >= latest_staking_date:
latest_staking_date = staked_date
staked_wallet = row['Wallet Address']
if staked_wallet == 'Not staked':
data.append([
asa_id,
asa_name,
txn_date,
latest_txn.tx_id,
'NOT STAKED',
txn_difference.days,
0,
'No'
])
continue
days_staked = datetime.now() - latest_staking_date
asa_owner = latest_txn.receiver if latest_txn.amount == 1 else latest_txn.close_address
is_eligible = 'No'
if txn_difference.days >= staking_period_days and \
days_staked.days >= staking_period_days and \
asa_owner == staked_wallet:
is_eligible = 'Yes'
data.append([
asa_id,
asa_name,
txn_date,
latest_txn.tx_id,
latest_staking_date,
txn_difference.days,
days_staked.days,
is_eligible
])
df = pd.DataFrame(data=data, columns=columns)
df.to_csv('latest_staked_stats.csv', index=False)