Skip to content

Commit efec749

Browse files
committed
feat: add Tron substreams indexing package
- Add substreams configuration for Tron payment indexing - Add protobuf definitions and schema - Add Rust implementation for payment extraction
1 parent 7928566 commit efec749

11 files changed

Lines changed: 558 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "request-network-tron"
3+
version = "0.1.0"
4+
edition = "2021"
5+
repository = "https://github.com/RequestNetwork/requestNetwork"
6+
license = "MIT"
7+
description = "Request Network TRON Substreams module for ERC20FeeProxy payment detection"
8+
9+
[lib]
10+
name = "request_network_tron"
11+
crate-type = ["cdylib"]
12+
13+
[dependencies]
14+
substreams = "0.5"
15+
substreams-tron = "0.1"
16+
prost = "0.11"
17+
prost-types = "0.11"
18+
hex = "0.4"
19+
20+
[build-dependencies]
21+
prost-build = "0.11"
22+
23+
[profile.release]
24+
lto = true
25+
opt-level = 's'
26+
strip = "debuginfo"

packages/substreams-tron/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.PHONY: build
2+
build:
3+
cargo build --target wasm32-unknown-unknown --release
4+
5+
.PHONY: protogen
6+
protogen:
7+
substreams protogen ./substreams.yaml --exclude-paths="sf/substreams,google"
8+
9+
.PHONY: package
10+
package: build
11+
substreams pack ./substreams.yaml
12+
13+
.PHONY: gui
14+
gui: build
15+
substreams gui ./substreams.yaml map_erc20_fee_proxy_payments -e tron.substreams.pinax.network:443
16+
17+
.PHONY: run
18+
run: build
19+
substreams run ./substreams.yaml map_erc20_fee_proxy_payments -e tron.substreams.pinax.network:443 --start-block 63208782 --stop-block +100
20+
21+
.PHONY: clean
22+
clean:
23+
cargo clean
24+
rm -f *.spkg
25+
26+
.PHONY: test
27+
test:
28+
cargo test

packages/substreams-tron/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Request Network TRON Substreams
2+
3+
This package contains a Substreams module for indexing ERC20FeeProxy payment events on the TRON blockchain.
4+
5+
## Overview
6+
7+
The module indexes `TransferWithReferenceAndFee` events from the deployed ERC20FeeProxy contracts:
8+
9+
- **Mainnet**: `TCUDPYnS9dH3WvFEaE7wN7vnDa51J4R4fd`
10+
- **Nile Testnet**: `THK5rNmrvCujhmrXa5DB1dASepwXTr9cJs`
11+
12+
## Prerequisites
13+
14+
1. **Rust toolchain** with `wasm32-unknown-unknown` target:
15+
16+
```bash
17+
rustup target add wasm32-unknown-unknown
18+
```
19+
20+
2. **Substreams CLI**:
21+
22+
```bash
23+
brew install streamingfast/tap/substreams
24+
```
25+
26+
3. **bs58 crate** for Base58 encoding (included in dependencies)
27+
28+
## Building
29+
30+
```bash
31+
# Build the WASM module
32+
make build
33+
34+
# Generate protobuf types
35+
make protogen
36+
37+
# Package for deployment
38+
make package
39+
```
40+
41+
## Running Locally
42+
43+
```bash
44+
# Run with GUI for debugging
45+
make gui
46+
47+
# Run and output to console
48+
make run
49+
```
50+
51+
## Deployment
52+
53+
### Deploy as Substreams-powered Subgraph
54+
55+
1. Build and package the Substreams module:
56+
57+
```bash
58+
make package
59+
```
60+
61+
2. Deploy to The Graph:
62+
```bash
63+
graph deploy --studio request-payments-tron
64+
```
65+
66+
### Subgraph Endpoints
67+
68+
Once deployed, the subgraph will be available at:
69+
70+
- **Mainnet**: `https://api.studio.thegraph.com/query/67444/request-payments-tron/version/latest`
71+
- **Nile Testnet**: `https://api.studio.thegraph.com/query/67444/request-payments-tron-nile/version/latest`
72+
73+
## Module Details
74+
75+
### `map_erc20_fee_proxy_payments`
76+
77+
Extracts payment events from TRON blocks:
78+
79+
**Input**: `sf.tron.type.v1.Block`
80+
81+
**Output**: `request.tron.v1.Payments`
82+
83+
**Fields extracted**:
84+
85+
- `token_address` - TRC20 token contract address
86+
- `to` - Payment recipient
87+
- `amount` - Payment amount
88+
- `payment_reference` - Indexed payment reference (hex)
89+
- `fee_amount` - Fee amount
90+
- `fee_address` - Fee recipient
91+
- `from` - Sender address
92+
- `block` - Block number
93+
- `timestamp` - Block timestamp (Unix seconds)
94+
- `tx_hash` - Transaction hash
95+
- `contract_address` - ERC20FeeProxy contract address
96+
97+
## Testing
98+
99+
```bash
100+
make test
101+
```
102+
103+
## License
104+
105+
MIT

packages/substreams-tron/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Build script for generating protobuf types
2+
3+
fn main() -> Result<(), Box<dyn std::error::Error>> {
4+
prost_build::compile_protos(&["proto/payments.proto"], &["proto/"])?;
5+
Ok(())
6+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@requestnetwork/substreams-tron",
3+
"version": "0.1.0",
4+
"description": "Request Network TRON Substreams module for ERC20FeeProxy payment detection",
5+
"private": true,
6+
"scripts": {
7+
"build": "make build",
8+
"protogen": "make protogen",
9+
"package": "make package",
10+
"gui": "make gui",
11+
"run": "make run",
12+
"clean": "make clean",
13+
"test": "make test"
14+
},
15+
"keywords": [
16+
"request-network",
17+
"tron",
18+
"substreams",
19+
"payment-detection"
20+
],
21+
"author": "Request Network",
22+
"license": "MIT",
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/RequestNetwork/requestNetwork.git",
26+
"directory": "packages/substreams-tron"
27+
}
28+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
syntax = "proto3";
2+
3+
package request.tron.v1;
4+
5+
// A single payment event from the ERC20FeeProxy contract
6+
message Payment {
7+
// The token contract address (TRC20)
8+
string token_address = 1;
9+
10+
// The recipient address
11+
string to = 2;
12+
13+
// The payment amount (as string to preserve precision)
14+
string amount = 3;
15+
16+
// The indexed payment reference (hex encoded)
17+
string payment_reference = 4;
18+
19+
// The fee amount (as string to preserve precision)
20+
string fee_amount = 5;
21+
22+
// The fee recipient address
23+
string fee_address = 6;
24+
25+
// The sender address (msg.sender)
26+
string from = 7;
27+
28+
// Block number where the event was emitted
29+
uint64 block = 8;
30+
31+
// Block timestamp (Unix timestamp in seconds)
32+
uint64 timestamp = 9;
33+
34+
// Transaction hash
35+
string tx_hash = 10;
36+
37+
// The proxy contract address that emitted the event
38+
string contract_address = 11;
39+
}
40+
41+
// Collection of payment events
42+
message Payments {
43+
repeated Payment payments = 1;
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# GraphQL schema for Request Network TRON payments
2+
# This schema is used when deploying a Substreams-powered subgraph
3+
4+
type Payment @entity {
5+
"Unique identifier: txHash-logIndex"
6+
id: ID!
7+
8+
"The TRC20 token contract address"
9+
tokenAddress: String!
10+
11+
"The payment recipient address"
12+
to: String!
13+
14+
"The payment amount"
15+
amount: BigInt!
16+
17+
"The indexed payment reference (keccak256 hash)"
18+
reference: Bytes!
19+
20+
"The fee amount"
21+
feeAmount: BigInt!
22+
23+
"The fee recipient address"
24+
feeAddress: String
25+
26+
"The sender address"
27+
from: String!
28+
29+
"Block number"
30+
block: Int!
31+
32+
"Block timestamp (Unix seconds)"
33+
timestamp: Int!
34+
35+
"Transaction hash"
36+
txHash: String!
37+
38+
"The ERC20FeeProxy contract address"
39+
contractAddress: String!
40+
}

0 commit comments

Comments
 (0)