Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal proxy factory #2437

Closed
frangio opened this issue Dec 14, 2020 · 1 comment · Fixed by #2449
Closed

Minimal proxy factory #2437

frangio opened this issue Dec 14, 2020 · 1 comment · Fixed by #2449
Labels
contracts Smart contract code. feature New contracts, functions, or helpers.

Comments

@frangio
Copy link
Contributor

frangio commented Dec 14, 2020

EIP-1167 specifies a Minimal Proxy Contract. It's just a bytecode blob and it would be convenient to wrap it in a factory contract or library. A few people have asked for this.

Consider also including functionality to use create2 for deterministic addresses. See the ProxyFactory contract in OpenZeppelin SDK for reference.

@abcoathup
Copy link
Contributor

There have been a few requests in the forum for a Minimal proxy factory. Having as part of OpenZeppelin Contracts could see more use of minimal proxies.

I created the following example (from: https://forum.openzeppelin.com/t/how-to-compute-the-create2-address-for-a-minimal-proxy/3595/2?u=abcoathup). Though it would need work and tests to be up to Contracts standard.

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/utils/Create2.sol";

contract MinimalProxyFactory {
    event MinimalProxyCreated(address minimalProxy);

    function computeAddress(uint256 salt, address implementation)
        public
        view
        returns (address)
    {
        return
            Create2.computeAddress(
                keccak256(abi.encodePacked(salt)),
                keccak256(getContractCreationCode(implementation)),
                address(this)
            );
    }

    function deploy(
        uint256 salt,
        address implementation
    ) public {
        address minimalProxy = Create2.deploy(
            0,
            keccak256(abi.encodePacked(salt)),
            getContractCreationCode(implementation)
        );
        emit MinimalProxyCreated(minimalProxy);
    }

    function getContractCreationCode(address logic)
        internal
        pure
        returns (bytes memory)
    {
        bytes10 creation = 0x3d602d80600a3d3981f3;
        bytes10 prefix = 0x363d3d373d3d3d363d73;
        bytes20 targetBytes = bytes20(logic);
        bytes15 suffix = 0x5af43d82803e903d91602b57fd5bf3;
        return abi.encodePacked(creation, prefix, targetBytes, suffix);
    }
}

@Amxx Amxx added feature New contracts, functions, or helpers. contracts Smart contract code. labels Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Smart contract code. feature New contracts, functions, or helpers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants