jeiwan / uniswapv3-book Goto Github PK
View Code? Open in Web Editor NEWUniswap V3 Development Book
Home Page: https://uniswapv3book.com/
Uniswap V3 Development Book
Home Page: https://uniswapv3book.com/
In https://uniswapv3book.com/docs/milestone_1/calculating-liquidity/, Its mentioned below formula to calculate tick
Thus, we can find tick
It should be
Hello, your topics helped me a lot in my area of development and understanding of fundamental things. Looking forward for version 3 of Uniswap.
In the bottom of this page, price range should be corrected from [
If I understand correctly, since
(Edit for correct math expression.)
Thanks for uniswap v3 guide. It's extremely useful.
I noticed in your book you refer to the ticket spacing as being used for pool identification and path creation:
https://uniswapv3book.com/docs/milestone_4/path/
It seems like uniswap uses the fee to identify pools:
https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol#L33
Am I reading this wrong or is this part of the docs off?
Unfortunately, it's not possible to launch the server locally due to an error when building the site.
$ hugo server -D
Watching for changes in /Users/leovct/Documents/learn/uniswap/uniswapv3-book/{archetypes,content,static}
Watching for config changes in /Users/leovct/Documents/learn/uniswap/uniswapv3-book/config.toml
Start building sites …
hugo v0.118.2-da7983ac4b94d97d776d7c2405040de97e95c03d+extended darwin/amd64 BuildDate=2023-08-31T11:23:51Z VendorInfo=brew
Built in 27 ms
Error: error building site: assemble: "/Users/leovct/Documents/learn/uniswap/uniswapv3-book/content/docs/introduction/constant-function-market-maker.md:163:1": failed to extract shortcode: template for shortcode "katex" not found
Clone the repo and the theme submodule to make it work using:
git clone https://github.com/Jeiwan/uniswapv3-book --recurse-submodules
.
As the title, is it possible to create a pdf version of this wonderful book?
Regards
In the following snippet, shouldTransferInCallback should be set before pool.mint()
uniswapv3-book/content/docs/milestone_1/providing-liquidity.md
Lines 459 to 485 in 7b6cc62
Otherwise the callback will not send the funds from the test contract to the pool contract and the assertions will fail.
I have been using the v3 Book a lot recently and I really appreciate the effort put in.
I recently spend some time integrating the tick bitmap and tick bitmap lens, and I spent some time confused by the results I was getting from the queries. I was able to clarify my misunderstanding by looking at the tick lens code, but thought some clarification in the book might help others. The issue I had was the following:
I was trying to use the bitmap and the bitmap lens to find initialized ticks around the current price tick. I was taking the current tick from the slot0
query and trying to find the associated word in the bitmap by integer dividing by 256; when I did this, I was always getting 0 for the bitmap result (no initialized ticks in word) even thought I knew there were initialized ticks around the current tick. In reality, the bitmap only indexes spaced ticks (i.e. ticks evenly divisible by tickSpacing
) and I had to first integer divide the current tick by tickSpacing
before dividing by 256.
The Tick Bitmap Index
page does a great job of explaining the bitmap, but since the explainer uses a tick spacing of 1, I think this step gets a little bit lost. Also, since the width of the tick index is 24 bits and the word index (16 bits) and bit array (8 bits) sum to that, I think it's easy to assume the bitmap is sparse. There is a disclaimer that the tick spacing is 1, but I think readers could benefit from an explanation that tick spacing must be collapsed to find the correct bitmap index.
I am happy to give it a shot if the maintainers would prefer a pull request over an issue. Thanks for the good work!
hi @Jeiwan, thanks for the great book!
After dived into the book and the source code, i still can't figure out why tick.feeGrowthOutside0X128
and tick.feeGrowthOutside1X128
are initialized as follows:
function update(
mapping(int24 => Tick.Info) storage self,
int24 tick,
int24 tickCurrent,
int128 liquidityDelta,
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128,
uint160 secondsPerLiquidityCumulativeX128,
int56 tickCumulative,
uint32 time,
bool upper,
uint128 maxLiquidity
) internal returns (bool flipped) {
// ......
if (liquidityGrossBefore == 0) {
// by convention, we assume that all growth before a tick was initialized happened _below_ the tick
if (tick <= tickCurrent) {
info.feeGrowthOutside0X128 = feeGrowthGlobal0X128;
info.feeGrowthOutside1X128 = feeGrowthGlobal1X128;
info.secondsPerLiquidityOutsideX128 = secondsPerLiquidityCumulativeX128;
info.tickCumulativeOutside = tickCumulative;
info.secondsOutside = time;
}
info.initialized = true;
}
// ......
}
Uniswap V3 whitepaper section 6
i tried to verify the swap fee accumulating process in my head, everything goes well until new ticks are initialized.
I must have misunderstood something!
thank you!
I am probably missing some point here, but after reading your article, still don't understand.
I copied a random position from the USDC/ETH 0.3% Ethereum mainnet pool. By simply running your price_to_tick
function over this 1900
price it yields a totally different tick price. Can you please elaborate what am I missing here?
Thanks,
Adrian
EDIT: 0.05% -> 0.3%
In this line instead of TickMath.nextInitializedTickWithinOneWord
it sould be TickBitmap.nextInitializedTickWithinOneWord
(nextInitializedTickWithinOneWord
function is in TickBitmap
library)
The code doesn't include import statements. This might be obvious to experienced solidity devs, but is confusing to learners and prevents the LSP functionality of some editors from working until fixed.
In book you use lower price 4545$, so sqrt from P * 2 * * 96 will be 5341294542274603406682713227264 (in book it is 5314786713428871004159001755648)
import math
q96 = 2**96
def price_to_sqrtp(p):
return int(math.sqrt(p) * q96)
print (price_to_sqrtp(4545))
5341294542274603406682713227264
I don't know, mb error in define lower price. If you want assign it to 4500, then it will be correct.
import math
q96 = 2**96
def price_to_sqrtp(p):
return int(math.sqrt(p) * q96)
print (price_to_sqrtp(4500))
5314786713428871004159001755648
Hello!
While following the miltestone_1 (https://uniswapv3book.com/docs/milestone_1/providing-liquidity/), at the end of the mint, we are expected to emit an event mint to inform the blockchain.
However, in the above code snippets/explanation, the declaration of the said event is missing.
event Mint(
address sender,
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
```
Hello, thank you for a great work!
Could you please explain why are you multiplying the USDC amount by ETH decimals (10^18) in the line 58 of unimath.py
example?
amount_usdc = 5000 * eth
And not by 10*(18-6)=10^12
?
I tested it on actual Uniswap position and the numbers matched with 10*12
.
In chapter 18 (generalized swapping), eventually swapMath.computeSwapStep is called with an argument: liquidity. Liquidity is not referenced / defined thus far. A look at the code indicates that liquidity should be an part of SwapState, yet SwapState, which is defined for the first time in this chapter does not have liquidity as a field.
As far as I understand it after looking at the code in the repo it is simply the current total liquidity in the pool. However the chapter does need revisions to clarify this for future readers so they don't need to go looking at the code.
The book has been a joy to follow along with btw :)
After following the whole book, I can almost understand all the code in the uniswapv3-code repo. But when reading the real uniswap v3 code repo, I found there is still some difference between it and our implementation, and there are some contracts we don't have(like V3Migrate, MultiCall, PeripheryPaymentWithFee, difference between QuoterV1&V2... etc.)
I'm wondering if it's convenient to add a section about the structure of the real V3 contracts, some contracts we do not have and their function, analyze some real transactions on Uniswap V3, etc. This would bring us closer to the real-world.
(And I know the repo is just for learning and not ready for deployment in real world. So maybe want some advice about wahat else we need to do&consider to make it a real system?)
Context
The code instructions from https://uniswapv3book.com/docs/milestone_1/calculating-liquidity/ are missing:
eth = 10**18
....
amount_eth = 1 * eth
amount_usdc = 5000 * eth
While I could look in this repo for the answer, it wasn't apparent with high certainty why my calculations weren't working.
Therefore, I propose adding the above code snippets to the linked page for a better UX.
Originally posted by said017 February 15, 2023
Hi,
I'm wondering if the statement number 4 in trade function explanation is true "The pool also takes a small fee (r) from the amount of token 0 we gave", should'nt it supposed to be r = 1 - swap fee ?
I really love this book and want to promote it to the Chinese community. May I translate it into Chinese (of course after your proofreading)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.