Uniswap V3 Current value of Positions

    What is the token value and USD value of open positions as of the most recent block?

    Take a position, you can use the positions table, and then merge in the current price of the pool from pool_stats. Then you will have current_price_0_1 (price), liquidity_adjusted (L), price_lower_0_1 (lower) and price_upper_0_1 (upper). Use this formula/ logic to calculate amounts, then convert to USD.

    if (price <= lower) {
    amount0 = L / sqrt(lower) - L / sqrt(upper)
    amount1 = 0
    } else if (price < upper) {
    amount0 = L / sqrt(price) - L / sqrt(upper)
    amount1 = L * sqrt(price) - L * sqrt(lower)
    } else {
    amount1 = L * sqrt(upper) - L * sqrt(lower)
    amount0 = 0
    }

    Loading...