Skip to content

Fix EVM token swap pending metadata showing 0#466

Open
j0ntz wants to merge 1 commit into
masterfrom
jon/fix-evm-token-swap-metadata
Open

Fix EVM token swap pending metadata showing 0#466
j0ntz wants to merge 1 commit into
masterfrom
jon/fix-evm-token-swap-metadata

Conversation

@j0ntz

@j0ntz j0ntz commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

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

Fixes a Maya/Thorchain bug where swapping an EVM ERC20 token (e.g. USDT on Ethereum) to a native asset showed 0 for the value (coins, USD, percentage) in the transaction metadata while the swap was pending.

Root cause: in makeThorchainBasedPlugin (src/swap/defi/thorchain/thorchainCommon.ts), EVM token swaps set the spend target nativeAmount to 0 (it reused the ethNativeAmount value, which is the parent-currency tx value and is 0 for token contract calls). The currency engine derives the pending EdgeTransaction.nativeAmount from spendTarget.nativeAmount, so the token swap recorded 0 and the pending-transaction metadata rendered 0. Once the tx mined, the engine re-read the real on-chain token amount, which is why only the pending state was wrong.

Fix: set the spend target nativeAmount to fromNativeAmount (the token amount being spent). The broadcast transaction is unchanged: for an EVM token contract call the engine sends the router depositWithExpiry calldata and forces the tx value to 0 regardless of spendTarget.nativeAmount (getTxParameterInformation returns value: undefined and signTx hard-sets txValue = 0x00 for token contract calls), so spendTarget.nativeAmount only drives the displayed amount and the balance check. Native EVM, RUNE/CACAO, ZEC and UTXO paths already passed fromNativeAmount, so this is a no-op for them.

Applies to both Maya and Thorchain since they share this code.

Testing

  • tsc --noEmit, eslint, and the jest suite pass (verify-repo).
  • Built into edge-react-gui (iOS sim, edge-funds account) and drove the real swap: forced Maya/Thorchain as the only enabled providers, obtained a live Maya Protocol quote for USDT (Ethereum) to BTC, and confirmed (slider) so the patched quote-construction path ran. Execution timed out at Maya's network "Locating a swap" step (60s) before the deposit broadcast, so the pending-transaction metadata could not be captured; no funds moved. Screenshot below shows the patched Maya path producing the token-swap quote in-app.

Note

Low Risk
Metadata and spend-target labeling fix in shared Thorchain/Maya quote code; EVM token broadcast behavior is documented as unchanged.

Overview
Fixes Thorchain/Maya pending swap UI showing 0 coins, USD, and percentage when swapping an EVM ERC-20 (e.g. USDT on Ethereum) to another asset.

In thorchainCommon.ts, EVM token swaps no longer set the spend target nativeAmount to 0. They now use fromNativeAmount (the token amount being spent), matching native EVM and other chain paths. The old ethNativeAmount override existed because the router depositWithExpiry call sends zero parent-chain value for tokens; that on-chain behavior is unchanged—the currency engine still forces value to 0 for token contract calls.

spendTarget.nativeAmount only drives pending transaction metadata and balance checks, so pending state now shows the correct from-amount until the tx confirms.

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

For Thorchain and Maya EVM token swaps (e.g. USDT to ETH) the spend target
nativeAmount was set to 0, so the recorded transaction amount and its fiat and
percentage metadata displayed 0 while the swap was pending. Use the actual token
amount for the spend target; the broadcast contract call is unchanged because
the currency engine forces zero parent-currency value for token contract calls.
@j0ntz

j0ntz commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence — Maya Protocol quote for USDT(ETH) token swap (patched path exercised in-app)

agent proof 1211543001846210 01 maya usdt swap quote

agent proof 1211543001846210 01 maya usdt swap quote

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

@j0ntz

j0ntz commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence — real Maya USDT(ETH)→ETH swap, pending metadata now non-zero (followup verification)

agent proof 1211543001846210 01 maya quote

agent proof 1211543001846210 01 maya quote

agent proof 1211543001846210 02 swap success

agent proof 1211543001846210 02 swap success

agent proof 1211543001846210 03 pending metadata nonzero

agent proof 1211543001846210 03 pending metadata nonzero

agent proof 1211543001846210 04 exchange details onchain

agent proof 1211543001846210 04 exchange details onchain

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

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