|
@@ -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) {
|