35 lines
826 B
JavaScript
35 lines
826 B
JavaScript
![]() |
import { Tool } from "langchain/tools"
|
||
|
|
||
|
/**
|
||
|
* Tool to fetch the price of a token in USDC
|
||
|
*/
|
||
|
export class SolanaFetchPriceTool extends Tool {
|
||
|
name = "solana_fetch_price"
|
||
|
description = `Fetch the price of a given token in USDC.
|
||
|
|
||
|
Inputs:
|
||
|
- tokenId: string, the mint address of the token, e.g., "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"`
|
||
|
|
||
|
constructor(solanaKit) {
|
||
|
super()
|
||
|
this.solanaKit = solanaKit
|
||
|
}
|
||
|
|
||
|
async _call(input) {
|
||
|
try {
|
||
|
const price = await this.solanaKit.fetchTokenPrice(input.trim())
|
||
|
return JSON.stringify({
|
||
|
status: "success",
|
||
|
tokenId: input.trim(),
|
||
|
priceInUSDC: price
|
||
|
})
|
||
|
} catch (error) {
|
||
|
return JSON.stringify({
|
||
|
status: "error",
|
||
|
message: error.message,
|
||
|
code: error.code || "UNKNOWN_ERROR"
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|