Created
October 17, 2022 22:32
-
-
Save emmaglorypraise/8abbdbaa3de426fe6dfaf51f7f8f8304 to your computer and use it in GitHub Desktop.
A factory contract A deploys a child contract B using create 3. Contract B has a constructor which contains a struct as a parameter. Contract A must send 2 ether to contract B upon deployment. A function is available in contract that cryptographically checks that contract B was deployed by him(Contract A)
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.7; | |
import {Create3} from "./lib.sol"; | |
//https://github.com/0xsequence/create3 - imported library | |
struct Work { | |
uint8 number; | |
} | |
contract Factory { | |
function deploy(bytes32 _salt) public payable returns(address _d) { | |
Work memory w = Work({number: 2}); | |
uint256 eth = 2 ether; | |
_d = Create3.create3( | |
_salt, | |
abi.encodePacked( | |
type(Child).creationCode, | |
abi.encode( | |
w | |
)), eth | |
); | |
} | |
function isMyChlid(bytes32 _salt, address _child) view public returns(bool isMine) { | |
address mine = Create3.addressOf(_salt); | |
if(mine == _child) { | |
isMine = true; | |
} | |
} | |
function AddressIsMine(bytes32 _salt) public view returns(address isMine) { | |
isMine = Create3.addressOf(_salt); | |
} | |
function createSalt(string memory name) pure public returns(bytes32 r) { | |
r = bytes32(abi.encodePacked(name)); | |
} | |
} | |
contract Child { | |
Work w; | |
constructor(Work memory _w) payable { | |
w = _w; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment