Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow simulating batch transactions #469

Open
efstajas opened this issue Mar 15, 2023 · 3 comments
Open

Allow simulating batch transactions #469

efstajas opened this issue Mar 15, 2023 · 3 comments

Comments

@efstajas
Copy link

efstajas commented Mar 15, 2023

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.

@mmv08
Copy link
Member

mmv08 commented Mar 15, 2023

Would it be possible to expose the ability to simulate a batch of transactions with the Safe SDK, and receive a gas estimate?

Currently, we don't have plans to expose this in the developer tools.

The Safe has a built-in functionality useful for your case:
https://github.com/safe-global/safe-contracts/blob/main/contracts/accessors/SimulateTxAccessor.sol

@efstajas
Copy link
Author

efstajas commented Mar 15, 2023

Hey @mikhailxyz, thanks a lot for your response, understood.

That simulate function you linked looks like it could do exactly what we need, but I'm not sure where to start. Do I understand correctly that we could simulate a call against this function with the same batch data we'd later submit to safeAppsSdk.txs.send to get a gas estimate for the entire batch? How would I go about encoding my batch as calldata for simulate? A quick pointer in the right direction would be much appreciated 🙌

@mshakeg
Copy link

mshakeg commented Dec 5, 2023

would appreciate if the sdk could expose a method of the Safe class to simulate a transaction using the SimulateTxAccessor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants