@@ -34,41 +34,42 @@ export interface GMPError {
3434 message : string ;
3535}
3636
37+ export function getAxelarApiUrl ( network : Network ) : string {
38+ return network === "Mainnet"
39+ ? "https://api.axelarscan.io"
40+ : "https://testnet.api.axelarscan.io" ;
41+ }
42+
43+ export function getAxelarChain ( chain : Chain ) : string {
44+ const axelarChain = axelarChains [ chain ] ;
45+ if ( ! axelarChain ) {
46+ throw new Error ( `Unsupported axelar chain: ${ chain } ` ) ;
47+ }
48+ return axelarChain ;
49+ }
50+
3751export async function getAxelarGasFee (
3852 network : Network ,
3953 sourceChain : Chain ,
4054 destinationChain : Chain ,
4155 gasLimit : bigint ,
4256 timeoutMs = 10000
4357) : Promise < bigint > {
44- const baseUrl =
45- network === "Mainnet"
46- ? "https://api.axelarscan.io/gmp/estimateGasFee"
47- : "https://testnet.api.axelarscan.io/gmp/estimateGasFee" ;
48-
49- const axelarSourceChain = axelarChains [ sourceChain ] ;
50- if ( ! axelarSourceChain ) {
51- throw new Error ( `Unsupported axelar source chain: ${ sourceChain } ` ) ;
52- }
53-
54- const axelarDestinationChain = axelarChains [ destinationChain ] ;
55- if ( ! axelarDestinationChain ) {
56- throw new Error (
57- `Unsupported axelar destination chain: ${ destinationChain } `
58- ) ;
59- }
58+ const url = `${ getAxelarApiUrl ( network ) } /gmp/estimateGasFee` ;
59+ const axelarSourceChain = getAxelarChain ( sourceChain ) ;
60+ const axelarDestinationChain = getAxelarChain ( destinationChain ) ;
6061
6162 const maxRetries = 3 ;
6263 let lastResult : bigint | null = null ;
6364
6465 // TODO: the Axelar API sometimes returns 0 gas fee. Retry a few times if we get 0.
65- // The issue is intermittent and the Axelar team is looking into it.
66+ // The issue is intermittent and the Axelar team is looking into fixing it.
6667 for ( let attempt = 0 ; attempt < maxRetries ; attempt ++ ) {
6768 const controller = new AbortController ( ) ;
6869 const timeoutId = setTimeout ( ( ) => controller . abort ( ) , timeoutMs ) ;
6970
7071 try {
71- const response = await fetch ( baseUrl , {
72+ const response = await fetch ( url , {
7273 method : "POST" ,
7374 headers : {
7475 "Content-Type" : "application/json" ,
@@ -115,21 +116,15 @@ export async function getAxelarTransactionStatus(
115116 txHash : string ,
116117 timeoutMs = 10000
117118) : Promise < { status : GMPStatus | string ; error ?: GMPError } > {
118- const baseUrl =
119- network === "Mainnet"
120- ? "https://api.axelarscan.io"
121- : "https://testnet.api.axelarscan.io" ;
122-
123- const axelarSourceChain = axelarChains [ sourceChain ] ;
124- if ( ! axelarSourceChain ) {
125- throw new Error ( `Unsupported axelar source chain: ${ sourceChain } ` ) ;
126- }
119+ const url = `${ getAxelarApiUrl ( network ) } /gmp/searchGMP` ;
120+
121+ const axelarSourceChain = getAxelarChain ( sourceChain ) ;
127122
128123 const controller = new AbortController ( ) ;
129124 const timeoutId = setTimeout ( ( ) => controller . abort ( ) , timeoutMs ) ;
130125
131126 try {
132- const response = await fetch ( ` ${ baseUrl } /gmp/searchGMP` , {
127+ const response = await fetch ( url , {
133128 method : "POST" ,
134129 headers : {
135130 "Content-Type" : "application/json" ,
0 commit comments