mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-27 03:36:32 +00:00
Fix .gitignore: stop tracking ignored files
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC20Wrapper.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../ERC20.sol";
|
||||
import "../utils/SafeERC20.sol";
|
||||
|
||||
/**
|
||||
* @dev Extension of the ERC20 token contract to support token wrapping.
|
||||
*
|
||||
* 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" ERC20 into a governance token.
|
||||
*
|
||||
* _Available since v4.2._
|
||||
*/
|
||||
abstract contract ERC20Wrapper is ERC20 {
|
||||
IERC20 private immutable _underlying;
|
||||
|
||||
constructor(IERC20 underlyingToken) {
|
||||
require(underlyingToken != this, "ERC20Wrapper: cannot self wrap");
|
||||
_underlying = underlyingToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {ERC20-decimals}.
|
||||
*/
|
||||
function decimals() public view virtual override returns (uint8) {
|
||||
try IERC20Metadata(address(_underlying)).decimals() returns (uint8 value) {
|
||||
return value;
|
||||
} catch {
|
||||
return super.decimals();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the underlying ERC-20 token that is being wrapped.
|
||||
*/
|
||||
function underlying() public view returns (IERC20) {
|
||||
return _underlying;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens.
|
||||
*/
|
||||
function depositFor(address account, uint256 amount) public virtual returns (bool) {
|
||||
address sender = _msgSender();
|
||||
require(sender != address(this), "ERC20Wrapper: wrapper can't deposit");
|
||||
SafeERC20.safeTransferFrom(_underlying, sender, address(this), amount);
|
||||
_mint(account, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allow a user to burn a number of wrapped tokens and withdraw the corresponding number of underlying tokens.
|
||||
*/
|
||||
function withdrawTo(address account, uint256 amount) public virtual returns (bool) {
|
||||
_burn(_msgSender(), amount);
|
||||
SafeERC20.safeTransfer(_underlying, account, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
function _recover(address account) internal virtual returns (uint256) {
|
||||
uint256 value = _underlying.balanceOf(address(this)) - totalSupply();
|
||||
_mint(account, value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user