Add projected prize pool balance and share price for real-time frontend display - #90
Open
bboud2 wants to merge 1 commit into
Open
Add projected prize pool balance and share price for real-time frontend display#90bboud2 wants to merge 1 commit into
bboud2 wants to merge 1 commit into
Conversation
Add two read-only view functions for real-time frontend display: - getProjectedPrizePoolBalance(): Projects the prize pool balance by querying the yield source live and applying the distribution strategy to unsync'd yield (or the deficit waterfall for losses). - getProjectedSharePrice(): Projects the share price by computing what syncWithYieldSource() would do to totalAssets (rewards portion of pending yield, or deficit impact on rewards after protocol/prize absorb first). Both are view-only with no state mutation, no new storage, and no entitlements — minimal audit blast radius. Refactored getProjectedUserBalance() to delegate to getProjectedSharePrice(), eliminating duplicated projection logic. Includes query scripts (production + test versions), test helper wrappers, and 11 tests covering excess yield, deficit, deficit absorbed by protocol fee, below-threshold, convergence after sync, and the refactored getProjectedUserBalance.
bboud2
force-pushed
the
feature/projected-prize-pool-and-share-price
branch
from
June 23, 2026 18:40
5d3a08e to
33bef15
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The frontend reports stale prize pool and share price values. These are derived from cached variables (, ) that only update when
syncWithYieldSource()runs — which happens on deposits/withdrawals, admin-triggered syncs, orstartDraw(). Between syncs, the yield source keeps accruing value but the displayed numbers don't change.Solution
Two read-only view functions that query the yield source live and project what sync would do — no state mutation, no new storage, no entitlements. Minimal audit blast radius.
getProjectedPrizePoolBalance()calculateDistribution()on the unsync'd difference, adds the prize portion toallocatedPrizeYieldgetProjectedSharePrice()totalAssets, computes projected price with virtual offsetgetSharePrice()Refactor
getProjectedUserBalance()now delegates togetProjectedSharePrice()instead of duplicating the projection math. Behavior identical — verified by all existingProjectedBalance_test.cdctests passing unchanged.Files Changed
cadence/contracts/PrizeLinkedAccounts.cdcgetProjectedUserBalancecadence/scripts/prize-linked-accounts/get_projected_prize_pool_balance.cdccadence/scripts/prize-linked-accounts/get_projected_share_price.cdccadence/scripts/test/get_projected_prize_pool_balance.cdccadence/scripts/test/get_projected_share_price.cdccadence/tests/test_helpers.cdccadence/tests/ProjectedPrizePoolAndSharePrice_test.cdcTest Results
New tests (11/11 pass):
Existing tests: All
ProjectedBalance_test.cdctests (7/7) pass — refactor is safe. Full suite passes (one pre-existing flaky randomness test inTWABAdversarialDeposit_test.cdcis unrelated and passes in isolation).Frontend Migration
get_pool_stats.cdc→prizePoolBalanceget_projected_prize_pool_balance.cdc→projectedPrizePoolBalanceget_pool_stats.cdc→sharePriceget_projected_share_price.cdc→projectedSharePriceget_pool_balance.cdc→totalBalanceget_projected_balance.cdc→projectedBalance(already existed)Both scripts return the projected and synced values so the frontend can compare or transition gradually.