Skip to content

Commit bccf33b

Browse files
committed
refactor: simplify getTotalTvl API and update related documentation
1 parent 5002c0f commit bccf33b

6 files changed

Lines changed: 31 additions & 42 deletions

File tree

apps/api/src/config/openapi.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,10 @@ export const openApiSpec = {
584584
get: {
585585
summary: "Get platform TVL",
586586
description:
587-
"Returns the total TVL across all vaults, or for a specific vault, sourced from the Aarna engine database.",
587+
"Returns the total TVL across all vaults, sourced from the Aarna engine database.",
588588
operationId: "getTotalTvl",
589589
tags: ["Analytics"],
590-
parameters: [
591-
{
592-
name: "address",
593-
in: "query",
594-
required: false,
595-
description: "Filter to a specific vault address (omit for platform-wide total)",
596-
schema: { type: "string", example: "0xabc123..." },
597-
},
598-
],
590+
parameters: [],
599591
responses: {
600592
"200": {
601593
description: "TVL data",

apps/api/src/config/vault-registry.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ class VaultRegistry {
3636
const vaults = await this.getVaults();
3737
return Object.fromEntries(
3838
vaults.map((v) => {
39-
const key =
40-
v.depositContractType === DepositContractType.ERC4626 &&
41-
v.contracts.timelock?.address
42-
? v.contracts.timelock.address.toLowerCase()
43-
: v.atvTokenAddress.toLowerCase();
39+
const key = v.atvTokenAddress.toLowerCase();
4440
return [key, v];
4541
}),
4642
);

apps/api/src/handlers/analytics.handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { UserInvestmentsQuery } from '../types/api.types';
44

55
export const analyticsHandler = {
66
getTotalTvl: async (
7-
req: Request<{}, {}, {}, { address?: string }>,
7+
req: Request,
88
res: Response,
99
next: NextFunction,
1010
) => {
1111
try {
12-
const data = await engineService.getTotalTvl(req.query.address);
12+
const data = await engineService.getTotalTvl();
1313
res.json({ data, message: 'Total TVL retrieved', statusCode: 200 });
1414
} catch (err) {
1515
next(err);

apps/api/src/routes/mcp.routes.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,11 @@ Analytics (engine API):
409409

410410
server.tool(
411411
"get_total_tvl",
412-
"Get the total TVL (Total Value Locked) across all ATV vaults, or for a specific vault, from the Aarna engine database.",
413-
{
414-
address: z
415-
.string()
416-
.optional()
417-
.describe("Vault contract address to filter to a single vault (omit for platform-wide TVL)"),
418-
},
412+
"Get the total TVL (Total Value Locked) across all ATV vaults from the Aarna engine database.",
413+
{},
419414
{ annotations: { title: "Get Total TVL", readOnlyHint: true, destructiveHint: false, openWorldHint: true } },
420-
async ({ address }) => {
421-
const data = await engineService.getTotalTvl(address);
415+
async () => {
416+
const data = await engineService.getTotalTvl();
422417
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
423418
},
424419
);

apps/api/src/services/engine.service.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@ class EngineService {
3030
headers: { Authorization: env.ENGINE_API_KEY },
3131
});
3232
} catch (err: any) {
33-
throw new Error(
34-
`Failed to reach engine API at ${url}: ${err.message}`,
35-
);
33+
throw new Error(`Failed to reach engine API at ${url}: ${err.message}`);
3634
}
3735

3836
if (!response.ok) {
39-
throw new Error(
40-
`Engine API returned HTTP ${response.status} for ${url}`,
41-
);
37+
throw new Error(`Engine API returned HTTP ${response.status} for ${url}`);
4238
}
4339

4440
return response.json() as Promise<T>;
@@ -69,7 +65,11 @@ class EngineService {
6965
* Returns the underlying token portfolio for the vault.
7066
*/
7167
async getVaultPortfolio(vaultAddress: string): Promise<unknown> {
72-
return this.get("/afi/vault-balance-data", { vaultAddress });
68+
const { data } = await this.get<{ data: unknown }>(
69+
"/afi/vault-balance-data",
70+
{ vaultAddress },
71+
);
72+
return data;
7373
}
7474

7575
/**
@@ -80,9 +80,16 @@ class EngineService {
8080
userAddress: string,
8181
vaultAddress?: string,
8282
): Promise<unknown> {
83-
const params: Record<string, string> = { address: userAddress };
83+
const params: Record<string, any> = {
84+
address: userAddress,
85+
metaInfo: false,
86+
};
8487
if (vaultAddress) params.vaultAddress = vaultAddress;
85-
return this.get("/afi/user-investments", params);
88+
const { data } = await this.get<{ data: unknown }>(
89+
"/afi/user-investments",
90+
params,
91+
);
92+
return data;
8693
}
8794

8895
/**
@@ -128,13 +135,12 @@ class EngineService {
128135
}
129136

130137
/**
131-
* GET /afi/total-tvl?vault_address=<addr>
132-
* Returns platform-wide or per-vault TVL from the engine DB.
138+
* GET /afi/total-tvl
139+
* Returns platform-wide TVL from the engine DB.
133140
*/
134-
async getTotalTvl(vaultAddress?: string): Promise<unknown> {
135-
const params: Record<string, string> = {};
136-
if (vaultAddress) params.vault_address = vaultAddress;
137-
return this.get("/afi/total-tvl", params);
141+
async getTotalTvl(): Promise<unknown> {
142+
const { data } = await this.get<{ data: unknown }>("/afi/total-tvl");
143+
return data;
138144
}
139145
}
140146

packages/mcp-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Add to `.vscode/settings.json`:
9696
| `get_vault_portfolio` | Underlying token portfolio |
9797
| `get_historical_nav` | NAV over a period (7, 30, 60, 360, max) |
9898
| `get_historical_tvl` | TVL over a period (7, 30, 60, 360, max) |
99-
| `get_total_tvl` | Platform-wide or per-vault TVL |
99+
| `get_total_tvl` | Platform-wide TVL |
100100
| `get_user_investments` | User portfolio and positions |
101101

102102
## Example Prompts

0 commit comments

Comments
 (0)