1

I have a counterfactual Safe ( v 1.3.0 ) , where funds have been already sent (ERC-20 token). I want to relay a transaction where

  1. Safe is being deployed
  2. funds are moved out of it

Transaction will be a multitx, meaning that within one call the Safe is deployed and funds are moved.

Since I'm going to relay the transaction, I want to provide the end user with a quote for it. If he accepts it, I then collect the necessary signature to move funds out, and execute the transaction.

To estimate the gas, I could technically use stateDiff to manipulate Safe storage when calling eth_estimateGas on the RPC node. The problem is I've figured it out that, since the Safe is not yet deployed, the stateDiff has no effect.

Any ideas or hacks on how to solve this problem?

I was thinking of simulate to separate transaction in a row, but haven't found out if that's possible with a standard RPC node. I know this won't give a super accurate estimation, but still will give a good approximation (< 10% error).

1 Answer 1

0

In the safe-wallet web UI we do something similar:

This estimation is done by calling eth_estimateGas with a MultiSendCallOnly batch transaction that

  1. Calls the SafeProxyFactory to deploy the SafeProxy
  2. Call the simulate function on the now deployed SafeProxy with the first transaction data. Then we substract a flat gas amount for the overhead of simulating the transaction.

You can view the code here: https://github.com/safe-global/safe-wallet-web/blob/d21ddd994ef6c904121ce633a44b5070285c7a4c/src/features/counterfactual/hooks/useDeployGasLimit.ts#L59

Maybe this would give you some ideas?

1
  • Thanks for the answer! You mean the simulateAndRevert function? Cause the simulate one is available in the 4337 compatible version of Safe, correct? We thought of simulateAndRevert, but we need to make multiple transfers on the same call (using multi sender), so if one reverts, then all the others are not executed.
    – 70ny
    Mar 28 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.