Skip to content

Commit d66a378

Browse files
authored
Merge pull request #3 from aave/juan/supply-tests
Test: supply with native and erc20
2 parents 2f1e1da + ce91256 commit d66a378

File tree

16 files changed

+603
-38
lines changed

16 files changed

+603
-38
lines changed

.github/workflows/verify.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ jobs:
1818
- name: Run Biome
1919
run: biome ci .
2020

21-
test:
22-
name: Test
23-
runs-on: ubuntu-latest
21+
- name: Build
22+
uses: ./.github/actions/setup
2423

25-
steps:
26-
- uses: actions/checkout@v4
24+
# test:
25+
# name: Test
26+
# needs: lint
27+
# runs-on: ubuntu-latest
2728

28-
- name: Run Tests
29-
uses: ./.github/actions/tests
30-
with:
31-
environment: 'staging'
32-
private_key: ${{ secrets.PRIVATE_KEY }}
29+
# steps:
30+
# - uses: actions/checkout@v4
31+
32+
# - name: Run Tests
33+
# uses: ./.github/actions/tests
34+
# with:
35+
# environment: 'staging'
36+
# private_key: ${{ secrets.PRIVATE_KEY }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ The project uses [Biome](https://biomejs.dev/) to format and lint the code. You
113113

114114
9. Merge the pull request to the `main` branch.
115115

116-
117116
## Contributing
118117

119118
We welcome contributions to the Aave SDK! If you're interested in contributing, please follow these steps:
119+
120120
1. Fork the repository.
121121
2. Create a new branch for your feature or bug fix.
122122
3. Make your changes and commit them with clear messages.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"new:package": "NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts",
2121
"prepublish": "pnpm run build",
2222
"test:client": "vitest --project client",
23+
"test:client:local": "ENVIRONMENT=local vitest --project client",
2324
"test:react": "vitest --project react",
2425
"test": "vitest"
2526
},

packages/client/src/actions/__snapshots__/markets.test.ts.snap

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`Given the Aave Protocol v3 > When fetching a market data for a given address > Then it should be possible to fetch market data for a given address 1`] = `
4+
{
5+
"__typename": "Market",
6+
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
7+
"borrowReserves": Any<Array>,
8+
"chain": {
9+
"__typename": "Chain",
10+
"chainId": 99999999,
11+
"explorerUrl": "https://dashboard.tenderly.co/explorer/vnet/27ff3c60-0e2c-4d46-8190-f5170dc7da8c",
12+
"icon": "https://statics.aave.com/ethereum.svg",
13+
"name": "Forked Ethereum",
14+
},
15+
"eModeCategories": Any<Array>,
16+
"icon": "https://statics.aave.com/ethereum.svg",
17+
"name": "AaveV3ForkedEthereum",
18+
"supplyReserves": Any<Array>,
19+
"totalAvailableLiquidity": Any<String>,
20+
"totalMarketSize": Any<String>,
21+
"userState": null,
22+
}
23+
`;
24+
325
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 1`] = `
426
{
527
"__typename": "Market",
@@ -65,3 +87,19 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
6587
"userState": null,
6688
}
6789
`;
90+
91+
exports[`Given the Aave Protocol v3 > When fetching user market state > Then it should be possible to fetch user market state for a given user, market address and chain ID 1`] = `
92+
{
93+
"__typename": "MarketUserState",
94+
"availableBorrowsBase": Any<String>,
95+
"currentLiquidationThreshold": Any<String>,
96+
"eModeEnabled": Any<Boolean>,
97+
"healthFactor": Any<String>,
98+
"isInIsolationMode": Any<Boolean>,
99+
"ltv": Any<String>,
100+
"netAPY": Any<String>,
101+
"netWorth": Any<String>,
102+
"totalCollateralBase": Any<String>,
103+
"totalDebtBase": Any<String>,
104+
}
105+
`;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
// THIS IS A VERY WIP
4+
5+
describe('Given an Aave Market', () => {
6+
describe('And a user with a supply position', () => {
7+
describe('When the user enables e-mode for that market', () => {
8+
it('Then it should be possible to borrow from the reserve', () => {
9+
expect(true).toBe(true);
10+
});
11+
});
12+
});
13+
});

packages/client/src/actions/eMode.todo.ts

Whitespace-only changes.

packages/client/src/actions/markets.test.ts

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { assertOk, chainId } from '@aave/types';
1+
import { assertOk, chainId, evmAddress } from '@aave/types';
22
import { describe, expect, it } from 'vitest';
3-
import { client } from '../test-utils';
4-
import { markets } from './markets';
3+
import {
4+
client,
5+
DEFAULT_MARKET_ADDRESS,
6+
ETHEREUM_FORK_ID,
7+
wallet,
8+
} from '../test-utils';
9+
import { market, markets, userMarketState } from './markets';
510

611
describe('Given the Aave Protocol v3', () => {
712
describe('When fetching markets data', () => {
@@ -23,4 +28,47 @@ describe('Given the Aave Protocol v3', () => {
2328
});
2429
});
2530
});
31+
32+
describe('When fetching a market data for a given address', () => {
33+
it('Then it should be possible to fetch market data for a given market address and chain ID', async () => {
34+
const result = await market(client, {
35+
address: DEFAULT_MARKET_ADDRESS,
36+
chainId: ETHEREUM_FORK_ID,
37+
});
38+
39+
assertOk(result);
40+
41+
expect(result.value).toMatchSnapshot({
42+
totalAvailableLiquidity: expect.any(String),
43+
totalMarketSize: expect.any(String),
44+
borrowReserves: expect.any(Array),
45+
supplyReserves: expect.any(Array),
46+
eModeCategories: expect.any(Array),
47+
});
48+
});
49+
});
50+
51+
describe('When fetching user market state', () => {
52+
it('Then it should be possible to fetch user market state for a given user, market address and chain ID', async () => {
53+
const result = await userMarketState(client, {
54+
market: DEFAULT_MARKET_ADDRESS,
55+
chainId: ETHEREUM_FORK_ID,
56+
user: evmAddress(wallet.account!.address),
57+
});
58+
59+
assertOk(result);
60+
expect(result.value).toMatchSnapshot({
61+
availableBorrowsBase: expect.any(String),
62+
currentLiquidationThreshold: expect.any(String),
63+
eModeEnabled: expect.any(Boolean),
64+
healthFactor: expect.any(String),
65+
isInIsolationMode: expect.any(Boolean),
66+
ltv: expect.any(String),
67+
netAPY: expect.any(String),
68+
netWorth: expect.any(String),
69+
totalCollateralBase: expect.any(String),
70+
totalDebtBase: expect.any(String),
71+
});
72+
});
73+
});
2674
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('Given an Aave Market', () => {
4+
describe('And a user with a borrow position', () => {
5+
describe('When the user repays their loan', () => {
6+
it('Then it should be reflected in the user borrow positions', () => {
7+
expect(true).toBe(true);
8+
});
9+
});
10+
11+
describe('And the reserve allows repaying in native tokens', () => {
12+
describe('When the user repays their loan in native tokens', () => {
13+
it('Then it should be reflected in the user borrow positions', () => {
14+
expect(true).toBe(true);
15+
});
16+
});
17+
});
18+
});
19+
});
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import type { Reserve } from '@aave/graphql';
2+
import { assertOk, bigDecimal, evmAddress } from '@aave/types';
3+
import { beforeAll, describe, expect, it } from 'vitest';
4+
import {
5+
client,
6+
createNewWallet,
7+
fetchReserve,
8+
fundErc20Address,
9+
fundNativeAddress,
10+
WETH_ADDRESS,
11+
} from '../test-utils';
12+
import { sendWith } from '../viem';
13+
import { supply } from './transactions';
14+
import { userSupplies } from './user';
15+
16+
describe('Given an Aave Market', () => {
17+
describe('When the user supplies tokens to a Reserve', () => {
18+
const wallet = createNewWallet();
19+
const amountToSupply = '0.01';
20+
let reserveInfo: Reserve;
21+
22+
beforeAll(async () => {
23+
await fundErc20Address(
24+
WETH_ADDRESS,
25+
evmAddress(wallet.account!.address),
26+
bigDecimal('0.02'),
27+
);
28+
29+
reserveInfo = await fetchReserve(WETH_ADDRESS);
30+
// Check if the reserve is not frozen or paused
31+
expect(reserveInfo.isFrozen).toBe(false);
32+
expect(reserveInfo.isPaused).toBe(false);
33+
});
34+
35+
it(`Then it should be available in the user's supply positions`, async () => {
36+
const result = await supply(client, {
37+
market: reserveInfo.market.address,
38+
supplier: evmAddress(wallet.account!.address),
39+
amount: {
40+
erc20: {
41+
value: amountToSupply,
42+
currency: WETH_ADDRESS,
43+
},
44+
},
45+
chainId: reserveInfo.market.chain.chainId,
46+
})
47+
.andThen(sendWith(wallet))
48+
.andThen(() =>
49+
userSupplies(client, {
50+
markets: [
51+
{
52+
address: reserveInfo.market.address,
53+
chainId: reserveInfo.market.chain.chainId,
54+
},
55+
],
56+
user: evmAddress(wallet.account!.address),
57+
}),
58+
);
59+
assertOk(result);
60+
expect(result.value).toEqual([
61+
expect.objectContaining({
62+
balance: expect.objectContaining({
63+
amount: expect.objectContaining({
64+
value: expect.toBeBigDecimalCloseTo(amountToSupply),
65+
}),
66+
}),
67+
}),
68+
]);
69+
}, 25_000);
70+
});
71+
72+
describe('And the Reserve allows to supply in native tokens', () => {
73+
let reserveInfo: Reserve;
74+
75+
beforeAll(async () => {
76+
reserveInfo = await fetchReserve(WETH_ADDRESS);
77+
// Check if the reserve is not frozen or paused
78+
expect(reserveInfo.isFrozen).toBe(false);
79+
expect(reserveInfo.isPaused).toBe(false);
80+
// And accepts native tokens
81+
expect(reserveInfo.acceptsNative?.symbol).toEqual('ETH');
82+
});
83+
84+
describe('When the user supplies to the reserve in native tokens', () => {
85+
const wallet = createNewWallet();
86+
const amountToSupply = '0.01';
87+
88+
beforeAll(async () => {
89+
await fundNativeAddress(
90+
evmAddress(wallet.account!.address),
91+
bigDecimal('0.02'),
92+
);
93+
});
94+
95+
it(`Then it should be available in the user's supply positions`, async () => {
96+
const result = await supply(client, {
97+
market: reserveInfo.market.address,
98+
supplier: evmAddress(wallet.account!.address),
99+
amount: {
100+
native: amountToSupply,
101+
},
102+
chainId: reserveInfo.market.chain.chainId,
103+
})
104+
.andThen(sendWith(wallet))
105+
.andThen(() =>
106+
userSupplies(client, {
107+
markets: [
108+
{
109+
address: reserveInfo.market.address,
110+
chainId: reserveInfo.market.chain.chainId,
111+
},
112+
],
113+
user: evmAddress(wallet.account!.address),
114+
}),
115+
);
116+
assertOk(result);
117+
expect(result.value).toEqual([
118+
expect.objectContaining({
119+
balance: expect.objectContaining({
120+
amount: expect.objectContaining({
121+
value: expect.toBeBigDecimalCloseTo(amountToSupply),
122+
}),
123+
}),
124+
}),
125+
]);
126+
}, 25_000);
127+
});
128+
});
129+
});

packages/client/src/actions/user.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ export function userBorrows(
5656
}
5757

5858
/**
59-
* Fetches the user's transaction history.
59+
* Fetches the user's transaction history for a given market.
6060
*
6161
* ```ts
62-
* const result = await userTransactionHistory(client);
62+
* const result = await userTransactionHistory(client, {
63+
* chainId: chainId(1),
64+
* market: evmAddress('0x87870bca…'),
65+
* user: evmAddress('0x742d35cc…'),
66+
* });
6367
* ```
6468
*
6569
* @param client - Aave client.
70+
* @param request - The user transaction history request parameters.
6671
* @returns The user's paginated transaction history.
6772
*/
6873
export function userTransactionHistory(

0 commit comments

Comments
 (0)