Skip to content

Conversation

@rodrigopavezi
Copy link
Member

@rodrigopavezi rodrigopavezi commented Jan 26, 2026

Description of the changes

Added support for Tron blockchain payments in the payment-processor package. This implementation enables TRC20 token payments through the ERC20 Fee Proxy contract on Tron networks.

The changes include:

  • New tron-fee-proxy.ts module with functions for paying requests on Tron:

    • payTronFeeProxyRequest - Process payments with TRC20 tokens
    • approveTronFeeProxyRequest - Approve token spending
    • hasSufficientTronAllowance - Check token allowance
    • hasSufficientTronBalance - Verify token balance
    • getTronPaymentInfo - Get payment details
  • New utils-tron.ts module with Tron-specific utilities:

    • TronWeb type definitions
    • Address validation
    • Contract interaction helpers
    • Token approval and payment processing
  • Comprehensive test coverage for all new functionality

  • Exports for the new modules in the package index


Closes RequestNetwork/private-issues#234

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/tron-payment-processor

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.

Copy link
Member Author

rodrigopavezi commented Jan 26, 2026

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

Added comprehensive Tron blockchain payment support to the payment-processor package, enabling TRC20 token payments through the ERC20 Fee Proxy contract.

Key Changes:

  • Implemented tron-fee-proxy.ts with core payment functions: payTronFeeProxyRequest, approveTronFeeProxyRequest, hasSufficientTronAllowance, hasSufficientTronBalance, and getTronPaymentInfo
  • Created utils-tron.ts with Tron-specific utilities including TronWeb type definitions, address validation (isValidTronAddress), and contract interaction helpers
  • Added comprehensive test coverage in tron-fee-proxy.test.ts with proper mocking and edge case testing
  • Leveraged existing ERC20FeeProxy smart contract artifact structure with Tron-specific deployments (mainnet: TCUDPYnS9dH3WvFEaE7wN7vnDa51J4R4fd, testnet: THK5rNmrvCujhmrXa5DB1dASepwXTr9cJs)
  • Added tronweb@5.3.2 and ethers@6.16.0 dependencies to support Tron integration

Implementation Details:

  • Payment flow follows the same pattern as EVM chains: validate network → check allowance → verify balance → execute payment
  • Uses TronWeb's contract API to interact with TRC20 tokens and the ERC20FeeProxy contract
  • Validates Tron addresses using Base58Check format (34 characters starting with 'T')
  • Properly formats payment references with 0x prefix for contract calls
  • Fee limits set to 100 TRX for approvals and 150 TRX for proxy payments

Confidence Score: 4/5

  • This PR is safe to merge with standard review
  • Implementation follows established patterns from EVM payment processors, includes comprehensive test coverage, and properly validates inputs. Minor points: error handling in utility functions returns default values which could mask network issues, and the test timeout increase suggests potential performance concerns worth monitoring
  • Pay close attention to utils-tron.ts error handling in isTronAccountSolvent and getTronAllowance functions which catch and suppress errors by returning default values

Important Files Changed

Filename Overview
packages/payment-processor/src/payment/tron-fee-proxy.ts adds Tron payment processor functions with proper validation, allowance/balance checks, and payment execution
packages/payment-processor/src/payment/utils-tron.ts implements Tron-specific utilities including TronWeb types, address validation, contract interactions, and payment processing
packages/payment-processor/test/payment/tron-fee-proxy.test.ts comprehensive test coverage for Tron payment processor functions with proper mocking and edge case testing
packages/payment-processor/src/index.ts exports new Tron modules for public API
yarn.lock adds tronweb@5.3.2 and related dependencies (ethers@6.16.0, axios@1.13.2, etc.)

Sequence Diagram

sequenceDiagram
    participant Client
    participant TronFeeProxy as tron-fee-proxy.ts
    participant UtilsTron as utils-tron.ts
    participant TronWeb
    participant TRC20Contract as TRC20 Token
    participant ProxyContract as ERC20FeeProxy

    Note over Client,ProxyContract: Approval Flow
    Client->>TronFeeProxy: approveTronFeeProxyRequest(request, tronWeb)
    TronFeeProxy->>TronFeeProxy: Validate network (TronChains)
    TronFeeProxy->>TronFeeProxy: Calculate total amount (payment + fee)
    TronFeeProxy->>UtilsTron: approveTrc20(tronWeb, tokenAddress, network, amount)
    UtilsTron->>UtilsTron: getERC20FeeProxyAddress(network)
    UtilsTron->>TronWeb: contract(TRC20_ABI, tokenAddress)
    TronWeb-->>UtilsTron: TRC20 contract instance
    UtilsTron->>TRC20Contract: approve(proxyAddress, amount).send()
    TRC20Contract-->>UtilsTron: Transaction result
    UtilsTron->>UtilsTron: callback.onHash(txHash)
    UtilsTron-->>TronFeeProxy: txHash
    TronFeeProxy-->>Client: txHash

    Note over Client,ProxyContract: Payment Flow
    Client->>TronFeeProxy: payTronFeeProxyRequest(request, tronWeb)
    TronFeeProxy->>TronFeeProxy: Validate network (TronChains)
    TronFeeProxy->>TronFeeProxy: validateRequest(ERC20_FEE_PROXY_CONTRACT)
    TronFeeProxy->>TronFeeProxy: getRequestPaymentValues()
    TronFeeProxy->>TronFeeProxy: validatePaymentReference()
    TronFeeProxy->>UtilsTron: isValidTronAddress(paymentAddress)
    UtilsTron-->>TronFeeProxy: validation result
    
    TronFeeProxy->>UtilsTron: getTronAllowance(tronWeb, tokenAddress, network)
    UtilsTron->>TronWeb: contract(TRC20_ABI, tokenAddress)
    TronWeb-->>UtilsTron: contract instance
    UtilsTron->>TRC20Contract: allowance(owner, spender).call()
    TRC20Contract-->>UtilsTron: allowance amount
    UtilsTron-->>TronFeeProxy: BigNumber allowance
    
    alt Insufficient Allowance
        TronFeeProxy-->>Client: Error: Insufficient TRC20 allowance
    end
    
    TronFeeProxy->>UtilsTron: isTronAccountSolvent(tronWeb, tokenAddress, amount)
    UtilsTron->>TronWeb: contract(TRC20_ABI, tokenAddress)
    TronWeb-->>UtilsTron: contract instance
    UtilsTron->>TRC20Contract: balanceOf(owner).call()
    TRC20Contract-->>UtilsTron: balance
    UtilsTron-->>TronFeeProxy: true/false
    
    alt Insufficient Balance
        TronFeeProxy-->>Client: Error: Insufficient TRC20 token balance
    end
    
    TronFeeProxy->>UtilsTron: processTronFeeProxyPayment(params)
    UtilsTron->>UtilsTron: Validate all addresses
    UtilsTron->>UtilsTron: getERC20FeeProxyAddress(network)
    UtilsTron->>TronWeb: contract(ERC20_FEE_PROXY_ABI, proxyAddress)
    TronWeb-->>UtilsTron: proxy contract instance
    UtilsTron->>UtilsTron: Format payment reference (add 0x prefix)
    UtilsTron->>ProxyContract: transferFromWithReferenceAndFee(token, to, amount, ref, feeAmount, feeAddress).send()
    ProxyContract->>TRC20Contract: transferFrom(payer, recipient, amount)
    TRC20Contract-->>ProxyContract: success
    alt Fee > 0
        ProxyContract->>TRC20Contract: transferFrom(payer, feeRecipient, feeAmount)
        TRC20Contract-->>ProxyContract: success
    end
    ProxyContract-->>UtilsTron: Transaction result
    UtilsTron->>UtilsTron: callback.onHash(txHash)
    UtilsTron-->>TronFeeProxy: txHash
    TronFeeProxy-->>Client: txHash
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 853297e to 5bb6ef7 Compare January 27, 2026 01:49
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch 2 times, most recently from 5ac332a to 984a642 Compare January 27, 2026 01:53
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch 2 times, most recently from 3c7d77f to 816af51 Compare January 27, 2026 01:56
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 984a642 to 41e33e8 Compare January 27, 2026 01:56
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 816af51 to fc1128c Compare January 27, 2026 01:58
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 41e33e8 to d03f1db Compare January 27, 2026 01:58
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from fc1128c to cf070e9 Compare January 27, 2026 02:02
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from d03f1db to 7d73139 Compare January 27, 2026 02:02
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from cf070e9 to 62f2685 Compare January 27, 2026 02:15
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch 2 times, most recently from 6dce563 to dbed330 Compare January 27, 2026 02:25
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch 2 times, most recently from 3bf2428 to f06892c Compare January 27, 2026 02:34
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch 2 times, most recently from 1797a69 to d5e25df Compare January 27, 2026 02:39
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from f06892c to 8456f0a Compare January 27, 2026 02:39
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch 2 times, most recently from b5ce760 to 60d3c03 Compare January 27, 2026 02:50
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from f8bb525 to ceec59f Compare January 28, 2026 14:50
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 2319127 to cecfc7e Compare January 28, 2026 14:50
MantisClone

This comment was marked as duplicate.

Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

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

Looks good to me so far.

Reviewed with Claude Code Opus 4.5

@MantisClone MantisClone self-requested a review February 10, 2026 15:10
Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

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

LGTM — well-typed TronWeb interface, good validation (address format, balance, allowance). One minor non-blocking comment about fee limits (see inline).

@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from cecfc7e to 6c8cb20 Compare February 11, 2026 13:29
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from ceec59f to 10ddce5 Compare February 11, 2026 13:29
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 6c8cb20 to 938afca Compare February 11, 2026 13:37
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 10ddce5 to 362dbbc Compare February 11, 2026 13:37
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 938afca to c8c4b67 Compare February 11, 2026 14:39
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 5ec56fe to b8f3840 Compare February 11, 2026 14:39
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from b8f3840 to 55c4451 Compare February 11, 2026 14:48
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch 2 times, most recently from 1408a38 to 559e872 Compare February 11, 2026 14:53
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 55c4451 to 2d1ffbc Compare February 11, 2026 14:53
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 559e872 to 96f878e Compare February 11, 2026 16:40
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 7f462e4 to 91553a4 Compare February 11, 2026 16:40
- Add tron-fee-proxy payment functions
- Add Tron utility functions for transaction handling
- Add unit tests for Tron payment processing
- Update request-client tests for Tron support
Add a retry loop to wait for the Graph node to be ready on port 8020
before attempting to create and deploy the subgraph.
- Introduce DEFAULT_TRON_APPROVAL_FEE_LIMIT and DEFAULT_TRON_PAYMENT_FEE_LIMIT constants for TRC20 transactions.
- Update approveTrc20 and processTronFeeProxyPayment functions to use dynamic fee limits instead of hardcoded values.
- Update ERC20FeeProxyPaymentDetector to support TronChainName by adding TronInfoRetriever.
- Enhance the getTheGraphInfoRetriever method to handle Tron payment chains.
- Change import statement for TronInfoRetriever to reflect new file structure in the tron directory.
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 91553a4 to 8315931 Compare February 11, 2026 16:42
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 96f878e to 35cc88d Compare February 11, 2026 16:42
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.

3 participants