Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions .github/workflows/tron-smart-contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
name: Tron Smart Contracts Tests

on:
pull_request:
branches:
- master
paths:
- 'packages/smart-contracts/tron/**'
- 'packages/smart-contracts/tronbox-config.js'
- 'packages/smart-contracts/src/lib/artifacts/ERC20FeeProxy/**'
- 'packages/payment-processor/src/payment/*tron*'
- 'packages/payment-processor/test/payment/*tron*'
- 'packages/currency/src/chains/tron/**'
- '.github/workflows/tron-smart-contracts.yml'
push:
branches:
- master
paths:
- 'packages/smart-contracts/tron/**'
- 'packages/smart-contracts/tronbox-config.js'
- 'packages/smart-contracts/src/lib/artifacts/ERC20FeeProxy/**'
- 'packages/payment-processor/src/payment/*tron*'
- 'packages/payment-processor/test/payment/*tron*'
- 'packages/currency/src/chains/tron/**'
workflow_dispatch:

jobs:
tron-compile-check:
name: Tron Contract Compilation Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'yarn'

- name: Install TronBox globally
run: npm install -g tronbox

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Compile Tron contracts
working-directory: packages/smart-contracts
run: yarn tron:compile

- name: Verify build artifacts exist
working-directory: packages/smart-contracts
run: |
echo "Checking build artifacts..."
ls -la tron-build/

# Verify key contracts were compiled
for contract in ERC20FeeProxy TestTRC20 BadTRC20 TRC20True TRC20NoReturn TRC20False TRC20Revert; do
if [ ! -f "tron-build/${contract}.json" ]; then
echo "ERROR: ${contract}.json not found!"
exit 1
fi
echo "✓ ${contract}.json exists"
done

echo "✅ All required artifacts present"

- name: Verify contract ABI structure
working-directory: packages/smart-contracts
run: |
echo "Verifying ERC20FeeProxy ABI..."

# Check that the compiled contract has the expected functions
for func in transferFromWithReferenceAndFee; do
if ! grep -q "$func" tron-build/ERC20FeeProxy.json; then
echo "ERROR: ERC20FeeProxy missing $func function!"
exit 1
fi
echo "✓ ERC20FeeProxy has $func"
done

# Verify TestTRC20 has standard ERC20 functions
for func in transfer approve transferFrom balanceOf allowance; do
if ! grep -q "$func" tron-build/TestTRC20.json; then
echo "ERROR: TestTRC20 missing $func function!"
exit 1
fi
echo "✓ TestTRC20 has $func"
done

echo "✅ Contract ABI structure verified"

- name: Verify deployment files are valid JSON
working-directory: packages/smart-contracts
run: |
echo "Validating deployment files..."

for network in nile mainnet; do
file="tron/deployments/${network}.json"
if [ -f "$file" ]; then
if ! python3 -m json.tool "$file" > /dev/null 2>&1; then
echo "ERROR: $file is not valid JSON!"
exit 1
fi

# Verify required fields
if ! grep -q '"ERC20FeeProxy"' "$file"; then
echo "ERROR: $file missing ERC20FeeProxy entry!"
exit 1
fi

if ! grep -q '"address"' "$file"; then
echo "ERROR: $file missing address field!"
exit 1
fi

echo "✓ $file is valid"
fi
done

echo "✅ Deployment files validated"

tron-payment-processor-tests:
name: Tron Payment Processor Unit Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build dependencies
run: |
yarn workspace @requestnetwork/types build
yarn workspace @requestnetwork/utils build
yarn workspace @requestnetwork/currency build
yarn workspace @requestnetwork/smart-contracts build
yarn workspace @requestnetwork/payment-detection build

- name: Run Tron payment processor tests
working-directory: packages/payment-processor
run: yarn test -- --testPathPattern="tron" --passWithNoTests

tron-artifact-registry-check:
name: Tron Artifact Registry Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build smart-contracts package
run: |
yarn workspace @requestnetwork/types build
yarn workspace @requestnetwork/utils build
yarn workspace @requestnetwork/currency build
yarn workspace @requestnetwork/smart-contracts build

- name: Verify Tron addresses in artifact registry
run: |
echo "Checking Tron addresses in artifact registry..."

# Check that nile address is registered
if ! grep -q "THK5rNmrvCujhmrXa5DB1dASepwXTr9cJs" packages/smart-contracts/src/lib/artifacts/ERC20FeeProxy/index.ts; then
echo "ERROR: Nile testnet address not found in artifact registry!"
exit 1
fi
echo "✓ Nile address registered"

# Check that mainnet address is registered
if ! grep -q "TCUDPYnS9dH3WvFEaE7wN7vnDa51J4R4fd" packages/smart-contracts/src/lib/artifacts/ERC20FeeProxy/index.ts; then
echo "ERROR: Mainnet address not found in artifact registry!"
exit 1
fi
echo "✓ Mainnet address registered"

echo "✅ Tron addresses verified in artifact registry"

# Note: Full integration tests require a Tron node and are skipped in CI.
# Run integration tests locally with:
# docker run -d --name tron-tre -p 9090:9090 tronbox/tre # On ARM64 machine
# yarn tron:test
# Or run against Nile testnet:
# TRON_PRIVATE_KEY=your_key yarn tron:test:nile
10 changes: 10 additions & 0 deletions packages/currency/src/chains/declarative/data/nile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const chainId = 'nile';

// Nile is Tron's test network
export const testnet = true;

// Test tokens on Nile testnet
// Note: These are testnet token addresses, not mainnet
export const currencies = {
// Add testnet token addresses as needed
};
19 changes: 19 additions & 0 deletions packages/currency/src/chains/declarative/data/tron.ts
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
export const chainId = 'tron';

// Tron mainnet configuration
export const testnet = false;

// Common TRC20 tokens on Tron
export const currencies = {
// USDT-TRC20 - the most widely used stablecoin on Tron
TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t: {
name: 'Tether USD',
symbol: 'USDT',
decimals: 6,
},
// USDC on Tron
TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8: {
name: 'USD Coin',
symbol: 'USDC',
decimals: 6,
},
};
2 changes: 2 additions & 0 deletions packages/currency/src/chains/declarative/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CurrencyTypes } from '@requestnetwork/types';

import * as TronDefinition from './data/tron';
import * as NileDefinition from './data/nile';
import * as SolanaDefinition from './data/solana';
import * as StarknetDefinition from './data/starknet';
import * as TonDefinition from './data/ton';
Expand All @@ -11,6 +12,7 @@ export type DeclarativeChain = CurrencyTypes.Chain;

export const chains: Record<CurrencyTypes.DeclarativeChainName, DeclarativeChain> = {
tron: TronDefinition,
nile: NileDefinition,
solana: SolanaDefinition,
starknet: StarknetDefinition,
ton: TonDefinition,
Expand Down
3 changes: 2 additions & 1 deletion packages/currency/src/chains/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import BtcChains from './btc/BtcChains';
import EvmChains from './evm/EvmChains';
import NearChains from './near/NearChains';
import TronChains from './tron/TronChains';
import DeclarativeChains from './declarative/DeclarativeChains';
import { isSameChain } from './utils';

export { BtcChains, EvmChains, NearChains, DeclarativeChains, isSameChain };
export { BtcChains, EvmChains, NearChains, TronChains, DeclarativeChains, isSameChain };
6 changes: 6 additions & 0 deletions packages/currency/src/chains/tron/TronChains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ChainsAbstract } from '../ChainsAbstract';
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
import { TronChain, chains } from './index';

class TronChains extends ChainsAbstract<CurrencyTypes.TronChainName, TronChain, string> {}
export default new TronChains(chains, RequestLogicTypes.CURRENCY.ETH);
11 changes: 11 additions & 0 deletions packages/currency/src/chains/tron/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CurrencyTypes } from '@requestnetwork/types';

import * as TronDefinition from '../declarative/data/tron';
import * as NileDefinition from '../declarative/data/nile';

export type TronChain = CurrencyTypes.Chain;

export const chains: Record<CurrencyTypes.TronChainName, TronChain> = {
tron: TronDefinition,
nile: NileDefinition,
};
11 changes: 11 additions & 0 deletions packages/payment-detection/codegen-tron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
overwrite: true
# Using local schema until the subgraph is deployed to The Graph Studio
schema: '../substreams-tron/schema.graphql'
documents: src/thegraph/queries/tron/*.graphql
generates:
src/thegraph/generated/graphql-tron.ts:
plugins:
- 'typescript'
- 'typescript-operations'
- 'typescript-graphql-request'
- 'typescript-document-nodes'
2 changes: 1 addition & 1 deletion packages/payment-detection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"prepare": "yarn run build",
"test": "jest --runInBand",
"test:watch": "yarn test --watch",
"codegen": "graphql-codegen --config codegen.yml ; graphql-codegen --config codegen-superfluid.yml; graphql-codegen --config codegen-near.yml"
"codegen": "graphql-codegen --config codegen.yml ; graphql-codegen --config codegen-superfluid.yml; graphql-codegen --config codegen-near.yml; graphql-codegen --config codegen-tron.yml"
},
"dependencies": {
"@requestnetwork/currency": "0.30.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/payment-detection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getTheGraphClientUrl,
getTheGraphEvmClient,
getTheGraphNearClient,
getTheGraphTronClient,
} from './thegraph';
import {
calculateEscrowState,
Expand All @@ -30,6 +31,7 @@ import {
unpadAmountFromChainlink,
} from './utils';
import { NearConversionNativeTokenPaymentDetector, NearNativeTokenPaymentDetector } from './near';
import { TronERC20FeeProxyPaymentDetector, TronInfoRetriever } from './tron';
import { FeeReferenceBasedDetector } from './fee-reference-based-detector';
import { SuperFluidPaymentDetector } from './erc777/superfluid-detector';
import { EscrowERC20InfoRetriever } from './erc20/escrow-info-retriever';
Expand All @@ -55,6 +57,8 @@ export {
SuperFluidPaymentDetector,
NearNativeTokenPaymentDetector,
NearConversionNativeTokenPaymentDetector,
TronERC20FeeProxyPaymentDetector,
TronInfoRetriever,
EscrowERC20InfoRetriever,
SuperFluidInfoRetriever,
MetaDetector,
Expand All @@ -65,6 +69,7 @@ export {
getTheGraphClientUrl,
getTheGraphEvmClient,
getTheGraphNearClient,
getTheGraphTronClient,
parseLogArgs,
padAmountForChainlink,
unpadAmountFromChainlink,
Expand Down
8 changes: 8 additions & 0 deletions packages/payment-detection/src/payment-network-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { SuperFluidPaymentDetector } from './erc777/superfluid-detector';
import { EthFeeProxyPaymentDetector, EthInputDataPaymentDetector } from './eth';
import { AnyToERC20PaymentDetector, AnyToEthFeeProxyPaymentDetector } from './any';
import { NearConversionNativeTokenPaymentDetector, NearNativeTokenPaymentDetector } from './near';
import { TronERC20FeeProxyPaymentDetector } from './tron';
import { getPaymentNetworkExtension } from './utils';
import { getTheGraphClient } from './thegraph';
import { getDefaultProvider } from 'ethers';
Expand Down Expand Up @@ -55,6 +56,13 @@ const supportedPaymentNetwork: ISupportedPaymentNetworkByCurrency = {
'near-testnet': {
[PN_ID.ERC20_FEE_PROXY_CONTRACT]: ERC20FeeProxyPaymentDetector<CurrencyTypes.NearChainName>,
},
// TRON chains
tron: {
[PN_ID.ERC20_FEE_PROXY_CONTRACT]: TronERC20FeeProxyPaymentDetector,
},
nile: {
[PN_ID.ERC20_FEE_PROXY_CONTRACT]: TronERC20FeeProxyPaymentDetector,
},

'*': {
[PN_ID.ERC20_ADDRESS_BASED]: ERC20AddressBasedPaymentDetector,
Expand Down
Loading
Loading