Skip to content

Add projected prize pool balance and share price for real-time frontend display - #90

Open
bboud2 wants to merge 1 commit into
mainfrom
feature/projected-prize-pool-and-share-price
Open

Add projected prize pool balance and share price for real-time frontend display#90
bboud2 wants to merge 1 commit into
mainfrom
feature/projected-prize-pool-and-share-price

Conversation

@bboud2

@bboud2 bboud2 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

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, or startDraw(). 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()

  • Excess yield: runs calculateDistribution() on the unsync'd difference, adds the prize portion to allocatedPrizeYield
  • Deficit: applies the waterfall (protocol fee → prize → rewards), reduces projected prize by only the prize-portion of the deficit
  • Below threshold: returns current synced value

getProjectedSharePrice()

  • Excess yield: adds the rewards portion (after virtual-share dust) to totalAssets, computes projected price with virtual offset
  • Deficit: subtracts only the rewards-portion of the deficit (after protocol/prize absorb first)
  • Below threshold: returns current getSharePrice()

Refactor

getProjectedUserBalance() now delegates to getProjectedSharePrice() instead of duplicating the projection math. Behavior identical — verified by all existing ProjectedBalance_test.cdc tests passing unchanged.

Files Changed

File Change
cadence/contracts/PrizeLinkedAccounts.cdc +2 Pool view functions, +2 contract-level wrappers, refactored getProjectedUserBalance
cadence/scripts/prize-linked-accounts/get_projected_prize_pool_balance.cdc Production query script
cadence/scripts/prize-linked-accounts/get_projected_share_price.cdc Production query script
cadence/scripts/test/get_projected_prize_pool_balance.cdc Test query script
cadence/scripts/test/get_projected_share_price.cdc Test query script
cadence/tests/test_helpers.cdc +2 test helper wrappers
cadence/tests/ProjectedPrizePoolAndSharePrice_test.cdc 11 new tests

Test Results

New tests (11/11 pass):

  • Projected equals synced when no unsync'd yield (both functions)
  • Projected reflects unsync'd yield (both functions)
  • Projected reflects deficit (both functions)
  • Deficit absorbed by protocol fee doesn't affect prize pool / share price
  • Below-threshold returns synced values
  • Projected user balance still correct after refactor
  • Projected prize pool with direct funding

Existing tests: All ProjectedBalance_test.cdc tests (7/7) pass — refactor is safe. Full suite passes (one pre-existing flaky randomness test in TWABAdversarialDeposit_test.cdc is unrelated and passes in isolation).

Frontend Migration

Current (stale) Replacement (real-time)
get_pool_stats.cdcprizePoolBalance get_projected_prize_pool_balance.cdcprojectedPrizePoolBalance
get_pool_stats.cdcsharePrice get_projected_share_price.cdcprojectedSharePrice
get_pool_balance.cdctotalBalance get_projected_balance.cdcprojectedBalance (already existed)

Both scripts return the projected and synced values so the frontend can compare or transition gradually.

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
bboud2 force-pushed the feature/projected-prize-pool-and-share-price branch from 5d3a08e to 33bef15 Compare June 23, 2026 18:40
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