Add note in ERC20Wrapper about rebasing tokens (#4755)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user