Last active
November 12, 2022 22:42
-
-
Save bjoveski/e46dc9ad2c89b997b65c38cb05221124 to your computer and use it in GitHub Desktop.
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
contract ForwarderFactory { | |
function cloneForwarder(address forwarder, uint256 salt) | |
public returns (Forwarder clonedForwarder) { | |
address clonedAddress = createClone(forwarder, salt); | |
Forwarder parentForwarder = Forwarder(forwarder); | |
clonedForwarder = Forwarder(clonedAddress); | |
clonedForwarder.init(parentForwarder.destination()); | |
} | |
function createClone(address target, uint256 salt) private returns (address result) { | |
bytes20 targetBytes = bytes20(target); | |
assembly { | |
let clone := mload(0x40) | |
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) | |
mstore(add(clone, 0x14), targetBytes) | |
mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) | |
result := create2(0, clone, 0x37, salt) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is init function of Forwarder public used in cloneForwarder? Can you please share code of init function?