import Dec from 'decimal.js'; import { MMUsedAssets, NetworkNumber } from '../../types/common'; import { MorphoMidnightAggregatedPositionData, MorphoMidnightAssetsData, MorphoMidnightBookSide, MorphoMidnightMarketData, MorphoMidnightMarketInfo, MorphoMidnightParsedBook } from '../../types'; export { buildMidnightParsedBook, midnightApyFromPrice, midnightBookBestFirst, midnightBoundPrice, midnightPriceFromApy, midnightTimeToMaturityDays, MIDNIGHT_DEFAULT_RATE_SLIPPAGE, } from './rate'; export { getMorphoMidnightBorrowHeadroom, MIDNIGHT_MIN_HEALTH_RATIO, } from './headroom'; export type { MidnightBorrowHeadroom, MidnightBorrowHeadroomParams } from './headroom'; export { tenorBookKeyFor, tenorBookRateToApyPercent, tenorOfferFillToApiFill, tenorOfferToApiOffer, } from './tenor'; /** * Aggregate a Morpho Midnight position. Midnight markets are multi-collateral, so the borrow limit is * the sum of each collateral's USD value times its own lltv (Aave-v4 style), rather than a single pair. * * Note on amounts: `borrowedUsd` is derived from the position's `debt`, which is the face value owed at * maturity (principal + fixed interest). Health is therefore measured against the full maturity debt, * matching how MidnightView computes `ratio`. Fixed-rate APY is not derived on-chain in MVP, so * `netApy` reflects the `'0'` rates in `assetsData` (see the module getter). */ export declare const getMorphoMidnightAggregatedPositionData: ({ usedAssets, assetsData, marketInfo, }: { usedAssets: MMUsedAssets; assetsData: MorphoMidnightAssetsData; marketInfo: MorphoMidnightMarketInfo; }) => MorphoMidnightAggregatedPositionData; export interface MorphoMidnightBorrowInfo { borrowRate: string; debtBase: string; debtInterest: string; debtTotal: string; } export interface MorphoMidnightBorrowQuote { bestPrice: string; worstPrice: string; estBorrowRate: string; maxRate: string; newUnits: string; maxUnits: string; availableAssets: string; availableUnits: string; takeableOffers: any[]; } export interface MorphoMidnightPaybackQuote { bestPrice: string; worstPrice: string; estPaybackRate: string; minRate: string; newUnits: string; minUnits: string; availableAssets: string; availableUnits: string; takeableOffers: any[]; } export interface MorphoMidnightPaybackUnitsQuote { bestPrice: string; worstPrice: string; estPaybackRate: string; minRate: string; newAssets: string; maxAssets: string; availableAssets: string; availableUnits: string; takeableOffers: any[]; } /** * Coerce a slippage into what the quote endpoint accepts: 0.1–100 with at most one decimal place. The * validation is lexical, so a computed value (`4.15066671050631467`) is rejected outright — without this * the request 400s and the quote looks unavailable. * * Rounded **down**, since a wider slippage is a looser cap than the caller asked for. */ export declare const midnightSlippageParam: (slippagePercent: Dec.Value) => string; /** * Current borrower rate + debt breakdown from the Midnight positions API. Reconstructing this from the raw * `/transactions` fill history only sums `borrow` fills, so it overstates debt for any position with an * early exit or partial liquidation (`exit_borrow_primary`, `partial_liquidation`, ... — the fill history * has no exhaustive list of debt-reducing event types). `/positions` instead reports the already-netted * `debt`, matching `MidnightView.getPositionInfo` exactly, plus `cost_basis` (outstanding principal, * WAD-scaled raw base units) and `effective_rate_wad` (borrow APY, WAD-scaled) for the base/interest split. * The caller swallows errors — a missing rate must never block position rendering. */ export declare const getMorphoMidnightUserBorrowInfo: (account: string, marketId: string, loanTokenSymbol: string) => Promise; /** * The inverse of the split above: where `getMorphoMidnightUserBorrowInfo` reads a position's principal and * interest off the indexer, this carries that same split forward through a payback, from a debt of * `borrowedBefore` down to one of `borrowedAfter`. Retiring units retires principal and interest pro rata, * so both scale by the same fraction. * * Deriving the interest as `borrowedAfter − debtBase` instead reads it off two different sources — * `borrowed` is the chain's debt, `debtBase` the indexer's principal — so the entire gap between them lands * in the interest whenever they disagree, which they do until the indexer catches up with a fresh borrow or * payback: behind a borrow it inflates the interest by the debt the indexer has not seen yet, behind a * payback it goes negative on a position that still owes. Callers detect that window as * `debtBase + debtInterest !== debt`. * * Pro rata is also what keeps the answer sane when a payback retires debt at a different rate than the one * it was opened at. Mirroring a borrow instead — principal growing by the assets received, interest by the * rest — hands back a negative interest as soon as the book sells units back cheaper than they were bought. */ export declare const scaleMorphoMidnightDebtSplit: ({ debtBase, debtInterest }: Pick, borrowedBefore: Dec.Value, borrowedAfter: Dec.Value) => Pick; /** * One side of a market's resting order book, as rates rather than the API's WAD-scaled loan-per-unit * prices. Annualizing each price against time-to-maturity gives the rate a taker filling that offer gets * — verified against Morpho's fixed-market UI, where per-offer rates match to the cent. * * `bids` are the lend offers a borrower fills, so the best of them is the *lowest* rate; `asks` are the * sell offers a repayer buys debt units from, where a lower price buys more units, so the best is the * *highest* rate. Either way `offers` comes back best-first and `bestRate` is `offers[0].rate`. * * Returns `null` for an empty side: there is nothing to take, so a market listing should skip the market * rather than advertise it at a 0% rate. Throws when the request fails — an error response is rarely * JSON, so without the `res.ok` check it parses as an empty book and the market silently vanishes. */ export declare const getMorphoMidnightMarketBook: (market: MorphoMidnightMarketData, network: NetworkNumber, side?: MorphoMidnightBookSide) => Promise; export declare const getMorphoMidnightBorrowQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, maxBorrowRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value) => Promise; export declare const getMorphoMidnightPaybackQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value) => Promise; export declare const getMorphoMidnightPaybackUnitsQuote: (marketId: string, unitsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value) => Promise;