Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/client/src/actions/hubs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { UnexpectedError } from '@aave/core-next';
import {
type Hub,
type HubAsset,
HubAssetsQuery,
type HubAssetsRequest,
HubQuery,
type HubRequest,
HubsQuery,
type HubsRequest,
} from '@aave/graphql-next';
import type { ResultAsync } from '@aave/types-next';

import type { AaveClient } from '../AaveClient';
import { type CurrencyQueryOptions, DEFAULT_QUERY_OPTIONS } from '../options';

Expand Down Expand Up @@ -55,3 +57,27 @@ export function hubs(
): ResultAsync<Hub[], UnexpectedError> {
return client.query(HubsQuery, { request, ...options });
}

/**
* Fetches hub assets for a specific chain and optional hub/user filtering.
*
* ```ts
* const result = await hubAssets(client, {
* chainId: chainId(1),
* hub: evmAddress('0x123...'), // optional
* user: evmAddress('0x456...'), // optional
* });
* ```
*
* @param client - Aave client.
* @param request - The hub assets request parameters.
* @param options - The query options.
* @returns The hub assets array.
*/
export function hubAssets(
client: AaveClient,
request: HubAssetsRequest,
options: Required<CurrencyQueryOptions> = DEFAULT_QUERY_OPTIONS,
): ResultAsync<HubAsset[], UnexpectedError> {
return client.query(HubAssetsQuery, { request, ...options });
}
55 changes: 55 additions & 0 deletions packages/client/src/actions/reserves.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { UnexpectedError } from '@aave/core-next';
import {
type APYSample,
type BorrowAPYHistoryRequest,
BorrowApyHistoryQuery,
type Reserve,
ReservesQuery,
type ReservesRequest,
type SupplyAPYHistoryRequest,
SupplyApyHistoryQuery,
} from '@aave/graphql-next';
import type { ResultAsync } from '@aave/types-next';
import type { AaveClient } from '../AaveClient';
Expand Down Expand Up @@ -36,3 +41,53 @@ export function reserves(
): ResultAsync<Reserve[], UnexpectedError> {
return client.query(ReservesQuery, { request, ...options });
}

/**
* Fetches borrow APY history for a specific reserve over time.
*
* ```ts
* const result = await borrowApyHistory(client, {
* spoke: {
* address: evmAddress('0x123...'),
* chainId: chainId(1)
* },
* reserve: reserveId(1),
* window: TimeWindow.LastWeek
* });
* ```
*
* @param client - Aave client.
* @param request - The borrow APY history request parameters.
* @returns The borrow APY history samples.
*/
export function borrowApyHistory(
client: AaveClient,
request: BorrowAPYHistoryRequest,
): ResultAsync<APYSample[], UnexpectedError> {
return client.query(BorrowApyHistoryQuery, { request });
}

/**
* Fetches supply APY history for a specific reserve over time.
*
* ```ts
* const result = await supplyApyHistory(client, {
* spoke: {
* address: evmAddress('0x123...'),
* chainId: chainId(1)
* },
* reserve: reserveId(1),
* window: TimeWindow.LastWeek
* });
* ```
*
* @param client - Aave client.
* @param request - The supply APY history request parameters.
* @returns The supply APY history samples.
*/
export function supplyApyHistory(
client: AaveClient,
request: SupplyAPYHistoryRequest,
): ResultAsync<APYSample[], UnexpectedError> {
return client.query(SupplyApyHistoryQuery, { request });
}
82 changes: 0 additions & 82 deletions packages/client/src/actions/user.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import type { UnexpectedError } from '@aave/core-next';
import {
type APYSample,
type BorrowAPYHistoryRequest,
BorrowApyHistoryQuery,
type HubAsset,
HubAssetsQuery,
type HubAssetsRequest,
type PaginatedUserHistoryResult,
type SupplyAPYHistoryRequest,
SupplyApyHistoryQuery,
type UserBalance,
UserBalancesQuery,
type UserBalancesRequest,
Expand Down Expand Up @@ -248,77 +240,3 @@ export function userSummaryHistory(
): ResultAsync<UserSummaryHistoryItem[], UnexpectedError> {
return client.query(UserSummaryHistoryQuery, { request });
}

/**
* Fetches borrow APY history for a specific reserve over time.
*
* ```ts
* const result = await borrowApyHistory(client, {
* spoke: {
* address: evmAddress('0x123...'),
* chainId: chainId(1)
* },
* reserve: reserveId(1),
* window: TimeWindow.LastWeek
* });
* ```
*
* @param client - Aave client.
* @param request - The borrow APY history request parameters.
* @returns The borrow APY history samples.
*/
export function borrowApyHistory(
client: AaveClient,
request: BorrowAPYHistoryRequest,
): ResultAsync<APYSample[], UnexpectedError> {
return client.query(BorrowApyHistoryQuery, { request });
}

/**
* Fetches supply APY history for a specific reserve over time.
*
* ```ts
* const result = await supplyApyHistory(client, {
* spoke: {
* address: evmAddress('0x123...'),
* chainId: chainId(1)
* },
* reserve: reserveId(1),
* window: TimeWindow.LastWeek
* });
* ```
*
* @param client - Aave client.
* @param request - The supply APY history request parameters.
* @returns The supply APY history samples.
*/
export function supplyApyHistory(
client: AaveClient,
request: SupplyAPYHistoryRequest,
): ResultAsync<APYSample[], UnexpectedError> {
return client.query(SupplyApyHistoryQuery, { request });
}

/**
* Fetches hub assets for a specific chain and optional hub/user filtering.
*
* ```ts
* const result = await hubAssets(client, {
* chainId: chainId(1),
* hub: evmAddress('0x123...'), // optional
* user: evmAddress('0x456...'), // optional
* });
* ```
*
* @param client - Aave client.
* @param request - The hub assets request parameters.
* @param options - The query options.
* @returns The hub assets array.
*/
export function hubAssets(
client: AaveClient,
request: HubAssetsRequest,
options: Required<CurrencyQueryOptions> = DEFAULT_QUERY_OPTIONS,
): ResultAsync<HubAsset[], UnexpectedError> {
return client.query(HubAssetsQuery, { request, ...options });
}
15 changes: 11 additions & 4 deletions packages/react/src/helpers/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { UnexpectedError } from '@aave/client-next';
* - Rely on the `loading` value to determine if the `data` or `error` can be evaluated.
* - If `error` is `undefined`, then `data` value will be available.
*/
export type ReadResult<T, E = never> =
export type ReadResult<T, E extends UnexpectedError = UnexpectedError> =
| {
data: undefined;
error: undefined;
Expand All @@ -28,17 +28,24 @@ export type ReadResult<T, E = never> =
* @internal
*/
export const ReadResult = {
Initial: <T, E = never>(): ReadResult<T, E> => ({
Initial: <T, E extends UnexpectedError = UnexpectedError>(): ReadResult<
T,
E
> => ({
data: undefined,
error: undefined,
loading: true,
}),
Success: <T, E = never>(data: T): ReadResult<T, E> => ({
Success: <T, E extends UnexpectedError = UnexpectedError>(
data: T,
): ReadResult<T, E> => ({
data,
error: undefined,
loading: false,
}),
Failure: <T, E = never>(error: E): ReadResult<T, E> => ({
Failure: <T, E extends UnexpectedError = UnexpectedError>(
error: E,
): ReadResult<T, E> => ({
data: undefined,
error,
loading: false,
Expand Down
59 changes: 59 additions & 0 deletions packages/react/src/hubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
} from '@aave/client-next';
import {
type Hub,
type HubAsset,
HubAssetsQuery,
type HubAssetsRequest,
HubQuery,
type HubRequest,
HubsQuery,
Expand Down Expand Up @@ -111,3 +114,59 @@ export function useHubs({
suspense,
});
}

export type UseHubAssetsArgs = Prettify<
HubAssetsRequest & CurrencyQueryOptions
>;

/**
* Fetch hub assets for a specific chain and optional hub/user filtering.
*
* This signature supports React Suspense:
*
* ```tsx
* const { data } = useHubAssets({
* chainId: chainId(1),
* hub: evmAddress('0x123...'), // optional
* user: evmAddress('0x456...'), // optional
* include: [HubAssetStatusType.Active, HubAssetStatusType.Frozen], // optional
* orderBy: HubAssetsRequestOrderBy.Name, // optional
* suspense: true,
* });
* ```
*/
export function useHubAssets(
args: UseHubAssetsArgs & Suspendable,
): SuspenseResult<HubAsset[]>;

/**
* Fetch hub assets for a specific chain and optional hub/user filtering.
*
* ```tsx
* const { data, error, loading } = useHubAssets({
* chainId: chainId(1),
* hub: evmAddress('0x123...'), // optional
* user: evmAddress('0x456...'), // optional
* include: [HubAssetStatusType.Active, HubAssetStatusType.Frozen], // optional
* orderBy: HubAssetsRequestOrderBy.Name, // optional
* });
* ```
*/
export function useHubAssets(args: UseHubAssetsArgs): ReadResult<HubAsset[]>;

export function useHubAssets({
suspense = false,
currency = DEFAULT_QUERY_OPTIONS.currency,
...request
}: UseHubAssetsArgs & {
suspense?: boolean;
}): SuspendableResult<HubAsset[]> {
return useSuspendableQuery({
document: HubAssetsQuery,
variables: {
request,
currency,
},
suspense,
});
}
Loading