|
| 1 | +import { |
| 2 | + type Market, |
| 3 | + MarketQuery, |
| 4 | + type MarketRequest, |
| 5 | + MarketsQuery, |
| 6 | + type MarketsRequest, |
| 7 | +} from '@aave/graphql'; |
| 8 | +import type { ResultAsync } from '@aave/types'; |
| 9 | +import type { AaveClient } from '../client'; |
| 10 | +import type { UnexpectedError } from '../errors'; |
| 11 | + |
| 12 | +/** |
| 13 | + * Fetches all markets for the specified chain IDs. |
| 14 | + * |
| 15 | + * ```ts |
| 16 | + * const result = await markets(client, { |
| 17 | + * chainIds: [chainId(1), chainId(137)] |
| 18 | + * }); |
| 19 | + * ``` |
| 20 | + * |
| 21 | + * @param client - Aave client. |
| 22 | + * @param request - The markets request parameters. |
| 23 | + * @returns The list of markets. |
| 24 | + */ |
| 25 | +export function markets( |
| 26 | + client: AaveClient, |
| 27 | + request: MarketsRequest, |
| 28 | +): ResultAsync<Market[], UnexpectedError> { |
| 29 | + return client.query(MarketsQuery, { request }); |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Fetches a specific market by address and chain ID. |
| 34 | + * |
| 35 | + * ```ts |
| 36 | + * const result = await market(client, { |
| 37 | + * address: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'), |
| 38 | + * chainId: chainId(1) |
| 39 | + * }); |
| 40 | + * ``` |
| 41 | + * |
| 42 | + * @param client - Aave client. |
| 43 | + * @param request - The market request parameters. |
| 44 | + * @returns The market data, or null if not found. |
| 45 | + */ |
| 46 | +export function market( |
| 47 | + client: AaveClient, |
| 48 | + request: MarketRequest, |
| 49 | +): ResultAsync<Market | null, UnexpectedError> { |
| 50 | + return client.query(MarketQuery, { request }); |
| 51 | +} |
0 commit comments