Last active
June 7, 2019 12:03
-
-
Save mikhaildobs/b5f18f77269a803b9be1b71c49b522bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @dev Internal function to deploy a proxy contract for linkdrop master | |
* @param _linkdropMaster Address of linkdrop master | |
* @return Proxy contract address | |
*/ | |
function _deployProxy(address payable _linkdropMaster) | |
internal | |
returns (address payable) | |
{ | |
require(!isDeployed(_linkdropMaster), "Deployed"); | |
require(_linkdropMaster != address(0), "Invalid linkdrop master address"); | |
bytes32 salt = keccak256(abi.encodePacked(_linkdropMaster)); | |
bytes memory initcode = getInitcode(); | |
address payable proxy; | |
// deploying proxy contract via create2 opcode | |
assembly { | |
proxy := create2(0, add(initcode, 0x20), mload(initcode), salt) | |
if iszero(extcodesize(proxy)) { revert(0, 0) } | |
} | |
deployed[_linkdropMaster] = proxy; | |
// Initialize owner address, linkdrop master address and master copy version in proxy contract | |
require | |
( | |
ILinkdropCommon(proxy).initialize | |
( | |
address(this), // Owner address | |
_linkdropMaster, // Linkdrop master address | |
masterCopyVersion, | |
chainId | |
), | |
"Failed to initialize" | |
); | |
emit Deployed(_linkdropMaster, proxy, salt, now); | |
return proxy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment