Shawn Lu 1 жил өмнө
parent
commit
d0b186ace7

+ 5 - 5
src/bridge/StargateClient.ts

@@ -45,15 +45,15 @@ export class StargateClient {
   }
 
   async bridge(toChainId: number) {
-    const routerEth = RouterETH__factory.connect(chainInfoMap[this.chainId].ethRouterAddress, this.wallet)
-    const lzGasCost = await this.getL0GasCost(toChainId)
-    const { gasCost, gasPrice, gasLimit } = await this.calculateGasCost(toChainId, routerEth, lzGasCost)
-    let cost = gasCost
-    let limit = gasLimit
     return await polly()
       .waitAndRetry([1000 * 60, 1000 * 60 * 2, 1000 * 60 * 3])
       .executeForPromise(async info => {
         try {
+          const routerEth = RouterETH__factory.connect(chainInfoMap[this.chainId].ethRouterAddress, this.wallet)
+          const lzGasCost = await this.getL0GasCost(toChainId)
+          const { gasCost, gasPrice, gasLimit } = await this.calculateGasCost(toChainId, routerEth, lzGasCost)
+          let cost = gasCost
+          let limit = gasLimit
           const balance = await this.provider.getBalance(this.wallet.address)
           // the cost is not precisely calculated, should be sufficient for common L2s
           if (balance < gasCost + lzGasCost) throw new Error('Insufficient balance')