Skip to content

fix: attempt at fixing rfox apy since usdc change#12120

Merged
gomesalexandre merged 5 commits intodevelopfrom
rfox-apy
Mar 13, 2026
Merged

fix: attempt at fixing rfox apy since usdc change#12120
gomesalexandre merged 5 commits intodevelopfrom
rfox-apy

Conversation

@NeOMakinG
Copy link
Collaborator

@NeOMakinG NeOMakinG commented Mar 9, 2026

Description

Fix rFOX APY calculation returning 0 after the v3 migration from RUNE to USDC rewards (epoch 18+).

Root cause: useCurrentApyQuery was treating totalRevenue from the epoch IPFS data as RUNE base units — wrapping it in BigAmount.fromBaseUnit({ precision: 8 }) and multiplying by RUNE price. Since the rFOX v3 migration at epoch 18, totalRevenue is stored as a USD decimal string (String(revenue.totalUsd)). Passing a value like "28928.25" into fromBaseUnit with precision 8 produced ~0.00028, making APY effectively 0.

Fix: Use bn(totalRevenue) directly since it's already USD — no base-unit conversion or RUNE price multiplication needed. Removed all RUNE-specific dependencies (thorchainAssetId, RUNE price history, runeAsset) from the hook.

Verified against raw IPFS epoch data:

Epoch totalRevenue Format
17 (pre-v3) "163737430793" RUNE base units
18 (transition) "20806.287943240724" USD
19 (post-v3) "28928.2559199948" USD

Risk

Low — isolated display-only fix in a single hook. No on-chain transactions, no state mutations, no wallet interactions affected. The only change is how the APY percentage is derived from existing epoch data.

rFOX APY display on the Fox page, Earn dashboard staking positions.

Testing

Engineering

  1. pnpm dev and navigate to the rFOX staking page (Fox page → rFOX section)
  2. Verify APY is displayed as a non-zero percentage
  3. Sanity-check the value: APY ≈ (totalRevenue × distributionRate / totalStakedUsd) × 12
    • totalRevenue ≈ $28,928 (epoch 19), distributionRate = 0.25 — can cross-reference with raw IPFS data at https://gateway.pinata.cloud/ipfs/bafkreiet7t7ypl55rkdpcj3eqvc4lnn3bbwxv5jiofvafq3pp4f5rj74sm
  4. Check Earn dashboard → rFOX staking positions also show the updated APY
  5. Confirm no TypeScript or lint errors: pnpm run lint && pnpm run type-check

Operations

  • Navigate to the Fox page → rFOX section and verify APY is displayed (previously showed 0%)
  • Navigate to Earn dashboard and confirm rFOX staking positions show the APY
  • Verify no visual regressions on the rFOX staking UI

Screenshots (if applicable)

image

Summary by CodeRabbit

  • Refactor
    • Streamlined APY calculation logic by consolidating data sources and removing redundant dependencies, resulting in improved efficiency and code maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7b21168b-6b43-4482-9639-d13795d379e5

📥 Commits

Reviewing files that changed from the base of the PR and between 455bdca and 500fb05.

📒 Files selected for processing (1)
  • src/pages/RFOX/hooks/useCurrentApyQuery.ts

📝 Walkthrough

Walkthrough

The hook for APY query calculations was refactored to remove rune-related data retrieval and price history calculations, consolidating the APY computation to depend solely on staking asset data and the latest epoch's total revenue.

Changes

Cohort / File(s) Summary
APY Calculation Simplification
src/pages/RFOX/hooks/useCurrentApyQuery.ts
Removed thorchainAssetId and rune price history retrieval. Simplified APY calculation to compute rewardDistributionUsd directly from latestEpoch.totalRevenue. Updated useCallback dependencies to reflect removal of rune-related state and assets.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 No more runes to chase around,
Just staking assets, code less bound,
APY flows from revenue alone,
Dependencies trimmed to the bone!
Simpler hooks, cleaner ground. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: addressing rFOX APY calculation issues following a USDC-related change (v3 migration from RUNE to USDC rewards).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rfox-apy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@NeOMakinG NeOMakinG marked this pull request as ready for review March 9, 2026 11:27
@NeOMakinG NeOMakinG requested a review from a team as a code owner March 9, 2026 11:27
@NeOMakinG
Copy link
Collaborator Author

@kaladinlight you've more context on this so I would prefer you to pick up this PR review if possible 🙏

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

Review: LGTM

Tested locally on rfox-apy branch (port 3001) with native wallet 0x5daF465a9cCf64DEB146eEaE9E7Bd40d6761c986.

Verification

  • rFOX Staking section displays 51.68% APY (previously showed 0%)
  • Staking Balance: 1.42287413 FOX ($0.01)
  • Lifetime Rewards: $0.01
  • Pending Rewards: 0.000098 USDC
  • Time in Pool: 8 months
  • rFOX Simulator renders correctly with estimated rewards
  • FOX Token section, FOX Farming+, Governance all load fine
  • No visual regressions

Code review

Cross-referenced against raw IPFS epoch data:

  • Epoch 17 (pre-v3): totalRevenue = "163737430793" (RUNE base units) - old formula was correct here
  • Epoch 18 (v3 transition): totalRevenue = "20806.287943240724" (USD decimal string)
  • Epoch 19 (current): totalRevenue = "28928.2559199948" (USD decimal string)

The old code passed the USD string through BigAmount.fromBaseUnit({ precision: 8 }) which divided by 10^8, producing ~0.00028 instead of ~28928. The fix correctly uses bn(totalRevenue) directly since it's already USD.

Verified all other rFOX hooks handle the v3 boundary correctly:

  • useLifetimeRewardsQuery - has epoch.number >= RFOX_V3_UPGRADE_EPOCH guard
  • useCurrentEpochRewardsQuery - uses USDC throughout
  • calcEpochRewardForAccountUsdcBaseUnit - USDC-native math

Safe because useCurrentApyQuery only uses epochs[0] (latest epoch, always >= 18 now), so no backward-compat concern with old RUNE-format epochs.

Blatant omission from the v3 migration, good catch Neo

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

✅ QA Bot — 2/2 Passed

rFOX APY fix verified on localhost:3000

Check Result
Fox Ecosystem page shows rFOX Staking APY ✅ 51.68% APY
APY persists on page revisit

Code Review

Clean fix. totalRevenue switched from RUNE base units to USD at epoch 18 (rFOX v3 migration). The old code wrapped it in BigAmount.fromBaseUnit({ precision: 8 }) which turned 28928.25 into ~0.00028, making APY effectively 0. Fix correctly uses bn(totalRevenue) directly since it's already USD. All RUNE dependencies removed from the hook.

QA Bot Run

@gomesalexandre gomesalexandre enabled auto-merge (squash) March 13, 2026 09:57
@gomesalexandre gomesalexandre merged commit ff0aa68 into develop Mar 13, 2026
4 checks passed
@gomesalexandre gomesalexandre deleted the rfox-apy branch March 13, 2026 10:07
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