Verified contractExactGPL-2.0-or-later
HookDeployer
Address0x041ef78a11bfcf92f9a1c031f23aeaebbcc38b03
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.26
- Same code
2 more contracts
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- GPL-2.0-or-later
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,116,248
- Creation transaction
- 0x63ac652dd9…2245bdcd3d
72 files
The source code is large: one file is shown at a time. Choose a file in the list.
- script/DeployFewV4ShellHookWithOwner.s.solmain6.82 KB
- lib/forge-std/src/Base.sol1.79 KB
- lib/forge-std/src/Script.sol832 B
- lib/forge-std/src/StdChains.sol12.8 KB
- lib/forge-std/src/StdCheats.sol31.49 KB
- lib/forge-std/src/StdJson.sol9.7 KB
- lib/forge-std/src/StdMath.sol1.36 KB
- lib/forge-std/src/StdStorage.sol17.84 KB
- lib/forge-std/src/StdStyle.sol10.46 KB
- lib/forge-std/src/StdUtils.sol10.66 KB
- lib/forge-std/src/Vm.sol108.08 KB
- lib/forge-std/src/console.sol69.27 KB
- lib/forge-std/src/console2.sol117 B
- lib/forge-std/src/interfaces/IERC165.sol537 B
- lib/forge-std/src/interfaces/IERC20.sol2.07 KB
- lib/forge-std/src/interfaces/IERC721.sol9.03 KB
- lib/forge-std/src/interfaces/IMulticall3.sol2.19 KB
- lib/forge-std/src/mocks/MockERC20.sol8.32 KB
- lib/forge-std/src/mocks/MockERC721.sol7.9 KB
- lib/forge-std/src/safeconsole.sol427.54 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol3.8 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol5.77 KB
- lib/openzeppelin-contracts/contracts/utils/Address.sol6.26 KB
- lib/v4-core/src/interfaces/IExtsload.sol1.02 KB
- lib/v4-core/src/interfaces/IExttload.sol699 B
- lib/v4-core/src/interfaces/IHooks.sol8.23 KB
- lib/v4-core/src/interfaces/IPoolManager.sol12.84 KB
- lib/v4-core/src/interfaces/IProtocolFees.sol2.49 KB
- lib/v4-core/src/interfaces/external/IERC20Minimal.sol3.04 KB
- lib/v4-core/src/interfaces/external/IERC6909Claims.sol3.16 KB
- lib/v4-core/src/libraries/BitMath.sol2.61 KB
- lib/v4-core/src/libraries/CurrencyReserves.sol1.29 KB
- lib/v4-core/src/libraries/CustomRevert.sol5.17 KB
- lib/v4-core/src/libraries/FixedPoint128.sol297 B
- lib/v4-core/src/libraries/FullMath.sol5.46 KB
- lib/v4-core/src/libraries/Hooks.sol16.51 KB
- lib/v4-core/src/libraries/LPFeeLibrary.sol3.6 KB
- lib/v4-core/src/libraries/LiquidityMath.sol742 B
- lib/v4-core/src/libraries/Lock.sol930 B
- lib/v4-core/src/libraries/NonzeroDeltaCount.sol1.46 KB
- lib/v4-core/src/libraries/ParseBytes.sol1.2 KB
- lib/v4-core/src/libraries/Position.sol4.81 KB
- lib/v4-core/src/libraries/SafeCast.sol2.27 KB
- lib/v4-core/src/libraries/StateLibrary.sol16.03 KB
- lib/v4-core/src/libraries/TickMath.sol12.38 KB
- lib/v4-core/src/libraries/TransientStateLibrary.sol2.36 KB
- lib/v4-core/src/types/BalanceDelta.sol2.34 KB
- lib/v4-core/src/types/BeforeSwapDelta.sol1.47 KB
- lib/v4-core/src/types/Currency.sol5.46 KB
- lib/v4-core/src/types/PoolId.sol539 B
- lib/v4-core/src/types/PoolKey.sol805 B
- lib/v4-core/src/types/PoolOperation.sol907 B
- lib/v4-periphery/src/base/DeltaResolver.sol5.8 KB
- lib/v4-periphery/src/base/ImmutableState.sol818 B
- lib/v4-periphery/src/base/ReentrancyLock.sol521 B
- lib/v4-periphery/src/interfaces/IImmutableState.sol365 B
- lib/v4-periphery/src/interfaces/IMsgSender.sol605 B
- lib/v4-periphery/src/interfaces/IV4Quoter.sol3.37 KB
- lib/v4-periphery/src/interfaces/external/IWETH9.sol364 B
- lib/v4-periphery/src/libraries/ActionConstants.sol1.04 KB
- lib/v4-periphery/src/libraries/Locker.sol734 B
- lib/v4-periphery/src/libraries/PathKey.sol1.37 KB
- lib/v4-periphery/src/utils/BaseHook.sol7.1 KB
- src/FewV4ShellHook.sol23.76 KB
- src/base/LpOwner.sol1.57 KB
- src/base/LpSettlement.sol7.61 KB
- src/interfaces/IAggregatorHook.sol1.84 KB
- src/interfaces/external/IFewFactory.sol450 B
- src/interfaces/external/IFewWrappedToken.sol989 B
- src/libraries/LpPriceLib.sol1.26 KB
- src/libraries/LpRouteLib.sol3.29 KB
script/DeployFewV4ShellHookWithOwner.s.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.26;
import {Script, console2} from "forge-std/Script.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {IV4Quoter} from "v4-periphery/src/interfaces/IV4Quoter.sol";
import {FewV4ShellHook} from "../src/FewV4ShellHook.sol";
import {IFewFactory} from "../src/interfaces/external/IFewFactory.sol";
import {IWETH9} from "v4-periphery/src/interfaces/external/IWETH9.sol";
/// @notice Helper contract that deploys FewV4ShellHook via CREATE2 from itself.
/// The hook owner is set at construction time via the constructor parameter,
/// so no transferOwner step is needed. The CREATE2 address is bound to the
/// owner address, making front-running at the same address impossible — an
/// attacker using a different owner gets a different address.
contract HookDeployer {
/// @dev Deploys the hook via CREATE2. The hook owner is embedded in initCode
/// (as a constructor argument), so the owner is set at construction time.
/// Returns the hook address.
function deployHook(bytes32 salt, bytes memory initCode) external returns (address hookAddr) {
hookAddr = create2(salt, initCode);
require(hookAddr != address(0), "CREATE2 failed");
}
/// @dev Internal CREATE2 deployment.
function create2(bytes32 salt, bytes memory initCode) internal returns (address addr) {
assembly {
let encodedData := add(initCode, 0x20)
let encodedSize := mload(initCode)
addr := create2(0, encodedData, encodedSize, salt)
}
}
}
/// @notice Deploys FewV4ShellHook via a HookDeployer helper with HOOK_OWNER embedded
/// in the hook constructor arguments.
///
/// Required env:
/// HOOK_OWNER - the hook owner set during construction
/// HOOK_SALT - the reviewed CREATE2 salt printed by the mining script
/// EXPECTED_HOOK_ADDRESS - the reviewed Hook address printed by the mining script
///
/// Optional env (defaults are Ethereum mainnet):
/// V4_POOL_MANAGER, FEW_FACTORY, WETH9, V4_QUOTER
contract DeployFewV4ShellHookWithOwner is Script {
address internal constant V4_POOL_MANAGER_DEFAULT = 0x000000000004444c5dc75cB358380D2e3dE08A90;
address internal constant FEW_FACTORY_DEFAULT = 0x7D86394139bf1122E82FDF45Bb4e3b038A4464DD;
address internal constant WETH9_DEFAULT = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant V4_QUOTER_DEFAULT = 0x52F0E24D1c21C8A0cB1e5a5dD6198556BD9E1203;
function run() external {
address poolManagerAddress = vm.envOr("V4_POOL_MANAGER", V4_POOL_MANAGER_DEFAULT);
address factoryAddress = vm.envOr("FEW_FACTORY", FEW_FACTORY_DEFAULT);
address wethAddress = vm.envOr("WETH9", WETH9_DEFAULT);
address v4QuoterAddress = vm.envOr("V4_QUOTER", V4_QUOTER_DEFAULT);
address newOwner = vm.envAddress("HOOK_OWNER");
bytes32 salt = vm.envBytes32("HOOK_SALT");
address reviewedHook = vm.envAddress("EXPECTED_HOOK_ADDRESS");
uint256 deployerPrivateKey = _privateKey();
address deployer = vm.addr(deployerPrivateKey);
bytes memory constructorArgs = abi.encode(
IPoolManager(poolManagerAddress),
IFewFactory(factoryAddress),
IWETH9(wethAddress),
IV4Quoter(v4QuoterAddress),
newOwner
);
bytes memory initCode = abi.encodePacked(type(FewV4ShellHook).creationCode, constructorArgs);
uint160 flags = _flags();
// Compute the HookDeployer's address (deployed via CREATE from deployer's next nonce).
// We need to know this address to mine the hook's CREATE2 address from it.
uint256 deployerNonce = vm.getNonce(deployer);
address deployerAddr = vm.computeCreateAddress(deployer, deployerNonce);
address expectedHook = address(
uint160(uint256(keccak256(abi.encodePacked(bytes1(0xff), deployerAddr, salt, keccak256(initCode)))))
);
require(expectedHook == reviewedHook, "salt/nonce/constructor drift from reviewed Hook");
require(
(uint160(reviewedHook) & uint160(Hooks.ALL_HOOK_MASK)) == flags, "reviewed Hook has wrong permission bits"
);
console2.log("=== FewV4ShellHook deployment (owner in constructor) ===");
console2.log("Deployer: ", deployer);
console2.log("HookDeployer: ", deployerAddr);
console2.log("Owner: ", newOwner);
console2.log("Expected hook: ", expectedHook);
console2.log("Salt:");
console2.logBytes32(salt);
vm.startBroadcast(deployerPrivateKey);
// 1. Deploy the HookDeployer helper (via CREATE, so its address matches deployerAddr).
HookDeployer deployerHelper = new HookDeployer();
require(address(deployerHelper) == deployerAddr, "deployer address mismatch");
// 2. Use the HookDeployer to deploy the hook. Owner is set at construction time.
address hookAddr = deployerHelper.deployHook(salt, initCode);
require(hookAddr == expectedHook, "hook address mismatch");
FewV4ShellHook hook = FewV4ShellHook(payable(hookAddr));
// 3. Verify deployment.
require(address(hook.poolManager()) == poolManagerAddress, "deployed manager mismatch");
require(address(hook.fewFactory()) == factoryAddress, "deployed factory mismatch");
require(address(hook.weth()) == wethAddress, "deployed weth mismatch");
require(address(hook.v4Quoter()) == v4QuoterAddress, "deployed v4Quoter mismatch");
require(hook.owner() == newOwner, "owner should be newOwner");
vm.stopBroadcast();
console2.log("=== Deployment verified (owner set at construction) ===");
console2.log("Hook: ", address(hook));
console2.log("poolManager: ", poolManagerAddress);
console2.log("fewFactory: ", factoryAddress);
console2.log("weth9: ", wethAddress);
console2.log("v4Quoter: ", v4QuoterAddress);
console2.log("Owner: ", hook.owner());
}
function _flags() internal pure returns (uint160) {
return uint160(Hooks.BEFORE_SWAP_FLAG | Hooks.BEFORE_SWAP_RETURNS_DELTA_FLAG | Hooks.BEFORE_INITIALIZE_FLAG);
}
function _privateKey() internal view returns (uint256) {
string memory raw = vm.envString("ETH_PRIVATE_KEY");
bytes memory value = bytes(raw);
if (value.length == 64) return vm.parseUint(string.concat("0x", raw));
require(value.length == 66 && value[0] == "0" && value[1] == "x", "invalid ETH_PRIVATE_KEY");
return vm.parseUint(raw);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"v4-periphery/=lib/v4-periphery/",
"@uniswap/v4-core/=lib/v4-core/",
"permit2/=lib/permit2/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"solmate/=lib/solmate/",
"forge-std/=lib/forge-std/src/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"v4-core/=lib/v4-core/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.