11import {
22 type Market ,
33 MarketQuery ,
4- type MarketRequest ,
54 MarketsQuery ,
6- type MarketsRequest ,
5+ type ReservesRequestOrderBy ,
76} from '@aave/graphql' ;
8- import type { ResultAsync } from '@aave/types' ;
7+ import type { ChainId , EvmAddress , ResultAsync } from '@aave/types' ;
98import type { AaveClient } from '../client' ;
109import type { UnexpectedError } from '../errors' ;
1110
11+ export type MarketsRequest = {
12+ /**
13+ * The markets you want to see based on the chain ids.
14+ */
15+ chainIds : ChainId [ ] ;
16+ /**
17+ * The user address in case you want to include user fields in the response.
18+ *
19+ * If not provided, user fields will not be included.
20+ */
21+ userAddress ?: EvmAddress ;
22+ /**
23+ * The order by clause for the borrow reserves in the market.
24+ *
25+ * @defaultValue { name: OrderDirection.Asc }
26+ */
27+ borrowsOrderBy ?: ReservesRequestOrderBy ;
28+ /**
29+ * The order by clause for the supply reserves in the market.
30+ *
31+ * @defaultValue { name: OrderDirection.Asc }
32+ */
33+ suppliesOrderBy ?: ReservesRequestOrderBy ;
34+ } ;
35+
1236/**
1337 * Fetches all markets for the specified chain IDs.
1438 *
@@ -24,11 +48,47 @@ import type { UnexpectedError } from '../errors';
2448 */
2549export function markets (
2650 client : AaveClient ,
27- request : MarketsRequest ,
51+ { chainIds , borrowsOrderBy , suppliesOrderBy , userAddress } : MarketsRequest ,
2852) : ResultAsync < Market [ ] , UnexpectedError > {
29- return client . query ( MarketsQuery , { request } ) ;
53+ return client . query ( MarketsQuery , {
54+ request : { chainIds } ,
55+ borrowsOrderBy,
56+ suppliesOrderBy,
57+ userAddress,
58+ includeUserFields : ! ! userAddress ,
59+ } ) ;
3060}
3161
62+ export type MarketRequest = {
63+ /**
64+ * The pool address for the market.
65+ */
66+ address : EvmAddress ;
67+
68+ /**
69+ * The chain id the market pool address is deployed on.
70+ */
71+ chainId : ChainId ;
72+ /**
73+ * The user address in case you want to include user fields in the response.
74+ *
75+ * If not provided, user fields will not be included.
76+ */
77+ userAddress ?: EvmAddress ;
78+ /**
79+ * The order by clause for the borrow reserves in the market.
80+ *
81+ * @defaultValue { name: OrderDirection.Asc }
82+ */
83+ borrowsOrderBy ?: ReservesRequestOrderBy ;
84+ /**
85+ * The order by clause for the supply reserves in the market.
86+ *
87+ * @defaultValue { name: OrderDirection.Asc }
88+ */
89+ suppliesOrderBy ?: ReservesRequestOrderBy ;
90+ } ;
91+
3292/**
3393 * Fetches a specific market by address and chain ID.
3494 *
@@ -45,7 +105,19 @@ export function markets(
45105 */
46106export function market (
47107 client : AaveClient ,
48- request : MarketRequest ,
108+ {
109+ address,
110+ chainId,
111+ userAddress,
112+ borrowsOrderBy,
113+ suppliesOrderBy,
114+ } : MarketRequest ,
49115) : ResultAsync < Market | null , UnexpectedError > {
50- return client . query ( MarketQuery , { request } ) ;
116+ return client . query ( MarketQuery , {
117+ request : { address, chainId } ,
118+ includeUserFields : ! ! userAddress ,
119+ userAddress,
120+ borrowsOrderBy,
121+ suppliesOrderBy,
122+ } ) ;
51123}
0 commit comments