Skip to content

Commit e345487

Browse files
committed
test: more
1 parent 59b23e9 commit e345487

File tree

7 files changed

+363
-67
lines changed

7 files changed

+363
-67
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export class AllocationManager {
521521
await this.dipsManager.tryUpdateAgreementAllocation(
522522
deployment,
523523
null,
524-
createAllocationEventLogs.allocationID,
524+
toAddress(createAllocationEventLogs.allocationID),
525525
)
526526
}
527527

@@ -685,7 +685,7 @@ export class AllocationManager {
685685
await this.dipsManager.tryCancelAgreement(allocationID)
686686
await this.dipsManager.tryUpdateAgreementAllocation(
687687
allocation.subgraphDeployment.id.toString(),
688-
allocationID,
688+
toAddress(allocationID),
689689
null,
690690
)
691691
}
@@ -992,8 +992,8 @@ export class AllocationManager {
992992
if (this.dipsManager) {
993993
await this.dipsManager.tryUpdateAgreementAllocation(
994994
subgraphDeploymentID.toString(),
995-
allocationID,
996-
createAllocationEventLogs.allocationID,
995+
toAddress(allocationID),
996+
toAddress(createAllocationEventLogs.allocationID),
997997
)
998998
}
999999

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

Lines changed: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
import {
2-
DataTypes,
3-
Sequelize,
4-
Model,
5-
CreationOptional,
6-
InferAttributes,
7-
InferCreationAttributes,
8-
} from 'sequelize'
1+
import { toAddress, Address } from '@graphprotocol/common-ts'
2+
import { DataTypes, Sequelize, Model, CreationOptional } from 'sequelize'
93

104
// Indexing Fees AKA "DIPs"
5+
export interface IndexingAgreementAttributes {
6+
id: string
7+
signature: Buffer
8+
signed_payload: Buffer
9+
protocol_network: string
10+
chain_id: string
11+
base_price_per_epoch: string
12+
price_per_entity: string
13+
subgraph_deployment_id: string
14+
service: string
15+
payee: string
16+
payer: string
17+
deadline: Date
18+
duration_epochs: bigint
19+
max_initial_amount: string
20+
max_ongoing_amount_per_epoch: string
21+
min_epochs_per_collection: bigint
22+
max_epochs_per_collection: bigint
23+
created_at: Date
24+
updated_at: Date
25+
cancelled_at: Date | null
26+
signed_cancellation_payload: Buffer | null
27+
current_allocation_id: string | null
28+
last_allocation_id: string | null
29+
last_payment_collected_at: Date | null
30+
}
1131

12-
export class IndexingAgreement extends Model<
13-
InferAttributes<IndexingAgreement>,
14-
InferCreationAttributes<IndexingAgreement>
15-
> {
32+
export class IndexingAgreement
33+
extends Model<IndexingAgreementAttributes>
34+
implements IndexingAgreementAttributes
35+
{
1636
declare id: CreationOptional<string>
1737
declare signature: Buffer
1838
declare signed_payload: Buffer
@@ -21,9 +41,9 @@ export class IndexingAgreement extends Model<
2141
declare base_price_per_epoch: string
2242
declare price_per_entity: string
2343
declare subgraph_deployment_id: string
24-
declare service: string
25-
declare payee: string
26-
declare payer: string
44+
declare service: Address
45+
declare payee: Address
46+
declare payer: Address
2747
declare deadline: Date
2848
declare duration_epochs: bigint
2949
declare max_initial_amount: string
@@ -34,8 +54,8 @@ export class IndexingAgreement extends Model<
3454
declare updated_at: Date
3555
declare cancelled_at: Date | null
3656
declare signed_cancellation_payload: Buffer | null
37-
declare current_allocation_id: string | null
38-
declare last_allocation_id: string | null
57+
declare current_allocation_id: Address | null
58+
declare last_allocation_id: Address | null
3959
declare last_payment_collected_at: Date | null
4060
}
4161

@@ -82,14 +102,38 @@ export const defineIndexingFeesModels = (sequelize: Sequelize): IndexingFeesMode
82102
service: {
83103
type: DataTypes.CHAR(40),
84104
allowNull: false,
105+
get() {
106+
const rawValue = this.getDataValue('service')
107+
return toAddress(rawValue)
108+
},
109+
set(value: Address) {
110+
const addressWithoutPrefix = value.toLowerCase().replace('0x', '')
111+
this.setDataValue('service', addressWithoutPrefix)
112+
},
85113
},
86114
payee: {
87115
type: DataTypes.CHAR(40),
88116
allowNull: false,
117+
get() {
118+
const rawValue = this.getDataValue('payee')
119+
return toAddress(rawValue)
120+
},
121+
set(value: Address) {
122+
const addressWithoutPrefix = value.toLowerCase().replace('0x', '')
123+
this.setDataValue('payee', addressWithoutPrefix)
124+
},
89125
},
90126
payer: {
91127
type: DataTypes.CHAR(40),
92128
allowNull: false,
129+
get() {
130+
const rawValue = this.getDataValue('payer')
131+
return toAddress(rawValue)
132+
},
133+
set(value: Address) {
134+
const addressWithoutPrefix = value.toLowerCase().replace('0x', '')
135+
this.setDataValue('payer', addressWithoutPrefix)
136+
},
93137
},
94138
deadline: {
95139
type: DataTypes.DATE,
@@ -134,10 +178,40 @@ export const defineIndexingFeesModels = (sequelize: Sequelize): IndexingFeesMode
134178
current_allocation_id: {
135179
type: DataTypes.CHAR(40),
136180
allowNull: true,
181+
get() {
182+
const rawValue = this.getDataValue('current_allocation_id')
183+
if (!rawValue) {
184+
return null
185+
}
186+
return toAddress(rawValue)
187+
},
188+
set(value: Address | null) {
189+
if (!value) {
190+
this.setDataValue('current_allocation_id', null)
191+
} else {
192+
const addressWithoutPrefix = value.toLowerCase().replace('0x', '')
193+
this.setDataValue('current_allocation_id', addressWithoutPrefix)
194+
}
195+
},
137196
},
138197
last_allocation_id: {
139198
type: DataTypes.CHAR(40),
140199
allowNull: true,
200+
get() {
201+
const rawValue = this.getDataValue('last_allocation_id')
202+
if (!rawValue) {
203+
return null
204+
}
205+
return toAddress(rawValue)
206+
},
207+
set(value: Address | null) {
208+
if (!value) {
209+
this.setDataValue('last_allocation_id', null)
210+
} else {
211+
const addressWithoutPrefix = value.toLowerCase().replace('0x', '')
212+
this.setDataValue('last_allocation_id', addressWithoutPrefix)
213+
}
214+
},
141215
},
142216
last_payment_collected_at: {
143217
type: DataTypes.DATE,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ export default {
581581
await actionManager.allocationManager.dipsManager.tryUpdateAgreementAllocation(
582582
deployment,
583583
null,
584-
createAllocationEventLogs.allocationID,
584+
toAddress(createAllocationEventLogs.allocationID),
585585
)
586586
}
587587

@@ -744,7 +744,7 @@ export default {
744744
await actionManager.allocationManager.dipsManager.tryCancelAgreement(allocation)
745745
await actionManager.allocationManager.dipsManager.tryUpdateAgreementAllocation(
746746
allocationData.subgraphDeployment.id.toString(),
747-
allocation,
747+
toAddress(allocation),
748748
null,
749749
)
750750
}
@@ -1058,8 +1058,8 @@ export default {
10581058
if (actionManager?.allocationManager?.dipsManager) {
10591059
await actionManager.allocationManager.dipsManager.tryUpdateAgreementAllocation(
10601060
allocationData.subgraphDeployment.id.toString(),
1061-
allocation,
1062-
createAllocationEventLogs.allocationID,
1061+
toAddress(allocation),
1062+
toAddress(createAllocationEventLogs.allocationID),
10631063
)
10641064
}
10651065

0 commit comments

Comments
 (0)