Untitled Diff

Created Diff never expires
73 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
446 lines
63 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
428 lines
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)


pragma solidity ^0.8.0;
pragma solidity =0.8.7;


import "./IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../../interfaces/IgETH.sol";


/**
/**
* @dev Implementation of the {IERC20} interface.
* @dev Implementation of the {IERC20} interface.
*
*
* This implementation is agnostic to the way tokens are created. This means
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
*
* TIP: For a detailed writeup see our guide
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
* to implement supply mechanisms].
*
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* conventional and does not conflict with the expectations of ERC20
* applications.
* applications.
*
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
* these events, as it isn't required by the specification.
*
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
* allowances. See {IERC20-approve}.
*/
*/
contract ERC20Upgradeable is

contract ERC20InterfaceUpgradable is
Initializable,
Initializable,
ContextUpgradeable,
ContextUpgradeable,
IERC20Upgradeable,
IERC20Upgradeable,
IERC20MetadataUpgradeable
IERC20MetadataUpgradeable
{
{
mapping(address => uint256) private _balances;
/**
* @dev gETH ERC20 interface doesn't use balance info, catches it from ERC1155.
* mapping(address => uint256) private _balances;
**/


mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => mapping(address => uint256)) private _allowances;


uint256 private _totalSupply;
/**
* @dev gETH ERC20 interface doesn't use totalSupply info, catches it from ERC1155.
* uint256 private _totalSupply;
**/


string private _name;
string private _name;
string private _symbol;
string private _symbol;


uint256 private _id;
IgETH private _ERC1155;

/**
/**
* @dev Sets the values for {name} and {symbol}.
* @dev Sets the values for {name} and {symbol}.
*
*
* The default value of {decimals} is 18. To select a different value for
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
* {decimals} you should overload it.
*
*
* All two of these values are immutable: they can only be set once during
* All two of these values are immutable: they can only be set once during
* construction.
* construction.
*/
*/
function __ERC20_init(string memory name_, string memory symbol_)

internal
function __ERC20interface_init(
onlyInitializing
uint256 id_,
{
string memory name_,
__ERC20_init_unchained(name_, symbol_);
string memory symbol_,
address gETH_1155
) internal onlyInitializing {
__ERC20interface_init_unchained(id_, name_, symbol_, gETH_1155);
}
}


function __ERC20_init_unchained(string memory name_, string memory symbol_)
function __ERC20interface_init_unchained(
internal
uint256 id_,
onlyInitializing
string memory name_,
{
string memory symbol_,
address gETH_1155
) internal onlyInitializing {
_id = id_;
_name = name_;
_name = name_;
_symbol = symbol_;
_symbol = symbol_;
_ERC1155 = IgETH(gETH_1155);
}
}


/**
/**
* @dev Returns the name of the token.
* @dev Returns the name of the token.
*/
*/
function name() public view virtual override returns (string memory) {
function name() public view virtual override returns (string memory) {
return _name;
return _name;
}
}


/**
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
* name.
*/
*/
function symbol() public view virtual override returns (string memory) {
function symbol() public view virtual override returns (string memory) {
return _symbol;
return _symbol;
}
}


/**
/**
* @dev Returns the number of decimals used to get its user representation.
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
* overridden;
*
*
* NOTE: This information is only used for _display_ purposes: it in
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
*/
function decimals() public view virtual override returns (uint8) {
function decimals() public view virtual override returns (uint8) {
return 18;
return 18;
}
}


/**
/**
* @dev See {IERC20-totalSupply}.
* @dev See {IERC20-totalSupply}.
* @dev CHANGED for gETH.
* @dev See {gETH-totalSupply}.
*/
*/
function totalSupply() public view virtual override returns (uint256) {
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
return _ERC1155.totalSupply(_id);
}
}


/**
/**
* @dev See {IERC20-balanceOf}.
* @dev See {IERC20-balanceOf}.
* @dev CHANGED for gETH.
* @dev See {gETH-balanceOf}.
*/
*/
function balanceOf(address account)
function balanceOf(address account)
public
public
view
view
virtual
virtual
override
override
returns (uint256)
returns (uint256)
{
{
Text moved with changes from lines 318-323 (84.1% similarity)
return _balances[account];
return _ERC1155.balanceOf(account, _id);
}

/**
* @dev shows the u underlying ETH for 1 staked ether for a given Registerer as 1e18
* @dev CHANGED for gETH.
* @dev See {gETH-pricePerShare}.
*/
function pricePerShare() public view returns (uint256) {
return _ERC1155.pricePerShare(_id);
}
}


/**
/**
* @dev See {IERC20-transfer}.
* @dev See {IERC20-transfer}.
*
*
* Requirements:
* Requirements:
*
*
* - `to` cannot be the zero address.
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
* - the caller must have a balance of at least `amount`.
*/
*/
function transfer(address to, uint256 amount)
function transfer(address to, uint256 amount)
public
public
virtual
virtual
override
override
returns (bool)
returns (bool)
{
{
address owner = _msgSender();
address owner = _msgSender();
_transfer(owner, to, amount);
_transfer(owner, to, amount);
return true;
return true;
}
}


/**
/**
* @dev See {IERC20-allowance}.
* @dev See {IERC20-allowance}.
*/
*/
function allowance(address owner, address spender)
function allowance(address owner, address spender)
public
public
view
view
virtual
virtual
override
override
returns (uint256)
returns (uint256)
{
{
return _allowances[owner][spender];
return _allowances[owner][spender];
}
}


/**
/**
* @dev See {IERC20-approve}.
* @dev See {IERC20-approve}.
*
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
*
* Requirements:
* Requirements:
*
*
* - `spender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
*/
function approve(address spender, uint256 amount)
function approve(address spender, uint256 amount)
public
public
virtual
virtual
override
override
returns (bool)
returns (bool)
{
{
address owner = _msgSender();
address owner = _msgSender();
_approve(owner, spender, amount);
_approve(owner, spender, amount);
return true;
return true;
}
}


/**
/**
* @dev See {IERC20-transferFrom}.
* @dev See {IERC20-transferFrom}.
*
*
* Emits an {Approval} event indicating the updated allowance. This is not
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
* required by the EIP. See the note at the beginning of {ERC20}.
*
*
* NOTE: Does not update the allowance if the current allowance
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
* is the maximum `uint256`.
*
*
* Requirements:
* Requirements:
*
*
* - `from` and `to` cannot be the zero address.
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
* `amount`.
*/
*/
function transferFrom(
function transferFrom(
address from,
address from,
address to,
address to,
uint256 amount
uint256 amount
) public virtual override returns (bool) {
) public virtual override returns (bool) {
address spender = _msgSender();
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
_transfer(from, to, amount);
return true;
return true;
}
}


/**
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
*
* This is an alternative to {approve} that can be used as a mitigation for
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
* problems described in {IERC20-approve}.
*
*
* Emits an {Approval} event indicating the updated allowance.
* Emits an {Approval} event indicating the updated allowance.
*
*
* Requirements:
* Requirements:
*
*
* - `spender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
*/
function increaseAllowance(address spender, uint256 addedValue)
function increaseAllowance(address spender, uint256 addedValue)
public
public
virtual
virtual
returns (bool)
returns (bool)
{
{
address owner = _msgSender();
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
return true;
}
}


/**
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
*
* This is an alternative to {approve} that can be used as a mitigation for
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
* problems described in {IERC20-approve}.
*
*
* Emits an {Approval} event indicating the updated allowance.
* Emits an {Approval} event indicating the updated allowance.
*
*
* Requirements:
* Requirements:
*
*
* - `spender` cannot be the zero address.
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
* `subtractedValue`.
*/
*/
function decreaseAllowance(address spender, uint256 subtractedValue)
function decreaseAllowance(address spender, uint256 subtractedValue)
public
public
virtual
virtual
returns (bool)
returns (bool)
{
{
address owner = _msgSender();
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
uint256 currentAllowance = allowance(owner, spender);
require(
require(
currentAllowance >= subtractedValue,
currentAllowance >= subtractedValue,
"ERC20: decreased allowance below zero"
"ERC20: decreased allowance below zero"
);
);
unchecked {
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
_approve(owner, spender, currentAllowance - subtractedValue);
}
}


return true;
return true;
}
}


/**
/**
* @dev Moves `amount` of tokens from `from` to `to`.
* @dev Moves `amount` of tokens from `from` to `to`.
*
*
* This internal function is equivalent to {transfer}, and can be used to
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
*
* Emits a {Transfer} event.
* Emits a {Transfer} event.
*
*
* Requirements:
* Requirements:
*
*
* - `from` cannot be the zero address.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - `from` must have a balance of at least `amount`.
* @dev CHANGED for gETH.
* @dev See {gETH-safeTransferFrom}.
*/
*/
function _transfer(
function _transfer(
address from,
address from,
address to,
address to,
uint256 amount
uint256 amount
) internal virtual {
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(to != address(0), "ERC20: transfer to the zero address");


_beforeTokenTransfer(from, to, amount);
_beforeTokenTransfer(from, to, amount);


uint256 fromBalance = _balances[from];
uint256 fromBalance = balanceOf(from);
require(
require(
fromBalance >= amount,
fromBalance >= amount,
"ERC20: transfer amount exceeds balance"
"ERC20: transfer amount exceeds balance"
);
);
unchecked {
_ERC1155.safeTransferFrom(from, to, _id, amount, "");
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;


emit Transfer(from, to, amount);
emit Transfer(from, to, amount);


_afterTokenTransfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
}


/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");

_beforeTokenTransfer(address(0), account, amount);

_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);

Text moved with changes to lines 146-151 (84.1% similarity)
_afterTokenTransfer(address(0), account, amount);
}

/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");

_beforeTokenTransfer(account, address(0), amount);

uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;

emit Transfer(account, address(0), amount);

_afterTokenTransfer(account, address(0), amount);
}

/**
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
*
* This internal function is equivalent to `approve`, and can be used to
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
* e.g. set automatic allowances for certain subsystems, etc.
*
*
* Emits an {Approval} event.
* Emits an {Approval} event.
*
*
* Requirements:
* Requirements:
*
*
* - `owner` cannot be the zero address.
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
*/
function _approve(
function _approve(
address owner,
address owner,
address spender,
address spender,
uint256 amount
uint256 amount
) internal virtual {
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
require(spender != address(0), "ERC20: approve to the zero address");


_allowances[owner][spender] = amount;
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
emit Approval(owner, spender, amount);
}
}


/**
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
*
* Does not update the allowance amount in case of infinite allowance.
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
* Revert if not enough allowance is available.
*
*
* Might emit an {Approval} event.
* Might emit an {Approval} event.
*/
*/
function _spendAllowance(
function _spendAllowance(
address owner,
address owner,
address spender,
address spender,
uint256 amount
uint256 amount
) internal virtual {
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance != type(uint256).max) {
require(
require(
currentAllowance >= amount,
currentAllowance >= amount,
"ERC20: insufficient allowance"
"ERC20: insufficient allowance"
);
);
unchecked {
unchecked {
_approve(owner, spender, currentAllowance - amount);
_approve(owner, spender, currentAllowance - amount);
}
}
}
}
}
}


/**
/**
* @dev Hook that is called before any transfer of tokens. This includes
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
* minting and burning.
*
*
* Calling conditions:
* Calling conditions:
*
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
* - `from` and `to` are never both zero.
*
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
*/
function _beforeTokenTransfer(
function _beforeTokenTransfer(
address from,
address from,
address to,
address to,
uint256 amount
uint256 amount
) internal virtual {}
) internal virtual {}


/**
/**
* @dev Hook that is called after any transfer of tokens. This includes
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
* minting and burning.
*
*
* Calling conditions:
* Calling conditions:
*
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
* - `from` and `to` are never both zero.
*
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
*/
function _afterTokenTransfer(
function _afterTokenTransfer(
address from,
address from,
address to,
address to,
uint256 amount
uint256 amount
) internal virtual {}
) internal virtual {}


/**
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
*/

uint256[45] private __gap;
uint256[45] private __gap;
}
}