Skip to content

Rango: Add Tron swap support - #484

Open
j0ntz wants to merge 1 commit into
masterfrom
jon/rango-tron-contract-call
Open

Rango: Add Tron swap support#484
j0ntz wants to merge 1 commit into
masterfrom
jon/rango-tron-contract-call

Conversation

@j0ntz

@j0ntz j0ntz commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

Needs edge-currency-accountbased Tron contract-call support to execute (PR linked in the description).

Description

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

tron -> TRON has been in the Rango mapping all along, so TRON quotes were already being
requested. Building the transaction was the missing half: tx.type === 'TRON' fell into the
default: branch, which runs asEvmTransaction(tx) and throws.

What changed

  • asTronTransaction reads Rango's raw_data (and approve_raw_data) as a
    TriggerSmartContract payload. Every level uses .withRest, so nothing the provider sent is
    dropped before it reaches the currency plugin — parameter.type_url is serialized into the
    signed raw data, so losing it would change the transaction.
  • The TRON case builds a spendInfo carrying { contractJson, feeLimit } in otherParams
    and targeting the router address. A TRC20 sell also needs an allowance, which Rango returns
    inline as approve_raw_data; that becomes a tokenApproval pre-transaction, the same shape
    the EVM path already uses.
  • hexToTronAddress converts the hex addresses in a contract payload to the base58check form
    wallets and spend targets speak.

Testing

Unit tests cover the address conversion against the USDT contract, the Sun Swap router, and an
owner address.

Driven against the live Rango API with stub wallets: a native TRX sell produces one swap
spendInfo with call_value set and no approval; a USDT sell produces the 095ea7b3 approval
pre-transaction followed by the swap.

Then end to end on the iOS sim with edge-currency-accountbased#1088
linked in: a TRX → USDT swap through Rango reached the success scene, and on-chain
42fd4970…9650
is a TriggerSmartContract with contractRet: SUCCESS, selector cef95229 against the Sun Swap
router, delivering 13.004043 USDT in the same transaction. Screenshots in a comment below.


Note

Medium Risk
Adds a new on-chain swap execution path with TRC20 approvals; validation mitigates wrong-spender approvals, but execution still depends on companion Tron contract-call support in the currency plugin.

Overview
Rango TRON swaps no longer hit the EVM default branch and fail parsing. Responses with tx.type === 'TRON' are validated and turned into wallet spends that pass Rango’s TriggerSmartContract payload through to the Tron currency plugin via otherParams.contractJson and feeLimit.

For TRC20 sells, when Rango includes approve_raw_data, the plugin queues a tokenApproval pre-transaction (same pattern as EVM). It decodes the approval spender from call data and rejects approvals that don’t target the swap router or the token being sold.

Address helpers hexToTronAddress and decodeTronApprovalSpender convert hex contract addresses to base58 and parse approve() calldata; unit tests cover known contracts and error cases.

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

@j0ntz

j0ntz commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence: Rango TRX → USDT swap on iOS sim

rango trx usdt quote

rango trx usdt quote

rango trx swap success

rango trx swap success

rango trx tx details

rango trx tx details

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

@j0ntz
j0ntz force-pushed the jon/rango-tron-contract-call branch from 49ca31d to dc41dc5 Compare August 14, 2026 17:24
@j0ntz
j0ntz marked this pull request as ready for review August 14, 2026 17:24
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@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.

Stale comment

Comment thread src/swap/defi/rango.ts
A TRON quote fell through to the EVM transaction handler and threw,
even though the chain was already mapped. Build the spend from the
TriggerSmartContract call Rango returns, passing it to the currency
plugin intact, and turn the router allowance Rango returns alongside a
TRC20 sell into a pre-transaction.
@j0ntz
j0ntz force-pushed the jon/rango-tron-contract-call branch from dc41dc5 to bcccdb3 Compare August 14, 2026 17:38
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