odos-py 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- odos_py-0.1.0/.github/workflows/ci.yml +38 -0
- odos_py-0.1.0/.gitignore +218 -0
- odos_py-0.1.0/LICENSE +21 -0
- odos_py-0.1.0/PKG-INFO +148 -0
- odos_py-0.1.0/README.md +114 -0
- odos_py-0.1.0/examples/async_quote.py +34 -0
- odos_py-0.1.0/examples/quote_and_assemble.py +44 -0
- odos_py-0.1.0/pyproject.toml +72 -0
- odos_py-0.1.0/src/odos_py/__init__.py +33 -0
- odos_py-0.1.0/src/odos_py/_base.py +110 -0
- odos_py-0.1.0/src/odos_py/async_client.py +163 -0
- odos_py-0.1.0/src/odos_py/client.py +167 -0
- odos_py-0.1.0/src/odos_py/exceptions.py +42 -0
- odos_py-0.1.0/src/odos_py/models.py +106 -0
- odos_py-0.1.0/src/odos_py/py.typed +0 -0
- odos_py-0.1.0/tests/__init__.py +0 -0
- odos_py-0.1.0/tests/test_async_client.py +118 -0
- odos_py-0.1.0/tests/test_base.py +59 -0
- odos_py-0.1.0/tests/test_client.py +235 -0
- odos_py-0.1.0/tests/test_exceptions.py +27 -0
- odos_py-0.1.0/tests/test_integration.py +27 -0
- odos_py-0.1.0/tests/test_models.py +115 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
19
|
+
uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
|
|
23
|
+
- name: Install
|
|
24
|
+
run: |
|
|
25
|
+
python -m pip install --upgrade pip
|
|
26
|
+
pip install -e ".[dev,exec]"
|
|
27
|
+
|
|
28
|
+
- name: Ruff
|
|
29
|
+
run: ruff check .
|
|
30
|
+
|
|
31
|
+
- name: Mypy (strict)
|
|
32
|
+
# mypy targets 3.10 (see pyproject) and the pinned mypy does not run on
|
|
33
|
+
# 3.9; the 3.9 job exists to prove the package imports and runs there.
|
|
34
|
+
if: matrix.python-version != '3.9'
|
|
35
|
+
run: mypy
|
|
36
|
+
|
|
37
|
+
- name: Pytest
|
|
38
|
+
run: pytest -q
|
odos_py-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
odos_py-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robert Ruben
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
odos_py-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: odos-py
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A modern Python client for the Odos DEX Aggregator API
|
|
5
|
+
Project-URL: Homepage, https://github.com/robertruben98/odos-py
|
|
6
|
+
Project-URL: Documentation, https://docs.odos.xyz/build/api-docs
|
|
7
|
+
Project-URL: Repository, https://github.com/robertruben98/odos-py
|
|
8
|
+
Project-URL: Issues, https://github.com/robertruben98/odos-py/issues
|
|
9
|
+
Author: robertdev
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: aggregator,defi,dex,ethereum,odos,swap
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: httpx>=0.24
|
|
24
|
+
Requires-Dist: pydantic>=2.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: mypy>=1.5; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: respx>=0.20; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
31
|
+
Provides-Extra: exec
|
|
32
|
+
Requires-Dist: web3>=6.0; extra == 'exec'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# odos-py
|
|
36
|
+
|
|
37
|
+
A modern, fully-typed Python client for the [Odos](https://docs.odos.xyz/build/api-docs) DEX Aggregator API.
|
|
38
|
+
|
|
39
|
+
- Sync (`OdosClient`) and async (`AsyncOdosClient`) clients built on `httpx`
|
|
40
|
+
- `pydantic` v2 models for all requests and responses
|
|
41
|
+
- Automatic HTTP 429 handling with exponential backoff
|
|
42
|
+
- Configurable base URL and API-key header
|
|
43
|
+
- `mypy --strict` clean, ships a `py.typed` marker
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install odos-py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Optional extra for signing/sending the assembled transaction with `web3.py`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install "odos-py[exec]"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Quickstart
|
|
58
|
+
|
|
59
|
+
Odos works in two steps: `quote` returns a `pathId`, then `assemble` turns that
|
|
60
|
+
`pathId` into ready-to-sign transaction calldata. The `swap()` helper chains
|
|
61
|
+
both:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from odos_py import OdosClient, QuoteRequest, InputToken, OutputToken
|
|
65
|
+
|
|
66
|
+
client = OdosClient(api_key="YOUR_KEY") # api_key optional but recommended
|
|
67
|
+
quote, assembled = client.swap(QuoteRequest(
|
|
68
|
+
chain_id=1,
|
|
69
|
+
input_tokens=[InputToken(token_address="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", # WETH
|
|
70
|
+
amount="1000000000000000000")], # 1 WETH (wei)
|
|
71
|
+
output_tokens=[OutputToken(token_address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", # USDC
|
|
72
|
+
proportion=1)],
|
|
73
|
+
user_addr="0x47E2D28169738039755586743E2dfCF3bd643f86",
|
|
74
|
+
slippage_limit_percent=0.3,
|
|
75
|
+
))
|
|
76
|
+
print(quote.path_id, assembled.transaction.to)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Async is identical with `await`:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import asyncio
|
|
83
|
+
from odos_py import AsyncOdosClient
|
|
84
|
+
|
|
85
|
+
async def main(request):
|
|
86
|
+
async with AsyncOdosClient() as client:
|
|
87
|
+
quote = await client.quote(request)
|
|
88
|
+
print(quote.path_id)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Auth & rate limits
|
|
92
|
+
|
|
93
|
+
There is a free, **keyless** tier, but it is heavily rate limited — `POST
|
|
94
|
+
/sor/quote/v2` returns HTTP 429 quickly without a key. Pass an `api_key` to
|
|
95
|
+
raise limits. The exact API-key header name is not publicly documented, so it
|
|
96
|
+
is configurable:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
OdosClient(api_key="YOUR_KEY", api_key_header="x-api-key") # default header name
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The client retries 429 responses with exponential backoff (honouring any
|
|
103
|
+
`Retry-After` header) and raises `OdosRateLimitError` once retries are
|
|
104
|
+
exhausted. Tune with `max_retries` and `backoff_base`.
|
|
105
|
+
|
|
106
|
+
## Endpoints
|
|
107
|
+
|
|
108
|
+
| Method | Endpoint |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `quote(request)` | `POST /sor/quote/v2` |
|
|
111
|
+
| `assemble(user_addr=, path_id=)` | `POST /sor/assemble` |
|
|
112
|
+
| `execute(user_addr=, path_id=)` | `POST /sor/execute` |
|
|
113
|
+
| `swap(request)` / `quote_and_assemble(request)` | quote then assemble |
|
|
114
|
+
| `get_chains()` | `GET /info/chains` |
|
|
115
|
+
| `get_tokens(chain_id)` | `GET /info/tokens/{chainId}` |
|
|
116
|
+
| `get_router(chain_id)` | `GET /info/router/v2/{chainId}` |
|
|
117
|
+
| `get_contract_info(chain_id)` | `GET /info/contract-info/v2/{chainId}` |
|
|
118
|
+
| `get_token_price(chain_id, token_address)` | `GET /pricing/token/{chainId}/{tokenAddress}` |
|
|
119
|
+
|
|
120
|
+
Multi-chain is handled per call via `chain_id` on `QuoteRequest` and the info
|
|
121
|
+
endpoints.
|
|
122
|
+
|
|
123
|
+
## Configuration
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
OdosClient(
|
|
127
|
+
base_url="https://api.odos.xyz", # configurable / proxyable
|
|
128
|
+
api_key=None,
|
|
129
|
+
api_key_header="x-api-key",
|
|
130
|
+
max_retries=3,
|
|
131
|
+
backoff_base=0.5,
|
|
132
|
+
timeout=30.0,
|
|
133
|
+
)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Development
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install -e ".[dev,exec]"
|
|
140
|
+
pytest # unit tests (HTTP mocked, no network)
|
|
141
|
+
pytest -m integration # live smoke test against /info/chains
|
|
142
|
+
ruff check .
|
|
143
|
+
mypy
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT
|
odos_py-0.1.0/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# odos-py
|
|
2
|
+
|
|
3
|
+
A modern, fully-typed Python client for the [Odos](https://docs.odos.xyz/build/api-docs) DEX Aggregator API.
|
|
4
|
+
|
|
5
|
+
- Sync (`OdosClient`) and async (`AsyncOdosClient`) clients built on `httpx`
|
|
6
|
+
- `pydantic` v2 models for all requests and responses
|
|
7
|
+
- Automatic HTTP 429 handling with exponential backoff
|
|
8
|
+
- Configurable base URL and API-key header
|
|
9
|
+
- `mypy --strict` clean, ships a `py.typed` marker
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install odos-py
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Optional extra for signing/sending the assembled transaction with `web3.py`:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install "odos-py[exec]"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
Odos works in two steps: `quote` returns a `pathId`, then `assemble` turns that
|
|
26
|
+
`pathId` into ready-to-sign transaction calldata. The `swap()` helper chains
|
|
27
|
+
both:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from odos_py import OdosClient, QuoteRequest, InputToken, OutputToken
|
|
31
|
+
|
|
32
|
+
client = OdosClient(api_key="YOUR_KEY") # api_key optional but recommended
|
|
33
|
+
quote, assembled = client.swap(QuoteRequest(
|
|
34
|
+
chain_id=1,
|
|
35
|
+
input_tokens=[InputToken(token_address="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", # WETH
|
|
36
|
+
amount="1000000000000000000")], # 1 WETH (wei)
|
|
37
|
+
output_tokens=[OutputToken(token_address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", # USDC
|
|
38
|
+
proportion=1)],
|
|
39
|
+
user_addr="0x47E2D28169738039755586743E2dfCF3bd643f86",
|
|
40
|
+
slippage_limit_percent=0.3,
|
|
41
|
+
))
|
|
42
|
+
print(quote.path_id, assembled.transaction.to)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Async is identical with `await`:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import asyncio
|
|
49
|
+
from odos_py import AsyncOdosClient
|
|
50
|
+
|
|
51
|
+
async def main(request):
|
|
52
|
+
async with AsyncOdosClient() as client:
|
|
53
|
+
quote = await client.quote(request)
|
|
54
|
+
print(quote.path_id)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Auth & rate limits
|
|
58
|
+
|
|
59
|
+
There is a free, **keyless** tier, but it is heavily rate limited — `POST
|
|
60
|
+
/sor/quote/v2` returns HTTP 429 quickly without a key. Pass an `api_key` to
|
|
61
|
+
raise limits. The exact API-key header name is not publicly documented, so it
|
|
62
|
+
is configurable:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
OdosClient(api_key="YOUR_KEY", api_key_header="x-api-key") # default header name
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The client retries 429 responses with exponential backoff (honouring any
|
|
69
|
+
`Retry-After` header) and raises `OdosRateLimitError` once retries are
|
|
70
|
+
exhausted. Tune with `max_retries` and `backoff_base`.
|
|
71
|
+
|
|
72
|
+
## Endpoints
|
|
73
|
+
|
|
74
|
+
| Method | Endpoint |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `quote(request)` | `POST /sor/quote/v2` |
|
|
77
|
+
| `assemble(user_addr=, path_id=)` | `POST /sor/assemble` |
|
|
78
|
+
| `execute(user_addr=, path_id=)` | `POST /sor/execute` |
|
|
79
|
+
| `swap(request)` / `quote_and_assemble(request)` | quote then assemble |
|
|
80
|
+
| `get_chains()` | `GET /info/chains` |
|
|
81
|
+
| `get_tokens(chain_id)` | `GET /info/tokens/{chainId}` |
|
|
82
|
+
| `get_router(chain_id)` | `GET /info/router/v2/{chainId}` |
|
|
83
|
+
| `get_contract_info(chain_id)` | `GET /info/contract-info/v2/{chainId}` |
|
|
84
|
+
| `get_token_price(chain_id, token_address)` | `GET /pricing/token/{chainId}/{tokenAddress}` |
|
|
85
|
+
|
|
86
|
+
Multi-chain is handled per call via `chain_id` on `QuoteRequest` and the info
|
|
87
|
+
endpoints.
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
OdosClient(
|
|
93
|
+
base_url="https://api.odos.xyz", # configurable / proxyable
|
|
94
|
+
api_key=None,
|
|
95
|
+
api_key_header="x-api-key",
|
|
96
|
+
max_retries=3,
|
|
97
|
+
backoff_base=0.5,
|
|
98
|
+
timeout=30.0,
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pip install -e ".[dev,exec]"
|
|
106
|
+
pytest # unit tests (HTTP mocked, no network)
|
|
107
|
+
pytest -m integration # live smoke test against /info/chains
|
|
108
|
+
ruff check .
|
|
109
|
+
mypy
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Async variant: quote WETH -> USDC on Ethereum mainnet.
|
|
2
|
+
|
|
3
|
+
python examples/async_quote.py
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
from odos_py import AsyncOdosClient, InputToken, OutputToken, QuoteRequest
|
|
12
|
+
|
|
13
|
+
WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
14
|
+
USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
15
|
+
USER = "0x47E2D28169738039755586743E2dfCF3bd643f86"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def main() -> None:
|
|
19
|
+
request = QuoteRequest(
|
|
20
|
+
chain_id=1,
|
|
21
|
+
input_tokens=[InputToken(token_address=WETH, amount="1000000000000000000")],
|
|
22
|
+
output_tokens=[OutputToken(token_address=USDC, proportion=1)],
|
|
23
|
+
user_addr=USER,
|
|
24
|
+
slippage_limit_percent=0.3,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
async with AsyncOdosClient(api_key=os.environ.get("ODOS_API_KEY")) as client:
|
|
28
|
+
quote = await client.quote(request)
|
|
29
|
+
print(f"pathId: {quote.path_id}")
|
|
30
|
+
print(f"out amount: {quote.out_amounts}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Quote WETH -> USDC on Ethereum mainnet, then assemble the transaction.
|
|
2
|
+
|
|
3
|
+
This reproduces the validated flow. The quote endpoint is heavily rate limited
|
|
4
|
+
without an API key, so set ODOS_API_KEY to avoid HTTP 429.
|
|
5
|
+
|
|
6
|
+
python examples/quote_and_assemble.py
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
|
|
13
|
+
from odos_py import InputToken, OdosClient, OutputToken, QuoteRequest
|
|
14
|
+
|
|
15
|
+
WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
16
|
+
USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
17
|
+
USER = "0x47E2D28169738039755586743E2dfCF3bd643f86"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main() -> None:
|
|
21
|
+
client = OdosClient(api_key=os.environ.get("ODOS_API_KEY"))
|
|
22
|
+
|
|
23
|
+
request = QuoteRequest(
|
|
24
|
+
chain_id=1,
|
|
25
|
+
input_tokens=[InputToken(token_address=WETH, amount="1000000000000000000")], # 1 WETH
|
|
26
|
+
output_tokens=[OutputToken(token_address=USDC, proportion=1)],
|
|
27
|
+
user_addr=USER,
|
|
28
|
+
slippage_limit_percent=0.3,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
quote, assembled = client.swap(request)
|
|
32
|
+
|
|
33
|
+
print(f"pathId: {quote.path_id}")
|
|
34
|
+
print(f"out amount: {quote.out_amounts}")
|
|
35
|
+
if assembled.transaction is not None:
|
|
36
|
+
data = assembled.transaction.data
|
|
37
|
+
print(f"tx to: {assembled.transaction.to}")
|
|
38
|
+
print(f"tx data: {data[:42] + '...' if data else None}")
|
|
39
|
+
|
|
40
|
+
client.close()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "odos-py"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A modern Python client for the Odos DEX Aggregator API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "robertdev" }]
|
|
13
|
+
keywords = ["odos", "dex", "aggregator", "defi", "ethereum", "swap"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.24",
|
|
27
|
+
"pydantic>=2.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
exec = ["web3>=6.0"]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=7.0",
|
|
34
|
+
"pytest-asyncio>=0.21",
|
|
35
|
+
"respx>=0.20",
|
|
36
|
+
"mypy>=1.5",
|
|
37
|
+
"ruff>=0.1",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/robertruben98/odos-py"
|
|
42
|
+
Documentation = "https://docs.odos.xyz/build/api-docs"
|
|
43
|
+
Repository = "https://github.com/robertruben98/odos-py"
|
|
44
|
+
Issues = "https://github.com/robertruben98/odos-py/issues"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["src/odos_py"]
|
|
48
|
+
|
|
49
|
+
[tool.ruff]
|
|
50
|
+
line-length = 100
|
|
51
|
+
target-version = "py39"
|
|
52
|
+
|
|
53
|
+
[tool.ruff.lint]
|
|
54
|
+
select = ["E", "F", "I", "UP", "B", "W"]
|
|
55
|
+
# Keep typing.Optional/Union: PEP 604 (`X | None`) in evaluated annotations is
|
|
56
|
+
# not safe on the 3.9 runtime we still support.
|
|
57
|
+
ignore = ["UP006", "UP007", "UP035", "UP045"]
|
|
58
|
+
|
|
59
|
+
[tool.mypy]
|
|
60
|
+
# Runtime supports 3.9+, but this mypy version requires a 3.10+ target.
|
|
61
|
+
python_version = "3.10"
|
|
62
|
+
strict = true
|
|
63
|
+
warn_unused_configs = true
|
|
64
|
+
files = ["src/odos_py"]
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
testpaths = ["tests"]
|
|
68
|
+
asyncio_mode = "auto"
|
|
69
|
+
markers = [
|
|
70
|
+
"integration: marks tests that hit the live network (deselected by default)",
|
|
71
|
+
]
|
|
72
|
+
addopts = "-m 'not integration'"
|