Skip to content

Commit 106f212

Browse files
committed
chore: manage dips in allocation actions
1 parent 919567a commit 106f212

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,22 @@ export type TransactionResult =
9999
| ActionFailure[]
100100

101101
export class AllocationManager {
102-
private dipsManager: DipsManager
102+
private dipsManager: DipsManager | null = null
103103
constructor(
104104
private logger: Logger,
105105
private models: IndexerManagementModels,
106106
private graphNode: GraphNode,
107107
private network: Network,
108108
) {
109-
this.dipsManager = new DipsManager(
110-
this.logger,
111-
this.models,
112-
this.graphNode,
113-
this.network,
114-
this,
115-
)
109+
if (this.network.specification.indexerOptions.dipperEndpoint) {
110+
this.dipsManager = new DipsManager(
111+
this.logger,
112+
this.models,
113+
this.graphNode,
114+
this.network,
115+
this,
116+
)
117+
}
116118
}
117119

118120
async executeBatch(actions: Action[]): Promise<AllocationResult[]> {
@@ -521,6 +523,14 @@ export class AllocationManager {
521523
await upsertIndexingRule(logger, this.models, indexingRule)
522524
}
523525

526+
if (this.dipsManager) {
527+
await this.dipsManager.tryUpdateAgreementAllocation(
528+
deployment,
529+
null,
530+
createAllocationEventLogs.allocationID,
531+
)
532+
}
533+
524534
return {
525535
actionID,
526536
type: 'allocate',
@@ -677,6 +687,15 @@ export class AllocationManager {
677687

678688
await upsertIndexingRule(logger, this.models, neverIndexingRule)
679689

690+
if (this.dipsManager) {
691+
await this.dipsManager.tryCancelAgreement(allocationID)
692+
await this.dipsManager.tryUpdateAgreementAllocation(
693+
allocation.subgraphDeployment.id.toString(),
694+
allocationID,
695+
null,
696+
)
697+
}
698+
680699
return {
681700
actionID,
682701
type: 'unallocate',
@@ -976,6 +995,14 @@ export class AllocationManager {
976995
await upsertIndexingRule(logger, this.models, indexingRule)
977996
}
978997

998+
if (this.dipsManager) {
999+
await this.dipsManager.tryUpdateAgreementAllocation(
1000+
subgraphDeploymentID.toString(),
1001+
allocationID,
1002+
createAllocationEventLogs.allocationID,
1003+
)
1004+
}
1005+
9791006
return {
9801007
actionID,
9811008
type: 'reallocate',

packages/indexer-common/src/indexing-fees/dips.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ export class DipsManager {
6969
}
7070
// Update the current and last allocation ids for an agreement if it exists
7171
async tryUpdateAgreementAllocation(
72-
oldAllocationId: string,
72+
deploymentId: string,
73+
oldAllocationId: string | null,
7374
newAllocationId: string | null,
7475
) {
7576
const agreement = await this.models.IndexingAgreement.findOne({
7677
where: {
77-
current_allocation_id: oldAllocationId,
78-
cancelled_at: null,
78+
subgraph_deployment_id: deploymentId,
7979
},
8080
})
8181
if (agreement) {

0 commit comments

Comments
 (0)