Skip to content

feat: staking epoch indexer and rewards accumulation API (#1086) - #1188

Open
jennioo wants to merge 1 commit into
accesslayerorg:mainfrom
jennioo:feat/staking-epoch-indexer-rewards-api
Open

jennioo wants to merge 1 commit into
accesslayerorg:mainfrom
jennioo:feat/staking-epoch-indexer-rewards-api

Conversation

@jennioo

@jennioo jennioo commented Oct 21, 2026

Copy link
Copy Markdown

Index StakeCreated, EpochRewardDistributed, and RewardsClaimed contract events into stakes and epoch_rewards tables. Expose three REST endpoints:

closes #1086

GET /staking/:wallet/positions active stakes with live rewards
GET /staking/:wallet/positions/:id single stake + epoch breakdown
GET /keys/:keyId/epochs epoch reward history for a key

Accrued rewards are fetched live per request via simulateTransaction on the staking contract's get_stake_rewards view function; failures degrade to '0' so a temporarily unavailable contract doesn't break list responses.

  • prisma/schema/staking-epoch.prisma: Stake and EpochReward models; both idempotent on @@unique([txHash, eventIndex])
  • migration 20261020100000_add_staking_epochs: stakes and epoch_rewards DDL with composite indexes for active-position and epoch-history queries
  • staking-epoch.contract.ts: BigInt-safe ScVal decoder, mirrors lp-rewards contract pattern
  • staking-epoch.service.ts: recordStake/removeStake/recordEpochReward writes; getActivePositions/getPosition/getKeyEpochs reads with parallel live rewards
  • staking-epoch-indexer.service.ts: validates required fields + numeric/date sanity per event; REWARDS_CLAIMED closes position only when closePosition is true; checkpoints highest ledger after each batch
  • staking-epoch.routes.ts: wallet-scoped positions routes behind requireWalletParamMatch; epochs route behind requireJwtAuth
  • config.schema.ts: adds optional STAKING_CONTRACT_ID env var
  • indexer-pipeline.service.ts: routes STAKING_EPOCH_EVENT_TYPES via lazy import before cursor advance

Summary

Testing

  • pnpm lint
  • pnpm build
  • pnpm exec prisma generate when schema or generated types changed

Checklist

  • Linked issue or backlog item
  • No secrets or live credentials added
  • Docs updated if setup or env changed
  • Change is scoped to one problem

…org#1086)

Index StakeCreated, EpochRewardDistributed, and RewardsClaimed contract
events into stakes and epoch_rewards tables. Expose three REST endpoints:

  GET /staking/:wallet/positions         active stakes with live rewards
  GET /staking/:wallet/positions/:id     single stake + epoch breakdown
  GET /keys/:keyId/epochs                epoch reward history for a key

Accrued rewards are fetched live per request via simulateTransaction on the
staking contract's get_stake_rewards view function; failures degrade to '0'
so a temporarily unavailable contract doesn't break list responses.

- prisma/schema/staking-epoch.prisma: Stake and EpochReward models; both
  idempotent on @@unique([txHash, eventIndex])
- migration 20261020100000_add_staking_epochs: stakes and epoch_rewards DDL
  with composite indexes for active-position and epoch-history queries
- staking-epoch.contract.ts: BigInt-safe ScVal decoder, mirrors lp-rewards
  contract pattern
- staking-epoch.service.ts: recordStake/removeStake/recordEpochReward writes;
  getActivePositions/getPosition/getKeyEpochs reads with parallel live rewards
- staking-epoch-indexer.service.ts: validates required fields + numeric/date
  sanity per event; REWARDS_CLAIMED closes position only when closePosition
  is true; checkpoints highest ledger after each batch
- staking-epoch.routes.ts: wallet-scoped positions routes behind
  requireWalletParamMatch; epochs route behind requireJwtAuth
- config.schema.ts: adds optional STAKING_CONTRACT_ID env var
- indexer-pipeline.service.ts: routes STAKING_EPOCH_EVENT_TYPES via lazy
  import before cursor advance
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@jennioo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093

Copy link
Copy Markdown
Member

⚠️ Merge Conflict Detected

This PR currently has a merge conflict and cannot be merged until it is resolved.

Please rebase or merge the latest changes from the base branch into your branch and push again.

1 similar comment
@Chucks1093

Copy link
Copy Markdown
Member

⚠️ Merge Conflict Detected

This PR currently has a merge conflict and cannot be merged until it is resolved.

Please rebase or merge the latest changes from the base branch into your branch and push again.

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.

Build staking epoch indexer and rewards accumulation API

2 participants