-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ERC20 inheritance layout, refactor
- Loading branch information
1 parent
7c1f68d
commit 3e7a23d
Showing
8 changed files
with
186 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; | ||
|
||
import { IEcoERC20Metadata, IERC20Metadata } from "./IERC20.sol"; | ||
|
||
abstract contract ERC20MetadataUpgradeable is IEcoERC20Metadata, ERC20Upgradeable { | ||
// keccak256(abi.encode(uint256(keccak256("eco.storage.ERC20MetadataUpgradeable")) - 1)) & ~bytes32(uint256(0xff)) | ||
bytes32 private constant ERC20MetadataUpgradeableStorageLocation = | ||
0x5bacbea0cd534f9867e3a5c99fe0e401e8856261242468f24aa4869ec40ac300; | ||
|
||
struct ERC20MetadataUpgradeableStorage { | ||
string name; | ||
string symbol; | ||
uint8 decimals; | ||
} | ||
|
||
function _getERC20MetadataUpgradeableStorage() private pure returns (ERC20MetadataUpgradeableStorage storage $) { | ||
assembly { | ||
$.slot := ERC20MetadataUpgradeableStorageLocation | ||
} | ||
} | ||
|
||
function _initEcoERC20Metadata( | ||
string memory _name, | ||
string memory _symbol, | ||
uint8 _decimals | ||
) public override onlyInitializing { | ||
ERC20MetadataUpgradeableStorage storage $ = _getERC20MetadataUpgradeableStorage(); | ||
$.name = _name; | ||
$.symbol = _symbol; | ||
$.decimals = _decimals; | ||
} | ||
|
||
function name() public view virtual override(ERC20Upgradeable, IERC20Metadata) returns (string memory) { | ||
return _getERC20MetadataUpgradeableStorage().name; | ||
} | ||
|
||
function symbol() public view virtual override(ERC20Upgradeable, IERC20Metadata) returns (string memory) { | ||
return _getERC20MetadataUpgradeableStorage().symbol; | ||
} | ||
|
||
function decimals() public view virtual override(ERC20Upgradeable, IERC20Metadata) returns (uint8) { | ||
return _getERC20MetadataUpgradeableStorage().decimals; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import { ISelectorRoleControl, IPausable, IEcoOwnable, SelectorRoleControlUpgradeable } from "../../access/SelectorRoleControlUpgradeable.sol"; | ||
|
||
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; | ||
import { ERC20BurnableUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol"; | ||
|
||
import { IERC20, IERC20Metadata, IERC20Burnable, IEcoERC20 } from "./IERC20.sol"; | ||
|
||
import { ERC20MetadataUpgradeable } from "./ERC20MetadataUpgradeable.sol"; | ||
import { ERC20MintableUpgradeable } from "./ERC20MintableUpgradeable.sol"; | ||
|
||
contract EcoERC20Upgradeable is IEcoERC20, ERC20MetadataUpgradeable, ERC20MintableUpgradeable { | ||
function initEcoERC20( | ||
address initialOwner, | ||
string memory _name, | ||
string memory _symbol, | ||
uint8 _decimals | ||
) public initializer { | ||
_initEcoOwnable(initialOwner); | ||
_initEcoERC20Metadata(_name, _symbol, _decimals); | ||
} | ||
|
||
function name() | ||
public | ||
view | ||
override(ERC20MetadataUpgradeable, ERC20Upgradeable, IERC20Metadata) | ||
returns (string memory) | ||
{ | ||
return super.name(); | ||
} | ||
|
||
function symbol() | ||
public | ||
view | ||
override(ERC20MetadataUpgradeable, ERC20Upgradeable, IERC20Metadata) | ||
returns (string memory) | ||
{ | ||
return super.symbol(); | ||
} | ||
|
||
function decimals() | ||
public | ||
view | ||
override(ERC20MetadataUpgradeable, ERC20Upgradeable, IERC20Metadata) | ||
returns (uint8) | ||
{ | ||
return super.decimals(); | ||
} | ||
|
||
function burn(uint256 amount) public virtual override(ERC20MintableUpgradeable, IERC20Burnable) { | ||
super.burn(amount); | ||
} | ||
|
||
function burnFrom( | ||
address account, | ||
uint256 amount | ||
) public virtual override(ERC20MintableUpgradeable, IERC20Burnable) { | ||
super.burnFrom(account, amount); | ||
} | ||
|
||
function totalSupply() public view override(ERC20Upgradeable, IERC20) returns (uint256) { | ||
return super.totalSupply(); | ||
} | ||
|
||
function balanceOf(address account) public view override(ERC20Upgradeable, IERC20) returns (uint256) { | ||
return super.balanceOf(account); | ||
} | ||
|
||
function transfer(address to, uint256 value) public virtual override(ERC20Upgradeable, IERC20) returns (bool) { | ||
return super.transfer(to, value); | ||
} | ||
|
||
function allowance( | ||
address owner, | ||
address spender | ||
) public view override(ERC20Upgradeable, IERC20) returns (uint256) { | ||
return super.allowance(owner, spender); | ||
} | ||
|
||
function approve(address spender, uint256 value) public virtual override(ERC20Upgradeable, IERC20) returns (bool) { | ||
return super.approve(spender, value); | ||
} | ||
|
||
function transferFrom( | ||
address from, | ||
address to, | ||
uint256 value | ||
) public virtual override(ERC20Upgradeable, IERC20) returns (bool) { | ||
return super.transferFrom(from, to, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters