Repository navigation
Expand file tree
/
Copy pathplugin.js
More file actions
67 lines (58 loc) · 2.45 KB
/
Copy pathplugin.js
File metadata and controls
67 lines (58 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
This source code is a copy of the Chainlink plugin created by the LATAM Builders team https://ethglobal.com/showcase/price-feed-plugin-kd27q
This version is reduced and simplied for educational purposes. If you like it give thanks and credits the original authors
*/
import { z } from 'zod';
import { getPriceFeedFromChainlink } from "./tool.js";
const getPriceFeedPrompt = `
Query the latest price from a Chainlink Price Feed oracle on Hedera Testnet.
This tool connects to Chainlink's decentralized oracle network to retrieve
real-time cryptocurrency price data. The price feeds are updated regularly
by multiple independent node operators.
Parameters:
- coinId (string, required): The coinId to query. Must be one of:
* BTC - Bitcoin to US Dollar
* ETH - Ethereum to US Dollar
* HBAR - Hedera to US Dollar
* LINK - Chainlink to US Dollar
* USDC - USD Coin to US Dollar
* USDT - Tether to US Dollar
* DAI - DAI Stablecoin to US Dollar
Returns:
- coinId: The coinId queried
- address: The contract address used to query the price feed
- price: Raw price value from the oracle
- formattedPrice: Human-readable price with currency formatting
- decimals: Number of decimal places in the raw price
- roundId: The round ID of the price update
- updatedAt: Timestamp when the price was last updated
Example usage:
- "What's the price of Bitcoin?"
- "Get me the current HBAR price"
- "Show me ETH price"
`;
const getChainlinkPriceFeedTool = (_context) => ({
method: 'get_chainlink_price_feed_tool',
name: 'get Chainlink price feed Tool',
description: getPriceFeedPrompt,
parameters: z.object({
coinId: z.string(),
}),
outputParser: undefined,
execute: async (client, context, params) => {
const { coinId } = params;
const result = await getPriceFeedFromChainlink(coinId);
return result;
},
});
// Export the plugin
export const ChainlinkPriceFeedPlugin = {
name: 'ChainlinkPriceFeedPlugin',
version: '1.0.0',
description: 'A plugin for querying Chainlink Price Feed oracles on Hedera Testnet. Provides real-time cryptocurrency price data from decentralized oracle networks.',
tools: (context) => { return [getChainlinkPriceFeedTool(context)]; }
};
export const chainlinkPriceFeedPluginToolNames = {
GET_CHAINLINK_PRICE_FEED_TOOL: 'get_chainlink_price_feed_tool',
};
export default { ChainlinkPriceFeedPlugin, chainlinkPriceFeedPluginToolNames };