ERC1155-UPGRADEABLE
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,3 +1,7 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
.DS_Store
|
|
||||||
src/*/artifacts/
|
src/*/artifacts/
|
||||||
|
src/artifacts/
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
src/*/.DS_Store
|
||||||
|
src/.DS_Store
|
||||||
|
|||||||
115
src/DEMO/Solidity.sol
Normal file
115
src/DEMO/Solidity.sol
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 智能合约中的一些内置函数
|
||||||
|
*/
|
||||||
|
contract Solidity {
|
||||||
|
// 计算输入的Keccak-256散列
|
||||||
|
function callKeccak256(bytes memory text)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (bytes32 result)
|
||||||
|
{
|
||||||
|
return keccak256(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function callKeccak256(string memory text)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (bytes32 result)
|
||||||
|
{
|
||||||
|
return keccak256(bytes(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算输入的SHA-256散列
|
||||||
|
function callSha256(bytes memory text) public pure returns (bytes32) {
|
||||||
|
return sha256(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function callRipemd160(bytes memory text) public pure returns (bytes20) {
|
||||||
|
return ripemd160(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 数值的另一种标记方式
|
||||||
|
*/
|
||||||
|
function totalSupply() public pure returns (uint256) {
|
||||||
|
return 9_527_000_000e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 获取当前区块链的CHAINID
|
||||||
|
*/
|
||||||
|
function chainId() public view virtual returns (uint256) {
|
||||||
|
uint256 _chainId;
|
||||||
|
|
||||||
|
assembly {
|
||||||
|
_chainId := chainid()
|
||||||
|
}
|
||||||
|
|
||||||
|
return _chainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 当前时间戳,单位秒。
|
||||||
|
*/
|
||||||
|
function timestamp() public view virtual returns (uint256) {
|
||||||
|
return block.timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 获取当前区块链高度
|
||||||
|
*/
|
||||||
|
function height() public view virtual returns (uint256) {
|
||||||
|
return block.number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 当前区块的难度
|
||||||
|
*/
|
||||||
|
function difficulty() public view virtual returns (uint256) {
|
||||||
|
return block.difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 当前区块的gaslimit
|
||||||
|
*/
|
||||||
|
function gaslimit() public view virtual returns (uint256) {
|
||||||
|
return block.gaslimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 当前区块矿工的地址
|
||||||
|
*/
|
||||||
|
function coinbase() public view virtual returns (address) {
|
||||||
|
return block.coinbase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 剩余 gas
|
||||||
|
*/
|
||||||
|
function gasLeft() public view virtual returns (uint256) {
|
||||||
|
return gasleft();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 交易中发送者愿意支付的价格
|
||||||
|
*/
|
||||||
|
function gasPrice() public view virtual returns (uint256) {
|
||||||
|
return tx.gasprice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 这笔交易的发送者。 在开发中避免使用,合约调用有Delegate call的方式可能不会与你的预期不一致。
|
||||||
|
*/
|
||||||
|
function origin() public view virtual returns (address) {
|
||||||
|
return tx.origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// msg.data (bytes calldata) 完成 calldata
|
||||||
|
// msg.sender (address payable) 消息发送者 (当前 caller)
|
||||||
|
// msg.sig (bytes4) calldata的前四个字节 (function identifier)
|
||||||
|
// msg.value (uint) 当前消息的wei值
|
||||||
|
}
|
||||||
@@ -24,7 +24,14 @@ contract MyERC20 is
|
|||||||
uint8 decimals_
|
uint8 decimals_
|
||||||
) ERC20(name_, symbol_) {
|
) ERC20(name_, symbol_) {
|
||||||
_decimals = decimals_;
|
_decimals = decimals_;
|
||||||
_mint(msg.sender, totalSupply_);
|
_mint(msg.sender, totalSupply_ * (10 ** decimals_));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 获取当前区块链高度
|
||||||
|
*/
|
||||||
|
function height() public view virtual returns (uint256) {
|
||||||
|
return block.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decimals() public view virtual override returns (uint8) {
|
function decimals() public view virtual override returns (uint8) {
|
||||||
@@ -36,7 +43,6 @@ contract MyERC20 is
|
|||||||
address to,
|
address to,
|
||||||
uint256 amount
|
uint256 amount
|
||||||
) internal virtual override(ERC20, ERC20Pausable, ERC20Snapshot) {
|
) internal virtual override(ERC20, ERC20Pausable, ERC20Snapshot) {
|
||||||
ERC20Pausable._beforeTokenTransfer(from, to, amount);
|
super._beforeTokenTransfer(from, to, amount);
|
||||||
ERC20Snapshot._beforeTokenTransfer(from, to, amount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/Proxy/UpgradeableToken/UpgradeableERC1155.sol
Normal file
39
src/Proxy/UpgradeableToken/UpgradeableERC1155.sol
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
|
||||||
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||||
|
|
||||||
|
contract UpgradeableERC1155 is ERC1155Upgradeable, OwnableUpgradeable {
|
||||||
|
string private _name;
|
||||||
|
|
||||||
|
string private _symbol;
|
||||||
|
|
||||||
|
function name() public view virtual returns (string memory) {
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function symbol() public view virtual returns (string memory) {
|
||||||
|
return _symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize(
|
||||||
|
string memory tokenName_,
|
||||||
|
string memory symbol_,
|
||||||
|
string memory uri_
|
||||||
|
) public initializer {
|
||||||
|
_name = tokenName_;
|
||||||
|
_symbol = symbol_;
|
||||||
|
__ERC1155_init(uri_);
|
||||||
|
__Ownable_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
function mint(
|
||||||
|
address to,
|
||||||
|
uint256 id,
|
||||||
|
uint256 amount
|
||||||
|
) public virtual {
|
||||||
|
super._mint(to, id, amount, bytes(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user