Skip to content

feat(api): migrate lava-ops monthly rewards pipeline to info endpoints - #32

Merged
nimrod-teich merged 2 commits into
mainfrom
feat/rewards-migration-endpoints
Apr 16, 2026
Merged

nimrod-teich merged 2 commits into
mainfrom
feat/rewards-migration-endpoints

Conversation

@nimrod-teich

Copy link
Copy Markdown
Contributor

Summary

Replaces the fragile monthly cron pipeline (lava-ops Jobs 1, 2, 3) with on-demand API endpoints so the lava-rewards repo can become a thin Next.js client instead of a file-commit sink.

Changes

  • /provider-rewards: fix multi-chain aggregation. GraphQL groupBy is now [PROVIDER] by default (pools all chains before cbrt to match delta's non-linear formula) and [CHAIN_ID, PROVIDER] with the new ?groupBy=spec for per-spec rows. Adds within-spec rewardShare and meta.bySpec in spec mode.
  • /provider-estimated-rewards: new ?block=N threads blockHeight through fetchRewardsBySpec → fetchRest via the existing x-cosmos-block-height header. Adds ?spec=X server-side filter and /provider-estimated-rewards/blocks sub-route listing the 17th-of-month snapshots via fetchBlockAtTimestamp. USD values keep using current CoinGecko prices even for historical blocks (matches old Job 2 behavior).
  • /provider-claimable-rewards (new): ports jsinfo's /lava_mainnet_provider_claimable_rewards using the existing fetchDelegatorRewards + prewarmPriceCache plumbing.
  • /validators-and-rewards (new): ports jsinfo's /lava_mainnet_validators_and_rewards — 5 RPC calls per validator (distribution, outstanding, estimated, delegations, unbonding), batched 3 at a time, all denoms converted to USD.
  • /burn-rate (new): monthly total-supply snapshots with supply_diff. Replaces lava-ops Job 3 and the lavad/Python/burn-ui commit chain entirely.

Depends on

Migration plan

  1. Merge this + lava-indexer#8. REFRESH MATERIALIZED VIEW app.mv_relay_daily on prod.
  2. Point lava-rewards FE at info: repoint the 5 pages in src/app/** (monthly_provider_data, provider_rewards, provider_rewards_by_spec, provider_claimable_rewards, validator_rewards).
  3. Delete lava-ops Jobs 1, 2, 3. Delete lava-rewards/scripts/ and src/app/monthly_provider_data/data/*.csv. Deprecate relayserver/pkg/handlers/adjustedrewards.go.

Test plan

  • pnpm typecheck clean across all packages
  • pnpm test — 97 tests passing (up from 79; 18 new tests across the new and refactored routes)
  • Smoke test /provider-rewards?from=&to= against a staging indexer and confirm numbers match an existing delta CSV for the same month
  • Smoke test /provider-rewards?groupBy=spec and confirm per-spec numbers match per-spec CSVs
  • Smoke test /provider-estimated-rewards?block=<past block> and confirm non-empty response
  • Smoke test /provider-estimated-rewards/blocks returns 12 monthly entries
  • Smoke test /provider-claimable-rewards and compare shape with jsinfo's response
  • Smoke test /validators-and-rewards and compare shape with jsinfo's response
  • Smoke test /burn-rate?months=6 and confirm supply_diff values look sane

Replaces the fragile monthly cron pipeline (lava-ops Jobs 1, 2, 3)
with on-demand API endpoints so the lava-rewards repo can become a
thin Next.js client instead of a file-commit sink.

- /provider-rewards: fix multi-chain aggregation. GraphQL groupBy is
  now [PROVIDER] by default (pools all chains before cbrt to match
  delta's non-linear formula) and [CHAIN_ID, PROVIDER] with the new
  ?groupBy=spec for per-spec rows. Adds within-spec rewardShare and
  meta.bySpec in spec mode.
- /provider-estimated-rewards: new ?block=N threads blockHeight
  through fetchRewardsBySpec -> fetchRest via the existing
  x-cosmos-block-height header. Adds ?spec=X server-side filter and
  /provider-estimated-rewards/blocks sub-route listing the 17th-of-
  month snapshots via fetchBlockAtTimestamp. USD values keep using
  current CoinGecko prices even for historical blocks (matches the
  old Job 2 behavior).
- /provider-claimable-rewards: ports jsinfo's
  /lava_mainnet_provider_claimable_rewards using the existing
  fetchDelegatorRewards + prewarmPriceCache plumbing.
- /validators-and-rewards: ports jsinfo's
  /lava_mainnet_validators_and_rewards — 5 RPC calls per validator
  (distribution, outstanding, estimated, delegations, unbonding),
  batched 3 at a time, all denoms converted to USD.
- /burn-rate: monthly total-supply snapshots with supply_diff.
  Replaces lava-ops Job 3 and the lavad/Python/burn-ui commit chain
  entirely.

Test coverage: 97 tests (up from 79). Typecheck clean across all
packages. Smoke test against a live stack was not run — local docker
+ indexer GraphQL required.
- Close cache-key amplification by setting additionalProperties:false
  on querystring schemas for burn-rate, provider-rewards, and both
  provider-estimated-rewards endpoints; Fastify now rejects unknown
  query params instead of spawning unique cache entries per junk key.
- Register missing "Validators" swagger tag so /validators-and-rewards
  renders in /docs.
- Introduce RPC_BATCH_SIZE env var (default 25, up from 3–5) used for
  every RPC fan-out in rpc/lava.ts plus the two batched routes; keep
  lower defaults for public RPC, raise via env on dedicated endpoints.
- Surface priceLavaUsd + priceTimestamp in /provider-estimated-rewards
  meta so consumers of historical block queries see USD is priced at
  request time, not at the queried block.
- Add AbortSignal.timeout to all remaining external fetches (Osmosis,
  Geckoterminal, Uniswap, CoinGecko, Keybase) to prevent hangs on slow
  upstreams from tying up request-loop slots.
- Document RPC_BATCH_SIZE in env vars, updated meta fields on the
  estimated-rewards endpoint, and replaced the hard-coded validator
  batch doc with the configurable form.
@nimrod-teich
nimrod-teich merged commit 9acb12a into main Apr 16, 2026
2 checks passed
nimrod-teich added a commit that referenced this pull request Apr 20, 2026
The chain RPC returns per-source entries like "Boost: ETH1", "Pools: ETH1",
"Subscription: ETH1". The previous implementation collapsed these into
per-spec totals, discarding the source categorization — which the
rewards-ui provider_rewards and validator_rewards pages need for their
Subscription / Pool / Boost / IPRPC columns.

- RewardsBySpecEntry now carries sources[]: per-source breakdown under
  each spec with raw chain source string + token amounts + USD total.
- ValidatorWithRewards.estimated_rewards is now EstimatedRewardsWithInfo
  which extends TokenBreakdown with info[]: the jsinfo-compatible
  {source, amount: {tokens, total_usd}} shape.
- fetchRewardsBySpec tracks per-(spec, source) denom sums alongside the
  existing per-spec sums.
- fetchValidatorEstimated returns {total, info}; fetchValidatorsWithRewards
  runs USD conversion for each info entry in parallel with the total.

Additive change — existing fields (tokens, total_usd) are unchanged. Tests
updated to assert the new fields flow through; 98/98 passing.

Stacked on top of feat/rewards-migration-endpoints (PR #32).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant