Skip to content

Commit 60feca3

Browse files
authored
Merge branch 'main' into feat/emode-tests
2 parents 7bfe820 + 23885c8 commit 60feca3

File tree

6 files changed

+341
-99
lines changed

6 files changed

+341
-99
lines changed

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

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
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-
253
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`] = `
264
{
275
"__typename": "Market",
@@ -47,7 +25,7 @@ exports[`Given the Aave Protocol v3 > When fetching a market data for a given ad
4725
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 1`] = `
4826
{
4927
"__typename": "Market",
50-
"address": "0x0AA97c284e98396202b6A04024F5E2c65026F3c0",
28+
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
5129
"borrowReserves": Any<Array>,
5230
"chain": {
5331
"__typename": "Chain",
@@ -58,7 +36,7 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
5836
},
5937
"eModeCategories": Any<Array>,
6038
"icon": "https://statics.aave.com/ethereum.svg",
61-
"name": "AaveV3EthereumEtherFi",
39+
"name": "AaveV3Ethereum",
6240
"supplyReserves": Any<Array>,
6341
"totalAvailableLiquidity": Any<String>,
6442
"totalMarketSize": Any<String>,
@@ -69,7 +47,7 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
6947
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 2`] = `
7048
{
7149
"__typename": "Market",
72-
"address": "0x4e033931ad43597d96D6bcc25c280717730B58B1",
50+
"address": "0x0AA97c284e98396202b6A04024F5E2c65026F3c0",
7351
"borrowReserves": Any<Array>,
7452
"chain": {
7553
"__typename": "Chain",
@@ -80,7 +58,7 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
8058
},
8159
"eModeCategories": Any<Array>,
8260
"icon": "https://statics.aave.com/ethereum.svg",
83-
"name": "AaveV3EthereumLido",
61+
"name": "AaveV3EthereumEtherFi",
8462
"supplyReserves": Any<Array>,
8563
"totalAvailableLiquidity": Any<String>,
8664
"totalMarketSize": Any<String>,
@@ -91,7 +69,7 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
9169
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 3`] = `
9270
{
9371
"__typename": "Market",
94-
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
72+
"address": "0x4e033931ad43597d96D6bcc25c280717730B58B1",
9573
"borrowReserves": Any<Array>,
9674
"chain": {
9775
"__typename": "Chain",
@@ -102,7 +80,7 @@ exports[`Given the Aave Protocol v3 > When fetching markets data > Then it shoul
10280
},
10381
"eModeCategories": Any<Array>,
10482
"icon": "https://statics.aave.com/ethereum.svg",
105-
"name": "AaveV3Ethereum",
83+
"name": "AaveV3EthereumLido",
10684
"supplyReserves": Any<Array>,
10785
"totalAvailableLiquidity": Any<String>,
10886
"totalMarketSize": Any<String>,

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

Lines changed: 87 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import {
1313
ETHEREUM_MARKET_ADDRESS,
1414
fetchReserve,
1515
fundErc20Address,
16+
fundNativeAddress,
1617
WETH_ADDRESS,
1718
wait,
1819
} from '../test-utils';
1920
import { sendWith } from '../viem';
2021
import { market } from './markets';
21-
import { borrow, collateralToggle, supply } from './transactions';
22+
import { borrow, supply } from './transactions';
2223
import { userBorrows, userSupplies } from './user';
2324

2425
async function supplyAndCheck(
@@ -55,30 +56,31 @@ async function supplyAndCheck(
5556
}
5657

5758
describe('Given an Aave Market', () => {
58-
let marketInfo: Market;
59-
const wallet: WalletClient = createNewWallet();
59+
describe('And a user with a supply position', () => {
60+
describe('When the user set the supply as collateral', async () => {
61+
let marketInfo: Market;
62+
const wallet: WalletClient = createNewWallet();
6063

61-
beforeAll(async () => {
62-
// Set up market info first
63-
const result = await market(client, {
64-
address: ETHEREUM_MARKET_ADDRESS,
65-
chainId: ETHEREUM_FORK_ID,
66-
});
67-
assertOk(result);
68-
marketInfo = result.value!;
64+
beforeAll(async () => {
65+
// Set up market info first
66+
const result = await market(client, {
67+
address: ETHEREUM_MARKET_ADDRESS,
68+
chainId: ETHEREUM_FORK_ID,
69+
});
70+
assertOk(result);
71+
marketInfo = result.value!;
6972

70-
// Set up wallet and supply position
71-
await fundErc20Address(
72-
WETH_ADDRESS,
73-
evmAddress(wallet.account!.address),
74-
bigDecimal('0.011'),
75-
);
76-
});
73+
// Set up wallet and supply position
74+
await fundErc20Address(
75+
WETH_ADDRESS,
76+
evmAddress(wallet.account!.address),
77+
bigDecimal('0.011'),
78+
);
79+
});
7780

78-
describe('And a user with a supply position', () => {
79-
describe('When user set the supply as collateral', async () => {
80-
it('Then it should be possible to borrow from the reserve', async () => {
81-
const supplyResult = await supplyAndCheck(wallet, {
81+
it('Then it should be possible to borrow ERC20 from the reserve', async () => {
82+
// NOTE: first time supply is set as collateral automatically
83+
await supplyAndCheck(wallet, {
8284
market: marketInfo.address,
8385
chainId: marketInfo.chain.chainId,
8486
supplier: evmAddress(wallet.account!.address),
@@ -90,35 +92,6 @@ describe('Given an Aave Market', () => {
9092
},
9193
});
9294

93-
if (!supplyResult[0]!.isCollateral) {
94-
// Enable collateral
95-
const result = await collateralToggle(client, {
96-
market: marketInfo.address,
97-
underlyingToken: WETH_ADDRESS,
98-
chainId: marketInfo.chain.chainId,
99-
user: evmAddress(wallet.account!.address),
100-
})
101-
.andThen(sendWith(wallet))
102-
.andTee((tx) => console.log(`tx to enable collateral: ${tx}`))
103-
.andThen(() => {
104-
return userSupplies(client, {
105-
markets: [
106-
{
107-
address: marketInfo.address,
108-
chainId: marketInfo.chain.chainId,
109-
},
110-
],
111-
user: evmAddress(wallet.account!.address),
112-
});
113-
});
114-
assertOk(result);
115-
expect(result.value).toEqual([
116-
expect.objectContaining({
117-
isCollateral: true,
118-
}),
119-
]);
120-
}
121-
12295
// Borrow from the reserve
12396
const borrowReserve = await fetchReserve(
12497
WETH_ADDRESS,
@@ -153,5 +126,68 @@ describe('Given an Aave Market', () => {
153126
expect(borrowResult.value.length).toBe(1);
154127
}, 25_000);
155128
});
129+
130+
describe('When the user set the supply as collateral', async () => {
131+
let marketInfo: Market;
132+
const wallet: WalletClient = createNewWallet();
133+
134+
beforeAll(async () => {
135+
// Set up market info first
136+
const result = await market(client, {
137+
address: ETHEREUM_MARKET_ADDRESS,
138+
chainId: ETHEREUM_FORK_ID,
139+
});
140+
assertOk(result);
141+
marketInfo = result.value!;
142+
143+
// Set up wallet and supply position
144+
await fundNativeAddress(
145+
evmAddress(wallet.account!.address),
146+
bigDecimal('0.2'),
147+
);
148+
});
149+
150+
it('Then it should be possible to borrow native from the reserve', async () => {
151+
// NOTE: first time supply is set as collateral automatically
152+
await supplyAndCheck(wallet, {
153+
market: marketInfo.address,
154+
chainId: marketInfo.chain.chainId,
155+
supplier: evmAddress(wallet.account!.address),
156+
amount: {
157+
native: '0.1',
158+
},
159+
});
160+
161+
// Borrow from the reserve
162+
const borrowReserve = await fetchReserve(
163+
WETH_ADDRESS,
164+
evmAddress(wallet.account!.address),
165+
);
166+
const borrowResult = await borrow(client, {
167+
market: marketInfo.address,
168+
chainId: marketInfo.chain.chainId,
169+
borrower: evmAddress(wallet.account!.address),
170+
amount: {
171+
native: borrowReserve.userState!.borrowable.amount.value,
172+
},
173+
})
174+
.andThen(sendWith(wallet))
175+
.andTee((tx) => console.log(`tx to borrow: ${tx}`))
176+
.andTee(() => wait(5000))
177+
.andThen(() =>
178+
userBorrows(client, {
179+
markets: [
180+
{
181+
address: marketInfo.address,
182+
chainId: marketInfo.chain.chainId,
183+
},
184+
],
185+
user: evmAddress(wallet.account!.address),
186+
}),
187+
);
188+
assertOk(borrowResult);
189+
expect(borrowResult.value.length).toBe(1);
190+
}, 25_000);
191+
});
156192
});
157193
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { assertOk, bigDecimal, evmAddress } from '@aave/types';
2+
import { beforeAll, describe, expect, it } from 'vitest';
3+
4+
import {
5+
client,
6+
createNewWallet,
7+
ETHEREUM_FORK_ID,
8+
ETHEREUM_MARKET_ADDRESS,
9+
fundErc20Address,
10+
WETH_ADDRESS,
11+
wait,
12+
} from '../test-utils';
13+
import { sendWith } from '../viem';
14+
import { collateralToggle, supply } from './transactions';
15+
import { userSupplies } from './user';
16+
17+
describe('Given Aave Market', () => {
18+
describe('And a user with a supply position', () => {
19+
describe('When the user toggles the position as collateral', () => {
20+
const wallet = createNewWallet();
21+
22+
beforeAll(async () => {
23+
await fundErc20Address(
24+
WETH_ADDRESS,
25+
evmAddress(wallet.account!.address),
26+
bigDecimal('0.02'),
27+
);
28+
29+
const result = await supply(client, {
30+
market: ETHEREUM_MARKET_ADDRESS,
31+
chainId: ETHEREUM_FORK_ID,
32+
supplier: evmAddress(wallet.account!.address),
33+
amount: { erc20: { currency: WETH_ADDRESS, value: '0.01' } },
34+
}).andThen(sendWith(wallet));
35+
assertOk(result);
36+
});
37+
38+
it('Then it should be reflected in the user supply positions', async () => {
39+
const userSuppliesBefore = await userSupplies(client, {
40+
markets: [
41+
{ address: ETHEREUM_MARKET_ADDRESS, chainId: ETHEREUM_FORK_ID },
42+
],
43+
user: evmAddress(wallet.account!.address),
44+
});
45+
assertOk(userSuppliesBefore);
46+
expect(userSuppliesBefore.value.length).toBe(1);
47+
48+
// Toggle collateral
49+
const result = await collateralToggle(client, {
50+
market: ETHEREUM_MARKET_ADDRESS,
51+
chainId: ETHEREUM_FORK_ID,
52+
user: evmAddress(wallet.account!.address),
53+
underlyingToken: WETH_ADDRESS,
54+
})
55+
.andThen(sendWith(wallet))
56+
.andTee((tx) => console.log(`tx to toggle collateral: ${tx}`))
57+
.andTee(() => wait(1000));
58+
assertOk(result);
59+
60+
const userSuppliesAfter = await userSupplies(client, {
61+
markets: [
62+
{ address: ETHEREUM_MARKET_ADDRESS, chainId: ETHEREUM_FORK_ID },
63+
],
64+
user: evmAddress(wallet.account!.address),
65+
});
66+
assertOk(userSuppliesAfter);
67+
expect(userSuppliesAfter.value.length).toBe(1);
68+
69+
expect(userSuppliesAfter.value[0]?.isCollateral).toEqual(
70+
!userSuppliesBefore.value[0]?.isCollateral,
71+
);
72+
});
73+
});
74+
});
75+
});

0 commit comments

Comments
 (0)