Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,42 @@ npm run start
# 3. Run the CORS verification script (in a new terminal)
node test-cors.js
```

## 📊 API Endpoints

### TVL Statistics

Get Total Value Locked (TVL) metrics for the TradeFlow protocol.

#### `GET /api/v1/stats/tvl`

Returns the current TVL in USD with optional formatting.

**Response Format:**
```json
{
"tvlUSD": 14500000.50,
"lastUpdated": "2026-03-19T00:00:00Z"
}
```

**Query Parameters:**
- `format` (optional): Set to `short` to return formatted TVL (e.g., "14.5M")

**Examples:**

```bash
# Get full TVL data
curl http://localhost:3000/api/v1/stats/tvl

# Get formatted TVL for display
curl http://localhost:3000/api/v1/stats/tvl?format=short
```

**Short Format Response:**
```json
{
"tvlUSD": "14.5M",
"lastUpdated": "2026-03-19T00:00:00Z"
}
```
26 changes: 0 additions & 26 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,26 +0,0 @@
import { Module } from '@nestjs/common';
import { APP_GUARD, APP_FILTER } from '@nestjs/core';
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { HealthModule } from './health/health.module';
import { RiskModule } from './risk/risk.module';
import { AuthModule } from './auth/auth.module';
import { TokensModule } from './tokens/tokens.module';

@Module({
imports: [HealthModule, RiskModule, AuthModule, TokensModule],
controllers: [AppController],
providers: [
AppService,
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
{
provide: APP_FILTER,
useClass: ThrottlerExceptionFilter,
},
],
})
export class AppModule { }
36 changes: 36 additions & 0 deletions src/stats/stats.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Controller, Get, Query } from '@nestjs/common';

@Controller('api/v1/stats')
export class StatsController {
@Get('tvl')
async getTVL(@Query('format') format?: string) {
const staticTVL = 14500000.50;
const lastUpdated = '2026-03-19T00:00:00Z';

if (format === 'short') {
// Format as "14.5M" for short display
const formattedTVL = this.formatTVL(staticTVL);
return {
tvlUSD: formattedTVL,
lastUpdated,
};
}

return {
tvlUSD: staticTVL,
lastUpdated,
};
}

private formatTVL(amount: number): string {
if (amount >= 1000000000) {
return `${(amount / 1000000000).toFixed(1)}B`;
} else if (amount >= 1000000) {
return `${(amount / 1000000).toFixed(1)}M`;
} else if (amount >= 1000) {
return `${(amount / 1000).toFixed(1)}K`;
} else {
return amount.toString();
}
}
}
7 changes: 7 additions & 0 deletions src/stats/stats.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { StatsController } from './stats.controller';

@Module({
controllers: [StatsController],
})
export class StatsModule {}
Loading