python utilities for uniswap v4
Project description
UV4
Math utils for Uniswap v4.
Install
pip install uv4
Q64.96
- Q64.96 Fixed Point convertions
- Convert decimal to Q64.96
- Convert Q64.96 to decimal
- Get 64 bit string
- Get 96 bit string
Usage
>>> from uv4 import Q6496
>>> value = 1.0001
>>> q = Q6496(value)
>>> q.from_decimal()
79236085330515764027303304731
>>> q.to_decimal()
Decimal('1.00009999999999999999999999999957590837735318405341065472330397412292768422048538923263549804688')
>>> q.get_64_bits_string()
'0000000000000000000000000000000000000000000000000000000000000001'
>>> q.get_96_bits_precision_string()
'000000000000011010001101101110001011101011000111000100001100101100101001010111101001111000011011'
>>> q.to_Q6496_binary_string()
'0b0000000000000000000000000000000000000000000000000000000000000001000000000000011010001101101110001011101011000111000100001100101100101001010111101001111000011011'
>>> q.value
Decimal('1.0001')
>>> q.q_number
79236085330515764027303304731
TickMath & Sqrt Prices
>>> from uv4 import TickMath
>>> tick = 10
>>> tick_spacing = 1
>>> t = TickMath(tick, tick_spacing)
>>> t.to_price()
Decimal('1.0010004501200210025202100120004500100001')
>>> t.to_sqrt_price()
Decimal('1.00050010001000050001')
>>> t.to_sqrt_price_x96()
79267784519130042428790663799
- get price at tick
- get tick at price
- get Q64.96 price at tick
- get tick at Q64.96 price
- get Q64.96 price from price
- get price from Q64.96 price
Hooks
>>> from uv4 import Hook
>>> address = 0x00000000000000000000000000000000000000b5
>>> h = Hook(address)
>>> h.has_after_swap_flag()
False
>>> h.has_before_swap_flag()
True
🧪 Run Tests
Dependencies:
- pytest
- pytest-watcher
Run command
ptw .
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
uv4-0.1.2.tar.gz
(62.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
uv4-0.1.2-py3-none-any.whl
(9.0 kB
view details)
File details
Details for the file uv4-0.1.2.tar.gz.
File metadata
- Download URL: uv4-0.1.2.tar.gz
- Upload date:
- Size: 62.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
914c6319512711cda719d2a6a8150f2675f75cead88aa97dc18986c21e4c93d8
|
|
| MD5 |
2e1850baa3ed85321dc921a443aefad7
|
|
| BLAKE2b-256 |
31e7cd694db2b44af6757fb6a5a5e07e89594ac8613edb64c45d791aae1ff5c7
|
File details
Details for the file uv4-0.1.2-py3-none-any.whl.
File metadata
- Download URL: uv4-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ba0020f6be2ec13581eea335fedd4af76d7b6f0011ffcbfb3bed59533e8a683
|
|
| MD5 |
b4b538190f0f01530abeafed7a9db84e
|
|
| BLAKE2b-256 |
8d55124d8aa4a1a5076b80143288f99cc5bb939dadbafcbbe1d5f27424a3339f
|