Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add universal router #2

Merged
merged 24 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e166794
chore: upgrade dependencies
fubuloubu Mar 15, 2024
e128f6b
feat: add start of Universal Router encoder/decoder algorithm
fubuloubu Mar 15, 2024
a85b4e6
feat: add Permit2 types
fubuloubu Mar 15, 2024
ade4078
chore: deprecate py3.7, add py3.11 and 3.12
fubuloubu Apr 28, 2024
85c7182
chore: update CI for py3.11+ and downgrade macos for fix
fubuloubu Apr 28, 2024
aa67ee1
style: fix black styling
fubuloubu Apr 28, 2024
d660914
fix: remove number of args from inner callable for typing
fubuloubu Apr 28, 2024
0f1afea
fix: update lower pin on ethpm-types for mypy fix; widen ape pin
fubuloubu Apr 29, 2024
8e2707d
fix: universal router class (still WIP, but no type issues)
fubuloubu Apr 29, 2024
3a2c487
refactor: typing and clarity improvements
fubuloubu Apr 29, 2024
6f104e0
feat: implement all universal router command encodings (#3)
banteg Jun 6, 2024
2305829
feat: config Uniswap projects for compiling manifests for project
fubuloubu Jun 7, 2024
bd6b26e
feat: add all known deployments of Singleton contracts for v2/v3/ur/p2
fubuloubu Jun 7, 2024
5c44162
chore: add manifests as package resources to package
fubuloubu Jun 7, 2024
ae3780b
feat: add UniversalRouter class
fubuloubu Jun 7, 2024
dbd7483
refactor: update UniversalRouter class to work
fubuloubu Jun 7, 2024
ac8263c
refactor: decode v3 path to show
fubuloubu Jun 7, 2024
7749dbf
fix: lint issues
fubuloubu Jun 7, 2024
e48dfbc
docs: add docs for Plan and UniversalRouter
fubuloubu Jun 7, 2024
25a9442
refactor: remove .inject function
fubuloubu Jun 7, 2024
672edbf
feat: add Plan class
fubuloubu Jun 7, 2024
bf6086e
refactor: fix docstring and add constants for easier use
fubuloubu Jul 24, 2024
74d361d
docs: add link to where I got the deploy addresses from
fubuloubu Jul 24, 2024
dd23dc9
refactor: add `__dir__` to Plan and also some TODOs
fubuloubu Jul 24, 2024
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
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: add types!

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model_copy() may also be an option here, however it doesn't seem like it comes with an exclude=



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
Loading