import { Client } from 'viem'; import { EthAddress, NetworkNumber } from '../types/common'; import { AaveMarketInfo, AaveV4SpokeInfo, CompoundMarketData, CrvUSDMarketData, LlamaLendMarketData, MorphoBlueMarketData, MorphoMidnightMarketData, PortfolioMarketsData, PortfolioPositionsData, PortfolioPositionsDataForAddress, PortfolioProtocolData, SparkMarketData } from '../types'; /** * The lending protocols the portfolio reads the same way — a market's data, then each address's position on it — one * entry each. Adding such a protocol is its types (its key in PortfolioPositionsDataForAddress and in * PortfolioMarketsData) and its entry in LENDING_PROTOCOLS; the portfolio reads, errors and options follow. Maker, * Liquity, Fluid and Liquity V2 have shapes of their own and are read by their own code in ./index.ts. */ /** What a position read gets. */ export interface PortfolioReadContext { client: Client; network: NetworkNumber; } /** What a market read gets: also the default client, on Ethereum (Compound V3 reads its prices there). */ export interface PortfolioMarketsReadContext extends PortfolioReadContext { defaultClient: Client; } type PositionKey = keyof PortfolioPositionsDataForAddress; type MarketsKey = keyof PortfolioMarketsData; type PositionsOf = NonNullable; /** The data of one of a protocol's positions: what positions[address][K][market] holds as `{ error, data }`. */ export type LendingPositionData = NonNullable[keyof PositionsOf]> extends PortfolioProtocolData ? D : never; export interface LendingProtocol { /** Its key in PortfolioMarketsData. */ marketsKey: M; /** Its name in error messages. */ label: string; /** Its markets on a network; none where it is not deployed. */ markets: (network: NetworkNumber) => Market[]; readMarket: (context: PortfolioMarketsReadContext, market: Market) => Promise; /** An address's position on a market; undefined when the market can hold none. */ readPosition: (context: PortfolioReadContext, address: EthAddress, market: Market, marketData: PortfolioMarketsData[M][string]) => Promise | undefined>; /** Whether there is a position to list: an address without one gets no entry for that market. */ holds: (position: LendingPositionData) => boolean; } /** * A market's data, or a throw that the caller's catch turns into the position's error entry: read against a missing * market, a position would otherwise come back empty and read as "no position". */ export declare const requireMarket: (marketsData: Record, market: string) => T; export declare const aaveV3Lending: { key: "aaveV3"; marketsKey: "aaveV3MarketsData"; markets: (network: NetworkNumber) => AaveMarketInfo[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const aaveV4Lending: { key: "aaveV4"; marketsKey: "aaveV4SpokesData"; markets: (network: NetworkNumber) => AaveV4SpokeInfo[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const morphoBlueLending: { key: "morphoBlue"; marketsKey: "morphoMarketsData"; markets: (network: NetworkNumber) => MorphoBlueMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const morphoMidnightLending: { key: "morphoMidnight"; marketsKey: "morphoMidnightMarketsData"; markets: (network: NetworkNumber) => MorphoMidnightMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const compoundV3Lending: { key: "compoundV3"; marketsKey: "compoundV3MarketsData"; markets: (network: NetworkNumber) => CompoundMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const sparkLending: { key: "spark"; marketsKey: "sparkMarketsData"; markets: (network: NetworkNumber) => SparkMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const aaveV2Lending: { key: "aaveV2"; marketsKey: "aaveV2MarketsData"; markets: (network: NetworkNumber) => AaveMarketInfo[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const compoundV2Lending: { key: "compoundV2"; marketsKey: "compoundV2MarketsData"; markets: (network: NetworkNumber) => CompoundMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const crvUsdLending: { key: "crvUsd"; marketsKey: "crvUsdMarketsData"; markets: (network: NetworkNumber) => CrvUSDMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; export declare const llamaLendLending: { key: "llamaLend"; marketsKey: "llamaLendMarketsData"; markets: (network: NetworkNumber) => LlamaLendMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }; /** Every lending protocol read through its entry, in the order positions list them. */ export declare const LENDING_PROTOCOLS: readonly [{ key: "aaveV3"; marketsKey: "aaveV3MarketsData"; markets: (network: NetworkNumber) => AaveMarketInfo[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "aaveV4"; marketsKey: "aaveV4SpokesData"; markets: (network: NetworkNumber) => AaveV4SpokeInfo[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "morphoBlue"; marketsKey: "morphoMarketsData"; markets: (network: NetworkNumber) => MorphoBlueMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "morphoMidnight"; marketsKey: "morphoMidnightMarketsData"; markets: (network: NetworkNumber) => MorphoMidnightMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "compoundV3"; marketsKey: "compoundV3MarketsData"; markets: (network: NetworkNumber) => CompoundMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "spark"; marketsKey: "sparkMarketsData"; markets: (network: NetworkNumber) => SparkMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "aaveV2"; marketsKey: "aaveV2MarketsData"; markets: (network: NetworkNumber) => AaveMarketInfo[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "compoundV2"; marketsKey: "compoundV2MarketsData"; markets: (network: NetworkNumber) => CompoundMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "crvUsd"; marketsKey: "crvUsdMarketsData"; markets: (network: NetworkNumber) => CrvUSDMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }, { key: "llamaLend"; marketsKey: "llamaLendMarketsData"; markets: (network: NetworkNumber) => LlamaLendMarketData[]; readMarkets: (context: PortfolioMarketsReadContext, markets: PortfolioMarketsData) => Promise>; readPositions: (context: PortfolioReadContext, addresses: EthAddress[], marketsData: Promise, positions: PortfolioPositionsData) => Promise[]; }]; export type LendingKey = typeof LENDING_PROTOCOLS[number]['key']; /** The keys ./index.ts reads with code of its own. */ export type SpecialPositionKey = 'maker' | 'liquity' | 'fluid' | 'liquityV2'; type SpecialMarketsKey = 'liquityV2MarketsData'; type UnreadPositionKey = Exclude; type UnreadMarketsKey = Exclude; export declare const EVERY_POSITION_KEY_IS_READ: [UnreadPositionKey] extends [never] ? true : UnreadPositionKey; export declare const EVERY_MARKETS_KEY_IS_READ: [UnreadMarketsKey] extends [never] ? true : UnreadMarketsKey; export {};