From 842d2ff315a0c711cec493c641ac21990b298255 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Fri, 7 Feb 2025 18:42:08 -0300 Subject: [PATCH] feat: indexing fees / dips (wip) --- packages/indexer-agent/src/commands/start.ts | 28 +++++ packages/indexer-common/src/index.ts | 1 + .../indexer-common/src/indexing-fees/index.ts | 1 + .../src/indexing-fees/models.ts | 113 ++++++++++++++++++ .../src/network-specification.ts | 3 + 5 files changed, 146 insertions(+) create mode 100644 packages/indexer-common/src/indexing-fees/index.ts create mode 100644 packages/indexer-common/src/indexing-fees/models.ts diff --git a/packages/indexer-agent/src/commands/start.ts b/packages/indexer-agent/src/commands/start.ts index f22943ddb..a9f59dba0 100644 --- a/packages/indexer-agent/src/commands/start.ts +++ b/packages/indexer-agent/src/commands/start.ts @@ -14,6 +14,7 @@ import { createIndexerManagementClient, createIndexerManagementServer, defineIndexerManagementModels, + defineIndexingFeesModels, defineQueryFeeModels, GraphNode, indexerError, @@ -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'] && @@ -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 }) }, @@ -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 = { @@ -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`) diff --git a/packages/indexer-common/src/index.ts b/packages/indexer-common/src/index.ts index ab3eedd97..9a378416b 100644 --- a/packages/indexer-common/src/index.ts +++ b/packages/indexer-common/src/index.ts @@ -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' diff --git a/packages/indexer-common/src/indexing-fees/index.ts b/packages/indexer-common/src/indexing-fees/index.ts new file mode 100644 index 000000000..ad200c539 --- /dev/null +++ b/packages/indexer-common/src/indexing-fees/index.ts @@ -0,0 +1 @@ +export * from './models' diff --git a/packages/indexer-common/src/indexing-fees/models.ts b/packages/indexer-common/src/indexing-fees/models.ts new file mode 100644 index 000000000..213351ebe --- /dev/null +++ b/packages/indexer-common/src/indexing-fees/models.ts @@ -0,0 +1,113 @@ +import { DataTypes, Sequelize, Model, Association, CreationOptional, InferAttributes, InferCreationAttributes } from 'sequelize' + +// Indexing Fees AKA "DIPs" + +export class IndexingAgreement extends Model< + InferAttributes, + InferCreationAttributes +> { + declare id: CreationOptional; + 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, + } +} diff --git a/packages/indexer-common/src/network-specification.ts b/packages/indexer-common/src/network-specification.ts index f683cdec5..d16d3b343 100644 --- a/packages/indexer-common/src/network-specification.ts +++ b/packages/indexer-common/src/network-specification.ts @@ -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