npm package: @pioneer-platform/e2e-endpoint-charts
Description: Advanced charts endpoint performance testing
Latest version: 1.0.2

# Charts Endpoint Testing

Performance and integration tests for Pioneer Server charts endpoints.

## Current Status: ⚠️ API MISMATCH DISCOVERED

### Issue Found

The `/api/v1/charts/portfolio` endpoint has a **different API structure** than expected:

**Current API** (Single network/address):
```json
{
  "networkId": "eip155:1",
  "address": "0x141D9959cAe3853b035000490C03991eB70Fc4aC"
}
```

**Expected API** (Multi-chain like portfolio endpoint):
```json
{
  "pubkeys": [
    { "pubkey": "0x141D9959cAe3853b035000490C03991eB70Fc4aC", "caip": "eip155:1/slip44:60" },
    { "pubkey": "cosmos1...", "caip": "cosmos:cosmoshub-4/slip44:118" }
  ]
}
```

### What the SDK Does

The Pioneer SDK's `app.getCharts()` method:
1. Processes multiple blockchains automatically
2. Takes 30+ seconds to complete
3. Likely calls `/charts/portfolio` once per chain

### Performance Problem

The slowness is caused by:
- **Sequential API calls**: One request per blockchain chain instead of batch
- **No batching**: Each chain requires a separate HTTP request
- **No caching coordination**: Multiple chains can't share cache hits

## Available Endpoints

Based on Swagger spec analysis:

```
/charts/portfolio       - Single network portfolio (networkId + address)
/charts/customtokens    - Custom token charts
/charts/stablecoins     - Stablecoin-specific charts
```

## Recommendations

### Option 1: Create Batch Endpoint
Add `/charts/portfolio/batch` endpoint accepting multiple pubkeys:
```json
{
  "pubkeys": [
    { "pubkey": "0x...", "caip": "eip155:1/slip44:60" },
    { "pubkey": "cosmos1...", "caip": "cosmos:cosmoshub-4/slip44:118" }
  ]
}
```

**Benefits**:
- Matches portfolio endpoint pattern
- Single HTTP round-trip
- Better cache coordination
- Parallel backend processing

### Option 2: SDK Optimization
Update SDK to:
- Call charts endpoints in parallel (Promise.all)
- Cache results locally
- Use HTTP/2 multiplexing

### Option 3: GraphQL/Streaming
Consider GraphQL or Server-Sent Events for:
- Subscription-based updates
- Progressive rendering
- Real-time balance updates

## Test Structure

The test suite is ready but needs the correct endpoint:

```bash
cd /Users/highlander/WebstormProjects/keepkey-stack/projects/pioneer/e2e/endpoint/charts

# Install dependencies
bun install

# Run tests
bun run test
```

### Test Features

- ✅ Performance benchmarking (cold vs cached)
- ✅ Multi-chain testing
- ✅ Response structure validation
- ✅ Bottleneck identification
- ✅ Server log diagnostics
- ⚠️  Waiting for correct API endpoint

## Next Steps

1. **Decide on API design**: Batch endpoint vs. optimization
2. **Implement chosen solution** in pioneer-server
3. **Update tests** to match new API
4. **Verify 10x+ performance improvement**

## Files

- `src/index.ts` - Main test suite (currently incompatible with API)
- `package.json` - Dependencies and scripts
- `tsconfig.json` - TypeScript configuration
- `README.md` - This file

## Related

- Portfolio tests: `../portfolio/`
- Pioneer Server: `/services/pioneer-server/`
- Charts controller: `/services/pioneer-server/src/controllers/charts.controller.ts`