Code Monkey home page Code Monkey logo

Comments (6)

zdenham avatar zdenham commented on June 1, 2024

Gas estimation continues to be an issue on optimism for us. We will likely need to move away from Hop as a result unfortunately

from hop.

miguelmota avatar miguelmota commented on June 1, 2024

The reason for the hardcoded limit is because the transaction fails due to ethers estimating too low (example txs 1, 2).

You can however specify your own gas limit or let ethers estimate it for you. Example:

const { Hop } = require('@hop-protocol/sdk')
const ethers = require('ethers')
require('dotenv').config()

async function main() {
  const hop = new Hop('mainnet')
  const privateKey = process.env.PRIVATE_KEY
  const provider = new ethers.providers.getDefaultProvider('mainnet')
  const signer = new ethers.Wallet(privateKey, provider)
  const bridge = hop.connect(signer).bridge('ETH')

  const txData = await bridge.populateSendTx(ethers.utils.parseUnits('0.01', 18), 'ethereum', 'optimism')

  // txData.gasLimit = 150_000 // your own custom gas limit
  delete txData.gasLimit // let ethers estimate gas limit
  console.log(txData)

  const tx = await signer.sendTransaction(txData)
  console.log(tx)
}

main().catch(console.error)

We're planning on removing the hardcoded value once the rpc providers return a more reliable gas limit for Optimism and Base, since currently it fails with estimated gas limit and users aren't able to perform transfers.

from hop.

zdenham avatar zdenham commented on June 1, 2024

I see, thank you for the response--will give this a whirl. Previously we had modified the code to use the gas estimation from populateSendTx but were running into the underestimate of gas limit like you mentioned, interesting that the underlying issue is ethers.

500000 though was too high for us because we were trying to do a full sweep of max native ether, anecdotally 170000 seems to be a more reasonable hardcoded limit at least for OP

from hop.

zdenham avatar zdenham commented on June 1, 2024

Even when using the above approach, sending the transaction always fails with:

Error: insufficient funds for intrinsic transaction cost [ See: https://links.ethers.org/v5-errors-INSUFFICIENT_FUNDS ] (error={"rawMessage":"Error forwarded from node: insufficient funds for gas * price + value: balance 3390584819344368, tx cost 8351900601944368, overshot 4961315782600000","code":-32603,"message":"Magic RPC Error: [-32603] Error forwarded from node: insufficient funds for gas * price + value: balance 3390584819344368, tx cost 8351900601944368, overshot 4961315782600000"}, method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS, version=providers/5.7.0)

When trying to do a full sweep... it seems something about the bridge transaction causes ethers to overestimate the txn cost and return early (before even submitting to the network where it would presumably fail)

from hop.

zdenham avatar zdenham commented on June 1, 2024

Actually, once we also specified other gas parameters such as maxFeePerGas and maxPriorityFeePerGas which aligned with our gas estimation it started working.

The issue seemed to be with gas spiking as the txn was submitted.

from hop.

zdenham avatar zdenham commented on June 1, 2024

Thanks for the support!

from hop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.