fix: attempt at fixing rfox apy since usdc change#12120
fix: attempt at fixing rfox apy since usdc change#12120gomesalexandre merged 5 commits intodevelopfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
|
@kaladinlight you've more context on this so I would prefer you to pick up this PR review if possible 🙏 |
gomesalexandre
left a comment
There was a problem hiding this comment.
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- hasepoch.number >= RFOX_V3_UPGRADE_EPOCHguarduseCurrentEpochRewardsQuery- uses USDC throughoutcalcEpochRewardForAccountUsdcBaseUnit- 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
gomesalexandre
left a comment
There was a problem hiding this comment.
✅ 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.
Description
Fix rFOX APY calculation returning 0 after the v3 migration from RUNE to USDC rewards (epoch 18+).
Root cause:
useCurrentApyQuerywas treatingtotalRevenuefrom the epoch IPFS data as RUNE base units — wrapping it inBigAmount.fromBaseUnit({ precision: 8 })and multiplying by RUNE price. Since the rFOX v3 migration at epoch 18,totalRevenueis stored as a USD decimal string (String(revenue.totalUsd)). Passing a value like"28928.25"intofromBaseUnitwith 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:
totalRevenue"163737430793""20806.287943240724""28928.2559199948"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.
Testing
Engineering
pnpm devand navigate to the rFOX staking page (Fox page → rFOX section)APY ≈ (totalRevenue × distributionRate / totalStakedUsd) × 12totalRevenue≈ $28,928 (epoch 19),distributionRate= 0.25 — can cross-reference with raw IPFS data athttps://gateway.pinata.cloud/ipfs/bafkreiet7t7ypl55rkdpcj3eqvc4lnn3bbwxv5jiofvafq3pp4f5rj74smpnpm run lint && pnpm run type-checkOperations
Screenshots (if applicable)
Summary by CodeRabbit