Lesson 13 - Wrong DAI price wih the Data Feed #2326
-
Hello, I am creating this discussion to now if this what is happening to me is some kind of mistake from me or, in another hand, is an issue. What happens is that when I am tryg to consoleLog the DAI/ETH price, I get another price, this: 634551646080931. When actually the ETH price is in 1580 rigth now, actually. This is my code:
When changing the return value of the function in: Thank you very much, hope that somebody knows that more about this help me with this. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
@SebasAran16 This is the DAI/ETH price without conversion. The starting 4 digits tells the exact price, and after that it includes the additional digits. After getting it, we convert it to only DAI and WEI amount. // * convert to dai amount user can borrow.
const amountDaiToBorrow =
availableBorrowsETH.toString() * 0.95 * (1 / daiPrice.toNumber());
console.log(`You can borrow ${amountDaiToBorrow.toString()} DAI`);
// * convert to wei
const amountToDaiBorrowWie = ethers.utils.parseEther(
amountDaiToBorrow.toString()
); |
Beta Was this translation helpful? Give feedback.
-
I guess with price feed of 0x773616E4d11A78F511299002da57A0a94577F1f4, we have the inverse price of ETH/USD (1 DAI = x ETH, and not 1 ETH = y DAI) |
Beta Was this translation helpful? Give feedback.
-
This was pretty confusing for me as well, until I realized that the async function getDaiPrice() {
// don't need to connect to deployer account since we are not sending any txs
const daiEthPriceFeed = await ethers.getContractAt(
"AggregatorV3Interface",
networkConfig[network.config.chainId].daiEthPriceFeed
)
const price = (await daiEthPriceFeed.latestRoundData())[1] // answer
console.log(`This how much ETH you could buy with 1 DAI ${ethers.utils.formatEther(price)}`)
const ethPriceInDai = ethers.utils.parseEther("1").div(price)
console.log(`This how much DAI you could buy with 1 ETH i.e. price of 1 ETH ${ethPriceInDai}`)
return price
} |
Beta Was this translation helpful? Give feedback.
@SebasAran16 This is the DAI/ETH price without conversion. The starting 4 digits tells the exact price, and after that it includes the additional digits. After getting it, we convert it to only DAI and WEI amount.