tensaikit
Version:
An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.
37 lines (36 loc) • 1.77 kB
TypeScript
import { z } from "zod";
import { EvmWalletProvider } from "../../../walletProviders";
import { BorrowSchema } from "../schemas";
/**
* Borrows a specified amount of loanToken from a Morpho Blue market using the connected wallet.
*
* This function:
* 1. Validates the input amount is greater than zero.
* 2. Fetches the market configuration for the provided `marketId`.
* 3. Reads the `decimals` of the loan token to convert user input to atomic units.
* 4. Prepares and encodes the `borrow` transaction for the Morpho Blue contract.
* 5. Sends the transaction and waits for confirmation.
*
* The borrow action transfers the specified loanToken amount from the Morpho market to the caller's wallet.
*
* @param walletProvider - Instance of {@link EvmWalletProvider} connected to the user's wallet.
* @param args - Object validated by {@link BorrowSchema}, containing:
* @property {string} assets - Amount of loanToken to borrow (as a human-readable string).
* @property {string} marketId - The bytes32 hex string identifier for the target market.
*
* @returns A Promise resolving to an object containing:
* @property {string} loanToken - The token being borrowed.
* @property {string} txHash - The transaction hash of the borrow operation.
* @property {object} receipt - The transaction receipt returned by the network.
*
* @throws Will throw if:
* - The input amount is invalid or zero.
* - Market configuration is missing or invalid.
* - Decimals lookup or transaction preparation fails.
* - Transaction fails to send or confirm.
*/
export declare const writeBorrowLoan: (walletProvider: EvmWalletProvider, args: z.infer<typeof BorrowSchema>) => Promise<{
loanToken: any;
txHash: `0x${string}`;
receipt: any;
}>;