From 8679bd20729da0d3051db74bb4b9c773a9c28820 Mon Sep 17 00:00:00 2001 From: odiinnn <38395645+odiinnn@users.noreply.github.com> Date: Sat, 24 May 2025 13:22:23 +0300 Subject: [PATCH] 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. --- src/core/liquidswap.ts | 10 +++++ .../get-pools-historical-aprs.ts | 41 +++++++++++++++++++ src/tools/get-pools-historical-aprs/index.ts | 1 + .../get-pools-historical-tvls.ts | 41 +++++++++++++++++++ src/tools/get-pools-historical-tvls/index.ts | 1 + src/tools/index.ts | 4 ++ 6 files changed, 98 insertions(+) create mode 100644 src/tools/get-pools-historical-aprs/get-pools-historical-aprs.ts create mode 100644 src/tools/get-pools-historical-aprs/index.ts create mode 100644 src/tools/get-pools-historical-tvls/get-pools-historical-tvls.ts create mode 100644 src/tools/get-pools-historical-tvls/index.ts diff --git a/src/core/liquidswap.ts b/src/core/liquidswap.ts index 4c013e3..8f32c12 100644 --- a/src/core/liquidswap.ts +++ b/src/core/liquidswap.ts @@ -17,6 +17,16 @@ export class Liquidswap { const response = await this.fetch(`/pools/registered?networkId=1&cl=true`) 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() \ No newline at end of file diff --git a/src/tools/get-pools-historical-aprs/get-pools-historical-aprs.ts b/src/tools/get-pools-historical-aprs/get-pools-historical-aprs.ts new file mode 100644 index 0000000..dfb79fe --- /dev/null +++ b/src/tools/get-pools-historical-aprs/get-pools-historical-aprs.ts @@ -0,0 +1,41 @@ +import type { Tool } from "../../types/tools.js"; +import { liquidswap } from "../../core/liquidswap.js"; +import { z } from "zod"; + +const getPoolsHistoricalAprs: Tool['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 = { + name: "get_pools_historical_aprs", + description: "Get historical APRs for all pools registered on Liquidswap", + execute: getPoolsHistoricalAprs, + parameters, +}; diff --git a/src/tools/get-pools-historical-aprs/index.ts b/src/tools/get-pools-historical-aprs/index.ts new file mode 100644 index 0000000..ceef8f8 --- /dev/null +++ b/src/tools/get-pools-historical-aprs/index.ts @@ -0,0 +1 @@ +export * from "./get-pools-historical-aprs.js"; \ No newline at end of file diff --git a/src/tools/get-pools-historical-tvls/get-pools-historical-tvls.ts b/src/tools/get-pools-historical-tvls/get-pools-historical-tvls.ts new file mode 100644 index 0000000..7bdff9c --- /dev/null +++ b/src/tools/get-pools-historical-tvls/get-pools-historical-tvls.ts @@ -0,0 +1,41 @@ +import type { Tool } from "../../types/tools.js"; +import { liquidswap } from "../../core/liquidswap.js"; +import { z } from "zod"; + +const getPoolsHistoricalTvls: Tool['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 = { + name: "get_pools_historical_tvls", + description: "Get historical TVLs for all pools registered on Liquidswap", + execute: getPoolsHistoricalTvls, + parameters, +}; diff --git a/src/tools/get-pools-historical-tvls/index.ts b/src/tools/get-pools-historical-tvls/index.ts new file mode 100644 index 0000000..8f81845 --- /dev/null +++ b/src/tools/get-pools-historical-tvls/index.ts @@ -0,0 +1 @@ +export * from "./get-pools-historical-tvls.js"; \ No newline at end of file diff --git a/src/tools/index.ts b/src/tools/index.ts index 08ff0a8..76d6629 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -1,10 +1,14 @@ import { Tool } from "../types/tools.js"; import { getTokensTool } from "./get-tokens/get-tokens.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[] = [ getTokensTool, getPoolsTool, + getPoolsHistoricalAprsTool, + getPoolsHistoricalTvlsTool, ]; export default tools; \ No newline at end of file