78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
import { tool } from 'ai';
|
|
import { z } from "zod";
|
|
import { queryBirdeye } from "./client.js";
|
|
import {getTokenMetadata} from '../solscan/getTokenMetadata.js'
|
|
|
|
const getTokenOverview = async (address) => {
|
|
//console.log(`getTokenOverview called with address: ${address}`);
|
|
|
|
const data = await queryBirdeye(
|
|
'defi/token_overview',
|
|
{ address }
|
|
);
|
|
|
|
const {
|
|
name = null,
|
|
symbol = null,
|
|
address: tokenAddress = null,
|
|
lastTradeUnixTime,
|
|
logoURI = null,
|
|
price = null,
|
|
mc = null,
|
|
liquidity = null,
|
|
circulatingSupply = null,
|
|
priceChange30mPercent = null,
|
|
priceChange1hPercent = null,
|
|
priceChange24hPercent = null,
|
|
trade30m = null,
|
|
trade1h = null,
|
|
trade24h = null,
|
|
buy30m = null,
|
|
sell30m = null,
|
|
uniqueWallet24h = null,
|
|
numberMarkets = null,
|
|
} = data;
|
|
|
|
|
|
const tokenMetadata = await getTokenMetadata(address);
|
|
|
|
return JSON.stringify({
|
|
name,
|
|
symbol,
|
|
address: tokenAddress,
|
|
logoURI,
|
|
price,
|
|
mc,
|
|
liquidity,
|
|
circulatingSupply,
|
|
priceChange30mPercent,
|
|
priceChange1hPercent,
|
|
priceChange24hPercent,
|
|
trade30m,
|
|
trade1h,
|
|
trade24h,
|
|
buy30m,
|
|
sell30m,
|
|
uniqueWallet24h,
|
|
numberMarkets,
|
|
lastTradeUnixTime,
|
|
metadata: tokenMetadata.data?.metadata || {},
|
|
});
|
|
};
|
|
|
|
export const getTokenOverviewTool = tool(
|
|
async (address) => {
|
|
return getTokenOverview(address);
|
|
},
|
|
{
|
|
name: "getTokenOverview",
|
|
description: "Retrieve an overview of a token by its address on the Solana blockchain.",
|
|
schema: z.string().describe("The token address to fetch an overview for")
|
|
}
|
|
);
|
|
|
|
// async function main(){
|
|
// const data = await getTokenOverview("7xXL8yXYotTvdrCQtayBH8cS8VyMRNw3a1x8kgf8pump")
|
|
// //console.log(data);
|
|
// }
|
|
// main()
|