DEX API
Base URL: /api/defi/dex
Decentralized exchange with AMM-powered swaps and liquidity pools.
Overview
The YaniPay DEX uses an Automated Market Maker (AMM) model with constant product formula (x * y = k). Trade any supported token pair with instant settlement and competitive fees.
Swap Fee
0.3%
Per transaction
LP Fee Share
0.25%
Goes to liquidity providers
Protocol Fee
0.05%
Goes to treasury
YaniChain DEX
Le DEX YaniPay fonctionne nativement sur YaniChain, notre blockchain haute performance optimisée pour les échanges décentralisés. Cette architecture offre des avantages significatifs par rapport aux DEX traditionnels.
AMM Nouvelle Génération
Y.A.N.I. Optimise Vos Swaps
Endpoints
GET /api/defi/dex/pairs
Retrieve all available trading pairs with liquidity and volume data.
curl -X GET "https://api.yanipay.com/api/defi/dex/pairs"Response
{
"pairs": [
{
"id": "yani-usdc",
"token0": {
"symbol": "YANI",
"address": "0x1234...abcd",
"decimals": 18
},
"token1": {
"symbol": "USDC",
"address": "0x5678...efgh",
"decimals": 6
},
"reserve0": "5000000.00",
"reserve1": "2500000.00",
"price": "0.50",
"priceChange24h": "+2.5",
"volume24h": "1250000.00",
"tvl": "5000000.00",
"apy": "45.2"
}
]
}GET /api/defi/dex/quote
Get a swap quote with price impact and minimum output calculation.
curl -X GET "https://api.yanipay.com/api/defi/dex/quote?tokenIn=YANI&tokenOut=USDC&amountIn=1000"Query Parameters
| Parameter | Type | Description |
|---|---|---|
tokenIn | string | Input token symbol |
tokenOut | string | Output token symbol |
amountIn | string | Amount to swap |
slippage | string | Max slippage % (default: 0.5) |
Response
{
"tokenIn": "YANI",
"tokenOut": "USDC",
"amountIn": "1000.00",
"amountOut": "498.50",
"priceImpact": "0.15",
"fee": "3.00",
"minimumReceived": "496.01",
"route": ["YANI", "USDC"],
"expiresAt": "2026-01-25T10:35:00Z"
}POST /api/defi/dex/swap
Execute a token swap.
Slippage Protection
Always set an appropriate slippage tolerance. The transaction will revert if the price moves more than your specified slippage.
curl -X POST "https://api.yanipay.com/api/defi/dex/swap" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tokenIn": "YANI",
"tokenOut": "USDC",
"amountIn": "1000.00",
"minAmountOut": "496.01",
"deadline": "2026-01-25T10:35:00Z"
}'Response
{
"transactionHash": "0xabcd...1234",
"tokenIn": "YANI",
"tokenOut": "USDC",
"amountIn": "1000.00",
"amountOut": "498.25",
"fee": "3.00",
"priceImpact": "0.15",
"executedAt": "2026-01-25T10:30:45Z"
}Liquidity Endpoints
POST /api/defi/dex/liquidity/add
Add liquidity to a pool and receive LP tokens.
curl -X POST "https://api.yanipay.com/api/defi/dex/liquidity/add" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"pairId": "yani-usdc",
"amount0": "1000.00",
"amount1": "500.00",
"slippage": "0.5"
}'Response
{
"transactionHash": "0xefgh...5678",
"lpTokensReceived": "707.10",
"poolShare": "0.0142",
"position": {
"id": "lp_abc123",
"pairId": "yani-usdc",
"lpTokens": "707.10",
"token0Deposited": "1000.00",
"token1Deposited": "500.00",
"currentValue": "1500.00"
}
}POST /api/defi/dex/liquidity/remove
Remove liquidity from a pool by burning LP tokens.
curl -X POST "https://api.yanipay.com/api/defi/dex/liquidity/remove" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"positionId": "lp_abc123",
"lpTokens": "350.00",
"minAmount0": "490.00",
"minAmount1": "245.00"
}'TypeScript Types
1 export interface Token { 2 symbol: string; 3 address: string; 4 decimals: number; 5 name?: string; 6 logoUrl?: string; 7 } 8 9 export interface TradingPair { 10 id: string; 11 token0: Token; 12 token1: Token; 13 reserve0: string; 14 reserve1: string; 15 price: string; 16 priceChange24h: string; 17 volume24h: string; 18 tvl: string; 19 apy: string; 20 } 21 22 export interface SwapQuote { 23 tokenIn: string; 24 tokenOut: string; 25 amountIn: string; 26 amountOut: string; 27 priceImpact: string; 28 fee: string; 29 minimumReceived: string; 30 route: string[]; 31 expiresAt: string; 32 } 33 34 export interface SwapRequest { 35 tokenIn: string; 36 tokenOut: string; 37 amountIn: string; 38 minAmountOut: string; 39 deadline: string; 40 } 41 42 export interface SwapResult { 43 transactionHash: string; 44 tokenIn: string; 45 tokenOut: string; 46 amountIn: string; 47 amountOut: string; 48 fee: string; 49 priceImpact: string; 50 executedAt: string; 51 } 52 53 export interface LiquidityPosition { 54 id: string; 55 pairId: string; 56 lpTokens: string; 57 token0Deposited: string; 58 token1Deposited: string; 59 currentValue: string; 60 unclaimedFees: string; 61 } 62 63 export interface AddLiquidityRequest { 64 pairId: string; 65 amount0: string; 66 amount1: string; 67 slippage: string; 68 } 69 70 export interface RemoveLiquidityRequest { 71 positionId: string; 72 lpTokens: string; 73 minAmount0: string; 74 minAmount1: string; 75 }
Error Handling
400 SLIPPAGE_EXCEEDEDPrice moved beyond slippage tolerance
400 INSUFFICIENT_LIQUIDITYNot enough liquidity for requested swap
400 QUOTE_EXPIREDSwap quote has expired, fetch a new one
400 IMBALANCED_AMOUNTSLiquidity amounts don't match pool ratio
404 PAIR_NOT_FOUNDTrading pair does not exist