-
Notifications
You must be signed in to change notification settings - Fork 12
Description
When user specify assetIn and assetOut on trade page
And best route is found by SDK
We should check on runtime, if route for specified pair is also existing on on chain router.
If route is not existing, check should be done if this is best route also for assetIn value 1% of liquidity for specified asset.
Add to on chain router route, which is best one for 1% of liquidity.
Example:
assetIn (10)
assetOut (0)
route found by SDK:
route:[
0:{
pool:{
Stableswap:"102"
}
assetIn:"10"
assetOut:"102"
}
1:{
pool:"Omnipool"
assetIn:"102"
assetOut:"0"
}
-
Check if route for specified pair is on runtime router:
router.routes(10,0)=>route was not found -
Check if route is best also for 1% of liquidity (check SDK for same asset combination, but assetIn will be amount of 1% of liquidity of specific asset)
How to find out how much liquidity is for specified asset?
Find in which pool assetIn is- either omnipool,stablepool or xyk
Get token balance tokens.accounts(accountId,assetid)- for omnipool accountId is 7L53bUTBbfuj14UpdCNPwmgzzHSsrsTWBHX5pys32mVWM3C1
- for stablepool&xyk its address of the pool (mind decimal points of asset when checking how much of token is in the pool)
- for stablepool, pool address needs to be determined using this function https://github.com/galacticcouncil/HydraDXui/blob/38852e802031ccf9e50c66b0b7e4c107076084de/src/sections/pools/PoolsPage.utils.ts#L50
- calculate 1% of the amount
- get best route from SDK for 1%
-
Add best route returned by SDK (for 1% of liquidity) to on chain router
- Batch add route with trade extrinsic