Prechádzať zdrojové kódy

check balance before

Shawn Lu 1 rok pred
rodič
commit
8e38a45141
2 zmenil súbory, kde vykonal 6 pridanie a 3 odobranie
  1. 5 2
      src/bridge/StargateClient.ts
  2. 1 1
      src/config/chain.ts

+ 5 - 2
src/bridge/StargateClient.ts

@@ -45,17 +45,20 @@ export class StargateClient {
   }
 
   async bridge(toChainId: number) {
-    if(toChainId === ChainId.ZKSYNC) throw new Error('Unsupported.')
+    if (toChainId === ChainId.ZKSYNC) throw new Error('Unsupported.')
     return await polly()
       .waitAndRetry([1000 * 10, 1000 * 20, 1000 * 30, 1000 * 40])
       .executeForPromise(async info => {
         try {
+          const balance = await this.provider.getBalance(this.wallet.address)
+          if (balance < ethers.parseEther('0.001')) {
+            throw new Error('Insufficient balance')
+          }
           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')
           if (info.count > 0) {

+ 1 - 1
src/config/chain.ts

@@ -52,7 +52,7 @@ export const chainInfoMap: { [chainId: number]: ChainInfo } = {
   [ChainId.BASE]: {
     name: 'Base',
     chainId: 184,
-    rpcUrl: 'https://mainnet.base.org',
+    rpcUrl: 'https://1rpc.io/base',
     feeAddress: '0x9d1b1669c73b033dfe47ae5a0164ab96df25b944',
     routerAddress: '0x45f1a95a4d3f3836523f5c83673c797f4d4d263b',
     ethRouterAddress: '0x50B6EbC2103BFEc165949CC946d739d5650d7ae4',