compound-finance / compound-protocol

The Compound On-Chain Protocol
https://compound.finance/developers
BSD 3-Clause "New" or "Revised" License
1.88k stars 1.2k forks source link

withdraw `type(uint256).max` will not affect usdc pool balance #237

Closed alan890104 closed 1 year ago

alan890104 commented 1 year ago

Reproduce (on block height 17228670)

  1. alice apply 1000 USDC to compound
  2. Bob supply 200,000 WETH to compound
  3. bob borrows all of the usdc from compound. However, when I fill in type(uint256).max instead of usdc.balanceOf(address(compound)), the balance of usdc in compound does not change.

This line in my code is the place where error occurs.

The document says A value of MaxUint256 will withdraw all of the src’s base balance. image

kevincheng96 commented 1 year ago

Just an FYI, the documentation you are referring to is for v3 but this repo is for v2. The v3 repo can be found here.

Your test is behaving as expected for v3. Using MaxUint256 as the amount for withdraw will withdraw all of the user's base balance (the amount of USDC supplied). In this case, Bob has not supplied any USDC so his base balance is 0.

alan890104 commented 1 year ago

Greatly appreciate your explanation!