From 3427a3afb5ac6567a148516e667167ddd56f89a9 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Fri, 14 Feb 2025 18:16:17 -0300 Subject: [PATCH] chore: add dips actions in allocations resolvers --- .../src/indexer-management/allocations.ts | 2 +- .../resolvers/allocations.ts | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/indexer-common/src/indexer-management/allocations.ts b/packages/indexer-common/src/indexer-management/allocations.ts index 4f6daa68d..e0529ccc7 100644 --- a/packages/indexer-common/src/indexer-management/allocations.ts +++ b/packages/indexer-common/src/indexer-management/allocations.ts @@ -99,7 +99,7 @@ export type TransactionResult = | ActionFailure[] export class AllocationManager { - private dipsManager: DipsManager | null = null + declare dipsManager: DipsManager | null constructor( private logger: Logger, private models: IndexerManagementModels, diff --git a/packages/indexer-common/src/indexer-management/resolvers/allocations.ts b/packages/indexer-common/src/indexer-management/resolvers/allocations.ts index b412beffb..7c8f9efca 100644 --- a/packages/indexer-common/src/indexer-management/resolvers/allocations.ts +++ b/packages/indexer-common/src/indexer-management/resolvers/allocations.ts @@ -374,7 +374,7 @@ export default { amount: string protocolNetwork: string }, - { network, graphNode, logger, models }: IndexerManagementResolverContext, + { network, graphNode, logger, models, actionManager }: IndexerManagementResolverContext, ): Promise => { logger.debug('Execute createAllocation() mutation', { deployment, @@ -571,6 +571,14 @@ export default { await models.IndexingRule.upsert(indexingRule) + if (actionManager?.allocationManager?.dipsManager) { + await actionManager.allocationManager.dipsManager.tryUpdateAgreementAllocation( + deployment, + null, + createAllocationEventLogs.allocationID, + ) + } + // Since upsert succeeded, we _must_ have a rule const updatedRule = await models.IndexingRule.findOne({ where: { identifier: indexingRule.identifier }, @@ -608,7 +616,7 @@ export default { poi: string | undefined force: boolean }, - { logger, models, network }: IndexerManagementResolverContext, + { logger, models, network, actionManager }: IndexerManagementResolverContext, ): Promise => { logger.debug('Execute closeAllocation() mutation', { allocationID: allocation, @@ -726,6 +734,17 @@ export default { await models.IndexingRule.upsert(offchainIndexingRule) + if (actionManager?.allocationManager?.dipsManager) { + await actionManager.allocationManager.dipsManager.tryCancelAgreement( + allocation, + ) + await actionManager.allocationManager.dipsManager.tryUpdateAgreementAllocation( + allocationData.subgraphDeployment.id.toString(), + allocation, + null, + ) + } + // Since upsert succeeded, we _must_ have a rule const updatedRule = await models.IndexingRule.findOne({ where: { identifier: offchainIndexingRule.identifier }, @@ -765,7 +784,7 @@ export default { force: boolean protocolNetwork: string }, - { logger, models, network }: IndexerManagementResolverContext, + { logger, models, network, actionManager }: IndexerManagementResolverContext, ): Promise => { logger = logger.child({ component: 'reallocateAllocationResolver', @@ -1032,6 +1051,14 @@ export default { await models.IndexingRule.upsert(indexingRule) + if (actionManager?.allocationManager?.dipsManager) { + await actionManager.allocationManager.dipsManager.tryUpdateAgreementAllocation( + allocationData.subgraphDeployment.id.toString(), + allocation, + createAllocationEventLogs.allocationID, + ) + } + // Since upsert succeeded, we _must_ have a rule const updatedRule = await models.IndexingRule.findOne({ where: { identifier: indexingRule.identifier },