ape icon indicating copy to clipboard operation
ape copied to clipboard

feat: detect uniswap v3 pools

Open banteg opened this issue 10 months ago • 3 comments

What I did

unfinished, the goal is:

  • automatically detect uniswap v3 pools and instantiate them with a proper abi

im not sure where to put it, it's not really a proxy type and the ecosystem doesn't provide a hook for loading contracts. up to ape maintainers to decide how to best integrate that.

How I did it

  • vendor uniswap v3 factory and pool abis
  • add a helper to check that bytecode contains all method selectors of the pool but none of the selectors of the factory (otherwise factory would be falsely detected as a pool since it contains the pool deployment code)

How to verify it

Contract('0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640') should work the same as the first verified pool Contract('0x1d42064Fc4Beb5F8aAF85F4617AE8b3b5B8Bd801')

Checklist

  • [ ] All changes are completed
  • [ ] New test cases have been added
  • [ ] Documentation has been updated

banteg avatar Apr 04 '24 12:04 banteg

so i've looked into this and the best tool i found is evmole https://github.com/cdump/evmole

it's really simple with no external deps and accurate as it runs a minimal evm than only reads the dispatch table.

it was faster and more precise than my home-cooked solution based on disassembly, pattern matching and filtering by valid jumpdests.

i suggest we use evmole as an optional dependency to detect some bundled contract types where abis are not returned from the explorer plugin.

now, i just need a hook where to put it when loading a contract. the check is similar in nature to how we do proxy detection (we just need the code), but we need a way to short-circuit it and return an abi type before it hits the explorer plugin.

import evmole
pool = Contract('0x1d42064Fc4Beb5F8aAF85F4617AE8b3b5B8Bd801')
factory = Contract(pool.factory())
evmole.function_selectors(factory.code)
# ['89035730', '8a7c195f', '8da5cb5b', 'a1671295', '13af4035', '1698ee82', '22afcccb']
evmole.function_selectors(pool.code)
# ['883bdbfd', 'a34123a7', 'a38807f2', '70cf754a', '8206a4d1', '85b66729', 'c45a0155', 'd0c93a7c', 'd21220a7', 'ddca3f43', 'f3058399', 'f30dba93', 'f637731d', '490e6cbc', '4f1eb3d8', '514ea4bf', '5339c296', '3850c7bd', '3c8a7d8d', '46141319', '1ad8b03b', '252c09d7', '32148f67', '0dfe1681', '128acb08', '1a686502']
# demonstrating that it didn't catch the dispatch table from the child contract stored in the factory
set(evmole.function_selectors(factory.code)) & set(evmole.function_selectors(pool.code))
# set()

banteg avatar Apr 08 '24 10:04 banteg

This pull request is considered stale because it has been open 30 days with no activity. Remove stale label, add a comment, or make a new commit, otherwise this PR will be closed in 5 days.

github-actions[bot] avatar May 09 '24 01:05 github-actions[bot]

Had an idea that an evmole ExplorerAPI plugin might be cool, or at least after the major refactor we want to do with the contract system where it becomes a QueryAPI type instead (so we can merge multiple sources of contract data)

Have some sort of independent confidence evaluation that triggers whether it can do the query or not

fubuloubu avatar May 09 '24 02:05 fubuloubu

This pull request is considered stale because it has been open 30 days with no activity. Remove stale label, add a comment, or make a new commit, otherwise this PR will be closed in 5 days.

github-actions[bot] avatar Jun 09 '24 01:06 github-actions[bot]

This PR was closed because it has been inactive for 35 days.

github-actions[bot] avatar Jun 15 '24 01:06 github-actions[bot]