Skip to content
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

feat: Add basic setup code for Diamond Hook #2

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
src = "src"
out = "out"
libs = ["lib"]
solc_version = '0.8.20'
evm_version = "paris"

[profile.ci]
fuzz_runs = 100000
solc = "./lib/v4-core/bin/solc-static-linux"

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 1 addition & 1 deletion lib/periphery-next
2 changes: 1 addition & 1 deletion lib/v4-core
Submodule v4-core updated 138 files
39 changes: 39 additions & 0 deletions src/BaseFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";

abstract contract BaseFactory {
/// @notice zero out all but the first byte of the address which is all 1's
uint160 public constant UNISWAP_FLAG_MASK = 0xff << 152;

// Uniswap hook contracts must have specific flags encoded in the first byte of their address
address public immutable TargetPrefix;

constructor(address _targetPrefix) {
TargetPrefix = _targetPrefix;
}

function deploy(IPoolManager poolManager, bytes32 salt) public virtual returns (address);

function mineDeploy(IPoolManager poolManager) external returns (address) {
return deploy(poolManager, 0);
}

function _computeHookAddress(IPoolManager poolManager, bytes32 salt) internal view returns (address) {
bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, _hashBytecode(poolManager)));
return address(uint160(uint256(hash)));
}

/// @dev The implementing contract must override this function to return the bytecode hash of its contract
/// For example, the CounterHook contract would return:
/// bytecodeHash = keccak256(abi.encodePacked(type(CounterHook).creationCode, abi.encode(poolManager)));
function _hashBytecode(IPoolManager poolManager) internal pure virtual returns (bytes32 bytecodeHash);

function _isPrefix(address _address) internal view returns (bool) {
// zero out all but the first byte of the address
address actualPrefix = address(uint160(_address) & UNISWAP_FLAG_MASK);
return actualPrefix == TargetPrefix;
}
}
14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

Loading