Skip to content

[VPD-1182]: add script to drain pendingScoreUpdates after addMarket#671

Merged
fred-venus merged 3 commits into
developfrom
feat/VPD-1182
May 17, 2026
Merged

[VPD-1182]: add script to drain pendingScoreUpdates after addMarket#671
fred-venus merged 3 commits into
developfrom
feat/VPD-1182

Conversation

@Debugger022
Copy link
Copy Markdown
Contributor

Summary

  • After addMarket/updateAlpha/updateMultipliers, Prime queues a score update per holder and freezes issue/burn until the queue drains. There is no on-chain holder enumeration and no existing keeper, so the queue must be drained manually.
  • Adds a standalone script that reconstructs the holder set from Mint/Burn events and batches updateScores until pendingScoreUpdates == 0. Resumable across runs via the contract's isScoreUpdated[roundId][user] mapping.

Changes

  • scripts/prime-update-scores.ts — new script. Exports chunk/eventsToHolders/fetchHolderEvents/runUpdate for testability; main() guarded by require.main === module. Address resolved via deployments.get("Prime"). Env vars: FROM_BLOCK, BLOCK_RANGE, DRY_RUN.
  • tests/hardhat/Scripts/primeUpdateScores.ts — 18 unit tests covering pure logic (chunk, eventsToHolders) plus runUpdate orchestration against a hand-rolled PrimeStub.
  • tests/hardhat/Scripts/primeUpdateScores.e2e.ts — 4 end-to-end tests against a real deployed Prime via the existing deployProtocol fixture. Trigger is the real addMarket(vU) codepath. Covers full drain, multi-batch chunking by maxLoopsLimit, resumability, and burn handling.
  • tests/hardhat/Prime/Prime.ts — added export to SetupProtocolFixture and deployProtocol so the E2E test can reuse them. No behavioral change.

Test plan

  • FORKED_NETWORK= npx hardhat test tests/hardhat/Scripts/ — expect 46 passing (18 unit + 4 E2E + 24 inherited via fixture import)
  • Dry-run against bscmainnet to preview holder count + batch plan:
    DRY_RUN=1 FROM_BLOCK=<prime_deploy_block> BLOCK_RANGE=2000 npx hardhat run scripts/prime-update-scores.ts --network bscmainnet
  • Confirm prime.paused() == false before any real execution
  • Real execution (post-addMarket(vU)):
    FROM_BLOCK=<prime_deploy_block> BLOCK_RANGE=2000 npx hardhat run scripts/prime-update-scores.ts --network bscmainnet
  • Verify pendingScoreUpdates() == 0 after run completes

Reconstructs holders from Mint/Burn events, batches updateScores by
maxLoopsLimit until drained. Resumable via on-chain isScoreUpdated.
Covered by 18 unit + 4 E2E tests (real Prime via deployProtocol).
@Debugger022 Debugger022 self-assigned this May 11, 2026
@Debugger022 Debugger022 marked this pull request as ready for review May 12, 2026 08:40
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Comment thread scripts/prime-update-scores.ts Outdated
Comment thread scripts/prime-update-scores.ts Outdated
Batch isScoreUpdated reads via Promise.all(20) — ~20x faster on
the cold path. Default FROM_BLOCK to BSC Prime deploy block
(33_264_762) so operators skip the lookup.
Copy link
Copy Markdown
Contributor

@fred-venus fred-venus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, lets see what happen tmr, if not good, might need retry mechanism

@fred-venus
Copy link
Copy Markdown
Contributor

performed some adjustment accordingly:

  • IP-7825 gas cap
  • holder cache
  • RPC retry

already drained pendingScoreUpdates, now back to 0

CleanShot 2026-05-17 at 14 21 25@2x

Cap tx gas at 15M (BSC's EIP-7825 cap is 2^24); add holder cache so reruns
skip the scan; retry transient ECONNRESET on isScoreUpdated + updateScores.
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Health
contracts 100% 100%
contracts.Admin 88% 41%
contracts.Comptroller 100% 90%
contracts.Comptroller.Diamond 95% 64%
contracts.Comptroller.Diamond.facets 87% 73%
contracts.Comptroller.Diamond.interfaces 100% 100%
contracts.Comptroller.Types 100% 100%
contracts.Comptroller.legacy 100% 100%
contracts.Comptroller.legacy.Diamond 0% 0%
contracts.Comptroller.legacy.Diamond.facets 0% 0%
contracts.Comptroller.legacy.Diamond.interfaces 100% 100%
contracts.DelegateBorrowers 100% 89%
contracts.FlashLoan.interfaces 100% 100%
contracts.Governance 68% 45%
contracts.InterestRateModels 74% 59%
contracts.Lens 43% 46%
contracts.Liquidator 83% 60%
contracts.Oracle 100% 100%
contracts.PegStability 88% 84%
contracts.Swap 87% 58%
contracts.Swap.interfaces 100% 100%
contracts.Swap.lib 81% 55%
contracts.Tokens 100% 100%
contracts.Tokens.Prime 97% 73%
contracts.Tokens.Prime.Interfaces 100% 100%
contracts.Tokens.Prime.libs 90% 76%
contracts.Tokens.VAI 82% 52%
contracts.Tokens.VRT 20% 9%
contracts.Tokens.VTokens 70% 52%
contracts.Tokens.VTokens.legacy 0% 0%
contracts.Tokens.VTokens.legacy.Utils 0% 0%
contracts.Tokens.XVS 19% 8%
contracts.Tokens.test 100% 100%
contracts.Utils 52% 31%
contracts.VAIVault 50% 45%
contracts.VRTVault 49% 36%
contracts.XVSVault 63% 50%
contracts.external 100% 100%
contracts.lib 89% 71%
Summary 57% (3740 / 6546) 43% (1412 / 3276)

@fred-venus fred-venus merged commit 7bb5c03 into develop May 17, 2026
5 checks passed
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.

2 participants