Skip to content

Commit 0aae67f

Browse files
authored
Merge pull request #21 from aave/feat/market-math-tests
feat: market math tests
2 parents f964b2a + 803f7d7 commit 0aae67f

File tree

5 files changed

+119
-21
lines changed

5 files changed

+119
-21
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"test:vaultDeploy": "vitest --project client packages/client/src/actions/vaultDeploy.test.ts",
2727
"test:857": "vitest --project client packages/client/src/actions/eMode.test.ts -t \"Then the market's reserves should have user state that reflects the selected E-Mode category settings\"",
2828
"test:858": "vitest --project client packages/client/src/actions/eMode.test.ts -t \"Then any user supply position that are not included in the E-Mode category should not be able to be used as collateral\"",
29+
"test:867": "vitest --project client packages/client/src/actions/markets.test.ts -t \"Then it should return supply reserves APYs in the expected order of magnitude\"",
2930
"test:withdraw": "vitest --project client packages/client/src/actions/withdraw.test.ts",
3031
"test": "vitest"
3132
},
@@ -34,6 +35,7 @@
3435
"@biomejs/biome": "^2.0.6",
3536
"@changesets/cli": "^2.29.5",
3637
"@types/node": "^24.0.7",
38+
"@vitest/ui": "^3.2.4",
3739
"jest-extended": "^6.0.0",
3840
"plop": "^4.0.1",
3941
"rimraf": "^6.0.1",

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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 market address and chain ID 1`] = `
3+
exports[`Given the Aave Protocol v3 > When fetching a single market > Then it should return the expected data for the market 1`] = `
44
{
55
"__typename": "Market",
66
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
@@ -22,10 +22,10 @@ exports[`Given the Aave Protocol v3 > When fetching a market data for a given ad
2222
}
2323
`;
2424
25-
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 1`] = `
25+
exports[`Given the Aave Protocol v3 > When fetching markets by chain ID(s) > Then it should return the expected data for each market 1`] = `
2626
{
2727
"__typename": "Market",
28-
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
28+
"address": "0x0AA97c284e98396202b6A04024F5E2c65026F3c0",
2929
"borrowReserves": Any<Array>,
3030
"chain": {
3131
"__typename": "Chain",
@@ -36,18 +36,18 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
3636
},
3737
"eModeCategories": Any<Array>,
3838
"icon": "https://statics.aave.com/ethereum.svg",
39-
"name": "AaveV3Ethereum",
39+
"name": "AaveV3EthereumEtherFi",
4040
"supplyReserves": Any<Array>,
4141
"totalAvailableLiquidity": Any<String>,
4242
"totalMarketSize": Any<String>,
4343
"userState": null,
4444
}
4545
`;
4646
47-
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 2`] = `
47+
exports[`Given the Aave Protocol v3 > When fetching markets by chain ID(s) > Then it should return the expected data for each market 2`] = `
4848
{
4949
"__typename": "Market",
50-
"address": "0x0AA97c284e98396202b6A04024F5E2c65026F3c0",
50+
"address": "0x4e033931ad43597d96D6bcc25c280717730B58B1",
5151
"borrowReserves": Any<Array>,
5252
"chain": {
5353
"__typename": "Chain",
@@ -58,18 +58,18 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
5858
},
5959
"eModeCategories": Any<Array>,
6060
"icon": "https://statics.aave.com/ethereum.svg",
61-
"name": "AaveV3EthereumEtherFi",
61+
"name": "AaveV3EthereumLido",
6262
"supplyReserves": Any<Array>,
6363
"totalAvailableLiquidity": Any<String>,
6464
"totalMarketSize": Any<String>,
6565
"userState": null,
6666
}
6767
`;
6868
69-
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 3`] = `
69+
exports[`Given the Aave Protocol v3 > When fetching markets by chain ID(s) > Then it should return the expected data for each market 3`] = `
7070
{
7171
"__typename": "Market",
72-
"address": "0x4e033931ad43597d96D6bcc25c280717730B58B1",
72+
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
7373
"borrowReserves": Any<Array>,
7474
"chain": {
7575
"__typename": "Chain",
@@ -80,15 +80,15 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
8080
},
8181
"eModeCategories": Any<Array>,
8282
"icon": "https://statics.aave.com/ethereum.svg",
83-
"name": "AaveV3EthereumLido",
83+
"name": "AaveV3Ethereum",
8484
"supplyReserves": Any<Array>,
8585
"totalAvailableLiquidity": Any<String>,
8686
"totalMarketSize": Any<String>,
8787
"userState": null,
8888
}
8989
`;
9090
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`] = `
91+
exports[`Given the Aave Protocol v3 > When fetching user market state for a new user > Then it should return the expected data for a user that has never interacted with the market 1`] = `
9292
{
9393
"__typename": "MarketUserState",
9494
"availableBorrowsBase": Any<String>,

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { assertOk, chainId, evmAddress } from '@aave/types';
1+
import { OrderDirection } from '@aave/graphql';
2+
import { assertOk, chainId, evmAddress, nonNullable } from '@aave/types';
23
import { describe, expect, it } from 'vitest';
34
import {
45
client,
@@ -11,8 +12,8 @@ import { market, markets, userMarketState } from './markets';
1112
describe('Given the Aave Protocol v3', () => {
1213
const wallet = createNewWallet();
1314

14-
describe('When fetching markets data', () => {
15-
it('Then it should be possible to fetch markets for a given chain ID', async () => {
15+
describe('When fetching markets by chain ID(s)', () => {
16+
it('Then it should return the expected data for each market', async () => {
1617
const result = await markets(client, {
1718
chainIds: [chainId(1)],
1819
});
@@ -31,8 +32,8 @@ describe('Given the Aave Protocol v3', () => {
3132
});
3233
});
3334

34-
describe('When fetching a market data for a given address', () => {
35-
it('Then it should be possible to fetch market data for a given market address and chain ID', async () => {
35+
describe('When fetching a single market', () => {
36+
it('Then it should return the expected data for the market', async () => {
3637
const result = await market(client, {
3738
address: ETHEREUM_MARKET_ADDRESS,
3839
chainId: ETHEREUM_FORK_ID,
@@ -48,10 +49,46 @@ describe('Given the Aave Protocol v3', () => {
4849
eModeCategories: expect.any(Array),
4950
});
5051
});
52+
53+
it('Then it should return supply reserves APYs in the expected order of magnitude', async () => {
54+
const result = await market(client, {
55+
address: ETHEREUM_MARKET_ADDRESS,
56+
chainId: ETHEREUM_FORK_ID,
57+
suppliesOrderBy: {
58+
supplyApy: OrderDirection.Desc,
59+
},
60+
}).map(nonNullable);
61+
62+
assertOk(result);
63+
64+
expect(
65+
result.value.supplyReserves.map((r) => ({
66+
token: r.underlyingToken.symbol,
67+
apy: r.supplyInfo.apy.value,
68+
})),
69+
).toEqual([
70+
{
71+
token: 'WETH',
72+
apy: expect.toBeBigDecimalCloseTo('4', 0), // ~4% APY at the time of the Tenderly fork
73+
},
74+
75+
{
76+
token: 'USDC',
77+
apy: expect.toBeBigDecimalCloseTo('3', 0), // ~3% APY at the time of the Tenderly fork
78+
},
79+
80+
{
81+
token: 'USDS',
82+
apy: expect.toBeBigDecimalCloseTo('3', 0), // ~3% APY at the time of the Tenderly fork
83+
},
84+
85+
...new Array(46).fill(expect.any(Object)),
86+
]);
87+
});
5188
});
5289

53-
describe('When fetching user market state', () => {
54-
it('Then it should be possible to fetch user market state for a given user, market address and chain ID', async () => {
90+
describe('When fetching user market state for a new user', () => {
91+
it('Then it should return the expected data for a user that has never interacted with the market', async () => {
5592
const result = await userMarketState(client, {
5693
market: ETHEREUM_MARKET_ADDRESS,
5794
chainId: ETHEREUM_FORK_ID,

pnpm-lock.yaml

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'vitest';
22

33
declare module 'vitest' {
4-
interface AsymmetricMatchersContaining extends JestExtendedMatchers {}
4+
interface AsymmetricMatchersContaining extends JestExtendedMatchers {
5+
toBeBigDecimalCloseTo: (expected: number | string, precision?: number) => R;
6+
}
57
}

0 commit comments

Comments
 (0)