Skip to content

Commit 7f69874

Browse files
committed
feat: adds test for supply APY values
1 parent a54f90f commit 7f69874

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

package.json

Lines changed: 1 addition & 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
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports[`Given the Aave Protocol v3 > When fetching a single market > Then it sh
2222
}
2323
`;
2424
25-
exports[`Given the Aave Protocol v3 > When fetching markets across one or more chains > Then it should return the expected data for each market 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",
2828
"address": "0x0AA97c284e98396202b6A04024F5E2c65026F3c0",
@@ -44,7 +44,7 @@ exports[`Given the Aave Protocol v3 > When fetching markets across one or more c
4444
}
4545
`;
4646
47-
exports[`Given the Aave Protocol v3 > When fetching markets across one or more chains > Then it should return the expected data for each market 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",
5050
"address": "0x4e033931ad43597d96D6bcc25c280717730B58B1",
@@ -66,7 +66,7 @@ exports[`Given the Aave Protocol v3 > When fetching markets across one or more c
6666
}
6767
`;
6868
69-
exports[`Given the Aave Protocol v3 > When fetching markets across one or more chains > Then it should return the expected data for each market 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",
7272
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",

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

Lines changed: 39 additions & 2 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,7 +12,7 @@ import { market, markets, userMarketState } from './markets';
1112
describe('Given the Aave Protocol v3', () => {
1213
const wallet = createNewWallet();
1314

14-
describe('When fetching markets across one or more chains', () => {
15+
describe('When fetching markets by chain ID(s)', () => {
1516
it('Then it should return the expected data for each market', async () => {
1617
const result = await markets(client, {
1718
chainIds: [chainId(1)],
@@ -48,6 +49,42 @@ 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

5390
describe('When fetching user market state for a new user', () => {

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)