Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ on:
env:
# The repo secret still points at a rate-limited Infura URL, so CI must use
# the public endpoint directly instead of preferring the secret on push runs.
PROVIDER_MAINNET: 'https://ethereum.publicnode.com'
#PROVIDER_MAINNET: 'https://ethereum.publicnode.com'
PROVIDER_MAINNET: 'https://eth.drpc.org'
PROVIDER_ARBITRUM: 'https://arb1.arbitrum.io/rpc'
PROVIDER_XDAI: 'https://rpc.ankr.com/gnosis'

Expand All @@ -20,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
uniswap-version: [1, 2, 3, 4]
uniswap-version: [2, 3, 4]
network: ["mainnet"]
# include:
# - network: arbitrum
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ Contributors also earn this beautiful [GitPOAP](https://gitpoap.notion.site/What

## 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

_0.8.0_

* Added: Uniswap V4 support
Expand Down
16 changes: 7 additions & 9 deletions examples/price_impact.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from typing import List

from web3 import Web3

from uniswap import Uniswap
from uniswap.types import AddressLike

eth = Web3.toChecksumAddress("0x0000000000000000000000000000000000000000")
weth = Web3.toChecksumAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
usdt = Web3.toChecksumAddress("0xdac17f958d2ee523a2206206994597c13d831ec7")
vxv = Web3.toChecksumAddress("0x7d29a64504629172a429e64183d6673b9dacbfce")
eth = Web3.to_checksum_address("0x0000000000000000000000000000000000000000")
weth = Web3.to_checksum_address("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
usdt = Web3.to_checksum_address("0xdac17f958d2ee523a2206206994597c13d831ec7")
vxv = Web3.to_checksum_address("0x7d29a64504629172a429e64183d6673b9dacbfce")


def _perc(f: float) -> str:
Expand All @@ -23,7 +21,7 @@ def usdt_to_vxv_v2():
"""
uniswap = Uniswap(address=None, private_key=None, version=2)

route: List[AddressLike] = [usdt, weth, vxv]
route: list[AddressLike] = [usdt, weth, vxv]

# Compare the results with the output of:
# https://app.uniswap.org/#/swap?use=v2&inputCurrency=0xdac17f958d2ee523a2206206994597c13d831ec7&outputCurrency=0x7d29a64504629172a429e64183d6673b9dacbfce
Expand All @@ -32,14 +30,14 @@ def usdt_to_vxv_v2():
# price = uniswap.get_price_input(usdt, vxv, qty, route=route) / 10 ** 18
# print(price)

impact = uniswap.estimate_price_impact(usdt, vxv, qty, route=route)
impact = uniswap.estimate_price_impact(usdt, vxv, qty, fee=3000, route=route)
# NOTE: Not sure why this differs from the quote in the UI?
# Getting -27% in the UI for 10 USDT, but this returns >95%
# The slippage for v3 (in example below) returns correct results.
print(f"Impact for buying VXV on v2 with {qty / 10**8} USDT: {_perc(impact)}")

qty = 13900 * 10**8
impact = uniswap.estimate_price_impact(usdt, vxv, qty, route=route)
impact = uniswap.estimate_price_impact(usdt, vxv, qty, fee=3000, route=route)
print(f"Impact for buying VXV on v2 with {qty / 10**8} USDT: {_perc(impact)}")


Expand Down
12 changes: 6 additions & 6 deletions examples/v4_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def pool_tests():
first_block = 21688329
print("Testing fetch_poolkey_data()...")
try:
v4pools_test.fetch_poolkey_data(first_block, chunk_size=500, clear_list=False)
v4pools_test.fetch_poolkey_data(first_block, chunk_size=5, clear_list=False)
print("Test passed.")
except Exception as e:
print(f"Test failed. {e}")
Expand Down Expand Up @@ -90,9 +90,9 @@ def quoter_tests():
test_pool2_tick_spacing,
default_test_hooks,
)
test_path_1hop = list()
test_path_1hop: list = []
test_path_1hop.append(test_pool_key1)
test_path_2hop = list()
test_path_2hop: list = []
test_path_2hop.append(test_pool_key1)
test_path_2hop.append(test_pool_key2)

Expand Down Expand Up @@ -592,9 +592,9 @@ def swap_tests():
test_pool2_tick_spacing,
default_test_hooks,
)
test_path_1hop = list()
test_path_1hop: list = []
test_path_1hop.append(test_pool_key1)
test_path_2hop = list()
test_path_2hop: list = []
test_path_2hop.append(test_pool_key1)
test_path_2hop.append(test_pool_key2)

Expand Down Expand Up @@ -923,7 +923,7 @@ def reserves_lens_tests():
print()
print()

# pool_tests()
pool_tests()
quoter_tests()
price_impact_tests()
state_view_tests()
Expand Down
1,032 changes: 578 additions & 454 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "uniswap-python"
version = "0.8.0" # this is automatically set in CI on tagged releases (before pushed to PyPI)
version = "0.9.0" # this is automatically set in CI on tagged releases (before pushed to PyPI)
description = "An unofficial Python wrapper for the decentralized exchange Uniswap"
repository = "https://github.com/shanefontaine/uniswap-python"
readme = "README.md"
Expand All @@ -24,7 +24,7 @@ unipy = "uniswap:main"

[tool.poetry.dependencies]
python = "^3.12"
web3 = ">=6.20.0,<7"
web3 = "^8.0.0"
cytoolz = ">=0.12.3"
frozenlist = ">=1.5.0"
multidict = ">=6.0.5"
Expand All @@ -41,9 +41,11 @@ setuptools = "<82"
[tool.poetry.dev-dependencies]
mypy = "*"
pre-commit = "*"
pytest = "^8"
pytest = "^8.4"
pytest-cov = "*"
pytest-dotenv = "*"
pytest-asyncio = "^1.4"

ruff = ">=0.9"
Sphinx = "^9"
sphinx-book-theme = "^1.1"
Expand Down
Loading
Loading