---
title: "Decentralized Exchange (x/dex)"
sidebarTitle: "Interchain Exchange"
icon: "coins"
tag: "x/dex"
description: "Cross-chain trading through IBC Interchain Accounts with DID-based authorization"
---
import { Card, CardGrid } from '@/components/mdx'
import { Tabs, Tab } from '@/components/mdx'
import { Accordion, AccordionItem } from '@/components/mdx'
import { CodeGroup } from '@/components/mdx'
import { Info } from '@/components/mdx'
# Sonr DEX Module
The Sonr Decentralized Exchange (DEX) module provides a powerful cross-chain trading infrastructure that enables seamless, secure, and self-sovereign trading across the Cosmos ecosystem.
## Overview
Execute swaps on remote DEX chains via Interchain Accounts (ICA)
Add and remove liquidity from pools across chains
All operations authorized through Sonr DIDs
Connect to multiple DEX chains simultaneously
## Core Concepts
The module leverages IBC's Interchain Accounts to create controlled accounts on remote DEX chains. Each account is linked to a Sonr DID and managed through ICA transactions.
All DEX operations require authorization from a valid Sonr DID, ensuring that only authenticated users can perform trading operations.
User-Controlled Authorization Network (UCAN) tokens provide delegated authority for specific operations, enabling secure third-party integrations.
## Trading Operations
```bash
# Execute a swap on Osmosis
snrd tx dex swap \
--did did:sonr:alice \
--connection connection-0 \
--source-denom uosmo \
--target-denom uatom \
--amount 1000000 \
--min-amount-out 950000 \
--ucan-token "eyJ0eXAiOi..." \
--from alice
```
Swap operations are protected against slippage with `min-amount-out` parameter.
```bash
# Provide liquidity to a pool
snrd tx dex provide-liquidity \
--did did:sonr:alice \
--connection connection-0 \
--pool-id 1 \
--assets 1000000uosmo,500000uatom \
--min-shares 100000 \
--ucan-token "eyJ0eXAiOi..." \
--from alice
```
Liquidity providers receive LP tokens proportional to their contribution.
```bash
# Create a limit order
snrd tx dex create-order \
--did did:sonr:alice \
--connection connection-0 \
--sell-denom uosmo \
--buy-denom uatom \
--amount 1000000 \
--price 1.2 \
--expiration "2024-12-31T23:59:59Z" \
--ucan-token "eyJ0eXAiOi..." \
--from alice
```
Limit orders can be created with precise price and expiration settings.
## Security and Performance
All operations require valid DID signatures
Protects against spam and DoS attacks
Fine-grained permissions prevent unauthorized operations
Multiple operations can be executed in a single transaction
## Supported DEX Chains
### Currently Supported
- **Osmosis**: Full swap, liquidity, and order support
- **Crescent**: Swap and liquidity operations
- **Neutron**: Astroport DEX integration
### Planned Support
- **Kujira**: FIN orderbook integration
- **Injective**: Derivatives and spot trading
- **Sei**: High-frequency trading support
## Future Enhancements
- Advanced Order Types (stop-loss, trailing stops)
- Cross-Chain Arbitrage
- Portfolio Management
- Yield Farming Integration
- Derivatives Trading
- MEV Protection
- Analytics Dashboard
- Social Trading Features
## Technical Details
```protobuf
message MsgExecuteSwap {
string did = 1; // DID initiating the swap
string connection_id = 2; // IBC connection to DEX chain
string source_denom = 3; // Token to swap from
string target_denom = 4; // Token to swap to
string amount = 5; // Amount to swap
string min_amount_out = 6; // Minimum amount out (slippage protection)
}
```
```go
// Per-block rate limiting
if opsThisBlock >= params.RateLimits.MaxOpsPerBlock {
return errorsmod.Wrap(ErrRateLimited, "max operations per block exceeded")
}
```
## Getting Started
### Integration Guide
1. **Account Setup**: Register ICA accounts for target DEX chains
2. **Permission Management**: Issue UCAN tokens for specific operations
3. **Execute Trades**: Use the module's messages to perform DEX operations
4. **Monitor Activity**: Subscribe to events for real-time updates
5. **Query State**: Use queries to display balances and history
## Development
```bash
# Run unit tests
make test-dex
# Run integration tests with IBC
make test-dex-ibc
# Start local chain with ICA enabled
make localnet-dex
```