# Key Concepts

### ⚠️ Important: Quotes simulation  <a href="#important-wallet-connection" id="important-wallet-connection"></a>

> **🔒 Connect your wallet to get real, pre-simulated pricing from the Ooga Booga backend.**
>
> **Without wallet connection, quotes may be spoofed or manipulated by aggregators.** Connected wallets receive verified quotes that reflect actual execution prices.

#### 🌐 Quote Stream API <a href="#quote-stream-api" id="quote-stream-api"></a>

The application connects to a streaming API for real-time swap quotes:

```typescript
const AGGREGATOR_BASE_URL = 'https://hyperevm.api.oogabooga.io/meta/stream/swap'
```

**Supported Parameters**

| Parameter     | Type      | Description                                 |
| ------------- | --------- | ------------------------------------------- |
| `tokenIn`     | string    | Input token address                         |
| `tokenOut`    | string    | Output token address                        |
| `amount`      | string    | Amount to swap (in token units)             |
| `maxSlippage` | string    | Maximum acceptable slippage (default: 0.01) |
| `to`          | string    | Recipient address                           |
| `aggregators` | string\[] | Specific aggregators to query               |

#### 📡 Event Types <a href="#event-types" id="event-types"></a>

The SSE stream emits the following events:

* **`connected`** - Initial connection established
* **`quote`** - New quote data received
* **`error`** - Error occurred during streaming
* **`heartbeat`** - Keep-alive signal

#### 📊 Quote Data Structure <a href="#quote-data-structure" id="quote-data-structure"></a>

Each quote contains comprehensive swap information:

```typescript
interface QuoteResponse {
  aggregator: string;
  quote: {
    status: string;
    amountIn: string;
    amountOut: string;
    fee: string;
    value: string;
    aggregator: string;
    routerAddr: string;
    calldata: string;
    gas: string;
    simulationAmountOut: string;
    priceImpact: number;
  };
  timestamp: number;
}
```

### 🔧 Usage Examples <a href="#usage-examples" id="usage-examples"></a>

#### Basic Quote Stream Implementation <a href="#basic-quote-stream-implementation" id="basic-quote-stream-implementation"></a>

```typescript
import { useQuoteStream } from '@/hooks/use-quote-stream'

const QuoteStreamComponent = () => {
  const { isConnected, latestQuote, error } = useQuoteStream({
    chainId: 999, // HyperEVM chain ID
    params: {
      tokenIn: '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb', // USDT
      tokenOut: '0x0000000000000000000000000000000000000000', // HYPE
      amount: '10000000', // 10 USDT
      maxSlippage: '0.5',
    },
    enabled: true
  })

  if (!isConnected) {
    return <div>🔄 Connecting to quote stream...</div>
  }
  
  if (error) {
    return <div>❌ Error: {error.message}</div>
  }
  
  return (
    <div>
      <h3>📊 Latest Quote</h3>
      <pre>{JSON.stringify(latestQuote, null, 2)}</pre>
    </div>
  )
}
```
