Skip to content

feat: add uniV4 deployments to supersim #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "contracts/lib/interop-lib"]
path = contracts/lib/interop-lib
url = https://github.com/ethereum-optimism/interop-lib
[submodule "contracts/lib/v4-periphery"]
path = contracts/lib/v4-periphery
url = https://github.com/uniswap/v4-periphery
9 changes: 7 additions & 2 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[profile.default]
src = "src"
test = "test"
optimizer_runs = 1
via_ir = true
Comment on lines +4 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you add these? just curious for my own learning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the v4 contracts are pretty huge. and our genesis script fails since it enforces limits via --sizes. So without optimization, v4 isn't straight up deployable. So they tinkered with the optimizations to just get the bytecode to the right size.

We could remove the limits in our scripts so that we don't need any of this

script = "script"
out = "out"
libs = ["lib"]
Expand All @@ -13,8 +15,11 @@ remappings = [
"@contracts-bedrock-interfaces/=lib/optimism/packages/contracts-bedrock/interfaces/",
"@solady-v0.0.245/=lib/optimism/packages/contracts-bedrock/lib/solady-v0.0.245/src/",
"@solady/=lib/optimism/packages/contracts-bedrock/lib/solady/src/",
"@openzeppelin/contracts=lib/optimism/packages/contracts-bedrock/lib/openzeppelin-contracts/contracts",
"@interop-lib/=lib/interop-lib/src/"
"@openzeppelin/contracts/=lib/optimism/packages/contracts-bedrock/lib/openzeppelin-contracts/contracts",
"@interop-lib/=lib/interop-lib/src/",
"@permit2/=lib/v4-periphery/lib/permit2/src",
"@uniswap-v4-core/=lib/v4-periphery/lib/v4-core/src",
"@uniswap-v4-periphery/=lib/v4-periphery/src",
]

[rpc_endpoints]
Expand Down
1 change: 1 addition & 0 deletions contracts/lib/v4-periphery
Submodule v4-periphery added at ad04c9
109 changes: 109 additions & 0 deletions contracts/script/DeployL2AuxiliaryContracts.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {Script, console} from "forge-std/Script.sol";

import {PoolManager} from "@uniswap-v4-core/PoolManager.sol";
import {IPoolManager} from "@uniswap-v4-core/interfaces/IPoolManager.sol";
import {Currency} from "@uniswap-v4-core/types/Currency.sol";

import {PositionManager} from "@uniswap-v4-periphery/PositionManager.sol";
import {PositionDescriptor} from "@uniswap-v4-periphery/PositionDescriptor.sol";
import {StateView} from "@uniswap-v4-periphery/lens/StateView.sol";
import {V4Router} from "@uniswap-v4-periphery/V4Router.sol";

import {Predeploys} from "@contracts-bedrock/libraries/Predeploys.sol";
import {Preinstalls} from "@contracts-bedrock/libraries/Preinstalls.sol";

import {Router} from "../src/uniswap/Router.sol";

interface ICreate2Deployer {
function computeAddress(bytes32 salt, bytes32 codeHash) external view returns (address);
function deploy(uint256 value, bytes32 salt, bytes memory code) external;
}

contract DeployL2AuxilliaryContracts is Script {
/// @notice Permit2 address.
address _permit2 = Preinstalls.Permit2;

/// @notice Create2 deployer address.
ICreate2Deployer internal constant _deployer = ICreate2Deployer(Preinstalls.Create2Deployer);

/// @notice Create2Deployer creationCode.
bytes internal constant _deployerCode =
hex"6080604052600436106100435760003560e01c8063076c37b21461004f578063481286e61461007157806356299481146100ba57806366cfa057146100da57600080fd5b3661004a57005b600080fd5b34801561005b57600080fd5b5061006f61006a366004610327565b6100fa565b005b34801561007d57600080fd5b5061009161008c366004610327565b61014a565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b3480156100c657600080fd5b506100916100d5366004610349565b61015d565b3480156100e657600080fd5b5061006f6100f53660046103ca565b610172565b61014582826040518060200161010f9061031a565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe082820381018352601f90910116604052610183565b505050565b600061015683836102e7565b9392505050565b600061016a8484846102f0565b949350505050565b61017d838383610183565b50505050565b6000834710156101f4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f437265617465323a20696e73756666696369656e742062616c616e636500000060448201526064015b60405180910390fd5b815160000361025f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f437265617465323a2062797465636f6465206c656e677468206973207a65726f60448201526064016101eb565b8282516020840186f5905073ffffffffffffffffffffffffffffffffffffffff8116610156576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f437265617465323a204661696c6564206f6e206465706c6f790000000000000060448201526064016101eb565b60006101568383305b6000604051836040820152846020820152828152600b8101905060ff815360559020949350505050565b61014e806104ad83390190565b6000806040838503121561033a57600080fd5b50508035926020909101359150565b60008060006060848603121561035e57600080fd5b8335925060208401359150604084013573ffffffffffffffffffffffffffffffffffffffff8116811461039057600080fd5b809150509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000806000606084860312156103df57600080fd5b8335925060208401359150604084013567ffffffffffffffff8082111561040557600080fd5b818601915086601f83011261041957600080fd5b81358181111561042b5761042b61039b565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019083821181831017156104715761047161039b565b8160405282815289602084870101111561048a57600080fd5b826020860160208301376000602084830101528095505050505050925092509256fe608060405234801561001057600080fd5b5061012e806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063249cb3fa14602d575b600080fd5b603c603836600460b1565b604e565b60405190815260200160405180910390f35b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915281205460ff16608857600060aa565b7fa2ef4600d742022d532d4747cb3547474667d6f13804902513b2ec01c848f4b45b9392505050565b6000806040838503121560c357600080fd5b82359150602083013573ffffffffffffffffffffffffffffffffffffffff8116811460ed57600080fd5b80915050925092905056fea26469706673582212205ffd4e6cede7d06a5daf93d48d0541fc68189eeb16608c1999a82063b666eb1164736f6c63430008130033a2646970667358221220fdc4a0fe96e3b21c108ca155438d37c9143fb01278a3c1d274948bad89c564ba64736f6c63430008130033";

/// @notice Salt used for all create2 deployments
bytes32 internal constant _salt = bytes32(0);

function run() public {
// setup the create2 deployer
vm.etch(address(_deployer), _deployerCode);

console.log("Deploying L2AuxilliaryContracts");
deployUniswapV4();
}

function deployUniswapV4() public {
console.log("Deploying UniswapV4");

PoolManager poolManager = deployUniswapV4PoolManager();
console.log("PoolManager deployed at", address(poolManager));

// omit logging the descriptor as an implementation detail
PositionDescriptor positionDescriptor = deployUniswapV4PositionDescriptor(address(poolManager));
PositionManager positionManager =
deployUniswapV4PositionManager(address(poolManager), address(positionDescriptor));
console.log("PositionManager deployed at", address(positionManager));

StateView stateView = deployUniswapStateView(address(poolManager));
console.log("StateView deployed at", address(stateView));

V4Router router = deployUniswapV4Router(address(poolManager));
console.log("Router deployed at", address(router));
}

function deployUniswapV4PoolManager() internal returns (PoolManager) {
bytes memory args = abi.encode(address(0));
bytes memory initcode = abi.encodePacked(type(PoolManager).creationCode, args);

address addr = _deployer.computeAddress(_salt, keccak256(initcode));
_deployer.deploy(0, _salt, initcode);
return PoolManager(addr);
}

function deployUniswapV4PositionDescriptor(address _manager) internal returns (PositionDescriptor) {
bytes memory args = abi.encode(_manager, Predeploys.WETH, "ETH");
bytes memory initcode = abi.encodePacked(type(PositionDescriptor).creationCode, args);
address addr = _deployer.computeAddress(_salt, keccak256(initcode));
_deployer.deploy(0, _salt, initcode);
return PositionDescriptor(addr);
}

function deployUniswapV4PositionManager(address _manager, address _positionsDescriptor)
internal
returns (PositionManager)
{
bytes memory args = abi.encode(_manager, _permit2, 300_000, _positionsDescriptor, Predeploys.WETH);
bytes memory initcode = abi.encodePacked(type(PositionManager).creationCode, args);
address addr = _deployer.computeAddress(_salt, keccak256(initcode));
_deployer.deploy(0, _salt, initcode);
return PositionManager(payable(addr));
}

function deployUniswapStateView(address _manager) internal returns (StateView) {
bytes memory args = abi.encode(_manager);
bytes memory initcode = abi.encodePacked(type(StateView).creationCode, args);
address addr = _deployer.computeAddress(_salt, keccak256(initcode));
_deployer.deploy(0, _salt, initcode);
return StateView(addr);
}

function deployUniswapV4Router(address _manager) internal returns (V4Router) {
bytes memory args = abi.encode(_manager);
bytes memory initcode = abi.encodePacked(type(Router).creationCode, args);
address addr = _deployer.computeAddress(_salt, keccak256(initcode));
_deployer.deploy(0, _salt, initcode);
return V4Router(payable(addr));
}
}
2 changes: 1 addition & 1 deletion contracts/src/L2NativeSuperchainERC20.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
pragma solidity ^0.8.25;

import {SuperchainERC20} from "@contracts-bedrock/L2/SuperchainERC20.sol";
import {ISemver} from "@contracts-bedrock-interfaces/universal/ISemver.sol";
Expand Down
42 changes: 42 additions & 0 deletions contracts/src/uniswap/Router.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {ERC20} from "@solady-v0.0.245/tokens/ERC20.sol";

import {Currency} from "@uniswap-v4-core/types/Currency.sol";
import {IPoolManager} from "@uniswap-v4-core/interfaces/IPoolManager.sol";

import {V4Router} from "@uniswap-v4-periphery/V4Router.sol";
import {ReentrancyLock} from "@uniswap-v4-periphery/base/ReentrancyLock.sol";

import {IAllowanceTransfer} from "@permit2/interfaces/IAllowanceTransfer.sol";

import {Predeploys} from "@contracts-bedrock/libraries/Predeploys.sol";
import {Preinstalls} from "@contracts-bedrock/libraries/Preinstalls.sol";

contract Router is V4Router, ReentrancyLock {
/// @notice Permit2 address.
IAllowanceTransfer internal constant _permit2 = IAllowanceTransfer(Preinstalls.Permit2);

constructor(IPoolManager _manager) V4Router(_manager) {}

function executeActions(bytes calldata params) external payable isNotLocked {
_executeActions(params);
}

function msgSender() public view override returns (address) {
return _getLocker();
}

receive() external payable {}

function _pay(Currency token, address payer, uint256 amount) internal override {
if (payer == address(this)) {
token.transfer(address(poolManager), amount);
} else {
// @dev supersim version swaps the permit2 with a direct transferFrom call
//ERC20(Currency.unwrap(token)).transferFrom(payer, address(poolManager), amount);
_permit2.transferFrom(payer, address(poolManager), uint160(amount), Currency.unwrap(token));
}
}
}
12 changes: 6 additions & 6 deletions genesis/generated/900-l1-genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
},
"nonce": "0x0",
"timestamp": "0x68533391",
"timestamp": "0x685ab796",
"extraData": "0x",
"gasLimit": "0x1c9c380",
"difficulty": "0x0",
Expand Down Expand Up @@ -361,7 +361,7 @@
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x000000000000000000003feb7f8765b9341b054eb4671cc47d3e33d1606d0001",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x00000000000000000000000051095eac6e2b6da9811c6febbdd67add79135ce0",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0xdead000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x0000000000000000000000000000000000000000000000006853339100000001",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x000000000000000000000000000000000000000000000000685ab79600000001",
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": "0x00000000000000000000000050a19fef2ae17260798f0a0adf180868844af1a3",
"0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103": "0x000000000000000000000000489d547a66233f1e476d4657cccd753a5629fe8c"
},
Expand Down Expand Up @@ -398,7 +398,7 @@
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x00000000000000000000522b0d266cce6225a8bd3d359d03221e7212bf570001",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x000000000000000000000000ee802cf29f1d865cf754629d660f5be0635ca756",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0xdead000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x0000000000000000000000000000000000000000000000006853339100000001",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x000000000000000000000000000000000000000000000000685ab79600000001",
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": "0x00000000000000000000000050a19fef2ae17260798f0a0adf180868844af1a3",
"0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103": "0x000000000000000000000000f6f324097a98dbeb92ec661c7a87f6586ecb38d3"
},
Expand Down Expand Up @@ -1210,7 +1210,7 @@
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x00000000000000000000e9adb6f1fcf6483303ba1ae5d6d567c81d8d11540001",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x000000000000000000000000222f7ecdd4103e9e5abf27f3e1d4fe4d0149260d",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0xdead000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x0000000000000000000000000000000000000000000000006853339100000001",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x000000000000000000000000000000000000000000000000685ab79600000001",
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": "0x00000000000000000000000050a19fef2ae17260798f0a0adf180868844af1a3",
"0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103": "0x000000000000000000000000cdfa36ba62b6ee90949b9b6168951f9469f9e045"
},
Expand Down Expand Up @@ -1238,7 +1238,7 @@
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x00000000000000000000fac884bb6214e8996e1450c23742340fd8ef82c60001",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x00000000000000000000000077bca78b72fe096e6009847aee0db96b4b516db9",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0xdead000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x0000000000000000000000000000000000000000000000006853339100000001",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x000000000000000000000000000000000000000000000000685ab79600000001",
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": "0x00000000000000000000000050a19fef2ae17260798f0a0adf180868844af1a3",
"0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103": "0x00000000000000000000000061118a6f1bcabdf1f4881c1d8f8fe7664e631625"
},
Expand Down Expand Up @@ -1300,7 +1300,7 @@
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x00000000000000000000c535519f1e5660a2c2fb2b9bb3abac94447f53400001",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x000000000000000000000000bd6b0d1587614c5825c35a7670c947cf5ac1200f",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0xdead000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x0000000000000000000000000000000000000000000000006853339100000001",
"0x0000000000000000000000000000000000000000000000000000000000000006": "0x000000000000000000000000000000000000000000000000685ab79600000001",
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": "0x00000000000000000000000050a19fef2ae17260798f0a0adf180868844af1a3",
"0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103": "0x000000000000000000000000b3b3e30b90e2c400d5b7c1bddcf0a8d2317d2941"
},
Expand Down
Loading