import { z } from "zod";
import axios, { AxiosResponse } from "axios";
import { baseUri, chainName } from "../../constants";
export default function (server: any) {
server.tool(
"getHistoricalBalance",
"Commonly used to fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date",
{
chainName: z.literal(chainName),
walletAddress: z.string().describe("Wallet address to fetch balance for"),
authToken: z
.string()
.describe("Authorization token for accessing the Somnia API"),
},
{
title: "Get Historical Balance",
readOnlyHint: true,
description:
"Fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date.",
destructiveHint: false,
idempotentHint: true,
},
async (args:any) => {
const { chainName, walletAddress, authToken } = args;
try {
const response: AxiosResponse<any> = await axios.get(
`${baseUri}/${chainName}/v1/address/${walletAddress}/balance/historical`,
{
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json",
Accept: "application/json",
},
}
);
return {
content: [
{
type: "text",
text: `Historical Balance Data: ${JSON.stringify(response.data)}`,
},
],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error fetching historical balance: ${error}`,
},
],
};
}
}
);
}