Skip to main content

Python UniswapX SDK


Project Information

Tests & Lint PyPI - Python Version GitHub release (latest by date) PyPi Repository GitHub

Code Quality

CodeQL Test Coverage Imports: isort Type Checker: mypy Linter: flake8


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, here is a tutorial.

The library can be pip installed from pypi.org as usual:

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

from uniswapx_sdk.encoder import (
    DecayTime,    
    ExclusiveDutchOrderInfo,
    ExclusiveDutchOrderInput,
    ExclusiveDutchOrderOutput,
    ExclusiveFiller,
    get_nonce,
)

Then you instantiate them:

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:

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:

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:

from uniswapx_sdk.decoder import ExclusiveDutchOrderDecoder

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

How to get orders from UniswapX API

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:

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.

Metadata

Release files for uniswapx-sdk 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uniswapx-sdk 0.0.2
File Size Uploaded Provenance Actions
uniswapx-sdk-0.0.2.tar.gz 18.4 kB Without provenance Details for uniswapx-sdk-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uniswapx-sdk 0.0.2
File Interpreter ABI Platform Actions
uniswapx_sdk-0.0.2-py3-none-any.whl Python 3 none any Details for uniswapx_sdk-0.0.2-py3-none-any.whl

Total release size: 29.6 kB

Release files / uniswapx-sdk-0.0.2.tar.gz

Download URL uniswapx-sdk-0.0.2.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
775ba7fe0f65928f8989b5af857aa10163dc6f9a5cc8894b4aca138db3246733
BLAKE2b-256 checksum
How to use checksums
a3c2b1226a3ffe8e7b4cfcae408a3c225ff4ed0cf3f034c6c5df20821bbaa1e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.5

Release files / uniswapx_sdk-0.0.2-py3-none-any.whl

Download URL uniswapx_sdk-0.0.2-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58139a67b0eacef56c98c39f0681df4408c3b888b09405da69d4769758897cc6
BLAKE2b-256 checksum
How to use checksums
0583abe851dd8db0e7a08c2b01276f031131b803b361d8d1b28382c73d9728ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.5

Security for uniswapx-sdk 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page