Skip to content

Commit 77e2575

Browse files
committed
*: Merge Epoch, Network and Tap subgraph client classes
- For user, this change effectively adds support for local querying on epoch and tap subgraphs (previously only supported on network subgraph). - For contributors, this simplifies the codebase to have 1 SubgraphClient class instead of 3 separate implementations: EpochSubgraph, NetworkSubgraph and TapSubgraph.
1 parent 064eb5d commit 77e2575

File tree

17 files changed

+103
-225
lines changed

17 files changed

+103
-225
lines changed

packages/indexer-agent/src/syncing-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { Logger } from '@graphprotocol/common-ts'
77
import { parse } from 'graphql'
88
import {
99
NetworkMapped,
10-
NetworkSubgraph,
10+
SubgraphClient,
1111
resolveChainId,
1212
} from '@graphprotocol/indexer-common'
1313

1414
export interface CreateSyncingServerOptions {
1515
logger: Logger
16-
networkSubgraphs: NetworkMapped<NetworkSubgraph>
16+
networkSubgraphs: NetworkMapped<SubgraphClient>
1717
port: number
1818
}
1919

packages/indexer-common/src/__tests__/subgraph.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ProviderInterface,
66
SubgraphQueryInterface,
77
} from '../subgraphs'
8-
import { QueryResult } from '../network-subgraph'
8+
import { QueryResult } from '../subgraph-client'
99
import gql from 'graphql-tag'
1010
import { mergeSelectionSets } from '../utils'
1111

packages/indexer-common/src/allocations/__tests__/tap-pagination.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Address, Eventual, createLogger, createMetrics } from '@graphprotocol/c
22
import {
33
Allocation,
44
AllocationsResponse,
5-
NetworkSubgraph,
5+
SubgraphClient,
66
QueryFeeModels,
77
QueryResult,
88
TapCollector,
@@ -11,7 +11,6 @@ import {
1111
TransactionManager,
1212
} from '@graphprotocol/indexer-common'
1313
import { NetworkContracts as TapContracts } from '@semiotic-labs/tap-contracts-bindings'
14-
import { TAPSubgraph } from '../../tap-subgraph'
1514
import { NetworkSpecification } from 'indexer-common/src/network-specification'
1615
import { createMockAllocation } from '../../indexer-management/__tests__/helpers.test'
1716
import { getContractAddress } from 'ethers/lib/utils'
@@ -155,10 +154,10 @@ const setup = () => {
155154

156155
const tapSubgraph = {
157156
query: mockQueryTapSubgraph,
158-
} as unknown as TAPSubgraph
157+
} as unknown as SubgraphClient
159158
const networkSubgraph = {
160159
query: mockQueryNetworkSubgraph,
161-
} as unknown as NetworkSubgraph
160+
} as unknown as SubgraphClient
162161

163162
tapCollector = TapCollector.create({
164163
logger,

packages/indexer-common/src/allocations/escrow-accounts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Address, toAddress } from '@graphprotocol/common-ts'
2-
import { TAPSubgraph } from '../tap-subgraph'
2+
import { SubgraphClient } from '../subgraph-client'
33
import gql from 'graphql-tag'
44

55
type U256 = bigint
@@ -44,7 +44,7 @@ export class EscrowAccounts {
4444
}
4545

4646
export const getEscrowAccounts = async (
47-
tapSubgraph: TAPSubgraph,
47+
tapSubgraph: SubgraphClient,
4848
indexer: Address,
4949
): Promise<EscrowAccounts> => {
5050
const result = await tapSubgraph.query<EscrowAccountResponse>(

packages/indexer-common/src/allocations/query-fees.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import {
2020
TransactionManager,
2121
specification as spec,
2222
sequentialTimerMap,
23+
SubgraphClient,
2324
} from '..'
2425
import { DHeap } from '@thi.ng/heaps'
2526
import { BigNumber, BigNumberish, Contract } from 'ethers'
2627
import { Op } from 'sequelize'
2728
import pReduce from 'p-reduce'
28-
import { NetworkSubgraph } from '../network-subgraph'
2929

3030
// Receipts are collected with a delay of 20 minutes after
3131
// the corresponding allocation was closed
@@ -71,7 +71,7 @@ export interface AllocationReceiptCollectorOptions {
7171
allocations: Eventual<Allocation[]>
7272
models: QueryFeeModels
7373
networkSpecification: spec.NetworkSpecification
74-
networkSubgraph: NetworkSubgraph
74+
networkSubgraph: SubgraphClient
7575
}
7676

7777
export interface ReceiptCollector {
@@ -94,7 +94,7 @@ export class AllocationReceiptCollector implements ReceiptCollector {
9494
declare voucherRedemptionBatchThreshold: BigNumber
9595
declare voucherRedemptionMaxBatchSize: number
9696
declare protocolNetwork: string
97-
declare networkSubgraph: NetworkSubgraph
97+
declare networkSubgraph: SubgraphClient
9898

9999
// eslint-disable-next-line @typescript-eslint/no-empty-function -- Private constructor to prevent direct instantiation
100100
private constructor() {}

packages/indexer-common/src/allocations/tap-collector.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import {
2525
} from '..'
2626
import { BigNumber } from 'ethers'
2727
import pReduce from 'p-reduce'
28-
import { TAPSubgraph } from '../tap-subgraph'
29-
import { NetworkSubgraph, QueryResult } from '../network-subgraph'
28+
import { SubgraphClient, QueryResult } from '../subgraph-client'
3029
import gql from 'graphql-tag'
3130
import { getEscrowAccounts } from './escrow-accounts'
3231

@@ -52,8 +51,8 @@ interface TapCollectorOptions {
5251
allocations: Eventual<Allocation[]>
5352
models: QueryFeeModels
5453
networkSpecification: spec.NetworkSpecification
55-
tapSubgraph: TAPSubgraph
56-
networkSubgraph: NetworkSubgraph
54+
tapSubgraph: SubgraphClient
55+
networkSubgraph: SubgraphClient
5756
}
5857

5958
interface ValidRavs {
@@ -107,8 +106,8 @@ export class TapCollector {
107106
declare allocations: Eventual<Allocation[]>
108107
declare ravRedemptionThreshold: BigNumber
109108
declare protocolNetwork: string
110-
declare tapSubgraph: TAPSubgraph
111-
declare networkSubgraph: NetworkSubgraph
109+
declare tapSubgraph: SubgraphClient
110+
declare networkSubgraph: SubgraphClient
112111
declare finalityTime: number
113112
declare indexerAddress: Address
114113

packages/indexer-common/src/allocations/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BigNumber } from 'ethers'
2-
import { NetworkSubgraph, SubgraphDeployment } from '@graphprotocol/indexer-common'
2+
import { SubgraphClient, SubgraphDeployment } from '@graphprotocol/indexer-common'
33

44
import { Logger, Address } from '@graphprotocol/common-ts'
55

@@ -31,7 +31,7 @@ export enum AllocationStatus {
3131
export interface MonitorEligibleAllocationsOptions {
3232
indexer: Address
3333
logger: Logger
34-
networkSubgraph: NetworkSubgraph
34+
networkSubgraph: SubgraphClient
3535
interval: number
3636
protocolNetwork: string
3737
}

packages/indexer-common/src/epoch-subgraph.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

packages/indexer-common/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
export * from './actions'
22
export * from './allocations'
33
export * from './async-cache'
4-
export * from './epoch-subgraph'
54
export * from './errors'
65
export * from './indexer-management'
76
export * from './graph-node'
87
export * from './operator'
98
export * from './network'
10-
export * from './network-subgraph'
119
export * from './query-fees'
1210
export * from './rules'
1311
export * from './subgraphs'
12+
export * from './subgraph-client'
1413
export * from './transactions'
1514
export * from './types'
1615
export * from './utils'

packages/indexer-common/src/indexer-management/__tests__/helpers.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ import { literal, Op, Sequelize } from 'sequelize'
2323
import {
2424
Allocation,
2525
AllocationStatus,
26-
EpochSubgraph,
2726
indexerError,
2827
IndexerErrorCode,
2928
GraphNode,
3029
NetworkMonitor,
31-
NetworkSubgraph,
30+
SubgraphClient,
3231
resolveChainAlias,
3332
resolveChainId,
3433
SubgraphDeployment,
@@ -48,8 +47,8 @@ let models: IndexerManagementModels
4847
let ethereum: ethers.providers.BaseProvider
4948
let contracts: NetworkContracts
5049
let graphNode: GraphNode
51-
let networkSubgraph: NetworkSubgraph
52-
let epochSubgraph: EpochSubgraph
50+
let networkSubgraph: SubgraphClient
51+
let epochSubgraph: SubgraphClient
5352
let networkMonitor: NetworkMonitor
5453
let logger: Logger
5554

@@ -84,18 +83,22 @@ const setupMonitor = async () => {
8483
)
8584

8685
const INDEXER_TEST_API_KEY: string = process.env['INDEXER_TEST_API_KEY'] || ''
87-
networkSubgraph = await NetworkSubgraph.create({
86+
87+
networkSubgraph = await SubgraphClient.create({
88+
name: 'NetworkSubgraph',
8889
logger,
8990
endpoint: `https://gateway-arbitrum.network.thegraph.com/api/${INDEXER_TEST_API_KEY}/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV`,
9091
deployment: undefined,
9192
subgraphFreshnessChecker,
9293
})
9394

94-
epochSubgraph = new EpochSubgraph(
95-
`https://gateway-arbitrum.network.thegraph.com/api/${INDEXER_TEST_API_KEY}/subgraphs/id/BhnsdeZihU4SuokxZMLF4FQBVJ3jgtZf6v51gHvz3bSS`,
96-
subgraphFreshnessChecker,
95+
epochSubgraph = await SubgraphClient.create({
96+
name: 'EpochSubgraph',
9797
logger,
98-
)
98+
endpoint: `https://gateway-arbitrum.network.thegraph.com/api/${INDEXER_TEST_API_KEY}/subgraphs/id/BhnsdeZihU4SuokxZMLF4FQBVJ3jgtZf6v51gHvz3bSS`,
99+
subgraphFreshnessChecker,
100+
})
101+
99102
graphNode = new GraphNode(
100103
logger,
101104
'http://test-admin-endpoint.xyz',

0 commit comments

Comments
 (0)