Skip to content

feat: add TRON substreams for ERC20FeeProxy payment detection #18

feat: add TRON substreams for ERC20FeeProxy payment detection

feat: add TRON substreams for ERC20FeeProxy payment detection #18

Workflow file for this run

name: Tron Substreams Build
on:
pull_request:
branches:
- main
paths:
- 'tron/**'
- '.github/workflows/tron-build.yml'
push:
branches:
- main
paths:
- 'tron/**'
- '.github/workflows/tron-build.yml'
workflow_dispatch:
inputs:
run_integration_tests:
description: 'Run integration tests against live endpoints'
required: false
default: false
type: boolean
publish_package:
description: 'Build and publish package artifact'
required: false
default: false
type: boolean
deploy_subgraph:
description: 'Deploy subgraph to The Graph Studio'
required: false
default: false
type: boolean
jobs:
build-and-test:
name: Build and Test Tron Substreams
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
tron/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('tron/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build WASM module
working-directory: tron
run: make build
- name: Run unit tests
working-directory: tron
run: make test
- name: Verify build artifacts
working-directory: tron
run: |
echo "Checking build artifacts..."
if [ ! -f "target/wasm32-unknown-unknown/release/request_network_tron.wasm" ]; then
echo "ERROR: WASM file not found!"
exit 1
fi
echo "Build artifacts verified successfully"
integration-test-mainnet:
name: Integration Test (Mainnet EVM)
runs-on: ubuntu-latest
needs: build-and-test
# Run on: push to main (merge) or manual trigger
# PRs only run unit tests (no API key needed)
if: |
github.event.inputs.run_integration_tests == 'true' ||
github.event.inputs.publish_package == 'true' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
tron/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('tron/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Substreams CLI
run: |
curl -sSL https://github.com/streamingfast/substreams/releases/latest/download/substreams_linux_x86_64.tar.gz | tar xz
sudo mv substreams /usr/local/bin/
substreams --version
- name: Build WASM module
working-directory: tron
run: make build
- name: Package Substreams
working-directory: tron
run: make package
- name: Verify package created
working-directory: tron
run: |
SPKG_FILE=$(ls -1 *.spkg 2>/dev/null | head -1)
if [ -z "$SPKG_FILE" ]; then
echo "ERROR: No .spkg package file found!"
exit 1
fi
echo "✅ Package created: $SPKG_FILE"
- name: Deploy and test against Mainnet EVM (Streamingfast)
working-directory: tron
env:
SUBSTREAMS_API_TOKEN: ${{ secrets.SUBSTREAMS_API_TOKEN }}
run: |
echo "=== Deploying to TRON Mainnet EVM (Streamingfast) ==="
echo "Endpoint: mainnet-evm.tron.streamingfast.io:443"
echo "Block range: 79216121 to 79216221 (100 blocks from mainnet deployment)"
echo ""
SPKG_FILE=$(ls -1 *.spkg | head -1)
echo "Using package: $SPKG_FILE"
# Run substreams and capture JSON output
if ! substreams run "$SPKG_FILE" map_erc20_fee_proxy_payments \
-e mainnet-evm.tron.streamingfast.io:443 \
--start-block 79216121 \
--stop-block +100 \
-o json 2>&1 | tee output_mainnet.log; then
echo ""
echo "❌ FAILED: Substreams command returned non-zero exit code"
echo "Output:"
cat output_mainnet.log
exit 1
fi
echo ""
echo "=== Validating Results ==="
# If any payments were found, validate the structure
if grep -q '"payments"' output_mainnet.log; then
echo "✅ Payments data structure detected in output"
# Extract and validate payment fields if present
if grep -q '"token_address"' output_mainnet.log; then
echo "✅ Payment fields present: token_address"
fi
if grep -q '"payment_reference"' output_mainnet.log; then
echo "✅ Payment fields present: payment_reference"
fi
if grep -q '"amount"' output_mainnet.log; then
echo "✅ Payment fields present: amount"
fi
else
echo "ℹ️ No payments found in block range (expected if no transactions in these blocks)"
fi
echo ""
echo "=== Mainnet Integration Test PASSED ==="
echo "The substreams module successfully:"
echo " - Loaded WASM module"
echo " - Connected to TRON Mainnet EVM endpoint via Streamingfast"
echo " - Processed 100 blocks without errors"
echo " - Output valid JSON structure"
# Publish package artifact for download/deployment
publish-package:
name: Publish Mainnet Package
runs-on: ubuntu-latest
needs: [build-and-test, integration-test-mainnet]
# Publish on: push to main (merge) or manual publish selection
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event.inputs.publish_package == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
tron/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('tron/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Substreams CLI
run: |
curl -sSL https://github.com/streamingfast/substreams/releases/latest/download/substreams_linux_x86_64.tar.gz | tar xz
sudo mv substreams /usr/local/bin/
- name: Build WASM module
working-directory: tron
run: make build
- name: Package Substreams
working-directory: tron
run: make package
- name: Get package info
id: package_info
working-directory: tron
run: |
SPKG_FILE=$(ls -1 *.spkg 2>/dev/null | head -1)
if [ -z "$SPKG_FILE" ]; then
echo "ERROR: No .spkg package file found!"
exit 1
fi
echo "spkg_file=$SPKG_FILE" >> $GITHUB_OUTPUT
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Package created successfully: $SPKG_FILE (version: $VERSION)"
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: request-network-tron-${{ steps.package_info.outputs.version }}
path: tron/${{ steps.package_info.outputs.spkg_file }}
retention-days: 90
- name: Package ready for deployment
run: |
echo "=============================================="
echo "📦 Substreams Package Ready"
echo "=============================================="
echo ""
echo "Package: ${{ steps.package_info.outputs.spkg_file }}"
echo "Version: ${{ steps.package_info.outputs.version }}"
echo "=============================================="
# Deploy subgraph to The Graph Network
deploy-subgraph:
name: Deploy Subgraph to The Graph
runs-on: ubuntu-latest
needs: [build-and-test, integration-test-mainnet]
# Deploy on: push to main (merge) or manual trigger
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event.inputs.deploy_subgraph == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
tron/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('tron/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Substreams CLI
run: |
curl -sSL https://github.com/streamingfast/substreams/releases/latest/download/substreams_linux_x86_64.tar.gz | tar xz
sudo mv substreams /usr/local/bin/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Graph CLI
run: npm install -g @graphprotocol/graph-cli
- name: Build WASM module
working-directory: tron
run: make build
- name: Package Substreams
working-directory: tron
run: make package
- name: Build Subgraph
working-directory: tron
run: |
echo "Building subgraph..."
graph build
- name: Deploy to Subgraph Studio
working-directory: tron
env:
SUBGRAPH_DEPLOY_KEY: ${{ secrets.SUBGRAPH_DEPLOY_KEY }}
run: |
echo "Deploying subgraph to The Graph Studio..."
# Authenticate with deploy key
graph auth --studio "$SUBGRAPH_DEPLOY_KEY"
# Get version from Cargo.toml
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
# Deploy to studio (use the subgraph slug from Subgraph Studio)
graph deploy --studio request-network-tron-payments \
--version-label "v${VERSION}" \
--skip-validation
echo ""
echo "=============================================="
echo "✅ Subgraph Deployed to The Graph Studio"
echo "=============================================="
echo ""
echo "Version: v${VERSION}"
echo ""
echo "Next steps:"
echo " 1. Visit https://thegraph.com/studio/"
echo " 2. Verify the subgraph is syncing"
echo " 3. When ready, publish to The Graph Network"
echo "=============================================="