tensaikit
Version:
An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.
45 lines (44 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchCurators = void 0;
const errors_1 = require("../../../common/errors");
const utils_1 = require("../utils");
const utils_2 = require("../../../common/utils");
const morphoAPIQuery_1 = require("../query/morphoAPIQuery");
/**
* Fetches all whitelisted curators from the Morpho subgraph for the connected network.
*
* This function queries the Morpho subgraph and retrieves metadata for each verified
* or whitelisted curator (such as name, image, state, and verification status).
*
* @param walletProvider - Connected EVM wallet instance.
*
* @returns A Promise resolving to a list of curators with their metadata, or `null` if none found.
*
* @throws Will throw an error if:
* - The connected network or chainId is missing or invalid.
* - The network is not supported by the Morpho subgraph.
* - The subgraph query fails or returns an invalid response.
*/
const fetchCurators = async (walletProvider) => {
try {
const network = walletProvider.getNetwork();
const chainId = network.chainId;
const networkId = network.networkId;
if (!chainId || !networkId) {
throw (0, errors_1.createError)("Invalid or missing network", errors_1.ErrorCode.INVALID_NETWORK);
}
if (!utils_1.MORPHO_SUPPORTED_SUB_GRAPH.includes(network.networkId)) {
throw (0, errors_1.createError)("Network not supported!", errors_1.ErrorCode.INVALID_NETWORK);
}
const response = await (0, utils_2.makeSubgraphQueryCall)(utils_1.MORPHO_GRAPH_API_URL, (0, morphoAPIQuery_1.queryCurators)({ chainId: Number(chainId) }));
if (!response || !response.curators) {
return null;
}
return response.curators;
}
catch (error) {
throw (0, errors_1.handleError)("Failed to fetch curators from Morpho subgraph", error);
}
};
exports.fetchCurators = fetchCurators;