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.88 kB
TypeScript
import { z } from "zod";
import { EvmWalletProvider } from "../../../walletProviders";
import { WithdrawCollateralSchema } from "../schemas";
/**
* Withdraws a specified amount of collateralToken from a Morpho Blue market for the connected wallet.
*
* This function:
* 1. Validates that the requested `assets` amount is greater than zero.
* 2. Fetches market configuration using the provided `marketId`.
* 3. Determines the decimals of the collateral token and converts the user-readable amount to atomic units.
* 4. Encodes the `withdrawCollateral` function call to the Morpho Blue contract.
* 5. Sends the transaction to withdraw collateral and waits for its confirmation.
*
* This is typically used to reclaim previously deposited collateral, if conditions allow (e.g. health factor is safe).
*
* @param walletProvider - Instance of {@link EvmWalletProvider} connected to the user's wallet.
* @param args - Object matching {@link WithdrawCollateralSchema}, including:
* @property {string} assets - The amount of collateralToken to withdraw (human-readable string).
* @property {string} marketId - The bytes32 hex identifier of the market to withdraw from.
*
* @returns A Promise resolving to an object containing:
* @property {string} collateralToken - The ERC20 token address of the withdrawn collateral.
* @property {string} txHash - The transaction hash of the withdrawal.
* @property {object} receipt - The transaction receipt after confirmation.
*
* @throws Will throw if:
* - The input amount is invalid or zero.
* - The market configuration cannot be fetched.
* - The transaction fails to send or confirm.
*/
export declare const writeWithdrawCollateralToken: (walletProvider: EvmWalletProvider, args: z.infer<typeof WithdrawCollateralSchema>) => Promise<{
collateralToken: any;
txHash: `0x${string}`;
receipt: any;
}>;