Skip to content

Instantly share code, notes, and snippets.

@ashwinYardi
Last active January 29, 2024 03:24
Show Gist options
  • Save ashwinYardi/4b711288a1332ed71596419f6a7fbd72 to your computer and use it in GitHub Desktop.
Save ashwinYardi/4b711288a1332ed71596419f6a7fbd72 to your computer and use it in GitHub Desktop.
EIP-1167 clone method
function clone(address implementation) internal returns (address instance) {
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create(0, ptr, 0x37)
}
require(instance != address(0), "ERC1167: create failed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment