UNPKG

@agentek/tools

Version:

Blockchain tools for AI agents

283 lines 10.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.intentTransferPosition = exports.intentCollectFees = exports.intentDecreaseLiquidity = exports.intentIncreaseLiquidity = exports.intentMintPosition = void 0; const zod_1 = require("zod"); const client_js_1 = require("../client.js"); const constants_js_1 = require("./constants.js"); const viem_1 = require("viem"); const constants_js_2 = require("./constants.js"); const intentMintPosition = (0, client_js_1.createTool)({ name: "intentMintPosition", description: "Creates a new Uniswap V3 liquidity position", supportedChains: constants_js_1.supportedChains, parameters: zod_1.z.object({ token0: zod_1.z.string(), token1: zod_1.z.string(), fee: zod_1.z.number(), tickLower: zod_1.z.number(), tickUpper: zod_1.z.number(), amount0Desired: zod_1.z.string(), amount1Desired: zod_1.z.string(), slippageTolerance: zod_1.z.number().default(0.5), recipient: zod_1.z.string().optional(), deadline: zod_1.z.number().optional(), chainId: zod_1.z.number(), }), execute: async (client, args) => { const user = await client.getAddress(); const deadline = args.deadline || Math.floor(Date.now() / 1000) + 1200; const amount0Desired = BigInt(args.amount0Desired); const amount1Desired = BigInt(args.amount1Desired); const amount0Min = (amount0Desired * (10000n - BigInt(args.slippageTolerance * 100))) / 10000n; const amount1Min = (amount1Desired * (10000n - BigInt(args.slippageTolerance * 100))) / 10000n; const data = (0, viem_1.encodeFunctionData)({ abi: constants_js_2.nonfungiblePositionManagerAbi, functionName: "mint", args: [ { token0: args.token0, token1: args.token1, fee: args.fee, tickLower: args.tickLower, tickUpper: args.tickUpper, amount0Desired, amount1Desired, amount0Min, amount1Min, recipient: args.recipient || user, deadline: BigInt(deadline), }, ], }); const ops = [ { target: (0, constants_js_1.getPositionManagerAddress)(args.chainId), value: "0", data, }, ]; const walletClient = client.getWalletClient(args.chainId); if (!walletClient) { return { intent: `Mint Uniswap V3 position for ${args.token0}/${args.token1}`, ops, chain: args.chainId, }; } const hash = await client.executeOps(ops, args.chainId); return { intent: `Mint Uniswap V3 position for ${args.token0}/${args.token1}`, ops, chain: args.chainId, hash, }; }, }); exports.intentMintPosition = intentMintPosition; const intentIncreaseLiquidity = (0, client_js_1.createTool)({ name: "intentIncreaseLiquidity", description: "Adds more liquidity to an existing Uniswap V3 position", supportedChains: constants_js_1.supportedChains, parameters: zod_1.z.object({ tokenId: zod_1.z.string(), amount0Desired: zod_1.z.string(), amount1Desired: zod_1.z.string(), slippageTolerance: zod_1.z.number().default(0.5), deadline: zod_1.z.number().optional(), chainId: zod_1.z.number(), }), execute: async (client, args) => { const deadline = args.deadline || Math.floor(Date.now() / 1000) + 1200; const amount0Desired = BigInt(args.amount0Desired); const amount1Desired = BigInt(args.amount1Desired); const amount0Min = (amount0Desired * (10000n - BigInt(args.slippageTolerance * 100))) / 10000n; const amount1Min = (amount1Desired * (10000n - BigInt(args.slippageTolerance * 100))) / 10000n; const data = (0, viem_1.encodeFunctionData)({ abi: constants_js_2.nonfungiblePositionManagerAbi, functionName: "increaseLiquidity", args: [ { tokenId: BigInt(args.tokenId), amount0Desired, amount1Desired, amount0Min, amount1Min, deadline: BigInt(deadline), }, ], }); const ops = [ { target: (0, constants_js_1.getPositionManagerAddress)(args.chainId), value: "0", data, }, ]; const walletClient = client.getWalletClient(args.chainId); if (!walletClient) { return { intent: `Increase liquidity for position #${args.tokenId}`, ops, chain: args.chainId, }; } const hash = await client.executeOps(ops, args.chainId); return { intent: `Increase liquidity for position #${args.tokenId}`, ops, chain: args.chainId, hash, }; }, }); exports.intentIncreaseLiquidity = intentIncreaseLiquidity; const intentDecreaseLiquidity = (0, client_js_1.createTool)({ name: "intentDecreaseLiquidity", description: "Removes liquidity from a Uniswap V3 position", supportedChains: constants_js_1.supportedChains, parameters: zod_1.z.object({ tokenId: zod_1.z.string(), liquidity: zod_1.z.string(), slippageTolerance: zod_1.z.number().default(0.5), deadline: zod_1.z.number().optional(), chainId: zod_1.z.number(), }), execute: async (client, args) => { const deadline = args.deadline || Math.floor(Date.now() / 1000) + 1200; const liquidity = BigInt(args.liquidity); const amountMin = (liquidity * (10000n - BigInt(args.slippageTolerance * 100))) / 10000n; const data = (0, viem_1.encodeFunctionData)({ abi: constants_js_2.nonfungiblePositionManagerAbi, functionName: "decreaseLiquidity", args: [ { tokenId: BigInt(args.tokenId), liquidity, amount0Min: amountMin, amount1Min: amountMin, deadline: BigInt(deadline), }, ], }); const ops = [ { target: (0, constants_js_1.getPositionManagerAddress)(args.chainId), value: "0", data, }, ]; const walletClient = client.getWalletClient(args.chainId); if (!walletClient) { return { intent: `Decrease liquidity for position #${args.tokenId}`, ops, chain: args.chainId, }; } const hash = await client.executeOps(ops, args.chainId); return { intent: `Decrease liquidity for position #${args.tokenId}`, ops, chain: args.chainId, hash, }; }, }); exports.intentDecreaseLiquidity = intentDecreaseLiquidity; const intentCollectFees = (0, client_js_1.createTool)({ name: "intentCollectFees", description: "Collects accumulated fees from a Uniswap V3 position", supportedChains: constants_js_1.supportedChains, parameters: zod_1.z.object({ tokenId: zod_1.z.string(), recipient: zod_1.z.string().optional(), chainId: zod_1.z.number(), }), execute: async (client, args) => { const user = await client.getAddress(); const data = (0, viem_1.encodeFunctionData)({ abi: constants_js_2.nonfungiblePositionManagerAbi, functionName: "collect", args: [ { tokenId: BigInt(args.tokenId), recipient: args.recipient || user, amount0Max: viem_1.maxUint128, amount1Max: viem_1.maxUint128, }, ], }); const ops = [ { target: (0, constants_js_1.getPositionManagerAddress)(args.chainId), value: "0", data, }, ]; const walletClient = client.getWalletClient(args.chainId); if (!walletClient) { return { intent: `Collect fees from position #${args.tokenId}`, ops, chain: args.chainId, }; } const hash = await client.executeOps(ops, args.chainId); return { intent: `Collect fees from position #${args.tokenId}`, ops, chain: args.chainId, hash, }; }, }); exports.intentCollectFees = intentCollectFees; const intentTransferPosition = (0, client_js_1.createTool)({ name: "intentTransferPosition", description: "Transfers ownership of a Uniswap V3 LP NFT", supportedChains: constants_js_1.supportedChains, parameters: zod_1.z.object({ tokenId: zod_1.z.string(), to: zod_1.z.string(), chainId: zod_1.z.number(), }), execute: async (client, args) => { const data = (0, viem_1.encodeFunctionData)({ abi: viem_1.erc721Abi, functionName: "safeTransferFrom", args: [ await client.getAddress(), args.to, BigInt(args.tokenId), ], }); const ops = [ { target: (0, constants_js_1.getPositionManagerAddress)(args.chainId), value: "0", data, }, ]; const walletClient = client.getWalletClient(args.chainId); if (!walletClient) { return { intent: `Transfer position #${args.tokenId} to ${args.to}`, ops, chain: args.chainId, }; } const hash = await client.executeOps(ops, args.chainId); return { intent: `Transfer position #${args.tokenId} to ${args.to}`, ops, chain: args.chainId, hash, }; }, }); exports.intentTransferPosition = intentTransferPosition; //# sourceMappingURL=intents.js.map