Coder Social home page Coder Social logo

isnan909 / uniswapv3-calculator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from normdoow/uniswap.fish

0.0 1.0 0.0 1.86 MB

Uniswap V3 Fee Calculator created with React & Typescript

Home Page: https://uniswapv3.thechun.dev

HTML 3.75% CSS 1.08% TypeScript 92.96% JavaScript 2.20%

uniswapv3-calculator's Introduction

๐Ÿฆ„ UniswapCalculator

Uniswap V3 Fee Calculator created with React & Typescript, Visit: uniswapv3.thechun.dev

Disclaimer: please do your own research, this website is intended to be used and must be used for informational purpose only. It is very important to do your own analysis before making any investment based on your personal circumstances.

Screenshot

Report a bug or request a feature

Features

  • Fee calculation: select pair and pool, input deposit amounts, and adjust your lower and upper price
  • Liquidity position histogram and correlation chart to help you plan your strategy better
  • It's 100% open source! hope that Uniswap community will bring a lot more ideas and features to this project

Calculation Breakdown

Please correct me if I'm wrong

1. Calculate deposit amounts of token0 and token1

  • Refer to Uniswap V3 Whitepaper (Formula: 6.29, 6.30, P.8), we can calculate total amounts of each token by using these formulas: (if il <= ic < iu; where il = lowerTickId, ic = currentTickId, iu = upperTickId)
    • deltaY = deltaL * (sqrt(P) - sqrt(Pl))
    • deltaX = deltaL * (1 / sqrt(P) - 1 / sqrt(Pu))
  • For estimation of the amounts of token0 (deltaX) and token1 (deltaY) we need to know deltaL that make:
    • deltaY * priceUSDY + deltaX * priceUSDX = targetAmounts
  • So we can write a equation like this:
    • deltaL * (sqrt(P) - sqrt(Pl)) * priceUSDY + deltaL * (1 / sqrt(P) - 1 / sqrt(Pu)) * priceUSDX = targetAmounts
    • Then: deltaL = targetAmounts / (sqrt(P) - sqrt(Pl)) * priceUSDY + (1 / sqrt(P) - 1 / sqrt(Pu)) * priceUSD
  • After we've calculated deltaL, we can calculate deltaX and deltaY using these formulas mentioned in Uniswap v3 Whitepaper
    • deltaY = deltaL * (sqrt(P) - sqrt(Pl)) (Formula: 6.29, P.8)
    • deltaX = deltaL * (1 / sqrt(P) - 1 / sqrt(Pu)) (Formula: 6.30, P.8)

2. Calculate estimated fee

  • Estimated fee (daily) can be calculated by this equation:
    • fee = feeTier * volume24H * (deltaL / (L + deltaL)) where:
      • volume24H = average of 24h volume from [currentDay - 4, currentDay - 1]
      • L = total liquidity (cumulative of liquidityNet from all ticks that il <= ic)
      • deltaL = delta liquidity, can be calculated from:
        • liquidityAmount0 = amount0 * (sqrt(pu) * sqrt(pl)) / (sqrt(pu) - sqrt(pl))
        • liquidityAmount1 = amount1 / (sqrt(pu) - sqrt(pl))
        • if ic < il; deltaL = liquidityAmount0
        • if ic > iu; deltaL = liquidityAmount1
        • if ic >= il && ic <= iu; deltaL = min(liquidityAmount0, liquidityAmount1)

Crafted with ๐Ÿงก by @chunza2542

uniswapv3-calculator's People

Contributors

chunrapeepat avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.