@@ -9,6 +9,8 @@ type RequestParams = typeof inputParameters.validated
9
9
const ETHEREUM_RPC_CHAIN_ID = '1'
10
10
const ETHEREUM_TBILL_CONTRACT_ADDRESS = '0xdd50C053C096CB04A3e3362E2b622529EC5f2e8a'
11
11
const ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS = '0xCe9a6626Eb99eaeA829D7fA613d5D0A2eaE45F40'
12
+ const ETHEREUM_USYC_CONTRACT_ADDRESS = '0x136471a34f6ef19fE571EFFC1CA711fdb8E49f2b'
13
+ const ETHEREUM_USYC_PRICE_ORACLE_ADDRESS = '0x4c48bcb2160F8e0aDbf9D4F3B034f1e36d1f8b3e'
12
14
13
15
const ARBITRUM_RPC_CHAIN_ID = '42161'
14
16
const ARBITRUM_TBILL_CONTRACT_ADDRESS = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
@@ -18,6 +20,7 @@ const BASE_RPC_CHAIN_ID = '8453'
18
20
const BASE_TBILL_CONTRACT_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
19
21
const BASE_TBILL_PRICE_ORACLE_ADDRESS = 'unknown'
20
22
23
+ const TOKEN_SYMBOL = 'TBILL'
21
24
const RESULT_DECIMALS = 18
22
25
23
26
const createRoundData = ( { price, priceDecimals } : { price : number ; priceDecimals : number } ) => {
@@ -45,12 +48,16 @@ const createMockPriceContract = () => ({
45
48
46
49
const ethTbillContract = createMockTokenContract ( )
47
50
const ethTbillPriceContract = createMockPriceContract ( )
51
+ const ethUsycContract = createMockTokenContract ( )
52
+ const ethUsycPriceContract = createMockPriceContract ( )
48
53
const arbTbillContract = createMockTokenContract ( )
49
54
const arbTbillPriceContract = createMockPriceContract ( )
50
55
51
56
const contracts : Record < string , unknown > = {
52
57
[ ETHEREUM_TBILL_CONTRACT_ADDRESS ] : ethTbillContract ,
53
58
[ ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ] : ethTbillPriceContract ,
59
+ [ ETHEREUM_USYC_CONTRACT_ADDRESS ] : ethUsycContract ,
60
+ [ ETHEREUM_USYC_PRICE_ORACLE_ADDRESS ] : ethUsycPriceContract ,
54
61
[ ARBITRUM_TBILL_CONTRACT_ADDRESS ] : arbTbillContract ,
55
62
[ ARBITRUM_TBILL_PRICE_ORACLE_ADDRESS ] : arbTbillPriceContract ,
56
63
}
@@ -131,6 +138,64 @@ describe('TbillTransport', () => {
131
138
} )
132
139
133
140
describe ( 'handleRequest' , ( ) => {
141
+ it ( 'should cache ethereum usyc balance' , async ( ) => {
142
+ const balance = 3
143
+ const balanceDecimals = 6
144
+ const price = 7
145
+ const priceDecimals = 8
146
+ const result = String ( balance * price * 10 ** RESULT_DECIMALS )
147
+
148
+ const walletAddress = '0x602a1cb1f821a3e8f507a7637a4be7af19578f75'
149
+ ethUsycContract . decimals . mockResolvedValue ( balanceDecimals )
150
+ ethUsycContract . balanceOf . mockResolvedValue ( BigInt ( balance * 10 ** balanceDecimals ) )
151
+ ethUsycPriceContract . decimals . mockResolvedValue ( priceDecimals )
152
+ ethUsycPriceContract . latestRoundData . mockResolvedValue (
153
+ createRoundData ( { price, priceDecimals } ) ,
154
+ )
155
+
156
+ const param = {
157
+ addresses : [
158
+ {
159
+ chainId : ETHEREUM_RPC_CHAIN_ID ,
160
+ contractAddress : ETHEREUM_USYC_CONTRACT_ADDRESS ,
161
+ token : 'USYC' ,
162
+ priceOracleAddress : ETHEREUM_USYC_PRICE_ORACLE_ADDRESS ,
163
+ wallets : [ walletAddress ] ,
164
+ } ,
165
+ ] ,
166
+ } as RequestParams
167
+
168
+ const now = Date . now ( )
169
+ await transport . handleRequest ( context , param )
170
+
171
+ expect ( ethUsycContract . balanceOf ) . toBeCalledWith ( walletAddress )
172
+ expect ( ethUsycContract . balanceOf ) . toBeCalledTimes ( 1 )
173
+ expect ( ethUsycPriceContract . latestRoundData ) . toBeCalledTimes ( 1 )
174
+ expect ( ethUsycContract . getWithdrawalQueueLength ) . toBeCalledTimes ( 0 )
175
+
176
+ expect ( arbTbillContract . balanceOf ) . toBeCalledTimes ( 0 )
177
+ expect ( arbTbillPriceContract . latestRoundData ) . toBeCalledTimes ( 0 )
178
+
179
+ expect ( responseCache . write ) . toBeCalledWith ( transportName , [
180
+ {
181
+ params : param ,
182
+ response : {
183
+ data : {
184
+ decimals : RESULT_DECIMALS ,
185
+ result,
186
+ } ,
187
+ result,
188
+ statusCode : 200 ,
189
+ timestamps : {
190
+ providerDataRequestedUnixMs : now ,
191
+ providerDataReceivedUnixMs : now ,
192
+ } ,
193
+ } ,
194
+ } ,
195
+ ] )
196
+ expect ( responseCache . write ) . toBeCalledTimes ( 1 )
197
+ } )
198
+
134
199
it ( 'should cache ethereum tbill balance' , async ( ) => {
135
200
const balance = 3
136
201
const balanceDecimals = 6
@@ -151,6 +216,7 @@ describe('TbillTransport', () => {
151
216
{
152
217
chainId : ETHEREUM_RPC_CHAIN_ID ,
153
218
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
219
+ token : TOKEN_SYMBOL ,
154
220
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
155
221
wallets : [ walletAddress ] ,
156
222
} ,
@@ -207,6 +273,7 @@ describe('TbillTransport', () => {
207
273
{
208
274
chainId : ARBITRUM_RPC_CHAIN_ID ,
209
275
contractAddress : ARBITRUM_TBILL_CONTRACT_ADDRESS ,
276
+ token : TOKEN_SYMBOL ,
210
277
priceOracleAddress : ARBITRUM_TBILL_PRICE_ORACLE_ADDRESS ,
211
278
wallets : [ walletAddress ] ,
212
279
} ,
@@ -307,18 +374,21 @@ describe('TbillTransport', () => {
307
374
{
308
375
chainId : ETHEREUM_RPC_CHAIN_ID ,
309
376
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
377
+ token : TOKEN_SYMBOL ,
310
378
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
311
379
wallets : [ ethWalletAddress2 ] ,
312
380
} ,
313
381
{
314
382
chainId : ARBITRUM_RPC_CHAIN_ID ,
315
383
contractAddress : ARBITRUM_TBILL_CONTRACT_ADDRESS ,
384
+ token : TOKEN_SYMBOL ,
316
385
priceOracleAddress : ARBITRUM_TBILL_PRICE_ORACLE_ADDRESS ,
317
386
wallets : [ arbWalletAddress1 ] ,
318
387
} ,
319
388
{
320
389
chainId : ARBITRUM_RPC_CHAIN_ID ,
321
390
contractAddress : ARBITRUM_TBILL_CONTRACT_ADDRESS ,
391
+ token : TOKEN_SYMBOL ,
322
392
priceOracleAddress : ARBITRUM_TBILL_PRICE_ORACLE_ADDRESS ,
323
393
wallets : [ arbWalletAddress2 ] ,
324
394
} ,
@@ -382,6 +452,7 @@ describe('TbillTransport', () => {
382
452
{
383
453
chainId : ETHEREUM_RPC_CHAIN_ID ,
384
454
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
455
+ token : TOKEN_SYMBOL ,
385
456
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
386
457
wallets : [ walletAddress ] ,
387
458
} ,
@@ -437,6 +508,7 @@ describe('TbillTransport', () => {
437
508
{
438
509
chainId : ETHEREUM_RPC_CHAIN_ID ,
439
510
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
511
+ token : TOKEN_SYMBOL ,
440
512
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
441
513
wallets : [ walletAddress ] ,
442
514
} ,
@@ -485,12 +557,14 @@ describe('TbillTransport', () => {
485
557
{
486
558
chainId : ETHEREUM_RPC_CHAIN_ID ,
487
559
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
560
+ token : TOKEN_SYMBOL ,
488
561
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
489
562
wallets : [ walletAddress ] ,
490
563
} ,
491
564
{
492
565
chainId : BASE_RPC_CHAIN_ID ,
493
566
contractAddress : BASE_TBILL_CONTRACT_ADDRESS ,
567
+ token : TOKEN_SYMBOL ,
494
568
priceOracleAddress : BASE_TBILL_PRICE_ORACLE_ADDRESS ,
495
569
wallets : [ walletAddress ] ,
496
570
} ,
@@ -564,6 +638,7 @@ describe('TbillTransport', () => {
564
638
{
565
639
chainId : ETHEREUM_RPC_CHAIN_ID ,
566
640
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
641
+ token : TOKEN_SYMBOL ,
567
642
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
568
643
wallets : [ walletAddress ] ,
569
644
} ,
@@ -639,6 +714,7 @@ describe('TbillTransport', () => {
639
714
{
640
715
chainId : ETHEREUM_RPC_CHAIN_ID ,
641
716
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
717
+ token : TOKEN_SYMBOL ,
642
718
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
643
719
wallets : [ walletAddress ] ,
644
720
} ,
@@ -720,6 +796,7 @@ describe('TbillTransport', () => {
720
796
addresses : [ walletAddress1 , walletAddress2 ] . map ( ( walletAddress ) => ( {
721
797
chainId : ETHEREUM_RPC_CHAIN_ID ,
722
798
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
799
+ token : TOKEN_SYMBOL ,
723
800
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
724
801
wallets : [ walletAddress ] ,
725
802
} ) ) ,
@@ -804,6 +881,7 @@ describe('TbillTransport', () => {
804
881
{
805
882
chainId : ETHEREUM_RPC_CHAIN_ID ,
806
883
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
884
+ token : TOKEN_SYMBOL ,
807
885
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
808
886
wallets : [ walletAddress1 , walletAddress2 ] ,
809
887
} ,
@@ -872,6 +950,7 @@ describe('TbillTransport', () => {
872
950
addresses : [ walletAddress1 , walletAddress2 ] . map ( ( walletAddress ) => ( {
873
951
chainId : ETHEREUM_RPC_CHAIN_ID ,
874
952
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
953
+ token : TOKEN_SYMBOL ,
875
954
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
876
955
wallets : [ walletAddress ] ,
877
956
} ) ) ,
@@ -953,12 +1032,14 @@ describe('TbillTransport', () => {
953
1032
{
954
1033
chainId : ETHEREUM_RPC_CHAIN_ID ,
955
1034
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
1035
+ token : TOKEN_SYMBOL ,
956
1036
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
957
1037
wallets : [ walletAddress ] ,
958
1038
} ,
959
1039
{
960
1040
chainId : ARBITRUM_RPC_CHAIN_ID ,
961
1041
contractAddress : ARBITRUM_TBILL_CONTRACT_ADDRESS ,
1042
+ token : TOKEN_SYMBOL ,
962
1043
priceOracleAddress : ARBITRUM_TBILL_PRICE_ORACLE_ADDRESS ,
963
1044
wallets : [ walletAddress ] ,
964
1045
} ,
@@ -1037,6 +1118,7 @@ describe('TbillTransport', () => {
1037
1118
addresses : [ walletAddress1 , walletAddress2 ] . map ( ( walletAddress ) => ( {
1038
1119
chainId : ETHEREUM_RPC_CHAIN_ID ,
1039
1120
contractAddress : ETHEREUM_TBILL_CONTRACT_ADDRESS ,
1121
+ token : TOKEN_SYMBOL ,
1040
1122
priceOracleAddress : ETHEREUM_TBILL_PRICE_ORACLE_ADDRESS ,
1041
1123
wallets : [ walletAddress ] ,
1042
1124
} ) ) ,
0 commit comments