Created
May 12, 2020 10:37
-
-
Save MrChico/73bfb879a231a406bf2d8fd5f6df3d97 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
pragma solidity ^0.6.0; | |
import "../deposit_contract.sol"; | |
contract DepositContractFactory { | |
bool public deployed; | |
uint public deploymentTime; | |
DepositContract depositContract; | |
constructor(uint _deploymentTime) public { | |
deploymentTime = _deploymentTime; | |
} | |
function deploy() external { | |
require(block.timestamp >= deploymentTime, "not yet!"); | |
require(!deployed, "already deployed"); | |
depositContract = new DepositContract(); | |
deployed = true; | |
} | |
} |
And this one adds an extra check on the resulting codehash (if we are not to trust the factory enough):
pragma solidity ^0.6.0;
import "../deposit_contract.sol";
contract DepositContractFactory {
bool public deployed;
uint public immutable deploymentTime;
bytes32 public immutable depositContractHash;
DepositContract public depositContract;
constructor(uint _deploymentTime, bytes32 _depositContractHash) public {
deploymentTime = _deploymentTime;
depositContractHash = _depositContractHash;
}
function deploy() external {
require(block.timestamp >= deploymentTime, "not yet!");
require(!deployed, "already deployed");
depositContract = new DepositContract();
// Soon to be supported as `address(depositContract).codehash`
bytes32 codehash;
assembly {
codehash := extcodehash(depositContract)
}
require(codehash == depositContractHash, "broken!?");
deployed = true;
}
}
Additionally could use CREATE2:
depositContract = new DepositContract{salt = <salt>}();
Export depositContract and use immutable:
👍
Additionally could use CREATE2:
yeah, but the address is already predictable regardless
I reckon actually CREATE2 would be a bad idea if the salt exists in the factory because the contract could be deployed outside the factory.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Export
depositContract
and useimmutable
: