Rango: Add Tron swap support - #484
Conversation
49ca31d to
dc41dc5
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
dc41dc5 to
bcccdb3
Compare
2abfbd5 to
85efab4
Compare
85efab4 to
407fb33
Compare
There was a problem hiding this comment.
Stale comment
Agentic security review found one remaining high-severity issue on the TRON swap path: provider swap calldata is still not bound to the quoted sell after the sold-token and selector checks. Approval amount and
call_valueguards do not cover an omitted-approval router pull against an existing allowance, orincreaseApprovalon a token other than the asset being sold.Sent by Cursor Security Agent: Security Reviewer
a937ff0 to
a89a728
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a89a728. Configure here.
|
Correction to the "Test evidence (apikey query param)" comment above: that Polygon swap ran the published edge-exchange-plugins 2.55.0, not this branch. The iOS build's |
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.
Rango is deprecating its old way of passing the API key and asked for the `apikey` query parameter. Its API still answers 401 to `apikey` alone and 200 when the legacy `apiKey` parameter rides with it, so both are sent until the lowercase name is accepted on its own.
a89a728 to
8dd52d9
Compare
There was a problem hiding this comment.
Agentic security review of the Rango TRON path found one remaining high-severity issue: provider fee_limit is copied unbounded onto the signed spend while the displayed network fee uses the energy estimate (or a small fallback). Prior findings on this PR were already addressed.
Sent by Cursor Security Agent: Security Reviewer

















CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
Needs
edge-currency-accountbasedTron contract-call support to execute (PR linked in the description).Description
Asana: https://app.asana.com/0/1215088146871429/1216839790397157
tron -> TRONhas been in the Rango mapping all along, so TRON quotes were already beingrequested. Building the transaction was the missing half:
tx.type === 'TRON'fell into thedefault:branch, which runsasEvmTransaction(tx)and throws.What changed
asTronTransactionreads Rango'sraw_data(andapprove_raw_data) as aTriggerSmartContractpayload. Every level uses.withRest, so nothing the provider sent isdropped before it reaches the currency plugin:
parameter.type_urlis serialized into thesigned raw data, so losing it would change the transaction.
TRONcase builds aspendInfocarrying{ contractJson, feeLimit }inotherParamsand targeting the router address. A TRC20 sell also needs an allowance, which Rango returns
inline as
approve_raw_data; that becomes atokenApprovalpre-transaction, the same shapethe EVM path already uses.
call_valuemay not exceed the quoted amount (native TRX) or be nonzero (TRC20), and the approval must
grant the swap router, over the sold token, no more than the quoted sell amount, with no TRX
attached. The swap itself may not call the sold token contract or use a transfer/approve
selector, so the bounded approval is the only call that touches the token directly. Neither call may
attach a TRC10 balance (
call_token_value).hexToTronAddressconverts the hex addresses in a contract payload to the base58check formwallets and spend targets speak.
Rango API key as
apikeyRango is deprecating its old way of passing the API key and asked for the
apikeyqueryparameter.
makeRangoAuthParamsputs the key in bothapikeyand the legacyapiKey, used bybasic/swapand the mapctl synchronizer'sbasic/meta. Sending onlyapikeyis not possibleyet: against
api.rango.exchange,apikeyalone returns 401,apiKeyalone 200, and bothtogether 200.
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
spendInfowithcall_valueset and no approval; a USDT sell produces the095ea7b3approvalpre-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
TriggerSmartContractwithcontractRet: SUCCESS, selectorcef95229against the Sun Swaprouter, delivering 13.004043 USDT in the same transaction. Screenshots in a comment below.
For the
apikeychange and the payload guards, with this branch's bundle andedge-currency-accountbased#1088's copied into the installed app:
plugin showed
basic/swapreturning 200 withapikeyandapiKeyin the query and no keyheader.
TriggerSmartContractSUCCESS, selectorcef95229,call_value14709000 (the quoted amount).60e0b6e4…
grants exactly 5002000 to the Sun Swap router with
call_value0, then swap87785e37…,
both SUCCESS.
1f6f4b0e…
granting exactly 3001000, swap
d44d1e67…,
both SUCCESS.
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
defaultbranch and fail parsing. Responses withtx.type === 'TRON'are validated and turned into wallet spends that pass Rango’sTriggerSmartContractpayload through to the Tron currency plugin viaotherParams.contractJsonandfeeLimit.For TRC20 sells, when Rango includes
approve_raw_data, the plugin queues atokenApprovalpre-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
hexToTronAddressanddecodeTronApprovalSpenderconvert hex contract addresses to base58 and parseapprove()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.