uniswapx-sdk


Nameuniswapx-sdk JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryPython SDK for the UniswapX protocol
upload_time2024-01-08 14:21:28
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License
keywords blockchain ethereum uniswap uniswapx decoder encoder codec wrapper sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python UniswapX SDK

---

#### Project Information
[![Tests & Lint](https://github.com/Elnaril/python-uniswapx-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/Elnaril/python-uniswapx-sdk/actions/workflows/ci.yml)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/uniswapx-sdk)](https://pypi.org/project/python-uniswapx-sdk/)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Elnaril/python-uniswapx-sdk)](https://github.com/Elnaril/python-uniswapx-sdk/releases)
[![PyPi Repository](https://img.shields.io/badge/repository-pipy.org-blue)](https://pypi.org/project/python-uniswapx-sdk/)
[![GitHub](https://img.shields.io/github/license/Elnaril/python-uniswapx-sdk)](https://github.com/Elnaril/python-uniswapx-sdk/blob/master/LICENSE)

#### Code Quality
[![CodeQL](https://github.com/elnaril/python-uniswapx-sdk/workflows/CodeQL/badge.svg)](https://github.com/Elnaril/python-uniswapx-sdk/actions/workflows/codeql.yml)
[![Test Coverage](https://img.shields.io/badge/dynamic/json?color=blueviolet&label=coverage&query=%24.totals.percent_covered_display&suffix=%25&url=https%3A%2F%2Fraw.githubusercontent.com%2FElnaril%2Fpython-uniswapx-sdk%2Fmaster%2Fcoverage.json)](https://github.com/Elnaril/python-uniswapx-sdk/blob/master/coverage.json)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Type Checker: mypy](https://img.shields.io/badge/%20type%20checker-mypy-%231674b1?style=flat&labelColor=ef8336)](https://mypy-lang.org/)
[![Linter: flake8](https://img.shields.io/badge/%20linter-flake8-%231674b1?style=flat&labelColor=ef8336)](https://flake8.pycqa.org/en/latest/)

---

## Release Notes
### V0.2.0
 - Exclusive Dutch Order Encoder
 - Reactor Execute Encoder
 - Get Orders from UniswapX API
 - Integration Tests
 - Documentation
### V0.1.0
 - Exclusive Dutch Order Decoder
 - Order Resolver

---

## Overview and Points of Attention
This library is a Python SDK that can be used to easily interact with UniswapX ecosystem: Reactors, Quoter, API.
It's partially inspired by https://github.com/Uniswap/uniswapx-sdk

⚠ This library has not been audited, so use at your own risk !

⚠ The API currently exposed is very likely to change with the following versions: consider forcing the version.

⚠ This project is a work in progress so not all features have already been implemented.

---

## Installation
A good practice is to use [Python virtual environments](https://python.readthedocs.io/en/latest/library/venv.html), here is a [tutorial](https://www.freecodecamp.org/news/how-to-setup-virtual-environments-in-python/).

The library can be pip installed from [pypi.org](https://pypi.org/project/uniswapx-sdk/) as usual:

```bash
# update pip to latest version if needed
pip install -U pip

# install the decoder from pypi.org
pip install uniswapx-sdk
```

---

## Usage

### How to encode an Exclusive Ducth Order
First, you need to import the classes that will help you to structure the encoding, along with a function that will compute the order nonce: 
```python
from uniswapx_sdk.encoder import (
    DecayTime,    
    ExclusiveDutchOrderInfo,
    ExclusiveDutchOrderInput,
    ExclusiveDutchOrderOutput,
    ExclusiveFiller,
    get_nonce,
)
```

Then you instantiate them:
```python
order_info = ExclusiveDutchOrderInfo(
    reactor="0x6000da47483062a0d734ba3dc7576ce6a0b645c4",
    swapper="0x...",  # your account address
    nonce=get_nonce(),
    deadline=deadline,  # Unix timestamp after which the order won't be valid any more.
)

decay_time = DecayTime(start_timestamp, end_timestamp)

dutch_input = ExclusiveDutchOrderInput(in_token_address, start_amount_in_wei, end_amount_in_wei)

dutch_outputs = (
    ExclusiveDutchOrderOutput(
        token=out_token_address,  # or '0x0000000000000000000000000000000000000000' for native coin
        start_amount=start_amount_in_wei,
        end_amount=end_amount_in_wei,
        recipient=recipient_address,  # who is going to receive the output
    ),
)

exclusive_filler = ExclusiveFiller(filler_address, bps)  # the exclusive filler if any with the override bps
#  or exclusive_filler = ExclusiveFiller() if no exclusive filler
```

And now you're ready to encode the order and sign it:
```python
import ExclusiveDutchOrderEncoder

encoder = ExclusiveDutchOrderEncoder(chain_id)
encoded_order, signable_message = encoder.encode_order(
    order_info,
    decay_time,
    dutch_input,
    dutch_outputs,
    exclusive_filler
)
signed_message = your_account.sign_message(signable_message)
```

### How to resolve/validate/quote an order
Let's say you have en encoded `order` along with its signature `sig`. Resolving it is as simple as:

```python
from uniswapx_sdk.resolver import OrderResolver

resolver = await OrderResolver.create(rpc_endpoint="https://...")
resolved_order = asyncio.run(resolver.resolve(order, sig))
```

### How to decode an order
Let's say you have en encoded order. Decoding it is as simple as:
```python
from uniswapx_sdk.decoder import ExclusiveDutchOrderDecoder

decoder = ExclusiveDutchOrderDecoder()
decoded_order = decoder.decode(encoded_order)
```

### How to get orders from UniswapX API
```python
from uniswapx_sdk.api import UniswapXAPI

api = UniswapXAPI(chain_id)
orders = await api.get_orders(order_status)  # with order_status in open, expired, error, cancelled, filled, insufficient-funds
```

### How to fill an order
Let's say you want to fill (execute) a dutch order. First you encode it as follows:
```python
from uniswapx_sdk.encoder import ExclusiveDutchOrderEncoder

encoded_input = ExclusiveDutchOrderEncoder.encode_execute(order, sig)  # where sig is the signature corresponding to the order
```
Then you include the `encoded_input` in the transaction you sign and send to the Exclusive Dutch Order Reactor.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "uniswapx-sdk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "blockchain,ethereum,uniswap,uniswapx,decoder,encoder,codec,wrapper,sdk",
    "author": "",
    "author_email": "Elnaril <elnaril_dev@caramail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a3/c2/b1226a3ffe8e7b4cfcae408a3c225ff4ed0cf3f034c6c5df20821bbaa1e1/uniswapx-sdk-0.0.2.tar.gz",
    "platform": null,
    "description": "# Python UniswapX SDK\n\n---\n\n#### Project Information\n[![Tests & Lint](https://github.com/Elnaril/python-uniswapx-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/Elnaril/python-uniswapx-sdk/actions/workflows/ci.yml)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/uniswapx-sdk)](https://pypi.org/project/python-uniswapx-sdk/)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Elnaril/python-uniswapx-sdk)](https://github.com/Elnaril/python-uniswapx-sdk/releases)\n[![PyPi Repository](https://img.shields.io/badge/repository-pipy.org-blue)](https://pypi.org/project/python-uniswapx-sdk/)\n[![GitHub](https://img.shields.io/github/license/Elnaril/python-uniswapx-sdk)](https://github.com/Elnaril/python-uniswapx-sdk/blob/master/LICENSE)\n\n#### Code Quality\n[![CodeQL](https://github.com/elnaril/python-uniswapx-sdk/workflows/CodeQL/badge.svg)](https://github.com/Elnaril/python-uniswapx-sdk/actions/workflows/codeql.yml)\n[![Test Coverage](https://img.shields.io/badge/dynamic/json?color=blueviolet&label=coverage&query=%24.totals.percent_covered_display&suffix=%25&url=https%3A%2F%2Fraw.githubusercontent.com%2FElnaril%2Fpython-uniswapx-sdk%2Fmaster%2Fcoverage.json)](https://github.com/Elnaril/python-uniswapx-sdk/blob/master/coverage.json)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![Type Checker: mypy](https://img.shields.io/badge/%20type%20checker-mypy-%231674b1?style=flat&labelColor=ef8336)](https://mypy-lang.org/)\n[![Linter: flake8](https://img.shields.io/badge/%20linter-flake8-%231674b1?style=flat&labelColor=ef8336)](https://flake8.pycqa.org/en/latest/)\n\n---\n\n## Release Notes\n### V0.2.0\n - Exclusive Dutch Order Encoder\n - Reactor Execute Encoder\n - Get Orders from UniswapX API\n - Integration Tests\n - Documentation\n### V0.1.0\n - Exclusive Dutch Order Decoder\n - Order Resolver\n\n---\n\n## Overview and Points of Attention\nThis library is a Python SDK that can be used to easily interact with UniswapX ecosystem: Reactors, Quoter, API.\nIt's partially inspired by https://github.com/Uniswap/uniswapx-sdk\n\n\u26a0 This library has not been audited, so use at your own risk !\n\n\u26a0 The API currently exposed is very likely to change with the following versions: consider forcing the version.\n\n\u26a0 This project is a work in progress so not all features have already been implemented.\n\n---\n\n## Installation\nA good practice is to use [Python virtual environments](https://python.readthedocs.io/en/latest/library/venv.html), here is a [tutorial](https://www.freecodecamp.org/news/how-to-setup-virtual-environments-in-python/).\n\nThe library can be pip installed from [pypi.org](https://pypi.org/project/uniswapx-sdk/) as usual:\n\n```bash\n# update pip to latest version if needed\npip install -U pip\n\n# install the decoder from pypi.org\npip install uniswapx-sdk\n```\n\n---\n\n## Usage\n\n### How to encode an Exclusive Ducth Order\nFirst, you need to import the classes that will help you to structure the encoding, along with a function that will compute the order nonce: \n```python\nfrom uniswapx_sdk.encoder import (\n    DecayTime,    \n    ExclusiveDutchOrderInfo,\n    ExclusiveDutchOrderInput,\n    ExclusiveDutchOrderOutput,\n    ExclusiveFiller,\n    get_nonce,\n)\n```\n\nThen you instantiate them:\n```python\norder_info = ExclusiveDutchOrderInfo(\n    reactor=\"0x6000da47483062a0d734ba3dc7576ce6a0b645c4\",\n    swapper=\"0x...\",  # your account address\n    nonce=get_nonce(),\n    deadline=deadline,  # Unix timestamp after which the order won't be valid any more.\n)\n\ndecay_time = DecayTime(start_timestamp, end_timestamp)\n\ndutch_input = ExclusiveDutchOrderInput(in_token_address, start_amount_in_wei, end_amount_in_wei)\n\ndutch_outputs = (\n    ExclusiveDutchOrderOutput(\n        token=out_token_address,  # or '0x0000000000000000000000000000000000000000' for native coin\n        start_amount=start_amount_in_wei,\n        end_amount=end_amount_in_wei,\n        recipient=recipient_address,  # who is going to receive the output\n    ),\n)\n\nexclusive_filler = ExclusiveFiller(filler_address, bps)  # the exclusive filler if any with the override bps\n#  or exclusive_filler = ExclusiveFiller() if no exclusive filler\n```\n\nAnd now you're ready to encode the order and sign it:\n```python\nimport ExclusiveDutchOrderEncoder\n\nencoder = ExclusiveDutchOrderEncoder(chain_id)\nencoded_order, signable_message = encoder.encode_order(\n    order_info,\n    decay_time,\n    dutch_input,\n    dutch_outputs,\n    exclusive_filler\n)\nsigned_message = your_account.sign_message(signable_message)\n```\n\n### How to resolve/validate/quote an order\nLet's say you have en encoded `order` along with its signature `sig`. Resolving it is as simple as:\n\n```python\nfrom uniswapx_sdk.resolver import OrderResolver\n\nresolver = await OrderResolver.create(rpc_endpoint=\"https://...\")\nresolved_order = asyncio.run(resolver.resolve(order, sig))\n```\n\n### How to decode an order\nLet's say you have en encoded order. Decoding it is as simple as:\n```python\nfrom uniswapx_sdk.decoder import ExclusiveDutchOrderDecoder\n\ndecoder = ExclusiveDutchOrderDecoder()\ndecoded_order = decoder.decode(encoded_order)\n```\n\n### How to get orders from UniswapX API\n```python\nfrom uniswapx_sdk.api import UniswapXAPI\n\napi = UniswapXAPI(chain_id)\norders = await api.get_orders(order_status)  # with order_status in open, expired, error, cancelled, filled, insufficient-funds\n```\n\n### How to fill an order\nLet's say you want to fill (execute) a dutch order. First you encode it as follows:\n```python\nfrom uniswapx_sdk.encoder import ExclusiveDutchOrderEncoder\n\nencoded_input = ExclusiveDutchOrderEncoder.encode_execute(order, sig)  # where sig is the signature corresponding to the order\n```\nThen you include the `encoded_input` in the transaction you sign and send to the Exclusive Dutch Order Reactor.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Python SDK for the UniswapX protocol",
    "version": "0.0.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/Elnaril/python-uniswapx-sdk/issues",
        "Buy Me A Coffee": "https://www.buymeacoffee.com/elnaril",
        "Fiverr": "https://www.fiverr.com/freelancers/elnaril",
        "Homepage": "https://github.com/Elnaril/python-uniswapx-sdk"
    },
    "split_keywords": [
        "blockchain",
        "ethereum",
        "uniswap",
        "uniswapx",
        "decoder",
        "encoder",
        "codec",
        "wrapper",
        "sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0583abe851dd8db0e7a08c2b01276f031131b803b361d8d1b28382c73d9728ad",
                "md5": "cbba3ad5050aea950e2a114c5f315875",
                "sha256": "58139a67b0eacef56c98c39f0681df4408c3b888b09405da69d4769758897cc6"
            },
            "downloads": -1,
            "filename": "uniswapx_sdk-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cbba3ad5050aea950e2a114c5f315875",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11190,
            "upload_time": "2024-01-08T14:21:26",
            "upload_time_iso_8601": "2024-01-08T14:21:26.963657Z",
            "url": "https://files.pythonhosted.org/packages/05/83/abe851dd8db0e7a08c2b01276f031131b803b361d8d1b28382c73d9728ad/uniswapx_sdk-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a3c2b1226a3ffe8e7b4cfcae408a3c225ff4ed0cf3f034c6c5df20821bbaa1e1",
                "md5": "1ceda54d278adba290c2d84977a1093d",
                "sha256": "775ba7fe0f65928f8989b5af857aa10163dc6f9a5cc8894b4aca138db3246733"
            },
            "downloads": -1,
            "filename": "uniswapx-sdk-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1ceda54d278adba290c2d84977a1093d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18389,
            "upload_time": "2024-01-08T14:21:28",
            "upload_time_iso_8601": "2024-01-08T14:21:28.767699Z",
            "url": "https://files.pythonhosted.org/packages/a3/c2/b1226a3ffe8e7b4cfcae408a3c225ff4ed0cf3f034c6c5df20821bbaa1e1/uniswapx-sdk-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-08 14:21:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Elnaril",
    "github_project": "python-uniswapx-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "uniswapx-sdk"
}
        
Elapsed time: 0.16497s