Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add v1 export #14

Merged
merged 8 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 58 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,79 @@

Aave protocol logic package, supports main and uniswap markets


The simplest way to get initial protocol data - use our subgraphs on TheGraph protocol:
https://thegraph.com/explorer/subgraph/aave/protocol-multy-ropsten-raw - ropsten
https://thegraph.com/explorer/subgraph/aave/protocol-multy-kovan-raw - kovan
https://thegraph.com/explorer/subgraph/aave/protocol-multy-raw - mainnet

_/graphql/_ folder contains graphql documents with the structures needed for aggregation methods.

## Methods description
## Installation

```bash
// with npm
npm install @aave/protocol-js
// with yarn
yarn add @aave/protocol-js
```

## Usage

```formatUserSummaryData(poolReservesData, rawUserReserves, userId, usdPriceEth, currentTimestamp)```
Here is a quick example to get you started:

returns user summary data in big units.
```js
import { v1, v2 } from '@aave/protocol-js';

```computeRawUserSummaryData(poolReservesData, rawUserReserves, userId, usdPriceEth, currentTimestamp)```
// returns user summary data in big units.
v1.formatUserSummaryData(
poolReservesData,
rawUserReserves,
userId,
usdPriceEth,
currentTimestamp
);

returns user summary data in small units with 0 decimal places, except health-factor.
// returns user summary data in small units with 0 decimal places, except health-factor.
v1.computeRawUserSummaryData(
poolReservesData,
rawUserReserves,
userId,
usdPriceEth,
currentTimestamp
);

```formatReserves(reserves)```
// returns reserves data formatted to big units.
v2.formatReserves(reserves, currentTimestamp);
```

returns reserves data formatted to big units.
If you want to use the built-in graphql queries & subscriptions you can find them in `dist/v<1|2>/graphql`.

## Braking changes in v1
* Endpoint addresses should be changed (addresses above)
* Graphql documents should be "recompiled"
* Reserve id not underlying asset address anymore, it's not unique enough because same asset can be in 2 or more pools.
* But reserve has underlyingAssetAddress field

- Endpoint addresses should be changed (addresses above)
- Graphql documents should be "recompiled"
- Reserve id not underlying asset address anymore, it's not unique enough because same asset can be in 2 or more pools.
- But reserve has underlyingAssetAddress field

## Braking changes in v2

- the main entry-point exports v2 methods & graphql queries

```js
// before
import { formatUserSummaryData } from '@aave/protocol-js';

formatUserSummaryData();

// after
import { v1 } from '@aave/protocol-js';

v1.formatUserSummaryData();
```

## TODO
* Extra documentation
* Transactions encoding logic
* React hooks
* Tests

- Extra documentation
- Transactions encoding logic
- React hooks
- Tests
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build && cp -R ./{src,dist}/graphql",
"build": "tsdx build && cp -R ./src/v2/graphql ./dist/graphql && cp -R ./{src,dist}/v1/graphql && cp -R ./{src,dist}/v2/graphql",
"test": "tsdx test",
"test:watch": "tsdx test --watch",
"lint": "tsdx lint",
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { valueToBigNumber } from './bignumber';

export const SECONDS_PER_YEAR = valueToBigNumber('31536000');
export const ETH_DECIMALS = 18;
export const USD_DECIMALS = 10;
export const RAY_DECIMALS = 27;
2 changes: 1 addition & 1 deletion src/helpers/pool-math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
valueToZDBigNumber,
} from './bignumber';
import * as RayMath from './ray-math';
import { SECONDS_PER_YEAR } from './constants';

const SECONDS_PER_YEAR = valueToBigNumber('31536000');
export const LTV_PRECISION = 4;

export function normalize(n: BigNumberValue, decimals: number): string {
Expand Down
17 changes: 14 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import * as v1 from './v1';
import * as v2 from './v2';

// export helpers
export * from './helpers/bignumber';
export { BigNumber } from 'bignumber.js';
export * from './helpers/pool-math';
export * from './types';
export * from './computations-and-formatting';
export * from './helpers/ray-math';

// export current version (v2) as top-level
export * from './v2';

// export v1 and v2 as dedicated entry points
export { v1, v2 };

// reexport bignumber
export { BigNumber } from 'bignumber.js';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReserveData, UserReserveData } from '../types';
import { ReserveData, UserReserveData } from '../../v2/types';
import {
formatReserves,
formatUserSummaryData,
} from '../computations-and-formatting';
} from '../../v2/computations-and-formatting';

const mockReserve: ReserveData = {
underlyingAsset: '0xff795577d9ac8bd7d90ee22b6c1703490b6512fd',
Expand Down
Loading