diff --git a/script/examples/BlockTime.s.sol b/script/examples/BlockTime.s.sol new file mode 100644 index 0000000..b505ad4 --- /dev/null +++ b/script/examples/BlockTime.s.sol @@ -0,0 +1,69 @@ + +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity 0.8.26; + +import {Script} from "forge-std/Script.sol"; +import {BaseDeployer} from "../BaseDeployer.s.sol"; +import {BlockTime} from "src/utilities/BlockTime.sol"; +import {BlockTimeScheduler} from "test/examples/BlockTime/BlockTimeScheduler.sol"; + +/* solhint-disable no-console*/ +import {console2} from "forge-std/console2.sol"; + +contract DeployBlockTime is Script, BaseDeployer { + address private _callBreaker; + address private _blockTime; + address private _blockTimeScheduler; + + /// @dev Compute the CREATE2 addresses for contracts (proxy, counter). + /// @param salt The salt for the BlockTime contract. + modifier computeCreate2(bytes32 salt) { + _callBreaker = vm.envAddress("CALL_BREAKER_ADDRESS"); + + _blockTime = + computeCreate2Address(salt, hashInitCode(type(BlockTime).creationCode, abi.encode())); + _blockTimeScheduler = + computeCreate2Address(salt, hashInitCode(type(BlockTimeScheduler).creationCode, abi.encode(_callBreaker, _blockTime))); + + _; + } + + /// @dev Helper to iterate over chains and select fork. + /// @param deployForks The chains to deploy to. + /// @return address of the deployed contract + function createDeployMultichain(Chains[] memory deployForks) + internal + override + computeCreate2(_salt) + returns (address) + { + console2.log("BlockTime create2 address:", _blockTime, "\n"); + console2.log("BlockTimeScheduler create2 address:", _blockTimeScheduler, "\n"); + + for (uint256 i; i < deployForks.length;) { + console2.log("Deploying BlockTime and BlockTimeScheduler to chain: ", uint256(deployForks[i]), "\n"); + + createSelectFork(deployForks[i]); + + chainDeployBlockTime(); + + unchecked { + ++i; + } + } + return _blockTime; + } + + /// @dev Function to perform actual deployment. + function chainDeployBlockTime() private broadcast(_deployerPrivateKey) { + address blockTime = address(new BlockTime{salt: _salt}()); + address blockTimeScheduler = address(new BlockTimeScheduler{salt: _salt}(_callBreaker, blockTime)); + + require(_blockTime == blockTime, "Address mismatch BlockTime"); + require(_blockTimeScheduler == blockTimeScheduler, "Address mismatch BlockTimeScheduler"); + + console2.log("BlockTime deployed at address:", blockTime, "\n"); + console2.log("BlockTimeScheduler deployed at address:", blockTimeScheduler, "\n"); + } +} diff --git a/src/utilities/BlockTime.sol b/src/utilities/BlockTime.sol index ac5a248..b6b73ca 100644 --- a/src/utilities/BlockTime.sol +++ b/src/utilities/BlockTime.sol @@ -32,8 +32,8 @@ contract BlockTime is IBlockTime, AccessControl, ReentrancyGuard { event EarthTimeUpdated(uint256 newEarthTime, Chronicle[] chronicles, address[] timeTokenReceivers, uint256[] amounts); event MaxBlockWidthSet(uint256 maxBlockWidth); - constructor(string memory _name, string memory _symbol) { - timeToken = new TimeToken(_name, _symbol, address(this)); + constructor() { + timeToken = new TimeToken(); _grantRole(DEFAULT_ADMIN_ROLE, _msgSender()); _grantRole(ADMIN_ROLE, _msgSender()); } diff --git a/src/utilities/TimeToken.sol b/src/utilities/TimeToken.sol index 89728cb..34bf0aa 100644 --- a/src/utilities/TimeToken.sol +++ b/src/utilities/TimeToken.sol @@ -11,7 +11,7 @@ contract TimeToken is ERC20, Ownable { // Event to log batch minting event BatchMinted(address[] to, uint256[] amounts); - constructor(string memory _name, string memory _symbol, address _blockTime) ERC20(_name, _symbol) Ownable(_blockTime) {} + constructor() ERC20("TimeToken", "TIME") Ownable(msg.sender) {} // Batch mint function /// @dev The onlyOwner modifier will be later changed to execute calls through a governance proposal diff --git a/test/examples/BlockTime/BlockTimeScheduler.sol b/test/examples/BlockTime/BlockTimeScheduler.sol index 127248b..301d46a 100644 --- a/test/examples/BlockTime/BlockTimeScheduler.sol +++ b/test/examples/BlockTime/BlockTimeScheduler.sol @@ -27,7 +27,7 @@ contract BlockTimeScheduler is SmarterContract, Ownable { address public callBreaker; IBlockTime public blockTime; - constructor(address _callBreaker, address _blockTime, address _owner) SmarterContract(_callBreaker) Ownable(_owner) { + constructor(address _callBreaker, address _blockTime) SmarterContract(_callBreaker) Ownable(msg.sender) { callBreaker = _callBreaker; blockTime = IBlockTime(_blockTime); shouldContinue = true;