-
Notifications
You must be signed in to change notification settings - Fork 92
add tron support for smart contracts and payment processor #1684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rodrigopavezi
wants to merge
1
commit into
master
Choose a base branch
from
01-21-add_tron_support_for_smart_contracts_and_payment_processor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why this is in a folder named "declarative". Shouldn't be in a "TronChains" directory ?