Skip to content

Commit

Permalink
feat: indexing fees / dips (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarranzav committed Feb 7, 2025
1 parent 7423814 commit 842d2ff
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/indexer-agent/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
createIndexerManagementClient,
createIndexerManagementServer,
defineIndexerManagementModels,
defineIndexingFeesModels,
defineQueryFeeModels,
GraphNode,
indexerError,
Expand Down Expand Up @@ -302,6 +303,26 @@ export const start = {
default: 1,
group: 'Indexer Infrastructure',
})
.option('enable-dips', {
description: 'Whether to enable Indexing Fees (DIPs)',
type: 'boolean',
default: false,
group: 'Indexing Fees ("DIPs")',
})
.option('dipper-endpoint', {
description: 'Gateway endpoint for DIPs receipts',
type: 'string',
array: false,
required: false,
group: 'Indexing Fees ("DIPs")',
})
.option('dips-allocation-amount', {
description: 'Amount of GRT to allocate for DIPs',
type: 'number',
default: 1,
required: false,
group: 'Indexing Fees ("DIPs")',
})
.check(argv => {
if (
!argv['network-subgraph-endpoint'] &&
Expand Down Expand Up @@ -329,6 +350,9 @@ export const start = {
) {
return 'Invalid --rebate-claim-max-batch-size provided. Must be > 0 and an integer.'
}
if (argv['enable-dips'] && !argv['dipper-endpoint']) {
return 'Invalid --dipper-endpoint provided. Must be provided when --enable-dips is true.'
}
return true
})
},
Expand Down Expand Up @@ -364,6 +388,9 @@ export async function createNetworkSpecification(
allocateOnNetworkSubgraph: argv.allocateOnNetworkSubgraph,
register: argv.register,
finalityTime: argv.chainFinalizeTime,
enableDips: argv.enableDips,
dipperEndpoint: argv.dipperEndpoint,
dipsAllocationAmount: argv.dipsAllocationAmount,
}

const transactionMonitoring = {
Expand Down Expand Up @@ -567,6 +594,7 @@ export async function run(
logger.info(`Sync database models`)
const managementModels = defineIndexerManagementModels(sequelize)
const queryFeeModels = defineQueryFeeModels(sequelize)
const indexingFeesModels = defineIndexingFeesModels(sequelize)
await sequelize.sync()
logger.info(`Successfully synced database models`)

Expand Down
1 change: 1 addition & 0 deletions packages/indexer-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './allocations'
export * from './async-cache'
export * from './errors'
export * from './indexer-management'
export * from './indexing-fees'
export * from './graph-node'
export * from './operator'
export * from './network'
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-common/src/indexing-fees/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './models'
113 changes: 113 additions & 0 deletions packages/indexer-common/src/indexing-fees/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { DataTypes, Sequelize, Model, Association, CreationOptional, InferAttributes, InferCreationAttributes } from 'sequelize'

// Indexing Fees AKA "DIPs"

export class IndexingAgreement extends Model<
InferAttributes<IndexingAgreement>,
InferCreationAttributes<IndexingAgreement>
> {
declare id: CreationOptional<string>;
declare signature: Buffer;
declare signed_payload: Buffer;
declare protocol_network: string;
declare chain_id: string;
declare price_per_block: string;
declare price_per_entity: string;
declare subgraph_deployment_id: string;
declare service: string;
declare payee: string;
declare payer: string;
declare created_at: Date;
declare updated_at: Date;
declare cancelled_at: Date | null;
declare signed_cancellation_payload: Buffer | null;
declare current_allocation_id: string | null;
declare last_allocation_id: string | null;
}

export interface IndexingFeesModels {
IndexingAgreement: typeof IndexingAgreement
}

export const defineIndexingFeesModels = (sequelize: Sequelize): IndexingFeesModels => {
IndexingAgreement.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
},
signature: {
type: DataTypes.BLOB, // == BYTEA in postgres
allowNull: false,
},
signed_payload: {
type: DataTypes.BLOB, // == BYTEA in postgres
allowNull: false,
},
protocol_network: {
type: DataTypes.STRING(255),
allowNull: false,
},
chain_id: {
type: DataTypes.STRING(255),
allowNull: false,
},
price_per_block: {
type: DataTypes.DECIMAL(39),
allowNull: false,
},
price_per_entity: {
type: DataTypes.DECIMAL(39),
allowNull: false,
},
subgraph_deployment_id: {
type: DataTypes.STRING(255),
allowNull: false,
},
service: {
type: DataTypes.CHAR(40),
allowNull: false,
},
payee: {
type: DataTypes.CHAR(40),
allowNull: false,
},
payer: {
type: DataTypes.CHAR(40),
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
},
cancelled_at: {
type: DataTypes.DATE,
allowNull: true,
},
signed_cancellation_payload: {
type: DataTypes.BLOB,
allowNull: true,
},
current_allocation_id: {
type: DataTypes.CHAR(40),
allowNull: true,
},
last_allocation_id: {
type: DataTypes.CHAR(40),
allowNull: true,
},
},
{
modelName: 'IndexingAgreement',
sequelize,
},
)

return {
['IndexingAgreement']: IndexingAgreement,
}
}
3 changes: 3 additions & 0 deletions packages/indexer-common/src/network-specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export const IndexerOptions = z
allocateOnNetworkSubgraph: z.boolean().default(false),
register: z.boolean().default(true),
finalityTime: positiveNumber().default(3600),
enableDips: z.boolean().default(false),
dipperEndpoint: z.string().url().optional(),
dipsAllocationAmount: GRT().default(1),
})
.strict()
export type IndexerOptions = z.infer<typeof IndexerOptions>
Expand Down

0 comments on commit 842d2ff

Please sign in to comment.