@@ -20,6 +20,17 @@ const BASE_TBILL_PRICE_ORACLE_ADDRESS = 'unknown'
20
20
21
21
const RESULT_DECIMALS = 18
22
22
23
+ const createRoundData = ( { price, priceDecimals } : { price : number ; priceDecimals : number } ) => {
24
+ const now = BigInt ( Math . floor ( Date . now ( ) / 1000 ) )
25
+ return [
26
+ 1n , // roundId
27
+ BigInt ( price * 10 ** priceDecimals ) , // answer
28
+ now , // startedAt
29
+ now , // updatedAt
30
+ 1n , // answeredInRound
31
+ ]
32
+ }
33
+
23
34
const createMockTokenContract = ( ) => ( {
24
35
decimals : jest . fn ( ) ,
25
36
getWithdrawalQueueLength : jest . fn ( ) ,
@@ -29,7 +40,7 @@ const createMockTokenContract = () => ({
29
40
30
41
const createMockPriceContract = ( ) => ( {
31
42
decimals : jest . fn ( ) ,
32
- latestAnswer : jest . fn ( ) ,
43
+ latestRoundData : jest . fn ( ) ,
33
44
} )
34
45
35
46
const ethTbillContract = createMockTokenContract ( )
@@ -131,7 +142,9 @@ describe('TbillTransport', () => {
131
142
ethTbillContract . decimals . mockResolvedValue ( balanceDecimals )
132
143
ethTbillContract . balanceOf . mockResolvedValue ( BigInt ( balance * 10 ** balanceDecimals ) )
133
144
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
134
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
145
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
146
+ createRoundData ( { price, priceDecimals } ) ,
147
+ )
135
148
136
149
const param = {
137
150
addresses : [
@@ -149,10 +162,10 @@ describe('TbillTransport', () => {
149
162
150
163
expect ( ethTbillContract . balanceOf ) . toBeCalledWith ( walletAddress )
151
164
expect ( ethTbillContract . balanceOf ) . toBeCalledTimes ( 1 )
152
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 1 )
165
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 1 )
153
166
154
167
expect ( arbTbillContract . balanceOf ) . toBeCalledTimes ( 0 )
155
- expect ( arbTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 0 )
168
+ expect ( arbTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 0 )
156
169
157
170
expect ( responseCache . write ) . toBeCalledWith ( transportName , [
158
171
{
@@ -185,7 +198,9 @@ describe('TbillTransport', () => {
185
198
arbTbillContract . decimals . mockResolvedValue ( balanceDecimals )
186
199
arbTbillContract . balanceOf . mockResolvedValue ( BigInt ( balance * 10 ** balanceDecimals ) )
187
200
arbTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
188
- arbTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
201
+ arbTbillPriceContract . latestRoundData . mockResolvedValue (
202
+ createRoundData ( { price, priceDecimals } ) ,
203
+ )
189
204
190
205
const param = {
191
206
addresses : [
@@ -203,10 +218,10 @@ describe('TbillTransport', () => {
203
218
204
219
expect ( arbTbillContract . balanceOf ) . toBeCalledWith ( walletAddress )
205
220
expect ( arbTbillContract . balanceOf ) . toBeCalledTimes ( 1 )
206
- expect ( arbTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 1 )
221
+ expect ( arbTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 1 )
207
222
208
223
expect ( ethTbillContract . balanceOf ) . toBeCalledTimes ( 0 )
209
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 0 )
224
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 0 )
210
225
211
226
expect ( responseCache . write ) . toBeCalledWith ( transportName , [
212
227
{
@@ -265,8 +280,8 @@ describe('TbillTransport', () => {
265
280
BigInt ( ethTbillBalance2 * 10 ** ethTbillBalanceDecimals ) ,
266
281
)
267
282
ethTbillPriceContract . decimals . mockResolvedValue ( ethTbillPriceDecimals )
268
- ethTbillPriceContract . latestAnswer . mockResolvedValue (
269
- BigInt ( ethTbillPrice * 10 ** ethTbillPriceDecimals ) ,
283
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
284
+ createRoundData ( { price : ethTbillPrice , priceDecimals : ethTbillPriceDecimals } ) ,
270
285
)
271
286
272
287
arbTbillContract . decimals . mockResolvedValue ( arbTbillBalanceDecimals )
@@ -277,8 +292,8 @@ describe('TbillTransport', () => {
277
292
BigInt ( arbTbillBalance2 * 10 ** arbTbillBalanceDecimals ) ,
278
293
)
279
294
arbTbillPriceContract . decimals . mockResolvedValue ( arbTbillPriceDecimals )
280
- arbTbillPriceContract . latestAnswer . mockResolvedValue (
281
- BigInt ( arbTbillPrice * 10 ** arbTbillPriceDecimals ) ,
295
+ arbTbillPriceContract . latestRoundData . mockResolvedValue (
296
+ createRoundData ( { price : arbTbillPrice , priceDecimals : arbTbillPriceDecimals } ) ,
282
297
)
283
298
284
299
const param = {
@@ -317,13 +332,13 @@ describe('TbillTransport', () => {
317
332
expect ( ethTbillContract . balanceOf ) . toHaveBeenNthCalledWith ( 2 , ethWalletAddress2 )
318
333
expect ( ethTbillContract . balanceOf ) . toBeCalledTimes ( 2 )
319
334
// TODO: Do we really need 2 calls to the price contract?
320
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 2 )
335
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 2 )
321
336
322
337
expect ( arbTbillContract . balanceOf ) . toHaveBeenNthCalledWith ( 1 , arbWalletAddress1 )
323
338
expect ( arbTbillContract . balanceOf ) . toHaveBeenNthCalledWith ( 2 , arbWalletAddress2 )
324
339
expect ( arbTbillContract . balanceOf ) . toBeCalledTimes ( 2 )
325
340
// TODO: Do we really need 2 calls to the price contract?
326
- expect ( arbTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 2 )
341
+ expect ( arbTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 2 )
327
342
328
343
expect ( responseCache . write ) . toBeCalledWith ( transportName , [
329
344
{
@@ -358,7 +373,9 @@ describe('TbillTransport', () => {
358
373
ethTbillContract . decimals . mockResolvedValue ( decimalsPromise )
359
374
ethTbillContract . balanceOf . mockResolvedValue ( BigInt ( balance * 10 ** balanceDecimals ) )
360
375
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
361
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
376
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
377
+ createRoundData ( { price, priceDecimals } ) ,
378
+ )
362
379
363
380
const param = {
364
381
addresses : [
@@ -411,7 +428,9 @@ describe('TbillTransport', () => {
411
428
ethTbillContract . decimals . mockRejectedValue ( new Error ( 'test error' ) )
412
429
ethTbillContract . balanceOf . mockResolvedValue ( BigInt ( balance * 10 ** balanceDecimals ) )
413
430
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
414
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
431
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
432
+ createRoundData ( { price, priceDecimals } ) ,
433
+ )
415
434
416
435
const param = {
417
436
addresses : [
@@ -457,7 +476,9 @@ describe('TbillTransport', () => {
457
476
ethTbillContract . decimals . mockResolvedValue ( balanceDecimals )
458
477
ethTbillContract . balanceOf . mockResolvedValue ( BigInt ( balance * 10 ** balanceDecimals ) )
459
478
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
460
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
479
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
480
+ createRoundData ( { price, priceDecimals } ) ,
481
+ )
461
482
462
483
const param = {
463
484
addresses : [
@@ -481,10 +502,10 @@ describe('TbillTransport', () => {
481
502
482
503
expect ( ethTbillContract . balanceOf ) . toBeCalledWith ( walletAddress )
483
504
expect ( ethTbillContract . balanceOf ) . toBeCalledTimes ( 1 )
484
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 1 )
505
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 1 )
485
506
486
507
expect ( arbTbillContract . balanceOf ) . toBeCalledTimes ( 0 )
487
- expect ( arbTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 0 )
508
+ expect ( arbTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 0 )
488
509
489
510
expect ( responseCache . write ) . toBeCalledWith ( transportName , [
490
511
{
@@ -534,7 +555,9 @@ describe('TbillTransport', () => {
534
555
} )
535
556
536
557
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
537
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
558
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
559
+ createRoundData ( { price, priceDecimals } ) ,
560
+ )
538
561
539
562
const param : RequestParams = {
540
563
addresses : [
@@ -607,7 +630,9 @@ describe('TbillTransport', () => {
607
630
} )
608
631
609
632
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
610
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
633
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
634
+ createRoundData ( { price, priceDecimals } ) ,
635
+ )
611
636
612
637
const param : RequestParams = {
613
638
addresses : [
@@ -687,7 +712,9 @@ describe('TbillTransport', () => {
687
712
)
688
713
689
714
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
690
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
715
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
716
+ createRoundData ( { price, priceDecimals } ) ,
717
+ )
691
718
692
719
const param : RequestParams = {
693
720
addresses : [ walletAddress1 , walletAddress2 ] . map ( ( walletAddress ) => ( {
@@ -768,7 +795,9 @@ describe('TbillTransport', () => {
768
795
)
769
796
770
797
ethTbillPriceContract . decimals . mockResolvedValue ( priceDecimals )
771
- ethTbillPriceContract . latestAnswer . mockResolvedValue ( BigInt ( price * 10 ** priceDecimals ) )
798
+ ethTbillPriceContract . latestRoundData . mockResolvedValue (
799
+ createRoundData ( { price, priceDecimals } ) ,
800
+ )
772
801
773
802
const param : RequestParams = {
774
803
addresses : [
@@ -834,8 +863,8 @@ describe('TbillTransport', () => {
834
863
deferred ( BigInt ( balance * 10 ** balanceDecimals ) ) ,
835
864
)
836
865
ethTbillPriceContract . decimals . mockImplementation ( deferred ( priceDecimals ) )
837
- ethTbillPriceContract . latestAnswer . mockImplementation (
838
- deferred ( BigInt ( price * 10 ** priceDecimals ) ) ,
866
+ ethTbillPriceContract . latestRoundData . mockImplementation (
867
+ deferred ( createRoundData ( { price, priceDecimals } ) ) ,
839
868
)
840
869
ethTbillContract . getWithdrawalQueueLength . mockImplementation ( deferred ( 0 ) )
841
870
@@ -855,7 +884,7 @@ describe('TbillTransport', () => {
855
884
// 2. ethTbillContract.balanceOf
856
885
// 5. ethTbillContract.getWithdrawalQueueLength
857
886
// 3. ethTbillPriceContract.decimals
858
- // 4. ethTbillPriceContract.latestAnswer
887
+ // 4. ethTbillPriceContract.latestRoundData
859
888
//
860
889
// So for 2 addresses we expect 10 RPCs. With a group size of 3, we
861
890
// should have 4 batches of sizes 3, 3, 3, and 1.
@@ -876,7 +905,7 @@ describe('TbillTransport', () => {
876
905
expect ( ethTbillContract . decimals ) . toBeCalledTimes ( 2 )
877
906
expect ( ethTbillContract . getWithdrawalQueueLength ) . toBeCalledTimes ( 2 )
878
907
expect ( ethTbillPriceContract . decimals ) . toBeCalledTimes ( 2 )
879
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 2 )
908
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 2 )
880
909
} )
881
910
882
911
it ( 'should limit concurrent RPCs per provider' , async ( ) => {
@@ -904,8 +933,8 @@ describe('TbillTransport', () => {
904
933
deferred ( BigInt ( balance * 10 ** balanceDecimals ) ) ,
905
934
)
906
935
ethTbillPriceContract . decimals . mockImplementation ( deferred ( priceDecimals ) )
907
- ethTbillPriceContract . latestAnswer . mockImplementation (
908
- deferred ( BigInt ( price * 10 ** priceDecimals ) ) ,
936
+ ethTbillPriceContract . latestRoundData . mockImplementation (
937
+ deferred ( createRoundData ( { price, priceDecimals } ) ) ,
909
938
)
910
939
ethTbillContract . getWithdrawalQueueLength . mockImplementation ( deferred ( 0 ) )
911
940
@@ -914,8 +943,8 @@ describe('TbillTransport', () => {
914
943
deferred ( BigInt ( balance * 10 ** balanceDecimals ) ) ,
915
944
)
916
945
arbTbillPriceContract . decimals . mockImplementation ( deferred ( priceDecimals ) )
917
- arbTbillPriceContract . latestAnswer . mockImplementation (
918
- deferred ( BigInt ( price * 10 ** priceDecimals ) ) ,
946
+ arbTbillPriceContract . latestRoundData . mockImplementation (
947
+ deferred ( createRoundData ( { price, priceDecimals } ) ) ,
919
948
)
920
949
arbTbillContract . getWithdrawalQueueLength . mockImplementation ( deferred ( 0 ) )
921
950
@@ -943,7 +972,7 @@ describe('TbillTransport', () => {
943
972
// 2. ethTbillContract.balanceOf
944
973
// 5. ethTbillContract.getWithdrawalQueueLength
945
974
// 3. ethTbillPriceContract.decimals
946
- // 4. ethTbillPriceContract.latestAnswer
975
+ // 4. ethTbillPriceContract.latestRoundData
947
976
//
948
977
// So for 4 addresses we expect 20 RPCs. With a group size of 3 but a
949
978
// separate group size per provider, we should have 4 batches of sizes 6,
@@ -965,13 +994,13 @@ describe('TbillTransport', () => {
965
994
expect ( ethTbillContract . decimals ) . toBeCalledTimes ( 2 )
966
995
expect ( ethTbillContract . getWithdrawalQueueLength ) . toBeCalledTimes ( 2 )
967
996
expect ( ethTbillPriceContract . decimals ) . toBeCalledTimes ( 2 )
968
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 2 )
997
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 2 )
969
998
970
999
expect ( arbTbillContract . balanceOf ) . toBeCalledTimes ( 2 )
971
1000
expect ( arbTbillContract . decimals ) . toBeCalledTimes ( 2 )
972
1001
expect ( arbTbillContract . getWithdrawalQueueLength ) . toBeCalledTimes ( 2 )
973
1002
expect ( arbTbillPriceContract . decimals ) . toBeCalledTimes ( 2 )
974
- expect ( arbTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 2 )
1003
+ expect ( arbTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 2 )
975
1004
} )
976
1005
977
1006
it ( 'should reset RPC grouping for a new request' , async ( ) => {
@@ -999,8 +1028,8 @@ describe('TbillTransport', () => {
999
1028
deferred ( BigInt ( balance * 10 ** balanceDecimals ) ) ,
1000
1029
)
1001
1030
ethTbillPriceContract . decimals . mockImplementation ( deferred ( priceDecimals ) )
1002
- ethTbillPriceContract . latestAnswer . mockImplementation (
1003
- deferred ( BigInt ( price * 10 ** priceDecimals ) ) ,
1031
+ ethTbillPriceContract . latestRoundData . mockImplementation (
1032
+ deferred ( createRoundData ( { price, priceDecimals } ) ) ,
1004
1033
)
1005
1034
ethTbillContract . getWithdrawalQueueLength . mockImplementation ( deferred ( 0 ) )
1006
1035
@@ -1020,7 +1049,7 @@ describe('TbillTransport', () => {
1020
1049
// 2. ethTbillContract.balanceOf
1021
1050
// 5. ethTbillContract.getWithdrawalQueueLength
1022
1051
// 3. ethTbillPriceContract.decimals
1023
- // 4. ethTbillPriceContract.latestAnswer
1052
+ // 4. ethTbillPriceContract.latestARoundData
1024
1053
//
1025
1054
// So for 2 addresses we expect 10 RPCs. With a group size of 3, we
1026
1055
// should have 4 batches of sizes 3, 3, 3, and 1.
@@ -1041,7 +1070,7 @@ describe('TbillTransport', () => {
1041
1070
expect ( ethTbillContract . decimals ) . toBeCalledTimes ( 2 )
1042
1071
expect ( ethTbillContract . getWithdrawalQueueLength ) . toBeCalledTimes ( 2 )
1043
1072
expect ( ethTbillPriceContract . decimals ) . toBeCalledTimes ( 2 )
1044
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 2 )
1073
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 2 )
1045
1074
1046
1075
// When we make a new request, it should start with another group of 3,
1047
1076
// rather than just 2, which might happen if we reuse the same
@@ -1058,7 +1087,7 @@ describe('TbillTransport', () => {
1058
1087
expect ( ethTbillContract . decimals ) . toBeCalledTimes ( 4 )
1059
1088
expect ( ethTbillContract . getWithdrawalQueueLength ) . toBeCalledTimes ( 4 )
1060
1089
expect ( ethTbillPriceContract . decimals ) . toBeCalledTimes ( 4 )
1061
- expect ( ethTbillPriceContract . latestAnswer ) . toBeCalledTimes ( 4 )
1090
+ expect ( ethTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 4 )
1062
1091
} )
1063
1092
} )
1064
1093
0 commit comments