safe-apps-sdk icon indicating copy to clipboard operation
safe-apps-sdk copied to clipboard

Allow simulating batch transactions

Open efstajas opened this issue 1 year ago • 3 comments

We have an (admittedly rather unique) situation where one of our dapp's contract functions uses an amount of gas that varies slightly over time, because some of its internal logic is based on the current blockTimestamp. This results in a small chance of transactions randomly failing when relying on gas limits set by wallets simulating the TX ahead of time. For this reason, we manually simulate transactions in our app, and add a small 10% gas buffer on top, which prevents these randomly failing transactions.

We're now working on adding Safe App support to our app, and want to use the Safe Apps SDK's batching functionality to call approve on an ERC-20 and also our own contract's top-up function in one batch for better UX.

This poses a challenge, because we cannot simply simulate these two transactions manually, add the gas cost together, and pass this to the Safe SDK's safeTxGas parameter, because the 2nd transaction depends on the first — so simulating it ahead of time would simply fail.

Just omitting safeTxGas and relying on the Safe's automatic gas estimation also isn't an option, as the transaction could randomly fail for the reason outlined above.

I noticed that when proposing a batch to a Safe, you can click Simulate and it uses Tenderly's batch simulation functionality to simulate the entire batch and calculate a gas cost. I assume that this is how the Gnosis UI generally calculates gas costs for batches.

My feature request: Would it be possible to expose the ability to simulate a batch of transactions with the Safe SDK, and receive a gas estimate? This would allow us to simulate our batch of inter-dependent transactions ahead of time, add our 10% buffer, and then pass the transactions alongside our custom gas limit to the Safe SDK.

efstajas avatar Mar 15 '23 12:03 efstajas