UNPKG

@agentek/tools

Version:

Blockchain tools for AI agents

214 lines 6.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTallyProposalsTool = createTallyProposalsTool; exports.createTallyChainsTool = createTallyChainsTool; exports.createTallyUserDaosTool = createTallyUserDaosTool; const zod_1 = __importDefault(require("zod")); const client_js_1 = require("../client.js"); const utils_js_1 = require("./utils.js"); const constants_js_1 = require("./constants.js"); function createTallyProposalsTool(tallyApiKey) { return (0, client_js_1.createTool)({ name: "tallyProposals", description: "Fetch proposals from the Tally governance API for a specified DAO/space.", supportedChains: [], parameters: zod_1.default.object({ space: zod_1.default .string() .describe("The DAO or space identifier e.g. uniswap, hai, nounsdao"), limit: zod_1.default .number() .optional() .default(10) .describe("Maximum number of proposals to fetch"), }), execute: async (_client, args) => { const governor = await (0, utils_js_1.getGovernorBySlug)(args.space, tallyApiKey); const governorId = governor.id; // Then get proposals using governor ID const getProposalsQuery = ` query GetProposals($governorId: AccountID!, $limit: Int!) { proposals( input: { filters: { governorId: $governorId } page: { limit: $limit } sort: { isDescending: true, sortBy: id } } ) { nodes { ... on Proposal { id onchainId metadata { title description } status start { ... on Block { number timestamp } ... on BlocklessTimestamp { timestamp } } end { ... on Block { number timestamp } ... on BlocklessTimestamp { timestamp } } voteStats { type votesCount votersCount percent } } } pageInfo { firstCursor lastCursor count } } } `; const proposalsResponse = await fetch(constants_js_1.TALLY_API_URL, { method: "POST", headers: { "Content-Type": "application/json", "Api-Key": tallyApiKey, }, body: JSON.stringify({ query: getProposalsQuery, variables: { governorId, limit: args.limit || 10, }, }), }); const result = await proposalsResponse.json(); if (result.errors) { throw new Error(`Tally API Error: ${JSON.stringify(result.errors)}`); } return result.data; }, }); } function createTallyChainsTool(tallyApiKey) { return (0, client_js_1.createTool)({ name: "tallyChains", description: "Fetch all chains supported by the Tally governance API.", supportedChains: [], parameters: zod_1.default.object({}), execute: async (_client, _args) => { const query = ` query Chains { chains { id layer1Id name mediumName shortName blockTime isTestnet nativeCurrency { name symbol decimals } chain useLayer1VotingPeriod } } `; const response = await fetch(constants_js_1.TALLY_API_URL, { method: "POST", headers: { "Content-Type": "application/json", "Api-Key": tallyApiKey, }, body: JSON.stringify({ query }), }); const result = await response.json(); if (result.errors) { throw new Error(`Tally API Error: ${JSON.stringify(result.errors)}`); } return result.data; }, }); } function createTallyUserDaosTool(tallyApiKey) { return (0, client_js_1.createTool)({ name: "tallyUserDaos", description: "Fetch all DAOs a user is a member of from the Tally governance API.", supportedChains: [], parameters: zod_1.default.object({ address: zod_1.default .string() .describe("The Ethereum address to check DAO membership for"), }), execute: async (_client, args) => { const query = ` query Organizations($input: OrganizationsInput) { organizations(input: $input) { nodes { ... on Organization { id slug name chainIds tokenIds governorIds metadata { color description icon } } } pageInfo { firstCursor lastCursor count } } } `; const response = await fetch(constants_js_1.TALLY_API_URL, { method: "POST", headers: { "Content-Type": "application/json", "Api-Key": tallyApiKey, }, body: JSON.stringify({ query, variables: { input: { filters: { address: args.address, isMember: true, }, }, }, }), }); console.log("response", response); const result = await response.json(); console.log("result", result); if (result.errors) { throw new Error(`Tally API Error: ${JSON.stringify(result.errors)}`); } return result.data; }, }); } //# sourceMappingURL=tools.js.map