osmojs icon indicating copy to clipboard operation
osmojs copied to clipboard

How to calculate routes for concentrated pools specifically?

Open anilhelvaci opened this issue 1 year ago • 6 comments

Context

I'm trying to build a program that trades on Osmosis. I want to use dynamic routes, meaning don't want to use hard coded routes for my trades.

Problem/Question

I haven't been able to find a method that calculate these routes for me yet. I'm aware of getRoutesForTrade which needs an array called pairs. Here's where the problem(or at least I think) arises because the array pairs is calculated from the pools using the makePoolPairs method. As you can see here the method makePoolPairs filters the pools into gamm pools only.

return pools
    .filter(
      (pool) =>
        pool.poolAssets.length === 2 &&
        pool.poolAssets.every(({ token }) => !token.denom.startsWith("gamm")) &&  // No concentrated liquidity pool allowed
        new BigNumber(calcPoolLiquidity(assets, pool, prices)).gte(liquidityLimit)
    )

I'm also aware that we can fetch the gamm equivalents of these concentratedPools. As application devs;

  • Are we expected to query all gamm pools, calculate routes using those and convert results to concentrated equivalent, if linked?

anilhelvaci avatar Nov 23 '23 16:11 anilhelvaci

@anilhelvaci did you figure this out? How did you get pools and prices that need to be pass here: const pairs = makePoolPairs(pools, prices);

haroondilshad avatar Dec 27 '23 22:12 haroondilshad

Hey @RonCan ✋

did you figure this out?

No, I haven't. I went with hard coding the route.

How did you get pools and prices that need to be pass here: const pairs = makePoolPairs(pools, prices);

You can get all gamm pools from this api => https://docs.osmosis.zone/api/?v=LCD#/operations/Pools

anilhelvaci avatar Dec 29 '23 10:12 anilhelvaci

If you need to do liquidity providing, you can checkout the FE for the main site: https://github.com/osmosis-labs/osmosis-frontend/tree/stage/packages/math/src/pool/concentrated

but it looks like it may be an issue with the actual routes? getRoutesForTrade should take in anything you pass into it

would the solution to be to make another method (or update makePoolPairs) to not filter gamm?

pyramation avatar Jan 08 '24 23:01 pyramation

would the solution to be to make another method (or update makePoolPairs) to not filter gamm?

I think this would be a sufficient approach 👍 @pyramation

anilhelvaci avatar Jan 15 '24 11:01 anilhelvaci

great, we're on it!

pyramation avatar Jan 16 '24 02:01 pyramation

As you can see here the method makePoolPairs filters the pools into gamm pools only.

Hi, I took a look into this. As my understanding, "pool.poolAssets.every(({ token }) => !token.denom.startsWith("gamm")) " makes all gamm out of the result, instead of "filtering the pools into gamm pools only."

Please excuse me if there's misunderstanding.

Could you please provide us more info on this issue like what's the input when unexpected output happened, then we can debug based on the input.

Thank you very much!

Zetazzz avatar Jan 22 '24 17:01 Zetazzz