UNPKG

@agentek/tools

Version:

Blockchain tools for AI agents

93 lines 3.09 kB
import { z } from "zod"; import { createTool } from "../client.js"; import { encodeFunctionData, parseEther } from "viem"; import { supportedChains, WETH_ADDRESS, wethAbi } from "./constants.js"; const depositWETHParameters = z.object({ chainId: z.number().describe("Chain ID to deposit on"), amount: z.number().describe("Amount of ETH to deposit (in ether)"), }); const withdrawWETHParameters = z.object({ chainId: z.number().describe("Chain ID to withdraw on"), amount: z.number().describe("Amount of WETH to withdraw (in ether)"), }); const depositWETHChains = supportedChains; const withdrawWETHChains = supportedChains; export const intentDepositWETH = createTool({ name: "depositWETH", description: "Deposit ETH into the WETH contract, receiving WETH in return", supportedChains: depositWETHChains, parameters: depositWETHParameters, execute: async (client, args) => { const { chainId, amount } = args; const walletClient = client.getWalletClient(chainId); const valueToDeposit = parseEther(amount.toString()); const data = encodeFunctionData({ abi: wethAbi, functionName: "deposit", args: [], }); const ops = [ { target: WETH_ADDRESS[chainId], value: valueToDeposit.toString(), data: data, }, ]; if (!walletClient) { return { intent: `Deposit ${amount} ETH into WETH`, ops, chain: chainId, }; } else { const hash = await client.executeOps(ops, chainId); return { intent: `Deposit ${amount} ETH into WETH`, ops, chain: chainId, hash, }; } }, }); export const intentWithdrawWETH = createTool({ name: "withdrawWETH", description: "Withdraw WETH back to native ETH", supportedChains: withdrawWETHChains, parameters: withdrawWETHParameters, execute: async (client, args) => { const { chainId, amount } = args; const walletClient = client.getWalletClient(chainId); const valueToWithdraw = parseEther(amount.toString()); const data = encodeFunctionData({ abi: wethAbi, functionName: "withdraw", args: [valueToWithdraw], }); const ops = [ { target: WETH_ADDRESS[chainId], value: "0", data, }, ]; if (!walletClient) { return { intent: `Withdraw ${amount} WETH to native ETH`, ops, chain: chainId, }; } else { const hash = await client.executeOps(ops, chainId); return { intent: `Withdraw ${amount} WETH to native ETH`, ops, chain: chainId, hash, }; } }, }); //# sourceMappingURL=intents.js.map