javascriptethereumdistributeduniswapdecentralized-applications

Uniswap use SDK to get historical rates (and current rate)


I am trying to use the Uniswap SDK to get historical rates between two coins on a pool. I believe the rate is simply just xy = k, where k is a constant. If someone buys n coins of x, the cost in terms of y coins would be whatever m value that makes the equation (x - n)(y + m) = k still hold.

I've been looking all over the Uniswap's SDK page and can't really find where I can find the historical data regarding this xy = k curve. I think it should be possible, but I'm not exactly sure where to find it.

I'm also looking for how the current swap rate (that is what the current values of x and y are).

I think it can be done via GraphQL, but I'm looking for a solution using the SDK. Can anyone help?


Solution

  • Two options

    You will find some historical Uniswap v3 price tutorial here.