Created
March 14, 2020 11:28
-
-
Save gitpusha/dfa3c5b966d08e72b0f760c7d4cf7467 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
function createTwoGelatoUserProxy( | |
address _mastercopy, | |
bytes memory _initializer, | |
uint256 _saltNonce | |
) | |
public | |
payable | |
override | |
returns(address userProxy) | |
{ | |
// Salt used by GnosisSafeProxyFactory | |
bytes32 salt = keccak256(abi.encodePacked(keccak256(_initializer), _saltNonce)); | |
// Get GnosisSafeProxy.CreationCode used by deployed Factory | |
bytes memory creationCode = factory.proxyCreationCode(); | |
// Derive undeployed userProxy address | |
address predictedAddress = address(uint(keccak256(abi.encodePacked( | |
byte(0xff), | |
address(factory), | |
salt, | |
keccak256(abi.encodePacked(creationCode, _mastercopy)) | |
)))); | |
// Prefund undeployed proxy | |
if (msg.value > 0) payable(predictedAddress).sendValue(msg.value); | |
// Deploy userProxy with create2 | |
userProxy = address(factory.createProxyWithNonce( | |
_mastercopy, | |
_initializer, | |
_saltNonce | |
)); | |
require( | |
userProxy == predictedAddress, | |
"GelatoCore.createTwoGelatoUserProxy: wrong address prediction" | |
); | |
// Map userProxy onto User | |
userByGelatoProxy[userProxy] = msg.sender; | |
gelatoProxyByUser[msg.sender] = userProxy; | |
// Success | |
emit LogGelatoUserProxyCreation(msg.sender, userProxy, msg.value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment