import { z } from "zod";
import axios, { AxiosResponse } from "axios";
import { baseUri, chainName } from "../../constants";
export default function (server: any) {
server.tool(
"getContractsWithHoldings",
"Gets a list of contracts containing specific token with defined threshold.",
{
chainName: z.literal(chainName),
token_address: z.string().describe("Token address to fetch contracts for"),
authToken: z
.string()
.describe("Authorization token for accessing the Somnia API"),
},
{
title: "Get Contracts With Holdings",
readOnlyHint: true,
description:
"Fetch a list of contracts containing specific token with defined threshold.",
destructiveHint: false,
},
async (args:any) => {
const { chainName, token_address, authToken } = args;
try {
const response: AxiosResponse<any> =
await axios.get(
`${baseUri}/${chainName}/v1/tokens/${token_address}/contract/list`,
{
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json",
Accept: "application/json",
},
}
);
return {
content: [
{
type: "text",
text: `Contracts With Holdings Data: ${JSON.stringify(
response.data
)}`,
},
],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error fetching contracts with holdings: ${error}`,
},
],
};
}
}
);
}