Skip to content

Commit 4ee72ba

Browse files
committed
feat: userBorrows, userSupplies actions
1 parent fe39054 commit 4ee72ba

File tree

11 files changed

+153
-1
lines changed

11 files changed

+153
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './markets';
22
export * from './misc';
33
export * from './reserve';
4+
export * from './user';
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
UserBorrowsQuery,
3+
type UserBorrowsRequest,
4+
type UserReserveBorrowPosition,
5+
type UserReserveSupplyPosition,
6+
UserSuppliesQuery,
7+
type UserSuppliesRequest,
8+
} from '@aave/graphql';
9+
import type { ResultAsync } from '@aave/types';
10+
import type { AaveClient } from '../client';
11+
import type { UnexpectedError } from '../errors';
12+
13+
/**
14+
* Fetches all user supply positions across specified markets.
15+
*
16+
* ```ts
17+
* const result = await userSupplies(client, {
18+
* markets: [evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2')],
19+
* user: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'),
20+
* orderBy: { name: OrderDirection.Asc }
21+
* });
22+
* ```
23+
*
24+
* @param client - Aave client.
25+
* @param request - The user supplies request parameters.
26+
* @returns The list of user supply positions.
27+
*/
28+
export function userSupplies(
29+
client: AaveClient,
30+
request: UserSuppliesRequest,
31+
): ResultAsync<UserReserveSupplyPosition[], UnexpectedError> {
32+
return client.query(UserSuppliesQuery, { request });
33+
}
34+
35+
/**
36+
* Fetches all user borrow positions across specified markets.
37+
*
38+
* ```ts
39+
* const result = await userBorrows(client, {
40+
* markets: [evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2')],
41+
* user: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'),
42+
* orderBy: { name: OrderDirection.Asc }
43+
* });
44+
* ```
45+
*
46+
* @param client - Aave client.
47+
* @param request - The user borrows request parameters.
48+
* @returns The list of user borrow positions.
49+
*/
50+
export function userBorrows(
51+
client: AaveClient,
52+
request: UserBorrowsRequest,
53+
): ResultAsync<UserReserveBorrowPosition[], UnexpectedError> {
54+
return client.query(UserBorrowsQuery, { request });
55+
}

packages/graphql/src/enums.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
export {};
1+
/**
2+
* The order direction for sorting results.
3+
*/
4+
export enum OrderDirection {
5+
Asc = 'ASC',
6+
Desc = 'DESC',
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './chain';
22
export * from './common';
33
export * from './market';
4+
export * from './positions';
45
export * from './reserve';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { FragmentOf } from 'gql.tada';
2+
import { graphql } from '../graphql';
3+
import { CurrencyFragment, DecimalValueFragment } from './common';
4+
5+
export const UserReserveBorrowPositionFragment = graphql(
6+
`fragment UserReserveBorrowPosition on UserReserveBorrowPosition {
7+
__typename
8+
market
9+
currency {
10+
...Currency
11+
}
12+
debt {
13+
...DecimalValue
14+
}
15+
apy {
16+
...DecimalValue
17+
}
18+
}`,
19+
[CurrencyFragment, DecimalValueFragment],
20+
);
21+
export type UserReserveBorrowPosition = FragmentOf<typeof UserReserveBorrowPositionFragment>;
22+
23+
export const UserReserveSupplyPositionFragment = graphql(
24+
`fragment UserReserveSupplyPosition on UserReserveSupplyPosition {
25+
__typename
26+
market
27+
currency {
28+
...Currency
29+
}
30+
balance {
31+
...DecimalValue
32+
}
33+
apy {
34+
...DecimalValue
35+
}
36+
collateral
37+
}`,
38+
[CurrencyFragment, DecimalValueFragment],
39+
);
40+
export type UserReserveSupplyPosition = FragmentOf<typeof UserReserveSupplyPositionFragment>;

packages/graphql/src/graphql.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
type TadaDocumentNode,
1919
} from 'gql.tada';
2020
import type { StandardData } from './common';
21+
import type { OrderDirection } from './enums';
2122
import type { introspection } from './graphql-env';
2223

2324
export type { FragmentOf } from 'gql.tada';
@@ -37,6 +38,7 @@ export const graphql = initGraphQLTada<{
3738
Float: number;
3839
ID: ID;
3940
Int: number;
41+
OrderDirection: OrderDirection;
4042
Signature: Signature;
4143
String: string;
4244
TxHash: TxHash;

packages/graphql/src/index.ts

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

packages/graphql/src/markets.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { MarketFragment } from './fragments';
22
import { graphql, type RequestOf } from './graphql';
33

4+
/**
5+
* @internal
6+
*/
47
export const MarketsQuery = graphql(
58
`query Markets($request: MarketsRequest!) {
69
value: markets(request: $request) {
@@ -11,6 +14,9 @@ export const MarketsQuery = graphql(
1114
);
1215
export type MarketsRequest = RequestOf<typeof MarketsQuery>;
1316

17+
/**
18+
* @internal
19+
*/
1420
export const MarketQuery = graphql(
1521
`query Market($request: MarketRequest!) {
1622
value: market(request: $request) {

packages/graphql/src/misc.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { ChainFragment } from './fragments';
22
import { graphql } from './graphql';
33

4+
/**
5+
* @internal
6+
*/
47
export const HealthQuery = graphql(
58
`query Health {
69
value: health
710
}`,
811
);
912

13+
/**
14+
* @internal
15+
*/
1016
export const ChainsQuery = graphql(
1117
`query Chains {
1218
value: chains {

packages/graphql/src/reserves.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { ReserveFragment } from './fragments';
22
import { graphql, type RequestOf } from './graphql';
33

4+
/**
5+
* @internal
6+
*/
47
export const ReserveQuery = graphql(
58
`query Reserve($request: ReserveRequest!) {
69
value: reserve(request: $request) {

0 commit comments

Comments
 (0)