Skip to content

Commit 4bee101

Browse files
committed
✨ add staked balance
1 parent f95e7f8 commit 4bee101

File tree

1 file changed

+55
-8
lines changed

1 file changed

+55
-8
lines changed

circulating-supply.py

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def sel(sig: str) -> bytes:
134134
SEL_GET_NEXT_STAKER_VER = sel("getNextStakerVersion()")
135135
SEL_GET_STAKER_IMPL = sel("getStakerImplementation(uint256)")
136136
SEL_WITHDRAW_ALL_TO_BENEFICIARY = sel("withdrawAllTokensToBeneficiary()")
137+
SEL_GET_ACTIVE_ATTESTER_COUNT = sel("getActiveAttesterCount()")
138+
SEL_GET_ATTESTER_AT_INDEX = sel("getAttesterAtIndex(uint256)")
139+
SEL_GET_ATTESTER_VIEW = sel("getAttesterView(address)")
137140
SEL_AGGREGATE3 = sel("aggregate3((address,bool,bytes)[])")
138141

139142

@@ -616,6 +619,51 @@ def _bool(i):
616619
else:
617620
print(f" No slashing events found")
618621

622+
# Follow-up: query actively staked tokens on the current rollup
623+
# Enumerate all active attesters and sum their effectiveBalance (status == VALIDATING only)
624+
print(f"\n Querying actively staked tokens on rollup...")
625+
actively_staked_rollup = 0
626+
attester_count = 0
627+
628+
# Step 1: Get active attester count
629+
count_result = multicall([(current_rollup, SEL_GET_ACTIVE_ATTESTER_COUNT)])
630+
if count_result[0][0] and len(count_result[0][1]) >= 32:
631+
attester_count = decode(["uint256"], count_result[0][1])[0]
632+
print(f" Active attester count: {attester_count}")
633+
634+
if attester_count > 0:
635+
# Step 2: Get all attester addresses
636+
index_calls = [
637+
(current_rollup, SEL_GET_ATTESTER_AT_INDEX + encode(["uint256"], [i]))
638+
for i in range(attester_count)
639+
]
640+
index_results = multicall_chunked(index_calls)
641+
attesters = []
642+
for ok, d in index_results:
643+
if ok and len(d) >= 32:
644+
attesters.append(decode(["address"], d)[0])
645+
646+
# Step 3: Get AttesterView for each attester (status + effectiveBalance)
647+
# AttesterView ABI: (uint8 status, uint256 effectiveBalance, Exit exit, AttesterConfig config)
648+
# We only need the first 64 bytes: status (uint8) + effectiveBalance (uint256)
649+
view_calls = [
650+
(current_rollup, SEL_GET_ATTESTER_VIEW + encode(["address"], [to_checksum_cached(a)]))
651+
for a in attesters
652+
]
653+
view_results = multicall_chunked(view_calls)
654+
655+
validating_count = 0
656+
for (ok, d) in view_results:
657+
if ok and len(d) >= 64:
658+
status = decode(["uint8"], d[:32])[0]
659+
effective_balance = decode(["uint256"], d[32:64])[0]
660+
if status == 1: # VALIDATING
661+
actively_staked_rollup += effective_balance
662+
validating_count += 1
663+
664+
print(f" Validating attesters: {validating_count}")
665+
print(f" Actively staked: {fmt(actively_staked_rollup)} AZTEC")
666+
619667
return {
620668
"total_supply": total_supply,
621669
"factory_global_locks": factory_global_locks,
@@ -629,6 +677,7 @@ def _bool(i):
629677
"factory_bals": factory_bals,
630678
"flush_rewarder_locked": flush_rewarder_locked,
631679
"factory_best_withdrawal_ts": factory_best_withdrawal_ts,
680+
"actively_staked_rollup": actively_staked_rollup,
632681
}
633682

634683

@@ -762,6 +811,9 @@ def display(atps, data):
762811
# Sum GSE balances (all historical instances)
763812
total_gse_balance = sum(gse_bals.values())
764813

814+
# Actively staked on rollup: sum of effectiveBalance for VALIDATING attesters
815+
actively_staked = data["actively_staked_rollup"]
816+
765817
total_locked = (
766818
total_atp_locked
767819
+ locked_future_incentives
@@ -770,7 +822,6 @@ def display(atps, data):
770822
+ locked_factories
771823
+ locked_slashed
772824
+ locked_flush_rewarder
773-
+ locked_flush_rewarder
774825
)
775826
circulating = total_supply - total_locked
776827

@@ -835,12 +886,6 @@ def display(atps, data):
835886
f" ({pct(locked_flush_rewarder, total_supply)})"
836887
f" [pending rewards]"
837888
)
838-
if locked_flush_rewarder > 0:
839-
print(
840-
f" Flush Rewarder: {fmt(locked_flush_rewarder):>27} AZTEC"
841-
f" ({pct(locked_flush_rewarder, total_supply)})"
842-
f" [pending rewards]"
843-
)
844889

845890
print(f"\n {'─'*54}")
846891
print(
@@ -872,7 +917,7 @@ def display(atps, data):
872917
# Rollup (sum of all instances)
873918
print(
874919
f" {'Rollup (sum):':.<24} {fmt(total_rollup_balance):>22} AZTEC"
875-
f" [ATP staked + rewards (claimable) + slashed]"
920+
f" [actively staked: {fmt(actively_staked)}, slashed: {fmt(locked_slashed)}]"
876921
)
877922
if len(rollup_bals) > 1:
878923
for addr, bal in rollup_bals.items():
@@ -1182,6 +1227,8 @@ def display(atps, data):
11821227
"token_sale": str(token_sale_balance),
11831228
**{name: str(bal) for name, bal in other_bals.items()},
11841229
},
1230+
"actively_staked": str(actively_staked),
1231+
"actively_staked_formatted": fmt(actively_staked),
11851232
"atp_count": len(atps),
11861233
"active_atp_count": len(active),
11871234
}

0 commit comments

Comments
 (0)