ApeWorX / ape-safe

Safe (Wallet) account plugin for the Ape Framework
https://www.apeworx.io/
Apache License 2.0
14 stars 8 forks source link

Ape cannot compute gas cost estimation if Safe has zero balance #36

Closed fubuloubu closed 8 months ago

fubuloubu commented 8 months ago

Environment information

$ ape --version
0.7.9

$ ape plugins list
Installed Plugins
  alchemy      0.7.1
  arbitrum     0.7.2
  etherscan    0.7.1
  foundry      0.7.3
  infura       0.7.1
  ledger       0.7.0
  optimism     0.7.2
  safe         0.7.0b1
  tokens       0.7.1

What went wrong?

I am trying to execute a transaction directly on a public network using the Safe plugin (but aiming to publish to the Safe API only)

  File "site-packages/ape_ethereum/provider.py", line 249, in estimate_gas_cost
    return self.web3.eth.estimate_gas(txn_params, block_identifier=block_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/web3/eth/eth.py", line 312, in estimate_gas
    return self._estimate_gas(transaction, block_identifier)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/web3/module.py", line 75, in caller
    result = w3.manager.request_blocking(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/web3/manager.py", line 326, in request_blocking
    return self.formatted_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/web3/manager.py", line 289, in formatted_response
    raise ValueError(error)
ValueError: {'code': -32000, 'message': 'insufficient funds for transfer'}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "script.py", line 38, in foo
    contract.methodName(sender=safe, submit_transaction=False)
  File "site-packages/ape/contracts/base.py", line 356, in __call__
    return contract_transaction(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/ape/contracts/base.py", line 290, in __call__
    return kwargs["sender"].call(txn, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "site-packages/ape_safe/accounts.py", line 531, in call
    return super().call(txn, **call_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/ape/api/accounts.py", line 125, in call
    txn = self.prepare_transaction(txn)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/ape_safe/accounts.py", line 462, in prepare_transaction
    return self.provider.prepare_transaction(txn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/ape_ethereum/provider.py", line 861, in prepare_transaction
    gas = self.estimate_gas_cost(txn)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/ape_ethereum/provider.py", line 259, in estimate_gas_cost
    raise TransactionError(
ape.exceptions.TransactionError: Gas estimation failed: 'insufficient funds for transfer'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

How can it be fixed?

I believe the root cause to be that the Safe I am using to execute has zero balance, leading web3py to fail when calling eth_estimateGas. Some effort to bypass this behavior or override the balance of the contract could help assist in properly determining the gas cost it would take.

linear[bot] commented 8 months ago

APE-1688 Ape cannot compute gas cost estimation if Safe has zero balance