Shawn Lu преди 1 година
родител
ревизия
d0b186ace7
променени са 1 файла, в които са добавени 5 реда и са изтрити 5 реда
  1. 5 5
      src/bridge/StargateClient.ts

+ 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')