Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
텍스트 스타일
모양 변경
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
Untitled Diff
생성일
4년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
77 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
446 행
복사
74 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
428 행
복사
// 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 ERC20
Upgrad
e
able is
contract ERC20
Interface
Upgrad
able 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 _
balance
s[
account
];
return _
ERC1155.
balance
Of(
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 =
_
balance
s[
from
]
;
uint256 fromBalance =
balance
Of(
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;
}
}
저장된 비교 결과
원본
파일 열기
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20Upgradeable.sol"; import "./extensions/IERC20MetadataUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC20} interface. * * 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}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * 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 * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @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 * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @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 * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require( currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero" ); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require( fromBalance >= amount, "ERC20: transfer amount exceeds balance" ); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(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); _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. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require( currentAllowance >= amount, "ERC20: insufficient allowance" ); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @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. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; }
수정본
파일 열기
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol) pragma solidity =0.8.7; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "../../interfaces/IgETH.sol"; /** * @dev Implementation of the {IERC20} interface. * * 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}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20InterfaceUpgradable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { /** * @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; /** * @dev gETH ERC20 interface doesn't use totalSupply info, catches it from ERC1155. * uint256 private _totalSupply; **/ string private _name; string private _symbol; uint256 private _id; IgETH private _ERC1155; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20interface_init( uint256 id_, string memory name_, string memory symbol_, address gETH_1155 ) internal onlyInitializing { __ERC20interface_init_unchained(id_, name_, symbol_, gETH_1155); } function __ERC20interface_init_unchained( uint256 id_, string memory name_, string memory symbol_, address gETH_1155 ) internal onlyInitializing { _id = id_; _name = name_; _symbol = symbol_; _ERC1155 = IgETH(gETH_1155); } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * 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 * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. * @dev CHANGED for gETH. * @dev See {gETH-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _ERC1155.totalSupply(_id); } /** * @dev See {IERC20-balanceOf}. * @dev CHANGED for gETH. * @dev See {gETH-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { 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}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @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 * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @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 * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require( currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero" ); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * @dev CHANGED for gETH. * @dev See {gETH-safeTransferFrom}. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = balanceOf(from); require( fromBalance >= amount, "ERC20: transfer amount exceeds balance" ); _ERC1155.safeTransferFrom(from, to, _id, amount, ""); emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** * @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 * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require( currentAllowance >= amount, "ERC20: insufficient allowance" ); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @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. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; }
비교하기