tensaikit
Version:
An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.
36 lines (35 loc) • 1.78 kB
TypeScript
import { z } from "zod";
import { EvmWalletProvider } from "../../../walletProviders";
import { WithdrawSchema } from "../schemas";
/**
* Withdraws a specified amount of previously supplied loanToken from a Morpho Blue market.
*
* This function:
* 1. Validates that the user-specified amount (`assets`) is a positive number.
* 2. Fetches the Morpho Blue market configuration using the provided `marketId`.
* 3. Determines the token decimals and converts the asset amount to atomic units.
* 4. Encodes the `withdraw` function call for the Morpho Blue contract.
* 5. Sends the transaction to withdraw the specified amount and waits for confirmation.
*
* Used when a user wants to retrieve supplied loanToken funds from a lending position.
*
* @param walletProvider - Instance of {@link EvmWalletProvider} connected to the user's wallet.
* @param args - Object validated by {@link WithdrawSchema}, including:
* @property {string} assets - Amount of loanToken to withdraw (human-readable format).
* @property {string} marketId - The bytes32 market identifier to withdraw from.
*
* @returns A Promise resolving to an object containing:
* @property {string} loanToken - ERC20 address of the token being withdrawn.
* @property {string} txHash - Transaction hash of the withdraw operation.
* @property {object} receipt - The receipt of the completed transaction.
*
* @throws Will throw if:
* - The input `assets` amount is zero or invalid.
* - The market configuration is missing or malformed.
* - The transaction fails to send or confirm.
*/
export declare const writeWithdrawLoanToken: (walletProvider: EvmWalletProvider, args: z.infer<typeof WithdrawSchema>) => Promise<{
loanToken: any;
txHash: `0x${string}`;
receipt: any;
}>;