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

chore: handle failed tx execution #153

Merged
merged 3 commits into from
Apr 8, 2024

Conversation

cbrzn
Copy link
Contributor

@cbrzn cbrzn commented Apr 8, 2024

this PR aims to show the error thrown from contract, instead of showing the entire logs

example:
send transfer without enough balance
image

swap token without enough balance
image

this is a first iteration, i am thinking how we might improve this... i tried to do an LLM call passing the error but it might not be very efficient

@cbrzn cbrzn requested review from dOrgJelli and nerfZael April 8, 2024 18:03
@nerfZael
Copy link
Contributor

nerfZael commented Apr 8, 2024

IMO we should add console colors in another PR

self.manager.send_tx_batch(self.transactions, require_approval=not non_interactive)
try:
self.manager.send_tx_batch(self.transactions, require_approval=not non_interactive)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this if we have the other catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah - otherwise the error shows like this:

Batched transactions:
1. Transfer 1000 USDC to vitalik.eth(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045) (nonce: 8)
Do you want to execute the above transactions? (y/n): y
Executing transactions...
Traceback (most recent call last):
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/safe/safe.py", line 819, in estimate_tx_gas
    self.estimate_tx_gas_by_trying(to, value, data, operation)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/safe/safe.py", line 760, in estimate_tx_gas_by_trying
    gas_estimated = self.estimate_tx_gas_with_safe(to, value, data, operation)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/safe/safe.py", line 716, in estimate_tx_gas_with_safe
    return parse_revert_data(
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/safe/safe.py", line 673, in parse_revert_data
    raise CannotEstimateGas("Received %s for tx=%s" % (result.hex(), tx))
gnosis.safe.exceptions.CannotEstimateGas: Received 0x for tx={'value': 0, 'chainId': 1, 'from': '0x4eB0b19553A892589CF21aAB9A22E82188EE90bA', 'gas': 0, 'gasPrice': 0, 'to': '0x4eB0b19553A892589CF21aAB9A22E82188EE90bA', 'data': '0xc4ca3a9c000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/safe/safe.py", line 732, in estimate_tx_gas_with_web3
    return self.ethereum_client.estimate_gas(
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/eth/ethereum_client.py", line 1497, in estimate_gas
    return self.w3.eth.estimate_gas(tx, block_identifier=block_identifier)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/web3/eth/eth.py", line 316, in estimate_gas
    return self._estimate_gas(transaction, block_identifier, state_override)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/web3/module.py", line 75, in caller
    result = w3.manager.request_blocking(
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/web3/manager.py", line 329, in request_blocking
    return self.formatted_response(
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/web3/manager.py", line 290, in formatted_response
    apply_error_formatters(error_formatters, response)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/web3/manager.py", line 103, in apply_error_formatters
    formatted_resp = pipe(response, error_formatters)
  File "cytoolz/functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/web3/_utils/error_formatters_utils.py", line 162, in raise_contract_logic_error_on_revert
    raise ContractLogicError(message, data=data)
web3.exceptions.ContractLogicError: ('execution reverted: revert: ERC20: transfer amount exceeds balance', '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002645524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63650000000000000000000000000000000000000000000000000000')

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

Traceback (most recent call last):
  File "/home/cesar/dev/polywrap/auto-tx/autotx/utils/ethereum/SafeManager.py", line 157, in execute_tx
    safe_tx = self.build_tx(tx, safe_nonce)
  File "/home/cesar/dev/polywrap/auto-tx/autotx/utils/ethereum/SafeManager.py", line 147, in build_tx
    safe_tx.safe_tx_gas = self.safe.estimate_tx_gas(safe_tx.to, safe_tx.value, safe_tx.data, safe_tx.operation)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/safe/safe.py", line 824, in estimate_tx_gas
    self.estimate_tx_gas_with_web3(to, value, data)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/gnosis/safe/safe.py", line 736, in estimate_tx_gas_with_web3
    raise CannotEstimateGas(
gnosis.safe.exceptions.CannotEstimateGas: Cannot estimate gas with `eth_estimateGas`: ('execution reverted: revert: ERC20: transfer amount exceeds balance', '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002645524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63650000000000000000000000000000000000000000000000000000')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/cesar/dev/polywrap/auto-tx/autotx/utils/ethereum/SafeManager.py", line 274, in send_tx_batch
    self.send_tx(prepared_tx.tx, start_nonce + i)
  File "/home/cesar/dev/polywrap/auto-tx/autotx/utils/ethereum/SafeManager.py", line 223, in send_tx
    hash = self.execute_tx(tx, safe_nonce)
  File "/home/cesar/dev/polywrap/auto-tx/autotx/utils/ethereum/SafeManager.py", line 173, in execute_tx
    raise ExecutionRevertedError(extracted_message.group(0))
autotx.utils.ethereum.SafeManager.ExecutionRevertedError: revert: ERC20: transfer amount exceeds balance'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/bin/ask", line 6, in <module>
    sys.exit(run())
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/cesar/.cache/pypoetry/virtualenvs/autotx-qxA8drhO-py3.10/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/cesar/dev/polywrap/auto-tx/autotx/cli.py", line 72, in run
    autotx.run(prompt, non_interactive)
  File "/home/cesar/dev/polywrap/auto-tx/autotx/AutoTx.py", line 80, in run
    self.manager.send_tx_batch(self.transactions, require_approval=not non_interactive)
  File "/home/cesar/dev/polywrap/auto-tx/autotx/utils/ethereum/SafeManager.py", line 276, in send_tx_batch
    raise Exception(f"{prepared_tx.summary} failed with error: {e}")
Exception: Transfer 1000 USDC to vitalik.eth(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045) failed with error: revert: ERC20: transfer amount exceeds balance'

@cbrzn
Copy link
Contributor Author

cbrzn commented Apr 8, 2024

IMO we should add console colors in another PR

added! now it look like this:
image

@cbrzn cbrzn requested a review from nerfZael April 8, 2024 19:46
@nerfZael nerfZael merged commit bfb916e into nerfzael/autogen Apr 8, 2024
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

Successfully merging this pull request may close these issues.

2 participants