You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to work with aave V3 but I'm stack on the borrowing section.
My code runs very well but when the borrowing sections reached, the transaction got reverted with error '31'
Here is my code:
const{ formatUnits }=require("ethers")const{ getNamedAccounts, ethers }=require("hardhat")const{ getWeth,AMOUNT}=require("../scripts/getWeth")asyncfunctionmain(){// the protocol treats everything as ERC20 tokenawaitgetWeth()const{deployer}=awaitgetNamedAccounts()// Pool Address Provider : 0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9econstpool=awaitgetPool(deployer)console.log(`Pool Address : ${pool.address}`)// deposit!constwethTokenAddress="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"// approve!awaitapproveERC20(wethTokenAddress,pool.address,AMOUNT,deployer)console.log("Depositing...")awaitpool.deposit(wethTokenAddress,AMOUNT,deployer,0)console.log("Deposited!");let{ availableBorrowsBase, totalDebtBase }=awaitgetBorrowUserData(pool,deployer)// borrow// how much we have borrowed, how much we have in collateral, how much we can borrow// // what is the conversion rate on DAIconstdaiPrice=awaitgetDaiPrice()constdaiAmount=awaitgetEthPrice(availableBorrowsBase)constamountDaiToBorrow=daiAmount.toString()*0.95*(1/daiPrice.toNumber())console.log(`You can borrow ${amountDaiToBorrow.toString()} DAI`)constamountDaiToBorrowWei=ethers.utils.parseEther(amountDaiToBorrow.toString())constdaiAddress="0x6B175474E89094C44Da98b954EedeAC495271d0F"awaitborrowDai(daiAddress,pool,amountDaiToBorrowWei,deployer)awaitgetBorrowUserData(pool,deployer)}asyncfunctionborrowDai(daiAddress,pool,amountDaiToBorrow,account){constborrowTx=awaitpool.borrow(daiAddress,amountDaiToBorrow,1,0,account)awaitborrowTx.wait(1)console.log("You've borrowed!");}asyncfunctiongetDaiPrice(){constdaiEthPriceFeed=awaitethers.getContractAt("AggregatorV3Interface","0x773616E4d11A78F511299002da57A0a94577F1f4")constprice=(awaitdaiEthPriceFeed.latestRoundData())[1]console.log(`The DAI/ETH price is ${price.toString()}`);returnprice}asyncfunctiongetEthPrice(basePrice){constEthPriceFeed=awaitethers.getContractAt("AggregatorV3Interface","0x773616E4d11A78F511299002da57A0a94577F1f4")constprice=(awaitEthPriceFeed.latestRoundData())[1]constethPrice=awaitprice*basePrice/10**8returnethPrice}asyncfunctiongetBorrowUserData(pool,account){const{ totalCollateralBase, totalDebtBase, availableBorrowsBase }=awaitpool.getUserAccountData(account)console.log(`You have ${(awaitgetEthPrice(totalCollateralBase)).toString()} worth of ETH deposited.`)console.log(`You have ${(awaitgetEthPrice(totalDebtBase)).toString()} worth of ETH borrowed.`)console.log(`You can borrow ${(awaitgetEthPrice(availableBorrowsBase)).toString()} worth of ETH.`)return{ availableBorrowsBase, totalDebtBase }}asyncfunctiongetPool(account){constpoolAddressesProvider=awaitethers.getContractAt("IPoolAddressesProvider","0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e",account)constpoolAddress=awaitpoolAddressesProvider.getPool()constpool=awaitethers.getContractAt("IPool",poolAddress,account)returnpool}asyncfunctionapproveERC20(erc20Address,spenderAddress,amountToSpend,account){consterc20Token=awaitethers.getContractAt("IERC20",erc20Address,account)consttx=awaiterc20Token.approve(spenderAddress,amountToSpend)awaittx.wait(1)console.log("Approved!")}main().then(()=>process.exit(0)).catch((error)=>{console.error(error)process.exit(1)})
Here is the error:
Got 200000000000000000 WETH
Pool Address : 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
Approved!
Depositing...
Deposited!
You have 200176654027392960 worth of ETH deposited.
You have 0 worth of ETH borrowed.
You can borrow 160141323221914370 worth of ETH.
The DAI/ETH price is 536699512676842
You can borrow 283.462633126 DAI
Error: VM Exception while processing transaction: reverted with reason string '31'
at <UnrecognizedContract>.<unknown> (0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2)
at <UnrecognizedContract>.<unknown> (0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2)
at <UnrecognizedContract>.<unknown> (0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at HardhatNode._mineBlockWithPendingTxs (/home/astro/Astro_sol_js/Defi-V3/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1840:23)
at HardhatNode.mineBlock (/home/astro/Astro_sol_js/Defi-V3/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:517:16)
at EthModule._sendTransactionAndReturnHash (/home/astro/Astro_sol_js/Defi-V3/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1532:18)
at HardhatNetworkProvider.request (/home/astro/Astro_sol_js/Defi-V3/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:123:18)
at EthersProviderWrapper.send (/home/astro/Astro_sol_js/Defi-V3/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
error Command failed with exit code 1.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to work with aave V3 but I'm stack on the borrowing section.
My code runs very well but when the borrowing sections reached, the transaction got reverted with error '31'
Here is my code:
Here is the error:
Can someone help on this please :)
Beta Was this translation helpful? Give feedback.
All reactions