@agentix/plugin-solana-switchboard
Version:
124 lines (117 loc) • 3.84 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
default: () => index_default
});
module.exports = __toCommonJS(index_exports);
var import_agentix = require("agentix");
// src/actions/simulateFeed.ts
var import_zod = require("zod");
// src/constants.ts
var SWITCHBOARD_DEFAULT_CROSSBAR = "https://crossbar.switchboard.xyz";
// src/tools/simulate_feed.ts
var import_common = require("@switchboard-xyz/common");
async function simulate_switchboard_feed(feed, crossbarUrl = SWITCHBOARD_DEFAULT_CROSSBAR) {
try {
const crossbar = new import_common.CrossbarClient(crossbarUrl, true);
const results = await crossbar.simulateSolanaFeeds("mainnet", [feed]);
if (results.length === 0) {
throw new Error(
`Error simulating feed ${feed}. Did you provide the right mainnet feed hash?`
);
}
return results[0].results.toString();
} catch (error) {
throw new Error(`Error: ${error.message}`);
}
}
// src/actions/simulateFeed.ts
var switchboardSimulateFeedAction = {
name: "SWITCHBOARD_SIMULATE_FEED",
similes: [
"simulate switchboard price feed",
"simulate switchboard feed",
"switchboard oracle feed",
"get switchboard price",
"check switchboard price",
"switchboard price",
"switchbaord feed"
],
description: "Simulates a given switchboard price feed and returns the value.",
examples: [
[
{
input: {
feed: "6qmsMwtMmeqMgZEhyLv1Pe4wcqT5iKwJAWnmzmnKjf83"
// BTC/USDT price feed
},
output: {
status: "success",
value: "104097.59",
message: "Simulation result: 104097.59"
},
explanation: "Get the current BTC/USDT price by simulating a Switchbaord feed"
}
]
],
schema: import_zod.z.object({
feed: import_zod.z.string().describe("The address of the Switchboard feed to simulate"),
crossbarUrl: import_zod.z.string().default(SWITCHBOARD_DEFAULT_CROSSBAR).describe("The url of the crossbar server to use")
}),
handler: async (_agent, input) => {
try {
const { feedAddress, crossbarUrl } = input;
const result = await simulate_switchboard_feed(feedAddress, crossbarUrl);
return {
status: "success",
feed: feedAddress,
message: `Simulation result: ${result}`
};
} catch (error) {
return {
status: "error",
message: `Failed to simulate Switchboard feed: ${error.message}`
};
}
}
};
var simulateFeed_default = switchboardSimulateFeedAction;
// src/index.ts
var SwitchboardPlugin = class extends import_agentix.PluginBase {
constructor() {
const methods = {
simulate_switchboard_feed
};
const actions = [
simulateFeed_default
];
const supportedChains = [
{
type: "solana"
}
];
super("switchboard", methods, actions, supportedChains);
}
supportsWallet(wallet) {
return wallet instanceof import_agentix.SolanaWalletBase;
}
};
var index_default = SwitchboardPlugin;