From e501cca7d5a9ebf611bae4011621e318a045408a Mon Sep 17 00:00:00 2001 From: TokenTitan Date: Tue, 30 Jul 2024 20:29:23 +0530 Subject: [PATCH 1/4] fix: changed import style for consistency --- script/{test => examples}/CronCounter.s.sol | 7 +++---- script/{test => examples}/SelfCheckout.s.sol | 0 test/AssociatedDataStorage.t.sol | 2 +- test/CronCounter.t.sol | 4 ++-- test/FlashLiquidity.t.sol | 3 +-- test/FlashPillTest.t.sol | 4 ++-- test/NoopTurnerTest.t.sol | 4 ++-- test/PnP.t.sol | 6 +++--- test/Sandwich.t.sol | 4 ++-- test/SlippageProtection.t.sol | 2 +- test/examples/CronCounter.sol | 2 +- test/examples/{ => DeFi}/FlashLiquidity.sol | 7 +++++-- test/examples/{ => DeFi}/SwapPool.sol | 4 ++-- test/examples/FlashPill.sol | 4 ++-- test/examples/NoopTurner.sol | 6 +++--- test/examples/PnP.sol | 2 +- test/solve-lib/CronCounterLib.sol | 8 ++++---- test/solve-lib/{ => DeFi}/FlashLiquidityLib.sol | 2 +- test/solve-lib/{ => DeFi}/SlippageProtectionLib.sol | 2 +- test/solve-lib/PnPLib.sol | 8 ++++---- test/utils/MockPositionManager.sol | 2 +- test/utils/MockSwapRouter.sol | 4 ++-- 22 files changed, 44 insertions(+), 43 deletions(-) rename script/{test => examples}/CronCounter.s.sol (84%) rename script/{test => examples}/SelfCheckout.s.sol (100%) rename test/examples/{ => DeFi}/FlashLiquidity.sol (99%) rename test/examples/{ => DeFi}/SwapPool.sol (98%) rename test/solve-lib/{ => DeFi}/FlashLiquidityLib.sol (99%) rename test/solve-lib/{ => DeFi}/SlippageProtectionLib.sol (99%) diff --git a/script/test/CronCounter.s.sol b/script/examples/CronCounter.s.sol similarity index 84% rename from script/test/CronCounter.s.sol rename to script/examples/CronCounter.s.sol index f5e383d..180fd45 100644 --- a/script/test/CronCounter.s.sol +++ b/script/examples/CronCounter.s.sol @@ -5,7 +5,6 @@ pragma solidity 0.8.26; import {Script} from "forge-std/Script.sol"; import {BaseDeployer} from "../BaseDeployer.s.sol"; import {CronCounter} from "test/examples/CronCounter.sol"; -import {MyErc20} from "test/examples/MyErc20.sol"; /* solhint-disable no-console*/ import {console2} from "forge-std/console2.sol"; @@ -51,10 +50,10 @@ contract DeployCronCounter is Script, BaseDeployer { /// @dev Function to perform actual deployment. function chainDeploySmartedContract() private broadcast(_deployerPrivateKey) { - address cronTwoCounter = address(new CronCounter{salt: _salt}(_callBreaker)); + address cronCounter = address(new CronCounter{salt: _salt}(_callBreaker)); - require(_create2addr == cronTwoCounter, "Address mismatch CronCounter"); + require(_create2addr == cronCounter, "Address mismatch CronCounter"); - console2.log("CronCounter deployed at address:", cronTwoCounter, "\n"); + console2.log("CronCounter deployed at address:", cronCounter, "\n"); } } diff --git a/script/test/SelfCheckout.s.sol b/script/examples/SelfCheckout.s.sol similarity index 100% rename from script/test/SelfCheckout.s.sol rename to script/examples/SelfCheckout.s.sol diff --git a/test/AssociatedDataStorage.t.sol b/test/AssociatedDataStorage.t.sol index f2fd5ba..6fee954 100644 --- a/test/AssociatedDataStorage.t.sol +++ b/test/AssociatedDataStorage.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {Test} from "forge-std/Test.sol"; -import {AssociatedDataStorage, AssociatedDataLib} from "../src/CallBreakerTypes.sol"; +import {AssociatedDataStorage, AssociatedDataLib} from "src/CallBreakerTypes.sol"; contract AssociatedDataStorageTest is Test { AssociatedDataStorage assocData; diff --git a/test/CronCounter.t.sol b/test/CronCounter.t.sol index 783679c..15b5ffc 100644 --- a/test/CronCounter.t.sol +++ b/test/CronCounter.t.sol @@ -6,8 +6,8 @@ import "forge-std/Vm.sol"; import "./solve-lib/CronCounterLib.sol"; -import "../src/lamination/Laminator.sol"; -import "../src/timetravel/CallBreaker.sol"; +import "src/lamination/Laminator.sol"; +import "src/timetravel/CallBreaker.sol"; contract CronTest is Test, CronCounterLib { address deployer; diff --git a/test/FlashLiquidity.t.sol b/test/FlashLiquidity.t.sol index 376d38b..2e39ab0 100644 --- a/test/FlashLiquidity.t.sol +++ b/test/FlashLiquidity.t.sol @@ -3,8 +3,7 @@ pragma solidity 0.8.26; import "forge-std/Test.sol"; -import "../src/timetravel/CallBreaker.sol"; -import "../test/solve-lib/FlashLiquidityLib.sol"; +import "test/solve-lib/FlashLiquidityLib.sol"; contract FlashLiquidityTest is Test, FlashLiquidityLib { address deployer; diff --git a/test/FlashPillTest.t.sol b/test/FlashPillTest.t.sol index b2a9801..961c388 100644 --- a/test/FlashPillTest.t.sol +++ b/test/FlashPillTest.t.sol @@ -3,8 +3,8 @@ pragma solidity 0.8.26; import "forge-std/Test.sol"; -import "../src/timetravel/CallBreaker.sol"; -import "../test/examples/FlashPill.sol"; +import "src/timetravel/CallBreaker.sol"; +import "test/examples/FlashPill.sol"; contract FlashPillTest is Test { CallBreaker private callbreaker; diff --git a/test/NoopTurnerTest.t.sol b/test/NoopTurnerTest.t.sol index 2fa7c7e..4ca73c7 100644 --- a/test/NoopTurnerTest.t.sol +++ b/test/NoopTurnerTest.t.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.26; import "forge-std/Test.sol"; -import "../src/timetravel/CallBreaker.sol"; -import "../test/examples/NoopTurner.sol"; +import "src/timetravel/CallBreaker.sol"; +import "test/examples/NoopTurner.sol"; contract NoopTurnerTest is Test { CallBreaker public callbreaker; diff --git a/test/PnP.t.sol b/test/PnP.t.sol index ef47df1..2769b74 100644 --- a/test/PnP.t.sol +++ b/test/PnP.t.sol @@ -3,9 +3,9 @@ pragma solidity 0.8.26; import "forge-std/Test.sol"; -import "../src/timetravel/CallBreaker.sol"; -import "../test/examples/PnP.sol"; -import "../test/solve-lib/PnPLib.sol"; +import "src/timetravel/CallBreaker.sol"; +import "test/examples/PnP.sol"; +import "test/solve-lib/PnPLib.sol"; contract PnPTest is Test, PnPLib { address deployer; diff --git a/test/Sandwich.t.sol b/test/Sandwich.t.sol index e523e01..9cb2478 100644 --- a/test/Sandwich.t.sol +++ b/test/Sandwich.t.sol @@ -6,8 +6,8 @@ import "forge-std/Vm.sol"; import "./solve-lib/CronCounterLib.sol"; -import "../src/lamination/Laminator.sol"; -import "../src/timetravel/CallBreaker.sol"; +import "src/lamination/Laminator.sol"; +import "src/timetravel/CallBreaker.sol"; contract CronTest is Test, CronCounterLib { address deployer; diff --git a/test/SlippageProtection.t.sol b/test/SlippageProtection.t.sol index 34a08ac..6d13fe9 100644 --- a/test/SlippageProtection.t.sol +++ b/test/SlippageProtection.t.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.26; import "forge-std/Test.sol"; import "src/timetravel/CallBreaker.sol"; -import "test/solve-lib/SlippageProtectionLib.sol"; +import "test/solve-lib/DeFi/SlippageProtectionLib.sol"; contract SlippageProtectionTest is Test, SlippageProtectionLib { address deployer; diff --git a/test/examples/CronCounter.sol b/test/examples/CronCounter.sol index c7374b8..d0405ae 100644 --- a/test/examples/CronCounter.sol +++ b/test/examples/CronCounter.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.26; -import "../../src/timetravel/SmarterContract.sol"; +import "src/timetravel/SmarterContract.sol"; contract CronCounter is SmarterContract { mapping(address => uint256) private _counters; diff --git a/test/examples/FlashLiquidity.sol b/test/examples/DeFi/FlashLiquidity.sol similarity index 99% rename from test/examples/FlashLiquidity.sol rename to test/examples/DeFi/FlashLiquidity.sol index c998fb2..e8b09fc 100644 --- a/test/examples/FlashLiquidity.sol +++ b/test/examples/DeFi/FlashLiquidity.sol @@ -1,12 +1,14 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.26; +import "forge-std/console.sol"; + import "openzeppelin/token/ERC20/ERC20.sol"; +import "test/utils/interfaces/IWeth.sol"; +import "test/utils/interfaces/ISwapRouter.sol"; import "src/timetravel/CallBreaker.sol"; import "src/timetravel/SmarterContract.sol"; import "src/TimeTypes.sol"; -import "test/utils/interfaces/ISwapRouter.sol"; -import "test/utils/interfaces/IWeth.sol"; address constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; address constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; @@ -67,6 +69,7 @@ contract FlashLiquidity is SmarterContract { // The call to `exactInputSingle` executes the swap. uint256 amountOut = router.exactInputSingle(params); + console.log("WETH", amountOut); // check whether or not CallObject memory callObj = CallObject({ diff --git a/test/examples/SwapPool.sol b/test/examples/DeFi/SwapPool.sol similarity index 98% rename from test/examples/SwapPool.sol rename to test/examples/DeFi/SwapPool.sol index aead196..34abfa8 100644 --- a/test/examples/SwapPool.sol +++ b/test/examples/DeFi/SwapPool.sol @@ -6,8 +6,8 @@ import "src/timetravel/SmarterContract.sol"; import "src/TimeTypes.sol"; import "test/utils/interfaces/ISwapRouter.sol"; -import {IWETH, IERC20} from "../utils/interfaces/IWeth.sol"; -import {IPositionManager} from "../utils/interfaces/IPositionManager.sol"; +import {IWETH, IERC20} from "test/utils/interfaces/IWeth.sol"; +import {IPositionManager} from "test/utils/interfaces/IPositionManager.sol"; // pool fee, 0.3%. uint24 constant poolFee = 3000; diff --git a/test/examples/FlashPill.sol b/test/examples/FlashPill.sol index 1665c13..5599284 100644 --- a/test/examples/FlashPill.sol +++ b/test/examples/FlashPill.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.26; import "openzeppelin/token/ERC20/IERC20.sol"; -import "../../src/timetravel/CallBreaker.sol"; -import "../../src/timetravel/SmarterContract.sol"; +import "src/timetravel/CallBreaker.sol"; +import "src/timetravel/SmarterContract.sol"; contract FlashPill is IERC20, SmarterContract { mapping(address => uint256) private _balances; diff --git a/test/examples/NoopTurner.sol b/test/examples/NoopTurner.sol index 17f4d3e..c74643f 100644 --- a/test/examples/NoopTurner.sol +++ b/test/examples/NoopTurner.sol @@ -2,9 +2,9 @@ pragma solidity 0.8.26; -import "../../src/timetravel/CallBreaker.sol"; -import "../../src/timetravel/SmarterContract.sol"; -import "../../src/TimeTypes.sol"; +import "src/timetravel/CallBreaker.sol"; +import "src/timetravel/SmarterContract.sol"; +import "src/TimeTypes.sol"; contract NoopTurner is SmarterContract { address private _callbreakerAddress; diff --git a/test/examples/PnP.sol b/test/examples/PnP.sol index 9a1756f..9c926fc 100644 --- a/test/examples/PnP.sol +++ b/test/examples/PnP.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.26; -import "../../src/timetravel/CallBreaker.sol"; +import "src/timetravel/CallBreaker.sol"; contract PnP { address private _callbreakerAddress; diff --git a/test/solve-lib/CronCounterLib.sol b/test/solve-lib/CronCounterLib.sol index ebf29a1..e7c0866 100644 --- a/test/solve-lib/CronCounterLib.sol +++ b/test/solve-lib/CronCounterLib.sol @@ -3,10 +3,10 @@ pragma solidity 0.8.26; import "forge-std/Vm.sol"; -import "../../src/lamination/Laminator.sol"; -import "../../src/timetravel/CallBreaker.sol"; -import "../../test/examples/CronCounter.sol"; -import "../../src/timetravel/SmarterContract.sol"; +import "src/lamination/Laminator.sol"; +import "src/timetravel/CallBreaker.sol"; +import "test/examples/CronCounter.sol"; +import "src/timetravel/SmarterContract.sol"; // for the next year, every day: // tip the pusher with a little eth diff --git a/test/solve-lib/FlashLiquidityLib.sol b/test/solve-lib/DeFi/FlashLiquidityLib.sol similarity index 99% rename from test/solve-lib/FlashLiquidityLib.sol rename to test/solve-lib/DeFi/FlashLiquidityLib.sol index 4578484..fc7eae1 100644 --- a/test/solve-lib/FlashLiquidityLib.sol +++ b/test/solve-lib/DeFi/FlashLiquidityLib.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.26; import "src/lamination/Laminator.sol"; import "src/timetravel/CallBreaker.sol"; import "src/timetravel/SmarterContract.sol"; -import "test/examples/SwapPool.sol"; +import "test/examples/DeFi/SwapPool.sol"; import "test/utils/MockERC20Token.sol"; import "test/utils/MockSwapRouter.sol"; import "test/utils/MockPositionManager.sol"; diff --git a/test/solve-lib/SlippageProtectionLib.sol b/test/solve-lib/DeFi/SlippageProtectionLib.sol similarity index 99% rename from test/solve-lib/SlippageProtectionLib.sol rename to test/solve-lib/DeFi/SlippageProtectionLib.sol index 9ac5809..2c1b006 100644 --- a/test/solve-lib/SlippageProtectionLib.sol +++ b/test/solve-lib/DeFi/SlippageProtectionLib.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.26; import "src/lamination/Laminator.sol"; import "src/timetravel/CallBreaker.sol"; -import "test/examples/SwapPool.sol"; +import "test/examples/DeFi/SwapPool.sol"; import "test/utils/MockERC20Token.sol"; import "test/utils/MockSwapRouter.sol"; import "test/utils/MockPositionManager.sol"; diff --git a/test/solve-lib/PnPLib.sol b/test/solve-lib/PnPLib.sol index 2cea968..1e5028a 100644 --- a/test/solve-lib/PnPLib.sol +++ b/test/solve-lib/PnPLib.sol @@ -3,10 +3,10 @@ pragma solidity 0.8.26; import "forge-std/Vm.sol"; -import "../../src/lamination/Laminator.sol"; -import "../../src/timetravel/CallBreaker.sol"; -import "../../test/examples/PnP.sol"; -import "../../src/timetravel/SmarterContract.sol"; +import "src/lamination/Laminator.sol"; +import "src/timetravel/CallBreaker.sol"; +import "src/timetravel/SmarterContract.sol"; +import "test/examples/PnP.sol"; contract PnPLib { address payable public pusherLaminated; diff --git a/test/utils/MockPositionManager.sol b/test/utils/MockPositionManager.sol index dbd7089..c226283 100644 --- a/test/utils/MockPositionManager.sol +++ b/test/utils/MockPositionManager.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.13; import {IPositionManager} from "./interfaces/IPositionManager.sol"; -import {ISwapRouter} from "../utils/interfaces/ISwapRouter.sol"; +import {ISwapRouter} from "./interfaces/ISwapRouter.sol"; /** * @notice Oversimplified mock version of a Position Manager diff --git a/test/utils/MockSwapRouter.sol b/test/utils/MockSwapRouter.sol index c8949f6..be7bcfc 100644 --- a/test/utils/MockSwapRouter.sol +++ b/test/utils/MockSwapRouter.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.26; -import {IWETH, IERC20} from "../utils/interfaces/IWeth.sol"; -import {ISwapRouter} from "../utils/interfaces/ISwapRouter.sol"; +import {IWETH, IERC20} from "./interfaces/IWeth.sol"; +import {ISwapRouter} from "./interfaces/ISwapRouter.sol"; /** * @notice Oversimplified mock version of a router From fefce587cfead24d4857b7d65c2b780d3ed140b3 Mon Sep 17 00:00:00 2001 From: TokenTitan Date: Tue, 30 Jul 2024 20:34:12 +0530 Subject: [PATCH 2/4] refactor: added view to verify solution --- test/FlashLiquidity.t.sol | 2 +- test/examples/DeFi/SwapPool.sol | 2 +- test/examples/MEVOracle/MEVTimeCompute.sol | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/FlashLiquidity.t.sol b/test/FlashLiquidity.t.sol index 2e39ab0..28210ee 100644 --- a/test/FlashLiquidity.t.sol +++ b/test/FlashLiquidity.t.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.26; import "forge-std/Test.sol"; -import "test/solve-lib/FlashLiquidityLib.sol"; +import "test/solve-lib/DeFi/FlashLiquidityLib.sol"; contract FlashLiquidityTest is Test, FlashLiquidityLib { address deployer; diff --git a/test/examples/DeFi/SwapPool.sol b/test/examples/DeFi/SwapPool.sol index 34abfa8..51bd26c 100644 --- a/test/examples/DeFi/SwapPool.sol +++ b/test/examples/DeFi/SwapPool.sol @@ -75,7 +75,7 @@ contract SwapPool is SmarterContract { }); // The call to `exactInputSingle` executes the swap. - uint256 amountOut = router.exactInputSingle(params); + router.exactInputSingle(params); // check whether or not CallObject[] memory callObjs = new CallObject[](1); diff --git a/test/examples/MEVOracle/MEVTimeCompute.sol b/test/examples/MEVOracle/MEVTimeCompute.sol index eab6f9f..815a3f7 100644 --- a/test/examples/MEVOracle/MEVTimeCompute.sol +++ b/test/examples/MEVOracle/MEVTimeCompute.sol @@ -49,7 +49,7 @@ contract MEVTimeCompute is SmarterContract { assertFutureCallTo(callObj, 1); } - function verifySolution() external { + function verifySolution() external view { require(initValue % divisor == 0, "Invalid Solution Provided"); } } From fbb41e436ab8a5b58d2cdaece5dc55fea1648bd9 Mon Sep 17 00:00:00 2001 From: TokenTitan Date: Tue, 30 Jul 2024 20:37:54 +0530 Subject: [PATCH 3/4] feat: added events to MevTimeCompute example --- test/examples/MEVOracle/MEVTimeCompute.sol | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/examples/MEVOracle/MEVTimeCompute.sol b/test/examples/MEVOracle/MEVTimeCompute.sol index 815a3f7..5127383 100644 --- a/test/examples/MEVOracle/MEVTimeCompute.sol +++ b/test/examples/MEVOracle/MEVTimeCompute.sol @@ -10,6 +10,9 @@ contract MEVTimeCompute is SmarterContract { uint256 public initValue; uint256 public divisor; + event InitValueUpdated(); + event DivisorUpdated(); + /** * @notice This is a basic example of performing a computation with a partial function application * At solvetime, the solver can provide an additional value via. associatedData, and the contract @@ -24,6 +27,12 @@ contract MEVTimeCompute is SmarterContract { function setInitValue(uint256 _initValue) external { initValue = _initValue; + emit InitValueUpdated(); + } + + function setDivisor(uint256 _divisor) external { + divisor = _divisor; + emit DivisorUpdated(); } /** From 4ed2093b20ce0e521e723fd9140e44909de95acb Mon Sep 17 00:00:00 2001 From: TokenTitan Date: Tue, 30 Jul 2024 20:44:56 +0530 Subject: [PATCH 4/4] feat: added deployment scripts for FlashLiquidity and MEVTimeOracle --- script/examples/FlashLiquidity.s.sol | 60 +++++++++++++++++++++++++++ script/examples/MEVTimeCompute.s.sol | 62 ++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 script/examples/FlashLiquidity.s.sol create mode 100644 script/examples/MEVTimeCompute.s.sol diff --git a/script/examples/FlashLiquidity.s.sol b/script/examples/FlashLiquidity.s.sol new file mode 100644 index 0000000..287055b --- /dev/null +++ b/script/examples/FlashLiquidity.s.sol @@ -0,0 +1,60 @@ +// 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 {FlashLiquidity} from "test/examples/DeFi/FlashLiquidity.sol"; + +/* solhint-disable no-console*/ +import {console2} from "forge-std/console2.sol"; + +contract DeployFlashLiquidity is Script, BaseDeployer { + address private _callBreaker; + + /// @dev Compute the CREATE2 addresses for contracts (proxy, counter). + /// @param salt The salt for the FlashLiquidity contract. + modifier computeCreate2(bytes32 salt) { + _callBreaker = vm.envAddress("CALL_BREAKER_ADDRESS"); + + _create2addr = computeCreate2Address( + salt, hashInitCode(type(FlashLiquidity).creationCode, abi.encode(_callBreaker, _ownerAddress)) + ); + + _; + } + + /// @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("FlashLiquidity create2 address:", _create2addr, "\n"); + + for (uint256 i; i < deployForks.length;) { + console2.log("Deploying FlashLiquidity to chain: ", uint256(deployForks[i]), "\n"); + + createSelectFork(deployForks[i]); + + chainDeploySmartedContract(); + + unchecked { + ++i; + } + } + return _create2addr; + } + + /// @dev Function to perform actual deployment. + function chainDeploySmartedContract() private broadcast(_deployerPrivateKey) { + address flashLiquidity = address(new FlashLiquidity{salt: _salt}(_callBreaker, _ownerAddress)); + + require(_create2addr == flashLiquidity, "Address mismatch FlashLiquidity"); + + console2.log("FlashLiquidity deployed at address:", flashLiquidity, "\n"); + } +} diff --git a/script/examples/MEVTimeCompute.s.sol b/script/examples/MEVTimeCompute.s.sol new file mode 100644 index 0000000..374f8dc --- /dev/null +++ b/script/examples/MEVTimeCompute.s.sol @@ -0,0 +1,62 @@ +// 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 {MEVTimeCompute} from "test/examples/MEVOracle/MEVTimeCompute.sol"; + +/* solhint-disable no-console*/ +import {console2} from "forge-std/console2.sol"; + +contract DeployMEVTimeCompute is Script, BaseDeployer { + address private _callBreaker; + + /// @dev Compute the CREATE2 addresses for contracts (proxy, counter). + /// @param salt The salt for the MEVTimeCompute contract. + modifier computeCreate2(bytes32 salt) { + _callBreaker = vm.envAddress("CALL_BREAKER_ADDRESS"); + + // passing 8 as a random divisor value for this example, can be updated with setters + _create2addr = computeCreate2Address( + salt, hashInitCode(type(MEVTimeCompute).creationCode, abi.encode(_callBreaker, 8)) + ); + + _; + } + + /// @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("MEVTimeCompute create2 address:", _create2addr, "\n"); + + for (uint256 i; i < deployForks.length;) { + console2.log("Deploying MEVTimeCompute to chain: ", uint256(deployForks[i]), "\n"); + + createSelectFork(deployForks[i]); + + chainDeploySmartedContract(); + + unchecked { + ++i; + } + } + return _create2addr; + } + + /// @dev Function to perform actual deployment. + function chainDeploySmartedContract() private broadcast(_deployerPrivateKey) { + // passing 8 as a random divisor value for this example, can be updated with setters + address mevTimeCompute = address(new MEVTimeCompute{salt: _salt}(_callBreaker, 8)); + + require(_create2addr == mevTimeCompute, "Address mismatch MEVTimeCompute"); + + console2.log("MEVTimeCompute contract deployed at address:", mevTimeCompute, "\n"); + } +}