Skip to content

Commit 1946425

Browse files
committed
add tron support for smart contracts and payment processor
1 parent 0324fff commit 1946425

40 files changed

Lines changed: 57065 additions & 6 deletions
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Tron Smart Contracts Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- 'packages/smart-contracts/tron/**'
9+
- 'packages/smart-contracts/tronbox-config.js'
10+
- '.github/workflows/tron-smart-contracts.yml'
11+
push:
12+
branches:
13+
- master
14+
paths:
15+
- 'packages/smart-contracts/tron/**'
16+
- 'packages/smart-contracts/tronbox-config.js'
17+
workflow_dispatch:
18+
19+
jobs:
20+
tron-tests:
21+
name: Tron Contract Tests
22+
runs-on: ubuntu-latest
23+
24+
services:
25+
tron:
26+
image: tronbox/tre
27+
ports:
28+
- 9090:9090
29+
options: >-
30+
--health-cmd "curl -f http://localhost:9090 || exit 1"
31+
--health-interval 10s
32+
--health-timeout 5s
33+
--health-retries 10
34+
--health-start-period 30s
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: '22'
44+
cache: 'yarn'
45+
46+
- name: Install TronBox globally
47+
run: npm install -g tronbox
48+
49+
- name: Install dependencies
50+
run: yarn install --frozen-lockfile
51+
52+
- name: Wait for Tron node to be ready
53+
run: |
54+
echo "Waiting for Tron node..."
55+
for i in {1..30}; do
56+
if curl -s http://localhost:9090 > /dev/null 2>&1; then
57+
echo "Tron node is ready!"
58+
break
59+
fi
60+
echo "Attempt $i/30 - Tron node not ready yet..."
61+
sleep 5
62+
done
63+
64+
- name: Compile Tron contracts
65+
working-directory: packages/smart-contracts
66+
run: yarn tron:compile
67+
68+
- name: Run Tron tests
69+
working-directory: packages/smart-contracts
70+
run: yarn tron:test
71+
env:
72+
CI: true
73+
74+
- name: Upload test artifacts
75+
if: failure()
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: tron-test-logs
79+
path: |
80+
packages/smart-contracts/tron-build/
81+
retention-days: 7
82+
83+
tron-compile-check:
84+
name: Tron Contract Compilation Check
85+
runs-on: ubuntu-latest
86+
87+
steps:
88+
- name: Checkout repository
89+
uses: actions/checkout@v4
90+
91+
- name: Setup Node.js
92+
uses: actions/setup-node@v4
93+
with:
94+
node-version: '22'
95+
cache: 'yarn'
96+
97+
- name: Install TronBox globally
98+
run: npm install -g tronbox
99+
100+
- name: Install dependencies
101+
run: yarn install --frozen-lockfile
102+
103+
- name: Compile Tron contracts
104+
working-directory: packages/smart-contracts
105+
run: yarn tron:compile
106+
107+
- name: Verify build artifacts exist
108+
working-directory: packages/smart-contracts
109+
run: |
110+
echo "Checking build artifacts..."
111+
ls -la tron-build/
112+
113+
# Verify key contracts were compiled
114+
if [ ! -f "tron-build/ERC20FeeProxy.json" ]; then
115+
echo "ERROR: ERC20FeeProxy.json not found!"
116+
exit 1
117+
fi
118+
119+
if [ ! -f "tron-build/TestTRC20.json" ]; then
120+
echo "ERROR: TestTRC20.json not found!"
121+
exit 1
122+
fi
123+
124+
echo "✅ All required artifacts present"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const chainId = 'nile';
2+
3+
// Nile is Tron's test network
4+
export const testnet = true;
5+
6+
// Test tokens on Nile testnet
7+
// Note: These are testnet token addresses, not mainnet
8+
export const currencies = {
9+
// Add testnet token addresses as needed
10+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11
export const chainId = 'tron';
2+
3+
// Tron mainnet configuration
4+
export const testnet = false;
5+
6+
// Common TRC20 tokens on Tron
7+
export const currencies = {
8+
// USDT-TRC20 - the most widely used stablecoin on Tron
9+
TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t: {
10+
name: 'Tether USD',
11+
symbol: 'USDT',
12+
decimals: 6,
13+
},
14+
// USDC on Tron
15+
TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8: {
16+
name: 'USD Coin',
17+
symbol: 'USDC',
18+
decimals: 6,
19+
},
20+
};

packages/currency/src/chains/declarative/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CurrencyTypes } from '@requestnetwork/types';
22

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

1213
export const chains: Record<CurrencyTypes.DeclarativeChainName, DeclarativeChain> = {
1314
tron: TronDefinition,
15+
nile: NileDefinition,
1416
solana: SolanaDefinition,
1517
starknet: StarknetDefinition,
1618
ton: TonDefinition,
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import BtcChains from './btc/BtcChains';
22
import EvmChains from './evm/EvmChains';
33
import NearChains from './near/NearChains';
4+
import TronChains from './tron/TronChains';
45
import DeclarativeChains from './declarative/DeclarativeChains';
56
import { isSameChain } from './utils';
67

7-
export { BtcChains, EvmChains, NearChains, DeclarativeChains, isSameChain };
8+
export { BtcChains, EvmChains, NearChains, TronChains, DeclarativeChains, isSameChain };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ChainsAbstract } from '../ChainsAbstract';
2+
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
3+
import { TronChain, chains } from './index';
4+
5+
class TronChains extends ChainsAbstract<CurrencyTypes.TronChainName, TronChain, string> {}
6+
export default new TronChains(chains, RequestLogicTypes.CURRENCY.ETH);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { CurrencyTypes } from '@requestnetwork/types';
2+
3+
import * as TronDefinition from '../declarative/data/tron';
4+
import * as NileDefinition from '../declarative/data/nile';
5+
6+
export type TronChain = CurrencyTypes.Chain;
7+
8+
export const chains: Record<CurrencyTypes.TronChainName, TronChain> = {
9+
tron: TronDefinition,
10+
nile: NileDefinition,
11+
};

packages/payment-processor/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export * from './payment/encoder-approval';
2828
export * as Escrow from './payment/erc20-escrow-payment';
2929
export * from './payment/prepared-transaction';
3030
export * from './payment/utils-near';
31+
export * from './payment/utils-tron';
32+
export * from './payment/tron-fee-proxy';
3133
export * from './payment/single-request-forwarder';
3234
export * from './payment/erc20-recurring-payment-proxy';
3335
export * from './payment/erc20-commerce-escrow-wrapper';

0 commit comments

Comments
 (0)