Skip to main content

python utilities for uniswap v4

Project description

UV4

test GitHub repo size GitHub last commit PyPI - Version PyPI - Downloads GitHub top language X (formerly Twitter) Follow

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.1.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uv4-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file uv4-0.1.1.tar.gz.

File metadata

  • Download URL: uv4-0.1.1.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for uv4-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eea989617efa6173389fb451417d030f056aca3b371227f8cdcca77e2a63e131
MD5 c96dcc2f9a81e94061f8695cd1daba2f
BLAKE2b-256 518b0cc56b9c2c1140787140d712736af6157cf222d7bf57ae14166855773644

See more details on using hashes here.

File details

Details for the file uv4-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: uv4-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for uv4-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7eb34ca83ebd79dbee0b59a37b36af1731d8038d22981c59c85417797c3d4d3d
MD5 eef46a05477dd869d146aebe98bc23e0
BLAKE2b-256 4582f417d6a57e517d8329e10f3c12b952ab6ef02270fc539296ab96b64f4a62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page