Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion app/api/dao-overview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,22 @@ const NATIVE_QUORUM_ABI = parseAbi([
]);
const NATIVE_VOTES_ABI = parseAbi([
"function getTotalVotingPower(uint256 timepoint) view returns (uint256)",
"function getPastTotalSupply(uint256 timepoint) view returns (uint256)",
]);

// Distinct-account count. There is no on-chain enumerator for holders (the
// precompile gives votes==balance per account but no list), so the ecosystem
// account count comes from the explorer's index. Best-effort; null on failure.
async function fetchHolderCount(): Promise<number | null> {
try {
const res = await fetch("https://mainnet.lightscan.app/api/v2/stats", { signal: AbortSignal.timeout(6000) });
if (!res.ok) return null;
const j = (await res.json()) as { total_addresses?: string };
return j.total_addresses ? Number(j.total_addresses) : null;
} catch {
return null;
}
}
const SCHEDULE_ABI = parseAbi([
"function votingDelay() view returns (uint256)",
"function votingPeriod() view returns (uint256)",
Expand Down Expand Up @@ -126,12 +141,21 @@ async function readLightchainOverview(pub: Pub) {
// Evaluate the real quorum + votable base at the latest finalized timepoint.
const clock = BigInt(clockRaw as bigint | number);
const ref = clock > 0n ? clock - 1n : 0n;
const [quorumWei, votableWei] = await Promise.all([
const [quorumWei, votableWei, rawSupplyWei, holderCount] = await Promise.all([
pub.readContract({ address: a.governor, abi: NATIVE_QUORUM_ABI, functionName: "quorum", args: [ref] }).catch(() => null),
a.ballots
? pub.readContract({ address: a.ballots, abi: NATIVE_VOTES_ABI, functionName: "getTotalVotingPower", args: [ref] }).catch(() => null)
: Promise.resolve(null),
a.ballots
? pub.readContract({ address: a.ballots, abi: NATIVE_VOTES_ABI, functionName: "getPastTotalSupply", args: [ref] }).catch(() => null)
: Promise.resolve(null),
fetchHolderCount(),
]);
// Staked LCAI excluded from the quorum base = raw votes supply - votable supply.
const stakeExcludedWei =
rawSupplyWei != null && votableWei != null && (rawSupplyWei as bigint) > (votableWei as bigint)
? (rawSupplyWei as bigint) - (votableWei as bigint)
: null;
return {
treasuryWei: treasuryWei.toString(),
feePoolWei: feePoolWei.toString(),
Expand All @@ -140,7 +164,10 @@ async function readLightchainOverview(pub: Pub) {
// The actual quorum threshold + the staked-excluded base it applies to.
quorumWei: quorumWei != null ? (quorumWei as bigint).toString() : null,
votableSupplyWei: votableWei != null ? (votableWei as bigint).toString() : null,
rawSupplyWei: rawSupplyWei != null ? (rawSupplyWei as bigint).toString() : null,
stakeExcludedWei: stakeExcludedWei != null ? stakeExcludedWei.toString() : null,
stakeExcludedFromQuorum: true as boolean,
holderCount: holderCount,
};
}

Expand Down
24 changes: 24 additions & 0 deletions app/build/dao/treasury-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,35 @@ interface Overview {
quorumWei?: string | null;
votableSupplyWei?: string | null;
stakeExcludedFromQuorum?: boolean;
// Voting-power distribution: the votable sum, how much staked LCAI is excluded
// from it, and the ecosystem account count (from the explorer index).
rawSupplyWei?: string | null;
stakeExcludedWei?: string | null;
holderCount?: number | null;
schedule?: Schedule;
error?: string;
}

const VOTE_SYMBOL: Record<DaoChain, string> = { ethereum: "LCAIB", lightchain: "LCAI" };

/** LightChain voting-power summary: votable sum, accounts, staked-excluded. */
function VotingPowerLine({ chain, data }: { chain: DaoChain; data: Overview }) {
if (!data.votableSupplyWei) return null;
const sym = VOTE_SYMBOL[chain];
const votable = formatLcaiWei(BigInt(data.votableSupplyWei), 0);
const accounts = data.holderCount != null ? `~${data.holderCount.toLocaleString()} accounts` : null;
const excluded = data.stakeExcludedWei && BigInt(data.stakeExcludedWei) > 0n
? `${formatLcaiWei(BigInt(data.stakeExcludedWei), 0)} ${sym} staked (excluded from quorum)`
: null;
return (
<p className="px-1 text-[11px] leading-relaxed text-content-soft">
<span className="font-medium text-content-default">Voting power:</span> {votable} {sym} votable
{accounts ? <> across <span className="text-content-default">{accounts}</span></> : null}
{excluded ? <> · {excluded}</> : null}
</p>
);
}

function ScheduleLine({ chain, schedule }: { chain: DaoChain; schedule: Schedule }) {
const vote = humanizeDuration(schedule.votingPeriodSeconds);
const delay = humanizeDuration(schedule.votingDelaySeconds);
Expand Down Expand Up @@ -123,6 +146,7 @@ export function TreasuryBar({ chain }: { chain: DaoChain }) {
</div>
<Stat icon={<Landmark className="size-4" />} label="Governor" value={shortAddr(data.governor)} href={`${data.explorer}/address/${data.governor}`} />
</div>
<VotingPowerLine chain={chain} data={data} />
{data.schedule && <ScheduleLine chain={chain} schedule={data.schedule} />}
</div>
);
Expand Down
Loading