@@ -11,12 +11,14 @@ import {
1111 createNewWallet ,
1212 DEFAULT_MARKET_ADDRESS ,
1313 ETHEREUM_FORK_ID ,
14+ fetchReserve ,
1415 fundErc20Address ,
16+ wait ,
1517 WETH_ADDRESS ,
1618} from '../test-utils' ;
1719import { sendWith } from '../viem' ;
1820import { market } from './markets' ;
19- import { borrow , collateralToggle , supply } from './transactions' ;
21+ import { borrow , supply } from './transactions' ;
2022import { userBorrows , userSupplies } from './user' ;
2123
2224async function supplyAndCheck (
@@ -45,6 +47,7 @@ async function supplyAndCheck(
4547 } ) ,
4648 } ) ,
4749 // Check if the position can be used as collateral
50+ isCollateral : true ,
4851 canBeCollateral : true ,
4952 } ) ,
5053 ] ) ;
@@ -53,7 +56,6 @@ async function supplyAndCheck(
5356
5457describe ( 'Given an Aave Market' , ( ) => {
5558 let marketInfo : Market ;
56- let initialPosition : MarketUserReserveSupplyPosition | undefined ;
5759
5860 const wallet : WalletClient = createNewWallet ( ) ;
5961
@@ -72,7 +74,8 @@ describe('Given an Aave Market', () => {
7274 evmAddress ( wallet . account ! . address ) ,
7375 bigDecimal ( '0.011' ) ,
7476 ) ;
75- const supplyResult = await supplyAndCheck ( wallet , {
77+
78+ await supplyAndCheck ( wallet , {
7679 market : marketInfo . address ,
7780 chainId : marketInfo . chain . chainId ,
7881 supplier : evmAddress ( wallet . account ! . address ) ,
@@ -83,56 +86,27 @@ describe('Given an Aave Market', () => {
8386 } ,
8487 } ,
8588 } ) ;
86- initialPosition = supplyResult [ 0 ] ;
8789 } ) ;
8890
8991 describe ( 'And a user with a supply position' , ( ) => {
9092 describe ( 'When user set the supply as collateral' , async ( ) => {
9193 it ( 'Then it should be possible to borrow from the reserve' , async ( ) => {
92- // Enable collateral
93- const result = await collateralToggle ( client , {
94- market : initialPosition ! . market . address ,
95- underlyingToken : initialPosition ! . currency . address ,
96- chainId : initialPosition ! . market . chain . chainId ,
97- user : evmAddress ( wallet . account ! . address ) ,
98- } )
99- . andThen ( sendWith ( wallet ) )
100- . andTee ( ( tx ) => console . log ( `tx to enable collateral: ${ tx } ` ) )
101- . andThen ( ( ) => {
102- return userSupplies ( client , {
103- markets : [
104- {
105- address : initialPosition ! . market . address ,
106- chainId : initialPosition ! . market . chain . chainId ,
107- } ,
108- ] ,
109- user : evmAddress ( wallet . account ! . address ) ,
110- } ) ;
111- } ) ;
112- assertOk ( result ) ;
113- expect ( result . value ) . toEqual ( [
114- expect . objectContaining ( {
115- isCollateral : true ,
116- } ) ,
117- ] ) ;
118-
11994 // Borrow from the reserve
120- const borrowReserve = marketInfo . borrowReserves . find (
121- ( reserve ) => reserve . underlyingToken . symbol === 'USDC' ,
122- ) ! ;
95+ const borrowReserve = await fetchReserve ( WETH_ADDRESS , evmAddress ( wallet . account ! . address ) ) ;
12396 const borrowResult = await borrow ( client , {
12497 market : marketInfo . address ,
12598 chainId : marketInfo . chain . chainId ,
12699 borrower : evmAddress ( wallet . account ! . address ) ,
127100 amount : {
128101 erc20 : {
129102 currency : borrowReserve . underlyingToken . address ,
130- value : '10' ,
103+ value : borrowReserve . userState ! . borrowable . amount . value ,
131104 } ,
132105 } ,
133106 } )
134107 . andThen ( sendWith ( wallet ) )
135108 . andTee ( ( tx ) => console . log ( `tx to borrow: ${ tx } ` ) )
109+ . andTee ( ( ) => wait ( 5000 ) )
136110 . andThen ( ( ) =>
137111 userBorrows ( client , {
138112 markets : [
@@ -145,7 +119,7 @@ describe('Given an Aave Market', () => {
145119 } ) ,
146120 ) ;
147121 assertOk ( borrowResult ) ;
148- } ) ;
122+ } , 25_000 ) ;
149123 } ) ;
150124 } ) ;
151125} ) ;
0 commit comments