Skip to content

Commit 2695781

Browse files
committed
feat: indexing fees / dips (wip)
1 parent 860aafb commit 2695781

File tree

24 files changed

+927
-12
lines changed

24 files changed

+927
-12
lines changed

packages/indexer-agent/src/__tests__/indexer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ const setup = async () => {
146146
const network = await Network.create(
147147
logger,
148148
networkSpecification,
149+
models,
149150
queryFeeModels,
150151
graphNode,
151152
metrics,

packages/indexer-agent/src/agent.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ export class Agent {
220220
sequentialTimerMap(
221221
{ logger, milliseconds: requestIntervalSmall },
222222
async () => {
223+
if (network.specification.indexerOptions.enableDips) {
224+
// There should be a DipsManager in the operator
225+
if (!operator.dipsManager) {
226+
throw new Error('DipsManager is not available')
227+
}
228+
logger.trace('Ensuring indexing rules for DIPS', {
229+
protocolNetwork: network.specification.networkIdentifier,
230+
})
231+
await operator.dipsManager.ensureAgreementRules()
232+
}
223233
logger.trace('Fetching indexing rules', {
224234
protocolNetwork: network.specification.networkIdentifier,
225235
})

packages/indexer-agent/src/commands/start.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ export const start = {
308308
default: 1,
309309
group: 'Indexer Infrastructure',
310310
})
311+
.option('enable-dips', {
312+
description: 'Whether to enable Indexing Fees (DIPs)',
313+
type: 'boolean',
314+
default: false,
315+
group: 'Indexing Fees ("DIPs")',
316+
})
317+
.option('dipper-endpoint', {
318+
description: 'Gateway endpoint for DIPs receipts',
319+
type: 'string',
320+
array: false,
321+
required: false,
322+
group: 'Indexing Fees ("DIPs")',
323+
})
324+
.option('dips-allocation-amount', {
325+
description: 'Amount of GRT to allocate for DIPs',
326+
type: 'number',
327+
default: 1,
328+
required: false,
329+
group: 'Indexing Fees ("DIPs")',
330+
})
311331
.check(argv => {
312332
if (
313333
!argv['network-subgraph-endpoint'] &&
@@ -335,6 +355,9 @@ export const start = {
335355
) {
336356
return 'Invalid --rebate-claim-max-batch-size provided. Must be > 0 and an integer.'
337357
}
358+
if (argv['enable-dips'] && !argv['dipper-endpoint']) {
359+
return 'Invalid --dipper-endpoint provided. Must be provided when --enable-dips is true.'
360+
}
338361
return true
339362
})
340363
},
@@ -370,6 +393,10 @@ export async function createNetworkSpecification(
370393
allocateOnNetworkSubgraph: argv.allocateOnNetworkSubgraph,
371394
register: argv.register,
372395
finalityTime: argv.chainFinalizeTime,
396+
enableDips: argv.enableDips,
397+
dipperEndpoint: argv.dipperEndpoint,
398+
dipsAllocationAmount: argv.dipsAllocationAmount,
399+
dipsEpochsMargin: argv.dipsEpochsMargin,
373400
}
374401

375402
const transactionMonitoring = {
@@ -587,6 +614,7 @@ export async function run(
587614
const network = await Network.create(
588615
logger,
589616
networkSpecification,
617+
managementModels,
590618
queryFeeModels,
591619
graphNode,
592620
metrics,

packages/indexer-cli/src/__tests__/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const setup = async () => {
8787
const network = await Network.create(
8888
logger,
8989
testNetworkSpecification,
90+
models,
9091
queryFeeModels,
9192
graphNode,
9293
metrics,

packages/indexer-common/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
"clean": "rm -rf ./node_modules ./dist ./tsconfig.tsbuildinfo"
2323
},
2424
"dependencies": {
25-
"@pinax/graph-networks-registry": "0.6.7",
25+
"@bufbuild/protobuf": "2.2.3",
2626
"@graphprotocol/common-ts": "2.0.11",
2727
"@graphprotocol/cost-model": "0.1.18",
28+
"@graphprotocol/dips-proto": "0.2.2",
29+
"@grpc/grpc-js": "^1.12.6",
30+
"@pinax/graph-networks-registry": "0.6.7",
2831
"@semiotic-labs/tap-contracts-bindings": "^1.2.1",
2932
"@thi.ng/heaps": "1.2.38",
3033
"@types/lodash.clonedeep": "^4.5.7",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
TapSubgraphResponse,
88
TapCollector,
99
Allocation,
10+
defineIndexerManagementModels,
1011
} from '@graphprotocol/indexer-common'
1112
import {
1213
Address,
@@ -43,6 +44,7 @@ const setup = async () => {
4344
// Clearing the registry prevents duplicate metric registration in the default registry.
4445
metrics.registry.clear()
4546
sequelize = await connectDatabase(__DATABASE__)
47+
const models = defineIndexerManagementModels(sequelize)
4648
queryFeeModels = defineQueryFeeModels(sequelize)
4749
sequelize = await sequelize.sync({ force: true })
4850

@@ -56,6 +58,7 @@ const setup = async () => {
5658
const network = await Network.create(
5759
logger,
5860
testNetworkSpecification,
61+
models,
5962
queryFeeModels,
6063
graphNode,
6164
metrics,

packages/indexer-common/src/allocations/__tests__/validate-queries.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
defineIndexerManagementModels,
23
defineQueryFeeModels,
34
GraphNode,
45
Network,
@@ -36,6 +37,7 @@ const setup = async () => {
3637
// Clearing the registry prevents duplicate metric registration in the default registry.
3738
metrics.registry.clear()
3839
sequelize = await connectDatabase(__DATABASE__)
40+
const models = defineIndexerManagementModels(sequelize)
3941
queryFeeModels = defineQueryFeeModels(sequelize)
4042
sequelize = await sequelize.sync({ force: true })
4143

@@ -49,6 +51,7 @@ const setup = async () => {
4951
const network = await Network.create(
5052
logger,
5153
testNetworkSpecification,
54+
models,
5255
queryFeeModels,
5356
graphNode,
5457
metrics,

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ export type EscrowAccountResponse = {
1313
}[]
1414
}
1515

16+
export type EscrowSenderResponse = {
17+
signer: {
18+
sender: {
19+
id: string
20+
}
21+
}
22+
}
23+
1624
export class EscrowAccounts {
1725
constructor(private sendersBalances: Map<Address, U256>) {}
1826

@@ -65,3 +73,26 @@ export const getEscrowAccounts = async (
6573
}
6674
return EscrowAccounts.fromResponse(result.data)
6775
}
76+
77+
export const getEscrowSenderForSigner = async (
78+
tapSubgraph: SubgraphClient,
79+
signer: Address,
80+
): Promise<Address> => {
81+
const signerLower = signer.toLowerCase()
82+
const result = await tapSubgraph.query<EscrowSenderResponse>(
83+
gql`
84+
query EscrowAccountQuery($signer: ID!) {
85+
signer(id: $signer) {
86+
sender {
87+
id
88+
}
89+
}
90+
}
91+
`,
92+
{ signer: signerLower },
93+
)
94+
if (!result.data) {
95+
throw `There was an error while querying Tap Subgraph. Errors: ${result.error}`
96+
}
97+
return toAddress(result.data.signer.sender.id)
98+
}

packages/indexer-common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './allocations'
33
export * from './async-cache'
44
export * from './errors'
55
export * from './indexer-management'
6+
export * from './indexing-fees'
67
export * from './graph-node'
78
export * from './operator'
89
export * from './network'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const setup = async () => {
6161
const network = await Network.create(
6262
logger,
6363
testNetworkSpecification,
64+
managementModels,
6465
queryFeeModels,
6566
graphNode,
6667
metrics,

0 commit comments

Comments
 (0)