@@ -2,6 +2,8 @@ import { DataTypes, Sequelize, Model, Association, CreationOptional } from 'sequ
2
2
import { Address , toAddress } from '@graphprotocol/common-ts'
3
3
import { caip2IdRegex } from '../parsers'
4
4
import { TAPVerifier } from '@semiotic-labs/tap-contracts-bindings'
5
+ import { RAV as RAVv2 } from '@graphprotocol/toolshed'
6
+ import { BytesLike } from 'ethers'
5
7
6
8
export interface ScalarTapReceiptsAttributes {
7
9
id : number
@@ -100,6 +102,21 @@ export interface ReceiptAggregateVoucherAttributes {
100
102
redeemedAt : Date | null
101
103
final : boolean
102
104
}
105
+
106
+ export interface ReceiptAggregateVoucherV2Attributes {
107
+ collectionId : string
108
+ payer : string
109
+ serviceProvider : string
110
+ dataService : string
111
+ metadata : string
112
+ signature : Uint8Array
113
+ timestampNs : bigint
114
+ valueAggregate : bigint
115
+ last : boolean
116
+ redeemedAt : Date | null
117
+ final : boolean
118
+ }
119
+
103
120
export interface FailedReceiptAggregateVoucherAttributes {
104
121
allocationId : string
105
122
senderAddress : string
@@ -142,6 +159,53 @@ export class ReceiptAggregateVoucher
142
159
}
143
160
}
144
161
162
+ // TODO HORIZON: move this to the toolshed package
163
+ export type SignedRAVv2 = {
164
+ rav : RAVv2
165
+ signature : BytesLike
166
+ }
167
+
168
+ export class ReceiptAggregateVoucherV2
169
+ extends Model < ReceiptAggregateVoucherV2Attributes >
170
+ implements ReceiptAggregateVoucherV2Attributes
171
+ {
172
+ public collectionId ! : Address
173
+ public payer ! : Address
174
+ public serviceProvider ! : Address
175
+ public dataService ! : Address
176
+ public metadata ! : string
177
+ public signature ! : Uint8Array
178
+ public timestampNs ! : bigint
179
+ public valueAggregate ! : bigint
180
+ public final ! : boolean
181
+ public last ! : boolean
182
+ public redeemedAt ! : Date | null
183
+
184
+ declare createdAt : CreationOptional < Date >
185
+ declare updatedAt : CreationOptional < Date >
186
+
187
+ public readonly allocationSummary ?: AllocationSummary
188
+
189
+ public static associations : {
190
+ allocationSummary : Association < ReceiptAggregateVoucherV2 , AllocationSummary >
191
+ }
192
+
193
+ getSignedRAV ( ) : SignedRAVv2 {
194
+ return {
195
+ rav : {
196
+ collectionId : this . collectionId ,
197
+ payer : this . payer ,
198
+ serviceProvider : this . serviceProvider ,
199
+ dataService : this . dataService ,
200
+ timestampNs : Number ( this . timestampNs ) ,
201
+ valueAggregate : this . valueAggregate ,
202
+ metadata : this . metadata ,
203
+ } ,
204
+ signature : this . signature ,
205
+ }
206
+ }
207
+ }
208
+
145
209
export type SignedRAV = TAPVerifier . SignedRAVStruct
146
210
147
211
export class FailedReceiptAggregateVoucher
@@ -265,6 +329,7 @@ export interface QueryFeeModels {
265
329
allocationReceipts : typeof AllocationReceipt
266
330
vouchers : typeof Voucher
267
331
receiptAggregateVouchers : typeof ReceiptAggregateVoucher
332
+ receiptAggregateVouchersV2 : typeof ReceiptAggregateVoucherV2
268
333
transferReceipts : typeof TransferReceipt
269
334
transfers : typeof Transfer
270
335
allocationSummaries : typeof AllocationSummary
@@ -416,6 +481,110 @@ export function defineQueryFeeModels(sequelize: Sequelize): QueryFeeModels {
416
481
} ,
417
482
)
418
483
484
+
485
+ ReceiptAggregateVoucherV2 . init (
486
+ {
487
+ collectionId : {
488
+ type : DataTypes . CHAR ( 64 ) , // 64 because prefix '0x' gets removed by GraphTally agent
489
+ allowNull : false ,
490
+ primaryKey : true ,
491
+ get ( ) {
492
+ const rawValue = this . getDataValue ( 'collectionId' )
493
+ return toAddress ( rawValue )
494
+ } ,
495
+ set ( value : Address ) {
496
+ const addressWithoutPrefix = value . toLowerCase ( ) . replace ( '0x' , '' )
497
+ this . setDataValue ( 'collectionId' , addressWithoutPrefix )
498
+ } ,
499
+ } ,
500
+ payer : {
501
+ type : DataTypes . CHAR ( 40 ) , // 40 because prefix '0x' gets removed by TAP agent
502
+ allowNull : false ,
503
+ primaryKey : true ,
504
+ get ( ) {
505
+ const rawValue = this . getDataValue ( 'payer' )
506
+ return toAddress ( rawValue )
507
+ } ,
508
+ set ( value : string ) {
509
+ const addressWithoutPrefix = value . toLowerCase ( ) . replace ( '0x' , '' )
510
+ this . setDataValue ( 'payer' , addressWithoutPrefix )
511
+ } ,
512
+ } ,
513
+ serviceProvider : {
514
+ type : DataTypes . CHAR ( 40 ) , // 40 because prefix '0x' gets removed by TAP agent
515
+ allowNull : false ,
516
+ primaryKey : true ,
517
+ get ( ) {
518
+ const rawValue = this . getDataValue ( 'serviceProvider' )
519
+ return toAddress ( rawValue )
520
+ } ,
521
+ set ( value : string ) {
522
+ const addressWithoutPrefix = value . toLowerCase ( ) . replace ( '0x' , '' )
523
+ this . setDataValue ( 'serviceProvider' , addressWithoutPrefix )
524
+ } ,
525
+ } ,
526
+ dataService : {
527
+ type : DataTypes . CHAR ( 40 ) , // 40 because prefix '0x' gets removed by TAP agent
528
+ allowNull : false ,
529
+ primaryKey : true ,
530
+ get ( ) {
531
+ const rawValue = this . getDataValue ( 'dataService' )
532
+ return toAddress ( rawValue )
533
+ } ,
534
+ set ( value : string ) {
535
+ const addressWithoutPrefix = value . toLowerCase ( ) . replace ( '0x' , '' )
536
+ this . setDataValue ( 'dataService' , addressWithoutPrefix )
537
+ } ,
538
+ } ,
539
+ metadata : {
540
+ type : DataTypes . STRING ,
541
+ allowNull : false ,
542
+ } ,
543
+ signature : {
544
+ type : DataTypes . BLOB ,
545
+ allowNull : false ,
546
+ } ,
547
+ // ternary operator added to timestampNs and valueAggregate
548
+ // due to sequelize UPDATE
549
+ // calls the getters with undefined data
550
+ // 0 is returned since no real data is being requested
551
+ timestampNs : {
552
+ type : DataTypes . DECIMAL ,
553
+ allowNull : false ,
554
+ get ( ) {
555
+ return BigInt ( this . getDataValue ( 'timestampNs' ) )
556
+ } ,
557
+ } ,
558
+ valueAggregate : {
559
+ type : DataTypes . DECIMAL ,
560
+ allowNull : false ,
561
+ get ( ) {
562
+ return BigInt ( this . getDataValue ( 'valueAggregate' ) )
563
+ } ,
564
+ } ,
565
+ last : {
566
+ type : DataTypes . BOOLEAN ,
567
+ allowNull : false ,
568
+ defaultValue : false ,
569
+ } ,
570
+ final : {
571
+ type : DataTypes . BOOLEAN ,
572
+ allowNull : false ,
573
+ defaultValue : false ,
574
+ } ,
575
+ redeemedAt : {
576
+ type : DataTypes . DATE ,
577
+ allowNull : true ,
578
+ defaultValue : null ,
579
+ } ,
580
+ } ,
581
+ {
582
+ underscored : true ,
583
+ sequelize,
584
+ tableName : 'scalar_tap_ravs' ,
585
+ } ,
586
+ )
587
+
419
588
TransferReceipt . init (
420
589
{
421
590
id : {
@@ -718,6 +887,7 @@ export function defineQueryFeeModels(sequelize: Sequelize): QueryFeeModels {
718
887
allocationReceipts : AllocationReceipt ,
719
888
vouchers : Voucher ,
720
889
receiptAggregateVouchers : ReceiptAggregateVoucher ,
890
+ receiptAggregateVouchersV2 : ReceiptAggregateVoucherV2 ,
721
891
transferReceipts : TransferReceipt ,
722
892
transfers : Transfer ,
723
893
allocationSummaries : AllocationSummary ,
0 commit comments