Skip to content

fix(swapper): correct maya non-cacao outbound fee precision#12341

Open
kaladinlight wants to merge 2 commits into
developfrom
fix/maya-outbound-fee-precision
Open

fix(swapper): correct maya non-cacao outbound fee precision#12341
kaladinlight wants to merge 2 commits into
developfrom
fix/maya-outbound-fee-precision

Conversation

@kaladinlight
Copy link
Copy Markdown
Contributor

Description

Fixes a precision bug in getThresholdedAffiliateBps for MAYA non-CACAO swaps. Midgard's assetPrice is 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:

  • Unified naming on *SellAssetThorBaseUnit (was mixed ThorUnit / ThorBaseUnit / InSellAsset / SellAsset).
  • Distilled the precision comment to two lines.
  • checkTradeStatus no longer dumps the full axios error object; logs checkTradeStatus(<chain>, <txHash>): <message> with the response body when present.

Issue (if applicable)

closes #

Risk

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

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

  • Added unit test covering MAYA non-CACAO precision scaling (CACAO 10-dec native fee → 8-dec sell asset).
  • Existing THOR test continues to pass; the precision conversion is a no-op there.
  • pnpm vitest run packages/swapper/src/thorchain-utils/getThresholdedAffiliateBps

Math walkthrough for the new test:

  • MAYA 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_000
  • 20_000_000 / 100 = 200_000 (0.002 ETH @ 8-dec) ✓

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

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

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>
@kaladinlight kaladinlight requested a review from a team as a code owner May 14, 2026 18:50
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@kaladinlight has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 5 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec06512f-3325-4da6-96bf-7e9c7196e8d5

📥 Commits

Reviewing files that changed from the base of the PR and between 57810a2 and 7af432b.

📒 Files selected for processing (5)
  • packages/swapper/package.json
  • packages/swapper/src/thorchain-utils/checkTradeStatus.ts
  • packages/swapper/src/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.ts
  • packages/swapper/src/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.ts
  • packages/swapper/src/thorchain-utils/index.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/maya-outbound-fee-precision

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.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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