Skip to content

Commit 8bc0d18

Browse files
committed
fix: format
1 parent 6556da3 commit 8bc0d18

File tree

3 files changed

+79
-44
lines changed

3 files changed

+79
-44
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ export class AllocationManager {
106106
private graphNode: GraphNode,
107107
private network: Network,
108108
) {
109-
this.dipsManager = new DipsManager(this.logger, this.models, this.graphNode, this.network, this)
109+
this.dipsManager = new DipsManager(
110+
this.logger,
111+
this.models,
112+
this.graphNode,
113+
this.network,
114+
this,
115+
)
110116
}
111117

112118
async executeBatch(actions: Action[]): Promise<AllocationResult[]> {

packages/indexer-common/src/indexer-management/models/indexing-agreement.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
import { DataTypes, Sequelize, Model, CreationOptional, InferAttributes, InferCreationAttributes } from 'sequelize'
1+
import {
2+
DataTypes,
3+
Sequelize,
4+
Model,
5+
CreationOptional,
6+
InferAttributes,
7+
InferCreationAttributes,
8+
} from 'sequelize'
29

310
// Indexing Fees AKA "DIPs"
411

512
export class IndexingAgreement extends Model<
613
InferAttributes<IndexingAgreement>,
714
InferCreationAttributes<IndexingAgreement>
815
> {
9-
declare id: CreationOptional<string>;
10-
declare signature: Buffer;
11-
declare signed_payload: Buffer;
12-
declare protocol_network: string;
13-
declare chain_id: string;
14-
declare base_price_per_epoch: string;
15-
declare price_per_entity: string;
16-
declare subgraph_deployment_id: string;
17-
declare service: string;
18-
declare payee: string;
19-
declare payer: string;
20-
declare deadline: Date;
21-
declare duration_epochs: bigint;
22-
declare max_initial_amount: string;
23-
declare max_ongoing_amount_per_epoch: string;
24-
declare min_epochs_per_collection: bigint;
25-
declare max_epochs_per_collection: bigint;
26-
declare created_at: Date;
27-
declare updated_at: Date;
28-
declare cancelled_at: Date | null;
29-
declare signed_cancellation_payload: Buffer | null;
30-
declare current_allocation_id: string | null;
31-
declare last_allocation_id: string | null;
32-
declare last_payment_collected_at: Date | null;
16+
declare id: CreationOptional<string>
17+
declare signature: Buffer
18+
declare signed_payload: Buffer
19+
declare protocol_network: string
20+
declare chain_id: string
21+
declare base_price_per_epoch: string
22+
declare price_per_entity: string
23+
declare subgraph_deployment_id: string
24+
declare service: string
25+
declare payee: string
26+
declare payer: string
27+
declare deadline: Date
28+
declare duration_epochs: bigint
29+
declare max_initial_amount: string
30+
declare max_ongoing_amount_per_epoch: string
31+
declare min_epochs_per_collection: bigint
32+
declare max_epochs_per_collection: bigint
33+
declare created_at: Date
34+
declare updated_at: Date
35+
declare cancelled_at: Date | null
36+
declare signed_cancellation_payload: Buffer | null
37+
declare current_allocation_id: string | null
38+
declare last_allocation_id: string | null
39+
declare last_payment_collected_at: Date | null
3340
}
3441

3542
export interface IndexingFeesModels {

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

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
import { formatGRT, Logger, SubgraphDeploymentID } from "@graphprotocol/common-ts";
2-
import { AllocationManager, GraphNode, IndexerManagementModels, IndexingDecisionBasis, IndexingRuleAttributes, Network, SubgraphIdentifierType, upsertIndexingRule } from '@graphprotocol/indexer-common'
3-
import { Op } from "sequelize";
1+
import { formatGRT, Logger, SubgraphDeploymentID } from '@graphprotocol/common-ts'
2+
import {
3+
AllocationManager,
4+
GraphNode,
5+
IndexerManagementModels,
6+
IndexingDecisionBasis,
7+
IndexingRuleAttributes,
8+
Network,
9+
SubgraphIdentifierType,
10+
upsertIndexingRule,
11+
} from '@graphprotocol/indexer-common'
12+
import { Op } from 'sequelize'
413

514
export class DipsManager {
615
constructor(
@@ -20,12 +29,14 @@ export class DipsManager {
2029
})
2130
if (agreement) {
2231
// TODO use dips-proto to cancel agreement via grpc
23-
2432
// Mark the agreement as cancelled
2533
}
2634
}
2735
// Update the current and last allocation ids for an agreement if it exists
28-
async tryUpdateAgreementAllocation(oldAllocationId: string, newAllocationId: string | null) {
36+
async tryUpdateAgreementAllocation(
37+
oldAllocationId: string,
38+
newAllocationId: string | null,
39+
) {
2940
const agreement = await this.models.IndexingAgreement.findOne({
3041
where: {
3142
current_allocation_id: oldAllocationId,
@@ -65,17 +76,22 @@ export class DipsManager {
6576
// (tap-agent will take care of aggregating it into a RAV)
6677

6778
// Mark the agreement as having had a payment collected
68-
await this.models.IndexingAgreement.update({
69-
last_payment_collected_at: new Date(),
70-
}, {
71-
where: {
72-
last_allocation_id: lastAllocationId,
79+
await this.models.IndexingAgreement.update(
80+
{
81+
last_payment_collected_at: new Date(),
7382
},
74-
})
83+
{
84+
where: {
85+
last_allocation_id: lastAllocationId,
86+
},
87+
},
88+
)
7589
}
7690
async ensureAgreementRules() {
7791
if (!this.parent) {
78-
this.logger.error('DipsManager has no parent AllocationManager, cannot ensure agreement rules')
92+
this.logger.error(
93+
'DipsManager has no parent AllocationManager, cannot ensure agreement rules',
94+
)
7995
return
8096
}
8197
// Get all the indexing agreements that are not cancelled
@@ -87,20 +103,26 @@ export class DipsManager {
87103
// For each agreement, check that there is an indexing rule to always
88104
// allocate to the agreement's subgraphDeploymentId, and if not, create one
89105
for (const agreement of indexingAgreements) {
90-
const subgraphDeploymentID = new SubgraphDeploymentID(agreement.subgraph_deployment_id)
106+
const subgraphDeploymentID = new SubgraphDeploymentID(
107+
agreement.subgraph_deployment_id,
108+
)
91109
// If there is not yet an indexingRule that deems this deployment worth allocating to, make one
92110
if (!(await this.parent.matchingRuleExists(this.logger, subgraphDeploymentID))) {
93-
this.logger.debug(
94-
`Creating indexing rule for agreement ${agreement.id}`,
95-
)
111+
this.logger.debug(`Creating indexing rule for agreement ${agreement.id}`)
96112
const indexingRule = {
97113
identifier: agreement.subgraph_deployment_id,
98-
allocationAmount: formatGRT(this.network.specification.indexerOptions.dipsAllocationAmount),
114+
allocationAmount: formatGRT(
115+
this.network.specification.indexerOptions.dipsAllocationAmount,
116+
),
99117
identifierType: SubgraphIdentifierType.DEPLOYMENT,
100118
decisionBasis: IndexingDecisionBasis.ALWAYS,
101119
protocolNetwork: this.network.specification.networkIdentifier,
102120
autoRenewal: true,
103-
allocationLifetime: Math.max(Number(agreement.min_epochs_per_collection), Number(agreement.max_epochs_per_collection) - this.network.specification.indexerOptions.dipsEpochsMargin),
121+
allocationLifetime: Math.max(
122+
Number(agreement.min_epochs_per_collection),
123+
Number(agreement.max_epochs_per_collection) -
124+
this.network.specification.indexerOptions.dipsEpochsMargin,
125+
),
104126
} as Partial<IndexingRuleAttributes>
105127

106128
await upsertIndexingRule(this.logger, this.models, indexingRule)

0 commit comments

Comments
 (0)