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.

  • 🔍 Trigger a full review

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

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@rodrigopavezi rodrigopavezi self-assigned this Jan 26, 2026
@rodrigopavezi rodrigopavezi marked this pull request as ready for review January 26, 2026 14:55
@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-detection branch 2 times, most recently from 720a911 to 9c63452 Compare January 27, 2026 08:43
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 60d3c03 to d0a6207 Compare January 27, 2026 08:43
@rodrigopavezi rodrigopavezi changed the base branch from feat/tron-payment-detection to graphite-base/1690 January 27, 2026 09:00
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from d0a6207 to 13b2632 Compare January 27, 2026 09:01
@rodrigopavezi rodrigopavezi changed the base branch from graphite-base/1690 to feat/tron-payment-detection January 27, 2026 09:01
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from 13b2632 to c5a8b72 Compare January 27, 2026 09:04
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 4770f6a to f39a087 Compare January 27, 2026 09:04
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch from c5a8b72 to 96fe3e0 Compare January 27, 2026 09:10
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-detection branch from 6631746 to e0785a2 Compare January 27, 2026 09:16
@rodrigopavezi rodrigopavezi force-pushed the feat/tron-payment-processor branch 2 times, most recently from 19beedb to f8bb525 Compare January 27, 2026 09:29
- 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.
@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

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