import { type MarketId } from "@morpho-org/blue-sdk"; import type { VaultV1ReallocationData } from "../entities/vaultV1ReallocationData.js"; import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../types/index.js"; /** * Computes vault reallocations for a `borrow` or `withdraw` on a target market. * * First attempts "friendly" reallocations respecting withdrawal utilization * targets, then falls back to aggressive reallocations (100% withdrawal * utilization) if liquidity is still insufficient. * * Algebra branches on `operation`: * - `"borrow"`: `S' = S`, `B' = B + amount` (additional borrow demand). * - `"withdraw"`: `S' = S − amount`, `B' = B` (supply-side shrinkage). * * In both cases reallocated assets are added on the supply side; `requiredAssets` * and `absoluteShortfall` are derived from the operation-specific post-state. * * @remarks Pass `options.timestamp` from the same block used to fetch `reallocationData`; when omitted, market accrual falls back to the target market's `lastUpdate`, which can diverge from the source rows' fetch block. Per-market `maxWithdrawalUtilization` overrides apply only to phase 1; phase 2 forces 100% utilization on every source market. * @param params.reallocationData - The local state containing market, vault, and position data. * @param params.marketId - The target market to reallocate liquidity into. * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`). * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization. * @param params.options - Optional reallocation computation options. * @returns Array of vault reallocations, sorted with withdrawals in ascending market id order. * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM. * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain. * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations. * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config. * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`. * @example * ```ts * import { createPublicClient, http, parseUnits } from "viem"; * import { mainnet } from "viem/chains"; * import { markets, vaults } from "@morpho-org/morpho-test"; * import { * computeVaultV1Reallocations, * morphoViemExtension, * } from "@morpho-org/morpho-sdk"; * * const client = createPublicClient({ * chain: mainnet, * transport: http(), * }).extend(morphoViemExtension()); * * const userAddress = "0x000000000000000000000000000000000000dEaD"; * const marketParams = markets[mainnet.id].usdc_wbtc; * const market = client.morpho.blue(marketParams, mainnet.id); * const block = await client.getBlock(); * const reallocationData = await market.getVaultV1ReallocationData({ * vaultAddresses: [vaults[mainnet.id].steakUsdc.address], * block: { number: block.number, timestamp: block.timestamp }, * }); * const borrowAmount = parseUnits("1000", 6); * const reallocations = computeVaultV1Reallocations({ * reallocationData, * marketId: marketParams.id, * operation: "borrow", * amount: borrowAmount, * options: { timestamp: block.timestamp }, * }); * const positionData = await market.getPositionData(userAddress); * const borrow = market.borrow({ * userAddress, * amount: borrowAmount, * positionData, * reallocations, * }); * // borrow.buildTx() includes any required PublicAllocator reallocations. * ``` */ export declare const computeVaultV1Reallocations: ({ reallocationData: data, marketId, operation, amount, options, }: { readonly reallocationData: VaultV1ReallocationData; readonly marketId: MarketId; readonly operation: "borrow" | "withdraw"; readonly amount: bigint; readonly options?: ReallocationComputeOptions; }) => readonly VaultV1Reallocation[]; /** * Deprecated name for the Vault V1 amount-aware reallocation planner. * * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM. * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`. */ export declare const computeReallocations: typeof computeVaultV1Reallocations;