joshstevens19 / simple-uniswap-sdk

Uniswap SDK which handles the routes automatically for you, changes in trade quotes reactive subscriptions, exposure to formatted easy to understand information, bringing back the best trade quotes automatically, generating transactions for you and much more.
MIT License
190 stars 94 forks source link

Liquidity pool support? #32

Open elhaix opened 2 years ago

elhaix commented 2 years ago

This SDK has made exchanging tokens easier in Metamask, thank you.

I'm looking for liquidity pool support, where I can get real usable price comparison data for arbitrage opportunities. I see a pools reference in src/factories/uniswap-factory/v3/uniswap-contract.factory.v3.ts but I don't see any related examples. Any additional info on this for this SDK please, and if so, how cold I subscribe to a pool price update event?

Or am I really completely missing something here?

joshstevens19 commented 2 years ago

So plan would be to find out how much liquidity would be on a pair? If so have plans to support this soon! Interested in how you would want it to work? You talked about a subscription on the pool.. would you want it to emit when liquidity changes?

elhaix commented 2 years ago

Hey there. I'm not sure if finding out liquidity is what I'm looking for (maybe just terminology)?

I've been struggling to find REALLY GOOD useful v3 examples. Many videos and articles will do one lookup, or something simple. In addition, I have been struggling to get the v3 guides (https://docs.uniswap.org/sdk/guides/creating-a-pool) converted to/running in JS/Node.

I have come across a good example that subscribes to the event of a pair contract. However this is a v2 implementation: Uniswap token price monitoring (this is not swapping), i.e. ETH/DAI https://www.youtube.com/watch?v=j_wVh_Sa1rU https://github.com/RudreshVeerkhare/UniswapPriceMonitor

// subscribe to Sync event of the pair contract
// When the event occurs call updateState()
PairContractWSS.events.Sync({}).on("data", (data) => updateState(data));    // Event Listener - callback to updateState()

In v3, how would you do this for say, 50 pools?

Still with ongoing confusion, firmly in place, I've been trying to convert this to v3 with no success yet. Is this actually showing the cost of a potential swap on a pool, and are the numbers usable for assessing an arbitrage opportunity on a different network, i.e. Kyber, Sushiswap, etc.? "pair" or "liquidity pool -> factory -> finally do stuff with it" in v3 ( actually, talking about it, I'm going to revisit my conversion project) ?

In calculating the amount for a pool in a given feeTier, you also need to provide ticks for a smoother rate within a time envelope, as I understand it (also are there numerous ways to get this figure?). https://www.youtube.com/watch?v=nCtJ0eqaEf0. Off the top of my head, some abstraction to ticks would be good where the input would easily set a time range and do that square root calculation thingy.

It's not enough to do the following in how I have seen in v2 examples and in the price-bot below:

x is the amount of token0, y is the amount of token1 price of token0 in terms of token1 P = y / x

This is how the token price is calculated in another example, which uses polling to get prices (v2) of various pairs. Another which would be good to convert to v3 and use an event subscriber:

https://github.com/dappuniversity/price-bot/blob/master/index.js

There also seems to be lack of documentation and responses on ethereum.stackexchange.com and Discord on several items. For example, the Subgraph shows "subscription" but how can we actually use the subgraph to subscribe to events? I haven't seen any examples and the only example for event subscription I could find is above, in v2.

I've been stitching together several concepts to:

I keep jumping around in a lot of areas to get this project completed and open to recommendations and a continuing dialogue!