Skip to content

Commit dfd9c58

Browse files
committed
feat: add client actions for deposit/withdraw/balance sGHO
1 parent 27d3d6e commit dfd9c58

File tree

3 files changed

+102
-7
lines changed

3 files changed

+102
-7
lines changed

packages/client/src/actions/gho.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import {
2+
type ExecutionPlan,
3+
SavingsGhoBalanceQuery,
4+
type SavingsGhoBalanceRequest,
5+
SavingsGhoDepositQuery,
6+
type SavingsGhoDepositRequest,
7+
SavingsGhoWithdrawQuery,
8+
type SavingsGhoWithdrawRequest,
9+
type TokenAmount,
10+
type TransactionRequest,
11+
} from '@aave/graphql';
12+
import type { ResultAsync } from '@aave/types';
13+
import type { AaveClient } from '../client';
14+
import type { UnexpectedError } from '../errors';
15+
16+
/**
17+
* Fetches the current sGHO balance for a user.
18+
*
19+
* ```ts
20+
* const result = await savingsGhoBalance(client, {
21+
* user: evmAddress('0x742d35cc…'),
22+
* });
23+
* ```
24+
*
25+
* @param client - Aave client.
26+
* @param request - The sGHO balance request parameters.
27+
* @returns The user's sGHO balance.
28+
*/
29+
export function savingsGhoBalance(
30+
client: AaveClient,
31+
request: SavingsGhoBalanceRequest,
32+
): ResultAsync<TokenAmount, UnexpectedError> {
33+
return client.query(SavingsGhoBalanceQuery, { request });
34+
}
35+
36+
/**
37+
* Creates a transaction to withdraw sGHO.
38+
*
39+
* ```ts
40+
* const result = await savingsGhoWithdraw(client, {
41+
* amount: {
42+
* exact: '1000',
43+
* },
44+
* sharesOwner: evmAddress('0x9abc…'),
45+
* }).andThen(sendWith(wallet)).andThen(client.waitForTransaction);
46+
*
47+
* if (result.isErr()) {
48+
* // Handle error, e.g. signing error, etc.
49+
* return;
50+
* }
51+
*
52+
* // result.value: TxHash
53+
* ```
54+
*
55+
* @param client - Aave client.
56+
* @param request - The sGHO withdraw request parameters.
57+
* @returns The transaction request data to withdraw sGHO.
58+
*/
59+
export function savingsGhoWithdraw(
60+
client: AaveClient,
61+
request: SavingsGhoWithdrawRequest,
62+
): ResultAsync<TransactionRequest, UnexpectedError> {
63+
return client.query(SavingsGhoWithdrawQuery, { request });
64+
}
65+
66+
/**
67+
* Creates a transaction to deposit GHO into sGHO.
68+
*
69+
* ```ts
70+
* const result = await savingsGhoDeposit(client, {
71+
* amount: {
72+
* value: '1000',
73+
* },
74+
* depositor: evmAddress('0x9abc…'),
75+
* }).andThen(sendWith(wallet)).andThen(client.waitForTransaction);
76+
*
77+
* if (result.isErr()) {
78+
* // Handle error, e.g. insufficient balance, signing error, etc.
79+
* return;
80+
* }
81+
*
82+
* // result.value: TxHash
83+
* ```
84+
*
85+
* @param client - Aave client.
86+
* @param request - The sGHO deposit request parameters.
87+
* @returns The transaction data, approval requirements, or insufficient balance error.
88+
*/
89+
export function savingsGhoDeposit(
90+
client: AaveClient,
91+
request: SavingsGhoDepositRequest,
92+
): ResultAsync<ExecutionPlan, UnexpectedError> {
93+
return client.query(SavingsGhoDepositQuery, { request });
94+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {
2-
MeritClaimRewardsQuery,
3-
type MeritClaimRewardsRequest,
2+
UserMeritRewardsQuery,
3+
type UserMeritRewardsRequest,
44
} from '@aave/graphql';
55
import type { AaveClient } from '../client';
66

77
/**
8-
* Fetches Merit claim rewards for a user with the transaction request to claim them.
8+
* Fetches Merit rewards for a user with the transaction request to claim them.
99
*
1010
* ```ts
11-
* const result = await meritClaimRewards(client, {
11+
* const result = await userMeritRewards(client, {
1212
* user: evmAddress('0x742d35cc…'),
1313
* chainId: chainId(1),
1414
* });
@@ -18,9 +18,9 @@ import type { AaveClient } from '../client';
1818
* @param request - The merit claim rewards request parameters.
1919
* @returns The rewards with the transaction request.
2020
*/
21-
export function meritClaimRewards(
21+
export function userMeritRewards(
2222
client: AaveClient,
23-
request: MeritClaimRewardsRequest,
23+
request: UserMeritRewardsRequest,
2424
) {
25-
return client.query(MeritClaimRewardsQuery, { request });
25+
return client.query(UserMeritRewardsQuery, { request });
2626
}

packages/client/src/actions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './gho';
12
export * from './incentives';
23
export * from './markets';
34
export * from './misc';

0 commit comments

Comments
 (0)