import { type Address, type Hex } from "viem"; import type { BigIntish, Hash } from "../../types.js"; import type { AccrualVault } from "../Vault.js"; import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter.js"; import { VaultV2Adapter } from "./VaultV2Adapter.js"; /** Plain input shape for a Vault V2 adapter investing in a MetaMorpho V1 vault. */ export interface IVaultV2MorphoVaultV1Adapter extends Omit { type?: "VaultV2MorphoVaultV1Adapter"; morphoVaultV1: Address; /** * Parent Vault V2 allocation for this adapter, when available. * * TODO(vNext-major): make `parentAllocation` required. */ readonly parentAllocation?: bigint; } /** Represents a Vault V2 adapter investing in a MetaMorpho V1 vault. */ export declare class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter implements IVaultV2MorphoVaultV1Adapter { readonly type: "VaultV2MorphoVaultV1Adapter"; /** * Returns the adapter-wide allocation-cap id. * * @param address - Adapter address. * @returns The adapter-wide allocation-cap id. * @example * ```ts * import { VaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk"; * * const adapterAddress = "0x2C32fF5E1d976015AdbeA8cC73c7Da3A6677C25F"; * const id = VaultV2MorphoVaultV1Adapter.adapterCapId(adapterAddress); * // id satisfies Hash * ``` */ static adapterCapId(address: Address): `0x${string}`; readonly morphoVaultV1: Address; /** * Parent Vault V2 allocation for this adapter, when available. * * TODO(vNext-major): make `parentAllocation` required. */ readonly parentAllocation?: bigint; constructor({ morphoVaultV1, parentAllocation, ...vaultV2Adapter }: IVaultV2MorphoVaultV1Adapter); /** * Returns this adapter's allocation-cap ids. * * @returns A readonly tuple containing the adapter-wide allocation-cap id. * @example * ```ts * import { VaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk"; * import { ZERO_ADDRESS } from "@morpho-org/morpho-ts"; * * const adapter = new VaultV2MorphoVaultV1Adapter({ * address: ZERO_ADDRESS, * parentVault: ZERO_ADDRESS, * skimRecipient: ZERO_ADDRESS, * morphoVaultV1: ZERO_ADDRESS, * }); * const [adapterCapId] = adapter.ids(); * ``` */ ids(): readonly [adapterCapId: Hash]; } /** Plain input shape for an accrued Vault V2 MetaMorpho V1 adapter. */ export interface IAccrualVaultV2MorphoVaultV1Adapter extends IVaultV2MorphoVaultV1Adapter { } /** Represents an accrued Vault V2 MetaMorpho V1 adapter. */ export declare class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter implements IAccrualVaultV2MorphoVaultV1Adapter, IAccrualVaultV2Adapter { accrualVaultV1: AccrualVault; shares: bigint; constructor(adapter: IAccrualVaultV2MorphoVaultV1Adapter, accrualVaultV1: AccrualVault, shares: bigint); /** * Returns underlying assets represented by the adapter's Vault V1 shares at a timestamp. * * Projects nested market interest and Vault V1 fees. Returns zero without projecting the nested * vault when the parent Vault V2 tracks no allocation for this adapter, even if the adapter holds * Vault V1 shares transferred directly to it. Zero shares also skip projection. * An undefined `parentAllocation` preserves legacy * share-based accounting. * * @param timestamp - Optional accrual timestamp. Defaults each nested market to its own * `lastUpdate`; markets at or beyond the requested timestamp keep their snapshots without * backward accrual or a timestamp error. * @returns The projected underlying assets represented by `shares`, or `0n` when * `parentAllocation` or `shares` is `0n`. * @throws {UnknownMarketAllocationError} when the nested Vault V1 withdraw queue references a * market without an allocation. * @throws {UnsupportedMarketIrmError} when forward projection of an allocated nested market with * positive debt requires an unsupported IRM. * @example * ```ts * import { AccrualVaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk"; * import { fetchAccrualVaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk-viem"; * import { createPublicClient, http } from "viem"; * import { base } from "viem/chains"; * * const client = createPublicClient({ chain: base, transport: http() }); * const fetched = await fetchAccrualVaultV2MorphoVaultV1Adapter( * "0x2C32fF5E1d976015AdbeA8cC73c7Da3A6677C25F", * client, * ); * const residual = new AccrualVaultV2MorphoVaultV1Adapter( * { ...fetched, parentAllocation: 0n }, * fetched.accrualVaultV1, * 1n, * ); * const assets = residual.realAssets(); * // assets === 0n * ``` */ realAssets(timestamp?: BigIntish): bigint; /** * Returns a new adapter whose underlying MetaMorpho V1 vault (and its market * positions) has been accrued up to the given timestamp. * An adapter with zero parent allocation or zero shares contributes no assets — * `realAssets` short-circuits to `0n` without inspecting the nested vault — so * it is returned unchanged and never accrues (nor throws for) its economically * inactive markets. * Past timestamps and markets already ahead of `timestamp` keep their snapshots * without throwing. * @param timestamp The timestamp at which to accrue interest. * @returns A new `AccrualVaultV2MorphoVaultV1Adapter` wrapping the V1 vault * accrued to `timestamp`, or this adapter unchanged when its parent allocation * or shares are zero. * @throws {UnknownMarketAllocationError} when the underlying V1 vault's withdraw * queue references a market without an allocation and both the parent allocation * and shares are non-zero. * @throws {UnsupportedMarketIrmError} when forward projection of an allocated * nested market with positive debt requires an unsupported IRM and both the * parent allocation and shares are non-zero. * @example * ```ts * import { fetchAccrualVaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk-viem"; * import { createPublicClient, http } from "viem"; * import { base } from "viem/chains"; * * const client = createPublicClient({ chain: base, transport: http() }); * const adapter = await fetchAccrualVaultV2MorphoVaultV1Adapter( * "0x2C32fF5E1d976015AdbeA8cC73c7Da3A6677C25F", * client, * ); * const timestamp = (await client.getBlock()).timestamp; * const accrued = adapter.accrueInterest(timestamp); * // accrued.realAssets(timestamp) reflects the V1 vault's assets at `timestamp` * ``` */ accrueInterest(timestamp: BigIntish): AccrualVaultV2MorphoVaultV1Adapter; /** * Returns this adapter's capacity to deposit into its Vault V1 vault. * * Delegates to the nested vault's supply-queue caps. Adapter routing data and * `parentAllocation` do not affect this calculation. * * @param _data - Adapter-specific data; ignored by this adapter. * @param assets - Maximum underlying assets to deposit. * @returns A capacity limit containing the depositable asset amount and either the `cap` or * `balance` limiting reason. * @example * ```ts * import { fetchAccrualVaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk-viem"; * import { createPublicClient, http } from "viem"; * import { base } from "viem/chains"; * * const client = createPublicClient({ chain: base, transport: http() }); * const adapter = await fetchAccrualVaultV2MorphoVaultV1Adapter( * "0x2C32fF5E1d976015AdbeA8cC73c7Da3A6677C25F", * client, * ); * const limit = adapter.maxDeposit("0x", 1_000_000n); * // limit satisfies CapacityLimit * ``` */ maxDeposit(_data: Hex, assets: BigIntish): import("../../utils.js").CapacityLimit; /** * Returns underlying assets currently withdrawable through this adapter. * * Returns a position-limited zero capacity when the parent Vault V2 tracks no allocation for * this adapter, even if the adapter holds Vault V1 shares transferred directly to it. An * undefined `parentAllocation` preserves legacy share-based accounting. Otherwise, the nested * vault applies share conversion and liquidity limiting. * * @param _data - Adapter-specific data; ignored by this adapter. * @returns A capacity limit using `position` for zero parent allocation, or the nested vault's * `balance` or `liquidity` limiting reason otherwise. * @example * ```ts * import { AccrualVaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk"; * import { fetchAccrualVaultV2MorphoVaultV1Adapter } from "@morpho-org/blue-sdk-viem"; * import { createPublicClient, http } from "viem"; * import { base } from "viem/chains"; * * const client = createPublicClient({ chain: base, transport: http() }); * const fetched = await fetchAccrualVaultV2MorphoVaultV1Adapter( * "0x2C32fF5E1d976015AdbeA8cC73c7Da3A6677C25F", * client, * ); * const residual = new AccrualVaultV2MorphoVaultV1Adapter( * { ...fetched, parentAllocation: 0n }, * fetched.accrualVaultV1, * 1n, * ); * const limit = residual.maxWithdraw("0x"); * // limit equals { value: 0n, limiter: CapacityLimitReason.position } * ``` */ maxWithdraw(_data: Hex): import("../../utils.js").CapacityLimit; }