Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.
This repository was archived by the owner on May 17, 2024. It is now read-only.

Error: fractional component exceeds decimals #29

@ilkinm03

Description

@ilkinm03

Here's my code

async function main() {
    await getWeth()

    const { deployer } = await getNamedAccounts()
    const signer = await ethers.getSigner(deployer)
    const lendingPool = await getLendingPool(signer)
    console.log(`Lending pool address: ${lendingPool.address}`)

    const wethTokenAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
    await approveERC20(wethTokenAddress, lendingPool.address, AMOUNT, signer)
    console.log("Depositing...")
    await lendingPool.supply(wethTokenAddress, AMOUNT, deployer, 0)
    console.log("Deposited!")

    let { totalDebtBase, availableBorrowsBase } = await getBorrowUserData(
        lendingPool,
        deployer
    )
    const daiPrice = await getDaiPrice()
    const amountDaiToBorrow =
        availableBorrowsBase.toString() * 0.95 * (1 / daiPrice.toNumber())
    console.log(`You can borrow ${amountDaiToBorrow} DAI`)
    const amountDaiToBorrowWei = ethers.utils.parseEther(
        amountDaiToBorrow.toString()
    )
    const daiTokenAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
    await borrowDai(
        daiTokenAddress,
        lendingPool,
        amountDaiToBorrowWei,
        deployer
    )
    await getBorrowUserData(lendingPool, deployer)
    // ....
}

The error occurs on the where I'm defining amountDaiToBorrowWei function with calling parseEther method
The full logs are as below

Got WETH 100000000000000000
Lending pool address: 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
Approved!
Depositing...
Deposited!
You have 29261361000 worth of ETH deposited
You have 0 worth of ETH borrowed
You can borrow 23555395605 worth of ETH
The DAI/ETH price is 342284730000000
You can borrow 0.00005505450530615257 DAI
Error: fractional component exceeds decimals [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT ] (fault="underflow", operation="parseFixed", code=NUMERIC_FAULT, version=bignumber/5.7.0)
  reason: 'fractional component exceeds decimals',
  code: 'NUMERIC_FAULT',
  fault: 'underflow',
  operation: 'parseFixed'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions