Bläddra i källkod

wait for confirmation when bridging, retry immediately if out of gas

Shawn Lu 1 år sedan
förälder
incheckning
e78048709f
2 ändrade filer med 5 tillägg och 16 borttagningar
  1. 5 1
      src/bridge/StargateClient.ts
  2. 0 15
      src/jobs/ConfirmJob.ts

+ 5 - 1
src/bridge/StargateClient.ts

@@ -70,6 +70,10 @@ export class StargateClient {
             minReceiveAmount,
             { value: sendAmount + lzGasCost, gasLimit, gasPrice },
           )
+          const receipt = await res.wait()
+          if (!receipt.status) {
+            throw new Error('Transaction reverted')
+          }
           return res.hash
         } catch (e) {
           StargateClient.logger.error(e.message, `Failed to bridge to ${toChainId}`)
@@ -92,7 +96,7 @@ export class StargateClient {
         value: amount + lzGasCost,
       },
     )
-    const gasCost = ((this.chainId === 110 ? gasPrice : ethers.parseUnits('0.5', 'gwei')) * gasLimit * 110n) / 100n
+    const gasCost = ((this.chainId === 110 ? gasPrice : ethers.parseUnits('0.55', 'gwei')) * gasLimit * 110n) / 100n
     return { gasCost, gasPrice, gasLimit }
   }
 }

+ 0 - 15
src/jobs/ConfirmJob.ts

@@ -52,21 +52,6 @@ export class ConfirmJob extends CronJob {
           }),
         ])
       } else {
-        // check tx status
-        const res = await targetProvider.getTransactionReceipt(task.txHash)
-        // if reverted
-        if (res && !res.status) {
-          await DBClient.instance.task.update({
-            where: {
-              id: task.id,
-            },
-            data: {
-              status: 'FAILED',
-              description: `transaction reverted`,
-            },
-          })
-          return
-        }
         if (task.executeTime < new Date(Date.now() - 2 * 60 * 60 * 1000)) {
           // if execute time is earlier than 2 hours ago, consider the bridge is probably failed
           await DBClient.instance.task.update({