import { type AccrualVaultV2 } from "@morpho-org/blue-sdk"; import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem"; import { type Address } from "viem"; import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types"; import type { FetchParameters } from "../../types/data"; export interface VaultV2Actions { /** * Fetches the latest vault data. * * This function fetches the latest vault data from the blockchain. * @param {FetchParameters} [parameters] - The parameters for the fetch operation. * * @returns {Promise>>} The latest vault data. */ getData: (parameters?: FetchParameters) => Promise>>; /** * Prepares a deposit transaction for the VaultV2 contract. * * This function constructs the transaction data required to deposit a specified amount of assets into the vault. * Uses pre-fetched accrual vault data for accurate calculations of slippage and asset address, * then returns the prepared deposit transaction and a function for retrieving all required approval transactions. * Bundler Integration: This flow uses the bundler to atomically execute the user's asset transfer and vault deposit in a single transaction for slippage protection. * * @param {Object} params - The deposit parameters. * @param {bigint} [params.amount=0n] - Amount of ERC-20 assets to deposit. At least one of amount or nativeAmount must be provided. * @param {Address} params.userAddress - User address initiating the deposit. * @param {AccrualVaultV2} params.accrualVault - Pre-fetched vault data with asset address and share conversion. * @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Optional slippage tolerance value. Default is 0.03%. Slippage tolerance must be less than 10%. * @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative. * @returns {Object} The result object. * @returns {Readonly>} returns.tx The prepared deposit transaction. * @returns {Promise<(Readonly> | Requirement)[]>} returns.getRequirements The function for retrieving all required approval transactions. */ deposit: (params: { userAddress: Address; accrualVault: AccrualVaultV2; slippageTolerance?: bigint; } & DepositAmountArgs) => { buildTx: (requirementSignature?: RequirementSignature) => Readonly>; getRequirements: (params?: { useSimplePermit?: boolean; }) => Promise<(Readonly> | Requirement)[]>; }; /** * Prepares a withdraw transaction for the VaultV2 contract. * * This function constructs the transaction data required to withdraw a specified amount of assets from the vault. * * @param {Object} params - The withdraw parameters. * @param {bigint} params.amount - The amount of assets to withdraw. * @param {Address} params.userAddress - User address initiating the withdraw. * @returns {Object} The result object. * @returns {Readonly>} returns.tx The prepared withdraw transaction. */ withdraw: (params: { amount: bigint; userAddress: Address; }) => { buildTx: () => Readonly>; }; /** * Prepares a redeem transaction for the VaultV2 contract. * * This function constructs the transaction data required to redeem a specified amount of shares from the vault. * * @param {Object} params - The redeem parameters. * @param {bigint} params.shares - The amount of shares to redeem. * @param {Address} params.userAddress - User address initiating the redeem. * @returns {Object} The result object. * @returns {Readonly>} returns.tx The prepared redeem transaction. */ redeem: (params: { shares: bigint; userAddress: Address; }) => { buildTx: () => Readonly>; }; /** * Prepares a force withdraw transaction for the VaultV2 contract using the vault's native multicall. * * This function encodes one or more on-chain forceDeallocate calls followed by a single withdraw, * executed atomically via VaultV2's multicall. This allows a user to free liquidity from multiple * illiquid markets and withdraw the resulting assets in one transaction. * * @param {Object} params - The force withdraw parameters. * @param {readonly Deallocation[]} params.deallocations - The typed list of deallocations to perform. * @param {Object} params.withdraw - The withdraw parameters applied after deallocations. * @param {bigint} params.withdraw.amount - The amount of assets to withdraw. * @param {Address} params.userAddress - User address (penalty source and withdraw recipient). * @returns {Object} The result object. * @returns {Readonly>} returns.buildTx The prepared multicall transaction. */ forceWithdraw: (params: { deallocations: readonly Deallocation[]; withdraw: { amount: bigint; }; userAddress: Address; }) => { buildTx: () => Readonly>; }; /** * Prepares a force redeem transaction for the VaultV2 contract using the vault's native multicall. * * This function encodes one or more on-chain forceDeallocate calls followed by a single redeem, * executed atomically via VaultV2's multicall. This allows a user to free liquidity from multiple * illiquid markets and redeem all their shares in one transaction. * * This is the share-based counterpart to forceWithdraw, useful for maximum withdrawal scenarios * where specifying an exact asset amount is impractical. * * The total assets passed to forceDeallocate calls must be greater than or equal to the * asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated * amounts to account for share-price drift between submission and execution. * * @param {Object} params - The force redeem parameters. * @param {readonly Deallocation[]} params.deallocations - The typed list of deallocations to perform. * @param {Object} params.redeem - The redeem parameters applied after deallocations. * @param {bigint} params.redeem.shares - The amount of shares to redeem. * @param {Address} params.userAddress - User address (penalty source and redeem recipient). * @returns {Object} The result object. * @returns {Readonly>} returns.buildTx The prepared multicall transaction. */ forceRedeem: (params: { deallocations: readonly Deallocation[]; redeem: { shares: bigint; }; userAddress: Address; }) => { buildTx: () => Readonly>; }; } export declare class MorphoVaultV2 implements VaultV2Actions { private readonly client; private readonly vault; private readonly chainId; constructor(client: MorphoClientType, vault: Address, chainId: number); getData(parameters?: FetchParameters): Promise; deposit({ amount, userAddress, accrualVault, slippageTolerance, nativeAmount, }: { userAddress: Address; accrualVault: AccrualVaultV2; slippageTolerance?: bigint; } & DepositAmountArgs): { getRequirements: (params?: { useSimplePermit?: boolean; }) => Promise<(Requirement | Readonly>)[]>; buildTx: (requirementSignature?: RequirementSignature) => Readonly>; }; withdraw({ amount, userAddress }: { amount: bigint; userAddress: Address; }): { buildTx: () => Readonly>; }; redeem({ shares, userAddress }: { shares: bigint; userAddress: Address; }): { buildTx: () => Readonly>; }; forceWithdraw({ deallocations, withdraw, userAddress, }: { deallocations: readonly Deallocation[]; withdraw: { amount: bigint; }; userAddress: Address; }): { buildTx: () => Readonly>; }; forceRedeem({ deallocations, redeem, userAddress, }: { deallocations: readonly Deallocation[]; redeem: { shares: bigint; }; userAddress: Address; }): { buildTx: () => Readonly>; }; }