-
Notifications
You must be signed in to change notification settings - Fork 1
feat: track exact block of staking rewards #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ances Co-authored-by: petersalomonsen <9760441+petersalomonsen@users.noreply.github.com>
- Assert exact blocks where 6 staking rewards occurred (epochs 3728-3733) - Assert exact reward amounts from blockchain data - Verify balance progression from 1000 to 1000.49 NEAR over 6 epochs - Makes test deterministic and validates PR functionality with real blockchain data
- Add API verification to test_track_and_fill_staking_rewards - Query balance changes using same filters as API (exclude STAKING_SNAPSHOT) - Assert API returns only 6 STAKING_REWARD records, not 7 STAKING_SNAPSHOT - Verify API blocks match reward blocks exactly - Ensures users see only real staking reward events, not synthetic snapshots
Remove unused import of track_and_fill_staking_rewards function. The test uses run_monitor_cycle instead which handles the full workflow.
- Always add 'near' to tokens list in monitor cycle, even when other tokens (like intents) have already been discovered. Previously, NEAR was only added when the tokens list was empty. - When seeding initial balance for a token that hasn't changed within the lookback window, insert a SNAPSHOT record at the lookback boundary instead of erroring due to missing receipts. - Add exclude_snapshots query parameter to balance-changes API to filter out SNAPSHOT and STAKING_SNAPSHOT records. - Exclude STAKING_SNAPSHOT from recent activity endpoint.
Validates the fix for the bug where NEAR was only added to the tokens list when it was empty, and the fix for inserting SNAPSHOT records when balance hasn't changed within the lookback window. Uses webassemblymusic-treasury.sputnik-dao.near which has intents tokens but no recent NEAR transactions, ensuring NEAR gets tracked as a SNAPSHOT.
|
@race-of-sloths include |
|
@copilot Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: waiting for merge
Your contribution is much appreciated with a final score of 5! @petersalomonsen received 25 Sloth Points for reviewing and scoring this pull request. What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
|
@race-of-sloths score 5 |
Summary
This PR implements tracking of exact block heights for staking rewards, so users can see the actual reward amount without having to calculate differences between staking snapshots.
Features
1. Exact Block Staking Rewards
STAKING_REWARDcounterparty constant for staking rewards2. Balance Change API Improvements
exclude_snapshotsquery parameter to filter outSNAPSHOTandSTAKING_SNAPSHOTrecords3. Bug Fixes
API Changes
/api/balance-changesNew query parameter:
exclude_snapshots(boolean, optional) - Whentrue, excludesSNAPSHOTandSTAKING_SNAPSHOTrecordsExample:
curl "http://localhost:3000/api/balance-changes?account_id=your-account.near&exclude_snapshots=true"Staking Reward Record Example
{ "id": 3167, "block_height": 182449384, "block_time": "2026-01-24T00:19:08.761126Z", "token_id": "staking:astro-stakers.poolv1.near", "counterparty": "STAKING_REWARD", "amount": "0.040456086036518156197191", "balance_before": "1029.479523405233304042477556", "balance_after": "1029.519979491269822198674747" }Record Types
nearnearSNAPSHOTft-contract.nearintents.near:nep141:*staking:pool.nearSTAKING_SNAPSHOTstaking:pool.nearSTAKING_REWARDImplementation Details
track_and_fill_staking_rewards()- Main entry point that creates epoch snapshots and fills gapsfind_staking_gaps()- Detects gaps between staking snapshots with different balancesfill_staking_gap()- Binary search to find exact block of balance changeinsert_staking_reward()- Creates STAKING_REWARD record at exact blockTests
test_find_staking_gaps- Gap detection between staking snapshotstest_insert_staking_reward- Staking reward record insertiontest_track_and_fill_staking_rewards- End-to-end staking reward trackingtest_near_snapshot_with_existing_intents_tokens- Validates NEAR tracking fixFiles Changed
src/handlers/balance_changes/account_monitor.rs- Always include NEAR in tokens listsrc/handlers/balance_changes/gap_filler.rs- SNAPSHOT for unchanged balances in lookback windowsrc/handlers/balance_changes/staking_rewards.rs- New gap filling and reward trackingsrc/routes/balance_changes.rs- Addedexclude_snapshotsfiltertests/balance_collection_integration_test.rs- Test for NEAR + intents fixtests/staking_rewards_test.rs- Tests for staking gap filling