部署demo
This commit is contained in:
@@ -6,20 +6,49 @@ pragma solidity ^0.8.0;
|
|||||||
* @dev 智能合约中的一些内置函数
|
* @dev 智能合约中的一些内置函数
|
||||||
*/
|
*/
|
||||||
contract Solidity {
|
contract Solidity {
|
||||||
|
/**
|
||||||
|
* @dev 计算参数的 ABI 编码。
|
||||||
|
*/
|
||||||
|
function encode() public pure returns (bytes memory) {
|
||||||
|
return abi.encode("initialize()");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 计算参数的紧密打包编码
|
||||||
|
*/
|
||||||
|
function encodePacked() public pure returns (bytes memory) {
|
||||||
|
return abi.encodePacked("initialize()");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 计算函数选择器和参数的 ABI 编码
|
||||||
|
*/
|
||||||
|
function encodeWithSelector() public pure returns (bytes memory) {
|
||||||
|
return abi.encodeWithSelector(0xFFFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 等价于* abi.encodeWithSelector(bytes4(keccak256(signature), …)
|
||||||
|
*/
|
||||||
|
function encodeWithSignature() public pure returns (bytes memory) {
|
||||||
|
return
|
||||||
|
abi.encodeWithSignature(
|
||||||
|
"initialize(string,string)",
|
||||||
|
"TEXT",
|
||||||
|
"DESC"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toBytes(string memory text) public pure returns (bytes memory) {
|
||||||
|
return bytes(text);
|
||||||
|
}
|
||||||
|
|
||||||
// 计算输入的Keccak-256散列
|
// 计算输入的Keccak-256散列
|
||||||
function callKeccak256(bytes memory text)
|
function callKeccak256(bytes memory text) public pure returns (bytes32) {
|
||||||
public
|
|
||||||
pure
|
|
||||||
returns (bytes32 result)
|
|
||||||
{
|
|
||||||
return keccak256(text);
|
return keccak256(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
function callKeccak256(string memory text)
|
function callKeccak256(string memory text) public pure returns (bytes32) {
|
||||||
public
|
|
||||||
pure
|
|
||||||
returns (bytes32 result)
|
|
||||||
{
|
|
||||||
return keccak256(bytes(text));
|
return keccak256(bytes(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/DEMO/tools.sol
Normal file
16
src/DEMO/tools.sol
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
contract Tool {
|
||||||
|
function code() public pure returns (bytes memory) {
|
||||||
|
return
|
||||||
|
abi.encodeWithSignature(
|
||||||
|
"initialize(string,string,uint256,uint8)",
|
||||||
|
abi.encode("MTKM"),
|
||||||
|
abi.encode("MTKM"),
|
||||||
|
abi.encode(11111111),
|
||||||
|
abi.encode(8)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/Proxy/Transparent/AdminContract.sol
Normal file
7
src/Proxy/Transparent/AdminContract.sol
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
|
||||||
|
|
||||||
|
contract AdminContract is ProxyAdmin {}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
pragma solidity ^0.8.0;
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
||||||
|
|
||||||
contract Proxy is TransparentUpgradeableProxy {
|
contract AdminUpgradeabilityProxy is TransparentUpgradeableProxy {
|
||||||
constructor(
|
constructor(
|
||||||
address logic,
|
address logic,
|
||||||
address admin,
|
address admin,
|
||||||
67
src/Proxy/代理合约部署/Admin.json
Executable file
67
src/Proxy/代理合约部署/Admin.json
Executable file
File diff suppressed because one or more lines are too long
0
src/Proxy/Transparent/Admin.sol → src/Proxy/代理合约部署/Admin.sol
Normal file → Executable file
0
src/Proxy/Transparent/Admin.sol → src/Proxy/代理合约部署/Admin.sol
Normal file → Executable file
58
src/Proxy/代理合约部署/AdminUpgradeabilityProxy.json
Executable file
58
src/Proxy/代理合约部署/AdminUpgradeabilityProxy.json
Executable file
File diff suppressed because one or more lines are too long
13
src/Proxy/代理合约部署/AdminUpgradeabilityProxy.sol
Executable file
13
src/Proxy/代理合约部署/AdminUpgradeabilityProxy.sol
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
||||||
|
|
||||||
|
contract AdminUpgradeabilityProxy is TransparentUpgradeableProxy {
|
||||||
|
constructor(
|
||||||
|
address logic,
|
||||||
|
address admin,
|
||||||
|
bytes memory data
|
||||||
|
) payable TransparentUpgradeableProxy(logic, admin, data) {}
|
||||||
|
}
|
||||||
67
src/Proxy/代理合约部署/M15.json
Executable file
67
src/Proxy/代理合约部署/M15.json
Executable file
File diff suppressed because one or more lines are too long
112
src/Proxy/代理合约部署/M15.sol
Executable file
112
src/Proxy/代理合约部署/M15.sol
Executable file
@@ -0,0 +1,112 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";
|
||||||
|
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
|
||||||
|
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";
|
||||||
|
|
||||||
|
contract MyERC1155 is ERC1155Pausable, Ownable {
|
||||||
|
mapping(uint256 => uint256) private _totalSupply;
|
||||||
|
|
||||||
|
string _name;
|
||||||
|
|
||||||
|
string _symbol;
|
||||||
|
|
||||||
|
constructor(string memory name_, string memory symbol_) ERC1155("") {
|
||||||
|
_name = name_;
|
||||||
|
_symbol = symbol_;
|
||||||
|
}
|
||||||
|
|
||||||
|
function name() public view virtual returns (string memory) {
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function symbol() public view virtual returns (string memory) {
|
||||||
|
return _symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mint(
|
||||||
|
address to,
|
||||||
|
uint256 id,
|
||||||
|
uint256 amount,
|
||||||
|
bytes memory data
|
||||||
|
) public virtual onlyOwner {
|
||||||
|
_mint(to, id, amount, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function burn(
|
||||||
|
address account,
|
||||||
|
uint256 id,
|
||||||
|
uint256 value
|
||||||
|
) public virtual onlyOwner {
|
||||||
|
require(
|
||||||
|
account == _msgSender() || isApprovedForAll(account, _msgSender()),
|
||||||
|
"ERC1155: caller is not token owner or approved"
|
||||||
|
);
|
||||||
|
|
||||||
|
_burn(account, id, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function burnBatch(
|
||||||
|
address account,
|
||||||
|
uint256[] memory ids,
|
||||||
|
uint256[] memory values
|
||||||
|
) public virtual onlyOwner {
|
||||||
|
require(
|
||||||
|
account == _msgSender() || isApprovedForAll(account, _msgSender()),
|
||||||
|
"ERC1155: caller is not token owner or approved"
|
||||||
|
);
|
||||||
|
|
||||||
|
_burnBatch(account, ids, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Total amount of tokens in with a given id.
|
||||||
|
*/
|
||||||
|
function totalSupply(uint256 id) public view virtual returns (uint256) {
|
||||||
|
return _totalSupply[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Indicates whether any token exist with a given id, or not.
|
||||||
|
*/
|
||||||
|
function exists(uint256 id) public view virtual returns (bool) {
|
||||||
|
return totalSupply(id) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev See {ERC1155-_beforeTokenTransfer}.
|
||||||
|
*/
|
||||||
|
function _beforeTokenTransfer(
|
||||||
|
address operator,
|
||||||
|
address from,
|
||||||
|
address to,
|
||||||
|
uint256[] memory ids,
|
||||||
|
uint256[] memory amounts,
|
||||||
|
bytes memory data
|
||||||
|
) internal virtual override {
|
||||||
|
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
|
||||||
|
|
||||||
|
if (from == address(0)) {
|
||||||
|
for (uint256 i = 0; i < ids.length; ++i) {
|
||||||
|
_totalSupply[ids[i]] += amounts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to == address(0)) {
|
||||||
|
for (uint256 i = 0; i < ids.length; ++i) {
|
||||||
|
uint256 id = ids[i];
|
||||||
|
uint256 amount = amounts[i];
|
||||||
|
uint256 supply = _totalSupply[id];
|
||||||
|
require(
|
||||||
|
supply >= amount,
|
||||||
|
"ERC1155: burn amount exceeds totalSupply"
|
||||||
|
);
|
||||||
|
unchecked {
|
||||||
|
_totalSupply[id] = supply - amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/Proxy/代理合约部署/new1155-v2.json
Executable file
64
src/Proxy/代理合约部署/new1155-v2.json
Executable file
File diff suppressed because one or more lines are too long
44
src/Proxy/代理合约部署/new1155-v2.sol
Executable file
44
src/Proxy/代理合约部署/new1155-v2.sol
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
constructor(string memory name_, string memory symbol_) {
|
||||||
|
_name = name_;
|
||||||
|
_symbol = 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 {
|
||||||
|
__ERC1155_init(uri_);
|
||||||
|
__Ownable_init();
|
||||||
|
_name = tokenName_;
|
||||||
|
_symbol = symbol_;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mint(
|
||||||
|
address to,
|
||||||
|
uint256 id,
|
||||||
|
uint256 amount
|
||||||
|
) public virtual {
|
||||||
|
super._mint(to, id, amount, bytes(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/Proxy/代理合约部署/newerc20.json
Executable file
64
src/Proxy/代理合约部署/newerc20.json
Executable file
File diff suppressed because one or more lines are too long
43
src/Proxy/代理合约部署/newerc20.sol
Executable file
43
src/Proxy/代理合约部署/newerc20.sol
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
|
||||||
|
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
|
||||||
|
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
|
||||||
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||||
|
|
||||||
|
contract UpgradeableERC20 is
|
||||||
|
ERC20Upgradeable,
|
||||||
|
ERC20BurnableUpgradeable,
|
||||||
|
ERC20PausableUpgradeable,
|
||||||
|
OwnableUpgradeable
|
||||||
|
{
|
||||||
|
uint8 private _decimals;
|
||||||
|
|
||||||
|
function initialize(string memory tokenName_, string memory symbol_, uint256 totalSupply_, uint8 decimals_)
|
||||||
|
public
|
||||||
|
initializer
|
||||||
|
{
|
||||||
|
__ERC20_init(tokenName_, symbol_);
|
||||||
|
__Ownable_init();
|
||||||
|
_decimals = decimals_;
|
||||||
|
super._mint(_msgSender(), (totalSupply_ * (10 ** _decimals)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function decimals() public view virtual override returns (uint8) {
|
||||||
|
return _decimals;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mint(address account, uint256 amount) public virtual onlyOwner {
|
||||||
|
_mint(account, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _beforeTokenTransfer(
|
||||||
|
address from,
|
||||||
|
address to,
|
||||||
|
uint256 amount
|
||||||
|
) internal virtual override(ERC20Upgradeable, ERC20PausableUpgradeable) {
|
||||||
|
super._beforeTokenTransfer(from, to, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/Proxy/代理合约部署/upgradeableERC20.json
Executable file
64
src/Proxy/代理合约部署/upgradeableERC20.json
Executable file
File diff suppressed because one or more lines are too long
43
src/Proxy/代理合约部署/upgradeableERC20.sol
Executable file
43
src/Proxy/代理合约部署/upgradeableERC20.sol
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
|
||||||
|
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
|
||||||
|
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
|
||||||
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||||
|
|
||||||
|
contract UpgradeableERC20 is
|
||||||
|
ERC20Upgradeable,
|
||||||
|
ERC20BurnableUpgradeable,
|
||||||
|
ERC20PausableUpgradeable,
|
||||||
|
OwnableUpgradeable
|
||||||
|
{
|
||||||
|
uint8 private _decimals;
|
||||||
|
|
||||||
|
function initialize(string memory tokenName_, string memory symbol_)
|
||||||
|
public
|
||||||
|
initializer
|
||||||
|
{
|
||||||
|
__ERC20_init(tokenName_, symbol_);
|
||||||
|
__Ownable_init();
|
||||||
|
_decimals = 6;
|
||||||
|
super._mint(_msgSender(), (33333333 * (10**_decimals)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function decimals() public view virtual override returns (uint8) {
|
||||||
|
return _decimals;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mint(address account, uint256 amount) public virtual onlyOwner {
|
||||||
|
_mint(account, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _beforeTokenTransfer(
|
||||||
|
address from,
|
||||||
|
address to,
|
||||||
|
uint256 amount
|
||||||
|
) internal virtual override(ERC20Upgradeable, ERC20PausableUpgradeable) {
|
||||||
|
super._beforeTokenTransfer(from, to, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/Proxy/代理合约部署/未命名.md
Executable file
27
src/Proxy/代理合约部署/未命名.md
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
## 1. 部署Admin合约
|
||||||
|
|
||||||
|
admin合约可以复用的,管理多个代理合约
|
||||||
|
|
||||||
|
## 2. 部署逻辑合约
|
||||||
|
|
||||||
|
## 3. 部署代理合约
|
||||||
|
|
||||||
|
## Admin 合约
|
||||||
|
|
||||||
|
0x9128d8eAc38FDa082c279eC500CE0a7894aC96C1
|
||||||
|
|
||||||
|
## ERC20 合约
|
||||||
|
|
||||||
|
OLD: 0x1270f768833fafc31942E7302FF140c6AdDf8A8C
|
||||||
|
|
||||||
|
NEW: 0xbB39bf57515603419406e3c3852547E6b884B7CC
|
||||||
|
|
||||||
|
|
||||||
|
## 1155
|
||||||
|
0x8c6ec0e994B2029dEdE5f8149f905f5CCc5Ae42B
|
||||||
|
UPGRADE 0xdCF63D0Da8C4362CB9504CA4E55bbABE9f9eD3C9
|
||||||
|
|
||||||
|
## AdminUpgradeabilityProxy
|
||||||
|
|
||||||
|
0x8cb08d8007d0145eca9e7adea2c390c4811d2561
|
||||||
|
0x624Ce28502147014AF4473B48d74b922fF08F45f
|
||||||
Reference in New Issue
Block a user