Verified contractPartial
JrnyHook
Address0x8cec12bc7ea6b92cd330b77e163fe5dbde88c0cc
- Balance
0.073978 ETH
- Transactions
18
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,253,533
- Creation transaction
- 0x857cd07677…3858f18ece
63 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/JrnyHook.solmain7.36 KB
- lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol4.05 KB
- lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol148 B
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol12.15 KB
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC20BurnableUpgradeable.sol1.51 KB
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC20PermitUpgradeable.sol3.16 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol1.22 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/NoncesUpgradeable.sol2.35 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/EIP712Upgradeable.sol6.85 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC1967.sol637 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol740 B
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol882 B
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol6.26 KB
- lib/openzeppelin-contracts/contracts/proxy/beacon/IBeacon.sol473 B
- lib/openzeppelin-contracts/contracts/proxy/utils/Initializable.sol9.28 KB
- lib/openzeppelin-contracts/contracts/proxy/utils/UUPSUpgradeable.sol6.32 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol3.81 KB
- lib/openzeppelin-contracts/contracts/utils/Address.sol6.8 KB
- lib/openzeppelin-contracts/contracts/utils/Arrays.sol35.17 KB
- lib/openzeppelin-contracts/contracts/utils/Bytes.sol14.74 KB
- lib/openzeppelin-contracts/contracts/utils/Comparators.sol443 B
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/openzeppelin-contracts/contracts/utils/LowLevelCall.sol5.55 KB
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/openzeppelin-contracts/contracts/utils/SlotDerivation.sol5.32 KB
- lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol4.18 KB
- lib/openzeppelin-contracts/contracts/utils/Strings.sol21.54 KB
- lib/openzeppelin-contracts/contracts/utils/TransientSlot.sol5.08 KB
- lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol12.15 KB
- lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol8.63 KB
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol32.66 KB
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol2.61 KB
- lib/openzeppelin-contracts/contracts/utils/structs/EnumerableMap.sol53.86 KB
- lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol33.3 KB
- lib/uniswap-hooks/lib/v4-core/src/interfaces/IExtsload.sol1.02 KB
- lib/uniswap-hooks/lib/v4-core/src/interfaces/IExttload.sol699 B
- lib/uniswap-hooks/lib/v4-core/src/interfaces/IHooks.sol8.23 KB
- lib/uniswap-hooks/lib/v4-core/src/interfaces/IPoolManager.sol12.84 KB
- lib/uniswap-hooks/lib/v4-core/src/interfaces/IProtocolFees.sol2.49 KB
- lib/uniswap-hooks/lib/v4-core/src/interfaces/external/IERC20Minimal.sol3.04 KB
- lib/uniswap-hooks/lib/v4-core/src/interfaces/external/IERC6909Claims.sol3.16 KB
- lib/uniswap-hooks/lib/v4-core/src/libraries/CustomRevert.sol5.17 KB
- lib/uniswap-hooks/lib/v4-core/src/libraries/Hooks.sol16.51 KB
- lib/uniswap-hooks/lib/v4-core/src/libraries/LPFeeLibrary.sol3.6 KB
- lib/uniswap-hooks/lib/v4-core/src/libraries/ParseBytes.sol1.2 KB
- lib/uniswap-hooks/lib/v4-core/src/libraries/SafeCast.sol2.27 KB
- lib/uniswap-hooks/lib/v4-core/src/types/BalanceDelta.sol2.34 KB
- lib/uniswap-hooks/lib/v4-core/src/types/BeforeSwapDelta.sol1.47 KB
- lib/uniswap-hooks/lib/v4-core/src/types/Currency.sol5.46 KB
- lib/uniswap-hooks/lib/v4-core/src/types/PoolId.sol539 B
- lib/uniswap-hooks/lib/v4-core/src/types/PoolKey.sol805 B
- lib/uniswap-hooks/lib/v4-core/src/types/PoolOperation.sol907 B
- lib/uniswap-hooks/lib/v4-periphery/src/base/ImmutableState.sol818 B
- lib/uniswap-hooks/lib/v4-periphery/src/interfaces/IImmutableState.sol365 B
- lib/uniswap-hooks/lib/v4-periphery/src/utils/BaseHook.sol7.1 KB
- src/JrnyToken.sol2.35 KB
- src/utils/FeeManager.sol15.81 KB
src/JrnyHook.sol
pragma solidity ^0.8.26;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {BaseHook} from "v4-periphery/src/utils/BaseHook.sol";
import {FeeManager} from "./utils/FeeManager.sol";
import {JrnyToken} from "./JrnyToken.sol";
import {BalanceDelta} from "v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta, toBeforeSwapDelta} from "v4-core/src/types/BeforeSwapDelta.sol";
import {Hooks} from "v4-core/src/libraries/Hooks.sol";
import {IPoolManager, SwapParams, ModifyLiquidityParams} from "v4-core/src/interfaces/IPoolManager.sol";
import {PoolKey} from "v4-core/src/types/PoolKey.sol";
contract JrnyHook is BaseHook, FeeManager {
// ── Errors ────────────────────────────────────────────────
error ProtocolFeeTooLarge();
error ProtocolTokenNotSupported();
// ── Variables ─────────────────────────────────────────────
bytes32 private constant HOOK_STORAGE_LOCATION = keccak256(abi.encode(uint256(keccak256("JrnyHook.HookStorage")) - 1)) & ~bytes32(uint256(0xff));
struct HookStorage {
JrnyToken token;
}
// ── Initialization ────────────────────────────────────────
constructor(
IPoolManager _poolManager,
address _tokenAddress,
address _owner
) BaseHook(_poolManager) Ownable(_owner) {
_getStorage().token = JrnyToken(_tokenAddress);
}
// ── External pure ─────────────────────────────────────────
function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
return Hooks.Permissions({
beforeInitialize: false,
afterInitialize: false,
beforeAddLiquidity: false,
afterAddLiquidity: false,
beforeRemoveLiquidity: false,
afterRemoveLiquidity: false,
beforeSwap: true,
afterSwap: true,
beforeDonate: false,
afterDonate: false,
beforeSwapReturnDelta: true,
afterSwapReturnDelta: true,
afterAddLiquidityReturnDelta: false,
afterRemoveLiquidityReturnDelta: false
});
}
// ── Internal state-modifying ──────────────────────────────
function _beforeSwap(
address,
PoolKey calldata key,
SwapParams calldata params,
bytes calldata
) internal override returns (bytes4, BeforeSwapDelta, uint24)
{
if(!key.currency0.isAddressZero()) {
revert ProtocolTokenNotSupported();
}
(uint256 fee, bool isBuy, bool isSell, bool isExactIn, bool isExactOut) = _getContext(params.amountSpecified, params);
BeforeSwapDelta returnDelta = toBeforeSwapDelta(0, 0); // No default delta balance change
// If we are buying Token by paying ETH and we are providing the ETH value
if (isBuy && isExactIn) {
_autoDistributeFees(); // Autodistribute now, before reporting new gathered fee
// Because we know the initial ETH value, we can just collect our fee here and the swap will proceed with X-fee ETH
// in: ETH / out: Token
poolManager.take(key.currency0, address(this), uint256(fee));
_reportFeeGathered(fee);
returnDelta = toBeforeSwapDelta(
int128(uint128(fee)),
0
);
}
// If we are selling Token by receiving ETH and we are providing the ETH value
if (isSell && isExactOut) {
_autoDistributeFees(); // Autodistribute now, before reporting new gathered fee
// Because we know the final ETH value, we can just specify the amount of ETH we are owed. This will inflate the price in Token required to do the swap.
// in: Token / out: ETH
poolManager.take(key.currency0, address(this), fee);
_reportFeeGathered(fee);
returnDelta = toBeforeSwapDelta(
int128(uint128(fee)),
0
);
}
// We do not change LP (third parameter);
return (BaseHook.beforeSwap.selector, returnDelta, 0);
}
function _afterSwap(
address,
PoolKey calldata key,
SwapParams calldata params,
BalanceDelta delta,
bytes calldata
) internal override returns (bytes4, int128) {
if(!key.currency0.isAddressZero()) {
revert ProtocolTokenNotSupported();
}
// We will know if it is the amount of eth/Token based on whether is buy/sell and is exact in/out.
(uint256 fee, bool isBuy, bool isSell, bool isExactIn, bool isExactOut) = _getContext(delta.amount0(), params);
// If we are buying Token by paying ETH and we are providing the Token value
if (isBuy && isExactOut) {
_autoDistributeFees(); // Autodistribute now, before reporting new gathered fee
// We just found out how much ETH we had to pay;
poolManager.take(key.currency0, address(this), fee);
_reportFeeGathered(fee);
return (BaseHook.afterSwap.selector, int128(uint128(fee)));
}
// If we are selling Token by receiving ETH and we are providing the Token value
if (isSell && isExactIn) {
_autoDistributeFees(); // Autodistribute now, before reporting new gathered fee
// We just found out how much ETH we will get for our exactly provided token:
poolManager.take(key.currency0, address(this), fee);
_reportFeeGathered(fee);
return (BaseHook.afterSwap.selector, int128(uint128(fee)));
}
return (BaseHook.afterSwap.selector, int128(0));
}
// ── Internal view ─────────────────────────────────────────
// @dev Access the namespace scoped storage
function _getStorage() private pure returns (HookStorage storage $) {
bytes32 slot = HOOK_STORAGE_LOCATION;
assembly {
$.slot := slot
}
}
// @dev Computes the fee that is owed and translates the params to a readable form
function _getContext(int256 _originalAmount, SwapParams calldata params) internal view returns (uint256 _fee, bool _isBuy, bool _isSell, bool _isExactIn, bool _isExactOut) {
uint256 _amount = _originalAmount < 0 ? uint256(- _originalAmount) : uint256(_originalAmount);
// If this swap is buyToken (ETH->Token)
_isBuy = params.zeroForOne;
_isSell = !params.zeroForOne;
// exactIn if negative and exactOut if positive.
_isExactIn = (params.amountSpecified < 0);
_isExactOut = (params.amountSpecified > 0);
_fee = _amount * _compoundedFee(_isBuy) / 10000;
if (_fee > ((uint256(1) << 127) - 1)) {
revert ProtocolFeeTooLarge();
}
return (_fee, _isBuy, _isSell, _isExactIn, _isExactOut);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/",
"@uniswap/v4-core/=lib/uniswap-hooks/lib/v4-core/",
"@uniswap/v4-periphery/=lib/uniswap-hooks/lib/v4-periphery/",
"@uniswap/universal-router/=lib/universal-router/",
"v4-core/=lib/uniswap-hooks/lib/v4-core/",
"v4-periphery/=lib/uniswap-hooks/lib/v4-periphery/",
"@openzeppelin/uniswap-hooks/=lib/uniswap-hooks/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"hookmate/=lib/hookmate/src/",
"permit2/=lib/uniswap-hooks/lib/v4-periphery/lib/permit2/",
"solmate/=lib/uniswap-hooks/lib/v4-core/lib/solmate/",
"@ensdomains/=lib/uniswap-hooks/lib/v4-core/node_modules/@ensdomains/",
"@uniswap/v2-core/=lib/universal-router/node_modules/@uniswap/v2-core/",
"@uniswap/v3-core/=lib/universal-router/node_modules/@uniswap/v3-core/",
"@uniswap/v3-periphery/=lib/universal-router/lib/v3-periphery/",
"ds-test/=lib/universal-router/lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/universal-router/lib/permit2/lib/forge-gas-snapshot/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"hardhat/=lib/uniswap-hooks/lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"uniswap-hooks/=lib/uniswap-hooks/src/",
"universal-router/=lib/universal-router/",
"v3-periphery/=lib/universal-router/lib/v3-periphery/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.