@agentek/tools
Version:
Blockchain tools for AI agents
96 lines • 3.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.intentWithdrawWETH = exports.intentDepositWETH = void 0;
const zod_1 = require("zod");
const client_js_1 = require("../client.js");
const viem_1 = require("viem");
const constants_js_1 = require("./constants.js");
const depositWETHParameters = zod_1.z.object({
chainId: zod_1.z.number().describe("Chain ID to deposit on"),
amount: zod_1.z.number().describe("Amount of ETH to deposit (in ether)"),
});
const withdrawWETHParameters = zod_1.z.object({
chainId: zod_1.z.number().describe("Chain ID to withdraw on"),
amount: zod_1.z.number().describe("Amount of WETH to withdraw (in ether)"),
});
const depositWETHChains = constants_js_1.supportedChains;
const withdrawWETHChains = constants_js_1.supportedChains;
exports.intentDepositWETH = (0, client_js_1.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 = (0, viem_1.parseEther)(amount.toString());
const data = (0, viem_1.encodeFunctionData)({
abi: constants_js_1.wethAbi,
functionName: "deposit",
args: [],
});
const ops = [
{
target: constants_js_1.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,
};
}
},
});
exports.intentWithdrawWETH = (0, client_js_1.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 = (0, viem_1.parseEther)(amount.toString());
const data = (0, viem_1.encodeFunctionData)({
abi: constants_js_1.wethAbi,
functionName: "withdraw",
args: [valueToWithdraw],
});
const ops = [
{
target: constants_js_1.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