Skip to content

Commit 976b4a1

Browse files
committed
refactor: deduplicate BASE_SPECS, consolidate reward pool fetch, update docs
- Import BASE_SPECS from @info/shared instead of duplicating locally - Extract shared fetchRewardPools() so both fetchRewardPoolsAmount and fetchProviderRewardPoolsAmount share one RPC call via request coalescing - Document new /provider-estimated-rewards endpoint in CLAUDE.md - Update /provider-rewards docs with new estimatedRewardsLava field - Add no-co-author rule to git-workflow.md - Add safe-range comment on Number(ulava) conversion
1 parent ff5e6b4 commit 976b4a1

4 files changed

Lines changed: 32 additions & 34 deletions

File tree

‎.claude/rules/git-workflow.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Use conventional commit format: `feat:`, `fix:`, `docs:`, `refactor:`, `test:`, `chore:`
55
- Keep commits atomic — one logical change per commit
66
- Write the "why" in the commit body if the diff doesn't make it obvious
7+
- Never add `Co-Authored-By` trailers — no AI attribution in commit history
78

89
## Branches
910
- Feature branches: `feat/<short-description>`

‎CLAUDE.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ packages/
190190
| `GET /apr` | 1800s | Chain RPC + CoinGecko | Per-entity APR percentiles matching jsinfo. Queries `estimated_{provider,validator}_rewards` for all providers/validators with 10k LAVA benchmark, converts multi-denom rewards to USD, compounds monthly, takes 80th percentile, caps at 30%. Returns `{ restaking_apr_percentile, staking_apr_percentile }`. Uses 7-day weighted Redis history when available |
191191
| `GET /all_providers_apr` | 1800s | Chain RPC + CoinGecko + Indexer MV | Per-provider APR data matching jsinfo. Returns array of providers with: APR, commission, 30d CU/relays, 10k LAVA reward breakdown, per-spec rewards (rewards_last_month), specs, avatar |
192192
| `GET /lava/specs` | 300s | Chain RPC | All chain specs (raw, used by frontend `useChainNames` hook) |
193-
| `GET /provider-rewards?from=&to=` | 300s | Indexer MV + CoinGecko | Per-provider QoS-adjusted reward distribution. Required: `from`, `to` (YYYY-MM-DD, max 6 months). Optional: `specs` (chain filter). Returns `{ meta: { from, to, lavaUsdPrice, totalAdjustedRewards }, data: [{ provider, moniker, relays, cus, adjustedRewards, rewardShare, estimatedRewardsUsd }] }`. Uses historical LAVA price when date range is in the past. Price gracefully degrades to null on CoinGecko failure |
193+
| `GET /provider-rewards?from=&to=` | 300s | Indexer MV + Chain RPC + CoinGecko | Per-provider QoS-adjusted reward distribution. Required: `from`, `to` (YYYY-MM-DD, max 6 months). Optional: `specs` (chain filter). Returns `{ meta: { from, to, lavaUsdPrice, providerPoolLava, totalAdjustedRewards }, data: [{ provider, moniker, relays, cus, adjustedRewards, rewardShare, estimatedRewardsLava, estimatedRewardsUsd }] }`. Estimated LAVA/USD amounts derived from on-chain provider reward pool balance. Uses historical LAVA price when date range is in the past. Price gracefully degrades to null on CoinGecko failure |
194+
| `GET /provider-estimated-rewards` | 1800s | Chain RPC + CoinGecko | Per-provider actual chain rewards from `estimated_provider_rewards` RPC, grouped by spec. Calls chain RPC per provider (batched 5 at a time). Returns `{ data: [{ provider, moniker, rewards: [{ chain, spec, tokens, total_usd }], total_usd }] }`. Sorted by total_usd descending. Replaces lava-ops Job 2 |
194195

195196
## Pagination Convention
196197

‎apps/api/src/routes/provider-rewards.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ export async function providerRewardsRoutes(app: FastifyInstance) {
161161
.catch(() => null as bigint | null),
162162
]);
163163

164-
// Convert provider pool from ulava to LAVA (1 LAVA = 1_000_000 ulava)
164+
// Convert provider pool from ulava to LAVA (1 LAVA = 1_000_000 ulava).
165+
// Safe: pool balance is well under Number.MAX_SAFE_INTEGER (~9B LAVA).
165166
const providerPoolLava = providerPoolUlava != null
166167
? Number(providerPoolUlava) / 1_000_000
167168
: null;

‎apps/api/src/rpc/lava.ts‎

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,22 @@ export async function fetchBlockAtTimestamp(targetUnix: number): Promise<number>
105105
return lo;
106106
}
107107

108-
const REWARD_POOLS = [
109-
"validators_rewards_distribution_pool",
110-
"validators_rewards_allocation_pool",
111-
"providers_rewards_distribution_pool",
112-
"providers_rewards_allocation_pool",
113-
"iprpc_pool",
114-
];
108+
interface RewardPool {
109+
name: string;
110+
balance: Array<{ denom: string; amount: string }>;
111+
}
115112

116-
async function fetchRewardPoolsAmount(): Promise<bigint> {
117-
const data = await fetchRest<{
118-
pools: Array<{ name: string; balance: Array<{ denom: string; amount: string }> }>;
119-
}>("/lavanet/lava/rewards/pools");
113+
/** Shared fetch for reward pools — both consumers filter by pool name. */
114+
async function fetchRewardPools(): Promise<RewardPool[]> {
115+
const data = await fetchRest<{ pools: RewardPool[] }>("/lavanet/lava/rewards/pools");
116+
return data.pools ?? [];
117+
}
120118

119+
function sumPoolsUlava(pools: RewardPool[], names: string[]): bigint {
120+
const nameSet = new Set(names);
121121
let total = 0n;
122-
for (const pool of data.pools ?? []) {
123-
if (REWARD_POOLS.includes(pool.name)) {
122+
for (const pool of pools) {
123+
if (nameSet.has(pool.name)) {
124124
for (const coin of pool.balance ?? []) {
125125
if (coin.denom === "ulava") total += BigInt(coin.amount);
126126
}
@@ -129,6 +129,18 @@ async function fetchRewardPoolsAmount(): Promise<bigint> {
129129
return total;
130130
}
131131

132+
const ALL_REWARD_POOLS = [
133+
"validators_rewards_distribution_pool",
134+
"validators_rewards_allocation_pool",
135+
"providers_rewards_distribution_pool",
136+
"providers_rewards_allocation_pool",
137+
"iprpc_pool",
138+
];
139+
140+
async function fetchRewardPoolsAmount(): Promise<bigint> {
141+
return sumPoolsUlava(await fetchRewardPools(), ALL_REWARD_POOLS);
142+
}
143+
132144
const PROVIDER_REWARD_POOLS = [
133145
"providers_rewards_distribution_pool",
134146
"providers_rewards_allocation_pool",
@@ -137,19 +149,7 @@ const PROVIDER_REWARD_POOLS = [
137149

138150
/** Fetch total ulava in provider-side reward pools (excludes validator pools). */
139151
export async function fetchProviderRewardPoolsAmount(): Promise<bigint> {
140-
const data = await fetchRest<{
141-
pools: Array<{ name: string; balance: Array<{ denom: string; amount: string }> }>;
142-
}>("/lavanet/lava/rewards/pools");
143-
144-
let total = 0n;
145-
for (const pool of data.pools ?? []) {
146-
if (PROVIDER_REWARD_POOLS.includes(pool.name)) {
147-
for (const coin of pool.balance ?? []) {
148-
if (coin.denom === "ulava") total += BigInt(coin.amount);
149-
}
150-
}
151-
}
152-
return total;
152+
return sumPoolsUlava(await fetchRewardPools(), PROVIDER_REWARD_POOLS);
153153
}
154154

155155
interface VestingStats {
@@ -347,12 +347,7 @@ function chainDisplayName(chainID: string, chainName: string): string {
347347
return titleCase(chainName);
348348
}
349349

350-
/** Base specs that aren't real chains — excluded from all chain lists */
351-
const BASE_SPECS = new Set([
352-
"SUIGRPC", "SUIJSONRPC",
353-
"COSMOSSDK", "COSMOSSDK50", "COSMOSWASM",
354-
"ETHERMINT", "TENDERMINT", "IBC",
355-
]);
350+
import { BASE_SPECS } from "@info/shared/constants";
356351

357352
export async function fetchAllSpecs(): Promise<Array<{ index: string; name: string }>> {
358353
const data = await fetchRest<{

0 commit comments

Comments
 (0)