Skip to content

Commit 4913860

Browse files
authored
Add more defillama endpoints (#63)
* fix: Remove is enabled check for raw data requests - Leave enabled check only for llm agent usage - Raw data tool will be enabled if a corresponding api key has been provided in env * feat: Enhance DefiLlamaTool for multi-token price retrieval and historical data - Introduced support for fetching prices of multiple tokens in a single request. - Added a new method for retrieving historical token prices based on a specified timestamp. - Updated schemas to validate input parameters for both current and historical price requests. - Improved error handling to provide detailed feedback for low confidence price data. - Expanded unit tests to cover new functionalities, including multi-token and historical price fetching. * refactor: Update DefiLlamaTool schemas and parsing logic - Removed historical price response schema in favor of a unified price response schema. - Enhanced token identifier description to include native token format. - Updated parsing logic to utilize the new schema for historical price retrieval. - Simplified type inference in the parseResult method to focus solely on the price response schema. * chore: Update .dockerignore and .gitignore to include .cursor * feat: Add TimestampConverterTool for timestamp conversions - Introduced TimestampConverterTool to convert between ISO strings and numeric timestamps (milliseconds or seconds). - Updated ToolName enum to include TIMESTAMP_CONVERTER. - Registered the new tool in availableTools and updated specialtyDomains to include it. - Added comprehensive unit tests to validate conversion functionality and error handling. * feat: Introduce CalculatorTool for arithmetic operations - Added CalculatorTool to perform various arithmetic operations including addition, subtraction, multiplication, division, power, square root, and percentage calculations. - Updated ToolName enum to include CALCULATOR. - Registered the new tool in availableTools for easy access. - Implemented comprehensive unit tests to validate functionality and error handling for all operations. * feat: Add Utility domain for general-purpose tools - Introduced a new domain, UTILITY, to encompass general-purpose utility tools. - Added capabilities for mathematical calculations, time conversions, and data formatting. - Registered tools including Calculator and TimestampConverter under the new domain, enhancing the toolset for common operations. * fix: Update default search width parameter in DefiLlamaTool - Changed the default value of the SearchWidthParamSchema from "4h" to "6h". - Enhanced the description to clarify accepted candle notation and provide examples for better user understanding. * feat: Add get_token_price_chart tool to DefiLlamaTool - Introduced a new tool for fetching token price charts from DefiLlama, supporting multiple tokens and customizable parameters. - Enhanced schemas to validate input for the new chart tool, including options for start and end timestamps, span, period, and search width. - Implemented error handling for low confidence price data and API/network errors. - Expanded unit tests to cover various scenarios for the new tool, ensuring robust functionality and error management. * feat: Add get_token_price_percentage_change tool to DefiLlamaTool - Introduced a new tool for fetching percentage changes in token prices over specified time periods. - Enhanced schemas to validate input parameters, including coins, timestamp, lookForward, and period. - Implemented error handling for API/network errors and low confidence data. - Updated unit tests to cover various scenarios for the new percentage change tool, ensuring robust functionality and error management.
1 parent 3129ca1 commit 4913860

File tree

11 files changed

+1551
-77
lines changed

11 files changed

+1551
-77
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ npm-debug.log
55
.env.*
66

77
configs/.env.*
8+
9+
.cursor

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ bun.lockb
3939
*.db
4040
package-lock.json
4141

42-
/coverage/
42+
/coverage/
43+
44+
.cursor

src/registry/toolClasses.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { CMCBaseTool } from "../tools/cmc";
1414
import { DefiLlamaTool } from "../tools/defillama";
1515
import { AskSpecialtyTool } from "../tools/askSpecialty";
1616
import { ToolName } from "./toolNames";
17+
import { TimestampConverterTool } from "../tools/time";
18+
import { CalculatorTool } from "../tools/calculator";
1719

1820
export const availableTools = [
1921
{
@@ -72,4 +74,12 @@ export const availableTools = [
7274
name: ToolName.ASK_SPECIALTY,
7375
toolClass: AskSpecialtyTool,
7476
},
77+
{
78+
name: ToolName.TIMESTAMP_CONVERTER,
79+
toolClass: TimestampConverterTool,
80+
},
81+
{
82+
name: ToolName.CALCULATOR,
83+
toolClass: CalculatorTool,
84+
},
7585
];

src/registry/toolNames.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ export enum ToolName {
1313
CMC = "cmc",
1414
DEFILLAMA = "defillama",
1515
ASK_SPECIALTY = "ask_specialty",
16+
TIMESTAMP_CONVERTER = "timestamp_converter",
17+
CALCULATOR = "calculator",
1618
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { describe, expect, it, beforeEach } from "vitest";
2+
import { CalculatorTool } from "../calculator";
3+
4+
describe("CalculatorTool", () => {
5+
let tool: CalculatorTool;
6+
7+
beforeEach(() => {
8+
tool = new CalculatorTool();
9+
});
10+
11+
describe("basic operations", () => {
12+
it("should add two numbers", async () => {
13+
const result = await tool.execute({
14+
operation: "add",
15+
operand1: 5,
16+
operand2: 3,
17+
});
18+
expect(result).toBe("8");
19+
});
20+
21+
it("should subtract two numbers", async () => {
22+
const result = await tool.execute({
23+
operation: "subtract",
24+
operand1: 10,
25+
operand2: 4,
26+
});
27+
expect(result).toBe("6");
28+
});
29+
30+
it("should multiply two numbers", async () => {
31+
const result = await tool.execute({
32+
operation: "multiply",
33+
operand1: 6,
34+
operand2: 7,
35+
});
36+
expect(result).toBe("42");
37+
});
38+
39+
it("should divide two numbers", async () => {
40+
const result = await tool.execute({
41+
operation: "divide",
42+
operand1: 15,
43+
operand2: 3,
44+
});
45+
expect(result).toBe("5");
46+
});
47+
});
48+
49+
describe("advanced operations", () => {
50+
it("should calculate power", async () => {
51+
const result = await tool.execute({
52+
operation: "power",
53+
operand1: 2,
54+
operand2: 3,
55+
});
56+
expect(result).toBe("8");
57+
});
58+
59+
it("should calculate square root", async () => {
60+
const result = await tool.execute({
61+
operation: "sqrt",
62+
operand1: 16,
63+
});
64+
expect(result).toBe("4");
65+
});
66+
67+
it("should calculate percentage", async () => {
68+
const result = await tool.execute({
69+
operation: "percentage",
70+
operand1: 50,
71+
operand2: 20,
72+
});
73+
expect(result).toBe("10");
74+
});
75+
});
76+
77+
describe("error handling", () => {
78+
it("should handle division by zero", async () => {
79+
const result = await tool.execute({
80+
operation: "divide",
81+
operand1: 10,
82+
operand2: 0,
83+
});
84+
expect(result).toBe("Error executing calculator tool");
85+
});
86+
87+
it("should handle negative square root", async () => {
88+
const result = await tool.execute({
89+
operation: "sqrt",
90+
operand1: -16,
91+
});
92+
expect(result).toBe("Error executing calculator tool");
93+
});
94+
95+
it("should handle missing second operand", async () => {
96+
const result = await tool.execute({
97+
operation: "add",
98+
operand1: 5,
99+
});
100+
expect(result).toBe("Error executing calculator tool");
101+
});
102+
});
103+
104+
describe("floating point precision", () => {
105+
it("should handle floating point calculations", async () => {
106+
const result = await tool.execute({
107+
operation: "divide",
108+
operand1: 10,
109+
operand2: 3,
110+
});
111+
expect(result).toBe("3.3333333333");
112+
});
113+
114+
it("should handle large numbers", async () => {
115+
const result = await tool.execute({
116+
operation: "multiply",
117+
operand1: 1e10,
118+
operand2: 1e10,
119+
});
120+
expect(result).toBe("100000000000000000000");
121+
});
122+
});
123+
});

0 commit comments

Comments
 (0)