import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk"; import type { MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk"; import { type Address } from "viem"; import { type BlueReallocationPlan, type VaultV1Reallocation, type VaultV2BlueReallocation } from "../types/index.js"; /** @internal */ export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0 | 1; /** * Validates that a raw or hydrated Midnight market belongs to the expected chain. * * @param market - Midnight market params or hydrated market state. * @param chainId - Expected EIP-155 chain id. * @returns Nothing when the market belongs to `chainId`. * @throws {ChainIdMismatchError} when the market belongs to another chain. * @example * ```ts * import { validateMidnightMarketChainId } from "@morpho-org/morpho-sdk"; * * validateMidnightMarketChainId(marketParams, 8453); * ``` */ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput, chainId: number) => void; /** * Asserts that the client has a connected account AND that it matches * the provided user address. * * Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which * backs the permit, Permit2, Blue authorization, and Midnight offer-root * signature flows) and by `encodeVaultSharesPermit`, to enforce builder = * signer: the signing flow is * the only path where an account/address mismatch is a real security concern * (rather than just an integrator footgun). * * Transaction builders no longer call this helper — callers are * responsible for keeping `userAddress` aligned with the signing account * at the builder layer. * * @param clientAccountAddress - The client's account address; if undefined, * `MissingClientPropertyError` is thrown. * @param userAddress - The user address provided by the caller. * @returns Nothing; narrows `clientAccountAddress` to a defined `Address` when * it is present and equal to `userAddress`. * @throws {MissingClientPropertyError} when the client has no connected account. * @throws {AddressMismatchError} when the client account differs from * `userAddress`. * @example * ```ts * import { createWalletClient, http } from "viem"; * import { privateKeyToAccount } from "viem/accounts"; * import { mainnet } from "viem/chains"; * import { validateUserAddress } from "@morpho-org/morpho-sdk"; * * const account = privateKeyToAccount("0x..."); * const walletClient = createWalletClient({ * account, * chain: mainnet, * transport: http(), * }); * * // Inside a `sign()` flow, before producing a typed-data signature: * validateUserAddress(walletClient.account?.address, account.address); * // Passes when the connected account equals the expected signer; * // throws if the wallet has no account or signs for a different address. * ``` */ export declare function validateUserAddress(clientAccountAddress: Address | undefined, userAddress: Address): asserts clientAccountAddress is Address; /** * Validates that the accrual position belongs to the expected market and user. * Throws {@link MarketIdMismatchError} if the position's market ID * does not match the expected market. * Throws {@link AccrualPositionUserMismatchError} if the position's user * does not match the expected user. * * @param params - Validation parameters. * @param params.positionData - The accrual position to validate. * @param params.expectedMarketId - The market ID the position must belong to. * @param params.expectedUser - The user address the position must belong to. */ export declare const validateAccrualPosition: (params: { positionData: AccrualPosition; expectedMarketId: MarketId; expectedUser: Address; }) => void; /** * Validates that the resulting position stays within the safe LTV threshold * (LLTV minus buffer) after supplying additional collateral and borrowing. * * @param params - Validation parameters. * @param params.positionData - The current accrual position with market data. * @param params.additionalCollateral - Amount of collateral being added. * @param params.borrowAmount - Amount being borrowed. * @param params.marketId - The market identifier (for error messages). * @param params.lltv - The market's liquidation LTV. */ export declare const validatePositionHealth: (params: { positionData: AccrualPosition; additionalCollateral: bigint; borrowAmount: bigint; marketId: MarketId; lltv: bigint; }) => void; /** * Validates that the viem client chain ID matches the expected chain ID. * Throws {@link ChainIdMismatchError} if they differ. * * @param clientChainId - Chain ID reported by the viem client (may be undefined). * @param expectedChainId - Chain ID expected by the entity or action. */ export declare const validateChainId: (clientChainId: number | undefined, expectedChainId: number) => void; /** * Validates that the given asset is the chain's wrapped native token. * Used by any action that may receive `nativeAmount` — the SDK wraps native * into wNative, so the target asset must be wNative for the action to succeed. * * @param chainId - The chain to look up wNative on. * @param asset - The asset address to check (collateral, loan, vault asset…). * @throws {ChainWNativeMissingError} if wNative is not configured for the chain. * @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative. */ export declare const validateNativeAsset: (chainId: number, asset: Address) => void; /** * Validates that the resulting position stays within the safe LTV threshold * (LLTV minus buffer) after withdrawing collateral. * * @param params - Validation parameters. * @param params.positionData - The current accrual position with market data. * @param params.withdrawAmount - Amount of collateral being withdrawn. * @param params.lltv - The market's liquidation LTV. * @param params.marketId - The market identifier (for error messages). */ export declare const validatePositionHealthAfterWithdraw: (params: { positionData: AccrualPosition; withdrawAmount: bigint; lltv: bigint; marketId: MarketId; }) => void; /** * Validates that the repay amount assets does not exceed the outstanding debt. * * @param params - Validation parameters. * @param params.positionData - The current accrual position. * @param params.repayAssets - The amount of assets to repay. * @param params.marketId - The market identifier (for error messages). */ export declare const validateRepayAmount: (params: { positionData: AccrualPosition; repayAssets: bigint; marketId: MarketId; }) => void; /** * Validates that the repay shares do not exceed the outstanding borrow shares. * * @param params - Validation parameters. * @param params.positionData - The current accrual position. * @param params.repayShares - The amount of shares to repay. * @param params.marketId - The market identifier (for error messages). */ export declare const validateRepayShares: (params: { positionData: AccrualPosition; repayShares: bigint; marketId: MarketId; }) => void; /** * Validates that Vault V1 PublicAllocator reallocations are well-formed. * * @param reallocations - Vault V1 reallocations to validate. * @param targetMarketId - The operation's target market ID. * @returns Nothing when every reallocation is valid. * @throws {NegativeInputError} when a reallocation fee is negative. * @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals. * @throws {NonPositiveInputError} when a withdrawal amount is non-positive. * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market. * @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted. * @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2 * reallocations for new integrations. * @example * ```ts * import type { BlueMarketId } from "@morpho-org/morpho-sdk/types"; * import { validateReallocations } from "@morpho-org/morpho-sdk"; * import { zeroHash } from "viem"; * * const result: void = validateReallocations([], zeroHash as BlueMarketId); * ``` */ export declare const validateReallocations: (reallocations: Iterable, targetMarketId: MarketId) => void; /** @internal */ export declare const validateVaultV2BlueReallocations: (reallocations: Iterable, targetMarketId: MarketId) => void; /** * Validates and normalizes a homogeneous Blue reallocation plan. * * @param params - Validation parameters. * @param params.reallocations - Optional Vault V1 or Vault V2 reallocation plan. * @param params.targetMarketId - Morpho Blue market receiving the liquidity. * @param params.chainId - Chain whose allocator deployment is required for a V2 plan. * @returns The validated plan tagged with its allocator version. * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain. * @internal */ export declare const validateAndNormalizeReallocations: ({ reallocations, targetMarketId, chainId, }: { readonly reallocations: BlueReallocationPlan | undefined; readonly targetMarketId: MarketId; readonly chainId: number; }) => { type: "vaultV2Blue"; reallocations: VaultV2BlueReallocation[]; } | { type: "vaultV1"; reallocations: VaultV1Reallocation[]; }; /** * Validates that a slippage tolerance is within an acceptable range. * * Throws {@link NegativeInputError} if negative. * Throws {@link ExcessiveSlippageToleranceError} if greater than {@link MAX_SLIPPAGE_TOLERANCE}. * * @param slippageTolerance - The slippage tolerance in WAD. * @returns Nothing when the slippage tolerance is valid. * @throws {NegativeInputError} when `slippageTolerance < 0n`. * @throws {ExcessiveSlippageToleranceError} when the tolerance exceeds the SDK maximum. * @example * ```ts * import { validateSlippageTolerance } from "@morpho-org/morpho-sdk"; * * const result: void = validateSlippageTolerance(5_000000000000000n); * ``` */ export declare const validateSlippageTolerance: (slippageTolerance: bigint) => void; /** * Validates that the withdraw assets do not exceed the user's supplied assets in the market. * * @param params - Validation parameters. * @param params.positionData - The current accrual position. * @param params.withdrawAssets - The amount of assets to withdraw. * @param params.marketId - The market identifier (for error messages). * @throws {WithdrawExceedsSupplyError} when `withdrawAssets > positionData.supplyAssets`. */ export declare const validateWithdrawAmount: (params: { positionData: AccrualPosition; withdrawAssets: bigint; marketId: MarketId; }) => void; /** * Validates that the withdraw shares do not exceed the user's owned supply shares in the market. * * @param params - Validation parameters. * @param params.positionData - The current accrual position. * @param params.withdrawShares - The amount of shares to withdraw. * @param params.marketId - The market identifier (for error messages). * @throws {WithdrawSharesExceedSupplyError} when `withdrawShares > positionData.supplyShares`. */ export declare const validateWithdrawShares: (params: { positionData: AccrualPosition; withdrawShares: bigint; marketId: MarketId; }) => void;