1- import axios from "axios" ;
21import AbstractApiClient from "./abstractClient" ;
3- import { BigNumber , parseEther } from "../utils" ;
2+ import { BigNumber , fetchWithTimeout , parseEther } from "../utils" ;
43import {
54 CoingeckoDataReturnType ,
65 SuggestedFeeReturnType ,
76 BridgeLimitsReturnType ,
87 AcrossBridgeStatisticsType ,
98} from "./types" ;
109
10+ type SuggestedFeesApiResponse = {
11+ relayFeePct : string ;
12+ relayFeeTotal : string ;
13+ capitalFeePct : string ;
14+ capitalFeeTotal : string ;
15+ relayGasFeePct : string ;
16+ relayGasFeeTotal : string ;
17+ isAmountTooLow : boolean ;
18+ timestamp : string ;
19+ quoteBlock : string ;
20+ } ;
21+
1122/**
1223 * An implementation of AbstractApiClient that uses the production API.
1324 * @class
@@ -20,13 +31,10 @@ export default class ProductionApiClient extends AbstractApiClient {
2031 }
2132
2233 public async getCoinGeckoData ( l1Token : string , baseCurrency : string ) : Promise < CoingeckoDataReturnType > {
23- const response = await axios . get ( `${ this . getServerlessApiUrl ( ) } /api/coingecko` , {
24- params : {
25- l1Token,
26- baseCurrency,
27- } ,
34+ const result = await fetchWithTimeout < { price : string } > ( `${ this . getServerlessApiUrl ( ) } /api/coingecko` , {
35+ l1Token,
36+ baseCurrency,
2837 } ) ;
29- const result = response . data ;
3038 const price = baseCurrency === "usd" ? parseEther ( String ( result . price ) ) : BigNumber . from ( result . price ) ;
3139 return {
3240 price,
@@ -38,16 +46,16 @@ export default class ProductionApiClient extends AbstractApiClient {
3846 toChainid : number ,
3947 fromChainid : number
4048 ) : Promise < SuggestedFeeReturnType > {
41- const response = await axios . get ( `${ this . getServerlessApiUrl ( ) } /api/suggested-fees` , {
42- params : {
49+ const result = await fetchWithTimeout < SuggestedFeesApiResponse > (
50+ `${ this . getServerlessApiUrl ( ) } /api/suggested-fees` ,
51+ {
4352 token : originToken ,
4453 destinationChainId : toChainid ,
4554 originChainId : fromChainid ,
4655 amount : amount . toString ( ) ,
4756 skipAmountLimit : true ,
48- } ,
49- } ) ;
50- const result = response . data ;
57+ }
58+ ) ;
5159 const relayFeePct = BigNumber . from ( result [ "relayFeePct" ] ) ;
5260 const relayFeeTotal = BigNumber . from ( result [ "relayFeeTotal" ] ) ;
5361
@@ -85,13 +93,15 @@ export default class ProductionApiClient extends AbstractApiClient {
8593 fromChainId : string | number ,
8694 toChainId : string | number
8795 ) : Promise < BridgeLimitsReturnType > {
88- const { data } = await axios . get < BridgeLimitsReturnType > (
89- `${ this . getServerlessApiUrl ( ) } /api/limits?token=${ token } &originChainId=${ fromChainId } &destinationChainId=${ toChainId } `
90- ) ;
96+ const data = await fetchWithTimeout < BridgeLimitsReturnType > ( `${ this . getServerlessApiUrl ( ) } /api/limits` , {
97+ token,
98+ originChainId : fromChainId ,
99+ destinationChainId : toChainId ,
100+ } ) ;
91101 return data ;
92102 }
93103 public async getAcrossStats ( ) : Promise < AcrossBridgeStatisticsType > {
94- const axiosResponse = await axios . get < AcrossBridgeStatisticsType > ( `${ this . getScraperApiUrl ( ) } /deposits/stats` ) ;
95- return axiosResponse . data ;
104+ const data = await fetchWithTimeout < AcrossBridgeStatisticsType > ( `${ this . getScraperApiUrl ( ) } /deposits/stats` ) ;
105+ return data ;
96106 }
97107}
0 commit comments