Skip to content

Instantly share code, notes, and snippets.

@bjoveski
Last active November 12, 2022 22:42
Show Gist options
  • Save bjoveski/e46dc9ad2c89b997b65c38cb05221124 to your computer and use it in GitHub Desktop.
Save bjoveski/e46dc9ad2c89b997b65c38cb05221124 to your computer and use it in GitHub Desktop.
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)
}
}
}
@gitchand
Copy link

gitchand commented Apr 2, 2022

Is init function of Forwarder public used in cloneForwarder? Can you please share code of init function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment