Last active
March 29, 2022 22:18
-
-
Save Turupawn/344eed273afe9bf0e8becedebfdafa94 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.13; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
contract TimelockDemo { | |
} | |
contract MyERC20 is ERC20 { | |
constructor (string memory name, string memory symbol, uint supply, address creator) ERC20(name, symbol) { | |
TimelockDemo timelock_demo = new TimelockDemo(); | |
_mint(address(timelock_demo), supply * 8500 / 10000); | |
_mint(creator, supply * 1500 / 10000); | |
} | |
} | |
contract MyContract { | |
string public hello; | |
uint public world; | |
constructor(string memory _hello, uint _world) | |
{ | |
hello = _hello; | |
world = _world; | |
} | |
} | |
contract Factory | |
{ | |
address public new_contract_address; | |
function createContract(string memory hello, uint256 world) public returns(address) | |
{ | |
MyContract new_contract = new MyContract(hello, world); | |
new_contract_address = address(new_contract); | |
return address(new_contract); | |
} | |
function createToken(string memory name, string memory symbol, uint supply, address creator) public returns(address) | |
{ | |
MyERC20 token_contract = new MyERC20(name, symbol, supply, creator); | |
new_contract_address = address(token_contract); | |
return address(token_contract); | |
} | |
} | |
contract Maestro { | |
bytes public my_calldata; | |
address public new_contract_address; | |
function getCalldata(string memory param1, uint param2) public pure returns(bytes memory) | |
{ | |
bytes4 signature = bytes4(keccak256("createContract(string,uint256)")); | |
return abi.encodeWithSelector(signature, param1, param2); | |
} | |
function launch(address factory_address, bytes calldata data) public | |
{ | |
(bool success, bytes memory returnData) = address(factory_address).call(data); | |
require(success, "low-level call failed"); | |
new_contract_address = bytesToAddress(returnData); | |
} | |
function bytesToAddress(bytes memory bys) private pure returns (address addr) { | |
assembly { | |
addr := mload(add(bys,32)) | |
} | |
} | |
} | |
/* | |
web3.eth.abi.encodeFunctionCall({ | |
name: 'createToken', | |
type: 'function', | |
inputs: [{ | |
type: 'string', | |
name: 'name' | |
},{ | |
type: 'string', | |
name: 'symbol' | |
},{ | |
type: 'uint256', | |
name: 'supply' | |
},{ | |
type: 'address', | |
name: 'creator' | |
}] | |
}, ['Mi token', 'MT', '1000000000000000000000000', '0xb6F5414bAb8d5ad8F33E37591C02f7284E974FcB']); | |
/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment