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
10 changes: 10 additions & 0 deletions packages/payment-detection/codegen-tron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
overwrite: true
schema: 'src/thegraph/queries/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: 4 additions & 1 deletion packages/payment-detection/src/erc20/fee-proxy-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ export class ERC20FeeProxyPaymentDetector<

protected getTheGraphInfoRetriever(
paymentChain: TChain,
subgraphClient: TheGraphClient | TheGraphClient<CurrencyTypes.NearChainName>,
subgraphClient:
| TheGraphClient
| TheGraphClient<CurrencyTypes.NearChainName>
| TheGraphClient<CurrencyTypes.TronChainName>,
): TheGraphInfoRetriever | NearInfoRetriever {
const graphInfoRetriever = EvmChains.isChainSupported(paymentChain)
? new TheGraphInfoRetriever(subgraphClient as TheGraphClient, this.currencyManager)
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
30 changes: 28 additions & 2 deletions packages/payment-detection/src/thegraph/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { CurrencyTypes } from '@requestnetwork/types';
import { NearChains } from '@requestnetwork/currency';
import { NearChains, TronChains } from '@requestnetwork/currency';
import { GraphQLClient } from 'graphql-request';
import { Block_Height, getSdk, Maybe } from './generated/graphql';
import { getSdk as getNearSdk } from './generated/graphql-near';
import { getSdk as getTronSdk } from './generated/graphql-tron';

const THE_GRAPH_STUDIO_URL =
'https://api.studio.thegraph.com/query/67444/request-payments-$NETWORK/version/latest';
Expand All @@ -20,6 +21,13 @@ const THE_GRAPH_URL_MANTLE =
const THE_GRAPH_URL_CORE =
'https://thegraph.coredao.org/subgraphs/name/requestnetwork/request-payments-core';

// TRON Substreams-powered subgraph URLs
const THE_GRAPH_URL_TRON =
'https://api.studio.thegraph.com/query/67444/request-payments-tron/version/latest';

const THE_GRAPH_URL_TRON_NILE =
'https://api.studio.thegraph.com/query/67444/request-payments-tron-nile/version/latest';

const THE_GRAPH_EXPLORER_SUBGRAPH_ID: Partial<Record<CurrencyTypes.ChainName, string>> = {
['arbitrum-one']: '3MtDdHbzvBVNBpzUTYXGuDDLgTd1b8bPYwoH1Hdssgp9',
avalanche: 'A27V4PeZdKHeyuBkehdBJN8cxNtzVpXvYoqkjHUHRCFp',
Expand Down Expand Up @@ -47,11 +55,13 @@ const THE_GRAPH_EXPLORER_SUBGRAPH_ID: Partial<Record<CurrencyTypes.ChainName, st
/**
* A GraphQL client to query Request's subgraph.
*
* @type TGraphClientVariant: null if no variant, 'near' if native token payments detection on Near
* @type TGraphClientVariant: null if no variant, 'near' if native token payments detection on Near, 'tron' for TRON
*/
export type TheGraphClient<TChain extends CurrencyTypes.VMChainName = CurrencyTypes.EvmChainName> =
(TChain extends CurrencyTypes.NearChainName
? ReturnType<typeof getNearSdk>
: TChain extends CurrencyTypes.TronChainName
? ReturnType<typeof getTronSdk>
: ReturnType<typeof getSdk>) & {
options?: TheGraphQueryOptions;
};
Expand Down Expand Up @@ -104,6 +114,9 @@ export const getTheGraphClient = (
) => {
const url = getTheGraphClientUrl(network, options);
if (!url) return;
if (TronChains.isChainSupported(network)) {
return getTheGraphTronClient(url, options);
}
return NearChains.isChainSupported(network)
? getTheGraphNearClient(url, options)
: getTheGraphEvmClient(url, options);
Expand All @@ -127,6 +140,15 @@ export const getTheGraphNearClient = (url: string, options?: TheGraphClientOptio
return sdk;
};

export const getTheGraphTronClient = (url: string, options?: TheGraphClientOptions) => {
const [clientOptions, queryOptions] = extractClientOptions(url, options);
const sdk: TheGraphClient<CurrencyTypes.TronChainName> = getTronSdk(
new GraphQLClient(url, clientOptions),
);
sdk.options = queryOptions;
return sdk;
};

export const getTheGraphClientUrl = (
network: CurrencyTypes.ChainName,
options?: TheGraphClientOptions,
Expand Down Expand Up @@ -155,6 +177,10 @@ export const getTheGraphClientUrl = (
return THE_GRAPH_URL_MANTLE_TESTNET;
case chain === 'core':
return THE_GRAPH_URL_CORE;
case chain === 'tron':
return THE_GRAPH_URL_TRON;
case chain === 'nile':
return THE_GRAPH_URL_TRON_NILE;
default:
return shouldUseTheGraphExplorer ? theGraphExplorerUrl : theGraphStudioUrl;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Getting TRC20 payments from the ERC20FeeProxy contract on TRON
query GetTronPayments(
$reference: Bytes!
$to: String!
$tokenAddress: String!
$contractAddress: String!
) {
payments(
where: {
reference: $reference
to: $to
tokenAddress: $tokenAddress
contractAddress: $contractAddress
}
orderBy: timestamp
orderDirection: asc
) {
amount
block
txHash
feeAmount
feeAddress
from
timestamp
tokenAddress
}
}

# Getting TRC20 payments without token address filter (for any token)
query GetTronPaymentsAnyToken($reference: Bytes!, $to: String!, $contractAddress: String!) {
payments(
where: { reference: $reference, to: $to, contractAddress: $contractAddress }
orderBy: timestamp
orderDirection: asc
) {
amount
block
txHash
feeAmount
feeAddress
from
timestamp
tokenAddress
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Using local schema until the subgraph is deployed to The Graph Studio
schema: ../../../../../substreams-tron/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# GraphQL schema for Request Network TRON payments
# This schema is used for generating TypeScript types for The Graph queries

type Query {
payments(
where: Payment_filter
orderBy: Payment_orderBy
orderDirection: OrderDirection
): [Payment!]!
}

enum OrderDirection {
asc
desc
}

enum Payment_orderBy {
timestamp
block
amount
}

input Payment_filter {
reference: Bytes
to: String
tokenAddress: String
contractAddress: String
}

type Payment {
"Unique identifier: txHash-logIndex"
id: ID!

"The TRC20 token contract address"
tokenAddress: String!

"The payment recipient address"
to: String!

"The payment amount"
amount: BigInt!

"The indexed payment reference (keccak256 hash)"
reference: Bytes!

"The fee amount"
feeAmount: BigInt!

"The fee recipient address"
feeAddress: String

"The sender address"
from: String!

"Block number"
block: Int!

"Block timestamp (Unix seconds)"
timestamp: Int!

"Transaction hash"
txHash: String!

"The ERC20FeeProxy contract address"
contractAddress: String!
}

scalar BigInt
scalar Bytes
3 changes: 3 additions & 0 deletions packages/payment-detection/src/tron/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { TronERC20FeeProxyPaymentDetector } from './tron-fee-proxy-detector';
export { TronInfoRetriever } from './tron-info-retriever';
export type { TronPaymentEvent } from './tron-info-retriever';
Loading