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' ;
28import { beforeAll , describe , expect , it } from 'vitest' ;
39import {
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' ;
1019import { sendWith } from '../viem' ;
1120import { market , userMarketState } from './markets' ;
12- import { userSetEmode } from './transactions' ;
21+ import { supply , userSetEmode } from './transactions' ;
22+ import { userSupplies } from './user' ;
1323
1424describe ( '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} ) ;
0 commit comments