shows undefined while getting UserBorrowData from Aave v2 #4788
Answered
by
alymurtazamemon
decentralized-86
asked this question in
Q&A
-
After depositing the Weth was making a call to get userBorrowData but the return values are undefiend...... const { getNamedAccounts } = require("hardhat");
const { networkConfig } = require("../helper-hardhat.config");
const { getWeth, Amount } = require("../scripts/getWeth");
async function main() {
const { deployer } = await getNamedAccounts();
await getWeth();
//interact with the aave protocol ABI and address
//address of 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5
const lendingpool = await GetLendingpooladdress(deployer);
console.log(lendingpool.address);
const wethTokenContractAddress =
networkConfig[network.config.chainId].wethToken;
//deposit
await approveERC20(
wethTokenContractAddress,
lendingpool.address,
Amount,
deployer
);
console.log("Depositing...");
await lendingpool.deposit(wethTokenContractAddress, Amount, deployer, 0);
console.log("deposited....");
//Borrow
let { totalcollateralEth, totalDebhEth, availableBorrowsEth } =
await getUserBorrowData(lendingpool, deployer);
}
async function getUserBorrowData(lendingpool, account) {
const { totalcollateralEth, totalDebhEth, availableBorrowsEth } =
await lendingpool.getUserAccountData(account);
console.log("The total collateral Eth is " + totalcollateralEth);
console.log("The total Debth Eth is " + totalDebhEth);
console.log("The total Available Eth is " + availableBorrowsEth);
return { totalcollateralEth, totalDebhEth, availableBorrowsEth };
}
async function GetLendingpooladdress(account) {
const IlendingpoolAddressProvider = await ethers.getContractAt(
"ILendingPoolAddressesProvider",
"0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5",
account
);
const LendingPoolAddress = await IlendingpoolAddressProvider.getLendingPool();
const ilendingPool = await ethers.getContractAt(
"ILendingPool",
LendingPoolAddress,
account
);
return ilendingPool;
}
async function approveERC20(
erc20address,
spenderaddress,
AmountToSpend,
account
) {
const erc20 = await ethers.getContractAt("IERC20", erc20address, account);
console.log("passed 1");
const approve = await erc20.approve(spenderaddress, AmountToSpend);
//console.log(approve);
console.log("Passed 2");
await approve.wait(1);
console.log("Approved to address " + spenderaddress);
}
main()
.then(() => {
process.exit(0);
})
.catch((err) => {
console.log(err);
process.exit(1);
}); Terminal logs Deposit fucntion [object Object]
The balance Weth is 20000000000000000
0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9
passed 1
Passed 2
Approved to address 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9
Depositing...
deposited....
The total collateral Eth is undefined
The total Debth Eth is undefined
The total Available Eth is undefined The Last 3 logs on the terminal |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Feb 11, 2023
Replies: 1 comment
-
@decentralized-86 Make sure to name the exported variables correctly; const { totalCollateralETH, totalDebtETH, availableBorrowsETH } =
await lendingPool.getUserAccountData(account) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
decentralized-86
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@decentralized-86 Make sure to name the exported variables correctly;