Skip to content

Commit e61c59f

Browse files
committed
feat: markets read actions
1 parent 7bc8f80 commit e61c59f

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './markets';
12
export * from './misc';
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { FragmentOf } from 'gql.tada';
2+
import { graphql } from '../graphql';
3+
4+
export const DecimalValueFragment = graphql(
5+
`fragment DecimalValue on DecimalValue {
6+
__typename
7+
raw
8+
decimals
9+
value
10+
}`,
11+
);
12+
export type DecimalValue = FragmentOf<typeof DecimalValueFragment>;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from './chain';
2+
export * from './common';
3+
export * from './market';
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { FragmentOf } from 'gql.tada';
2+
import { graphql } from '../graphql';
3+
import { ChainFragment } from './chain';
4+
import { DecimalValueFragment } from './common';
5+
6+
export const MarketFragment = graphql(
7+
`fragment Market on Market {
8+
__typename
9+
name
10+
chain {
11+
...Chain
12+
}
13+
address
14+
totalMarketSize
15+
totalAvailableLiquidity
16+
totalBorrows
17+
}`,
18+
[ChainFragment],
19+
);
20+
export type Market = FragmentOf<typeof MarketFragment>;
21+
22+
export const MarketInfoFragment = graphql(
23+
`fragment MarketInfo on MarketInfo {
24+
__typename
25+
name
26+
chain {
27+
...Chain
28+
}
29+
}`,
30+
[ChainFragment],
31+
);
32+
export type MarketInfo = FragmentOf<typeof MarketInfoFragment>;
33+
34+
export const MarketUserStatsFragment = graphql(
35+
`fragment MarketUserStats on MarketUserStats {
36+
__typename
37+
netWorth {
38+
...DecimalValue
39+
}
40+
netAPY {
41+
...DecimalValue
42+
}
43+
healthFactor {
44+
...DecimalValue
45+
}
46+
eModeEnabled
47+
}`,
48+
[DecimalValueFragment],
49+
);
50+
export type MarketUserStats = FragmentOf<typeof MarketUserStatsFragment>;

packages/graphql/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from './common';
22
export * from './enums';
33
export * from './fragments';
44
export * from './graphql';
5+
export * from './markets';
56
export * from './misc';

packages/graphql/src/markets.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { MarketFragment } from './fragments';
2+
import { graphql, type RequestOf } from './graphql';
3+
4+
export const MarketsQuery = graphql(
5+
`query Markets($request: MarketsRequest!) {
6+
value: markets(request: $request) {
7+
...Market
8+
}
9+
}`,
10+
[MarketFragment],
11+
);
12+
export type MarketsRequest = RequestOf<typeof MarketsQuery>;
13+
14+
export const MarketQuery = graphql(
15+
`query Market($request: MarketRequest!) {
16+
value: market(request: $request) {
17+
...Market
18+
}
19+
}`,
20+
[MarketFragment],
21+
);
22+
export type MarketRequest = RequestOf<typeof MarketQuery>;

0 commit comments

Comments
 (0)