← Protocols
Osmosis
01Description

Osmosis is the largest AMM and cross-chain DEX in the Cosmos ecosystem, featuring concentrated liquidity (Supercharged Pools), classic xy=k pools, stableswap, and a built-in token-factory. Liquidity is sourced via IBC from 50+ chains and routed through the Sidecar query server for best-execution swaps.

02Best for
  • 01Cosmos AMM swaps and routing
  • 02concentrated-liquidity LP positions
  • 03IBC-native token listings via tokenfactory
  • 04yield farming with superfluid staking
  • 05permissionless pool creation
03Install
  • pnpm add osmojs @cosmjs/stargate @cosmjs/proto-signing
04Environment variables
VariableScopeDescription
OSMOSIS_RPC_URLClientOsmosis Tendermint RPC endpoint (e.g., `https://rpc.osmosis.zone`). Required for SigningStargateClient construction.
OSMOSIS_LCD_URLClientOsmosis REST/LCD endpoint (e.g., `https://lcd.osmosis.zone`) for queries. Optional if you only use RPC.
05Prompt snippet
Use `osmojs` for Osmosis-specific message types and queries. Build a signer with `getOfflineSigner` from a Keplr/Leap wallet, then `osmosis.ClientFactory.createRPCQueryClient({ rpcEndpoint })` for queries and `getSigningOsmosisClient({ rpcEndpoint, signer })` for txs. Swaps go through `osmosis.poolmanager.v1beta1.MessageComposer.withTypeUrl.swapExactAmountIn({ sender, routes, tokenIn, tokenOutMinAmount })` — resolve the optimal `routes` via the Sidecar `/router/quote` HTTP endpoint, never hard-code pool IDs. For concentrated liquidity use `osmosis.concentratedliquidity.v1beta1.MsgCreatePosition` with explicit lower/upper ticks. Always set `gasPrice: GasPrice.fromString('0.025uosmo')` and simulate with `client.simulate(...)` before broadcasting.
06Gotchas
  • Pool IDs and tick spacing change over time — always fetch the active route from the Sidecar router (`https://sgw.osmosis.zone/router/quote`) instead of hard-coding pool IDs; stale routes lead to failed swaps or terrible execution.
  • Concentrated-liquidity positions require funds in the EXACT ratio implied by current price within the chosen tick range; off-ratio inputs are silently rounded and the leftover stays in the wallet.
  • OsmoJS major versions track Osmosis chain upgrades (e.g., v16 'Nebula', v22, v25, v26). After every chain upgrade you must bump `osmojs` to a compatible version or new message types will be unrecognized; CI-pin the version.
  • IBC-deposited tokens have path-dependent `ibc/...` denoms — the same USDC routed via Noble vs. Axelar is non-fungible. Show the path to users and use the canonical Noble route for stables.
  • Slashing risk for superfluid-staked LPs: if the validator delegated to is slashed, your LP shares are slashed proportionally; diversify validator selection and monitor signing.
  • Gas token is `uosmo` (1 OSMO = 1_000_000 uosmo). Some endpoints accept fee-grant or alternative fee tokens via the txfees module; do not assume only OSMO works but always default to OSMO for reliability.
  • Swap slippage is enforced by `tokenOutMinAmount`, not a percentage — compute it client-side from the quoted out amount; passing 0 risks sandwich-style MEV losses.
07Alternatives