Python SDK for the UniswapX protocol
Project description
Python UniswapX SDK
Project Information
Code Quality
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file uniswapx-sdk-0.0.2.tar.gz
.
File metadata
- Download URL: uniswapx-sdk-0.0.2.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 775ba7fe0f65928f8989b5af857aa10163dc6f9a5cc8894b4aca138db3246733 |
|
MD5 | 1ceda54d278adba290c2d84977a1093d |
|
BLAKE2b-256 | a3c2b1226a3ffe8e7b4cfcae408a3c225ff4ed0cf3f034c6c5df20821bbaa1e1 |
File details
Details for the file uniswapx_sdk-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: uniswapx_sdk-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58139a67b0eacef56c98c39f0681df4408c3b888b09405da69d4769758897cc6 |
|
MD5 | cbba3ad5050aea950e2a114c5f315875 |
|
BLAKE2b-256 | 0583abe851dd8db0e7a08c2b01276f031131b803b361d8d1b28382c73d9728ad |