From 5b4df7597c4acd28e172e7d42af7cbe2e9b36828 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Fri, 7 Feb 2025 20:11:51 -0300 Subject: [PATCH] fix: format --- .../src/indexer-management/allocations.ts | 8 ++- .../models/indexing-agreement.ts | 57 ++++++++++-------- .../indexer-common/src/indexing-fees/dips.ts | 58 +++++++++++++------ 3 files changed, 79 insertions(+), 44 deletions(-) diff --git a/packages/indexer-common/src/indexer-management/allocations.ts b/packages/indexer-common/src/indexer-management/allocations.ts index a44db2053..d9303345d 100644 --- a/packages/indexer-common/src/indexer-management/allocations.ts +++ b/packages/indexer-common/src/indexer-management/allocations.ts @@ -106,7 +106,13 @@ export class AllocationManager { private graphNode: GraphNode, private network: Network, ) { - this.dipsManager = new DipsManager(this.logger, this.models, this.graphNode, this.network, this) + this.dipsManager = new DipsManager( + this.logger, + this.models, + this.graphNode, + this.network, + this, + ) } async executeBatch(actions: Action[]): Promise { diff --git a/packages/indexer-common/src/indexer-management/models/indexing-agreement.ts b/packages/indexer-common/src/indexer-management/models/indexing-agreement.ts index 4d9351779..180e528a4 100644 --- a/packages/indexer-common/src/indexer-management/models/indexing-agreement.ts +++ b/packages/indexer-common/src/indexer-management/models/indexing-agreement.ts @@ -1,4 +1,11 @@ -import { DataTypes, Sequelize, Model, CreationOptional, InferAttributes, InferCreationAttributes } from 'sequelize' +import { + DataTypes, + Sequelize, + Model, + CreationOptional, + InferAttributes, + InferCreationAttributes, +} from 'sequelize' // Indexing Fees AKA "DIPs" @@ -6,30 +13,30 @@ 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 base_price_per_epoch: string; - declare price_per_entity: string; - declare subgraph_deployment_id: string; - declare service: string; - declare payee: string; - declare payer: string; - declare deadline: Date; - declare duration_epochs: bigint; - declare max_initial_amount: string; - declare max_ongoing_amount_per_epoch: string; - declare min_epochs_per_collection: bigint; - declare max_epochs_per_collection: bigint; - 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; - declare last_payment_collected_at: Date | null; + declare id: CreationOptional + declare signature: Buffer + declare signed_payload: Buffer + declare protocol_network: string + declare chain_id: string + declare base_price_per_epoch: string + declare price_per_entity: string + declare subgraph_deployment_id: string + declare service: string + declare payee: string + declare payer: string + declare deadline: Date + declare duration_epochs: bigint + declare max_initial_amount: string + declare max_ongoing_amount_per_epoch: string + declare min_epochs_per_collection: bigint + declare max_epochs_per_collection: bigint + 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 + declare last_payment_collected_at: Date | null } export interface IndexingFeesModels { diff --git a/packages/indexer-common/src/indexing-fees/dips.ts b/packages/indexer-common/src/indexing-fees/dips.ts index 28da7d9b1..de9ada303 100644 --- a/packages/indexer-common/src/indexing-fees/dips.ts +++ b/packages/indexer-common/src/indexing-fees/dips.ts @@ -1,6 +1,15 @@ -import { formatGRT, Logger, SubgraphDeploymentID } from "@graphprotocol/common-ts"; -import { AllocationManager, GraphNode, IndexerManagementModels, IndexingDecisionBasis, IndexingRuleAttributes, Network, SubgraphIdentifierType, upsertIndexingRule } from '@graphprotocol/indexer-common' -import { Op } from "sequelize"; +import { formatGRT, Logger, SubgraphDeploymentID } from '@graphprotocol/common-ts' +import { + AllocationManager, + GraphNode, + IndexerManagementModels, + IndexingDecisionBasis, + IndexingRuleAttributes, + Network, + SubgraphIdentifierType, + upsertIndexingRule, +} from '@graphprotocol/indexer-common' +import { Op } from 'sequelize' export class DipsManager { constructor( @@ -20,12 +29,14 @@ export class DipsManager { }) if (agreement) { // TODO use dips-proto to cancel agreement via grpc - // Mark the agreement as cancelled } } // Update the current and last allocation ids for an agreement if it exists - async tryUpdateAgreementAllocation(oldAllocationId: string, newAllocationId: string | null) { + async tryUpdateAgreementAllocation( + oldAllocationId: string, + newAllocationId: string | null, + ) { const agreement = await this.models.IndexingAgreement.findOne({ where: { current_allocation_id: oldAllocationId, @@ -65,17 +76,22 @@ export class DipsManager { // (tap-agent will take care of aggregating it into a RAV) // Mark the agreement as having had a payment collected - await this.models.IndexingAgreement.update({ - last_payment_collected_at: new Date(), - }, { - where: { - last_allocation_id: lastAllocationId, + await this.models.IndexingAgreement.update( + { + last_payment_collected_at: new Date(), }, - }) + { + where: { + last_allocation_id: lastAllocationId, + }, + }, + ) } async ensureAgreementRules() { if (!this.parent) { - this.logger.error('DipsManager has no parent AllocationManager, cannot ensure agreement rules') + this.logger.error( + 'DipsManager has no parent AllocationManager, cannot ensure agreement rules', + ) return } // Get all the indexing agreements that are not cancelled @@ -87,20 +103,26 @@ export class DipsManager { // For each agreement, check that there is an indexing rule to always // allocate to the agreement's subgraphDeploymentId, and if not, create one for (const agreement of indexingAgreements) { - const subgraphDeploymentID = new SubgraphDeploymentID(agreement.subgraph_deployment_id) + const subgraphDeploymentID = new SubgraphDeploymentID( + agreement.subgraph_deployment_id, + ) // If there is not yet an indexingRule that deems this deployment worth allocating to, make one if (!(await this.parent.matchingRuleExists(this.logger, subgraphDeploymentID))) { - this.logger.debug( - `Creating indexing rule for agreement ${agreement.id}`, - ) + this.logger.debug(`Creating indexing rule for agreement ${agreement.id}`) const indexingRule = { identifier: agreement.subgraph_deployment_id, - allocationAmount: formatGRT(this.network.specification.indexerOptions.dipsAllocationAmount), + allocationAmount: formatGRT( + this.network.specification.indexerOptions.dipsAllocationAmount, + ), identifierType: SubgraphIdentifierType.DEPLOYMENT, decisionBasis: IndexingDecisionBasis.ALWAYS, protocolNetwork: this.network.specification.networkIdentifier, autoRenewal: true, - allocationLifetime: Math.max(Number(agreement.min_epochs_per_collection), Number(agreement.max_epochs_per_collection) - this.network.specification.indexerOptions.dipsEpochsMargin), + allocationLifetime: Math.max( + Number(agreement.min_epochs_per_collection), + Number(agreement.max_epochs_per_collection) - + this.network.specification.indexerOptions.dipsEpochsMargin, + ), } as Partial await upsertIndexingRule(this.logger, this.models, indexingRule)