UNPKG

@brian-ai/langchain

Version:

Repository containing the LangchainJS toolkit for creating powerful web3 agents.

2,218 lines (2,200 loc) 177 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { BrianCDPToolkit: () => BrianCDPToolkit, BrianStarknetToolkit: () => BrianStarknetToolkit, BrianToolkit: () => BrianToolkit, FarcasterToolkit: () => FarcasterToolkit, TwitterToolkit: () => TwitterToolkit, XMTPCallbackHandler: () => XMTPCallbackHandler, createBrianAgent: () => createBrianAgent, createBrianCDPAgent: () => createBrianCDPAgent, createBrianStarknetAgent: () => createBrianStarknetAgent, createFarcasterMemoryVectorStore: () => createFarcasterMemoryVectorStore, createFarcasterSupabaseVectorStore: () => createFarcasterSupabaseVectorStore }); module.exports = __toCommonJS(src_exports); // src/callback-handlers/xmtp.ts var import_base = require("@langchain/core/tracers/base"); // src/callback-handlers/utils.ts var tryJsonStringify = (obj, fallback) => { try { return JSON.stringify(obj, null, 2); } catch (err) { return fallback; } }; var formatKVMapItem = (value) => { if (typeof value === "string") { return value.trim(); } if (value === null || value === void 0) { return value; } return tryJsonStringify(value, value.toString()); }; // src/callback-handlers/xmtp.ts var generateSystemTemplate = (instructions) => { return [ instructions, "Generate a message based on the context that the user will provide. This message must be human-readable without any complex terms.", "Your message will be sent to a chat, so make sure it is clear and concise.", "Speak in first person, since the context that you will receive will be related to your actions and thoughts." ].join("\n"); }; var generateMessage = async (llm, instructions, context) => { const result = await llm.invoke([ { role: "system", content: generateSystemTemplate(instructions) }, { role: "user", content: context } ]); return typeof result === "string" ? result : result.text; }; var XMTPCallbackHandler = class extends import_base.BaseTracer { name = "xmtp_callback_handler"; xmtpHandler; llm; instructions; options = { onChainStart: false, onChainEnd: false, onChainError: false, onLLMStart: false, onLLMEnd: false, onLLMError: false, onToolStart: false, onToolEnd: false, onToolError: false, onRetrieverStart: false, onRetrieverEnd: false, onRetrieverError: false, onAgentAction: false }; persistRun(run) { return Promise.resolve(); } constructor(xmtpHandler, llm, instructions, options) { super(); this.xmtpHandler = xmtpHandler; this.llm = llm; this.instructions = instructions || "You are a web3 helpful assistant"; this.options = options || this.options; } /** * Method used to get all the parent runs of a given run. * @param run The run whose parents are to be retrieved. * @returns An array of parent runs. */ getParents(run) { const parents = []; let currentRun = run; while (currentRun.parent_run_id) { const parent = this.runMap.get(currentRun.parent_run_id); if (parent) { parents.push(parent); currentRun = parent; } else { break; } } return parents; } /** * Method used to get a string representation of the run's lineage, which * is used in logging. * @param run The run whose lineage is to be retrieved. * @returns A string representation of the run's lineage. */ getBreadcrumbs(run) { const parents = this.getParents(run).reverse(); const string = [...parents, run].map((parent, i, arr) => { const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`; return name; }).join(" > "); return string; } // logging methods /** * Method used to log the start of a chain run. * @param run The chain run that has started. * @returns void */ async onChainStart(run) { if (!this.options.onChainStart) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `You are entering the chain of thoughts with this input: ${tryJsonStringify( run.inputs, "[inputs]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the end of a chain run. * @param run The chain run that has ended. * @returns void */ async onChainEnd(run) { if (!this.options.onChainEnd) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `You are exiting the chain of thoughts with this output: ${tryJsonStringify( run.outputs, "[outputs]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log any errors of a chain run. * @param run The chain run that has errored. * @returns void */ async onChainError(run) { if (!this.options.onChainError) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `Chain run errored with error: ${tryJsonStringify(run.error, "[error]")}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the start of an LLM run. * @param run The LLM run that has started. * @returns void */ async onLLMStart(run) { if (!this.options.onLLMStart) return; const crumbs = this.getBreadcrumbs(run); const inputs = "prompts" in run.inputs ? { prompts: run.inputs.prompts.map((p) => p.trim()) } : run.inputs; const message = await generateMessage( this.llm, this.instructions, `You are entering the LLM run with this input: ${tryJsonStringify( inputs, "[inputs]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the end of an LLM run. * @param run The LLM run that has ended. * @returns void */ async onLLMEnd(run) { if (!this.options.onLLMEnd) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `You are exiting the LLM run with this output: ${tryJsonStringify( run.outputs, "[outputs]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log any errors of an LLM run. * @param run The LLM run that has errored. * @returns void */ async onLLMError(run) { if (!this.options.onLLMError) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `LLM run errored with error: ${tryJsonStringify(run.error, "[error]")}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the start of a tool run. * @param run The tool run that has started. * @returns void */ async onToolStart(run) { if (!this.options.onToolStart) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `You are entering the Tool run with this input: ${tryJsonStringify( run.inputs, "[inputs]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the end of a tool run. * @param run The tool run that has ended. * @returns void */ async onToolEnd(run) { if (!this.options.onToolEnd) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `You are exiting the Tool run with this output: "${formatKVMapItem( run.outputs?.output )}".` ); await this.xmtpHandler.send(message); } /** * Method used to log any errors of a tool run. * @param run The tool run that has errored. * @returns void */ async onToolError(run) { if (!this.options.onToolError) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `Tool run errored with error: ${tryJsonStringify(run.error, "[error]")}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the start of a retriever run. * @param run The retriever run that has started. * @returns void */ async onRetrieverStart(run) { if (!this.options.onRetrieverStart) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `You are entering the Retriever run with this input: ${tryJsonStringify( run.inputs, "[inputs]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the end of a retriever run. * @param run The retriever run that has ended. * @returns void */ async onRetrieverEnd(run) { if (!this.options.onRetrieverEnd) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `You are exiting the Retriever run with this output: ${tryJsonStringify( run.outputs, "[outputs]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log any errors of a retriever run. * @param run The retriever run that has errored. * @returns void */ async onRetrieverError(run) { if (!this.options.onRetrieverError) return; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `Retriever run errored with error: ${tryJsonStringify( run.error, "[error]" )}.` ); await this.xmtpHandler.send(message); } /** * Method used to log the action selected by the agent. * @param run The run in which the agent action occurred. * @returns void */ async onAgentAction(run) { if (!this.options.onAgentAction) return; const agentRun = run; const crumbs = this.getBreadcrumbs(run); const message = await generateMessage( this.llm, this.instructions, `Agent selected action: ${tryJsonStringify( agentRun.actions[agentRun.actions.length - 1], "[action]" )}.` ); await this.xmtpHandler.send(message); } }; // src/toolkits/brian/index.ts var import_sdk2 = require("@brian-ai/sdk"); var import_tools2 = require("@langchain/core/tools"); var import_accounts = require("viem/accounts"); // src/toolkits/brian/tools/balance-tool.ts var import_zod = require("zod"); // src/toolkits/brian/tools/tool.ts var import_tools = require("langchain/tools"); var BrianTool = class extends import_tools.DynamicStructuredTool { brianSDK; account; options; constructor(fields) { super(fields); this.brianSDK = fields.brianSDK; this.account = fields.account; this.options = fields.options; } }; // src/toolkits/brian/tools/balance-tool.ts var balanceToolSchema = import_zod.z.object({ token: import_zod.z.string(), chain: import_zod.z.string(), address: import_zod.z.string().or(import_zod.z.undefined()) }); var createGetBalanceTool = (brianSDK, account) => { return new BrianTool({ name: "get_balance", description: "returns the balance of the token for the given address on the given chain.", schema: balanceToolSchema, brianSDK, account, func: async ({ token, chain, address }) => { const prompt = `What is the ${token} balance of ${address || account.address} on ${chain}?`; const brianTx = await brianSDK.transact({ prompt, address: account.address }); if (brianTx.length === 0) { return `The ${token} balance of ${address || account.address} is 0 on ${chain}.`; } const [tx] = brianTx; return tx.data.description; } }); }; // src/toolkits/brian/tools/borrow-tool.ts var import_zod2 = require("zod"); // src/toolkits/brian/tools/utils.ts var import_viem = require("viem"); // src/utils/index.ts var chains = __toESM(require("viem/chains"), 1); var getChain = (chainId) => { for (const chain of Object.values(chains)) { if ("id" in chain) { if (chain.id === chainId) { return chain; } } } throw new Error(`Chain with id ${chainId} not found`); }; var isZkChain = (chainId) => { const zkChains = [chains.zksync.id]; return zkChains.includes(chainId); }; var roundToFirstDecimal = (value) => { if (value >= 1) { return value.toFixed(1); } const decimalPlaces = 1 - Math.floor(Math.log10(value)); return value.toFixed(decimalPlaces); }; // src/toolkits/brian/tools/utils.ts var import_relay_sdk_viem = require("@gelatonetwork/relay-sdk-viem"); var import_zksync = require("viem/zksync"); var getChainAndClients = (account, chainId) => { const network = getChain(chainId); const walletClient = isZkChain(chainId) ? (0, import_viem.createWalletClient)({ account, chain: network, transport: (0, import_viem.http)() }).extend((0, import_zksync.eip712WalletActions)()) : (0, import_viem.createWalletClient)({ account, chain: network, transport: (0, import_viem.http)() }); const publicClient = (0, import_viem.createPublicClient)({ chain: network, transport: (0, import_viem.http)() }); return { network, walletClient, publicClient }; }; var executeTransactionSteps = async (data, account, successMessage, options) => { const chainId = data.fromChainId; const { network, walletClient, publicClient } = getChainAndClients( account, chainId ); if (options?.gelatoApiKey) { let lastTxLink = ""; const gelatoRelay = new import_relay_sdk_viem.GelatoRelay(); const walletClient2 = (0, import_viem.createWalletClient)({ account, transport: (0, import_viem.http)() }); for (const step of data.steps) { const gelatoRequest = { user: step.from, chainId: BigInt(network.id), target: step.to, data: step.data }; const gelatoResponse = await gelatoRelay.sponsoredCallERC2771( gelatoRequest, walletClient2, options.gelatoApiKey ); lastTxLink = `https://relay.gelato.digital/tasks/status/${gelatoResponse.taskId}`; } return `${successMessage} - You can check the transaction here: ${lastTxLink}`; } else { let lastTxLink = ""; for (const step of data.steps) { if (step.chainId !== walletClient.chain.id) { await walletClient.switchChain({ id: step.chainId }); } const txHash = await walletClient.sendTransaction({ from: step.from, to: step.to, value: BigInt(step.value), data: step.data, chainId: step.chainId }); console.log( `Transaction executed, tx hash: ${txHash} -- waiting for confirmation.` ); const { transactionHash } = await publicClient.waitForTransactionReceipt({ hash: txHash }); console.log( `Transaction executed successfully, this is the transaction link: ${network.blockExplorers?.default.url}/tx/${transactionHash}` ); lastTxLink = `${network.blockExplorers?.default.url}/tx/${transactionHash}`; } return `${successMessage} - You can check the transaction here: ${lastTxLink}`; } }; // src/toolkits/brian/tools/borrow-tool.ts var borrowToolSchema = import_zod2.z.object({ token: import_zod2.z.string(), chain: import_zod2.z.string(), amount: import_zod2.z.string() }); var createBorrowTool = (brianSDK, account, options) => { return new BrianTool({ name: "borrow", description: "borrows the amount of token from aave on the given chain. you must've deposited before to execute this action.", schema: borrowToolSchema, brianSDK, account, options, func: async ({ token, amount, chain }) => { const prompt = `Borrow ${amount} ${token} on ${chain}`; const brianTx = await brianSDK.transact({ prompt, address: account.address }); if (brianTx.length === 0) { return "Whoops, could not perform the borrow, an error occurred while calling the Brian APIs."; } const [tx] = brianTx; const { data } = tx; if (data.steps && data.steps.length > 0) { return await executeTransactionSteps( data, account, `Borrow executed successfully! I've borrowed ${amount} of ${token} on ${chain}.`, options ); } return "No transaction to be executed from this prompt. Maybe you should try with another one?"; } }); }; // src/toolkits/brian/tools/bridge-tool.ts var import_zod3 = require("zod"); var bridgeToolSchema = import_zod3.z.object({ tokenIn: import_zod3.z.string(), inputChain: import_zod3.z.string(), outputChain: import_zod3.z.string(), amount: import_zod3.z.string() }); var createBridgeTool = (brianSDK, account, options) => { return new BrianTool({ name: "bridge", description: "bridges the amount of tokenIn from the inputChain to the outputChain", schema: bridgeToolSchema, brianSDK, account, options, func: async ({ tokenIn, inputChain, outputChain, amount }) => { const prompt = `Bridge ${amount} ${tokenIn} from ${inputChain} to ${outputChain}`; const brianTx = await brianSDK.transact({ prompt, address: account.address }); if (brianTx.length === 0) { return "Whoops, could not perform the bridge, an error occurred while calling the Brian APIs."; } const [tx] = brianTx; const { data } = tx; if (data.steps && data.steps.length > 0) { return await executeTransactionSteps( data, account, `Bridge executed successfully! I've moved ${amount} of ${tokenIn} from ${inputChain} to ${outputChain}.`, options ); } return "No transaction to be executed from this prompt. Maybe you should try with another one?"; } }); }; // src/toolkits/brian/tools/create-pool-tool.ts var import_viem2 = require("viem"); var import_zod4 = require("zod"); var import_sdk_core = require("@uniswap/sdk-core"); var import_v3_sdk = require("@uniswap/v3-sdk"); // src/abis/uniswap-v3-pool.ts var UNISWAP_V3_POOL_ABI = [ { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address" }, { indexed: true, internalType: "int24", name: "tickLower", type: "int24" }, { indexed: true, internalType: "int24", name: "tickUpper", type: "int24" }, { indexed: false, internalType: "uint128", name: "amount", type: "uint128" }, { indexed: false, internalType: "uint256", name: "amount0", type: "uint256" }, { indexed: false, internalType: "uint256", name: "amount1", type: "uint256" } ], name: "Burn", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address" }, { indexed: false, internalType: "address", name: "recipient", type: "address" }, { indexed: true, internalType: "int24", name: "tickLower", type: "int24" }, { indexed: true, internalType: "int24", name: "tickUpper", type: "int24" }, { indexed: false, internalType: "uint128", name: "amount0", type: "uint128" }, { indexed: false, internalType: "uint128", name: "amount1", type: "uint128" } ], name: "Collect", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "sender", type: "address" }, { indexed: true, internalType: "address", name: "recipient", type: "address" }, { indexed: false, internalType: "uint128", name: "amount0", type: "uint128" }, { indexed: false, internalType: "uint128", name: "amount1", type: "uint128" } ], name: "CollectProtocol", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "sender", type: "address" }, { indexed: true, internalType: "address", name: "recipient", type: "address" }, { indexed: false, internalType: "uint256", name: "amount0", type: "uint256" }, { indexed: false, internalType: "uint256", name: "amount1", type: "uint256" }, { indexed: false, internalType: "uint256", name: "paid0", type: "uint256" }, { indexed: false, internalType: "uint256", name: "paid1", type: "uint256" } ], name: "Flash", type: "event" }, { anonymous: false, inputs: [ { indexed: false, internalType: "uint16", name: "observationCardinalityNextOld", type: "uint16" }, { indexed: false, internalType: "uint16", name: "observationCardinalityNextNew", type: "uint16" } ], name: "IncreaseObservationCardinalityNext", type: "event" }, { anonymous: false, inputs: [ { indexed: false, internalType: "uint160", name: "sqrtPriceX96", type: "uint160" }, { indexed: false, internalType: "int24", name: "tick", type: "int24" } ], name: "Initialize", type: "event" }, { anonymous: false, inputs: [ { indexed: false, internalType: "address", name: "sender", type: "address" }, { indexed: true, internalType: "address", name: "owner", type: "address" }, { indexed: true, internalType: "int24", name: "tickLower", type: "int24" }, { indexed: true, internalType: "int24", name: "tickUpper", type: "int24" }, { indexed: false, internalType: "uint128", name: "amount", type: "uint128" }, { indexed: false, internalType: "uint256", name: "amount0", type: "uint256" }, { indexed: false, internalType: "uint256", name: "amount1", type: "uint256" } ], name: "Mint", type: "event" }, { anonymous: false, inputs: [ { indexed: false, internalType: "uint8", name: "feeProtocol0Old", type: "uint8" }, { indexed: false, internalType: "uint8", name: "feeProtocol1Old", type: "uint8" }, { indexed: false, internalType: "uint8", name: "feeProtocol0New", type: "uint8" }, { indexed: false, internalType: "uint8", name: "feeProtocol1New", type: "uint8" } ], name: "SetFeeProtocol", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "sender", type: "address" }, { indexed: true, internalType: "address", name: "recipient", type: "address" }, { indexed: false, internalType: "int256", name: "amount0", type: "int256" }, { indexed: false, internalType: "int256", name: "amount1", type: "int256" }, { indexed: false, internalType: "uint160", name: "sqrtPriceX96", type: "uint160" }, { indexed: false, internalType: "uint128", name: "liquidity", type: "uint128" }, { indexed: false, internalType: "int24", name: "tick", type: "int24" } ], name: "Swap", type: "event" }, { inputs: [ { internalType: "int24", name: "tickLower", type: "int24" }, { internalType: "int24", name: "tickUpper", type: "int24" }, { internalType: "uint128", name: "amount", type: "uint128" } ], name: "burn", outputs: [ { internalType: "uint256", name: "amount0", type: "uint256" }, { internalType: "uint256", name: "amount1", type: "uint256" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "recipient", type: "address" }, { internalType: "int24", name: "tickLower", type: "int24" }, { internalType: "int24", name: "tickUpper", type: "int24" }, { internalType: "uint128", name: "amount0Requested", type: "uint128" }, { internalType: "uint128", name: "amount1Requested", type: "uint128" } ], name: "collect", outputs: [ { internalType: "uint128", name: "amount0", type: "uint128" }, { internalType: "uint128", name: "amount1", type: "uint128" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "recipient", type: "address" }, { internalType: "uint128", name: "amount0Requested", type: "uint128" }, { internalType: "uint128", name: "amount1Requested", type: "uint128" } ], name: "collectProtocol", outputs: [ { internalType: "uint128", name: "amount0", type: "uint128" }, { internalType: "uint128", name: "amount1", type: "uint128" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [], name: "factory", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "fee", outputs: [ { internalType: "uint24", name: "", type: "uint24" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "feeGrowthGlobal0X128", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "feeGrowthGlobal1X128", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "recipient", type: "address" }, { internalType: "uint256", name: "amount0", type: "uint256" }, { internalType: "uint256", name: "amount1", type: "uint256" }, { internalType: "bytes", name: "data", type: "bytes" } ], name: "flash", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint16", name: "observationCardinalityNext", type: "uint16" } ], name: "increaseObservationCardinalityNext", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint160", name: "sqrtPriceX96", type: "uint160" } ], name: "initialize", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [], name: "liquidity", outputs: [ { internalType: "uint128", name: "", type: "uint128" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "maxLiquidityPerTick", outputs: [ { internalType: "uint128", name: "", type: "uint128" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "recipient", type: "address" }, { internalType: "int24", name: "tickLower", type: "int24" }, { internalType: "int24", name: "tickUpper", type: "int24" }, { internalType: "uint128", name: "amount", type: "uint128" }, { internalType: "bytes", name: "data", type: "bytes" } ], name: "mint", outputs: [ { internalType: "uint256", name: "amount0", type: "uint256" }, { internalType: "uint256", name: "amount1", type: "uint256" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "index", type: "uint256" } ], name: "observations", outputs: [ { internalType: "uint32", name: "blockTimestamp", type: "uint32" }, { internalType: "int56", name: "tickCumulative", type: "int56" }, { internalType: "uint160", name: "secondsPerLiquidityCumulativeX128", type: "uint160" }, { internalType: "bool", name: "initialized", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "uint32[]", name: "secondsAgos", type: "uint32[]" } ], name: "observe", outputs: [ { internalType: "int56[]", name: "tickCumulatives", type: "int56[]" }, { internalType: "uint160[]", name: "secondsPerLiquidityCumulativeX128s", type: "uint160[]" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "bytes32", name: "key", type: "bytes32" } ], name: "positions", outputs: [ { internalType: "uint128", name: "_liquidity", type: "uint128" }, { internalType: "uint256", name: "feeGrowthInside0LastX128", type: "uint256" }, { internalType: "uint256", name: "feeGrowthInside1LastX128", type: "uint256" }, { internalType: "uint128", name: "tokensOwed0", type: "uint128" }, { internalType: "uint128", name: "tokensOwed1", type: "uint128" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "protocolFees", outputs: [ { internalType: "uint128", name: "token0", type: "uint128" }, { internalType: "uint128", name: "token1", type: "uint128" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "uint8", name: "feeProtocol0", type: "uint8" }, { internalType: "uint8", name: "feeProtocol1", type: "uint8" } ], name: "setFeeProtocol", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [], name: "slot0", outputs: [ { internalType: "uint160", name: "sqrtPriceX96", type: "uint160" }, { internalType: "int24", name: "tick", type: "int24" }, { internalType: "uint16", name: "observationIndex", type: "uint16" }, { internalType: "uint16", name: "observationCardinality", type: "uint16" }, { internalType: "uint16", name: "observationCardinalityNext", type: "uint16" }, { internalType: "uint8", name: "feeProtocol", type: "uint8" }, { internalType: "bool", name: "unlocked", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "int24", name: "tickLower", type: "int24" }, { internalType: "int24", name: "tickUpper", type: "int24" } ], name: "snapshotCumulativesInside", outputs: [ { internalType: "int56", name: "tickCumulativeInside", type: "int56" }, { internalType: "uint160", name: "secondsPerLiquidityInsideX128", type: "uint160" }, { internalType: "uint32", name: "secondsInside", type: "uint32" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "recipient", type: "address" }, { internalType: "bool", name: "zeroForOne", type: "bool" }, { internalType: "int256", name: "amountSpecified", type: "int256" }, { internalType: "uint160", name: "sqrtPriceLimitX96", type: "uint160" }, { internalType: "bytes", name: "data", type: "bytes" } ], name: "swap", outputs: [ { internalType: "int256", name: "amount0", type: "int256" }, { internalType: "int256", name: "amount1", type: "int256" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "int16", name: "wordPosition", type: "int16" } ], name: "tickBitmap", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "tickSpacing", outputs: [ { internalType: "int24", name: "", type: "int24" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "int24", name: "tick", type: "int24" } ], name: "ticks", outputs: [ { internalType: "uint128", name: "liquidityGross", type: "uint128" }, { internalType: "int128", name: "liquidityNet", type: "int128" }, { internalType: "uint256", name: "feeGrowthOutside0X128", type: "uint256" }, { internalType: "uint256", name: "feeGrowthOutside1X128", type: "uint256" }, { internalType: "int56", name: "tickCumulativeOutside", type: "int56" }, { internalType: "uint160", name: "secondsPerLiquidityOutsideX128", type: "uint160" }, { internalType: "uint32", name: "secondsOutside", type: "uint32" }, { internalType: "bool", name: "initialized", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "token0", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "token1", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" } ]; // src/abis/uniswap-v3-position-manager.ts var NON_FUNGIBLE_POSITION_MANAGER_ABI = [ { inputs: [ { internalType: "address", name: "_factory", type: "address" }, { internalType: "address", name: "_WETH9", type: "address" }, { internalType: "address", name: "_tokenDescriptor_", type: "address" } ], stateMutability: "nonpayable", type: "constructor" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address" }, { indexed: true, internalType: "address", name: "approved", type: "address" }, { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "Approval", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address" }, { indexed: true, internalType: "address", name: "operator", type: "address" }, { indexed: false, internalType: "bool", name: "approved", type: "bool" } ], name: "ApprovalForAll", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" }, { indexed: false, internalType: "address", name: "recipient", type: "address" }, { indexed: false, internalType: "uint256", name: "amount0", type: "uint256" }, { indexed: false, internalType: "uint256", name: "amount1", type: "uint256" } ], name: "Collect", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" }, { indexed: false, internalType: "uint128", name: "liquidity", type: "uint128" }, { indexed: false, internalType: "uint256", name: "amount0", type: "uint256" }, { indexed: false, internalType: "uint256", name: "amount1", type: "uint256" } ], name: "DecreaseLiquidity", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" }, { indexed: false, internalType: "uint128", name: "liquidity", type: "uint128" }, { indexed: false, internalType: "uint256", name: "amount0", type: "uint256" }, { indexed: false, internalType: "uint256", name: "amount1", type: "uint256" } ], name: "IncreaseLiquidity", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "from", type: "address" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "Transfer", type: "event" }, { inputs: [], name: "DOMAIN_SEPARATOR", outputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "PERMIT_TYPEHASH", outputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "WETH9", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "to", type: "address" }, { internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "approve", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "owner", type: "address" } ], name: "balanceOf", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "baseURI", outputs: [ { internalType: "string", name: "", type: "string" } ], stateMutability: "pure", type: "function" }, { inputs: [ { internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "burn", outputs: [], stateMutability: "payable", type: "function" }, { inputs: [ { components: [ { internalType: "uint256", name: "tokenId", type: "uint256" }, { internalType: "address", name: "recipient", type: "address" }, { internalType: "uint128", name: "amount0Max", type: "uint128" }, { internalType: "uint128", name: "amount1Max", type: "uint128" } ], internalType: "struct INonfungiblePositionManager.CollectParams", name: "params", type: "tuple" } ], name: "collect", outputs: [ { internalType: "uint256", name: "amount0", type: "uint256" }, { internalType: "uint256", name: "amount1", type: "uint256" } ], stateMutability: "payable", type: "function" }, { inputs: [ { internalType: "address", name: "token0", type: "address" }, { internalType: "address", name: "token1", type: "address" }, { internalType: "uint24", name: "fee", type: "uint24" }, { internalType: "uint160", name: "sqrtPriceX96", type: "uint160" } ], name: "createAndInitializePoolIfNecessary", outputs: [ { internalType: "address", name: "pool", type: "address" } ], stateMutability: "payable", type: "function" }, { inputs: [ { components: [ { internalType: "uint256", name: "tokenId", type: "uint256" }, { internalType: "uint128", name: "liquidity", type: "uint128" }, { internalType: "uint256", name: "amount0Min", type: "uint256" }, { internalType: "uint256", name: "amount1Min", type: "uint256" }, { internalType: "uint256", name: "deadline", type: "uint256" } ], internalType: "struct INonfungiblePositionManager.DecreaseLiquidityParams", name: "params", type: "tuple" } ], name: "decreaseLiquidity", outputs: [ { internalType: "uint256", name: "amount0", type: "uint256" }, { internalType: "uint256", name: "amount1", type: "uint256" } ], stateMutability: "payable", type: "function" }, { inputs: [], name: "factory", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "getApproved", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [ { components: [ { internalType: "uint256", name: "tokenId", type: "uint256" }, { internalType: "uint256", name: "amount0Desired", type: "uint256" }, { internalType: "uint256", name: "amount1Desired", type: "uint256" }, { internalType: "uint256", name: "amount0Min", type: "uint256" }, { internalType: "uint256", name: "amount1Min", type: "uint256" }, { internalType: "uint256", name: "deadline", type: "uint256" } ], internalType: "struct INonfungiblePositionManager.IncreaseLiquidityParams", name: "params", type: "tuple" } ], name: "increaseLiquidity", outputs: [ { internalType: "uint128", name: "liquidity", type: "uint128" }, { internalType: "uint256", name: "amount0", type: "uint256" }, { internalType: "uint256", name: "amount1", type: "uint256" } ], stateMutability: "payable", type: "function" }, { inputs: [ { internalType: "address", name: "owner", type: "address" }, { internalType: "address", name: "operator", type: "address" } ], name: "isApprovedForAll", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [ { components: [ { internalType: "address", name: "token0", type: "address" }, { internalType: "address", name: "token1", type: "address" }, { internalType: "uint24", name: "fee", type: "uint24" }, { internalType: "int24", name: "tickLower", type: "int24" }, { internalType: "int24", name: "tickUpper", type: "int24" }, { internalType: "uint256", name: "amount0Desired", type: "uint256" }, { internalType: "uint256", name: "amount1Desired", type: "uint256" }, { internalType: "uint256", name: "amount0Min", type: "uint256" }, { internalType: "uint256", name: "amount1Min", type: "uint256" }, { internalType: "address", name: "recipient", type: "address" }, { internalType: "uint256", name: "deadline", type: "uint256" } ], internalType: "struct INonfungiblePositionManager.MintParams", name: "params", type: "tuple" } ], name: "mint", outputs: [ { internalType: "uint256", name: "tokenId",