flashbots / ethers-provider-flashbots-bundle

Flashbots provider for ethers.js
543 stars 212 forks source link

signBundle bundle used too little gas #74

Open maooricio opened 2 years ago

maooricio commented 2 years ago

Hi, well I don't know if this provider is only for transfers transactions, if so, my question doesn't have a point. But, if this module was built to support contract interactions so I want to know if I am doing something wrong. I have the following code:

const GWEI = 10n ** 9n
const CHAIN_ID = 5
const FLASHBOTS_ENDPOINT = 'https://relay-goerli.flashbots.net'
const provider = new providers.InfuraProvider('goerli', process.env.INFURA_API_KEY)
const signer = Wallet.createRandom()
const flashbot = await FlashbotsBundleProvider.create(provider, signer, FLASHBOTS_ENDPOINT)
const valueToSendParsed = utils.parseEther('0.01')
const encodedData = '0x7ff36ab500000000000000000000000000000000000000000000000016498f36d4b30300000000000000000000000000000000000000000000000000000000000000008000000000000000000000000054a1c450e8cf7dcde904aa9340375ced46d1cc8c00000000000000000000000000000000000000000000000000000180b94bcbd00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d60000000000000000000000009fffb5a9f5c6a55fa802318ff49936e672399b56'

const signedTx = await flashbot.signBundle([
      {
        signer: wallet,
        transaction: {
          chainId: CHAIN_ID,
          // EIP 1559 transaction
          type: 2,
          value: valueToSendParsed,
          data: encodedData,
          maxFeePerGas: GWEI * 3n,
          maxPriorityFeePerGas: GWEI * 2n,
          gasLimit: 300000,
          to: process.env.ROUTER_CONTRACT_ADDRESS
        }
      }
   ])

The method signBundle always return body="{\"error\":{\"message\":\"bundle used too little gas, must use at least 42000\"}}", no matter if I increase the gas limit of the transaction. The data of the transaction is a swap of a DEX router. What am I doing wron? In advance thanks

a180024 commented 2 years ago

Having the same issue, were you able to solve it?

maooricio commented 2 years ago

No yet, I am still waiting for an answer

a180024 commented 2 years ago

was an error on my side, i didn't have enough funds for swapping

maooricio commented 2 years ago

It worked to you? If so, would you please share your code in order to see what is wrong with mine? Or do you see something wrong in the code that I shared?

a180024 commented 2 years ago

variable names might be hard to see but generally the same other than maxPriorityFeePerGas and maxFeePerGas. what went wrong for me was i didn't have enough funds in the separate swap contract i was using

  const baseFeePerGas = block.baseFeePerGas; 
  const maxBaseFeePerGas = FlashbotsBundleProvider.getMaxBaseFeeInFutureBlock(
    baseFeePerGas,
    1
  );