Add historical APRs and TVLs tools to Liquidswap

- Implemented `getPoolsHistoricalAprs` and `getPoolsHistoricalTvls` methods in the Liquidswap class.
- Created tools for fetching historical APRs and TVLs, including validation for the last 365 days.
- Updated tools index to include the new historical tools.
This commit is contained in:
odiinnn committed 2025-05-24 13:22:23 +03:00
1 parent 56fb2646df
commit 8679bd2072
6 files changed
+98

No files matched your search

+10
View File
@@ -17,6 +17,16 @@ export class Liquidswap {
const response = await this.fetch(`/pools/registered?networkId=1&cl=true`) const response = await this.fetch(`/pools/registered?networkId=1&cl=true`)
return response return response
} }
public async getPoolsHistoricalAprs(from: string, to: string = 'now') {
const response = await this.fetch(`/sentio/historical_aprs?start=${from}&end=${to}`)
return response
}
public async getPoolsHistoricalTvls(from: string, to: string = 'now') {
const response = await this.fetch(`/sentio/historical_tvls?start=${from}&end=${to}`)
return response
}
} }
export const liquidswap = new Liquidswap() export const liquidswap = new Liquidswap()
@@ -0,0 +1,41 @@
import type { Tool } from "../../types/tools.js";
import { liquidswap } from "../../core/liquidswap.js";
import { z } from "zod";
const getPoolsHistoricalAprs: Tool<typeof parameters>['execute'] = async (args) => {
if (args.daysAgo > 365) {
return {
isError: true,
content: [
{
type: "text",
text: "You can only get the historical APRs for the last 365 days"
}
],
};
}
const data = await liquidswap.getPoolsHistoricalAprs(`now-${args.daysAgo}d`);
return {
content: data.map((item: any) => ({
type: "text",
text: JSON.stringify(item, null, 2)
})),
};
};
const parameters = z.object({
daysAgo: z.number().describe("Number of days ago to get the historical APRs for"),
});
export const getPoolsHistoricalAprsTool: Tool<typeof parameters> = {
name: "get_pools_historical_aprs",
description: "Get historical APRs for all pools registered on Liquidswap",
execute: getPoolsHistoricalAprs,
parameters,
};
@@ -0,0 +1 @@
export * from "./get-pools-historical-aprs.js";
@@ -0,0 +1,41 @@
import type { Tool } from "../../types/tools.js";
import { liquidswap } from "../../core/liquidswap.js";
import { z } from "zod";
const getPoolsHistoricalTvls: Tool<typeof parameters>['execute'] = async (args) => {
if (args.daysAgo > 365) {
return {
isError: true,
content: [
{
type: "text",
text: "You can only get the historical TVLs for the last 365 days"
}
],
};
}
const data = await liquidswap.getPoolsHistoricalTvls(`now-${args.daysAgo}d`);
return {
content: data.map((item: any) => ({
type: "text",
text: JSON.stringify(item, null, 2)
})),
};
};
const parameters = z.object({
daysAgo: z.number().describe("Number of days ago to get the historical TVLs for"),
});
export const getPoolsHistoricalTvlsTool: Tool<typeof parameters> = {
name: "get_pools_historical_tvls",
description: "Get historical TVLs for all pools registered on Liquidswap",
execute: getPoolsHistoricalTvls,
parameters,
};
@@ -0,0 +1 @@
export * from "./get-pools-historical-tvls.js";
+4
View File
@@ -1,10 +1,14 @@
import { Tool } from "../types/tools.js"; import { Tool } from "../types/tools.js";
import { getTokensTool } from "./get-tokens/get-tokens.js"; import { getTokensTool } from "./get-tokens/get-tokens.js";
import { getPoolsTool } from "./get-pools/get-pools.js"; import { getPoolsTool } from "./get-pools/get-pools.js";
import { getPoolsHistoricalAprsTool } from "./get-pools-historical-aprs/index.js";
import { getPoolsHistoricalTvlsTool } from "./get-pools-historical-tvls/index.js";
const tools: Tool<any>[] = [ const tools: Tool<any>[] = [
getTokensTool, getTokensTool,
getPoolsTool, getPoolsTool,
getPoolsHistoricalAprsTool,
getPoolsHistoricalTvlsTool,
]; ];
export default tools; export default tools;