Find the path from v2 and v3 pools to swap with the best price, including gas fees
Project description
Uniswap Smart Path
Project Information
Code Quality
Overview
With several V2 and V3 pools, and 2 or 3 tokens per path, there may be quite a few routes to perform a swap. And if you add the gas fees into the equation, it is not straightforward to be sure to get the best deal.
The object of this library is to find the path(s), from v2 and v3 pools, to swap with the best price, including gas fees, and to return it/them in order to be used directly with the UR codec, along with a percentage to know how to divide the amount between them.
⚠ This project is a work in progress. Not all features have been implemented yet. For instance the gas fees is not evaluated in the current version.
⚠ This tool does not replace your own due diligence to find the best price/path to swap any token.
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 uniswap-smart-path
Usage
The library exposes a class, SmartPath
with a public method get_swap_in_path()
that can be used to find the best path/price.
For performance's sake, it is asynchronous.
from uniswap_smart_path import SmartPath
smart_path = await SmartPath.create(async_w3) # where async_w3 is your AsyncWeb3 instance
path = await smart_path.get_swap_in_path(amount_in_wei, token0_address, token1_address)
You can also create the SmartPath
instance from a rpc endpoint:
from uniswap_smart_path import SmartPath
smart_path = await SmartPath.create(rpc_endpoint=rpc_endpoint)
Result
Examples of output paths that you can use with the UR codec to encode a transaction.
Single path
(
{
'path': ('0xD533a949740bb3306d119CC777fa900bA034cd52', 3000, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 3000, '0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2'),
'function': 'V3_SWAP_EXACT_IN',
'weight': 100,
'estimate': 128331138758276360764
},
)
Multi path
Here, 90% of the amount should be swapped on a V3 pool and 10% on a V2 pool, all that in a single transaction using the UR codec.
(
{
'path': ('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
'function': 'V2_SWAP_EXACT_IN',
'weight': 10,
'estimate': 32858922292711987411
},
{
'path': ('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984', 3000, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
'function': 'V3_SWAP_EXACT_IN',
'weight': 90,
'estimate': 295000857928717844546
}
)
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 uniswap-smart-path-0.1.0.tar.gz
.
File metadata
- Download URL: uniswap-smart-path-0.1.0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e86991915a3d83b97ee5ebe03cd37313924b1ce86af46f19138127e1a04787ba |
|
MD5 | b448283e8d7617d5dbfe048d80fd9411 |
|
BLAKE2b-256 | be9e7130f5bd01a4477f06c8e9deeb0ed7a36b47e7225fe19834bcf9fb7d4372 |
File details
Details for the file uniswap_smart_path-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: uniswap_smart_path-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 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 | 7ebd3ae176ac8abd5062174253e0c86dee99e2e769b73d350abed1938097123e |
|
MD5 | d227d82cd6a0ee5db3bf801a38397139 |
|
BLAKE2b-256 | 0e47d6dd01b99d1df240210575bafb23713935a132b8cb9fa2ce52aec7abab27 |