@agentek/tools
Version:
Blockchain tools for AI agents
96 lines • 3.74 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 (e.g. 1 for Ethereum, 8453 for Base, 42161 for Arbitrum)"),
amount: zod_1.z.string().describe("Amount of ETH to wrap in human-readable units (e.g. '1.5' for 1.5 ETH)"),
});
const withdrawWETHParameters = zod_1.z.object({
chainId: zod_1.z.number().describe("Chain ID to withdraw on (e.g. 1 for Ethereum, 8453 for Base, 42161 for Arbitrum)"),
amount: zod_1.z.string().describe("Amount of WETH to unwrap in human-readable units (e.g. '1.5' for 1.5 WETH)"),
});
const depositWETHChains = constants_js_1.supportedChains;
const withdrawWETHChains = constants_js_1.supportedChains;
exports.intentDepositWETH = (0, client_js_1.createTool)({
name: "depositWETH",
description: "Wrap native ETH into WETH (Wrapped ETH) by depositing into the WETH contract. You receive an equal amount of WETH, an ERC20 token.",
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: "Unwrap WETH back to native ETH by withdrawing from the WETH contract. Burns your WETH and returns an equal amount of 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