Skip to content

Commit

Permalink
feat: add universal router (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: banteg <4562643+banteg@users.noreply.github.com>
  • Loading branch information
fubuloubu and banteg authored Jul 26, 2024
1 parent d3d9c42 commit 4418bfd
Show file tree
Hide file tree
Showing 18 changed files with 1,129 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/commitlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"

- name: Install Dependencies
run: pip install .[dev]
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[release]
- name: Build
run: python setup.py sdist bdist_wheel

Expand Down
41 changes: 10 additions & 31 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"

- name: Install Dependencies
run: pip install .[lint]
Expand All @@ -30,12 +30,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"

- name: Install Dependencies
run: pip install .[lint,test] # Might need test deps
Expand All @@ -49,39 +49,18 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest] # eventually add `windows-latest`
python-version: [3.7, 3.8, 3.9]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: pip install .[test]

- name: Run Tests
run: pytest -m "not fuzzing" -n 0 -s --cov

# NOTE: uncomment this block after you've marked tests with @pytest.mark.fuzzing
# fuzzing:
# runs-on: ubuntu-latest
#
# strategy:
# fail-fast: true
#
# steps:
# - uses: actions/checkout@v2
#
# - name: Setup Python
# uses: actions/setup-python@v2
# with:
# python-version: 3.8
#
# - name: Install Dependencies
# run: pip install .[test]
#
# - name: Run Tests
# run: pytest -m "fuzzing" --no-cov -s
run: ape test -s
6 changes: 3 additions & 3 deletions .github/workflows/title.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"

- name: Install Dependencies
run: pip install commitizen
Expand Down
39 changes: 39 additions & 0 deletions ape-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# NOTE: We don't need this other than for copying over the manifests to build with the
# python package, and for testing

plugins:
# For compiling contracts
- name: solidity
# For fork testing
- name: foundry

dependencies:
- name: uniswap-v3
github: Uniswap/v3-core
ref: v1.0.0

- name: uniswap-v2
github: Uniswap/v2-core
ref: v1.0.1

- name: permit2
github: Uniswap/permit2
ref: main
config_override:
solidity:
via_ir: True # NOTE: Trouble compiling without this

- name: universal-router
github: Uniswap/universal-router
ref: v1.6.0
config_override:
dependencies:
- name: openzeppelin
github: OpenZeppelin/openzeppelin-contracts
ref: v4.7.0
solidity:
import_remapping:
- "permit2=permit2"
- "@uniswap/v3-core=uniswap-v3"
- "@uniswap/v2-core=uniswap-v2"
via_ir: True # NOTE: Trouble compiling without this
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ include = '\.pyi?$'

[tool.pytest.ini_options]
addopts = """
-n auto
-p no:ape_test
--cov-branch
--cov-report term
--cov-report html
--cov-report xml
--cov=<MODULE_NAME>
--cov=uniswap_sdk
"""
python_files = "test_*.py"
testpaths = "tests"
Expand All @@ -37,3 +35,6 @@ force_grid_wrap = 0
include_trailing_comma = true
multi_line_output = 3
use_parentheses = true

[tool.ruff]
line-length = 100
68 changes: 68 additions & 0 deletions scripts/update_manifests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from pathlib import Path

from ape import project
from ethpm_types import ContractType

PACKAGE_FOLDER = Path(__file__).parent.parent / "uniswap_sdk"


def clean_contract_type(contract_type):
clean_model_dict = contract_type.model_dump(
exclude={
"ast",
"deployment_bytecode",
"runtime_bytecode",
"source_id",
"pcmap",
"dev_messages",
"sourcemap",
"userdoc",
"devdoc",
"method_identifiers",
}
)
return ContractType.model_validate(clean_model_dict)


def clean_manifest(manifest, *contract_types_to_keep):
manifest.contract_types = {
k: clean_contract_type(v)
for k, v in manifest.contract_types.items()
if k in contract_types_to_keep
}
return manifest.model_dump_json(
exclude={
"meta",
"dependencies",
"sources",
"compilers",
}
)


def main():
manifest_json = clean_manifest(
project.dependencies["uniswap-v2"]["v1.0.1"].extract_manifest(),
"UniswapV2Factory",
"UniswapV2Pair",
)
(PACKAGE_FOLDER / "v2-manifest.json").write_text(manifest_json)

manifest_json = clean_manifest(
project.dependencies["uniswap-v3"]["v1.0.0"].extract_manifest(),
"UniswapV3Factory",
"UniswapV3Pool",
)
(PACKAGE_FOLDER / "v3-manifest.json").write_text(manifest_json)

manifest_json = clean_manifest(
project.dependencies["permit2"]["main"].extract_manifest(),
"Permit2",
)
(PACKAGE_FOLDER / "permit2-manifest.json").write_text(manifest_json)

manifest_json = clean_manifest(
project.dependencies["universal-router"]["v1.6.0"].extract_manifest(),
"UniversalRouter",
)
(PACKAGE_FOLDER / "unirouter-manifest.json").write_text(manifest_json)
25 changes: 13 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@

extras_require = {
"test": [ # `test` GitHub Action jobs uses this
"pytest>=6.0,<7.0", # Core testing package
"pytest", # Core testing package
"pytest-xdist", # multi-process runner
"pytest-cov", # Coverage analyzer plugin
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
"hypothesis", # Strategy-based fuzzer
],
"lint": [
"black>=21.10b0,<22.0", # auto-formatter and linter
"mypy>=0.910,<1.0", # Static type analyzer
"flake8>=3.8.3,<4.0", # Style linter
"isort>=5.9.3,<6.0", # Import sorting linter
"black", # auto-formatter and linter
"mypy", # Static type analyzer
"flake8", # Style linter
"isort", # Import sorting linter
],
"release": [ # `release` GitHub Action job uses this
"setuptools", # Installation tool
"wheel", # Packaging tool
"twine", # Package upload tool
],
"dev": [
"commitizen>=2.19,<2.20", # Manage commits and publishing releases
"commitizen", # Manage commits and publishing releases
"pre-commit", # Ensure that linters are run prior to commiting
"pytest-watch", # `ptw` test watcher/runner
"IPython", # Console for interacting
Expand Down Expand Up @@ -53,17 +53,17 @@
url="https://github.com/ApeWorX/uniswap-sdk",
include_package_data=True,
install_requires=[
"importlib-metadata ; python_version<'3.8'",
"eth-ape>=0.2.3,<0.3.0",
"eth-ape>=0.8,<1",
"ethpm-types>=0.6.11", # higher peer dep of `eth-ape`, solves typing issue
], # NOTE: Add 3rd party libraries here
python_requires=">=3.7.2,<4",
python_requires=">=3.8,<4",
extras_require=extras_require,
py_modules=["uniswap_sdk"],
license="Apache-2.0",
zip_safe=False,
keywords="ethereum",
packages=find_packages(exclude=["tests", "tests.*"]),
package_data={"uniswap_sdk": ["py.typed"]},
package_data={"uniswap_sdk": ["py.typed", "*.json"]},
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand All @@ -72,9 +72,10 @@
"Operating System :: MacOS",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
)
Empty file removed tests/.gitkeep
Empty file.
Loading

0 comments on commit 4418bfd

Please sign in to comment.