@@ -59,55 +59,46 @@ export async function getAxelarGasFee(
5959 const axelarSourceChain = getAxelarChain ( sourceChain ) ;
6060 const axelarDestinationChain = getAxelarChain ( destinationChain ) ;
6161
62- const maxRetries = 3 ;
63- let lastResult : bigint | null = null ;
64-
65- // TODO: the Axelar API sometimes returns 0 gas fee. Retry a few times if we get 0.
66- // The issue is intermittent and the Axelar team is looking into fixing it.
67- for ( let attempt = 0 ; attempt < maxRetries ; attempt ++ ) {
68- const controller = new AbortController ( ) ;
69- const timeoutId = setTimeout ( ( ) => controller . abort ( ) , timeoutMs ) ;
70-
71- try {
72- const response = await fetch ( url , {
73- method : "POST" ,
74- headers : {
75- "Content-Type" : "application/json" ,
76- } ,
77- body : JSON . stringify ( {
78- sourceChain : axelarSourceChain ,
79- destinationChain : axelarDestinationChain ,
80- gasMultiplier : "auto" ,
81- gasLimit : gasLimit . toString ( ) ,
82- } ) ,
83- signal : controller . signal ,
84- } ) ;
85-
86- if ( ! response . ok ) {
87- const errorText = await response . text ( ) ;
88- throw new Error (
89- `Failed to estimate gas fee: ${ response . status } ${ errorText } `
90- ) ;
91- }
92-
93- const result = await response . json ( ) ;
94- lastResult = BigInt ( result ) ;
95-
96- if ( lastResult !== 0n ) {
97- return lastResult ;
98- }
99-
100- // If we got 0 and have more retries, wait 1 second before trying again
101- if ( attempt < maxRetries - 1 ) {
102- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
103- }
104- } finally {
105- clearTimeout ( timeoutId ) ;
62+ const controller = new AbortController ( ) ;
63+ const timeoutId = setTimeout ( ( ) => controller . abort ( ) , timeoutMs ) ;
64+
65+ // Set a minimum fee of 1 to avoid 0-fee issue with relays not proceeding
66+ // past the gas paid step
67+ let fee = 1n ;
68+
69+ try {
70+ const response = await fetch ( url , {
71+ method : "POST" ,
72+ headers : {
73+ "Content-Type" : "application/json" ,
74+ } ,
75+ body : JSON . stringify ( {
76+ sourceChain : axelarSourceChain ,
77+ destinationChain : axelarDestinationChain ,
78+ gasMultiplier : "auto" ,
79+ gasLimit : gasLimit . toString ( ) ,
80+ } ) ,
81+ signal : controller . signal ,
82+ } ) ;
83+
84+ if ( ! response . ok ) {
85+ const errorText = await response . text ( ) ;
86+ throw new Error (
87+ `Failed to estimate gas fee: ${ response . status } ${ errorText } `
88+ ) ;
10689 }
90+
91+ const result = await response . json ( ) ;
92+
93+ const parsedFee = BigInt ( result ) ;
94+ if ( parsedFee > 0n ) {
95+ fee = parsedFee ;
96+ }
97+ } finally {
98+ clearTimeout ( timeoutId ) ;
10799 }
108100
109- // If all retries returned 0, just return 1 wei
110- return lastResult ?? 1n ;
101+ return fee ;
111102}
112103
113104export async function getAxelarTransactionStatus (
0 commit comments