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'
9
3
10
4
// 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
+ }
11
31
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
+ {
16
36
declare id : CreationOptional < string >
17
37
declare signature : Buffer
18
38
declare signed_payload : Buffer
@@ -21,9 +41,9 @@ export class IndexingAgreement extends Model<
21
41
declare base_price_per_epoch : string
22
42
declare price_per_entity : string
23
43
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
27
47
declare deadline : Date
28
48
declare duration_epochs : bigint
29
49
declare max_initial_amount : string
@@ -34,8 +54,8 @@ export class IndexingAgreement extends Model<
34
54
declare updated_at : Date
35
55
declare cancelled_at : Date | null
36
56
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
39
59
declare last_payment_collected_at : Date | null
40
60
}
41
61
@@ -82,14 +102,38 @@ export const defineIndexingFeesModels = (sequelize: Sequelize): IndexingFeesMode
82
102
service : {
83
103
type : DataTypes . CHAR ( 40 ) ,
84
104
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
+ } ,
85
113
} ,
86
114
payee : {
87
115
type : DataTypes . CHAR ( 40 ) ,
88
116
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
+ } ,
89
125
} ,
90
126
payer : {
91
127
type : DataTypes . CHAR ( 40 ) ,
92
128
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
+ } ,
93
137
} ,
94
138
deadline : {
95
139
type : DataTypes . DATE ,
@@ -134,10 +178,40 @@ export const defineIndexingFeesModels = (sequelize: Sequelize): IndexingFeesMode
134
178
current_allocation_id : {
135
179
type : DataTypes . CHAR ( 40 ) ,
136
180
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
+ } ,
137
196
} ,
138
197
last_allocation_id : {
139
198
type : DataTypes . CHAR ( 40 ) ,
140
199
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
+ } ,
141
215
} ,
142
216
last_payment_collected_at : {
143
217
type : DataTypes . DATE ,
0 commit comments