New Features: Uniswap V4 Database Integration & Path Finding
Getting Ready for 0.5.0
I have published a new beta of degenbot, 0.5.0b4 which adds two key features.
Uniswap V4
The UniswapV4Pool class now performs a lookup from the database at construction time. If you have activated and updated either of the built-in exchanges (base_uniswap_v4 or ethereum_uniswap_v4), the class can skip many onchain calls needed to look up tokens, fee, tick spacing, etc.
Consequently many of the inputs to the construction are now optional. If you build a V4 pool that exists in the database, you only need to provide its pool manager address and pool ID. If you aren’t using the database, you can continue passing the values in as before.
Path Finding
I have also included an arbitrage path finding function find_paths(). It uses the database to discover pools and their tokens, then works through them to find pool paths in increasing depth.
This is a key unlock because it means that paths can be built during runtime, instead of needing to prebuild them with a separate script.
Here is an example of the simplest case, a two-pool cycle using some arbitrary profit token:
for arb_path in find_paths(
chain_id=8453,
start_token=WETH_ADDRESS,
end_token=WETH_ADDRESS,
max_depth=2,
):
for pool in arb_path:
# [create pools and build the arbitrage helper here]The path finding function also supports limiting the pools to a subset of types that identify the database types:
for arb_path in find_paths(
chain_id=8453,
start_token=WETH_ADDRESS,
end_token=WETH_ADDRESS,
max_depth=2,
pool_types=[
UniswapV2PoolTable,
UniswapV4PoolTable,
],
):
for pool in arb_path:
# [create pools and build the arbitrage helper here]This is very useful if you have a specialized contract that is specific to V4-V2 arbs like this one I shared:
It also accepts a list of equivalent tokens, for instance Ether & WETH. This is very useful for cases where an execution contract can perform wrapping and unwrapping in between pools. This example would find all paths that take the forms WETH-X → Ether→X and Ether-X → WETH-X:
for arb_path in find_paths(
chain_id=8453,
start_token=WETH_ADDRESS,
end_token=V4_NATIVE_ADDRESS,
max_depth=2,
equivalent_tokens=[(WETH_ADDRESS, V4_NATIVE_ADDRESS)],
):
for pool in arb_path:
# [create pools and build the arbitrage helper here]In the case of two equivalent profit tokens, the ordering of the inputs is arbitrary. Reversing the start and end works as expected and yields the same pools.
Currently the only supported paths are two-pool, but I am working on pools of arbitrary length and will include that in the coming stable release.
Talkin' 'bout My Generator
The function is a generator which must be consumed.
You can either loop through it using for or next, or capture all of the paths in a container (tuple, list, deque, etc). It’s simple enough once you’ve seen it, but don’t panic when a familiar operation like len(find_paths(…)) or find_paths(…)[0] fails.
The generator approach has two key benefits:
Path finding can start immediately — improving time-to-first-calculation
Memory use is minimized — each path is built and given directly to the consuming function instead of being held until the path search is complete
Final Release Soon
I’m pleased with the new features in testing, and have already retired my Cryo extraction and two-pool path finding scripts. After I convert the remaining path finding scripts for 3 or more tokens, it should be much simpler to manage and consolidate all of this stuff.
This should be the final beta release ahead of 0.5.0, so please report bugs if you find them.

