Lesson 13 invalid signer bug #1380
Answered
by
alymurtazamemon
AlexK020908
asked this question in
Q&A
-
I am following the video on AAVE, and currently I am working on a function called however, whenever I specify the signer in
here is my code : const { getNamedAccounts, ethers } = require("hardhat")
const { getWeth, AMOUNT } = require("../scripts/getWeth.js")
async function main() {
//protocal treats everything as an erc 20 token
//eth and native blockchian isn't erc 20 token
//the reason why we do this is becuase it makes everything easier
//wrapped erc is bascially eth but wrapped as an erc-20 token
await getWeth()
const { deployer } = await getNamedAccounts()
//now we want to interact with the aave protocol
//lending pool address provider: 0xb53c1a33016b2dc2ff3653530bff1848a515c8c5
const LendingPool = await getLendingPool()
console.log(`the lending pool contract at ${LendingPool.address}`)
//deposit !
//by looking at the deposit function in the aave github https://github.com/aave/protocol-v2/blob/master/contracts/protocol/lendingpool/LendingPool.sol
/*
IERC20(asset).safeTransferFrom(msg.sender, aToken, amount); gets money out of our wallet
so we have to approve it
let us get the weth token first
*/
const wethTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
//approve !
//THE weth token address is where we are going to get the weth from ...
console.log(`deployer address ${deployer}`)
await approveErc20(wethTokenAddress, LendingPool.address, AMOUNT, deployer)
console.log(`depositing....`)
await LendingPool.deposit(wethTokenAddress, AMOUNT, deployer, 0)
console.log("deposited!")
//you can look at paramters on the docs.
/*
the first is the type of asset we are depositing --> which isa weth
*/
//first we need to grab all the info about a user getUserAccountData() --> where you can see health factor etc, liquidation threshold, we want to see how much we can borrow
let { totalCollateralETH, totalDebtETH, availableBorrowsETH } = getBorrowUserData(
LendingPool,
deployer
)
}
async function getBorrowUserData(lendingpool, account) {
const { totalCollateralETH, totalDebtETH, availableBorrowsETH } =
await lendingpool.getUserAccountData(account)
console.log(`you have total collateral eth of ${totalCollateralETH}`)
console.log(`you have ${totalDebtETH} in debt `)
console.log(`you have ${availableBorrowsETH} eth to borrow`)
return { totalCollateralETH, totalDebtETH, availableBorrowsETH }
}
async function approveErc20(ERC20Address, spenderAddress, amountToSpend, account) {
//the address of our erc20 token lcoation
//contract address
//spender address: contract we are going to give approval to
//account --> to do all this on
const erc20Token = await ethers.getContractAt("IERC20", ERC20Address, account)
const tx = await erc20Token.approve(spenderAddress, amountToSpend) //with the weth contract
//we can approve it taking funds out of our wallet and giving it to the lending pool!!!
await tx.wait(1)
console.log("token approved ")
}
async function getLendingPool() {
const ILendingPoolAddressProvier = await ethers.getContractAt(
"ILendingPoolAddressesProvider",
"0xb53c1a33016b2dc2ff3653530bff1848a515c8c5"
)
const lendingPoolAddress = await ILendingPoolAddressProvier.getLendingPool()
//now we want to get the lendingpool contract
//need abi and contract addresss which we have already
const contract = await ethers.getContractAt("ILendingPool", lendingPoolAddress)
//if i specify deployer. it fails, I do not know why
return contract
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
}) any help is appreciated! Thank you so much! |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Jul 29, 2022
Replies: 1 comment 11 replies
-
let { totalCollateralETH, totalDebtETH, availableBorrowsETH } = getBorrowUserData(
LendingPool,
deployer
) You forgot to add let { totalCollateralETH, totalDebtETH, availableBorrowsETH } = await getBorrowUserData(
LendingPool,
deployer
) It should be like this. |
Beta Was this translation helpful? Give feedback.
11 replies
Answer selected by
AlexK020908
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AlexK020908
You forgot to add
await here
It should be like this.