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.83 kB
TypeScript
import { z } from "zod";
import { EvmWalletProvider } from "../../../walletProviders";
import { RepaySchema } from "../schemas";
/**
* Repays a specified amount of loanToken to a Morpho Blue market on behalf of the connected wallet.
*
* This function:
* 1. Validates that the input amount is a positive number.
* 2. Fetches the market configuration from the Morpho Blue contract using the given `marketId`.
* 3. Determines the loan token's decimals and parses the human-readable amount into atomic units.
* 4. Checks and ensures sufficient allowance; triggers approval if required.
* 5. Encodes the `repay` call and sends the transaction to the Morpho Blue contract.
* 6. Waits for the transaction to be confirmed and returns the result.
*
* @param walletProvider - Instance of {@link EvmWalletProvider} connected to the user's wallet.
* @param args - Object matching {@link RepaySchema}, containing:
* @property {string} assets - Amount of loanToken to repay (as a string in user-readable units).
* @property {string} marketId - Unique bytes32 identifier for the market.
*
* @returns A Promise resolving to an object containing:
* @property {string} loanToken - Address of the loan token being repaid.
* @property {string} txHash - Transaction hash of the repay operation.
* @property {object} receipt - Transaction receipt after successful confirmation.
*
* @throws Will throw an error if:
* - The input amount is invalid or zero.
* - Market configuration is missing or malformed.
* - ERC20 allowance is insufficient and approval fails.
* - Transaction fails to send or confirm on-chain.
*/
export declare const writeRepayLoan: (walletProvider: EvmWalletProvider, args: z.infer<typeof RepaySchema>) => Promise<{
loanToken: any;
txHash: `0x${string}`;
receipt: any;
}>;