---
# System prepended metadata

title: Swap Osmosis

---

# Swap Osmosis

## How I find the right route for swaping with two tokens

- Get all pools
- Keep only pools with 2 assets
- Keep only pools that have `@type` `/osmosis.gamm.v1beta1.Pool`
- Keep only pools that have existing tokens from `@cosmology/core/src/assets`
- Keep only pools that include at least one of the two tokens
.
- (Direct) For all direct pools found, keep the one with the highest liquidity
.
- (Multihop) If no direct pool found, keep only pools that include at least 1000000 `uosmo`
- (Multihop) Keep only pools with `liquidity` > 10000000000 (Property `liquidity` from `PrettyPool`)
- (Multihop) Find two pools that include firstToken+OSMO and OSMO+secondToken
- (Multihop) Keep only the two cheapest pools (Property `poolParams.swapFee` from `LcdPool`)
.
- If both Direct pool and Multihop possible, find the cheapest way (`poolParams.swapFee`)

## Miscelaneous issues

- Balances from `https://lcd.osmosis.zone/cosmos/bank/v1beta1/balances/WALLET_ADDRESS` take time to be updated.
=> `osmosis-frontend` got balances from `@keplr-wallet`
- Spot price takes time and fails randomly
- Swap takes time
- `https://rpc.osmosis.zone/` gives 504 sometimes
- White screen sometimes (If calls takes too much time, or if Reject Swap TX manually)

- VERY laggy
- Need to refactor `ToastError` and `ToastSuccess` to allow to display them everywhere, not only under the modals, not only above the modals.
- Didn't find how to determine "Price impact"


## Import / libs errors

- I need osmosis assets to use multihop : We don't want to use pools that have unknown assets, so I do :
`import { assets as osmosisAssets } from "@cosmology/core/src/assets";`. But error (Even if it works).

- I use `new OsmosisApiClient` to `getPools`. The types of these pools is `LcdPools` from `@cosmology/core`.
But some properties have underscore, like `pool_assets`. Except that `LcdPool` has properties like `poolAssets`. So I have to "clean" my fetched pools !
**=> ISSUE OPENED : https://github.com/cosmology-tech/cosmology/issues/26**

- `PriceHash` has an error in `@cosmology/core/src/types`, so I have an error when I try to build a `PriceHash` like `prices[asset.token.denom]` (Even if it works)

## Osmosis UI errors

- Broken Price Impact here ? 
![](https://i.imgur.com/WEw0BZ7.png)