SDKs
Currently there is a Typescript package available on NPM to help with your implementation of the Aave Protocol. The SDK provides easy to use methods to interact with the Aave Protocol, as well as methods to calculate user positions such as the health factor.
The SDK requires a basic understanding of Javascript/Typescript, as well as experience using NPM.
You can easily install the SDK using the command:
1
// with npm
2
npm install @aave/protocol-js
3
4
// or with yarn
5
yarn add @aave/protocol-js
Copied!

Protocol-js

An example of using the SDK with data fetched from the subgraph:
1
import { v1, v2 } from '@aave/protocol-js';
2
3
// returns user summary data in big units.
4
v1.formatUserSummaryData(
5
poolReservesData,
6
rawUserReserves,
7
userId,
8
usdPriceEth,
9
currentTimestamp
10
);
11
12
// returns user summary data in small units with 0 decimal places, except health-factor.
13
v1.computeRawUserSummaryData(
14
poolReservesData,
15
rawUserReserves,
16
userId,
17
usdPriceEth,
18
currentTimestamp
19
);
20
21
// returns reserves data formatted to big units.
22
v2.formatReserves(reserves, currentTimestamp);
Copied!
For a list of transaction methods, see the Github repo.

Rates calculation

Calculating rates in Aave is somewhat complicated due to the interest bearing nature of aTokens.
The reason for that is twofold:
    1.
    liquidity of aTokens constantly changes which is making utilization based rates extremely dynamic (it's changing every second)
    2.
    depositor interest is not only based on interest, but also includes factors like flash premiums (so it's usually "a little more")
Therefore the Aave protocol keeps track of two values:
Rate: The rate is a purely utilization based metric which represents the current rate at a specific point in time.
Index: The index keeps track of reserve growth also incorporating things like the flash premium.
To calculate correct historically archived deposit rates you should use index based rate calculation.
1
/*
2
You can fetch the data rquired from graphql.
3
This query would provide the mot up to date & the first ever data.
4
This data could be used to calculate the average liquidityRate since inception.
5
{
6
reserves(first: 1) {
7
lastUpdateTimestamp
8
liquidityIndex
9
variableBorrowIndex
10
paramsHistory(first: 1, orderDirection: asc, orderBy: timestamp){
11
timestamp
12
liquidityIndex
13
variableBorrowIndex
14
}
15
}
16
}
17
*/
18
19
// data returned by gql
20
const result = {
21
lastUpdateTimestamp: 1611926412,
22
liquidityIndex: "1031830159181667334741382194",
23
variableBorrowIndex: "1048002659480593195934069307",
24
paramsHistory: [
25
{
26
timestamp: 1606903009,
27
liquidityIndex: "1021187617641523092754480830",
28
variableBorrowIndex: "1034162815675781948442542345",
29
},
30
],
31
};
32
const archivedRate = calculateAverageRate(
33
result.paramsHistory[0].liquidityIndex,
34
result.liquidityIndex,
35
result.paramsHistory[0].timestamp,
36
result.lastUpdateTimestamp
37
);
Copied!
Last modified 8mo ago