Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
PoolModifyLiquidityTest
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 44444444 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; import {CurrencyLibrary, Currency} from "../types/Currency.sol"; import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {BalanceDelta} from "../types/BalanceDelta.sol"; import {PoolKey} from "../types/PoolKey.sol"; import {PoolTestBase} from "./PoolTestBase.sol"; import {IHooks} from "../interfaces/IHooks.sol"; import {Hooks} from "../libraries/Hooks.sol"; import {LPFeeLibrary} from "../libraries/LPFeeLibrary.sol"; import {CurrencySettler} from "../../test/utils/CurrencySettler.sol"; import {StateLibrary} from "../libraries/StateLibrary.sol"; contract PoolModifyLiquidityTest is PoolTestBase { using CurrencySettler for Currency; using Hooks for IHooks; using LPFeeLibrary for uint24; using StateLibrary for IPoolManager; constructor(IPoolManager _manager) PoolTestBase(_manager) {} struct CallbackData { address sender; PoolKey key; IPoolManager.ModifyLiquidityParams params; bytes hookData; bool settleUsingBurn; bool takeClaims; } function modifyLiquidity( PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, bytes memory hookData ) external payable returns (BalanceDelta delta) { delta = modifyLiquidity(key, params, hookData, false, false); } function modifyLiquidity( PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, bytes memory hookData, bool settleUsingBurn, bool takeClaims ) public payable returns (BalanceDelta delta) { delta = abi.decode( manager.unlock(abi.encode(CallbackData(msg.sender, key, params, hookData, settleUsingBurn, takeClaims))), (BalanceDelta) ); uint256 ethBalance = address(this).balance; if (ethBalance > 0) { CurrencyLibrary.ADDRESS_ZERO.transfer(msg.sender, ethBalance); } } function unlockCallback(bytes calldata rawData) external returns (bytes memory) { require(msg.sender == address(manager)); CallbackData memory data = abi.decode(rawData, (CallbackData)); (uint128 liquidityBefore,,) = manager.getPositionInfo( data.key.toId(), address(this), data.params.tickLower, data.params.tickUpper, data.params.salt ); (BalanceDelta delta,) = manager.modifyLiquidity(data.key, data.params, data.hookData); (uint128 liquidityAfter,,) = manager.getPositionInfo( data.key.toId(), address(this), data.params.tickLower, data.params.tickUpper, data.params.salt ); (,, int256 delta0) = _fetchBalances(data.key.currency0, data.sender, address(this)); (,, int256 delta1) = _fetchBalances(data.key.currency1, data.sender, address(this)); require( int128(liquidityBefore) + data.params.liquidityDelta == int128(liquidityAfter), "liquidity change incorrect" ); if (data.params.liquidityDelta < 0) { assert(delta0 > 0 || delta1 > 0); assert(!(delta0 < 0 || delta1 < 0)); } else if (data.params.liquidityDelta > 0) { assert(delta0 < 0 || delta1 < 0); assert(!(delta0 > 0 || delta1 > 0)); } if (delta0 < 0) data.key.currency0.settle(manager, data.sender, uint256(-delta0), data.settleUsingBurn); if (delta1 < 0) data.key.currency1.settle(manager, data.sender, uint256(-delta1), data.settleUsingBurn); if (delta0 > 0) data.key.currency0.take(manager, data.sender, uint256(delta0), data.takeClaims); if (delta1 > 0) data.key.currency1.take(manager, data.sender, uint256(delta1), data.takeClaims); return abi.encode(delta); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {IERC20Minimal} from "../interfaces/external/IERC20Minimal.sol"; import {CustomRevert} from "../libraries/CustomRevert.sol"; type Currency is address; using {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global; using CurrencyLibrary for Currency global; function equals(Currency currency, Currency other) pure returns (bool) { return Currency.unwrap(currency) == Currency.unwrap(other); } function greaterThan(Currency currency, Currency other) pure returns (bool) { return Currency.unwrap(currency) > Currency.unwrap(other); } function lessThan(Currency currency, Currency other) pure returns (bool) { return Currency.unwrap(currency) < Currency.unwrap(other); } function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) { return Currency.unwrap(currency) >= Currency.unwrap(other); } /// @title CurrencyLibrary /// @dev This library allows for transferring and holding native tokens and ERC20 tokens library CurrencyLibrary { using CustomRevert for bytes4; /// @notice Thrown when a native transfer fails /// @param reason bubbled up revert reason error Wrap__NativeTransferFailed(address recipient, bytes reason); /// @notice Thrown when an ERC20 transfer fails /// @param reason bubbled up revert reason error Wrap__ERC20TransferFailed(address token, bytes reason); /// @notice A constant to represent the native currency Currency public constant ADDRESS_ZERO = Currency.wrap(address(0)); function transfer(Currency currency, address to, uint256 amount) internal { // altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol // modified custom error selectors bool success; if (currency.isAddressZero()) { assembly ("memory-safe") { // Transfer the ETH and revert if it fails. success := call(gas(), to, amount, 0, 0, 0, 0) } // revert with NativeTransferFailed, containing the bubbled up error as an argument if (!success) Wrap__NativeTransferFailed.selector.bubbleUpAndRevertWith(to); } else { assembly ("memory-safe") { // Get a pointer to some free memory. let fmp := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument. mstore(add(fmp, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), currency, 0, fmp, 68, 0, 32) ) // Now clean the memory we used mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here } // revert with ERC20TransferFailed, containing the bubbled up error as an argument if (!success) Wrap__ERC20TransferFailed.selector.bubbleUpAndRevertWith(Currency.unwrap(currency)); } } function balanceOfSelf(Currency currency) internal view returns (uint256) { if (currency.isAddressZero()) { return address(this).balance; } else { return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this)); } } function balanceOf(Currency currency, address owner) internal view returns (uint256) { if (currency.isAddressZero()) { return owner.balance; } else { return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner); } } function isAddressZero(Currency currency) internal pure returns (bool) { return Currency.unwrap(currency) == Currency.unwrap(ADDRESS_ZERO); } function toId(Currency currency) internal pure returns (uint256) { return uint160(Currency.unwrap(currency)); } // If the upper 12 bytes are non-zero, they will be zero-ed out // Therefore, fromId() and toId() are not inverses of each other function fromId(uint256 id) internal pure returns (Currency) { return Currency.wrap(address(uint160(id))); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {Currency} from "../types/Currency.sol"; import {PoolKey} from "../types/PoolKey.sol"; import {IHooks} from "./IHooks.sol"; import {IERC6909Claims} from "./external/IERC6909Claims.sol"; import {IProtocolFees} from "./IProtocolFees.sol"; import {BalanceDelta} from "../types/BalanceDelta.sol"; import {PoolId} from "../types/PoolId.sol"; import {IExtsload} from "./IExtsload.sol"; import {IExttload} from "./IExttload.sol"; /// @notice Interface for the PoolManager interface IPoolManager is IProtocolFees, IERC6909Claims, IExtsload, IExttload { /// @notice Thrown when a currency is not netted out after the contract is unlocked error CurrencyNotSettled(); /// @notice Thrown when trying to interact with a non-initialized pool error PoolNotInitialized(); /// @notice Thrown when unlock is called, but the contract is already unlocked error AlreadyUnlocked(); /// @notice Thrown when a function is called that requires the contract to be unlocked, but it is not error ManagerLocked(); /// @notice Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow error TickSpacingTooLarge(int24 tickSpacing); /// @notice Pools must have a positive non-zero tickSpacing passed to #initialize error TickSpacingTooSmall(int24 tickSpacing); /// @notice PoolKey must have currencies where address(currency0) < address(currency1) error CurrenciesOutOfOrderOrEqual(address currency0, address currency1); /// @notice Thrown when a call to updateDynamicLPFee is made by an address that is not the hook, /// or on a pool that does not have a dynamic swap fee. error UnauthorizedDynamicLPFeeUpdate(); /// @notice Thrown when trying to swap amount of 0 error SwapAmountCannotBeZero(); ///@notice Thrown when native currency is passed to a non native settlement error NonzeroNativeValue(); /// @notice Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta. error MustClearExactPositiveDelta(); /// @notice Emitted when a new pool is initialized /// @param id The abi encoded hash of the pool key struct for the new pool /// @param currency0 The first currency of the pool by address sort order /// @param currency1 The second currency of the pool by address sort order /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @param tickSpacing The minimum number of ticks between initialized ticks /// @param hooks The hooks contract address for the pool, or address(0) if none /// @param sqrtPriceX96 The price of the pool on initialization /// @param tick The initial tick of the pool corresponding to the intialized price event Initialize( PoolId indexed id, Currency indexed currency0, Currency indexed currency1, uint24 fee, int24 tickSpacing, IHooks hooks, uint160 sqrtPriceX96, int24 tick ); /// @notice Emitted when a liquidity position is modified /// @param id The abi encoded hash of the pool key struct for the pool that was modified /// @param sender The address that modified the pool /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param liquidityDelta The amount of liquidity that was added or removed /// @param salt The extra data to make positions unique event ModifyLiquidity( PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt ); /// @notice Emitted for swaps between currency0 and currency1 /// @param id The abi encoded hash of the pool key struct for the pool that was modified /// @param sender The address that initiated the swap call, and that received the callback /// @param amount0 The delta of the currency0 balance of the pool /// @param amount1 The delta of the currency1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of the price of the pool after the swap /// @param fee The swap fee in hundredths of a bip event Swap( PoolId indexed id, address indexed sender, int128 amount0, int128 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick, uint24 fee ); /// @notice Emitted for donations /// @param id The abi encoded hash of the pool key struct for the pool that was donated to /// @param sender The address that initiated the donate call /// @param amount0 The amount donated in currency0 /// @param amount1 The amount donated in currency1 event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1); /// @notice All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement /// `IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract. /// @dev The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee` /// @param data Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)` /// @return The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)` function unlock(bytes calldata data) external returns (bytes memory); /// @notice Initialize the state for a given pool ID /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee /// @param key The pool key for the pool to initialize /// @param sqrtPriceX96 The initial square root price /// @return tick The initial tick of the pool function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick); struct ModifyLiquidityParams { // the lower and upper tick of the position int24 tickLower; int24 tickUpper; // how to modify the liquidity int256 liquidityDelta; // a value to set if you want unique liquidity positions at the same range bytes32 salt; } /// @notice Modify the liquidity for the given pool /// @dev Poke by calling with a zero liquidityDelta /// @param key The pool to modify liquidity in /// @param params The parameters for modifying the liquidity /// @param hookData The data to pass through to the add/removeLiquidity hooks /// @return callerDelta The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable /// @return feesAccrued The balance delta of the fees generated in the liquidity range. Returned for informational purposes function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData) external returns (BalanceDelta callerDelta, BalanceDelta feesAccrued); struct SwapParams { /// Whether to swap token0 for token1 or vice versa bool zeroForOne; /// The desired input amount if negative (exactIn), or the desired output amount if positive (exactOut) int256 amountSpecified; /// The sqrt price at which, if reached, the swap will stop executing uint160 sqrtPriceLimitX96; } /// @notice Swap against the given pool /// @param key The pool to swap in /// @param params The parameters for swapping /// @param hookData The data to pass through to the swap hooks /// @return swapDelta The balance delta of the address swapping /// @dev Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified. /// Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG /// the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta. function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData) external returns (BalanceDelta swapDelta); /// @notice Donate the given currency amounts to the in-range liquidity providers of a pool /// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds. /// Donors should keep this in mind when designing donation mechanisms. /// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of /// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to /// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)). /// Read the comments in `Pool.swap()` for more information about this. /// @param key The key of the pool to donate to /// @param amount0 The amount of currency0 to donate /// @param amount1 The amount of currency1 to donate /// @param hookData The data to pass through to the donate hooks /// @return BalanceDelta The delta of the caller after the donate function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) external returns (BalanceDelta); /// @notice Writes the current ERC20 balance of the specified currency to transient storage /// This is used to checkpoint balances for the manager and derive deltas for the caller. /// @dev This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped /// for native tokens because the amount to settle is determined by the sent value. /// However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle /// native funds, this function can be called with the native currency to then be able to settle the native currency function sync(Currency currency) external; /// @notice Called by the user to net out some value owed to the user /// @dev Can also be used as a mechanism for _free_ flash loans /// @param currency The currency to withdraw from the pool manager /// @param to The address to withdraw to /// @param amount The amount of currency to withdraw function take(Currency currency, address to, uint256 amount) external; /// @notice Called by the user to pay what is owed /// @return paid The amount of currency settled function settle() external payable returns (uint256 paid); /// @notice Called by the user to pay on behalf of another address /// @param recipient The address to credit for the payment /// @return paid The amount of currency settled function settleFor(address recipient) external payable returns (uint256 paid); /// @notice WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently. /// A call to clear will zero out a positive balance WITHOUT a corresponding transfer. /// @dev This could be used to clear a balance that is considered dust. /// Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared. function clear(Currency currency, uint256 amount) external; /// @notice Called by the user to move value into ERC6909 balance /// @param to The address to mint the tokens to /// @param id The currency address to mint to ERC6909s, as a uint256 /// @param amount The amount of currency to mint /// @dev The id is converted to a uint160 to correspond to a currency address /// If the upper 12 bytes are not 0, they will be 0-ed out function mint(address to, uint256 id, uint256 amount) external; /// @notice Called by the user to move value from ERC6909 balance /// @param from The address to burn the tokens from /// @param id The currency address to burn from ERC6909s, as a uint256 /// @param amount The amount of currency to burn /// @dev The id is converted to a uint160 to correspond to a currency address /// If the upper 12 bytes are not 0, they will be 0-ed out function burn(address from, uint256 id, uint256 amount) external; /// @notice Updates the pools lp fees for the a pool that has enabled dynamic lp fees. /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee /// @param key The key of the pool to update dynamic LP fees for /// @param newDynamicLPFee The new dynamic pool LP fee function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {SafeCast} from "../libraries/SafeCast.sol"; /// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0 /// and the lower 128 bits represent the amount1. type BalanceDelta is int256; using {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global; using BalanceDeltaLibrary for BalanceDelta global; using SafeCast for int256; function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) { assembly ("memory-safe") { balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1)) } } function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) { int256 res0; int256 res1; assembly ("memory-safe") { let a0 := sar(128, a) let a1 := signextend(15, a) let b0 := sar(128, b) let b1 := signextend(15, b) res0 := add(a0, b0) res1 := add(a1, b1) } return toBalanceDelta(res0.toInt128(), res1.toInt128()); } function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) { int256 res0; int256 res1; assembly ("memory-safe") { let a0 := sar(128, a) let a1 := signextend(15, a) let b0 := sar(128, b) let b1 := signextend(15, b) res0 := sub(a0, b0) res1 := sub(a1, b1) } return toBalanceDelta(res0.toInt128(), res1.toInt128()); } function eq(BalanceDelta a, BalanceDelta b) pure returns (bool) { return BalanceDelta.unwrap(a) == BalanceDelta.unwrap(b); } function neq(BalanceDelta a, BalanceDelta b) pure returns (bool) { return BalanceDelta.unwrap(a) != BalanceDelta.unwrap(b); } /// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type library BalanceDeltaLibrary { /// @notice A BalanceDelta of 0 BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0); function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) { assembly ("memory-safe") { _amount0 := sar(128, balanceDelta) } } function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) { assembly ("memory-safe") { _amount1 := signextend(15, balanceDelta) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {Currency} from "./Currency.sol"; import {IHooks} from "../interfaces/IHooks.sol"; import {PoolIdLibrary} from "./PoolId.sol"; using PoolIdLibrary for PoolKey global; /// @notice Returns the key for identifying a pool struct PoolKey { /// @notice The lower currency of the pool, sorted numerically Currency currency0; /// @notice The higher currency of the pool, sorted numerically Currency currency1; /// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000 uint24 fee; /// @notice Ticks that involve positions must be a multiple of tick spacing int24 tickSpacing; /// @notice The hooks of the pool IHooks hooks; }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; import {Currency} from "../types/Currency.sol"; import {IUnlockCallback} from "../interfaces/callback/IUnlockCallback.sol"; import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {StateLibrary} from "../libraries/StateLibrary.sol"; import {TransientStateLibrary} from "../libraries/TransientStateLibrary.sol"; abstract contract PoolTestBase is IUnlockCallback { using StateLibrary for IPoolManager; using TransientStateLibrary for IPoolManager; IPoolManager public immutable manager; constructor(IPoolManager _manager) { manager = _manager; } function _fetchBalances(Currency currency, address user, address deltaHolder) internal view returns (uint256 userBalance, uint256 poolBalance, int256 delta) { userBalance = currency.balanceOf(user); poolBalance = currency.balanceOf(address(manager)); delta = manager.currencyDelta(deltaHolder, currency); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {PoolKey} from "../types/PoolKey.sol"; import {BalanceDelta} from "../types/BalanceDelta.sol"; import {IPoolManager} from "./IPoolManager.sol"; import {BeforeSwapDelta} from "../types/BeforeSwapDelta.sol"; /// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits /// of the address that the hooks contract is deployed to. /// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400 /// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used. /// See the Hooks library for the full spec. /// @dev Should only be callable by the v4 PoolManager. interface IHooks { /// @notice The hook called before the state of a pool is initialized /// @param sender The initial msg.sender for the initialize call /// @param key The key for the pool being initialized /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96 /// @return bytes4 The function selector for the hook function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4); /// @notice The hook called after the state of a pool is initialized /// @param sender The initial msg.sender for the initialize call /// @param key The key for the pool being initialized /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96 /// @param tick The current tick after the state of a pool is initialized /// @return bytes4 The function selector for the hook function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick) external returns (bytes4); /// @notice The hook called before liquidity is added /// @param sender The initial msg.sender for the add liquidity call /// @param key The key for the pool /// @param params The parameters for adding liquidity /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook /// @return bytes4 The function selector for the hook function beforeAddLiquidity( address sender, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata params, bytes calldata hookData ) external returns (bytes4); /// @notice The hook called after liquidity is added /// @param sender The initial msg.sender for the add liquidity call /// @param key The key for the pool /// @param params The parameters for adding liquidity /// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta /// @param feesAccrued The fees accrued since the last time fees were collected from this position /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook /// @return bytes4 The function selector for the hook /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency function afterAddLiquidity( address sender, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata params, BalanceDelta delta, BalanceDelta feesAccrued, bytes calldata hookData ) external returns (bytes4, BalanceDelta); /// @notice The hook called before liquidity is removed /// @param sender The initial msg.sender for the remove liquidity call /// @param key The key for the pool /// @param params The parameters for removing liquidity /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook /// @return bytes4 The function selector for the hook function beforeRemoveLiquidity( address sender, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata params, bytes calldata hookData ) external returns (bytes4); /// @notice The hook called after liquidity is removed /// @param sender The initial msg.sender for the remove liquidity call /// @param key The key for the pool /// @param params The parameters for removing liquidity /// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta /// @param feesAccrued The fees accrued since the last time fees were collected from this position /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook /// @return bytes4 The function selector for the hook /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency function afterRemoveLiquidity( address sender, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata params, BalanceDelta delta, BalanceDelta feesAccrued, bytes calldata hookData ) external returns (bytes4, BalanceDelta); /// @notice The hook called before a swap /// @param sender The initial msg.sender for the swap call /// @param key The key for the pool /// @param params The parameters for the swap /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook /// @return bytes4 The function selector for the hook /// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency /// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million) function beforeSwap( address sender, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata hookData ) external returns (bytes4, BeforeSwapDelta, uint24); /// @notice The hook called after a swap /// @param sender The initial msg.sender for the swap call /// @param key The key for the pool /// @param params The parameters for the swap /// @param delta The amount owed to the caller (positive) or owed to the pool (negative) /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook /// @return bytes4 The function selector for the hook /// @return int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency function afterSwap( address sender, PoolKey calldata key, IPoolManager.SwapParams calldata params, BalanceDelta delta, bytes calldata hookData ) external returns (bytes4, int128); /// @notice The hook called before donate /// @param sender The initial msg.sender for the donate call /// @param key The key for the pool /// @param amount0 The amount of token0 being donated /// @param amount1 The amount of token1 being donated /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook /// @return bytes4 The function selector for the hook function beforeDonate( address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData ) external returns (bytes4); /// @notice The hook called after donate /// @param sender The initial msg.sender for the donate call /// @param key The key for the pool /// @param amount0 The amount of token0 being donated /// @param amount1 The amount of token1 being donated /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook /// @return bytes4 The function selector for the hook function afterDonate( address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData ) external returns (bytes4); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {PoolKey} from "../types/PoolKey.sol"; import {IHooks} from "../interfaces/IHooks.sol"; import {SafeCast} from "./SafeCast.sol"; import {LPFeeLibrary} from "./LPFeeLibrary.sol"; import {BalanceDelta, toBalanceDelta, BalanceDeltaLibrary} from "../types/BalanceDelta.sol"; import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "../types/BeforeSwapDelta.sol"; import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {ParseBytes} from "./ParseBytes.sol"; import {CustomRevert} from "./CustomRevert.sol"; /// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits /// of the address that the hooks contract is deployed to. /// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400 /// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used. library Hooks { using LPFeeLibrary for uint24; using Hooks for IHooks; using SafeCast for int256; using BeforeSwapDeltaLibrary for BeforeSwapDelta; using ParseBytes for bytes; using CustomRevert for bytes4; uint160 internal constant ALL_HOOK_MASK = uint160((1 << 14) - 1); uint160 internal constant BEFORE_INITIALIZE_FLAG = 1 << 13; uint160 internal constant AFTER_INITIALIZE_FLAG = 1 << 12; uint160 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 11; uint160 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 10; uint160 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 9; uint160 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 8; uint160 internal constant BEFORE_SWAP_FLAG = 1 << 7; uint160 internal constant AFTER_SWAP_FLAG = 1 << 6; uint160 internal constant BEFORE_DONATE_FLAG = 1 << 5; uint160 internal constant AFTER_DONATE_FLAG = 1 << 4; uint160 internal constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 3; uint160 internal constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 2; uint160 internal constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 1; uint160 internal constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 0; struct Permissions { bool beforeInitialize; bool afterInitialize; bool beforeAddLiquidity; bool afterAddLiquidity; bool beforeRemoveLiquidity; bool afterRemoveLiquidity; bool beforeSwap; bool afterSwap; bool beforeDonate; bool afterDonate; bool beforeSwapReturnDelta; bool afterSwapReturnDelta; bool afterAddLiquidityReturnDelta; bool afterRemoveLiquidityReturnDelta; } /// @notice Thrown if the address will not lead to the specified hook calls being called /// @param hooks The address of the hooks contract error HookAddressNotValid(address hooks); /// @notice Hook did not return its selector error InvalidHookResponse(); /// @notice thrown when a hook call fails /// @param revertReason bubbled up revert reason error Wrap__FailedHookCall(address hook, bytes revertReason); /// @notice The hook's delta changed the swap from exactIn to exactOut or vice versa error HookDeltaExceedsSwapAmount(); /// @notice Utility function intended to be used in hook constructors to ensure /// the deployed hooks address causes the intended hooks to be called /// @param permissions The hooks that are intended to be called /// @dev permissions param is memory as the function will be called from constructors function validateHookPermissions(IHooks self, Permissions memory permissions) internal pure { if ( permissions.beforeInitialize != self.hasPermission(BEFORE_INITIALIZE_FLAG) || permissions.afterInitialize != self.hasPermission(AFTER_INITIALIZE_FLAG) || permissions.beforeAddLiquidity != self.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG) || permissions.afterAddLiquidity != self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG) || permissions.beforeRemoveLiquidity != self.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG) || permissions.afterRemoveLiquidity != self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG) || permissions.beforeSwap != self.hasPermission(BEFORE_SWAP_FLAG) || permissions.afterSwap != self.hasPermission(AFTER_SWAP_FLAG) || permissions.beforeDonate != self.hasPermission(BEFORE_DONATE_FLAG) || permissions.afterDonate != self.hasPermission(AFTER_DONATE_FLAG) || permissions.beforeSwapReturnDelta != self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG) || permissions.afterSwapReturnDelta != self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG) || permissions.afterAddLiquidityReturnDelta != self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG) || permissions.afterRemoveLiquidityReturnDelta != self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG) ) { HookAddressNotValid.selector.revertWith(address(self)); } } /// @notice Ensures that the hook address includes at least one hook flag or dynamic fees, or is the 0 address /// @param self The hook to verify /// @param fee The fee of the pool the hook is used with /// @return bool True if the hook address is valid function isValidHookAddress(IHooks self, uint24 fee) internal pure returns (bool) { // The hook can only have a flag to return a hook delta on an action if it also has the corresponding action flag if (!self.hasPermission(BEFORE_SWAP_FLAG) && self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)) return false; if (!self.hasPermission(AFTER_SWAP_FLAG) && self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG)) return false; if (!self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG) && self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG)) { return false; } if ( !self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG) && self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG) ) return false; // If there is no hook contract set, then fee cannot be dynamic // If a hook contract is set, it must have at least 1 flag set, or have a dynamic fee return address(self) == address(0) ? !fee.isDynamicFee() : (uint160(address(self)) & ALL_HOOK_MASK > 0 || fee.isDynamicFee()); } /// @notice performs a hook call using the given calldata on the given hook that doesn't return a delta /// @return result The complete data returned by the hook function callHook(IHooks self, bytes memory data) internal returns (bytes memory result) { bool success; assembly ("memory-safe") { success := call(gas(), self, 0, add(data, 0x20), mload(data), 0, 0) } // Revert with FailedHookCall, containing any error message to bubble up if (!success) Wrap__FailedHookCall.selector.bubbleUpAndRevertWith(address(self)); // The call was successful, fetch the returned data assembly ("memory-safe") { // allocate result byte array from the free memory pointer result := mload(0x40) // store new free memory pointer at the end of the array padded to 32 bytes mstore(0x40, add(result, and(add(returndatasize(), 0x3f), not(0x1f)))) // store length in memory mstore(result, returndatasize()) // copy return data to result returndatacopy(add(result, 0x20), 0, returndatasize()) } // Length must be at least 32 to contain the selector. Check expected selector and returned selector match. if (result.length < 32 || result.parseSelector() != data.parseSelector()) { InvalidHookResponse.selector.revertWith(); } } /// @notice performs a hook call using the given calldata on the given hook /// @return int256 The delta returned by the hook function callHookWithReturnDelta(IHooks self, bytes memory data, bool parseReturn) internal returns (int256) { bytes memory result = callHook(self, data); // If this hook wasnt meant to return something, default to 0 delta if (!parseReturn) return 0; // A length of 64 bytes is required to return a bytes4, and a 32 byte delta if (result.length != 64) InvalidHookResponse.selector.revertWith(); return result.parseReturnDelta(); } /// @notice modifier to prevent calling a hook if they initiated the action modifier noSelfCall(IHooks self) { if (msg.sender != address(self)) { _; } } /// @notice calls beforeInitialize hook if permissioned and validates return value function beforeInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96) internal noSelfCall(self) { if (self.hasPermission(BEFORE_INITIALIZE_FLAG)) { self.callHook(abi.encodeCall(IHooks.beforeInitialize, (msg.sender, key, sqrtPriceX96))); } } /// @notice calls afterInitialize hook if permissioned and validates return value function afterInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96, int24 tick) internal noSelfCall(self) { if (self.hasPermission(AFTER_INITIALIZE_FLAG)) { self.callHook(abi.encodeCall(IHooks.afterInitialize, (msg.sender, key, sqrtPriceX96, tick))); } } /// @notice calls beforeModifyLiquidity hook if permissioned and validates return value function beforeModifyLiquidity( IHooks self, PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, bytes calldata hookData ) internal noSelfCall(self) { if (params.liquidityDelta > 0 && self.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG)) { self.callHook(abi.encodeCall(IHooks.beforeAddLiquidity, (msg.sender, key, params, hookData))); } else if (params.liquidityDelta <= 0 && self.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG)) { self.callHook(abi.encodeCall(IHooks.beforeRemoveLiquidity, (msg.sender, key, params, hookData))); } } /// @notice calls afterModifyLiquidity hook if permissioned and validates return value function afterModifyLiquidity( IHooks self, PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, BalanceDelta delta, BalanceDelta feesAccrued, bytes calldata hookData ) internal returns (BalanceDelta callerDelta, BalanceDelta hookDelta) { if (msg.sender == address(self)) return (delta, BalanceDeltaLibrary.ZERO_DELTA); callerDelta = delta; if (params.liquidityDelta > 0) { if (self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG)) { hookDelta = BalanceDelta.wrap( self.callHookWithReturnDelta( abi.encodeCall( IHooks.afterAddLiquidity, (msg.sender, key, params, delta, feesAccrued, hookData) ), self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG) ) ); callerDelta = callerDelta - hookDelta; } } else { if (self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)) { hookDelta = BalanceDelta.wrap( self.callHookWithReturnDelta( abi.encodeCall( IHooks.afterRemoveLiquidity, (msg.sender, key, params, delta, feesAccrued, hookData) ), self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG) ) ); callerDelta = callerDelta - hookDelta; } } } /// @notice calls beforeSwap hook if permissioned and validates return value function beforeSwap(IHooks self, PoolKey memory key, IPoolManager.SwapParams memory params, bytes calldata hookData) internal returns (int256 amountToSwap, BeforeSwapDelta hookReturn, uint24 lpFeeOverride) { amountToSwap = params.amountSpecified; if (msg.sender == address(self)) return (amountToSwap, BeforeSwapDeltaLibrary.ZERO_DELTA, lpFeeOverride); if (self.hasPermission(BEFORE_SWAP_FLAG)) { bytes memory result = callHook(self, abi.encodeCall(IHooks.beforeSwap, (msg.sender, key, params, hookData))); // A length of 96 bytes is required to return a bytes4, a 32 byte delta, and an LP fee if (result.length != 96) InvalidHookResponse.selector.revertWith(); // dynamic fee pools that do not want to override the cache fee, return 0 otherwise they return a valid fee with the override flag if (key.fee.isDynamicFee()) lpFeeOverride = result.parseFee(); // skip this logic for the case where the hook return is 0 if (self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)) { hookReturn = BeforeSwapDelta.wrap(result.parseReturnDelta()); // any return in unspecified is passed to the afterSwap hook for handling int128 hookDeltaSpecified = hookReturn.getSpecifiedDelta(); // Update the swap amount according to the hook's return, and check that the swap type doesn't change (exact input/output) if (hookDeltaSpecified != 0) { bool exactInput = amountToSwap < 0; amountToSwap += hookDeltaSpecified; if (exactInput ? amountToSwap > 0 : amountToSwap < 0) { HookDeltaExceedsSwapAmount.selector.revertWith(); } } } } } /// @notice calls afterSwap hook if permissioned and validates return value function afterSwap( IHooks self, PoolKey memory key, IPoolManager.SwapParams memory params, BalanceDelta swapDelta, bytes calldata hookData, BeforeSwapDelta beforeSwapHookReturn ) internal returns (BalanceDelta, BalanceDelta) { if (msg.sender == address(self)) return (swapDelta, BalanceDeltaLibrary.ZERO_DELTA); int128 hookDeltaSpecified = beforeSwapHookReturn.getSpecifiedDelta(); int128 hookDeltaUnspecified = beforeSwapHookReturn.getUnspecifiedDelta(); if (self.hasPermission(AFTER_SWAP_FLAG)) { hookDeltaUnspecified += self.callHookWithReturnDelta( abi.encodeCall(IHooks.afterSwap, (msg.sender, key, params, swapDelta, hookData)), self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG) ).toInt128(); } BalanceDelta hookDelta; if (hookDeltaUnspecified != 0 || hookDeltaSpecified != 0) { hookDelta = (params.amountSpecified < 0 == params.zeroForOne) ? toBalanceDelta(hookDeltaSpecified, hookDeltaUnspecified) : toBalanceDelta(hookDeltaUnspecified, hookDeltaSpecified); // the caller has to pay for (or receive) the hook's delta swapDelta = swapDelta - hookDelta; } return (swapDelta, hookDelta); } /// @notice calls beforeDonate hook if permissioned and validates return value function beforeDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) internal noSelfCall(self) { if (self.hasPermission(BEFORE_DONATE_FLAG)) { self.callHook(abi.encodeCall(IHooks.beforeDonate, (msg.sender, key, amount0, amount1, hookData))); } } /// @notice calls afterDonate hook if permissioned and validates return value function afterDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) internal noSelfCall(self) { if (self.hasPermission(AFTER_DONATE_FLAG)) { self.callHook(abi.encodeCall(IHooks.afterDonate, (msg.sender, key, amount0, amount1, hookData))); } } function hasPermission(IHooks self, uint160 flag) internal pure returns (bool) { return uint160(address(self)) & flag != 0; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {CustomRevert} from "./CustomRevert.sol"; /// @notice Library of helper functions for a pools LP fee library LPFeeLibrary { using LPFeeLibrary for uint24; using CustomRevert for bytes4; /// @notice Thrown when the static or dynamic fee on a pool exceeds 100%. error LPFeeTooLarge(uint24 fee); /// @notice An lp fee of exactly 0b1000000... signals a dynamic fee pool. This isnt a valid static fee as it is > MAX_LP_FEE uint24 public constant DYNAMIC_FEE_FLAG = 0x800000; /// @notice the second bit of the fee returned by beforeSwap is used to signal if the stored LP fee should be overridden in this swap // only dynamic-fee pools can return a fee via the beforeSwap hook uint24 public constant OVERRIDE_FEE_FLAG = 0x400000; /// @notice mask to remove the override fee flag from a fee returned by the beforeSwaphook uint24 public constant REMOVE_OVERRIDE_MASK = 0xBFFFFF; /// @notice the lp fee is represented in hundredths of a bip, so the max is 100% uint24 public constant MAX_LP_FEE = 1000000; /// @notice returns true if a pool's LP fee signals that the pool has a dynamic fee /// @param self The fee to check /// @return bool True of the fee is dynamic function isDynamicFee(uint24 self) internal pure returns (bool) { return self == DYNAMIC_FEE_FLAG; } /// @notice returns true if an LP fee is valid, aka not above the maximum permitted fee /// @param self The fee to check /// @return bool True of the fee is valid function isValid(uint24 self) internal pure returns (bool) { return self <= MAX_LP_FEE; } /// @notice validates whether an LP fee is larger than the maximum, and reverts if invalid /// @param self The fee to validate function validate(uint24 self) internal pure { if (!self.isValid()) LPFeeTooLarge.selector.revertWith(self); } /// @notice gets and validates the initial LP fee for a pool. Dynamic fee pools have an initial fee of 0. /// @dev if a dynamic fee pool wants a non-0 initial fee, it should call `updateDynamicLPFee` in the afterInitialize hook /// @param self The fee to get the initial LP from /// @return initialFee 0 if the fee is dynamic, otherwise the fee (if valid) function getInitialLPFee(uint24 self) internal pure returns (uint24) { // the initial fee for a dynamic fee pool is 0 if (self.isDynamicFee()) return 0; self.validate(); return self; } /// @notice returns true if the fee has the override flag set (2nd highest bit of the uint24) /// @param self The fee to check /// @return bool True of the fee has the override flag set function isOverride(uint24 self) internal pure returns (bool) { return self & OVERRIDE_FEE_FLAG != 0; } /// @notice returns a fee with the override flag removed /// @param self The fee to remove the override flag from /// @return fee The fee without the override flag set function removeOverrideFlag(uint24 self) internal pure returns (uint24) { return self & REMOVE_OVERRIDE_MASK; } /// @notice Removes the override flag and validates the fee (reverts if the fee is too large) /// @param self The fee to remove the override flag from, and then validate /// @return fee The fee without the override flag set (if valid) function removeOverrideFlagAndValidate(uint24 self) internal pure returns (uint24 fee) { fee = self.removeOverrideFlag(); fee.validate(); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {Currency} from "../../src/types/Currency.sol"; import {IERC20Minimal} from "../../src/interfaces/external/IERC20Minimal.sol"; import {IPoolManager} from "../../src/interfaces/IPoolManager.sol"; /// @notice Library used to interact with PoolManager.sol to settle any open deltas. /// To settle a positive delta (a credit to the user), a user may take or mint. /// To settle a negative delta (a debt on the user), a user make transfer or burn to pay off a debt. /// @dev Note that sync() is called before any erc-20 transfer in `settle`. library CurrencySettler { /// @notice Settle (pay) a currency to the PoolManager /// @param currency Currency to settle /// @param manager IPoolManager to settle to /// @param payer Address of the payer, the token sender /// @param amount Amount to send /// @param burn If true, burn the ERC-6909 token, otherwise ERC20-transfer to the PoolManager function settle(Currency currency, IPoolManager manager, address payer, uint256 amount, bool burn) internal { // for native currencies or burns, calling sync is not required // short circuit for ERC-6909 burns to support ERC-6909-wrapped native tokens if (burn) { manager.burn(payer, currency.toId(), amount); } else if (currency.isAddressZero()) { manager.settle{value: amount}(); } else { manager.sync(currency); if (payer != address(this)) { IERC20Minimal(Currency.unwrap(currency)).transferFrom(payer, address(manager), amount); } else { IERC20Minimal(Currency.unwrap(currency)).transfer(address(manager), amount); } manager.settle(); } } /// @notice Take (receive) a currency from the PoolManager /// @param currency Currency to take /// @param manager IPoolManager to take from /// @param recipient Address of the recipient, the token receiver /// @param amount Amount to receive /// @param claims If true, mint the ERC-6909 token, otherwise ERC20-transfer from the PoolManager to recipient function take(Currency currency, IPoolManager manager, address recipient, uint256 amount, bool claims) internal { claims ? manager.mint(recipient, currency.toId(), amount) : manager.take(currency, recipient, amount); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {PoolId} from "../types/PoolId.sol"; import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {Position} from "./Position.sol"; /// @notice A helper library to provide state getters that use extsload library StateLibrary { /// @notice index of pools mapping in the PoolManager bytes32 public constant POOLS_SLOT = bytes32(uint256(6)); /// @notice index of feeGrowthGlobal0X128 in Pool.State uint256 public constant FEE_GROWTH_GLOBAL0_OFFSET = 1; // feeGrowthGlobal1X128 offset in Pool.State = 2 /// @notice index of liquidity in Pool.State uint256 public constant LIQUIDITY_OFFSET = 3; /// @notice index of TicksInfo mapping in Pool.State: mapping(int24 => TickInfo) ticks; uint256 public constant TICKS_OFFSET = 4; /// @notice index of tickBitmap mapping in Pool.State uint256 public constant TICK_BITMAP_OFFSET = 5; /// @notice index of Position.State mapping in Pool.State: mapping(bytes32 => Position.State) positions; uint256 public constant POSITIONS_OFFSET = 6; /** * @notice Get Slot0 of the pool: sqrtPriceX96, tick, protocolFee, lpFee * @dev Corresponds to pools[poolId].slot0 * @param manager The pool manager contract. * @param poolId The ID of the pool. * @return sqrtPriceX96 The square root of the price of the pool, in Q96 precision. * @return tick The current tick of the pool. * @return protocolFee The protocol fee of the pool. * @return lpFee The swap fee of the pool. */ function getSlot0(IPoolManager manager, PoolId poolId) internal view returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee) { // slot key of Pool.State value: `pools[poolId]` bytes32 stateSlot = _getPoolStateSlot(poolId); bytes32 data = manager.extsload(stateSlot); // 24 bits |24bits|24bits |24 bits|160 bits // 0x000000 |000bb8|000000 |ffff75 |0000000000000000fe3aa841ba359daa0ea9eff7 // ---------- | fee |protocolfee | tick | sqrtPriceX96 assembly ("memory-safe") { // bottom 160 bits of data sqrtPriceX96 := and(data, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) // next 24 bits of data tick := signextend(2, shr(160, data)) // next 24 bits of data protocolFee := and(shr(184, data), 0xFFFFFF) // last 24 bits of data lpFee := and(shr(208, data), 0xFFFFFF) } } /** * @notice Retrieves the tick information of a pool at a specific tick. * @dev Corresponds to pools[poolId].ticks[tick] * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param tick The tick to retrieve information for. * @return liquidityGross The total position liquidity that references this tick * @return liquidityNet The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left) * @return feeGrowthOutside0X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick) * @return feeGrowthOutside1X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick) */ function getTickInfo(IPoolManager manager, PoolId poolId, int24 tick) internal view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128 ) { bytes32 slot = _getTickInfoSlot(poolId, tick); // read all 3 words of the TickInfo struct bytes32[] memory data = manager.extsload(slot, 3); assembly ("memory-safe") { let firstWord := mload(add(data, 32)) liquidityNet := sar(128, firstWord) liquidityGross := and(firstWord, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) feeGrowthOutside0X128 := mload(add(data, 64)) feeGrowthOutside1X128 := mload(add(data, 96)) } } /** * @notice Retrieves the liquidity information of a pool at a specific tick. * @dev Corresponds to pools[poolId].ticks[tick].liquidityGross and pools[poolId].ticks[tick].liquidityNet. A more gas efficient version of getTickInfo * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param tick The tick to retrieve liquidity for. * @return liquidityGross The total position liquidity that references this tick * @return liquidityNet The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left) */ function getTickLiquidity(IPoolManager manager, PoolId poolId, int24 tick) internal view returns (uint128 liquidityGross, int128 liquidityNet) { bytes32 slot = _getTickInfoSlot(poolId, tick); bytes32 value = manager.extsload(slot); assembly ("memory-safe") { liquidityNet := sar(128, value) liquidityGross := and(value, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) } } /** * @notice Retrieves the fee growth outside a tick range of a pool * @dev Corresponds to pools[poolId].ticks[tick].feeGrowthOutside0X128 and pools[poolId].ticks[tick].feeGrowthOutside1X128. A more gas efficient version of getTickInfo * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param tick The tick to retrieve fee growth for. * @return feeGrowthOutside0X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick) * @return feeGrowthOutside1X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick) */ function getTickFeeGrowthOutside(IPoolManager manager, PoolId poolId, int24 tick) internal view returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128) { bytes32 slot = _getTickInfoSlot(poolId, tick); // offset by 1 word, since the first word is liquidityGross + liquidityNet bytes32[] memory data = manager.extsload(bytes32(uint256(slot) + 1), 2); assembly ("memory-safe") { feeGrowthOutside0X128 := mload(add(data, 32)) feeGrowthOutside1X128 := mload(add(data, 64)) } } /** * @notice Retrieves the global fee growth of a pool. * @dev Corresponds to pools[poolId].feeGrowthGlobal0X128 and pools[poolId].feeGrowthGlobal1X128 * @param manager The pool manager contract. * @param poolId The ID of the pool. * @return feeGrowthGlobal0 The global fee growth for token0. * @return feeGrowthGlobal1 The global fee growth for token1. */ function getFeeGrowthGlobals(IPoolManager manager, PoolId poolId) internal view returns (uint256 feeGrowthGlobal0, uint256 feeGrowthGlobal1) { // slot key of Pool.State value: `pools[poolId]` bytes32 stateSlot = _getPoolStateSlot(poolId); // Pool.State, `uint256 feeGrowthGlobal0X128` bytes32 slot_feeGrowthGlobal0X128 = bytes32(uint256(stateSlot) + FEE_GROWTH_GLOBAL0_OFFSET); // read the 2 words of feeGrowthGlobal bytes32[] memory data = manager.extsload(slot_feeGrowthGlobal0X128, 2); assembly ("memory-safe") { feeGrowthGlobal0 := mload(add(data, 32)) feeGrowthGlobal1 := mload(add(data, 64)) } } /** * @notice Retrieves total the liquidity of a pool. * @dev Corresponds to pools[poolId].liquidity * @param manager The pool manager contract. * @param poolId The ID of the pool. * @return liquidity The liquidity of the pool. */ function getLiquidity(IPoolManager manager, PoolId poolId) internal view returns (uint128 liquidity) { // slot key of Pool.State value: `pools[poolId]` bytes32 stateSlot = _getPoolStateSlot(poolId); // Pool.State: `uint128 liquidity` bytes32 slot = bytes32(uint256(stateSlot) + LIQUIDITY_OFFSET); liquidity = uint128(uint256(manager.extsload(slot))); } /** * @notice Retrieves the tick bitmap of a pool at a specific tick. * @dev Corresponds to pools[poolId].tickBitmap[tick] * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param tick The tick to retrieve the bitmap for. * @return tickBitmap The bitmap of the tick. */ function getTickBitmap(IPoolManager manager, PoolId poolId, int16 tick) internal view returns (uint256 tickBitmap) { // slot key of Pool.State value: `pools[poolId]` bytes32 stateSlot = _getPoolStateSlot(poolId); // Pool.State: `mapping(int16 => uint256) tickBitmap;` bytes32 tickBitmapMapping = bytes32(uint256(stateSlot) + TICK_BITMAP_OFFSET); // slot id of the mapping key: `pools[poolId].tickBitmap[tick] bytes32 slot = keccak256(abi.encodePacked(int256(tick), tickBitmapMapping)); tickBitmap = uint256(manager.extsload(slot)); } /** * @notice Retrieves the position information of a pool without needing to calculate the `positionId`. * @dev Corresponds to pools[poolId].positions[positionId] * @param poolId The ID of the pool. * @param owner The owner of the liquidity position. * @param tickLower The lower tick of the liquidity range. * @param tickUpper The upper tick of the liquidity range. * @param salt The bytes32 randomness to further distinguish position state. * @return liquidity The liquidity of the position. * @return feeGrowthInside0LastX128 The fee growth inside the position for token0. * @return feeGrowthInside1LastX128 The fee growth inside the position for token1. */ function getPositionInfo( IPoolManager manager, PoolId poolId, address owner, int24 tickLower, int24 tickUpper, bytes32 salt ) internal view returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128) { // positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt)) bytes32 positionKey = Position.calculatePositionKey(owner, tickLower, tickUpper, salt); (liquidity, feeGrowthInside0LastX128, feeGrowthInside1LastX128) = getPositionInfo(manager, poolId, positionKey); } /** * @notice Retrieves the position information of a pool at a specific position ID. * @dev Corresponds to pools[poolId].positions[positionId] * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param positionId The ID of the position. * @return liquidity The liquidity of the position. * @return feeGrowthInside0LastX128 The fee growth inside the position for token0. * @return feeGrowthInside1LastX128 The fee growth inside the position for token1. */ function getPositionInfo(IPoolManager manager, PoolId poolId, bytes32 positionId) internal view returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128) { bytes32 slot = _getPositionInfoSlot(poolId, positionId); // read all 3 words of the Position.State struct bytes32[] memory data = manager.extsload(slot, 3); assembly ("memory-safe") { liquidity := mload(add(data, 32)) feeGrowthInside0LastX128 := mload(add(data, 64)) feeGrowthInside1LastX128 := mload(add(data, 96)) } } /** * @notice Retrieves the liquidity of a position. * @dev Corresponds to pools[poolId].positions[positionId].liquidity. More gas efficient for just retrieiving liquidity as compared to getPositionInfo * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param positionId The ID of the position. * @return liquidity The liquidity of the position. */ function getPositionLiquidity(IPoolManager manager, PoolId poolId, bytes32 positionId) internal view returns (uint128 liquidity) { bytes32 slot = _getPositionInfoSlot(poolId, positionId); liquidity = uint128(uint256(manager.extsload(slot))); } /** * @notice Calculate the fee growth inside a tick range of a pool * @dev pools[poolId].feeGrowthInside0LastX128 in Position.State is cached and can become stale. This function will calculate the up to date feeGrowthInside * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param tickLower The lower tick of the range. * @param tickUpper The upper tick of the range. * @return feeGrowthInside0X128 The fee growth inside the tick range for token0. * @return feeGrowthInside1X128 The fee growth inside the tick range for token1. */ function getFeeGrowthInside(IPoolManager manager, PoolId poolId, int24 tickLower, int24 tickUpper) internal view returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) { (uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128) = getFeeGrowthGlobals(manager, poolId); (uint256 lowerFeeGrowthOutside0X128, uint256 lowerFeeGrowthOutside1X128) = getTickFeeGrowthOutside(manager, poolId, tickLower); (uint256 upperFeeGrowthOutside0X128, uint256 upperFeeGrowthOutside1X128) = getTickFeeGrowthOutside(manager, poolId, tickUpper); (, int24 tickCurrent,,) = getSlot0(manager, poolId); unchecked { if (tickCurrent < tickLower) { feeGrowthInside0X128 = lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128; feeGrowthInside1X128 = lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128; } else if (tickCurrent >= tickUpper) { feeGrowthInside0X128 = upperFeeGrowthOutside0X128 - lowerFeeGrowthOutside0X128; feeGrowthInside1X128 = upperFeeGrowthOutside1X128 - lowerFeeGrowthOutside1X128; } else { feeGrowthInside0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128; feeGrowthInside1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128; } } } function _getPoolStateSlot(PoolId poolId) internal pure returns (bytes32) { return keccak256(abi.encodePacked(PoolId.unwrap(poolId), POOLS_SLOT)); } function _getTickInfoSlot(PoolId poolId, int24 tick) internal pure returns (bytes32) { // slot key of Pool.State value: `pools[poolId]` bytes32 stateSlot = _getPoolStateSlot(poolId); // Pool.State: `mapping(int24 => TickInfo) ticks` bytes32 ticksMappingSlot = bytes32(uint256(stateSlot) + TICKS_OFFSET); // slot key of the tick key: `pools[poolId].ticks[tick] return keccak256(abi.encodePacked(int256(tick), ticksMappingSlot)); } function _getPositionInfoSlot(PoolId poolId, bytes32 positionId) internal pure returns (bytes32) { // slot key of Pool.State value: `pools[poolId]` bytes32 stateSlot = _getPoolStateSlot(poolId); // Pool.State: `mapping(bytes32 => Position.State) positions;` bytes32 positionMapping = bytes32(uint256(stateSlot) + POSITIONS_OFFSET); // slot of the mapping key: `pools[poolId].positions[positionId] return keccak256(abi.encodePacked(positionId, positionMapping)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title Minimal ERC20 interface for Uniswap /// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3 interface IERC20Minimal { /// @notice Returns an account's balance in the token /// @param account The account for which to look up the number of tokens it has, i.e. its balance /// @return The number of tokens held by the account function balanceOf(address account) external view returns (uint256); /// @notice Transfers the amount of token from the `msg.sender` to the recipient /// @param recipient The account that will receive the amount transferred /// @param amount The number of tokens to send from the sender to the recipient /// @return Returns true for a successful transfer, false for an unsuccessful transfer function transfer(address recipient, uint256 amount) external returns (bool); /// @notice Returns the current allowance given to a spender by an owner /// @param owner The account of the token owner /// @param spender The account of the token spender /// @return The current allowance granted by `owner` to `spender` function allowance(address owner, address spender) external view returns (uint256); /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount` /// @param spender The account which will be allowed to spend a given amount of the owners tokens /// @param amount The amount of tokens allowed to be used by `spender` /// @return Returns true for a successful approval, false for unsuccessful function approve(address spender, uint256 amount) external returns (bool); /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender` /// @param sender The account from which the transfer will be initiated /// @param recipient The recipient of the transfer /// @param amount The amount of the transfer /// @return Returns true for a successful transfer, false for unsuccessful function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`. /// @param from The account from which the tokens were sent, i.e. the balance decreased /// @param to The account to which the tokens were sent, i.e. the balance increased /// @param value The amount of tokens that were transferred event Transfer(address indexed from, address indexed to, uint256 value); /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes. /// @param owner The account that approved spending of its tokens /// @param spender The account for which the spending allowance was modified /// @param value The new allowance from the owner to the spender event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Library for reverting with custom errors efficiently /// @notice Contains functions for reverting with custom errors with different argument types efficiently /// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with /// `CustomError.selector.revertWith()` /// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately library CustomRevert { /// @dev Reverts with the selector of a custom error in the scratch space function revertWith(bytes4 selector) internal pure { assembly ("memory-safe") { mstore(0, selector) revert(0, 0x04) } } /// @dev Reverts with a custom error with an address argument in the scratch space function revertWith(bytes4 selector, address addr) internal pure { assembly ("memory-safe") { mstore(0, selector) mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff)) revert(0, 0x24) } } /// @dev Reverts with a custom error with an int24 argument in the scratch space function revertWith(bytes4 selector, int24 value) internal pure { assembly ("memory-safe") { mstore(0, selector) mstore(0x04, signextend(2, value)) revert(0, 0x24) } } /// @dev Reverts with a custom error with a uint160 argument in the scratch space function revertWith(bytes4 selector, uint160 value) internal pure { assembly ("memory-safe") { mstore(0, selector) mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff)) revert(0, 0x24) } } /// @dev Reverts with a custom error with two int24 arguments function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure { assembly ("memory-safe") { let fmp := mload(0x40) mstore(fmp, selector) mstore(add(fmp, 0x04), signextend(2, value1)) mstore(add(fmp, 0x24), signextend(2, value2)) revert(fmp, 0x44) } } /// @dev Reverts with a custom error with two uint160 arguments function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure { assembly ("memory-safe") { let fmp := mload(0x40) mstore(fmp, selector) mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff)) mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff)) revert(fmp, 0x44) } } /// @dev Reverts with a custom error with two address arguments function revertWith(bytes4 selector, address value1, address value2) internal pure { assembly ("memory-safe") { let fmp := mload(0x40) mstore(fmp, selector) mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff)) mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff)) revert(fmp, 0x44) } } /// @notice bubble up the revert message returned by a call and revert with the selector provided /// @dev this function should only be used with custom errors of the type `CustomError(address target, bytes revertReason)` function bubbleUpAndRevertWith(bytes4 selector, address addr) internal pure { assembly ("memory-safe") { let size := returndatasize() let fmp := mload(0x40) // Encode selector, address, offset, size, data mstore(fmp, selector) mstore(add(fmp, 0x04), addr) mstore(add(fmp, 0x24), 0x40) mstore(add(fmp, 0x44), size) returndatacopy(add(fmp, 0x64), 0, size) // Ensure the size is a multiple of 32 bytes let encodedSize := add(0x64, mul(div(add(size, 31), 32), 32)) revert(fmp, encodedSize) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @notice Interface for claims over a contract balance, wrapped as a ERC6909 interface IERC6909Claims { /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event OperatorSet(address indexed owner, address indexed operator, bool approved); event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount); event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount); /*////////////////////////////////////////////////////////////// FUNCTIONS //////////////////////////////////////////////////////////////*/ /// @notice Owner balance of an id. /// @param owner The address of the owner. /// @param id The id of the token. /// @return amount The balance of the token. function balanceOf(address owner, uint256 id) external view returns (uint256 amount); /// @notice Spender allowance of an id. /// @param owner The address of the owner. /// @param spender The address of the spender. /// @param id The id of the token. /// @return amount The allowance of the token. function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount); /// @notice Checks if a spender is approved by an owner as an operator /// @param owner The address of the owner. /// @param spender The address of the spender. /// @return approved The approval status. function isOperator(address owner, address spender) external view returns (bool approved); /// @notice Transfers an amount of an id from the caller to a receiver. /// @param receiver The address of the receiver. /// @param id The id of the token. /// @param amount The amount of the token. /// @return bool True, always, unless the function reverts function transfer(address receiver, uint256 id, uint256 amount) external returns (bool); /// @notice Transfers an amount of an id from a sender to a receiver. /// @param sender The address of the sender. /// @param receiver The address of the receiver. /// @param id The id of the token. /// @param amount The amount of the token. /// @return bool True, always, unless the function reverts function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool); /// @notice Approves an amount of an id to a spender. /// @param spender The address of the spender. /// @param id The id of the token. /// @param amount The amount of the token. /// @return bool True, always function approve(address spender, uint256 id, uint256 amount) external returns (bool); /// @notice Sets or removes an operator for the caller. /// @param operator The address of the operator. /// @param approved The approval status. /// @return bool True, always function setOperator(address operator, bool approved) external returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {Currency} from "../types/Currency.sol"; import {IProtocolFeeController} from "../interfaces/IProtocolFeeController.sol"; import {PoolId} from "../types/PoolId.sol"; import {PoolKey} from "../types/PoolKey.sol"; /// @notice Interface for all protocol-fee related functions in the pool manager interface IProtocolFees { /// @notice Thrown when protocol fee is set too high error ProtocolFeeTooLarge(uint24 fee); /// @notice Thrown when the contract is unlocked error ContractUnlocked(); /// @notice Thrown when collectProtocolFees or setProtocolFee is not called by the controller. error InvalidCaller(); /// @notice Emitted when the protocol fee controller address is updated in setProtocolFeeController. event ProtocolFeeControllerUpdated(address indexed protocolFeeController); /// @notice Emitted when the protocol fee is updated for a pool. event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee); /// @notice Given a currency address, returns the protocol fees accrued in that currency /// @param currency The currency to check /// @return amount The amount of protocol fees accrued in the currency function protocolFeesAccrued(Currency currency) external view returns (uint256 amount); /// @notice Sets the protocol fee for the given pool /// @param key The key of the pool to set a protocol fee for /// @param newProtocolFee The fee to set function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external; /// @notice Sets the protocol fee controller /// @param controller The new protocol fee controller function setProtocolFeeController(IProtocolFeeController controller) external; /// @notice Collects the protocol fees for a given recipient and currency, returning the amount collected /// @dev This will revert if the contract is unlocked /// @param recipient The address to receive the protocol fees /// @param currency The currency to withdraw /// @param amount The amount of currency to withdraw /// @return amountCollected The amount of currency successfully withdrawn function collectProtocolFees(address recipient, Currency currency, uint256 amount) external returns (uint256 amountCollected); /// @notice Returns the current protocol fee controller address /// @return IProtocolFeeController The currency protocol fee controller function protocolFeeController() external view returns (IProtocolFeeController); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {PoolKey} from "./PoolKey.sol"; type PoolId is bytes32; /// @notice Library for computing the ID of a pool library PoolIdLibrary { /// @notice Returns value equal to keccak256(abi.encode(poolKey)) function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) { assembly ("memory-safe") { // 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes) poolId := keccak256(poolKey, 0xa0) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @notice Interface for functions to access any storage slot in a contract interface IExtsload { /// @notice Called by external contracts to access granular pool state /// @param slot Key of slot to sload /// @return value The value of the slot as bytes32 function extsload(bytes32 slot) external view returns (bytes32 value); /// @notice Called by external contracts to access granular pool state /// @param startSlot Key of slot to start sloading from /// @param nSlots Number of slots to load into return value /// @return values List of loaded values. function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory values); /// @notice Called by external contracts to access sparse pool state /// @param slots List of slots to SLOAD from. /// @return values List of loaded values. function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; /// @notice Interface for functions to access any transient storage slot in a contract interface IExttload { /// @notice Called by external contracts to access transient storage of the contract /// @param slot Key of slot to tload /// @return value The value of the slot as bytes32 function exttload(bytes32 slot) external view returns (bytes32 value); /// @notice Called by external contracts to access sparse transient pool state /// @param slots List of slots to tload /// @return values List of loaded values function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory values); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {CustomRevert} from "./CustomRevert.sol"; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCast { using CustomRevert for bytes4; error SafeCastOverflow(); /// @notice Cast a uint256 to a uint160, revert on overflow /// @param x The uint256 to be downcasted /// @return y The downcasted integer, now type uint160 function toUint160(uint256 x) internal pure returns (uint160 y) { y = uint160(x); if (y != x) SafeCastOverflow.selector.revertWith(); } /// @notice Cast a uint256 to a uint128, revert on overflow /// @param x The uint256 to be downcasted /// @return y The downcasted integer, now type uint128 function toUint128(uint256 x) internal pure returns (uint128 y) { y = uint128(x); if (x != y) SafeCastOverflow.selector.revertWith(); } /// @notice Cast a int128 to a uint128, revert on overflow or underflow /// @param x The int128 to be casted /// @return y The casted integer, now type uint128 function toUint128(int128 x) internal pure returns (uint128 y) { if (x < 0) SafeCastOverflow.selector.revertWith(); y = uint128(x); } /// @notice Cast a int256 to a int128, revert on overflow or underflow /// @param x The int256 to be downcasted /// @return y The downcasted integer, now type int128 function toInt128(int256 x) internal pure returns (int128 y) { y = int128(x); if (y != x) SafeCastOverflow.selector.revertWith(); } /// @notice Cast a uint256 to a int256, revert on overflow /// @param x The uint256 to be casted /// @return y The casted integer, now type int256 function toInt256(uint256 x) internal pure returns (int256 y) { y = int256(x); if (y < 0) SafeCastOverflow.selector.revertWith(); } /// @notice Cast a uint256 to a int128, revert on overflow /// @param x The uint256 to be downcasted /// @return The downcasted integer, now type int128 function toInt128(uint256 x) internal pure returns (int128) { if (x >= 1 << 127) SafeCastOverflow.selector.revertWith(); return int128(int256(x)); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @notice Interface for the callback executed when an address unlocks the pool manager interface IUnlockCallback { /// @notice Called by the pool manager on `msg.sender` when the manager is unlocked /// @param data The data that was passed to the call to unlock /// @return Any data that you want to be returned from the unlock call function unlockCallback(bytes calldata data) external returns (bytes memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {Currency} from "../types/Currency.sol"; import {CurrencyReserves} from "./CurrencyReserves.sol"; import {NonzeroDeltaCount} from "./NonzeroDeltaCount.sol"; import {Lock} from "./Lock.sol"; /// @notice A helper library to provide state getters that use exttload library TransientStateLibrary { /// @notice returns the reserves for the synced currency /// @param manager The pool manager contract. /// @return uint256 The reserves of the currency. /// @dev returns 0 if the reserves are not synced or value is 0. /// Checks the synced currency to only return valid reserve values (after a sync and before a settle). function getSyncedReserves(IPoolManager manager) internal view returns (uint256) { if (getSyncedCurrency(manager).isAddressZero()) return 0; return uint256(manager.exttload(CurrencyReserves.RESERVES_OF_SLOT)); } function getSyncedCurrency(IPoolManager manager) internal view returns (Currency) { return Currency.wrap(address(uint160(uint256(manager.exttload(CurrencyReserves.CURRENCY_SLOT))))); } /// @notice Returns the number of nonzero deltas open on the PoolManager that must be zeroed out before the contract is locked function getNonzeroDeltaCount(IPoolManager manager) internal view returns (uint256) { return uint256(manager.exttload(NonzeroDeltaCount.NONZERO_DELTA_COUNT_SLOT)); } /// @notice Get the current delta for a caller in the given currency /// @param target The credited account address /// @param currency The currency for which to lookup the delta function currencyDelta(IPoolManager manager, address target, Currency currency) internal view returns (int256) { bytes32 key; assembly ("memory-safe") { mstore(0, and(target, 0xffffffffffffffffffffffffffffffffffffffff)) mstore(32, and(currency, 0xffffffffffffffffffffffffffffffffffffffff)) key := keccak256(0, 64) } return int256(uint256(manager.exttload(key))); } /// @notice Returns whether the contract is unlocked or not function isUnlocked(IPoolManager manager) internal view returns (bool) { return manager.exttload(Lock.IS_UNLOCKED_SLOT) != 0x0; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Return type of the beforeSwap hook. // Upper 128 bits is the delta in specified tokens. Lower 128 bits is delta in unspecified tokens (to match the afterSwap hook) type BeforeSwapDelta is int256; // Creates a BeforeSwapDelta from specified and unspecified function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified) pure returns (BeforeSwapDelta beforeSwapDelta) { assembly ("memory-safe") { beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified)) } } /// @notice Library for getting the specified and unspecified deltas from the BeforeSwapDelta type library BeforeSwapDeltaLibrary { /// @notice A BeforeSwapDelta of 0 BeforeSwapDelta public constant ZERO_DELTA = BeforeSwapDelta.wrap(0); /// extracts int128 from the upper 128 bits of the BeforeSwapDelta /// returned by beforeSwap function getSpecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaSpecified) { assembly ("memory-safe") { deltaSpecified := sar(128, delta) } } /// extracts int128 from the lower 128 bits of the BeforeSwapDelta /// returned by beforeSwap and afterSwap function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) { assembly ("memory-safe") { deltaUnspecified := signextend(15, delta) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @notice Parses bytes returned from hooks and the byte selector used to check return selectors from hooks. /// @dev parseSelector also is used to parse the expected selector /// For parsing hook returns, note that all hooks return either bytes4 or (bytes4, 32-byte-delta) or (bytes4, 32-byte-delta, uint24). library ParseBytes { function parseSelector(bytes memory result) internal pure returns (bytes4 selector) { // equivalent: (selector,) = abi.decode(result, (bytes4, int256)); assembly ("memory-safe") { selector := mload(add(result, 0x20)) } } function parseFee(bytes memory result) internal pure returns (uint24 lpFee) { // equivalent: (,, lpFee) = abi.decode(result, (bytes4, int256, uint24)); assembly ("memory-safe") { lpFee := mload(add(result, 0x60)) } } function parseReturnDelta(bytes memory result) internal pure returns (int256 hookReturn) { // equivalent: (, hookReturnDelta) = abi.decode(result, (bytes4, int256)); assembly ("memory-safe") { hookReturn := mload(add(result, 0x40)) } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.0; import {FullMath} from "./FullMath.sol"; import {FixedPoint128} from "./FixedPoint128.sol"; import {LiquidityMath} from "./LiquidityMath.sol"; import {CustomRevert} from "./CustomRevert.sol"; /// @title Position /// @notice Positions represent an owner address' liquidity between a lower and upper tick boundary /// @dev Positions store additional state for tracking fees owed to the position library Position { using CustomRevert for bytes4; /// @notice Cannot update a position with no liquidity error CannotUpdateEmptyPosition(); // info stored for each user's position struct State { // the amount of liquidity owned by this position uint128 liquidity; // fee growth per unit of liquidity as of the last update to liquidity or fees owed uint256 feeGrowthInside0LastX128; uint256 feeGrowthInside1LastX128; } /// @notice Returns the State struct of a position, given an owner and position boundaries /// @param self The mapping containing all user positions /// @param owner The address of the position owner /// @param tickLower The lower tick boundary of the position /// @param tickUpper The upper tick boundary of the position /// @param salt A unique value to differentiate between multiple positions in the same range /// @return position The position info struct of the given owners' position function get(mapping(bytes32 => State) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt) internal view returns (State storage position) { bytes32 positionKey = calculatePositionKey(owner, tickLower, tickUpper, salt); position = self[positionKey]; } /// @notice A helper function to calculate the position key /// @param owner The address of the position owner /// @param tickLower the lower tick boundary of the position /// @param tickUpper the upper tick boundary of the position /// @param salt A unique value to differentiate between multiple positions in the same range, by the same owner. Passed in by the caller. function calculatePositionKey(address owner, int24 tickLower, int24 tickUpper, bytes32 salt) internal pure returns (bytes32 positionKey) { // positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt)) assembly ("memory-safe") { let fmp := mload(0x40) mstore(add(fmp, 0x26), salt) // [0x26, 0x46) mstore(add(fmp, 0x06), tickUpper) // [0x23, 0x26) mstore(add(fmp, 0x03), tickLower) // [0x20, 0x23) mstore(fmp, owner) // [0x0c, 0x20) positionKey := keccak256(add(fmp, 0x0c), 0x3a) // len is 58 bytes // now clean the memory we used mstore(add(fmp, 0x40), 0) // fmp+0x40 held salt mstore(add(fmp, 0x20), 0) // fmp+0x20 held tickLower, tickUpper, salt mstore(fmp, 0) // fmp held owner } } /// @notice Credits accumulated fees to a user's position /// @param self The individual position to update /// @param liquidityDelta The change in pool liquidity as a result of the position update /// @param feeGrowthInside0X128 The all-time fee growth in currency0, per unit of liquidity, inside the position's tick boundaries /// @param feeGrowthInside1X128 The all-time fee growth in currency1, per unit of liquidity, inside the position's tick boundaries /// @return feesOwed0 The amount of currency0 owed to the position owner /// @return feesOwed1 The amount of currency1 owed to the position owner function update( State storage self, int128 liquidityDelta, uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128 ) internal returns (uint256 feesOwed0, uint256 feesOwed1) { uint128 liquidity = self.liquidity; if (liquidityDelta == 0) { // disallow pokes for 0 liquidity positions if (liquidity == 0) CannotUpdateEmptyPosition.selector.revertWith(); } else { self.liquidity = LiquidityMath.addDelta(liquidity, liquidityDelta); } // calculate accumulated fees. overflow in the subtraction of fee growth is expected unchecked { feesOwed0 = FullMath.mulDiv(feeGrowthInside0X128 - self.feeGrowthInside0LastX128, liquidity, FixedPoint128.Q128); feesOwed1 = FullMath.mulDiv(feeGrowthInside1X128 - self.feeGrowthInside1LastX128, liquidity, FixedPoint128.Q128); } // update the position self.feeGrowthInside0LastX128 = feeGrowthInside0X128; self.feeGrowthInside1LastX128 = feeGrowthInside1X128; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {PoolKey} from "../types/PoolKey.sol"; /// @notice Interface to fetch the protocol fees for a pool from the protocol fee controller interface IProtocolFeeController { /// @notice Returns the protocol fees for a pool given the conditions of this contract /// @param poolKey The pool key to identify the pool. The controller may want to use attributes on the pool /// to determine the protocol fee, hence the entire key is needed. /// @return protocolFee The pool's protocol fee, expressed in hundredths of a bip. The upper 12 bits are for 1->0 /// and the lower 12 are for 0->1. The maximum is 1000 - meaning the maximum protocol fee is 0.1%. /// the protocolFee is taken from the input first, then the lpFee is taken from the remaining input function protocolFeeForPool(PoolKey memory poolKey) external view returns (uint24 protocolFee); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import {Currency} from "../types/Currency.sol"; import {CustomRevert} from "./CustomRevert.sol"; library CurrencyReserves { using CustomRevert for bytes4; /// bytes32(uint256(keccak256("ReservesOf")) - 1) bytes32 constant RESERVES_OF_SLOT = 0x1e0745a7db1623981f0b2a5d4232364c00787266eb75ad546f190e6cebe9bd95; /// bytes32(uint256(keccak256("Currency")) - 1) bytes32 constant CURRENCY_SLOT = 0x27e098c505d44ec3574004bca052aabf76bd35004c182099d8c575fb238593b9; function getSyncedCurrency() internal view returns (Currency currency) { assembly ("memory-safe") { currency := tload(CURRENCY_SLOT) } } function resetCurrency() internal { assembly ("memory-safe") { tstore(CURRENCY_SLOT, 0) } } function syncCurrencyAndReserves(Currency currency, uint256 value) internal { assembly ("memory-safe") { tstore(CURRENCY_SLOT, and(currency, 0xffffffffffffffffffffffffffffffffffffffff)) tstore(RESERVES_OF_SLOT, value) } } function getSyncedReserves() internal view returns (uint256 value) { assembly ("memory-safe") { value := tload(RESERVES_OF_SLOT) } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; /// @notice This is a temporary library that allows us to use transient storage (tstore/tload) /// for the nonzero delta count. /// TODO: This library can be deleted when we have the transient keyword support in solidity. library NonzeroDeltaCount { // The slot holding the number of nonzero deltas. bytes32(uint256(keccak256("NonzeroDeltaCount")) - 1) bytes32 internal constant NONZERO_DELTA_COUNT_SLOT = 0x7d4b3164c6e45b97e7d87b7125a44c5828d005af88f9d751cfd78729c5d99a0b; function read() internal view returns (uint256 count) { assembly ("memory-safe") { count := tload(NONZERO_DELTA_COUNT_SLOT) } } function increment() internal { assembly ("memory-safe") { let count := tload(NONZERO_DELTA_COUNT_SLOT) count := add(count, 1) tstore(NONZERO_DELTA_COUNT_SLOT, count) } } /// @notice Potential to underflow. Ensure checks are performed by integrating contracts to ensure this does not happen. /// Current usage ensures this will not happen because we call decrement with known boundaries (only up to the number of times we call increment). function decrement() internal { assembly ("memory-safe") { let count := tload(NONZERO_DELTA_COUNT_SLOT) count := sub(count, 1) tstore(NONZERO_DELTA_COUNT_SLOT, count) } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; /// @notice This is a temporary library that allows us to use transient storage (tstore/tload) /// TODO: This library can be deleted when we have the transient keyword support in solidity. library Lock { // The slot holding the unlocked state, transiently. bytes32(uint256(keccak256("Unlocked")) - 1) bytes32 internal constant IS_UNLOCKED_SLOT = 0xc090fc4683624cfc3884e9d8de5eca132f2d0ec062aff75d43c0465d5ceeab23; function unlock() internal { assembly ("memory-safe") { // unlock tstore(IS_UNLOCKED_SLOT, true) } } function lock() internal { assembly ("memory-safe") { tstore(IS_UNLOCKED_SLOT, false) } } function isUnlocked() internal view returns (bool unlocked) { assembly ("memory-safe") { unlocked := tload(IS_UNLOCKED_SLOT) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0 = a * b; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly ("memory-safe") { let mm := mulmod(a, b, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { assembly ("memory-safe") { result := div(prod0, denominator) } return result; } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly ("memory-safe") { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly ("memory-safe") { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = (0 - denominator) & denominator; // Divide denominator by power of two assembly ("memory-safe") { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly ("memory-safe") { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly ("memory-safe") { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the preconditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) { unchecked { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) != 0) { require(++result > 0); } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title FixedPoint128 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) library FixedPoint128 { uint256 internal constant Q128 = 0x100000000000000000000000000000000; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title Math library for liquidity library LiquidityMath { /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows /// @param x The liquidity before change /// @param y The delta by which liquidity should be changed /// @return z The liquidity delta function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { assembly ("memory-safe") { z := add(and(x, 0xffffffffffffffffffffffffffffffff), signextend(15, y)) if shr(128, z) { // revert SafeCastOverflow() mstore(0, 0x93dafdf1) revert(0x1c, 0x04) } } } }
{ "remappings": [ "@uniswap/v4-core/=lib/v4-core/", "forge-gas-snapshot/=lib/v4-core/lib/forge-gas-snapshot/src/", "ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/", "forge-std/=lib/v4-core/lib/forge-std/src/", "openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/", "solmate/=lib/v4-core/lib/solmate/", "@ensdomains/=lib/v4-core/node_modules/@ensdomains/", "@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/", "@openzeppelin/contracts/=lib/v4-core/lib/openzeppelin-contracts/contracts/", "erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/", "hardhat/=lib/v4-core/node_modules/hardhat/", "permit2/=lib/permit2/", "v4-core/=lib/v4-core/src/" ], "optimizer": { "enabled": true, "runs": 44444444 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "cancun", "viaIR": true, "libraries": {} }
[{"inputs":[{"internalType":"contract IPoolManager","name":"_manager","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"manager","outputs":[{"internalType":"contract IPoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int256","name":"liquidityDelta","type":"int256"},{"internalType":"bytes32","name":"salt","type":"bytes32"}],"internalType":"struct IPoolManager.ModifyLiquidityParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"},{"internalType":"bool","name":"settleUsingBurn","type":"bool"},{"internalType":"bool","name":"takeClaims","type":"bool"}],"name":"modifyLiquidity","outputs":[{"internalType":"BalanceDelta","name":"delta","type":"int256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int256","name":"liquidityDelta","type":"int256"},{"internalType":"bytes32","name":"salt","type":"bytes32"}],"internalType":"struct IPoolManager.ModifyLiquidityParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"modifyLiquidity","outputs":[{"internalType":"BalanceDelta","name":"delta","type":"int256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"rawData","type":"bytes"}],"name":"unlockCallback","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a034607a57601f61180a38819003918201601f19168301916001600160401b03831184841017607e57808492602094604052833981010312607a57516001600160a01b0381168103607a576080526040516117779081610093823960805181818160b50152818161099001528181610ac101526111390152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffdfe60806040526004361015610011575f80fd5b5f3560e01c80630a5b11e414610ae5578063481c6a7514610a775780635a6bcfda14610790576391dd734614610045575f80fd5b346107795760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126107795760043567ffffffffffffffff8111610779573660238201121561077957806004013567ffffffffffffffff81116107795781016024810190368211610779577f00000000000000000000000000000000000000000000000000000000000000009273ffffffffffffffffffffffffffffffffffffffff841690813303610779576020818403126107795760248101359067ffffffffffffffff82116107795701906101a082840312610779576040519161012d83610c27565b61013960248201610ce9565b835260a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08286030112610779576040519361017485610c70565b61018060448301610ce9565b855261018e60648301610ce9565b6020860152608482013562ffffff811681036107795760408601526101b560a48301610d0a565b606086015260c482013573ffffffffffffffffffffffffffffffffffffffff81168103610779577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1c83608093602493858a01526020880198895203010112610779576040519561022487610c8c565b61023060e48301610d0a565b875261023f6101048301610d0a565b6020880152610124820135604088015261014482013560608801526040840196875261016482013567ffffffffffffffff81116107795761039f96602461028892850101610e8a565b916060850192835260406102b36101a46102a56101848501610ed0565b936080890194855201610ed0565b9360a087019485526102e060a08951208b51805160020b6060602083015160020b92015192309089610f80565b5050956103715f8c6103b38c519151955187519e8f97889687957f5a6bcfda000000000000000000000000000000000000000000000000000000008752600487019073ffffffffffffffffffffffffffffffffffffffff6080809282815116855282602082015116602086015262ffffff6040820151166040860152606081015160020b6060860152015116910152565b8051600290810b60a48701526020820151900b60c4860152604081015160e486015260600151610104850152565b610140610124840152610144830190610edd565b03925af1968715610785575f9761074d575b506103eb60a08751208951805160020b6060602083015160020b92015192309087610f80565b50509061042a73ffffffffffffffffffffffffffffffffffffffff88515116309073ffffffffffffffffffffffffffffffffffffffff89511690611114565b939150506fffffffffffffffffffffffffffffffff61047e73ffffffffffffffffffffffffffffffffffffffff60208b51015116309073ffffffffffffffffffffffffffffffffffffffff8b511690611114565b9891505016600f0b9060408b510151915f8382019384129112908015821691151617610720576fffffffffffffffffffffffffffffffff16600f0b036106c2576040610548995101515f81125f1461067d57505f82138015610674575b6104e490610f20565b5f8212801561066b575b6104f89015610f20565b5f821261061d575b5f85126105ca575b505f8113610583575b505f831361054c575b868660405190602082015260208152610534604082610ca8565b604051918291602083526020830190610edd565b0390f35b73ffffffffffffffffffffffffffffffffffffffff80602061057997510151169451169151151593611545565b5f8080808061051a565b6105c49073ffffffffffffffffffffffffffffffffffffffff875151169073ffffffffffffffffffffffffffffffffffffffff875116848651151593611545565b5f610511565b6106179073ffffffffffffffffffffffffffffffffffffffff602089510151169073ffffffffffffffffffffffffffffffffffffffff8851168561060d89610f54565b925115159361120d565b5f610508565b61066673ffffffffffffffffffffffffffffffffffffffff8851511673ffffffffffffffffffffffffffffffffffffffff88511661065a85610f54565b9086855115159361120d565b610500565b505f85126104ee565b505f85136104db565b5f12156104f8575f821280156106b9575b61069790610f20565b5f821380156106b0575b6106ab9015610f20565b6104f8565b505f85136106a1565b505f851261068e565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f6c6971756964697479206368616e676520696e636f72726563740000000000006044820152fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b9096506040813d60401161077d575b8161076960409383610ca8565b810103126107795751955f6103c5565b5f80fd5b3d915061075c565b6040513d5f823e3d90fd5b6101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610779576107c436610d18565b6107cd36610de4565b90610124359167ffffffffffffffff83116107795761093b5f9273ffffffffffffffffffffffffffffffffffffffff9261080e610976963690600401610e8a565b916108fc6040519361081f85610c27565b3385526020850192835260408501938452606085019081526108e760808601948986526108b560a08801958b87526040519a8b996020808c0152511660408a015251606089019073ffffffffffffffffffffffffffffffffffffffff6080809282815116855282602082015116602086015262ffffff6040820151166040860152606081015160020b6060860152015116910152565b518051600290810b6101008901526020820151900b610120880152604081015161014088015260600151610160870152565b516101a06101808601526101e0850190610edd565b915115156101a08401525115156101c0830152037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282610ca8565b604051809381927f48c89491000000000000000000000000000000000000000000000000000000008352602060048401526024830190610edd565b03818373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af1908115610785575f916109fd575b50602081805181010312610779576020015147806109e4575b602082604051908152f35b5f80808093335af1156109f757816109d9565b33611656565b90503d805f833e610a0e8183610ca8565b8101906020818303126107795780519067ffffffffffffffff8211610779570181601f8201121561077957805190610a4582610e50565b92610a536040519485610ca8565b8284526020838301011161077957815f9260208093018386015e83010152816109c0565b34610779575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261077957602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b6101807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261077957610b1936610d18565b610b2236610de4565b906101243567ffffffffffffffff811161077957610b44903690600401610e8a565b91610144359283151580940361077957610164359283151580940361077957610976945f946108fc61093b946108e773ffffffffffffffffffffffffffffffffffffffff976108b560405197610b9989610c27565b3389526020890190815260408901928352606089019485526080890197885260a089019687526040519a8b996020808c0152511660408a015251606089019073ffffffffffffffffffffffffffffffffffffffff6080809282815116855282602082015116602086015262ffffff6040820151166040860152606081015160020b6060860152015116910152565b60c0810190811067ffffffffffffffff821117610c4357604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60a0810190811067ffffffffffffffff821117610c4357604052565b6080810190811067ffffffffffffffff821117610c4357604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610c4357604052565b359073ffffffffffffffffffffffffffffffffffffffff8216820361077957565b35908160020b820361077957565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60a09101126107795760405190610d4f82610c70565b8160043573ffffffffffffffffffffffffffffffffffffffff8116810361077957815260243573ffffffffffffffffffffffffffffffffffffffff8116810361077957602082015260443562ffffff811681036107795760408201526064358060020b81036107795760608201526084359073ffffffffffffffffffffffffffffffffffffffff821682036107795760800152565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5c60809101126107795760405190610e1b82610c8c565b8160a4358060020b810361077957815260c4358060020b810361077957602082015260e4356040820152606061010435910152565b67ffffffffffffffff8111610c4357601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b81601f8201121561077957803590610ea182610e50565b92610eaf6040519485610ca8565b8284526020838301011161077957815f926020809301838601378301015290565b3590811515820361077957565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f602080948051918291828752018686015e5f8582860101520116010190565b15610f2757565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b7f80000000000000000000000000000000000000000000000000000000000000008114610720575f0390565b94939290926040519460268601526006850152600384015282525f603a600c8401209281604082015281602082015252604051602081019182526006604082015260408152610fd0606082610ca8565b51902091600683018093116107205760445f9273ffffffffffffffffffffffffffffffffffffffff946040519060208201928352604082015260408152611018606082610ca8565b51902060405194859384927f35fd631a000000000000000000000000000000000000000000000000000000008452600484015260036024840152165afa908115610785575f91611078575b50602081015160408201516060909201519092565b90503d805f833e6110898183610ca8565b8101906020818303126107795780519067ffffffffffffffff821161077957019080601f830112156107795781519167ffffffffffffffff8311610c43578260051b90604051936110dd6020840186610ca8565b845260208085019282010192831161077957602001905b828210611104575050505f611063565b81518152602091820191016110f4565b929061112090846116c2565b9273ffffffffffffffffffffffffffffffffffffffff807f000000000000000000000000000000000000000000000000000000000000000016918161116584836116c2565b95165f5216602052602060405f206024604051809481937ff135baaa00000000000000000000000000000000000000000000000000000000835260048301525afa908115610785575f916111b7575090565b90506020813d6020116111de575b816111d260209383610ca8565b81010312610779575190565b3d91506111c5565b90816020910312610779575180151581036107795790565b90816020910312610779575190565b9293156112af5773ffffffffffffffffffffffffffffffffffffffff16803b15610779576040517ff5298aca00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831660048201529290911660248301526044820192909252905f908290818381606481015b03925af18015610785576112a35750565b5f6112ad91610ca8565b565b9173ffffffffffffffffffffffffffffffffffffffff168061134d57505073ffffffffffffffffffffffffffffffffffffffff600460209260405194859384927f11da60b4000000000000000000000000000000000000000000000000000000008452165af18015610785576113225750565b6113439060203d602011611346575b61133b8183610ca8565b8101906111fe565b50565b503d611331565b90929173ffffffffffffffffffffffffffffffffffffffff1691823b1561077957604051937fa58411940000000000000000000000000000000000000000000000000000000085525f948360048201525f8160248183895af180156107855761151c575b5073ffffffffffffffffffffffffffffffffffffffff16843082146114a8576020929160649160405195869485937f23b872dd000000000000000000000000000000000000000000000000000000008552600485015288602485015260448401525af1801561149d57916020918493611470575b505b6004604051809581937f11da60b40000000000000000000000000000000000000000000000000000000083525af190811561146457506113225750565b604051903d90823e3d90fd5b61148f90833d8511611496575b6114878183610ca8565b8101906111e6565b505f611425565b503d61147d565b6040513d85823e3d90fd5b929050604460209260405194859384927fa9059cbb00000000000000000000000000000000000000000000000000000000845288600485015260248401525af1801561149d579160209184936114ff575b50611427565b61151590833d8511611496576114878183610ca8565b505f6114f9565b6115299195505f90610ca8565b5f9373ffffffffffffffffffffffffffffffffffffffff6113b1565b9293156115ce5773ffffffffffffffffffffffffffffffffffffffff16803b15610779576040517f156e29f600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831660048201529290911660248301526044820192909252905f90829081838160648101611292565b90929073ffffffffffffffffffffffffffffffffffffffff16803b15610779575f928360649273ffffffffffffffffffffffffffffffffffffffff948560405198899788967f0b0d9c0900000000000000000000000000000000000000000000000000000000885216600487015216602485015260448401525af18015610785576112a35750565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f3d604051937f8549db59000000000000000000000000000000000000000000000000000000008552600485015260406024850152806044850152805f606486013e011660640190fd5b73ffffffffffffffffffffffffffffffffffffffff16806116e257503190565b9073ffffffffffffffffffffffffffffffffffffffff602460209260405194859384927f70a082310000000000000000000000000000000000000000000000000000000084521660048301525afa908115610785575f916111b757509056fea264697066735822122081fd8d0da8b43d074ee4b6817a8326f7fab52d40050df6e3ed50701db98def5564736f6c634300081a0033000000000000000000000000e5df461803a59292c6c03978c17857479c40bc46
Deployed Bytecode
0x60806040526004361015610011575f80fd5b5f3560e01c80630a5b11e414610ae5578063481c6a7514610a775780635a6bcfda14610790576391dd734614610045575f80fd5b346107795760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126107795760043567ffffffffffffffff8111610779573660238201121561077957806004013567ffffffffffffffff81116107795781016024810190368211610779577f000000000000000000000000e5df461803a59292c6c03978c17857479c40bc469273ffffffffffffffffffffffffffffffffffffffff841690813303610779576020818403126107795760248101359067ffffffffffffffff82116107795701906101a082840312610779576040519161012d83610c27565b61013960248201610ce9565b835260a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08286030112610779576040519361017485610c70565b61018060448301610ce9565b855261018e60648301610ce9565b6020860152608482013562ffffff811681036107795760408601526101b560a48301610d0a565b606086015260c482013573ffffffffffffffffffffffffffffffffffffffff81168103610779577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1c83608093602493858a01526020880198895203010112610779576040519561022487610c8c565b61023060e48301610d0a565b875261023f6101048301610d0a565b6020880152610124820135604088015261014482013560608801526040840196875261016482013567ffffffffffffffff81116107795761039f96602461028892850101610e8a565b916060850192835260406102b36101a46102a56101848501610ed0565b936080890194855201610ed0565b9360a087019485526102e060a08951208b51805160020b6060602083015160020b92015192309089610f80565b5050956103715f8c6103b38c519151955187519e8f97889687957f5a6bcfda000000000000000000000000000000000000000000000000000000008752600487019073ffffffffffffffffffffffffffffffffffffffff6080809282815116855282602082015116602086015262ffffff6040820151166040860152606081015160020b6060860152015116910152565b8051600290810b60a48701526020820151900b60c4860152604081015160e486015260600151610104850152565b610140610124840152610144830190610edd565b03925af1968715610785575f9761074d575b506103eb60a08751208951805160020b6060602083015160020b92015192309087610f80565b50509061042a73ffffffffffffffffffffffffffffffffffffffff88515116309073ffffffffffffffffffffffffffffffffffffffff89511690611114565b939150506fffffffffffffffffffffffffffffffff61047e73ffffffffffffffffffffffffffffffffffffffff60208b51015116309073ffffffffffffffffffffffffffffffffffffffff8b511690611114565b9891505016600f0b9060408b510151915f8382019384129112908015821691151617610720576fffffffffffffffffffffffffffffffff16600f0b036106c2576040610548995101515f81125f1461067d57505f82138015610674575b6104e490610f20565b5f8212801561066b575b6104f89015610f20565b5f821261061d575b5f85126105ca575b505f8113610583575b505f831361054c575b868660405190602082015260208152610534604082610ca8565b604051918291602083526020830190610edd565b0390f35b73ffffffffffffffffffffffffffffffffffffffff80602061057997510151169451169151151593611545565b5f8080808061051a565b6105c49073ffffffffffffffffffffffffffffffffffffffff875151169073ffffffffffffffffffffffffffffffffffffffff875116848651151593611545565b5f610511565b6106179073ffffffffffffffffffffffffffffffffffffffff602089510151169073ffffffffffffffffffffffffffffffffffffffff8851168561060d89610f54565b925115159361120d565b5f610508565b61066673ffffffffffffffffffffffffffffffffffffffff8851511673ffffffffffffffffffffffffffffffffffffffff88511661065a85610f54565b9086855115159361120d565b610500565b505f85126104ee565b505f85136104db565b5f12156104f8575f821280156106b9575b61069790610f20565b5f821380156106b0575b6106ab9015610f20565b6104f8565b505f85136106a1565b505f851261068e565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f6c6971756964697479206368616e676520696e636f72726563740000000000006044820152fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b9096506040813d60401161077d575b8161076960409383610ca8565b810103126107795751955f6103c5565b5f80fd5b3d915061075c565b6040513d5f823e3d90fd5b6101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610779576107c436610d18565b6107cd36610de4565b90610124359167ffffffffffffffff83116107795761093b5f9273ffffffffffffffffffffffffffffffffffffffff9261080e610976963690600401610e8a565b916108fc6040519361081f85610c27565b3385526020850192835260408501938452606085019081526108e760808601948986526108b560a08801958b87526040519a8b996020808c0152511660408a015251606089019073ffffffffffffffffffffffffffffffffffffffff6080809282815116855282602082015116602086015262ffffff6040820151166040860152606081015160020b6060860152015116910152565b518051600290810b6101008901526020820151900b610120880152604081015161014088015260600151610160870152565b516101a06101808601526101e0850190610edd565b915115156101a08401525115156101c0830152037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282610ca8565b604051809381927f48c89491000000000000000000000000000000000000000000000000000000008352602060048401526024830190610edd565b03818373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e5df461803a59292c6c03978c17857479c40bc46165af1908115610785575f916109fd575b50602081805181010312610779576020015147806109e4575b602082604051908152f35b5f80808093335af1156109f757816109d9565b33611656565b90503d805f833e610a0e8183610ca8565b8101906020818303126107795780519067ffffffffffffffff8211610779570181601f8201121561077957805190610a4582610e50565b92610a536040519485610ca8565b8284526020838301011161077957815f9260208093018386015e83010152816109c0565b34610779575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261077957602060405173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e5df461803a59292c6c03978c17857479c40bc46168152f35b6101807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261077957610b1936610d18565b610b2236610de4565b906101243567ffffffffffffffff811161077957610b44903690600401610e8a565b91610144359283151580940361077957610164359283151580940361077957610976945f946108fc61093b946108e773ffffffffffffffffffffffffffffffffffffffff976108b560405197610b9989610c27565b3389526020890190815260408901928352606089019485526080890197885260a089019687526040519a8b996020808c0152511660408a015251606089019073ffffffffffffffffffffffffffffffffffffffff6080809282815116855282602082015116602086015262ffffff6040820151166040860152606081015160020b6060860152015116910152565b60c0810190811067ffffffffffffffff821117610c4357604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60a0810190811067ffffffffffffffff821117610c4357604052565b6080810190811067ffffffffffffffff821117610c4357604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610c4357604052565b359073ffffffffffffffffffffffffffffffffffffffff8216820361077957565b35908160020b820361077957565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60a09101126107795760405190610d4f82610c70565b8160043573ffffffffffffffffffffffffffffffffffffffff8116810361077957815260243573ffffffffffffffffffffffffffffffffffffffff8116810361077957602082015260443562ffffff811681036107795760408201526064358060020b81036107795760608201526084359073ffffffffffffffffffffffffffffffffffffffff821682036107795760800152565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5c60809101126107795760405190610e1b82610c8c565b8160a4358060020b810361077957815260c4358060020b810361077957602082015260e4356040820152606061010435910152565b67ffffffffffffffff8111610c4357601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b81601f8201121561077957803590610ea182610e50565b92610eaf6040519485610ca8565b8284526020838301011161077957815f926020809301838601378301015290565b3590811515820361077957565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f602080948051918291828752018686015e5f8582860101520116010190565b15610f2757565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b7f80000000000000000000000000000000000000000000000000000000000000008114610720575f0390565b94939290926040519460268601526006850152600384015282525f603a600c8401209281604082015281602082015252604051602081019182526006604082015260408152610fd0606082610ca8565b51902091600683018093116107205760445f9273ffffffffffffffffffffffffffffffffffffffff946040519060208201928352604082015260408152611018606082610ca8565b51902060405194859384927f35fd631a000000000000000000000000000000000000000000000000000000008452600484015260036024840152165afa908115610785575f91611078575b50602081015160408201516060909201519092565b90503d805f833e6110898183610ca8565b8101906020818303126107795780519067ffffffffffffffff821161077957019080601f830112156107795781519167ffffffffffffffff8311610c43578260051b90604051936110dd6020840186610ca8565b845260208085019282010192831161077957602001905b828210611104575050505f611063565b81518152602091820191016110f4565b929061112090846116c2565b9273ffffffffffffffffffffffffffffffffffffffff807f000000000000000000000000e5df461803a59292c6c03978c17857479c40bc4616918161116584836116c2565b95165f5216602052602060405f206024604051809481937ff135baaa00000000000000000000000000000000000000000000000000000000835260048301525afa908115610785575f916111b7575090565b90506020813d6020116111de575b816111d260209383610ca8565b81010312610779575190565b3d91506111c5565b90816020910312610779575180151581036107795790565b90816020910312610779575190565b9293156112af5773ffffffffffffffffffffffffffffffffffffffff16803b15610779576040517ff5298aca00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831660048201529290911660248301526044820192909252905f908290818381606481015b03925af18015610785576112a35750565b5f6112ad91610ca8565b565b9173ffffffffffffffffffffffffffffffffffffffff168061134d57505073ffffffffffffffffffffffffffffffffffffffff600460209260405194859384927f11da60b4000000000000000000000000000000000000000000000000000000008452165af18015610785576113225750565b6113439060203d602011611346575b61133b8183610ca8565b8101906111fe565b50565b503d611331565b90929173ffffffffffffffffffffffffffffffffffffffff1691823b1561077957604051937fa58411940000000000000000000000000000000000000000000000000000000085525f948360048201525f8160248183895af180156107855761151c575b5073ffffffffffffffffffffffffffffffffffffffff16843082146114a8576020929160649160405195869485937f23b872dd000000000000000000000000000000000000000000000000000000008552600485015288602485015260448401525af1801561149d57916020918493611470575b505b6004604051809581937f11da60b40000000000000000000000000000000000000000000000000000000083525af190811561146457506113225750565b604051903d90823e3d90fd5b61148f90833d8511611496575b6114878183610ca8565b8101906111e6565b505f611425565b503d61147d565b6040513d85823e3d90fd5b929050604460209260405194859384927fa9059cbb00000000000000000000000000000000000000000000000000000000845288600485015260248401525af1801561149d579160209184936114ff575b50611427565b61151590833d8511611496576114878183610ca8565b505f6114f9565b6115299195505f90610ca8565b5f9373ffffffffffffffffffffffffffffffffffffffff6113b1565b9293156115ce5773ffffffffffffffffffffffffffffffffffffffff16803b15610779576040517f156e29f600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831660048201529290911660248301526044820192909252905f90829081838160648101611292565b90929073ffffffffffffffffffffffffffffffffffffffff16803b15610779575f928360649273ffffffffffffffffffffffffffffffffffffffff948560405198899788967f0b0d9c0900000000000000000000000000000000000000000000000000000000885216600487015216602485015260448401525af18015610785576112a35750565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f3d604051937f8549db59000000000000000000000000000000000000000000000000000000008552600485015260406024850152806044850152805f606486013e011660640190fd5b73ffffffffffffffffffffffffffffffffffffffff16806116e257503190565b9073ffffffffffffffffffffffffffffffffffffffff602460209260405194859384927f70a082310000000000000000000000000000000000000000000000000000000084521660048301525afa908115610785575f916111b757509056fea264697066735822122081fd8d0da8b43d074ee4b6817a8326f7fab52d40050df6e3ed50701db98def5564736f6c634300081a0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000e5df461803a59292c6c03978c17857479c40bc46
-----Decoded View---------------
Arg [0] : _manager (address): 0xE5dF461803a59292c6c03978c17857479c40bc46
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000e5df461803a59292c6c03978c17857479c40bc46
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.