Repository navigation
Commit 7ea6442
committed
fix: correct integer-shift price floor and odd-tick TVL bounds
v3/v4 raw price: move the 2**192 divisor outside the integer shift so
fractional sqrtPriceX96 values are not truncated before the decimal
scaling. (sqrtPriceX96**2 * 10**den1 >> 192) / 10**den0 floors too
early for low-price tokens (e.g. 9.87e-6 returns 9e-6; 4.9e-7 returns
zero and the reciprocal raises ZeroDivisionError). Change to
(sqrtPriceX96**2 * 10**den1) / ((1 << 192) * 10**den0).
get_tvl_in_pool: replace tick // 2 with tick / 2 for the sqrt-price
boundary exponent. Integer floor-division produces wrong results for
odd ticks (fee=100, tick_spacing=1): position [0,1) returns zero
token0 instead of ~4.999625e13; [1,2) doubles; negative odd ticks
also overcount. Floating-point tick / 2 recovers the correct bounds.
Reported by Xamit Kadirbekov and Daniyal Kadirbekov (GERO numerical
software assurance, https://www.gero.uz/research/). Relates to
issue uniswap-python#269 (low-price floor, still open).
Co-Authored-By: Bob <bob@superuserlabs.org>1 parent bc8fdf4 commit 7ea6442
2 files changed
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
740 | 740 | | |
741 | 741 | | |
742 | 742 | | |
743 | | - | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
744 | 746 | | |
745 | 747 | | |
746 | 748 | | |
| |||
1010 | 1012 | | |
1011 | 1013 | | |
1012 | 1014 | | |
1013 | | - | |
| 1015 | + | |
| 1016 | + | |
1014 | 1017 | | |
1015 | 1018 | | |
1016 | 1019 | | |
| |||
1372 | 1375 | | |
1373 | 1376 | | |
1374 | 1377 | | |
1375 | | - | |
1376 | | - | |
| 1378 | + | |
| 1379 | + | |
1377 | 1380 | | |
1378 | 1381 | | |
1379 | 1382 | | |
| |||
1879 | 1882 | | |
1880 | 1883 | | |
1881 | 1884 | | |
1882 | | - | |
1883 | | - | |
| 1885 | + | |
| 1886 | + | |
1884 | 1887 | | |
1885 | 1888 | | |
1886 | 1889 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1635 | 1635 | | |
1636 | 1636 | | |
1637 | 1637 | | |
1638 | | - | |
1639 | | - | |
| 1638 | + | |
| 1639 | + | |
1640 | 1640 | | |
1641 | 1641 | | |
1642 | 1642 | | |
| |||
0 commit comments