What we are most concerned about is transactions don't fail due to lack of gas. Forcing users to set gas limit a bit high and getting a bigger gas refund than expected is not too big of a deal.
This shit is hard since a different state variable can cause a contract to go down a different code path, making transaction costs wildly different. One solution to this problem is to simulate across many blocks, not just the most recent block.
There's a eth_estimateUserOperationGas
that in theory should solve this issue for us. However, if this is not a supported endpoint for the rpc provider and chain we are using, then this will be a big problem. Pimlico needs to support every chain we support for us to be able to use them as a bundler
Gas is three parts:
Create an accurate estimate gas function. We don't care about the gas price, we just want to set the gas limit barely high enough to get the transaction to succeed
Sometimes gas estimation fails on the first check
Gas estimation issue:
Gas estimation fails on polygon.
Current solution is to manually bump up the contract gas limit if the transaction is on polygon
Sometimes gas estimation fails on arbitrum
The likely problems to this solution(unless we want to do our own rewrite), is to get a list of all all bundlers for every network and test with them to get the best for each network. Sometimes when we get bad results, this is just because we have an incorrect combination of bundler JsonRpcProvider URL, chain Id, userOp, and entrypoint address
Get list of all bundlers
We are currently using the pimlico bundler