Browse Source

Add note in ERC20Wrapper about rebasing tokens (#4755)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Ernesto García 1 year ago
parent
commit
769071d473
1 changed files with 7 additions and 2 deletions
  1. 7 2
      contracts/token/ERC20/extensions/ERC20Wrapper.sol

+ 7 - 2
contracts/token/ERC20/extensions/ERC20Wrapper.sol

@@ -12,6 +12,11 @@ import {SafeERC20} from "../utils/SafeERC20.sol";
  * Users can deposit and withdraw "underlying tokens" and receive a matching number of "wrapped tokens". This is useful
  * in conjunction with other modules. For example, combining this wrapping mechanism with {ERC20Votes} will allow the
  * wrapping of an existing "basic" ERC-20 into a governance token.
+ *
+ * WARNING: Any mechanism in which the underlying token changes the {balanceOf} of an account without an explicit transfer
+ * may desynchronize this contract's supply and its underlying balance. Please exercise caution when wrapping tokens that
+ * may undercollateralize the wrapper (i.e. wrapper's total supply is higher than its underlying balance). See {_recover}
+ * for recovering value accrued to the wrapper.
  */
 abstract contract ERC20Wrapper is ERC20 {
     IERC20 private immutable _underlying;
@@ -75,8 +80,8 @@ abstract contract ERC20Wrapper is ERC20 {
     }
 
     /**
-     * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
-     * function that can be exposed with access control if desired.
+     * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake or acquired from
+     * rebasing mechanisms. Internal function that can be exposed with access control if desired.
      */
     function _recover(address account) internal virtual returns (uint256) {
         uint256 value = _underlying.balanceOf(address(this)) - totalSupply();