Skip to content

Commit 2445e95

Browse files
authored
Merge pull request #15 from aave/feat/emode-tests
feat: test E-Mode implications for MarketUserReserveSupplyPosition
2 parents 9ee8f46 + 7675baf commit 2445e95

File tree

5 files changed

+120
-21
lines changed

5 files changed

+120
-21
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:856": "vitest --project client packages/client/src/actions/eMode.test.ts -t 'Then they should be able to disable it at any time'",
2828
"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\"",
29+
"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\"",
2930
"test:withdraw": "vitest --project client packages/client/src/actions/withdraw.test.ts",
3031
"test": "vitest"
3132
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { beforeAll, describe, expect, it } from 'vitest';
99
import {
1010
client,
1111
createNewWallet,
12-
DEFAULT_MARKET_ADDRESS,
1312
ETHEREUM_FORK_ID,
13+
ETHEREUM_MARKET_ADDRESS,
1414
fetchReserve,
1515
fundErc20Address,
1616
WETH_ADDRESS,
@@ -61,7 +61,7 @@ describe('Given an Aave Market', () => {
6161
beforeAll(async () => {
6262
// Set up market info first
6363
const result = await market(client, {
64-
address: DEFAULT_MARKET_ADDRESS,
64+
address: ETHEREUM_MARKET_ADDRESS,
6565
chainId: ETHEREUM_FORK_ID,
6666
});
6767
assertOk(result);

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

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
1-
import { assertOk, evmAddress, never, nonNullable } from '@aave/types';
1+
import {
2+
assertOk,
3+
bigDecimal,
4+
evmAddress,
5+
never,
6+
nonNullable,
7+
} from '@aave/types';
28
import { beforeAll, describe, expect, it } from 'vitest';
39
import {
410
client,
511
createNewWallet,
6-
DEFAULT_MARKET_ADDRESS,
7-
DEFAULT_MARKET_EMODE_CATEGORY,
812
ETHEREUM_FORK_ID,
13+
ETHEREUM_MARKET_ADDRESS,
14+
ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
15+
fundErc20Address,
16+
USDC_ADDRESS,
17+
WETH_ADDRESS,
918
} from '../test-utils';
1019
import { sendWith } from '../viem';
1120
import { market, userMarketState } from './markets';
12-
import { userSetEmode } from './transactions';
21+
import { supply, userSetEmode } from './transactions';
22+
import { userSupplies } from './user';
1323

1424
describe('Given an Aave Market', () => {
15-
const wallet = createNewWallet();
16-
1725
describe('When a user enables an E-Mode category for the given market', () => {
26+
const wallet = createNewWallet();
27+
1828
beforeAll(async () => {
1929
const result = await userSetEmode(client, {
2030
chainId: ETHEREUM_FORK_ID,
21-
market: DEFAULT_MARKET_ADDRESS,
22-
categoryId: DEFAULT_MARKET_EMODE_CATEGORY,
31+
market: ETHEREUM_MARKET_ADDRESS,
32+
categoryId: ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
2333
user: evmAddress(wallet.account!.address),
2434
}).andThen(sendWith(wallet));
2535
assertOk(result);
2636
});
2737

2838
it('Then it should be reflected in their market user state', async () => {
2939
const result = await userMarketState(client, {
30-
market: DEFAULT_MARKET_ADDRESS,
40+
market: ETHEREUM_MARKET_ADDRESS,
3141
chainId: ETHEREUM_FORK_ID,
3242
user: evmAddress(wallet.account!.address),
3343
});
@@ -40,15 +50,16 @@ describe('Given an Aave Market', () => {
4050

4151
it("Then the market's reserves should have user state that reflects the selected E-Mode category settings", async () => {
4252
const result = await market(client, {
43-
address: DEFAULT_MARKET_ADDRESS,
53+
address: ETHEREUM_MARKET_ADDRESS,
4454
chainId: ETHEREUM_FORK_ID,
4555
user: evmAddress(wallet.account!.address),
4656
}).map(nonNullable);
4757
assertOk(result);
4858

4959
const eModeCategory =
5060
result.value?.eModeCategories.find(
51-
(category) => category.id === DEFAULT_MARKET_EMODE_CATEGORY,
61+
(category) =>
62+
category.id === ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
5263
) ?? never('No eMode category found');
5364
for (let i = 0; i < result.value.supplyReserves.length; i++) {
5465
const reserve = result.value.supplyReserves[i] ?? never();
@@ -68,14 +79,14 @@ describe('Given an Aave Market', () => {
6879
it('Then they should be able to disable it at any time', async () => {
6980
const result = await userSetEmode(client, {
7081
chainId: ETHEREUM_FORK_ID,
71-
market: DEFAULT_MARKET_ADDRESS,
82+
market: ETHEREUM_MARKET_ADDRESS,
7283
categoryId: null,
7384
user: evmAddress(wallet.account!.address),
7485
})
7586
.andThen(sendWith(wallet))
7687
.andThen(() =>
7788
userMarketState(client, {
78-
market: DEFAULT_MARKET_ADDRESS,
89+
market: ETHEREUM_MARKET_ADDRESS,
7990
chainId: ETHEREUM_FORK_ID,
8091
user: evmAddress(wallet.account!.address),
8192
}),
@@ -87,4 +98,91 @@ describe('Given an Aave Market', () => {
8798
});
8899
});
89100
});
101+
102+
describe('And the user has some supply positions', () => {
103+
const wallet = createNewWallet();
104+
105+
beforeAll(async () => {
106+
await Promise.all([
107+
fundErc20Address(
108+
USDC_ADDRESS,
109+
evmAddress(wallet.account!.address),
110+
bigDecimal('0.02'),
111+
),
112+
fundErc20Address(
113+
WETH_ADDRESS,
114+
evmAddress(wallet.account!.address),
115+
bigDecimal('0.02'),
116+
),
117+
]);
118+
119+
const result = await supply(client, {
120+
chainId: ETHEREUM_FORK_ID,
121+
market: ETHEREUM_MARKET_ADDRESS,
122+
supplier: evmAddress(wallet.account!.address),
123+
amount: {
124+
erc20: {
125+
currency: USDC_ADDRESS,
126+
value: '0.01',
127+
},
128+
},
129+
})
130+
.andThen(sendWith(wallet))
131+
.andThen(() =>
132+
supply(client, {
133+
chainId: ETHEREUM_FORK_ID,
134+
market: ETHEREUM_MARKET_ADDRESS,
135+
supplier: evmAddress(wallet.account!.address),
136+
amount: {
137+
erc20: {
138+
currency: WETH_ADDRESS,
139+
value: '0.01',
140+
},
141+
},
142+
}),
143+
)
144+
.andThen(sendWith(wallet));
145+
146+
assertOk(result);
147+
});
148+
149+
describe('When the user enables an E-Mode category involving some of the supply positions', () => {
150+
beforeAll(async () => {
151+
const result = await userSetEmode(client, {
152+
chainId: ETHEREUM_FORK_ID,
153+
market: ETHEREUM_MARKET_ADDRESS,
154+
categoryId: ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
155+
user: evmAddress(wallet.account!.address),
156+
}).andThen(sendWith(wallet));
157+
assertOk(result);
158+
});
159+
160+
it('Then any user supply position that are not included in the E-Mode category should not be able to be used as collateral', async () => {
161+
const result = await userSupplies(client, {
162+
markets: [
163+
{ address: ETHEREUM_MARKET_ADDRESS, chainId: ETHEREUM_FORK_ID },
164+
],
165+
user: evmAddress(wallet.account!.address),
166+
});
167+
assertOk(result);
168+
169+
expect(result.value).toMatchObject([
170+
expect.objectContaining({
171+
currency: expect.objectContaining({
172+
address: USDC_ADDRESS,
173+
}),
174+
// USDC is not in the E-Mode category, so it should be false
175+
canBeCollateral: false,
176+
}),
177+
expect.objectContaining({
178+
currency: expect.objectContaining({
179+
address: WETH_ADDRESS,
180+
}),
181+
// WETH is part of ETH-correlated E-Mode category, so it should be true
182+
canBeCollateral: true,
183+
}),
184+
]);
185+
});
186+
});
187+
});
90188
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { describe, expect, it } from 'vitest';
33
import {
44
client,
55
createNewWallet,
6-
DEFAULT_MARKET_ADDRESS,
76
ETHEREUM_FORK_ID,
7+
ETHEREUM_MARKET_ADDRESS,
88
} from '../test-utils';
99
import { market, markets, userMarketState } from './markets';
1010

@@ -34,7 +34,7 @@ describe('Given the Aave Protocol v3', () => {
3434
describe('When fetching a market data for a given address', () => {
3535
it('Then it should be possible to fetch market data for a given market address and chain ID', async () => {
3636
const result = await market(client, {
37-
address: DEFAULT_MARKET_ADDRESS,
37+
address: ETHEREUM_MARKET_ADDRESS,
3838
chainId: ETHEREUM_FORK_ID,
3939
});
4040

@@ -53,7 +53,7 @@ describe('Given the Aave Protocol v3', () => {
5353
describe('When fetching user market state', () => {
5454
it('Then it should be possible to fetch user market state for a given user, market address and chain ID', async () => {
5555
const result = await userMarketState(client, {
56-
market: DEFAULT_MARKET_ADDRESS,
56+
market: ETHEREUM_MARKET_ADDRESS,
5757
chainId: ETHEREUM_FORK_ID,
5858
user: evmAddress(wallet.account!.address),
5959
});

packages/client/src/test-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export const USDC_ADDRESS = evmAddress(
4646
export const DAI_ADDRESS = evmAddress(
4747
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
4848
);
49-
export const DEFAULT_MARKET_ADDRESS = evmAddress(
49+
export const ETHEREUM_MARKET_ADDRESS = evmAddress(
5050
'0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2',
5151
);
52-
export const DEFAULT_MARKET_EMODE_CATEGORY = 1;
52+
export const ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY = 1;
5353

5454
export const ETHEREUM_FORK_RPC_URL =
5555
'https://virtual.mainnet.rpc.tenderly.co/27ff3c60-0e2c-4d46-8190-f5170dc7da8c';
@@ -172,7 +172,7 @@ export async function fetchReserve(
172172
): Promise<Reserve> {
173173
const result = await reserve(client, {
174174
chainId: ETHEREUM_FORK_ID,
175-
market: DEFAULT_MARKET_ADDRESS,
175+
market: ETHEREUM_MARKET_ADDRESS,
176176
underlyingToken: tokenAddress,
177177
user: user,
178178
}).map(nonNullable);

0 commit comments

Comments
 (0)