Skip to content

Commit 24b713b

Browse files
authored
🐛 Show staking data (#5)
1 parent 7506b73 commit 24b713b

1 file changed

Lines changed: 48 additions & 6 deletions

File tree

‎lambda/supply_calculator.py‎

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,20 @@ def calculate_supply():
4242

4343
# Calculate locked and circulating supply
4444
total_supply = data["total_supply"]
45+
is_rewards_claimable = data["is_rewards_claimable"]
4546

4647
# Compute per-ATP locked amounts (same logic as display())
4748
now = int(time.time())
4849
factory_global_locks = data["factory_global_locks"]
4950
factory_fracs = {f: unlock_frac(lock, now) for f, lock in factory_global_locks.items()}
5051

52+
type_locked = {"LATP": 0, "MATP": 0, "NCATP": 0}
53+
type_names = {0: "LATP", 1: "MATP", 2: "NCATP"}
54+
5155
for a in atps:
5256
wts = a.get("withdrawal_ts")
5357
frac = factory_fracs.get(a["factory"], 0.0)
58+
atp_type_name = type_names.get(a["atp_type"], "LATP")
5459
if a["atp_type"] == 2:
5560
# NCATP: claim() always reverts, only unlockable via staker withdrawal
5661
if wts is not None and now >= wts:
@@ -77,18 +82,19 @@ def calculate_supply():
7782
a["locked"] = 0
7883
else:
7984
a["locked"] = max(0, a["allocation"] - unlocked)
85+
type_locked[atp_type_name] += a["locked"]
8086

8187
total_atp_locked = sum(a["locked"] for a in atps)
8288
locked_future_incentives = data["other_bals"].get("Future Incentives", 0)
8389
locked_y1_rewards = data["other_bals"].get("Y1 Network Rewards", 0)
8490
locked_investor_wallet = data["other_bals"].get("Investor Wallet", 0)
8591
locked_factories = sum(data["factory_bals"].values())
86-
87-
# Slashed funds
8892
locked_slashed = data["total_slashed_funds"]
89-
90-
# FlushRewarder: pending rewards
9193
locked_flush_rewarder = data["flush_rewarder_locked"]
94+
token_sale_balance = data["token_sale_balance"]
95+
96+
# Token sale is locked until isRewardsClaimable
97+
locked_token_sale = token_sale_balance if not is_rewards_claimable else 0
9298

9399
total_locked = (
94100
total_atp_locked
@@ -98,10 +104,17 @@ def calculate_supply():
98104
+ locked_factories
99105
+ locked_slashed
100106
+ locked_flush_rewarder
107+
+ locked_token_sale
101108
)
102109

103110
circulating = total_supply - total_locked
104111

112+
# Contract balances
113+
total_rollup_balance = sum(data["rollup_bals"].values())
114+
total_governance_balance = sum(data["governance_bals"].values())
115+
total_gse_balance = sum(data["gse_bals"].values())
116+
actively_staked = data["actively_staked_rollup"]
117+
105118
# Get current block
106119
block_number = retry(lambda: w3.eth.block_number)
107120

@@ -120,8 +133,17 @@ def calculate_supply():
120133
"locked_supply_wei": str(total_locked),
121134
"percentage_circulating": round((circulating / total_supply * 100), 4) if total_supply > 0 else 0,
122135
"percentage_locked": round((total_locked / total_supply * 100), 4) if total_supply > 0 else 0,
123-
"is_rewards_claimable": data["is_rewards_claimable"],
136+
"is_rewards_claimable": is_rewards_claimable,
124137
"atp_count": len(atps),
138+
"actively_staked": str(actively_staked),
139+
"actively_staked_formatted": f"{actively_staked / 1e18:,.2f}",
140+
"contract_balances": {
141+
"governance_total": str(total_governance_balance),
142+
"rollup_total": str(total_rollup_balance),
143+
"gse_total": str(total_gse_balance),
144+
"token_sale": str(token_sale_balance),
145+
**{name: str(bal) for name, bal in data["other_bals"].items()},
146+
},
125147
"breakdown": {
126148
"atp_locked": str(total_atp_locked),
127149
"future_incentives": str(locked_future_incentives),
@@ -130,9 +152,29 @@ def calculate_supply():
130152
"factories": str(locked_factories),
131153
"slashed_funds": str(locked_slashed),
132154
"flush_rewarder": str(locked_flush_rewarder),
133-
}
155+
"token_sale": str(locked_token_sale),
156+
},
157+
"atp_type_breakdown": {
158+
name: str(val) for name, val in type_locked.items()
159+
},
134160
}
135161

162+
# Add global lock info if available
163+
if factory_global_locks:
164+
primary_lock = None
165+
for f, lock in factory_global_locks.items():
166+
frac = factory_fracs.get(f, 0.0)
167+
if frac < 1.0:
168+
if primary_lock is None or lock[2] > primary_lock[2]:
169+
primary_lock = lock
170+
if primary_lock:
171+
result["global_lock"] = {
172+
"start": primary_lock[0],
173+
"cliff": primary_lock[1],
174+
"end": primary_lock[2],
175+
"current_unlock_pct": round(unlock_frac(primary_lock, now) * 100, 4),
176+
}
177+
136178
return result
137179

138180
except Exception as e:

0 commit comments

Comments
 (0)