Skip to content

bug: CompoundERC4626 redeem() #5

@shortdoom

Description

@shortdoom

Using redeem() on CompoundV2 wrapper with current implementation, leveraging LibCompound, fails to return appropriate assets calculation when calling redeem(). Issue doesn't touch withdraw().

Exchanging totalAsset() implementation from LibCompound's viewUnderlyingBalanceOf() too:

function totalAssets() public view virtual override returns (uint256) {
    return cToken.balanceOf(address(this)).mulWadDown(cToken.exchangeRateStored());
}

fixes shares/assets calculation.

Otherwise, inspecting state change during redeem() yields wrong amount of totalAssets() (AUM), example with hh console.log

totalAssets() 3177334480600619999224 --- with LibCompound
totalAssets() 999999999999801353087 --- with hardcoded division by exchangeRateStored()

I may be missing something as I didn't fully inspect where things go south in LibCompound and my implementation of CompoundWrapper is also protocol specific. Can make a PR later if Issue makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions