Skip to content

Commit fe39054

Browse files
committed
feat: reserve action
1 parent e61c59f commit fe39054

File tree

7 files changed

+223
-0
lines changed

7 files changed

+223
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './markets';
22
export * from './misc';
3+
export * from './reserve';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
type Reserve,
3+
ReserveQuery,
4+
type ReserveRequest,
5+
} from '@aave/graphql';
6+
import type { ResultAsync } from '@aave/types';
7+
import type { AaveClient } from '../client';
8+
import type { UnexpectedError } from '../errors';
9+
10+
/**
11+
* Fetches a specific reserve by market address, token address, and chain ID.
12+
*
13+
* ```ts
14+
* const result = await reserve(client, {
15+
* marketAddress: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'),
16+
* token: evmAddress('0xa0b86a33e6441c8c5f0bb9b7e5e1f8bbf5b78b5c'),
17+
* chainId: chainId(1)
18+
* });
19+
* ```
20+
*
21+
* @param client - Aave client.
22+
* @param request - The reserve request parameters.
23+
* @returns The reserve data, or null if not found.
24+
*/
25+
export function reserve(
26+
client: AaveClient,
27+
request: ReserveRequest,
28+
): ResultAsync<Reserve | null, UnexpectedError> {
29+
return client.query(ReserveQuery, { request });
30+
}

packages/graphql/src/fragments/common.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,40 @@ export const DecimalValueFragment = graphql(
1010
}`,
1111
);
1212
export type DecimalValue = FragmentOf<typeof DecimalValueFragment>;
13+
14+
export const CurrencyFragment = graphql(
15+
`fragment Currency on Currency {
16+
__typename
17+
address
18+
imageUrl
19+
name
20+
symbol
21+
decimals
22+
chainId
23+
}`,
24+
);
25+
export type Currency = FragmentOf<typeof CurrencyFragment>;
26+
27+
export const NativeCurrencyFragment = graphql(
28+
`fragment NativeCurrency on NativeCurrency {
29+
__typename
30+
imageUrl
31+
name
32+
symbol
33+
decimals
34+
chainId
35+
}`,
36+
);
37+
export type NativeCurrency = FragmentOf<typeof NativeCurrencyFragment>;
38+
39+
export const TokenAmountFragment = graphql(
40+
`fragment TokenAmount on TokenAmount {
41+
__typename
42+
amount {
43+
...DecimalValue
44+
}
45+
usd
46+
}`,
47+
[DecimalValueFragment],
48+
);
49+
export type TokenAmount = FragmentOf<typeof TokenAmountFragment>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './chain';
22
export * from './common';
33
export * from './market';
4+
export * from './reserve';
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import type { FragmentOf } from 'gql.tada';
2+
import { graphql } from '../graphql';
3+
import { ChainFragment } from './chain';
4+
import {
5+
DecimalValueFragment,
6+
CurrencyFragment,
7+
NativeCurrencyFragment,
8+
TokenAmountFragment
9+
} from './common';
10+
11+
export const EmodeInfoFragment = graphql(
12+
`fragment EmodeInfo on EmodeInfo {
13+
__typename
14+
maxLTV {
15+
...DecimalValue
16+
}
17+
liquidationThreshold {
18+
...DecimalValue
19+
}
20+
liquidationPenalty {
21+
...DecimalValue
22+
}
23+
}`,
24+
[DecimalValueFragment],
25+
);
26+
export type EmodeInfo = FragmentOf<typeof EmodeInfoFragment>;
27+
28+
export const ReserveSupplyInfoFragment = graphql(
29+
`fragment ReserveSupplyInfo on ReserveSupplyInfo {
30+
__typename
31+
apy {
32+
...DecimalValue
33+
}
34+
total {
35+
...DecimalValue
36+
}
37+
maxLTV {
38+
...DecimalValue
39+
}
40+
liquidationThreshold {
41+
...DecimalValue
42+
}
43+
liquidationPenalty {
44+
...DecimalValue
45+
}
46+
canBeCollateral
47+
}`,
48+
[DecimalValueFragment],
49+
);
50+
export type ReserveSupplyInfo = FragmentOf<typeof ReserveSupplyInfoFragment>;
51+
52+
export const ReserveBorrowInfoFragment = graphql(
53+
`fragment ReserveBorrowInfo on ReserveBorrowInfo {
54+
__typename
55+
apy {
56+
...DecimalValue
57+
}
58+
total {
59+
...DecimalValue
60+
}
61+
borrowCap {
62+
...DecimalValue
63+
}
64+
reserveFactor
65+
}`,
66+
[DecimalValueFragment],
67+
);
68+
export type ReserveBorrowInfo = FragmentOf<typeof ReserveBorrowInfoFragment>;
69+
70+
export const ReserveUserAvailabilityFragment = graphql(
71+
`fragment ReserveUserAvailability on ReserveUserAvailability {
72+
__typename
73+
balance {
74+
...DecimalValue
75+
}
76+
supply {
77+
...DecimalValue
78+
}
79+
borrow {
80+
...DecimalValue
81+
}
82+
}`,
83+
[DecimalValueFragment],
84+
);
85+
export type ReserveUserAvailability = FragmentOf<typeof ReserveUserAvailabilityFragment>;
86+
87+
export const ReserveFragment = graphql(
88+
`fragment Reserve on Reserve {
89+
__typename
90+
market {
91+
name
92+
chain {
93+
...Chain
94+
}
95+
}
96+
address
97+
underlyingToken {
98+
...Currency
99+
}
100+
aToken {
101+
...Currency
102+
}
103+
vToken {
104+
...Currency
105+
}
106+
acceptsNative {
107+
...NativeCurrency
108+
}
109+
size {
110+
...TokenAmount
111+
}
112+
utilizationRate {
113+
...DecimalValue
114+
}
115+
available {
116+
...TokenAmount
117+
}
118+
usdExchangeRate
119+
usdOracleAddress
120+
supplyInfo {
121+
...ReserveSupplyInfo
122+
}
123+
borrowInfo {
124+
...ReserveBorrowInfo
125+
}
126+
eModeInfo {
127+
...EmodeInfo
128+
}
129+
}`,
130+
[
131+
ChainFragment,
132+
CurrencyFragment,
133+
NativeCurrencyFragment,
134+
TokenAmountFragment,
135+
DecimalValueFragment,
136+
ReserveSupplyInfoFragment,
137+
ReserveBorrowInfoFragment,
138+
EmodeInfoFragment,
139+
],
140+
);
141+
export type Reserve = FragmentOf<typeof ReserveFragment>;

packages/graphql/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './fragments';
44
export * from './graphql';
55
export * from './markets';
66
export * from './misc';
7+
export * from './reserves';

packages/graphql/src/reserves.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ReserveFragment } from './fragments';
2+
import { graphql, type RequestOf } from './graphql';
3+
4+
export const ReserveQuery = graphql(
5+
`query Reserve($request: ReserveRequest!) {
6+
value: reserve(request: $request) {
7+
...Reserve
8+
}
9+
}`,
10+
[ReserveFragment],
11+
);
12+
export type ReserveRequest = RequestOf<typeof ReserveQuery>;

0 commit comments

Comments
 (0)