Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test:vaultDeploy": "vitest --project client packages/client/src/actions/vaultDeploy.test.ts",
"test:856": "vitest --project client packages/client/src/actions/eMode.test.ts -t 'Then they should be able to disable it at any time'",
"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\"",
"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\"",
"test:withdraw": "vitest --project client packages/client/src/actions/withdraw.test.ts",
"test": "vitest"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/actions/borrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { beforeAll, describe, expect, it } from 'vitest';
import {
client,
createNewWallet,
DEFAULT_MARKET_ADDRESS,
ETHEREUM_FORK_ID,
ETHEREUM_MARKET_ADDRESS,
fetchReserve,
fundErc20Address,
WETH_ADDRESS,
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('Given an Aave Market', () => {
beforeAll(async () => {
// Set up market info first
const result = await market(client, {
address: DEFAULT_MARKET_ADDRESS,
address: ETHEREUM_MARKET_ADDRESS,
chainId: ETHEREUM_FORK_ID,
});
assertOk(result);
Expand Down
124 changes: 111 additions & 13 deletions packages/client/src/actions/eMode.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
import { assertOk, evmAddress, never, nonNullable } from '@aave/types';
import {
assertOk,
bigDecimal,
evmAddress,
never,
nonNullable,
} from '@aave/types';
import { beforeAll, describe, expect, it } from 'vitest';
import {
client,
createNewWallet,
DEFAULT_MARKET_ADDRESS,
DEFAULT_MARKET_EMODE_CATEGORY,
ETHEREUM_FORK_ID,
ETHEREUM_MARKET_ADDRESS,
ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
fundErc20Address,
USDC_ADDRESS,
WETH_ADDRESS,
} from '../test-utils';
import { sendWith } from '../viem';
import { market, userMarketState } from './markets';
import { userSetEmode } from './transactions';
import { supply, userSetEmode } from './transactions';
import { userSupplies } from './user';

describe('Given an Aave Market', () => {
const wallet = createNewWallet();

describe('When a user enables an E-Mode category for the given market', () => {
const wallet = createNewWallet();

beforeAll(async () => {
const result = await userSetEmode(client, {
chainId: ETHEREUM_FORK_ID,
market: DEFAULT_MARKET_ADDRESS,
categoryId: DEFAULT_MARKET_EMODE_CATEGORY,
market: ETHEREUM_MARKET_ADDRESS,
categoryId: ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
user: evmAddress(wallet.account!.address),
}).andThen(sendWith(wallet));
assertOk(result);
});

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

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

const eModeCategory =
result.value?.eModeCategories.find(
(category) => category.id === DEFAULT_MARKET_EMODE_CATEGORY,
(category) =>
category.id === ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
) ?? never('No eMode category found');
for (let i = 0; i < result.value.supplyReserves.length; i++) {
const reserve = result.value.supplyReserves[i] ?? never();
Expand All @@ -68,14 +79,14 @@ describe('Given an Aave Market', () => {
it('Then they should be able to disable it at any time', async () => {
const result = await userSetEmode(client, {
chainId: ETHEREUM_FORK_ID,
market: DEFAULT_MARKET_ADDRESS,
market: ETHEREUM_MARKET_ADDRESS,
categoryId: null,
user: evmAddress(wallet.account!.address),
})
.andThen(sendWith(wallet))
.andThen(() =>
userMarketState(client, {
market: DEFAULT_MARKET_ADDRESS,
market: ETHEREUM_MARKET_ADDRESS,
chainId: ETHEREUM_FORK_ID,
user: evmAddress(wallet.account!.address),
}),
Expand All @@ -87,4 +98,91 @@ describe('Given an Aave Market', () => {
});
});
});

describe('And the user has some supply positions', () => {
const wallet = createNewWallet();

beforeAll(async () => {
await Promise.all([
fundErc20Address(
USDC_ADDRESS,
evmAddress(wallet.account!.address),
bigDecimal('0.02'),
),
fundErc20Address(
WETH_ADDRESS,
evmAddress(wallet.account!.address),
bigDecimal('0.02'),
),
]);

const result = await supply(client, {
chainId: ETHEREUM_FORK_ID,
market: ETHEREUM_MARKET_ADDRESS,
supplier: evmAddress(wallet.account!.address),
amount: {
erc20: {
currency: USDC_ADDRESS,
value: '0.01',
},
},
})
.andThen(sendWith(wallet))
.andThen(() =>
supply(client, {
chainId: ETHEREUM_FORK_ID,
market: ETHEREUM_MARKET_ADDRESS,
supplier: evmAddress(wallet.account!.address),
amount: {
erc20: {
currency: WETH_ADDRESS,
value: '0.01',
},
},
}),
)
.andThen(sendWith(wallet));

assertOk(result);
});

describe('When the user enables an E-Mode category involving some of the supply positions', () => {
beforeAll(async () => {
const result = await userSetEmode(client, {
chainId: ETHEREUM_FORK_ID,
market: ETHEREUM_MARKET_ADDRESS,
categoryId: ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY,
user: evmAddress(wallet.account!.address),
}).andThen(sendWith(wallet));
assertOk(result);
});

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 () => {
const result = await userSupplies(client, {
markets: [
{ address: ETHEREUM_MARKET_ADDRESS, chainId: ETHEREUM_FORK_ID },
],
user: evmAddress(wallet.account!.address),
});
assertOk(result);

expect(result.value).toMatchObject([
expect.objectContaining({
currency: expect.objectContaining({
address: USDC_ADDRESS,
}),
// USDC is not in the E-Mode category, so it should be false
canBeCollateral: false,
}),
expect.objectContaining({
currency: expect.objectContaining({
address: WETH_ADDRESS,
}),
// WETH is part of ETH-correlated E-Mode category, so it should be true
canBeCollateral: true,
}),
]);
});
});
});
});
6 changes: 3 additions & 3 deletions packages/client/src/actions/markets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { describe, expect, it } from 'vitest';
import {
client,
createNewWallet,
DEFAULT_MARKET_ADDRESS,
ETHEREUM_FORK_ID,
ETHEREUM_MARKET_ADDRESS,
} from '../test-utils';
import { market, markets, userMarketState } from './markets';

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

Expand All @@ -53,7 +53,7 @@ describe('Given the Aave Protocol v3', () => {
describe('When fetching user market state', () => {
it('Then it should be possible to fetch user market state for a given user, market address and chain ID', async () => {
const result = await userMarketState(client, {
market: DEFAULT_MARKET_ADDRESS,
market: ETHEREUM_MARKET_ADDRESS,
chainId: ETHEREUM_FORK_ID,
user: evmAddress(wallet.account!.address),
});
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export const USDC_ADDRESS = evmAddress(
export const DAI_ADDRESS = evmAddress(
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
);
export const DEFAULT_MARKET_ADDRESS = evmAddress(
export const ETHEREUM_MARKET_ADDRESS = evmAddress(
'0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2',
);
export const DEFAULT_MARKET_EMODE_CATEGORY = 1;
export const ETHEREUM_MARKET_ETH_CORRELATED_EMODE_CATEGORY = 1;

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