Skip to content

Commit

Permalink
Merge pull request #57 from smart-transaction/scripts/deploy-mev-time…
Browse files Browse the repository at this point in the history
…-compute-and-flash-liquidity

Deploy scripts for MEV time compute and flash liquidity
  • Loading branch information
TokenTitan authored Jul 31, 2024
2 parents 75c86a2 + 4ed2093 commit c1483c7
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
}
}
60 changes: 60 additions & 0 deletions script/examples/FlashLiquidity.s.sol
Original file line number Diff line number Diff line change
@@ -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");
}
}
62 changes: 62 additions & 0 deletions script/examples/MEVTimeCompute.s.sol
Original file line number Diff line number Diff line change
@@ -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");
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion test/AssociatedDataStorage.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/CronCounter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions test/FlashLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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/DeFi/FlashLiquidityLib.sol";

contract FlashLiquidityTest is Test, FlashLiquidityLib {
address deployer;
Expand Down
4 changes: 2 additions & 2 deletions test/FlashPillTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/NoopTurnerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/PnP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/Sandwich.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/SlippageProtection.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/examples/CronCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/examples/FlashPill.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion test/examples/MEVOracle/MEVTimeCompute.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

/**
Expand All @@ -49,7 +58,7 @@ contract MEVTimeCompute is SmarterContract {
assertFutureCallTo(callObj, 1);
}

function verifySolution() external {
function verifySolution() external view {
require(initValue % divisor == 0, "Invalid Solution Provided");
}
}
6 changes: 3 additions & 3 deletions test/examples/NoopTurner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/examples/PnP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.26;

import "../../src/timetravel/CallBreaker.sol";
import "src/timetravel/CallBreaker.sol";

contract PnP {
address private _callbreakerAddress;
Expand Down
8 changes: 4 additions & 4 deletions test/solve-lib/CronCounterLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions test/solve-lib/PnPLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit c1483c7

Please sign in to comment.