Skip to main content

python utilities for uniswap v4

Project description

UV4

test codecov 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.3.tar.gz (63.4 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.3-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: uv4-0.1.3.tar.gz
  • Upload date:
  • Size: 63.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.4

File hashes

Hashes for uv4-0.1.3.tar.gz
Algorithm Hash digest
SHA256 432226ca5d1ea3b7fe807b75d10ba39428d2d91d4f8de0fecea78444cbec8a55
MD5 2827e6b8ea6b0c9cdf63f31481a045a7
BLAKE2b-256 e52f9c1a4b8e15fc95f81195ae698536fee30cf1d520d2d2821d2e564974d48a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uv4-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.4

File hashes

Hashes for uv4-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0514fd6ca5f23a38e2f7ad15681f342bfb3efb9fa130f0b34db2611fd432c11f
MD5 7d419455546e02b6c6695471ca668451
BLAKE2b-256 939f88924188652622e4f9e265b8d58ab5bdb1807ebfb0541a991cff9fd26afb

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