uniswap-python
The unofficial Python client for Uniswap.
Documentation is available at https://uniswap-python.com/
Functionality
- A simple to use Python wrapper for all available contract functions and variables
- A basic CLI to get prices and token metadata
- Simple parsing of data returned from the Uniswap contract
Supports
- Uniswap v4 (as of v0.8.0, beta) - Swaps, price quoting, liquidity management - Pool discovery via pool cache service - Uniswap v3 (as of v0.5.0) - Including beta support for Arbitrum & Optimism deployments (as of v0.5.4) - Uniswap v2 (as of v0.4.0) - Uniswap v1 (deprecated) - Various forks (untested, but should work) - Honeyswap (xDai) - Pancakeswap (BSC) - Sushiswap (mainnet)
Getting Started
See our Getting started guide in the documentation.
Testing
Unit tests are under development using the pytest framework. Contributions are welcome!
Tests run on a fork of mainnet using Anvil (part of Foundry). Install Foundry with:
curl -L https://foundry.paradigm.xyz | bash
export PATH="$PATH:$HOME/.foundry/bin"
foundryup
To run the full test suite, in the project directory set the PROVIDER env variable to a mainnet provider, and run:
poetry install
export PROVIDER= # URL of provider, e.g. https://mainnet.infura.io/v3/...
make test
or...
poetry run pytest --capture=no # doesn't capture output (verbose)
Funding
Development of this library has been funded by:
- The Uniswap Grants Program, which awarded a $15k grant (2021) that funded the development of Uniswap v3 support.
- Community donations through Gitcoin Grants, which were used to compensate contributors (see #181).
- Superuser Labs, Erik's company, which has sponsored continued development and maintenance, including funding @liquid-8's work on Uniswap v4 support.
Authors
Contributors also earn this beautiful GitPOAP for their contributions!Changelog
_0.9.0_
- Added: Async versions of Uniswap V2-V4
- Added: V2 and V3 custom routes (untested)
- Added: Async pool cache service for Uniswap V4
- Removed: V1 support
- Added: Uniswap V4 support
- Added: Pool cache service for Uniswap V4
- Full parameters customization for V4 transactions; V4 transaction replacement and cancelling.
- Updated: Default fee is not applied when using Uniswap V3. Default fee for Uniswap V1 and V2 is still 0.3%.
- Updated:
InvalidFeeTierexception is raised when a tier is not supported by the protocol version. See all supported tiers inuniswap.fee.FeeTier
- incomplete changelog
- incomplete changelog
- added use of gas estimation instead of a fixed gas limit (to support Arbitrum)
- added
use_estimate_gasconstructor argument (used in testing) - added constants/basic support for Arbitrum, Optimism, Polygon, and Fantom. (untested)
- incomplete changelog
- incomplete changelog
- incomplete changelog
- Updated dependencies
- Fixed minor typing issues
- Basic support for Uniswap V3
- Added new methods
get_price_inputandget_price_output - Made a lot of previously public methods private
- Added documentation site
- Removed ENS support (which was probably broken to begin with)
- Bug fix: Update bleach package from 3.1.4 to 3.3.0
- Bug fix: Use .eth instead of .ens
- General: Add new logo for Uniswap V2
- Bug fix: Invalid balance check (#25)
- Bug fix: Fixed error when passing WETH as token
- Allow kwargs in
approveddecorator.
- Add note about Uniswap V2 support
- Update changelog for PyPi and clean up
_A huge thank you Erik Bjäreholt for adding Uniswap V2 support, as well as all changes in this version!_
- Added support for Uniswap v2
- Handle arbitrary tokens (by address) using the factory contract
- Switched from setup.py to pyproject.toml/poetry
- Switched from Travis to GitHub Actions
- For CI to work in your repo, you need to set the secret MAINNET_PROVIDER. I use Infura.
- Running tests on a local fork of mainnet using Anvil/Foundry (started as a fixture)
- Fixed tests for make_trade and make_trade_output
- Added type annotations to the entire codebase and check them with mypy in CI
- Formatted entire codebase with black
- Moved stuff around such that the basic import becomes from uniswap import Uniswap (instead of from uniswap.uniswap import UniswapWrapper)
- Fixed misc bugs
- Provide token inputs as addresses instead of names
- Add ability to transfer tokens after a trade
- Add tests for this new functionality
- Add tests for all types of trades
- Add ability to make all types of trades
- Add example to README
- Add liquidity tests
- Add liquidity and ERC20 pool methods
- Major README update
- Add market endpoints
- Add tests for market endpoints