Skip to content

Commit f6a7376

Browse files
committed
feat: useEModeToggle, useWithdraw, useRepay, useBorrow, useSupply
1 parent f6e57bf commit f6a7376

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

packages/react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export { useAaveClient } from './context';
33
export * from './markets';
44
export * from './misc';
55
export * from './reserves';
6+
export * from './transactions';
67
export * from './user';

packages/react/src/transactions.ts

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import type { UnexpectedError } from '@aave/client';
2-
import type { ExecutionPlan, SupplyRequest } from '@aave/graphql';
3-
import { supply } from '../../client/src/actions';
2+
import type {
3+
ExecutionPlan,
4+
SupplyRequest,
5+
BorrowRequest,
6+
RepayRequest,
7+
WithdrawRequest,
8+
EModeToggleRequest,
9+
TransactionRequest,
10+
} from '@aave/graphql';
11+
import {
12+
supply,
13+
borrow,
14+
repay,
15+
withdraw,
16+
eModeToggle,
17+
} from '../../client/src/actions';
418
import { useAaveClient } from './context';
519
import { type UseAsyncTask, useAsyncTask } from './helpers';
620

@@ -20,3 +34,71 @@ export function useSupply(): UseAsyncTask<
2034

2135
return useAsyncTask((request: SupplyRequest) => supply(client, request));
2236
}
37+
38+
/**
39+
* A hook that provides a way to borrow assets from an Aave market.
40+
*
41+
* ```ts
42+
* const [borrow, { loading, error, data }] = useBorrow();
43+
* ```
44+
*/
45+
export function useBorrow(): UseAsyncTask<
46+
BorrowRequest,
47+
ExecutionPlan,
48+
UnexpectedError
49+
> {
50+
const client = useAaveClient();
51+
52+
return useAsyncTask((request: BorrowRequest) => borrow(client, request));
53+
}
54+
55+
/**
56+
* A hook that provides a way to repay borrowed assets to an Aave market.
57+
*
58+
* ```ts
59+
* const [repay, { loading, error, data }] = useRepay();
60+
* ```
61+
*/
62+
export function useRepay(): UseAsyncTask<
63+
RepayRequest,
64+
ExecutionPlan,
65+
UnexpectedError
66+
> {
67+
const client = useAaveClient();
68+
69+
return useAsyncTask((request: RepayRequest) => repay(client, request));
70+
}
71+
72+
/**
73+
* A hook that provides a way to withdraw supplied assets from an Aave market.
74+
*
75+
* ```ts
76+
* const [withdraw, { loading, error, data }] = useWithdraw();
77+
* ```
78+
*/
79+
export function useWithdraw(): UseAsyncTask<
80+
WithdrawRequest,
81+
ExecutionPlan,
82+
UnexpectedError
83+
> {
84+
const client = useAaveClient();
85+
86+
return useAsyncTask((request: WithdrawRequest) => withdraw(client, request));
87+
}
88+
89+
/**
90+
* A hook that provides a way to toggle eMode for a user in an Aave market.
91+
*
92+
* ```ts
93+
* const [toggleEMode, { loading, error, data }] = useEModeToggle();
94+
* ```
95+
*/
96+
export function useEModeToggle(): UseAsyncTask<
97+
EModeToggleRequest,
98+
TransactionRequest,
99+
UnexpectedError
100+
> {
101+
const client = useAaveClient();
102+
103+
return useAsyncTask((request: EModeToggleRequest) => eModeToggle(client, request));
104+
}

0 commit comments

Comments
 (0)