import type { MarketParams } from "@morpho-org/blue-sdk"; import type { Address } from "viem"; import { type AuthorizationRequirementSignature, type BlueReallocationPlan, type BlueWithdrawAction, type Metadata, type Transaction } from "../../types/index.js"; /** Parameters for {@link blueWithdraw}. */ export interface BlueWithdrawParams { market: { readonly chainId: number; readonly marketParams: MarketParams; }; args: { /** Withdraw assets amount (`0n` when withdrawing by shares). */ assets: bigint; /** Withdraw shares amount (`0n` when withdrawing by assets). */ shares: bigint; /** Address that receives the withdrawn assets. */ receiver: Address; /** Minimum withdraw share price (in ray). Slippage protection. */ minSharePrice: bigint; /** * Homogeneous Vault V1 or Vault V2 reallocations to execute before withdrawing. V1 entries can be * computed via `MorphoBlue.getVaultV1Reallocations({ operation: "withdraw", amount })` or directly * via `computeVaultV1Reallocations({ operation: "withdraw", amount, ... })`. * Vault V1 inputs are deprecated for high-level Blue writes; use Vault V2 for new integrations. */ reallocations?: BlueReallocationPlan; /** * Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is * prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a * standalone `setAuthorization` transaction. */ authorizationSignature?: AuthorizationRequirementSignature; }; metadata?: Metadata; } /** * Prepares a loan-asset withdraw transaction for a Morpho Blue market. * * Routed through bundler3 via `morphoWithdraw`. Supports two modes (exactly one): * * - **By assets** (`assets > 0, shares = 0`): withdraws an exact asset amount. * - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full * supplier position close; immune to interest accrual between tx construction and execution). * * A `reallocations` plan contains either V1 entries or V2 market/idle entries, * never both. The calls run before the withdraw. V1 * fees accumulate in `tx.value`; V2 penalties are paid in the target loan * token and donated to the vaults. The on-chain `morphoWithdraw` sends the * assets computed on-chain directly to `receiver`; no skim is required. * * The withdraw is performed on behalf of the transaction initiator (signer) — there is no * separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned * with the user when none is provided. Requires the user to have authorized `GeneralAdapter1` * on Morpho. * * @param params.market.chainId - The chain the market lives on. * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv). * @param params.args.assets - Withdraw amount in loan-token assets. Set to `0n` in shares mode. * @param params.args.shares - Withdraw amount in supply shares. Set to `0n` in assets mode. * @param params.args.receiver - Address that receives the withdrawn assets. * @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage * protection. * @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to * execute before withdrawing. Vault V1 inputs are deprecated; use Vault V2 for new integrations. * @param params.args.authorizationSignature - Optional signed Morpho authorization; when present, * a `setAuthorizationWithSig` call is prepended to the bundle. * @param params.metadata - Optional analytics metadata attached to the bundle. * @returns A deep-frozen `Transaction` with `to`, `value`, `data`, and * the typed `action` discriminator the simulation layer consumes. * @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, a V1 fee, or a V2 * penalty is negative. * @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation * withdrawal amount is non-positive. * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD. * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties. * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed. * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator. * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape. * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries. * @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero. * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals. * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references * the target market. * @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly * sorted by market id. * @example * ```ts * import { blueWithdraw } from "@morpho-org/morpho-sdk"; * * const tx = blueWithdraw({ * market: { chainId: 1, marketParams }, * args: { * assets: 1_000_000_000n, * shares: 0n, * receiver: supplier, * minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinWithdrawSharePrice` from market state + slippage tolerance * }, * }); * // tx satisfies Readonly> * ``` */ export declare const blueWithdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }: BlueWithdrawParams) => Readonly>;