Skip to content

Commit 96ff585

Browse files
authored
Merge branch 'main' into juan/swap-sign-action-hook
2 parents 6c363cc + 04939db commit 96ff585

File tree

7 files changed

+254
-419
lines changed

7 files changed

+254
-419
lines changed

packages/client/src/actions/hubs.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import type { UnexpectedError } from '@aave/core-next';
22
import {
33
type Hub,
4+
type HubAsset,
5+
HubAssetsQuery,
6+
type HubAssetsRequest,
47
HubQuery,
58
type HubRequest,
69
HubsQuery,
710
type HubsRequest,
811
} from '@aave/graphql-next';
912
import type { ResultAsync } from '@aave/types-next';
10-
1113
import type { AaveClient } from '../AaveClient';
1214
import { type CurrencyQueryOptions, DEFAULT_QUERY_OPTIONS } from '../options';
1315

@@ -55,3 +57,27 @@ export function hubs(
5557
): ResultAsync<Hub[], UnexpectedError> {
5658
return client.query(HubsQuery, { request, ...options });
5759
}
60+
61+
/**
62+
* Fetches hub assets for a specific chain and optional hub/user filtering.
63+
*
64+
* ```ts
65+
* const result = await hubAssets(client, {
66+
* chainId: chainId(1),
67+
* hub: evmAddress('0x123...'), // optional
68+
* user: evmAddress('0x456...'), // optional
69+
* });
70+
* ```
71+
*
72+
* @param client - Aave client.
73+
* @param request - The hub assets request parameters.
74+
* @param options - The query options.
75+
* @returns The hub assets array.
76+
*/
77+
export function hubAssets(
78+
client: AaveClient,
79+
request: HubAssetsRequest,
80+
options: Required<CurrencyQueryOptions> = DEFAULT_QUERY_OPTIONS,
81+
): ResultAsync<HubAsset[], UnexpectedError> {
82+
return client.query(HubAssetsQuery, { request, ...options });
83+
}

packages/client/src/actions/reserves.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import type { UnexpectedError } from '@aave/core-next';
22
import {
3+
type APYSample,
4+
type BorrowAPYHistoryRequest,
5+
BorrowApyHistoryQuery,
36
type Reserve,
47
ReservesQuery,
58
type ReservesRequest,
9+
type SupplyAPYHistoryRequest,
10+
SupplyApyHistoryQuery,
611
} from '@aave/graphql-next';
712
import type { ResultAsync } from '@aave/types-next';
813
import type { AaveClient } from '../AaveClient';
@@ -36,3 +41,53 @@ export function reserves(
3641
): ResultAsync<Reserve[], UnexpectedError> {
3742
return client.query(ReservesQuery, { request, ...options });
3843
}
44+
45+
/**
46+
* Fetches borrow APY history for a specific reserve over time.
47+
*
48+
* ```ts
49+
* const result = await borrowApyHistory(client, {
50+
* spoke: {
51+
* address: evmAddress('0x123...'),
52+
* chainId: chainId(1)
53+
* },
54+
* reserve: reserveId(1),
55+
* window: TimeWindow.LastWeek
56+
* });
57+
* ```
58+
*
59+
* @param client - Aave client.
60+
* @param request - The borrow APY history request parameters.
61+
* @returns The borrow APY history samples.
62+
*/
63+
export function borrowApyHistory(
64+
client: AaveClient,
65+
request: BorrowAPYHistoryRequest,
66+
): ResultAsync<APYSample[], UnexpectedError> {
67+
return client.query(BorrowApyHistoryQuery, { request });
68+
}
69+
70+
/**
71+
* Fetches supply APY history for a specific reserve over time.
72+
*
73+
* ```ts
74+
* const result = await supplyApyHistory(client, {
75+
* spoke: {
76+
* address: evmAddress('0x123...'),
77+
* chainId: chainId(1)
78+
* },
79+
* reserve: reserveId(1),
80+
* window: TimeWindow.LastWeek
81+
* });
82+
* ```
83+
*
84+
* @param client - Aave client.
85+
* @param request - The supply APY history request parameters.
86+
* @returns The supply APY history samples.
87+
*/
88+
export function supplyApyHistory(
89+
client: AaveClient,
90+
request: SupplyAPYHistoryRequest,
91+
): ResultAsync<APYSample[], UnexpectedError> {
92+
return client.query(SupplyApyHistoryQuery, { request });
93+
}

packages/client/src/actions/user.ts

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import type { UnexpectedError } from '@aave/core-next';
22
import {
3-
type APYSample,
4-
type BorrowAPYHistoryRequest,
5-
BorrowApyHistoryQuery,
6-
type HubAsset,
7-
HubAssetsQuery,
8-
type HubAssetsRequest,
93
type PaginatedUserHistoryResult,
10-
type SupplyAPYHistoryRequest,
11-
SupplyApyHistoryQuery,
124
type UserBalance,
135
UserBalancesQuery,
146
type UserBalancesRequest,
@@ -248,77 +240,3 @@ export function userSummaryHistory(
248240
): ResultAsync<UserSummaryHistoryItem[], UnexpectedError> {
249241
return client.query(UserSummaryHistoryQuery, { request });
250242
}
251-
252-
/**
253-
* Fetches borrow APY history for a specific reserve over time.
254-
*
255-
* ```ts
256-
* const result = await borrowApyHistory(client, {
257-
* spoke: {
258-
* address: evmAddress('0x123...'),
259-
* chainId: chainId(1)
260-
* },
261-
* reserve: reserveId(1),
262-
* window: TimeWindow.LastWeek
263-
* });
264-
* ```
265-
*
266-
* @param client - Aave client.
267-
* @param request - The borrow APY history request parameters.
268-
* @returns The borrow APY history samples.
269-
*/
270-
export function borrowApyHistory(
271-
client: AaveClient,
272-
request: BorrowAPYHistoryRequest,
273-
): ResultAsync<APYSample[], UnexpectedError> {
274-
return client.query(BorrowApyHistoryQuery, { request });
275-
}
276-
277-
/**
278-
* Fetches supply APY history for a specific reserve over time.
279-
*
280-
* ```ts
281-
* const result = await supplyApyHistory(client, {
282-
* spoke: {
283-
* address: evmAddress('0x123...'),
284-
* chainId: chainId(1)
285-
* },
286-
* reserve: reserveId(1),
287-
* window: TimeWindow.LastWeek
288-
* });
289-
* ```
290-
*
291-
* @param client - Aave client.
292-
* @param request - The supply APY history request parameters.
293-
* @returns The supply APY history samples.
294-
*/
295-
export function supplyApyHistory(
296-
client: AaveClient,
297-
request: SupplyAPYHistoryRequest,
298-
): ResultAsync<APYSample[], UnexpectedError> {
299-
return client.query(SupplyApyHistoryQuery, { request });
300-
}
301-
302-
/**
303-
* Fetches hub assets for a specific chain and optional hub/user filtering.
304-
*
305-
* ```ts
306-
* const result = await hubAssets(client, {
307-
* chainId: chainId(1),
308-
* hub: evmAddress('0x123...'), // optional
309-
* user: evmAddress('0x456...'), // optional
310-
* });
311-
* ```
312-
*
313-
* @param client - Aave client.
314-
* @param request - The hub assets request parameters.
315-
* @param options - The query options.
316-
* @returns The hub assets array.
317-
*/
318-
export function hubAssets(
319-
client: AaveClient,
320-
request: HubAssetsRequest,
321-
options: Required<CurrencyQueryOptions> = DEFAULT_QUERY_OPTIONS,
322-
): ResultAsync<HubAsset[], UnexpectedError> {
323-
return client.query(HubAssetsQuery, { request, ...options });
324-
}

packages/react/src/helpers/results.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { UnexpectedError } from '@aave/client-next';
77
* - Rely on the `loading` value to determine if the `data` or `error` can be evaluated.
88
* - If `error` is `undefined`, then `data` value will be available.
99
*/
10-
export type ReadResult<T, E = never> =
10+
export type ReadResult<T, E extends UnexpectedError = UnexpectedError> =
1111
| {
1212
data: undefined;
1313
error: undefined;
@@ -28,17 +28,24 @@ export type ReadResult<T, E = never> =
2828
* @internal
2929
*/
3030
export const ReadResult = {
31-
Initial: <T, E = never>(): ReadResult<T, E> => ({
31+
Initial: <T, E extends UnexpectedError = UnexpectedError>(): ReadResult<
32+
T,
33+
E
34+
> => ({
3235
data: undefined,
3336
error: undefined,
3437
loading: true,
3538
}),
36-
Success: <T, E = never>(data: T): ReadResult<T, E> => ({
39+
Success: <T, E extends UnexpectedError = UnexpectedError>(
40+
data: T,
41+
): ReadResult<T, E> => ({
3742
data,
3843
error: undefined,
3944
loading: false,
4045
}),
41-
Failure: <T, E = never>(error: E): ReadResult<T, E> => ({
46+
Failure: <T, E extends UnexpectedError = UnexpectedError>(
47+
error: E,
48+
): ReadResult<T, E> => ({
4249
data: undefined,
4350
error,
4451
loading: false,

packages/react/src/hubs.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {
44
} from '@aave/client-next';
55
import {
66
type Hub,
7+
type HubAsset,
8+
HubAssetsQuery,
9+
type HubAssetsRequest,
710
HubQuery,
811
type HubRequest,
912
HubsQuery,
@@ -111,3 +114,59 @@ export function useHubs({
111114
suspense,
112115
});
113116
}
117+
118+
export type UseHubAssetsArgs = Prettify<
119+
HubAssetsRequest & CurrencyQueryOptions
120+
>;
121+
122+
/**
123+
* Fetch hub assets for a specific chain and optional hub/user filtering.
124+
*
125+
* This signature supports React Suspense:
126+
*
127+
* ```tsx
128+
* const { data } = useHubAssets({
129+
* chainId: chainId(1),
130+
* hub: evmAddress('0x123...'), // optional
131+
* user: evmAddress('0x456...'), // optional
132+
* include: [HubAssetStatusType.Active, HubAssetStatusType.Frozen], // optional
133+
* orderBy: HubAssetsRequestOrderBy.Name, // optional
134+
* suspense: true,
135+
* });
136+
* ```
137+
*/
138+
export function useHubAssets(
139+
args: UseHubAssetsArgs & Suspendable,
140+
): SuspenseResult<HubAsset[]>;
141+
142+
/**
143+
* Fetch hub assets for a specific chain and optional hub/user filtering.
144+
*
145+
* ```tsx
146+
* const { data, error, loading } = useHubAssets({
147+
* chainId: chainId(1),
148+
* hub: evmAddress('0x123...'), // optional
149+
* user: evmAddress('0x456...'), // optional
150+
* include: [HubAssetStatusType.Active, HubAssetStatusType.Frozen], // optional
151+
* orderBy: HubAssetsRequestOrderBy.Name, // optional
152+
* });
153+
* ```
154+
*/
155+
export function useHubAssets(args: UseHubAssetsArgs): ReadResult<HubAsset[]>;
156+
157+
export function useHubAssets({
158+
suspense = false,
159+
currency = DEFAULT_QUERY_OPTIONS.currency,
160+
...request
161+
}: UseHubAssetsArgs & {
162+
suspense?: boolean;
163+
}): SuspendableResult<HubAsset[]> {
164+
return useSuspendableQuery({
165+
document: HubAssetsQuery,
166+
variables: {
167+
request,
168+
currency,
169+
},
170+
suspense,
171+
});
172+
}

0 commit comments

Comments
 (0)