tensaikit
Version:
An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.
38 lines (37 loc) • 1.95 kB
TypeScript
import { z } from "zod";
import { EvmWalletProvider } from "../../../walletProviders";
import { SupplyCollateralSchema } from "../schemas";
/**
* Supplies a specified amount of collateralToken into a Morpho Blue market using the connected wallet.
*
* This function:
* 1. Validates that the input asset amount is greater than zero.
* 2. Fetches the market configuration using the provided marketId.
* 3. Reads the collateralToken's decimals and parses the input amount to atomic units.
* 4. Checks and ensures the token allowance; calls approve if necessary.
* 5. Prepares and encodes the `supplyCollateral` function call to Morpho Blue.
* 6. Sends the transaction and waits for it to be mined.
*
* This is typically used to deposit collateral before borrowing from a Morpho Blue market.
*
* @param walletProvider - Instance of {@link EvmWalletProvider} connected to the user's wallet.
* @param args - Object validated by {@link SupplyCollateralSchema}, including:
* @property {string} assets - The amount of collateralToken to supply (human-readable string).
* @property {string} marketId - The bytes32 hex identifier for the target Morpho Blue market.
*
* @returns A Promise resolving to an object with:
* @property {string} collateralToken - The ERC20 address of the collateral token.
* @property {string} txHash - The hash of the submitted supplyCollateral transaction.
* @property {object} receipt - The transaction receipt after confirmation.
*
* @throws Will throw if:
* - The assets value is invalid or non-positive.
* - The marketId is invalid or configuration cannot be fetched.
* - The token approval process fails.
* - The transaction fails to send or confirm on-chain.
*/
export declare const writeSupplyCollateralToken: (walletProvider: EvmWalletProvider, args: z.infer<typeof SupplyCollateralSchema>) => Promise<{
collateralToken: any;
txHash: `0x${string}`;
receipt: any;
}>;