Skip to content

Commit

Permalink
Merge pull request #101 from smart-transaction/feat/deployment-script…
Browse files Browse the repository at this point in the history
…-for-block-time

Modified constructors and added deploy script
  • Loading branch information
TokenTitan authored Dec 16, 2024
2 parents ee6ca07 + e0f8dfa commit c7510ef
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
69 changes: 69 additions & 0 deletions script/examples/BlockTime.s.sol
Original file line number Diff line number Diff line change
@@ -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");
}
}
4 changes: 2 additions & 2 deletions src/utilities/BlockTime.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/TimeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/examples/BlockTime/BlockTimeScheduler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c7510ef

Please sign in to comment.