Skip to content

Fix Maya CACAO source swaps (below min limit / Invalid publicAddress)#465

Merged
j0ntz merged 1 commit into
masterfrom
jon/fix-maya-cacao-swap
Jun 23, 2026
Merged

Fix Maya CACAO source swaps (below min limit / Invalid publicAddress)#465
j0ntz merged 1 commit into
masterfrom
jon/fix-maya-cacao-swap

Conversation

@j0ntz

@j0ntz j0ntz commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

Fixes Maya Protocol swaps from CACAO (e.g. CACAO → BTC), which failed at every amount with "amount is below the min limit" (and, at large amounts, an Invalid publicAddress core log). Maya CACAO → BTC works on the Maya website, so this was an Edge-side plugin bug.

There were two distinct root causes in the shared Thorchain/Maya plugin code (src/swap/defi/thorchain/thorchainCommon.ts):

  1. Wrong pluginId for the native deposit branch. The RUNE/CACAO MakeTxDeposit path was gated on fromWallet.currencyInfo.pluginId === 'cacao', but the Maya chain's pluginId is mayachain (CACAO is only the currency code, confirmed in edge-currency-accountbased mayachainInfo.ts). CACAO sources never matched the deposit branch, fell through to the UTXO path, left publicAddress null, and threw Invalid publicAddress once an amount cleared the (broken) min check. The GUI surfaces that thrown error as the generic "below min limit" message.

  2. Wrong amount precision for Mayanode quotes. Mayanode expresses quote amounts in each asset's native precision (CACAO is 1e10, BTC is 1e8), whereas Thornode normalizes everything to THOR_LIMIT_UNITS (1e8). Using 1e8 for CACAO under-scaled the amount sent to Mayanode by 100×, so any normal amount came back below Maya's minimum. A new getNodeLimitUnits helper resolves the correct multiplier per asset for Maya (the asset's native multiplier) while leaving Thorchain on THOR_LIMIT_UNITS. The deposit coin decimals likewise now uses the source asset's native multiplier (a no-op for RUNE, since its native multiplier already equals 1e8).

Thorchain (RUNE) behavior is unchanged: for every RUNE/Thorchain asset the new helper resolves to the existing THOR_LIMIT_UNITS.

Testing

Verified end to end on the iOS simulator with the funded edge-funds MAYAChain wallet:

  • tsc + eslint + jest (verify-repo.sh) pass.
  • Before the fix, a CACAO → BTC swap returned "amount is below the min limit" at $15, $100, and MAX.
  • After the fix, a 942.667 CACAO (~$100) → BTC quote resolves correctly (0.00156738 BTC, matching a direct Mayanode /quote/swap call) and the swap executes through the confirm slider to the "Congratulations! Your exchange is being processed!" success scene.

Screenshots attached below.

Asana: https://app.asana.com/0/1215088146871429/1215734647159265


Note

Medium Risk
Touches shared quote and tx-building logic for all Maya swaps and max-quote paths; Thorchain is gated on pluginId but any Maya precision mistake could mis-quote or mis-build deposits.

Overview
Fixes Maya Protocol swaps when CACAO is the source (e.g. CACAO → BTC), which previously failed with “below min limit” or Invalid publicAddress.

The shared Thorchain/Maya plugin now treats native CACAO/RUNE deposits with wallet pluginId mayachain instead of the non-existent cacao, so CACAO uses the MakeTxDeposit path instead of falling through to UTXO handling.

For mayaprotocol quotes, amounts sent to Mayanode and converted back use getNodeLimitUnits (per-asset native multipliers via exported getTokenMultiplier) instead of universal THOR_LIMIT_UNITS (1e8)—fixing ~100× under-scaling for CACAO (1e10). Deposit decimals and max-quote probe amounts follow the same multipliers (e.g. ~1000 CACAO for max seeds on Maya).

Thorchain/RUNE behavior is unchanged when the helper resolves to 1e8.

Reviewed by Cursor Bugbot for commit d57b048. Bugbot is set up for automated code reviews on this repo. Configure here.

@j0ntz

j0ntz commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence — CACAO → BTC Maya swap on iOS sim

agent proof 1215734647159265 01 cacao btc quote

agent proof 1215734647159265 01 cacao btc quote

agent proof 1215734647159265 02 swap success

agent proof 1215734647159265 02 swap success

Captured by the agent's in-app test run (build-and-test).

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3e8b1c0. Configure here.

Comment thread src/swap/defi/thorchain/thorchainCommon.ts
@j0ntz j0ntz force-pushed the jon/fix-maya-cacao-swap branch from 3e8b1c0 to bf81347 Compare June 18, 2026 19:01
@j0ntz

j0ntz commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence (after fix) — MAX CACAO → BTC quote resolves

agent proof 1215734647159265 03 max quote

agent proof 1215734647159265 03 max quote

Captured by the agent's in-app test run (build-and-test).

@peachbits peachbits left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is fine. I would have preferred to see the getNodeLimitUnits to be passed into makeThorchainBasedPlugin as an opt to avoid another instance of the common code asking itself what it is but we can clean up if we add another clone later.

@j0ntz j0ntz enabled auto-merge June 23, 2026 22:17
Swapping CACAO (Maya Protocol native asset) to BTC failed at any amount.
Two distinct bugs in the shared Thorchain/Maya plugin code were responsible:

1. The native RUNE/CACAO deposit branch was gated on a source wallet
   pluginId of 'cacao', but the Maya chain's pluginId is 'mayachain'
   (CACAO is only the currency code). CACAO sources never matched the
   deposit branch and fell through to the UTXO path, throwing
   'Invalid publicAddress' once an amount cleared the min check.

2. Mayanode expresses quote amounts in each asset's native precision
   (CACAO is 1e10, BTC is 1e8), whereas Thornode normalizes everything
   to THOR_LIMIT_UNITS (1e8). Using 1e8 for CACAO under-scaled the
   amount sent to Mayanode by 100x, so normal amounts came back below
   the min limit. Quote conversions and the deposit's coin decimals now
   use each asset's native multiplier for Maya; Thorchain is unchanged
   (its multiplier resolves to THOR_LIMIT_UNITS).

Verified end to end on the iOS simulator: a 942 CACAO -> BTC swap now
builds a correct quote and executes to the success scene.
@j0ntz j0ntz force-pushed the jon/fix-maya-cacao-swap branch from bf81347 to d57b048 Compare June 23, 2026 22:38
@j0ntz j0ntz merged commit a1f9489 into master Jun 23, 2026
4 checks passed
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