Skip to content

Commit b7d6df6

Browse files
authored
Merge branch 'main' into pawel/aave-995-integrate-split-revenue-into-the-sdk
2 parents feaf7c6 + 5694151 commit b7d6df6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+454
-329
lines changed

.changeset/angry-webs-relate.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@aave/graphql": minor
3+
"@aave/client": minor
4+
"@aave/react": minor
5+
"@aave/types": minor
6+
"@aave/core": minor
7+
---
8+
9+
**chore:** extract core logic into internal @aave/core package

.changeset/fair-mice-burn.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/sharp-chefs-fail.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@aave/graphql": patch
3+
"@aave/types": patch
4+
---
5+
6+
**chore:** removes unused types.

packages/client/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @aave/client
22

3+
## 0.6.1
4+
5+
### Patch Changes
6+
7+
- 9fbf4bd: **fix:** republish due to CI issue with previous release
8+
- Updated dependencies [9fbf4bd]
9+
- @aave/graphql@0.6.1
10+
- @aave/types@0.1.1
11+
312
## 0.6.0
413

514
### Minor Changes

packages/client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aave/client",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "The official JavaScript client for the Aave API",
55
"repository": {
66
"directory": "packages/client",
@@ -72,6 +72,7 @@
7272
},
7373
"dependencies": {
7474
"@aave/graphql": "workspace:*",
75+
"@aave/core": "workspace:*",
7576
"@aave/types": "workspace:*",
7677
"@urql/core": "^5.2.0",
7778
"graphql": "^16.11.0"

packages/client/src/AaveClient.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { delay, GqlClient, TimeoutError, UnexpectedError } from '@aave/core';
2+
import type { HasProcessedKnownTransactionRequest } from '@aave/graphql';
3+
import { invariant, okAsync, ResultAsync, type TxHash } from '@aave/types';
4+
import { hasProcessedKnownTransaction } from './actions';
5+
import { type ClientConfig, configureContext } from './config';
6+
import {
7+
isHasProcessedKnownTransactionRequest,
8+
type TransactionExecutionResult,
9+
} from './types';
10+
11+
export class AaveClient extends GqlClient {
12+
/**
13+
* Create a new instance of the {@link AaveClient}.
14+
*
15+
* ```ts
16+
* const client = AaveClient.create({
17+
* environment: production,
18+
* });
19+
* ```
20+
*
21+
* @param options - The options to configure the client.
22+
* @returns The new instance of the client.
23+
*/
24+
static create(options?: ClientConfig): AaveClient {
25+
return new AaveClient(configureContext(options ?? {}));
26+
}
27+
28+
/**
29+
* @internal
30+
*/
31+
readonly waitForSupportedTransaction = (
32+
result: TransactionExecutionResult,
33+
): ResultAsync<TxHash, TimeoutError | UnexpectedError> => {
34+
if (isHasProcessedKnownTransactionRequest(result)) {
35+
return this.waitForTransaction(result);
36+
}
37+
return okAsync(result.txHash);
38+
};
39+
40+
/**
41+
* Given the transaction hash of an Aave protocol transaction, wait for the transaction to be
42+
* processed by the Aave v3 API.
43+
*
44+
* Returns a {@link TimeoutError} if the transaction is not processed within the expected timeout period.
45+
*
46+
* @param result - The transaction execution result to wait for.
47+
* @returns The transaction hash or a TimeoutError
48+
*/
49+
readonly waitForTransaction = (
50+
result: TransactionExecutionResult,
51+
): ResultAsync<TxHash, TimeoutError | UnexpectedError> => {
52+
invariant(
53+
isHasProcessedKnownTransactionRequest(result),
54+
`Received a transaction result for an untracked operation. Make sure you're following the instructions in the docs.`,
55+
);
56+
57+
return ResultAsync.fromPromise(
58+
this.pollTransactionStatus(result),
59+
(err) => {
60+
if (err instanceof TimeoutError || err instanceof UnexpectedError) {
61+
return err;
62+
}
63+
return UnexpectedError.from(err);
64+
},
65+
);
66+
};
67+
68+
protected async pollTransactionStatus(
69+
request: HasProcessedKnownTransactionRequest,
70+
): Promise<TxHash> {
71+
const startedAt = Date.now();
72+
73+
while (Date.now() - startedAt < this.context.environment.indexingTimeout) {
74+
const processed = await hasProcessedKnownTransaction(this, request).match(
75+
(ok) => ok,
76+
(err) => {
77+
throw err;
78+
},
79+
);
80+
81+
if (processed) {
82+
return request.txHash;
83+
}
84+
85+
await delay(this.context.environment.pollingInterval);
86+
}
87+
throw TimeoutError.from(
88+
`Timeout waiting for transaction ${request.txHash} to be processed.`,
89+
);
90+
}
91+
}

packages/client/src/actions/gho.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { UnexpectedError } from '@aave/core';
12
import {
23
type ExecutionPlan,
34
SavingsGhoBalanceQuery,
@@ -9,8 +10,7 @@ import {
910
type TokenAmount,
1011
} from '@aave/graphql';
1112
import type { ResultAsync } from '@aave/types';
12-
import type { AaveClient } from '../client';
13-
import type { UnexpectedError } from '../errors';
13+
import type { AaveClient } from '../AaveClient';
1414

1515
/**
1616
* Fetches the current sGHO balance for a user.

packages/client/src/actions/incentives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
UserMeritRewardsQuery,
33
type UserMeritRewardsRequest,
44
} from '@aave/graphql';
5-
import type { AaveClient } from '../client';
5+
import type { AaveClient } from '../AaveClient';
66

77
/**
88
* Fetches Merit rewards for a user with the transaction request to claim them.

packages/client/src/actions/markets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { UnexpectedError } from '@aave/core';
12
import {
23
type Market,
34
MarketQuery,
@@ -9,8 +10,7 @@ import {
910
type UserMarketStateRequest,
1011
} from '@aave/graphql';
1112
import type { ChainId, EvmAddress, ResultAsync } from '@aave/types';
12-
import type { AaveClient } from '../client';
13-
import type { UnexpectedError } from '../errors';
13+
import type { AaveClient } from '../AaveClient';
1414

1515
export const defaultMarketReservesRequestOrderBy: MarketReservesRequestOrderBy =
1616
{

packages/client/src/actions/misc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { UnexpectedError } from '@aave/core';
12
import {
23
type Chain,
34
ChainsFilter,
@@ -13,8 +14,7 @@ import {
1314
type UsdExchangeRatesRequest,
1415
} from '@aave/graphql';
1516
import type { ResultAsync } from '@aave/types';
16-
import type { AaveClient } from '../client';
17-
import type { UnexpectedError } from '../errors';
17+
import type { AaveClient } from '../AaveClient';
1818

1919
/**
2020
* Health check query.

0 commit comments

Comments
 (0)