Skip to content

fix: tron butter swaps#11783

Merged
gomesalexandre merged 6 commits intodevelopfrom
tron-swap-fix
Jan 27, 2026
Merged

fix: tron butter swaps#11783
gomesalexandre merged 6 commits intodevelopfrom
tron-swap-fix

Conversation

@NeOMakinG
Copy link
Collaborator

@NeOMakinG NeOMakinG commented Jan 27, 2026

Description

We were not supporting smart contract calls when swapping for TRON, this was the main reason why it was failing

Another thing: every swaps are applying a 20 TRX fees, quite expensive, so don't forget to have as much TRX in your pockets

Issue (if applicable)

Spotted in release thread

Risk

Quite high

High Risk PRs Require 2 approvals

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

Testing

  • Bridge from any chain to TRON using butter (status endpoint can take much time to be success)
  • Swap from TRX to USDC on Tron (be careful to be well funded, it costs 20 TRX as fees + gas fees)
  • Swap from USDC to TRX (same, be well funded because 20 TRX fees are applied)

Engineering

Operations

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

Screenshots (if applicable)

https://jam.dev/c/fcee306c-8ecf-49e5-af98-f1ae3d264d02

Summary by CodeRabbit

  • New Features
    • Added support for custom API transactions on the Tron blockchain.
    • Enhanced Tron smart contract interaction capabilities for swaps.
    • Improved Tron chain integration with extended transaction metadata handling.

✏️ Tip: You can customize this high-level summary in your review settings.

NeOMakinG and others added 3 commits January 27, 2026 02:29
This commit adds proper support for Tron contract calls in ButterSwap
integration but temporarily disables Tron due to persistent contract
revert issues with Butter Network's Tron contracts.

Changes:
- Add buildCustomApiTx() to TronChainAdapter supporting arbitrary
  contract calls with both raw calldata and method/args formats
- Fix ButterSwap to use buildCustomApiTx for Tron swaps with proper
  value handling (only send value for native TRX swaps)
- Add method/args fields to butterSwapTransactionMetadata type
- Fix allowanceContract to use buildTx.to for Tron (Butter doesn't
  return route.contract for Tron chains)
- Add referrer parameter for same-chain Tron swaps (similar to Solana)
- Temporarily disable Tron support until Butter's contract revert
  issue can be resolved

The transaction building logic is correct and should work once Butter
Network fixes their Tron contract issues. Multiple test attempts
resulted in contract reverts despite correct calldata, approvals, and
transaction structure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

This change introduces a new buildCustomApiTx method to the Tron ChainAdapter for constructing custom API transactions using raw data fields. It integrates this capability into the ButterSwap flow for same-chain swaps, extending type definitions to carry method and args metadata through the transaction building pipeline.

Changes

Cohort / File(s) Summary
Tron Chain Adapter
packages/chain-adapters/src/tron/TronChainAdapter.ts
Introduces new public method buildCustomApiTx() that constructs custom API transactions by sending triggersmartcontract requests to TronGrid API, validating responses, extracting/normalizing raw_data_hex, and returning a TronSignTx with error handling.
ButterSwap Integration
packages/swapper/src/swappers/ButterSwap/swapperApi/getTradeQuote.ts, packages/swapper/src/tron-utils/getUnsignedTronTransaction.ts, packages/swapper/src/types.ts
Extends TradeQuoteStep type with optional method and args fields. Adjusts allowance contract logic in quote building for Tron assets. Adds dedicated Butter Swap path in unsigned transaction builder that dispatches to the new buildCustomApiTx adapter method with validated transaction metadata.

Sequence Diagram(s)

sequenceDiagram
    participant Swapper as ButterSwap Swapper
    participant Quote as getTradeQuote
    participant TxBuilder as getUnsignedTronTransaction
    participant Adapter as TronChainAdapter
    participant API as TronGrid API

    Swapper->>Quote: Request trade quote (Tron)
    Quote->>Quote: Adjust allowanceContract for Tron
    Quote->>Quote: Attach method/args to metadata
    Quote-->>Swapper: Return quote with metadata
    
    Swapper->>TxBuilder: Build unsigned transaction
    TxBuilder->>TxBuilder: Detect butterSwapTransactionMetadata
    TxBuilder->>Adapter: Call buildCustomApiTx(from, to, data, value, method, args)
    Adapter->>API: Send triggersmartcontract request
    API-->>Adapter: Return transaction with raw_data_hex
    Adapter->>Adapter: Extract and normalize raw_data_hex
    Adapter-->>TxBuilder: Return TronSignTx
    TxBuilder-->>Swapper: Return unsigned transaction
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • fix: add throttler to tron chain adapter #11544: Adds request queue wrapping for triggerSmartContract and other TronChainAdapter calls, intersecting with the new buildCustomApiTx TronGrid API integration.
  • feat: enable butter same chain swaps #10202: Modifies ButterSwap quote/build flows to support same-chain Tron swaps and extends metadata handling, directly related to the swapper and metadata changes in this PR.
  • feat: enable butter for TRON #11769: Extends getUnsignedTronTransaction to add ButterSwap-specific Tron transaction paths and dispatches custom API transactions via the adapter, core overlap with this PR's transaction building logic.

Suggested reviewers

  • gomesalexandre
  • premiumjibles

Poem

🐰✨ A rabbit hops through Tron's bright chain,
With custom transactions, no refrain!
Raw data flows and API calls align,
ButterSwap swaps now smoothly shine—
All metadata bundled, logic divine! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: tron butter swaps' clearly identifies the main change: enabling TRON support for Butter swaps by fixing contract call handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tron-swap-fix

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.

@NeOMakinG NeOMakinG marked this pull request as ready for review January 27, 2026 06:51
@NeOMakinG NeOMakinG requested a review from a team as a code owner January 27, 2026 06:51
Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

Confirmed happy on both sides

https://jam.dev/c/1a8b3de5-86ed-4db3-93c8-eb3ece98e80f

Also oh boi dem rates and fees 💀

@gomesalexandre gomesalexandre enabled auto-merge (squash) January 27, 2026 22:37
@gomesalexandre gomesalexandre merged commit 6099303 into develop Jan 27, 2026
4 checks passed
@gomesalexandre gomesalexandre deleted the tron-swap-fix branch January 27, 2026 22:47
gomesalexandre pushed a commit that referenced this pull request Jan 27, 2026
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