Skip to content

Commit 697ede4

Browse files
committed
feat: withdraw, repay, supply actions
1 parent 2f30d95 commit 697ede4

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

packages/client/src/actions/transactions.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import {
22
BorrowQuery,
33
type BorrowRequest,
4+
RepayQuery,
5+
type RepayRequest,
6+
SupplyQuery,
7+
type SupplyRequest,
48
type Transaction,
9+
WithdrawQuery,
10+
type WithdrawRequest,
511
} from '@aave/graphql';
612
import type { ResultAsync } from '@aave/types';
713
import type { AaveClient } from '../client';
@@ -34,3 +40,87 @@ export function borrow(
3440
): ResultAsync<Transaction, UnexpectedError> {
3541
return client.query(BorrowQuery, { request });
3642
}
43+
44+
/**
45+
* Creates a transaction to supply to a market.
46+
*
47+
* ```ts
48+
* const result = await supply(client, {
49+
* market: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'),
50+
* amount: {
51+
* erc20: {
52+
* currency: evmAddress('0xa0b86a33e6441c8c5f0bb9b7e5e1f8bbf5b78b5c'),
53+
* value: '1000'
54+
* }
55+
* },
56+
* supplier: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'),
57+
* chainId: chainId(1)
58+
* });
59+
* ```
60+
*
61+
* @param client - Aave client.
62+
* @param request - The supply request parameters.
63+
* @returns The transaction data, approval requirements, or insufficient balance error.
64+
*/
65+
export function supply(
66+
client: AaveClient,
67+
request: SupplyRequest,
68+
): ResultAsync<Transaction, UnexpectedError> {
69+
return client.query(SupplyQuery, { request });
70+
}
71+
72+
/**
73+
* Creates a transaction to repay to a market.
74+
*
75+
* ```ts
76+
* const result = await repay(client, {
77+
* market: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'),
78+
* amount: {
79+
* erc20: {
80+
* currency: evmAddress('0xa0b86a33e6441c8c5f0bb9b7e5e1f8bbf5b78b5c'),
81+
* value: '500'
82+
* }
83+
* },
84+
* borrower: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'),
85+
* chainId: chainId(1)
86+
* });
87+
* ```
88+
*
89+
* @param client - Aave client.
90+
* @param request - The repay request parameters.
91+
* @returns The transaction data, approval requirements, or insufficient balance error.
92+
*/
93+
export function repay(
94+
client: AaveClient,
95+
request: RepayRequest,
96+
): ResultAsync<Transaction, UnexpectedError> {
97+
return client.query(RepayQuery, { request });
98+
}
99+
100+
/**
101+
* Creates a transaction to withdraw from a market.
102+
*
103+
* ```ts
104+
* const result = await withdraw(client, {
105+
* market: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'),
106+
* amount: {
107+
* erc20: {
108+
* currency: evmAddress('0xa0b86a33e6441c8c5f0bb9b7e5e1f8bbf5b78b5c'),
109+
* value: '750'
110+
* }
111+
* },
112+
* supplier: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'),
113+
* chainId: chainId(1)
114+
* });
115+
* ```
116+
*
117+
* @param client - Aave client.
118+
* @param request - The withdraw request parameters.
119+
* @returns The transaction data, approval requirements, or insufficient balance error.
120+
*/
121+
export function withdraw(
122+
client: AaveClient,
123+
request: WithdrawRequest,
124+
): ResultAsync<Transaction, UnexpectedError> {
125+
return client.query(WithdrawQuery, { request });
126+
}

packages/graphql/src/transactions.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,42 @@ export const BorrowQuery = graphql(
1313
[TransactionFragment],
1414
);
1515
export type BorrowRequest = RequestOf<typeof BorrowQuery>;
16+
17+
/**
18+
* @internal
19+
*/
20+
export const SupplyQuery = graphql(
21+
`query Supply($request: SupplyRequest!) {
22+
value: supply(request: $request) {
23+
...Transaction
24+
}
25+
}`,
26+
[TransactionFragment],
27+
);
28+
export type SupplyRequest = RequestOf<typeof SupplyQuery>;
29+
30+
/**
31+
* @internal
32+
*/
33+
export const RepayQuery = graphql(
34+
`query Repay($request: RepayRequest!) {
35+
value: repay(request: $request) {
36+
...Transaction
37+
}
38+
}`,
39+
[TransactionFragment],
40+
);
41+
export type RepayRequest = RequestOf<typeof RepayQuery>;
42+
43+
/**
44+
* @internal
45+
*/
46+
export const WithdrawQuery = graphql(
47+
`query Withdraw($request: WithdrawRequest!) {
48+
value: withdraw(request: $request) {
49+
...Transaction
50+
}
51+
}`,
52+
[TransactionFragment],
53+
);
54+
export type WithdrawRequest = RequestOf<typeof WithdrawQuery>;

0 commit comments

Comments
 (0)