Taking Smart Notes With Org-mode
  • About
  • Articles
  • Notes
  • Search
Home » Notes

Uniswap V3

August 25, 2022 · 1 min · Gray King
  • tags: Uniswap
  • The Graph: Uniswap V3 Subgraph

Links to this note


    Uniswap Tick Boundary To Liquidity Amounts

    tags: Uniswap Tick To Price, Uniswap V3 import math tick_upper_bits = 4294945516 tick_lower_bits = 4294931656 tick_curre_bits = 4294938547 sqrtp_low = price_to_sqrtp(uint32_tick_to_price(tick_lower_bits)) sqrtp_cur = price_to_sqrtp(uint32_tick_to_price(tick_curre_bits)) sqrtp_upp = price_to_sqrtp(uint32_tick_to_price(tick_upper_bits)) def calc_amount0(liq, pa, pb): if pa > pb: pa, pb = pb, pa return int(liq * q96 * (pb - pa) / pa / pb) def calc_amount1(liq, pa, pb): if pa > pb: pa, pb = pb, pa return int(liq * (pb - pa) / q96) liq = 8599967722 amount0 = calc_amount0(liq, sqrtp_upp, sqrtp_cur) amount1 = calc_amount1(liq, sqrtp_low, sqrtp_cur)

    November 19, 2024 · 1 min · Gray King

    Uniswap Tick To Price

    tags: Uniswap V3 def tick_to_price(tick: int) -> float: return 1.0001 ** tick def uint32_tick_to_price(bits: int) -> float: # https://stackoverflow.com/a/20766900 u = bits & ((1 << 32) - 1) tick = (u & ((1 << 31) - 1)) - (u & (1 << 31)) return 1.0001 ** tick q96 = 2**96 def price_to_sqrtp(p): return int(math.sqrt(p) * q96)

    November 19, 2024 · 1 min · Gray King

    Uniswap V3 Event Log

    tags: Uniswap V3, Ethereum POST https://rpc.ankr.com/eth Content-Type: application/json { "jsonrpc": "2.0", "id": 1, "method": "eth_getTransactionReceipt", "params": ["0xeedf302cc12f4b7194742694aabec075c1c229f7b9d8e57a53c44c992bc6690c"] }

    July 31, 2023 · 1 min · Gray King

    DeFi from Scratch

    tags: DeFi, Blockchain, Uniswap, Uniswap V3 I need derive price from decentralized exchanges, and I have finished some research about Uniswap v3. It’s brand new for me, and after that I want to share some ideas about DeFi, and I think it would be helpful for you to understand Uniswap and some other decentralized exchanges. DeFi from Scratch We exchange stuffs very often, and we can exchange tokens in a centralized exchange. For example, Alice owns some ETH, and Bob owns some DAI. Now, Alice want to swap some ETH for DAI, and Bob want to swap some DAI for ETH. How could they do? ...

    August 25, 2022 · 3 min · Gray King

    Uniswap V3 Tick

    tags: Uniswap V3 source: Shao, 田少谷. “Uniswap v3 Features Explained in Depth.” Taipei Ethereum Meetup (blog), July 20, 2021. https://medium.com/taipei-ethereum-meetup/uniswap-v3-features-explained-in-depth-178cfe45f223. Tick is a price range Each tick is a price range with upper bound and lower bound. Tick price from index: \(p(i) = 1.0001 ^ i\) 1.0001 ** 138162 # 999_998 Tick index from price: \(log_{1.0001}p\) import math math.log(1000_000, base=1.0001) # 138162.01321981344

    August 25, 2022 · 1 min · Gray King
© 2025 Taking Smart Notes With Org-mode · Powered by Hugo & PaperMod