Discover more from Degen Code
Uniswap V3 Bot — Bugfixes (Part II)
This is a short post detailing one bug fix for the Uniswap V3 bot.
I will release periodic posts like this as I identify and fix bugs. Thank you for reporting issues!
I reported and fixed an issue in the flashbots web3py middleware a few months ago. That fix has now made it into the latest stable version of web3-flashbots on PyPi (the repository that
pip uses to install Python packages).
The issue I fixed was that the argument
state_block_tag was treated inconsistently. If passed directly, it assumed the value was already a hex-encoded block number, despite the type hint being
int. My fix simply aligned the behavior inside the method with the type hint with an inline conversion.
However not everyone was using a git-synced version of the module, so I published my bot with a workaround that pre-converted the state block to hex before passing it to
This was all good for a while, but the workaround now causes issues with the updated version!
You may have already noticed this exception:
TypeError: Unsupported type: The primitive argument must be one of: bytes,bytearray, int or bool and not str
This is thrown because web3py is attempting to convert a hex string to a hex number, which fails.
Fortunately the fix is simple. If you are running the newer version of the
flashbots Python module (1.1.0) and getting this error, change the two similar code blocks in the function
execute_arb_with_relay from this:
simulation = w3.flashbots.simulate( bundled_transactions=bundle, state_block_tag=w3.toHex(state_block), block_tag=target_block, block_timestamp=newest_block_timestamp + AVERAGE_BLOCK_TIME, )
simulation = w3.flashbots.simulate( bundled_transactions=bundle, state_block_tag=state_block, block_tag=target_block, block_timestamp=newest_block_timestamp + AVERAGE_BLOCK_TIME, )