fix(swapper): correct maya non-cacao outbound fee precision#12341
fix(swapper): correct maya non-cacao outbound fee precision#12341kaladinlight wants to merge 2 commits into
Conversation
CACAO is 10-dec but MAYA pool assets are 8-dec; without converting the native fee to the sell asset's precision before dividing by `assetPrice`, the outbound-fee threshold was 100x too large, silently zeroing out legitimate affiliate fees on MAYA non-CACAO swaps. Also unifies *ThorBaseUnit naming and surfaces useful axios error messages from checkTradeStatus instead of dumping the full error object. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ 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 |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Description
Fixes a precision bug in
getThresholdedAffiliateBpsfor MAYA non-CACAO swaps. Midgard'sassetPriceis a precision-normalized decimal ratio (native asset per sell asset), but the previous implementation divided the raw native fee by it without first reconciling that MAYA's CACAO is 10-dec while pool assets are 8-dec.Result: the outbound-fee threshold was 100x too large on MAYA non-CACAO pairs, silently zeroing out legitimate affiliate fees.
Also included:
*SellAssetThorBaseUnit(was mixedThorUnit/ThorBaseUnit/InSellAsset/SellAsset).checkTradeStatusno longer dumps the full axios error object; logscheckTradeStatus(<chain>, <txHash>): <message>with the response body when present.Issue (if applicable)
closes #
Risk
THORChain and Mayachain L1 swap quotes. Behavior is unchanged for THOR (8→8 precision conversion is a no-op) and for native sell assets (RUNE/CACAO, gated upstream). Only MAYA non-CACAO sell assets see a change: outbound fee comparison value is now 100x smaller, matching reality.
Testing
Engineering
pnpm vitest run packages/swapper/src/thorchain-utils/getThresholdedAffiliateBpsMath walkthrough for the new test:
NATIVE_FEE = 2_000_000_000(0.2 CACAO @ 10-dec)assetPrice = 100(1 ETH = 100 CACAO)convertPrecision(2_000_000_000, 10, 8) = 20_000_00020_000_000 / 100 = 200_000(0.002 ETH @ 8-dec) ✓Operations
Not behind a flag, but the change only affects MAYA non-CACAO affiliate fee calculations server-side — no UI changes. Smoke a MAYA non-CACAO swap (e.g. ETH→BTC) and verify quotes still return normally; expectation is that more swaps now correctly carry the configured affiliate BPS instead of
0.Screenshots (if applicable)
n/a
🤖 Generated with Claude Code