Overview
ETH Balance
ETH Value
$0.00Latest 10 from a total of 10 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Set Swap Route | 27524844 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Swap Route | 27524843 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Swap Route | 27524843 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Swap Route | 27524842 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Swap Path | 27524841 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Swap Path | 27524840 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Swap Path | 27524840 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Swap Path | 27524840 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Routes Opera... | 27524840 | 129 days ago | IN | 0 ETH | 0 | ||||
| Set Components | 27524839 | 129 days ago | IN | 0 ETH | 0 |
View more zero value Internal Transactions in Advanced View mode
Cross-Chain Transactions
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// ** v4 imports
import {PoolKey} from "v4-core/types/PoolKey.sol";
import {Actions} from "v4-periphery/src/libraries/Actions.sol";
import {Currency} from "v4-core/types/Currency.sol";
import {IV4Router, PathKey} from "v4-periphery/src/interfaces/IV4Router.sol";
import {IPermit2} from "v4-periphery/lib/permit2/src/interfaces/IPermit2.sol";
import {IWETH9} from "v4-periphery/src/interfaces/external/IWETH9.sol";
import {IPoolManager} from "v4-core/interfaces/IPoolManager.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
// ** external imports
import {mulDiv18 as mul18} from "@prb-math/Common.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Commands} from "@universal-router/Commands.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IUniversalRouter} from "@universal-router/IUniversalRouter.sol";
// ** contracts
import {Base} from "../base/Base.sol";
// ** interfaces
import {ISwapAdapter} from "../../interfaces/ISwapAdapter.sol";
/// @title Uniswap Swap Adapter
/// @notice Provides swap functionality with Uniswap V2, V3, and V4 using UniversalRouter.
contract UniswapSwapAdapter is Base, ISwapAdapter {
error InvalidSwapRoute();
error InvalidProtocolType();
error NotRoutesOperator(address account);
error RouteNotFound(bool isBaseToQuote, bool isExactInput);
event RoutesOperatorSet(address indexed routesOperator);
event SwapPathSet(uint256 indexed swapRouteId, uint8 indexed protocolType, bytes input);
event SwapRouteSet(uint8 indexed swapKey, uint256[] swapRoute);
using SafeERC20 for IERC20;
IUniversalRouter public immutable router;
IPoolManager public immutable manager;
IPermit2 public immutable permit2;
address public routesOperator;
IWETH9 public immutable WETH9;
struct SwapPath {
uint8 protocolType;
bytes input;
}
mapping(uint256 => SwapPath) public swapPaths;
mapping(uint8 => uint256[]) public swapRoutes;
constructor(
IERC20 _base,
IERC20 _quote,
IUniversalRouter _router,
IPoolManager _manager,
IPermit2 _permit2,
IWETH9 _WETH9
) Base(ComponentType.EXTERNAL_ADAPTER, msg.sender, _base, _quote) {
router = _router;
manager = _manager;
permit2 = _permit2;
WETH9 = _WETH9;
BASE.forceApprove(address(permit2), type(uint256).max);
permit2.approve(address(BASE), address(router), type(uint160).max, type(uint48).max);
QUOTE.forceApprove(address(permit2), type(uint256).max);
permit2.approve(address(QUOTE), address(router), type(uint160).max, type(uint48).max);
}
function setRoutesOperator(address _routesOperator) external onlyOwner {
routesOperator = _routesOperator;
emit RoutesOperatorSet(_routesOperator);
}
/**
* @notice Sets the swap route for a given swap key based on input/output and base/quote direction.
* @param isExactInput Indicates whether the swap is for an exact input amount (true) or an exact output amount (false).
* @param isBaseToQuote Indicates the direction of the swap: true for base-to-quote, false for quote-to-base.
* @param swapRoute An array containing path IDs and their corresponding multipliers.
* For example, [1, 35e18, 3] means 35% of the amount is routed through path 1 and the remaining 65% through path 3.
* The array must have an odd number of elements, where even indices are path IDs and odd indices are multipliers (in 1e18 precision).
*/
function setSwapRoute(
bool isExactInput,
bool isBaseToQuote,
uint256[] calldata swapRoute
) external onlyRoutesOperator {
if (swapRoute.length % 2 == 0) revert InvalidSwapRoute();
uint8 swapKey = toSwapKey(isExactInput, isBaseToQuote);
swapRoutes[swapKey] = swapRoute;
emit SwapRouteSet(swapKey, swapRoute);
}
/**
* @notice Sets the swap path details for a given swap path ID.
* @dev Defines the protocol and input data used for a specific swap path.
* @param swapPathId The unique identifier for the swap path.
* @param protocolType The protocol type to use:
* 0 = Uniswap V2, 1 = Uniswap V3, 2 = Uniswap V4 (single swap), 3 = Uniswap V4 (multihop swap).
* @param input Encoded input data required by the specified protocol for the swap path.
*/
function setSwapPath(uint256 swapPathId, uint8 protocolType, bytes calldata input) external onlyRoutesOperator {
swapPaths[swapPathId] = SwapPath({protocolType: protocolType, input: input});
emit SwapPathSet(swapPathId, protocolType, input);
}
function swapExactInput(
bool isBaseToQuote,
uint256 amountIn
) external onlyModule notPaused returns (uint256 amountOut) {
if (amountIn == 0) return 0;
IERC20 tokenIn = isBaseToQuote ? BASE : QUOTE;
IERC20 tokenOut = isBaseToQuote ? QUOTE : BASE;
tokenIn.safeTransferFrom(msg.sender, address(this), amountIn);
executeSwap(isBaseToQuote, true, amountIn);
amountOut = tokenOut.balanceOf(address(this));
tokenOut.safeTransfer(msg.sender, amountOut);
}
function swapExactOutput(
bool isBaseToQuote,
uint256 amountOut
) external onlyModule notPaused returns (uint256 amountIn) {
if (amountOut == 0) return 0;
IERC20 tokenIn = isBaseToQuote ? BASE : QUOTE;
IERC20 tokenOut = isBaseToQuote ? QUOTE : BASE;
amountIn = tokenIn.balanceOf(msg.sender);
tokenIn.safeTransferFrom(msg.sender, address(this), amountIn);
executeSwap(isBaseToQuote, false, amountOut);
tokenOut.safeTransfer(msg.sender, amountOut);
uint256 amountExtra = tokenIn.balanceOf(address(this));
if (amountExtra > 0) {
tokenIn.safeTransfer(msg.sender, amountExtra);
amountIn -= amountExtra;
}
}
function executeSwap(bool isBaseToQuote, bool isExactInput, uint256 amountTarget) internal {
bytes memory swapCommands;
uint256[] memory route = swapRoutes[toSwapKey(isExactInput, isBaseToQuote)];
if (route.length == 0) revert RouteNotFound(isBaseToQuote, isExactInput);
bytes[] memory inputs = new bytes[]((route.length + 1) / 2 + 1);
uint256 amountTargetLeft = amountTarget;
for (uint256 i = 0; i < route.length + 1; ) {
SwapPath memory path = swapPaths[route[i]];
if (path.protocolType > 3) revert InvalidProtocolType();
uint256 nextAmount = route.length == i + 1 ? amountTargetLeft : mul18(amountTarget, route[i + 1]);
uint8 nextCommand;
if (path.protocolType == 0) {
nextCommand = isExactInput ? uint8(Commands.V2_SWAP_EXACT_IN) : uint8(Commands.V2_SWAP_EXACT_OUT);
inputs[i / 2] = _getV2Input(isExactInput, nextAmount, path.input);
} else if (path.protocolType == 1) {
nextCommand = isExactInput ? uint8(Commands.V3_SWAP_EXACT_IN) : uint8(Commands.V3_SWAP_EXACT_OUT);
inputs[i / 2] = _getV3Input(isExactInput, nextAmount, path.input);
} else {
nextCommand = uint8(Commands.V4_SWAP);
inputs[i / 2] = _getV4Input(
isBaseToQuote,
isExactInput,
path.protocolType == 3,
nextAmount,
path.input
);
}
swapCommands = bytes.concat(swapCommands, bytes(abi.encodePacked(nextCommand)));
amountTargetLeft -= nextAmount;
unchecked {
i += 2;
}
}
// Always sweep extra ETH from router to adapter.
swapCommands = bytes.concat(swapCommands, bytes(abi.encodePacked(uint8(Commands.SWEEP))));
inputs[inputs.length - 1] = abi.encode(address(0), address(this), 0);
uint256 ethBalance = address(this).balance;
router.execute{value: ethBalance}(swapCommands, inputs, block.timestamp);
// If router returns ETH, we need to wrap it.
ethBalance = address(this).balance;
if (ethBalance > 0) WETH9.deposit{value: ethBalance}();
}
function _getV2Input(bool isExactInput, uint256 amount, bytes memory route) internal view returns (bytes memory) {
address[] memory path = abi.decode(route, (address[]));
return abi.encode(address(this), amount, isExactInput ? 0 : type(uint256).max, path, true);
}
function _getV3Input(bool isExactInput, uint256 amount, bytes memory path) internal view returns (bytes memory) {
return abi.encode(address(this), amount, isExactInput ? 0 : type(uint256).max, path, true);
}
function _getV4Input(
bool isBaseToQuote,
bool isExactInput,
bool isMultihop,
uint256 amount,
bytes memory route
) internal returns (bytes memory) {
bytes[] memory params = new bytes[](3);
uint8 swapAction;
bool unwrapBefore;
if (isMultihop) {
PathKey[] memory path;
(unwrapBefore, path) = abi.decode(route, (bool, PathKey[]));
swapAction = isExactInput ? uint8(Actions.SWAP_EXACT_IN) : uint8(Actions.SWAP_EXACT_OUT);
params[0] = abi.encode(
// We use ExactInputParams structure for both exact input and output swaps
// since parameter structure is identical.
IV4Router.ExactInputParams({
currencyIn: adjustForEth(isBaseToQuote == isExactInput ? BASE : QUOTE), // or currencyOut for ExactOutputParams.
path: path,
amountIn: SafeCast.toUint128(amount), // or amountOut for ExactOutputParams.
amountOutMinimum: isExactInput ? uint128(0) : type(uint128).max // or amountInMaximum for ExactOutputParams.
})
);
} else {
PoolKey memory key;
bool zeroForOne;
bytes memory hookData;
(unwrapBefore, key, zeroForOne, hookData) = abi.decode(route, (bool, PoolKey, bool, bytes));
swapAction = isExactInput ? uint8(Actions.SWAP_EXACT_IN_SINGLE) : uint8(Actions.SWAP_EXACT_OUT_SINGLE);
params[0] = abi.encode(
// We use ExactInputSingleParams structure for both exact input and output swaps
// since parameter structure is identical.
IV4Router.ExactInputSingleParams({
poolKey: key,
zeroForOne: zeroForOne,
amountIn: SafeCast.toUint128(amount), // or amountOut for ExactOutputSingleParams.
amountOutMinimum: isExactInput ? uint128(0) : type(uint128).max, // or amountInMaximum for ExactInputSingleParams.
hookData: hookData
})
);
}
if (unwrapBefore) isExactInput ? WETH9.withdraw(amount) : WETH9.withdraw(WETH9.balanceOf(address(this)));
params[1] = abi.encode(adjustForEth(isBaseToQuote ? BASE : QUOTE), isExactInput ? amount : type(uint256).max);
params[2] = abi.encode(adjustForEth(isBaseToQuote ? QUOTE : BASE), isExactInput ? 0 : amount);
return abi.encode(abi.encodePacked(swapAction, uint8(Actions.SETTLE_ALL), uint8(Actions.TAKE_ALL)), params);
}
receive() external payable notPaused {
if (msg.sender != address(WETH9) && msg.sender != address(manager) && msg.sender != address(router))
revert InvalidNativeTokenSender();
}
// ** Helpers
function adjustForEth(IERC20 token) internal view returns (Currency) {
if (address(token) == address(WETH9)) return Currency.wrap(address(0));
return Currency.wrap(address(token));
}
function toSwapKey(bool isExactInput, bool isBaseToQuote) public pure returns (uint8) {
return (isExactInput ? 2 : 0) + (isBaseToQuote ? 1 : 0);
}
// ** Modifiers
modifier onlyRoutesOperator() {
if (msg.sender != routesOperator) revert NotRoutesOperator(msg.sender);
_;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
/// @title Commands
/// @notice Command Flags used to decode commands
library Commands {
// Masks to extract certain bits of commands
bytes1 internal constant FLAG_ALLOW_REVERT = 0x80;
bytes1 internal constant COMMAND_TYPE_MASK = 0x3f;
// Command Types. Maximum supported command at this moment is 0x3f.
// The commands are executed in nested if blocks to minimise gas consumption
// Command Types where value<=0x07, executed in the first nested-if block
uint256 constant V3_SWAP_EXACT_IN = 0x00;
uint256 constant V3_SWAP_EXACT_OUT = 0x01;
uint256 constant PERMIT2_TRANSFER_FROM = 0x02;
uint256 constant PERMIT2_PERMIT_BATCH = 0x03;
uint256 constant SWEEP = 0x04;
uint256 constant TRANSFER = 0x05;
uint256 constant PAY_PORTION = 0x06;
// COMMAND_PLACEHOLDER = 0x07;
// Command Types where 0x08<=value<=0x0f, executed in the second nested-if block
uint256 constant V2_SWAP_EXACT_IN = 0x08;
uint256 constant V2_SWAP_EXACT_OUT = 0x09;
uint256 constant PERMIT2_PERMIT = 0x0a;
uint256 constant WRAP_ETH = 0x0b;
uint256 constant UNWRAP_WETH = 0x0c;
uint256 constant PERMIT2_TRANSFER_FROM_BATCH = 0x0d;
uint256 constant BALANCE_CHECK_ERC20 = 0x0e;
// COMMAND_PLACEHOLDER = 0x0f;
// Command Types where 0x10<=value<=0x20, executed in the third nested-if block
uint256 constant V4_SWAP = 0x10;
uint256 constant V3_POSITION_MANAGER_PERMIT = 0x11;
uint256 constant V3_POSITION_MANAGER_CALL = 0x12;
uint256 constant V4_INITIALIZE_POOL = 0x13;
uint256 constant V4_POSITION_MANAGER_CALL = 0x14;
// COMMAND_PLACEHOLDER = 0x15 -> 0x20
// Command Types where 0x21<=value<=0x3f
uint256 constant EXECUTE_SUB_PLAN = 0x21;
// COMMAND_PLACEHOLDER for 0x22 to 0x3f
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
interface IUniversalRouter {
/// @notice Thrown when a required command has failed
error ExecutionFailed(uint256 commandIndex, bytes message);
/// @notice Thrown when attempting to send ETH directly to the contract
error ETHNotAccepted();
/// @notice Thrown when executing commands with an expired deadline
error TransactionDeadlinePassed();
/// @notice Thrown when attempting to execute commands and an incorrect number of inputs are provided
error LengthMismatch();
// @notice Thrown when an address that isn't WETH tries to send ETH to the router without calldata
error InvalidEthSender();
/// @notice Executes encoded commands along with provided inputs. Reverts if deadline has expired.
/// @param commands A set of concatenated commands, each 1 byte in length
/// @param inputs An array of byte strings containing abi encoded inputs for each command
/// @param deadline The deadline by which the transaction must be executed
function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
// Common.sol
//
// Common mathematical functions used in both SD59x18 and UD60x18. Note that these global functions do not
// always operate with SD59x18 and UD60x18 numbers.
/*//////////////////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
error PRBMath_MulDivSigned_InputTooSmall();
/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev The maximum value a uint128 number can have.
uint128 constant MAX_UINT128 = type(uint128).max;
/// @dev The maximum value a uint40 number can have.
uint40 constant MAX_UINT40 = type(uint40).max;
/// @dev The maximum value a uint64 number can have.
uint64 constant MAX_UINT64 = type(uint64).max;
/// @dev The unit number, which the decimal precision of the fixed-point types.
uint256 constant UNIT = 1e18;
/// @dev The unit number inverted mod 2^256.
uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
/// bit in the binary representation of `UNIT`.
uint256 constant UNIT_LPOTD = 262144;
/*//////////////////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the binary exponent of x using the binary fraction method.
/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
/// @param x The exponent as an unsigned 192.64-bit fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function exp2(uint256 x) pure returns (uint256 result) {
unchecked {
// Start from 0.5 in the 192.64-bit fixed-point format.
result = 0x800000000000000000000000000000000000000000000000;
// The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
//
// 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
// 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
// a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
// we know that `x & 0xFF` is also 1.
if (x & 0xFF00000000000000 > 0) {
if (x & 0x8000000000000000 > 0) {
result = (result * 0x16A09E667F3BCC909) >> 64;
}
if (x & 0x4000000000000000 > 0) {
result = (result * 0x1306FE0A31B7152DF) >> 64;
}
if (x & 0x2000000000000000 > 0) {
result = (result * 0x1172B83C7D517ADCE) >> 64;
}
if (x & 0x1000000000000000 > 0) {
result = (result * 0x10B5586CF9890F62A) >> 64;
}
if (x & 0x800000000000000 > 0) {
result = (result * 0x1059B0D31585743AE) >> 64;
}
if (x & 0x400000000000000 > 0) {
result = (result * 0x102C9A3E778060EE7) >> 64;
}
if (x & 0x200000000000000 > 0) {
result = (result * 0x10163DA9FB33356D8) >> 64;
}
if (x & 0x100000000000000 > 0) {
result = (result * 0x100B1AFA5ABCBED61) >> 64;
}
}
if (x & 0xFF000000000000 > 0) {
if (x & 0x80000000000000 > 0) {
result = (result * 0x10058C86DA1C09EA2) >> 64;
}
if (x & 0x40000000000000 > 0) {
result = (result * 0x1002C605E2E8CEC50) >> 64;
}
if (x & 0x20000000000000 > 0) {
result = (result * 0x100162F3904051FA1) >> 64;
}
if (x & 0x10000000000000 > 0) {
result = (result * 0x1000B175EFFDC76BA) >> 64;
}
if (x & 0x8000000000000 > 0) {
result = (result * 0x100058BA01FB9F96D) >> 64;
}
if (x & 0x4000000000000 > 0) {
result = (result * 0x10002C5CC37DA9492) >> 64;
}
if (x & 0x2000000000000 > 0) {
result = (result * 0x1000162E525EE0547) >> 64;
}
if (x & 0x1000000000000 > 0) {
result = (result * 0x10000B17255775C04) >> 64;
}
}
if (x & 0xFF0000000000 > 0) {
if (x & 0x800000000000 > 0) {
result = (result * 0x1000058B91B5BC9AE) >> 64;
}
if (x & 0x400000000000 > 0) {
result = (result * 0x100002C5C89D5EC6D) >> 64;
}
if (x & 0x200000000000 > 0) {
result = (result * 0x10000162E43F4F831) >> 64;
}
if (x & 0x100000000000 > 0) {
result = (result * 0x100000B1721BCFC9A) >> 64;
}
if (x & 0x80000000000 > 0) {
result = (result * 0x10000058B90CF1E6E) >> 64;
}
if (x & 0x40000000000 > 0) {
result = (result * 0x1000002C5C863B73F) >> 64;
}
if (x & 0x20000000000 > 0) {
result = (result * 0x100000162E430E5A2) >> 64;
}
if (x & 0x10000000000 > 0) {
result = (result * 0x1000000B172183551) >> 64;
}
}
if (x & 0xFF00000000 > 0) {
if (x & 0x8000000000 > 0) {
result = (result * 0x100000058B90C0B49) >> 64;
}
if (x & 0x4000000000 > 0) {
result = (result * 0x10000002C5C8601CC) >> 64;
}
if (x & 0x2000000000 > 0) {
result = (result * 0x1000000162E42FFF0) >> 64;
}
if (x & 0x1000000000 > 0) {
result = (result * 0x10000000B17217FBB) >> 64;
}
if (x & 0x800000000 > 0) {
result = (result * 0x1000000058B90BFCE) >> 64;
}
if (x & 0x400000000 > 0) {
result = (result * 0x100000002C5C85FE3) >> 64;
}
if (x & 0x200000000 > 0) {
result = (result * 0x10000000162E42FF1) >> 64;
}
if (x & 0x100000000 > 0) {
result = (result * 0x100000000B17217F8) >> 64;
}
}
if (x & 0xFF000000 > 0) {
if (x & 0x80000000 > 0) {
result = (result * 0x10000000058B90BFC) >> 64;
}
if (x & 0x40000000 > 0) {
result = (result * 0x1000000002C5C85FE) >> 64;
}
if (x & 0x20000000 > 0) {
result = (result * 0x100000000162E42FF) >> 64;
}
if (x & 0x10000000 > 0) {
result = (result * 0x1000000000B17217F) >> 64;
}
if (x & 0x8000000 > 0) {
result = (result * 0x100000000058B90C0) >> 64;
}
if (x & 0x4000000 > 0) {
result = (result * 0x10000000002C5C860) >> 64;
}
if (x & 0x2000000 > 0) {
result = (result * 0x1000000000162E430) >> 64;
}
if (x & 0x1000000 > 0) {
result = (result * 0x10000000000B17218) >> 64;
}
}
if (x & 0xFF0000 > 0) {
if (x & 0x800000 > 0) {
result = (result * 0x1000000000058B90C) >> 64;
}
if (x & 0x400000 > 0) {
result = (result * 0x100000000002C5C86) >> 64;
}
if (x & 0x200000 > 0) {
result = (result * 0x10000000000162E43) >> 64;
}
if (x & 0x100000 > 0) {
result = (result * 0x100000000000B1721) >> 64;
}
if (x & 0x80000 > 0) {
result = (result * 0x10000000000058B91) >> 64;
}
if (x & 0x40000 > 0) {
result = (result * 0x1000000000002C5C8) >> 64;
}
if (x & 0x20000 > 0) {
result = (result * 0x100000000000162E4) >> 64;
}
if (x & 0x10000 > 0) {
result = (result * 0x1000000000000B172) >> 64;
}
}
if (x & 0xFF00 > 0) {
if (x & 0x8000 > 0) {
result = (result * 0x100000000000058B9) >> 64;
}
if (x & 0x4000 > 0) {
result = (result * 0x10000000000002C5D) >> 64;
}
if (x & 0x2000 > 0) {
result = (result * 0x1000000000000162E) >> 64;
}
if (x & 0x1000 > 0) {
result = (result * 0x10000000000000B17) >> 64;
}
if (x & 0x800 > 0) {
result = (result * 0x1000000000000058C) >> 64;
}
if (x & 0x400 > 0) {
result = (result * 0x100000000000002C6) >> 64;
}
if (x & 0x200 > 0) {
result = (result * 0x10000000000000163) >> 64;
}
if (x & 0x100 > 0) {
result = (result * 0x100000000000000B1) >> 64;
}
}
if (x & 0xFF > 0) {
if (x & 0x80 > 0) {
result = (result * 0x10000000000000059) >> 64;
}
if (x & 0x40 > 0) {
result = (result * 0x1000000000000002C) >> 64;
}
if (x & 0x20 > 0) {
result = (result * 0x10000000000000016) >> 64;
}
if (x & 0x10 > 0) {
result = (result * 0x1000000000000000B) >> 64;
}
if (x & 0x8 > 0) {
result = (result * 0x10000000000000006) >> 64;
}
if (x & 0x4 > 0) {
result = (result * 0x10000000000000003) >> 64;
}
if (x & 0x2 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
if (x & 0x1 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
}
// In the code snippet below, two operations are executed simultaneously:
//
// 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
// accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
// 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
//
// The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
// integer part, $2^n$.
result *= UNIT;
result >>= (191 - (x >> 64));
}
}
/// @notice Finds the zero-based index of the first 1 in the binary representation of x.
///
/// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
///
/// Each step in this implementation is equivalent to this high-level code:
///
/// ```solidity
/// if (x >= 2 ** 128) {
/// x >>= 128;
/// result += 128;
/// }
/// ```
///
/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
///
/// The Yul instructions used below are:
///
/// - "gt" is "greater than"
/// - "or" is the OR bitwise operator
/// - "shl" is "shift left"
/// - "shr" is "shift right"
///
/// @param x The uint256 number for which to find the index of the most significant bit.
/// @return result The index of the most significant bit as a uint256.
/// @custom:smtchecker abstract-function-nondet
function msb(uint256 x) pure returns (uint256 result) {
// 2^128
assembly ("memory-safe") {
let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^64
assembly ("memory-safe") {
let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^32
assembly ("memory-safe") {
let factor := shl(5, gt(x, 0xFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^16
assembly ("memory-safe") {
let factor := shl(4, gt(x, 0xFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^8
assembly ("memory-safe") {
let factor := shl(3, gt(x, 0xFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^4
assembly ("memory-safe") {
let factor := shl(2, gt(x, 0xF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^2
assembly ("memory-safe") {
let factor := shl(1, gt(x, 0x3))
x := shr(factor, x)
result := or(result, factor)
}
// 2^1
// No need to shift x any more.
assembly ("memory-safe") {
let factor := gt(x, 0x1)
result := or(result, factor)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - The denominator must not be zero.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as a uint256.
/// @param y The multiplier as a uint256.
/// @param denominator The divisor as a uint256.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// 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; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
unchecked {
return prod0 / denominator;
}
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (prod1 >= denominator) {
revert PRBMath_MulDiv_Overflow(x, y, denominator);
}
////////////////////////////////////////////////////////////////////////////
// 512 by 256 division
////////////////////////////////////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using the mulmod Yul instruction.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512-bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
unchecked {
// Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
// because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
// For more detail, see https://cs.stackexchange.com/q/138556/92363.
uint256 lpotdod = denominator & (~denominator + 1);
uint256 flippedLpotdod;
assembly ("memory-safe") {
// Factor powers of two out of denominator.
denominator := div(denominator, lpotdod)
// Divide [prod1 prod0] by lpotdod.
prod0 := div(prod0, lpotdod)
// Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
// `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
// However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * flippedLpotdod;
// 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 for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the 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.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // 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 * inverse;
}
}
/// @notice Calculates x*y÷1e18 with 512-bit precision.
///
/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
///
/// Notes:
/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
/// - The result is rounded toward zero.
/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
///
/// $$
/// \begin{cases}
/// x * y = MAX\_UINT256 * UNIT \\
/// (x * y) \% UNIT \geq \frac{UNIT}{2}
/// \end{cases}
/// $$
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
uint256 prod0;
uint256 prod1;
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
unchecked {
return prod0 / UNIT;
}
}
if (prod1 >= UNIT) {
revert PRBMath_MulDiv18_Overflow(x, y);
}
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(x, y, UNIT)
result :=
mul(
or(
div(sub(prod0, remainder), UNIT_LPOTD),
mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
),
UNIT_INVERSE
)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - None of the inputs can be `type(int256).min`.
/// - The result must fit in int256.
///
/// @param x The multiplicand as an int256.
/// @param y The multiplier as an int256.
/// @param denominator The divisor as an int256.
/// @return result The result as an int256.
/// @custom:smtchecker abstract-function-nondet
function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
revert PRBMath_MulDivSigned_InputTooSmall();
}
// Get hold of the absolute values of x, y and the denominator.
uint256 xAbs;
uint256 yAbs;
uint256 dAbs;
unchecked {
xAbs = x < 0 ? uint256(-x) : uint256(x);
yAbs = y < 0 ? uint256(-y) : uint256(y);
dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
}
// Compute the absolute value of x*y÷denominator. The result must fit in int256.
uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
if (resultAbs > uint256(type(int256).max)) {
revert PRBMath_MulDivSigned_Overflow(x, y);
}
// Get the signs of x, y and the denominator.
uint256 sx;
uint256 sy;
uint256 sd;
assembly ("memory-safe") {
// "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
sx := sgt(x, sub(0, 1))
sy := sgt(y, sub(0, 1))
sd := sgt(denominator, sub(0, 1))
}
// XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
// If there are, the result should be negative. Otherwise, it should be positive.
unchecked {
result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function sqrt(uint256 x) pure returns (uint256 result) {
if (x == 0) {
return 0;
}
// For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
//
// We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
//
// $$
// msb(x) <= x <= 2*msb(x)$
// $$
//
// We write $msb(x)$ as $2^k$, and we get:
//
// $$
// k = log_2(x)
// $$
//
// Thus, we can write the initial inequality as:
//
// $$
// 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
// sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
// 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
// $$
//
// Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
uint256 xAux = uint256(x);
result = 1;
if (xAux >= 2 ** 128) {
xAux >>= 128;
result <<= 64;
}
if (xAux >= 2 ** 64) {
xAux >>= 64;
result <<= 32;
}
if (xAux >= 2 ** 32) {
xAux >>= 32;
result <<= 16;
}
if (xAux >= 2 ** 16) {
xAux >>= 16;
result <<= 8;
}
if (xAux >= 2 ** 8) {
xAux >>= 8;
result <<= 4;
}
if (xAux >= 2 ** 4) {
xAux >>= 4;
result <<= 2;
}
if (xAux >= 2 ** 2) {
result <<= 1;
}
// At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
// most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision
// doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of
// precision into the expected uint128 result.
unchecked {
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
// If x is not a perfect square, round the result toward zero.
uint256 roundedResult = x / result;
if (result >= roundedResult) {
result = roundedResult;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IEIP712} from "./IEIP712.sol";
/// @title AllowanceTransfer
/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
/// @dev Requires user's token approval on the Permit2 contract
interface IAllowanceTransfer is IEIP712 {
/// @notice Thrown when an allowance on a token has expired.
/// @param deadline The timestamp at which the allowed amount is no longer valid
error AllowanceExpired(uint256 deadline);
/// @notice Thrown when an allowance on a token has been depleted.
/// @param amount The maximum amount allowed
error InsufficientAllowance(uint256 amount);
/// @notice Thrown when too many nonces are invalidated.
error ExcessiveInvalidation();
/// @notice Emits an event when the owner successfully invalidates an ordered nonce.
event NonceInvalidation(
address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
);
/// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
event Approval(
address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
);
/// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
event Permit(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration,
uint48 nonce
);
/// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
event Lockdown(address indexed owner, address token, address spender);
/// @notice The permit data for a token
struct PermitDetails {
// ERC20 token address
address token;
// the maximum amount allowed to spend
uint160 amount;
// timestamp at which a spender's token allowances become invalid
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice The permit message signed for a single token allowance
struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The permit message signed for multiple token allowances
struct PermitBatch {
// the permit data for multiple token allowances
PermitDetails[] details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The saved permissions
/// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
/// @dev Setting amount to type(uint160).max sets an unlimited approval
struct PackedAllowance {
// amount allowed
uint160 amount;
// permission expiry
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice A token spender pair.
struct TokenSpenderPair {
// the token the spender is approved
address token;
// the spender address
address spender;
}
/// @notice Details for a token transfer.
struct AllowanceTransferDetails {
// the owner of the token
address from;
// the recipient of the token
address to;
// the amount of the token
uint160 amount;
// the token to be transferred
address token;
}
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
/// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
function allowance(address user, address token, address spender)
external
view
returns (uint160 amount, uint48 expiration, uint48 nonce);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration
/// @param token The token to approve
/// @param spender The spender address to approve
/// @param amount The approved amount of the token
/// @param expiration The timestamp at which the approval is no longer valid
/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
/// @dev Setting amount to type(uint160).max sets an unlimited approval
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitSingle Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;
/// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitBatch Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;
/// @notice Transfer approved tokens from one address to another
/// @param from The address to transfer from
/// @param to The address of the recipient
/// @param amount The amount of the token to transfer
/// @param token The token address to transfer
/// @dev Requires the from address to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(address from, address to, uint160 amount, address token) external;
/// @notice Transfer approved tokens in a batch
/// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
/// @dev Requires the from addresses to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
/// @notice Enables performing a "lockdown" of the sender's Permit2 identity
/// by batch revoking approvals
/// @param approvals Array of approvals to revoke.
function lockdown(TokenSpenderPair[] calldata approvals) external;
/// @notice Invalidate nonces for a given (token, spender) pair
/// @param token The token to invalidate nonces for
/// @param spender The spender to invalidate nonces for
/// @param newNonce The new nonce to set. Invalidates all nonces less than it.
/// @dev Can't invalidate more than 2**16 nonces per transaction.
function invalidateNonces(address token, address spender, uint48 newNonce) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IEIP712 {
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {ISignatureTransfer} from "./ISignatureTransfer.sol";
import {IAllowanceTransfer} from "./IAllowanceTransfer.sol";
/// @notice Permit2 handles signature-based transfers in SignatureTransfer and allowance-based transfers in AllowanceTransfer.
/// @dev Users must approve Permit2 before calling any of the transfer functions.
interface IPermit2 is ISignatureTransfer, IAllowanceTransfer {
// IPermit2 unifies the two interfaces so users have maximal flexibility with their approval.
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IEIP712} from "./IEIP712.sol";
/// @title SignatureTransfer
/// @notice Handles ERC20 token transfers through signature based actions
/// @dev Requires user's token approval on the Permit2 contract
interface ISignatureTransfer is IEIP712 {
/// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
/// @param maxAmount The maximum amount a spender can request to transfer
error InvalidAmount(uint256 maxAmount);
/// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
/// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
error LengthMismatch();
/// @notice Emits an event when the owner successfully invalidates an unordered nonce.
event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask);
/// @notice The token and amount details for a transfer signed in the permit transfer signature
struct TokenPermissions {
// ERC20 token address
address token;
// the maximum amount that can be spent
uint256 amount;
}
/// @notice The signed permit message for a single token transfer
struct PermitTransferFrom {
TokenPermissions permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice Specifies the recipient address and amount for batched transfers.
/// @dev Recipients and amounts correspond to the index of the signed token permissions array.
/// @dev Reverts if the requested amount is greater than the permitted signed amount.
struct SignatureTransferDetails {
// recipient address
address to;
// spender requested amount
uint256 requestedAmount;
}
/// @notice Used to reconstruct the signed permit message for multiple token transfers
/// @dev Do not need to pass in spender address as it is required that it is msg.sender
/// @dev Note that a user still signs over a spender address
struct PermitBatchTransferFrom {
// the tokens and corresponding amounts permitted for a transfer
TokenPermissions[] permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
/// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
/// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
/// @dev It returns a uint256 bitmap
/// @dev The index, or wordPosition is capped at type(uint248).max
function nonceBitmap(address, uint256) external view returns (uint256);
/// @notice Transfers a token using a signed permit message
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param signature The signature to verify
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers a token using a signed permit message
/// @notice Includes extra data provided by the caller to verify signature over
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param signature The signature to verify
function permitTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @notice Includes extra data provided by the caller to verify signature over
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Invalidates the bits specified in mask for the bitmap at the word position
/// @dev The wordPos is maxed at type(uint248).max
/// @param wordPos A number to index the nonceBitmap at
/// @param mask A bitmap masked against msg.sender's current bitmap at the word position
function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}// 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: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.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,
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,
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,
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 removing 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,
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, 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,
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.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";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.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 initialized 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);
/// @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
/// @dev Note that feesAccrued can be artificially inflated by a malicious actor and integrators should be careful using the value
/// For pools with a single liquidity position, actors can donate to themselves to inflate feeGrowthGlobal (and consequently feesAccrued)
/// atomically donating and collecting fees in the same unlockCallback may make the inflated value more extreme
function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
external
returns (BalanceDelta callerDelta, BalanceDelta feesAccrued);
/// @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 Will revert if the requested amount is not available, consider using `mint` instead
/// @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 {Currency} from "../types/Currency.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 collectProtocolFees or setProtocolFee is not called by the controller.
error InvalidCaller();
/// @notice Thrown when collectProtocolFees is attempted on a token that is synced.
error ProtocolFeeCurrencySynced();
/// @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(address 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 address The current protocol fee controller address
function protocolFeeController() external view returns (address);
}// SPDX-License-Identifier: MIT
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;
/// @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;
/// @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 ERC-7751 error for wrapping bubbled up reverts
error WrappedError(address target, bytes4 selector, bytes reason, bytes details);
/// @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 a wrapped ERC-7751 error
/// @dev this method can be vulnerable to revert data bombs
function bubbleUpAndRevertWith(
address revertingContract,
bytes4 revertingFunctionSelector,
bytes4 additionalContext
) internal pure {
bytes4 wrappedErrorSelector = WrappedError.selector;
assembly ("memory-safe") {
// Ensure the size of the revert data is a multiple of 32 bytes
let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)
let fmp := mload(0x40)
// Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
mstore(fmp, wrappedErrorSelector)
mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(
add(fmp, 0x24),
and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
// offset revert reason
mstore(add(fmp, 0x44), 0x80)
// offset additional context
mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
// size revert reason
mstore(add(fmp, 0x84), returndatasize())
// revert reason
returndatacopy(add(fmp, 0xa4), 0, returndatasize())
// size additional context
mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
// additional context
mstore(
add(fmp, add(0xc4, encodedDataSize)),
and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
revert(fmp, add(0xe4, encodedDataSize))
}
}
}// SPDX-License-Identifier: MIT
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;
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;
// 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: 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 {
/// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
error NativeTransferFailed();
/// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
error ERC20TransferFailed();
/// @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) {
CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
}
} 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) {
CustomRevert.bubbleUpAndRevertWith(
Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector
);
}
}
}
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.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;
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: MIT
pragma solidity ^0.8.24;
import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
/// @notice Parameter struct for `ModifyLiquidity` pool operations
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 Parameter struct for `Swap` pool operations
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;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
/// @title IImmutableState
/// @notice Interface for the ImmutableState contract
interface IImmutableState {
/// @notice The Uniswap v4 PoolManager contract
function poolManager() external view returns (IPoolManager);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {PathKey} from "../libraries/PathKey.sol";
import {IImmutableState} from "./IImmutableState.sol";
/// @title IV4Router
/// @notice Interface for the V4Router contract
interface IV4Router is IImmutableState {
/// @notice Emitted when an exactInput swap does not receive its minAmountOut
error V4TooLittleReceived(uint256 minAmountOutReceived, uint256 amountReceived);
/// @notice Emitted when an exactOutput is asked for more than its maxAmountIn
error V4TooMuchRequested(uint256 maxAmountInRequested, uint256 amountRequested);
/// @notice Parameters for a single-hop exact-input swap
struct ExactInputSingleParams {
PoolKey poolKey;
bool zeroForOne;
uint128 amountIn;
uint128 amountOutMinimum;
bytes hookData;
}
/// @notice Parameters for a multi-hop exact-input swap
struct ExactInputParams {
Currency currencyIn;
PathKey[] path;
uint128 amountIn;
uint128 amountOutMinimum;
}
/// @notice Parameters for a single-hop exact-output swap
struct ExactOutputSingleParams {
PoolKey poolKey;
bool zeroForOne;
uint128 amountOut;
uint128 amountInMaximum;
bytes hookData;
}
/// @notice Parameters for a multi-hop exact-output swap
struct ExactOutputParams {
Currency currencyOut;
PathKey[] path;
uint128 amountOut;
uint128 amountInMaximum;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title IWETH9
interface IWETH9 is IERC20 {
/// @notice Deposit ether to get wrapped ether
function deposit() external payable;
/// @notice Withdraw wrapped ether to get ether
function withdraw(uint256) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Library to define different pool actions.
/// @dev These are suggested common commands, however additional commands should be defined as required
/// Some of these actions are not supported in the Router contracts or Position Manager contracts, but are left as they may be helpful commands for other peripheral contracts.
library Actions {
// pool actions
// liquidity actions
uint256 internal constant INCREASE_LIQUIDITY = 0x00;
uint256 internal constant DECREASE_LIQUIDITY = 0x01;
uint256 internal constant MINT_POSITION = 0x02;
uint256 internal constant BURN_POSITION = 0x03;
uint256 internal constant INCREASE_LIQUIDITY_FROM_DELTAS = 0x04;
uint256 internal constant MINT_POSITION_FROM_DELTAS = 0x05;
// swapping
uint256 internal constant SWAP_EXACT_IN_SINGLE = 0x06;
uint256 internal constant SWAP_EXACT_IN = 0x07;
uint256 internal constant SWAP_EXACT_OUT_SINGLE = 0x08;
uint256 internal constant SWAP_EXACT_OUT = 0x09;
// donate
// note this is not supported in the position manager or router
uint256 internal constant DONATE = 0x0a;
// closing deltas on the pool manager
// settling
uint256 internal constant SETTLE = 0x0b;
uint256 internal constant SETTLE_ALL = 0x0c;
uint256 internal constant SETTLE_PAIR = 0x0d;
// taking
uint256 internal constant TAKE = 0x0e;
uint256 internal constant TAKE_ALL = 0x0f;
uint256 internal constant TAKE_PORTION = 0x10;
uint256 internal constant TAKE_PAIR = 0x11;
uint256 internal constant CLOSE_CURRENCY = 0x12;
uint256 internal constant CLEAR_OR_TAKE = 0x13;
uint256 internal constant SWEEP = 0x14;
uint256 internal constant WRAP = 0x15;
uint256 internal constant UNWRAP = 0x16;
// minting/burning 6909s to close deltas
// note this is not supported in the position manager or router
uint256 internal constant MINT_6909 = 0x17;
uint256 internal constant BURN_6909 = 0x18;
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
struct PathKey {
Currency intermediateCurrency;
uint24 fee;
int24 tickSpacing;
IHooks hooks;
bytes hookData;
}
using PathKeyLibrary for PathKey global;
/// @title PathKey Library
/// @notice Functions for working with PathKeys
library PathKeyLibrary {
/// @notice Get the pool and swap direction for a given PathKey
/// @param params the given PathKey
/// @param currencyIn the input currency
/// @return poolKey the pool key of the swap
/// @return zeroForOne the direction of the swap, true if currency0 is being swapped for currency1
function getPoolAndSwapDirection(PathKey calldata params, Currency currencyIn)
internal
pure
returns (PoolKey memory poolKey, bool zeroForOne)
{
Currency currencyOut = params.intermediateCurrency;
(Currency currency0, Currency currency1) =
currencyIn < currencyOut ? (currencyIn, currencyOut) : (currencyOut, currencyIn);
zeroForOne = currencyIn == currency0;
poolKey = PoolKey(currency0, currency1, params.fee, params.tickSpacing, params.hooks);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// ** external imports
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// ** interfaces
import {IALM} from "../../interfaces/IALM.sol";
import {IBaseStrategyHook} from "../../interfaces/IBaseStrategyHook.sol";
import {ILendingAdapter} from "../../interfaces/ILendingAdapter.sol";
import {IFlashLoanAdapter} from "../../interfaces/IFlashLoanAdapter.sol";
import {IPositionManager} from "../../interfaces/IPositionManager.sol";
import {IOracle} from "../../interfaces/IOracle.sol";
import {IRebalanceAdapter} from "../../interfaces/IRebalanceAdapter.sol";
import {ISwapAdapter} from "../../interfaces/ISwapAdapter.sol";
import {IBase} from "../../interfaces/IBase.sol";
/// @title Base
/// @notice Abstract contract that serves as the base for all modules and adapters.
abstract contract Base is IBase {
using SafeERC20 for IERC20;
enum ComponentType {
ALM,
HOOK,
REBALANCE_ADAPTER,
POSITION_MANAGER,
EXTERNAL_ADAPTER
}
ComponentType public immutable componentType;
address public owner;
IERC20 public immutable BASE;
IERC20 public immutable QUOTE;
IALM public alm;
IBaseStrategyHook public hook;
ILendingAdapter public lendingAdapter;
IFlashLoanAdapter public flashLoanAdapter;
IPositionManager public positionManager;
IOracle public oracle;
IRebalanceAdapter public rebalanceAdapter;
ISwapAdapter public swapAdapter;
constructor(ComponentType _componentType, address initialOwner, IERC20 _base, IERC20 _quote) {
componentType = _componentType;
BASE = _base;
QUOTE = _quote;
owner = initialOwner;
emit OwnershipTransferred(address(0), initialOwner);
}
function setComponents(
IALM _alm,
IBaseStrategyHook _hook,
ILendingAdapter _lendingAdapter,
IFlashLoanAdapter _flashLoanAdapter,
IPositionManager _positionManager,
IOracle _oracle,
IRebalanceAdapter _rebalanceAdapter,
ISwapAdapter _swapAdapter
) external onlyOwner {
alm = _alm;
hook = _hook;
oracle = _oracle;
rebalanceAdapter = _rebalanceAdapter;
if (componentType == ComponentType.POSITION_MANAGER) {
switchApproval(address(lendingAdapter), address(_lendingAdapter));
} else if (componentType == ComponentType.HOOK) {
switchApproval(address(lendingAdapter), address(_lendingAdapter));
switchApproval(address(positionManager), address(_positionManager));
} else if (componentType == ComponentType.ALM || componentType == ComponentType.REBALANCE_ADAPTER) {
switchApproval(address(lendingAdapter), address(_lendingAdapter));
switchApproval(address(flashLoanAdapter), address(_flashLoanAdapter));
switchApproval(address(swapAdapter), address(_swapAdapter));
}
lendingAdapter = _lendingAdapter;
flashLoanAdapter = _flashLoanAdapter;
swapAdapter = _swapAdapter;
positionManager = _positionManager;
}
function switchApproval(address moduleOld, address moduleNew) internal {
if (moduleOld == moduleNew) return;
if (moduleOld != address(0)) {
BASE.forceApprove(moduleOld, 0);
QUOTE.forceApprove(moduleOld, 0);
}
BASE.forceApprove(moduleNew, type(uint256).max);
QUOTE.forceApprove(moduleNew, type(uint256).max);
}
function transferOwnership(address newOwner) external onlyOwner {
if (owner == newOwner) return;
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
// ** Modifiers
modifier onlyOwner() {
if (owner != msg.sender) {
revert OwnableUnauthorizedAccount(msg.sender);
}
_;
}
/// @dev Only the ALM may call this function.
modifier onlyALM() {
if (msg.sender != address(alm)) revert NotALM(msg.sender);
_;
}
modifier onlyHook() {
if (msg.sender != address(hook)) revert NotHook(msg.sender);
_;
}
/// @dev Only the rebalance adapter may call this function.
modifier onlyRebalanceAdapter() {
if (msg.sender != address(rebalanceAdapter)) revert NotRebalanceAdapter(msg.sender);
_;
}
/// @dev Only the flash loan adapter may call this function.
modifier onlyFlashLoanAdapter() {
if (msg.sender != address(flashLoanAdapter)) revert NotFlashLoanAdapter(msg.sender);
_;
}
/// @dev Only modules may call this function.
modifier onlyModule() {
if (
msg.sender != address(alm) &&
msg.sender != address(hook) &&
msg.sender != address(rebalanceAdapter) &&
msg.sender != address(positionManager)
) revert NotModule(msg.sender);
_;
}
/// @notice Restricts function execution when contract is paused.
/// @dev Allows execution when status is active (0) or shutdown (2).
/// @dev Reverts with ContractPaused when status equals 1 (paused).
modifier notPaused() {
if (alm.status() == 1) revert ContractPaused();
_;
}
/// @notice Restricts function execution when contract is not active.
/// @dev Allows execution when status equals 0 (active).
/// @dev Reverts with ContractNotActive when status is paused (1) or shutdown (2).
modifier onlyActive() {
if (alm.status() != 0) revert ContractNotActive();
_;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Defines the interface for an Automated Liquidity Manager.
interface IALM {
error ZeroLiquidity();
error NotZeroShares();
error NotMinOutWithdrawBase();
error NotMinOutWithdrawQuote();
error NotALiquidityOperator();
error TVLCapExceeded();
error NotAValidPositionState();
error NotMinShares();
event StatusSet(uint8 indexed status);
event OperatorSet(address indexed liquidityOperator);
event TVLCapSet(uint256 tvlCap);
event Deposit(address indexed to, uint256 amount, uint256 delShares, uint256 TVL, uint256 totalSupply);
event Withdraw(
address indexed to,
uint256 delShares,
uint256 baseOut,
uint256 quoteOut,
uint256 totalSupply,
uint256 liquidity
);
function status() external view returns (uint8);
function TVL(uint256 price) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// ** interfaces
import {IALM} from "./IALM.sol";
import {IBaseStrategyHook} from "./IBaseStrategyHook.sol";
import {ILendingAdapter} from "./ILendingAdapter.sol";
import {IFlashLoanAdapter} from "./IFlashLoanAdapter.sol";
import {IPositionManager} from "./IPositionManager.sol";
import {IOracle} from "./IOracle.sol";
import {IRebalanceAdapter} from "./IRebalanceAdapter.sol";
import {ISwapAdapter} from "./ISwapAdapter.sol";
/// @notice Defines the interface for a Base contract.
interface IBase {
error OwnableUnauthorizedAccount(address account);
error NotALM(address account);
error NotHook(address account);
error NotRebalanceAdapter(address account);
error NotModule(address account);
error NotFlashLoanAdapter(address account);
error ContractPaused();
error ContractNotActive();
error InvalidNativeTokenSender();
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function setComponents(
IALM _alm,
IBaseStrategyHook _hook,
ILendingAdapter _lendingAdapter,
IFlashLoanAdapter _flashLoanAdapter,
IPositionManager _positionManager,
IOracle _oracle,
IRebalanceAdapter _rebalanceAdapter,
ISwapAdapter _swapAdapter
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Defines the interface for a Base Strategy Hook.
interface IBaseStrategyHook {
error AddLiquidityThroughHook();
error UnauthorizedPool();
error SwapPriceChangeTooHigh();
error NotASwapOperator();
error OnlyOnePoolPerHook();
error MustUseDynamicFee();
error ProtocolFeeNotValid();
error LiquidityMultiplierNotValid();
error TicksMisordered(int24 tickLower, int24 tickUpper);
error TickLowerOutOfBounds(int24 tick);
error TickUpperOutOfBounds(int24 tick);
error TickDeltasNotValid();
error LPFeeTooLarge(uint24 fee);
error NativeTokenUnsupported();
event OperatorSet(address indexed swapOperator);
event TreasurySet(address indexed treasury);
event ProtocolParamsSet(
uint256 liquidityMultiplier,
uint256 protocolFee,
uint256 swapPriceThreshold,
int24 tickLowerDelta,
int24 tickUpperDelta
);
event LiquidityUpdated(uint128 newLiquidity);
event SqrtPriceUpdated(uint160 newSqrtPrice);
event BoundariesUpdated(int24 newTickLower, int24 newTickUpper);
event LPFeeSet(uint24 fee);
event HookFee(bytes32 indexed id, address indexed sender, uint128 feeAmount0, uint128 feeAmount1);
struct Ticks {
int24 lower;
int24 upper;
}
function activeTicks() external view returns (int24 lower, int24 upper);
function tickDeltas() external view returns (int24 lower, int24 upper);
function refreshReservesAndTransferFees() external;
function updateLiquidityAndBoundariesToOracle() external;
function updateLiquidityAndBoundaries(uint160 sqrtPrice) external returns (uint128 newLiquidity);
function updateLiquidity() external returns (uint128 newLiquidity);
function isInvertedPool() external view returns (bool);
function protocolFee() external view returns (uint256);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/// @notice Defines the interface for a Flash Loan Adapter.
interface IFlashLoanAdapter {
function flashLoanSingle(bool isBase, uint256 amount, bytes calldata data) external;
function flashLoanTwoTokens(uint256 amountBase, uint256 amountQuote, bytes calldata data) external;
}
/// @notice Defines the interface for a Flash Loan Receiver.
interface IFlashLoanReceiver {
function onFlashLoanSingle(bool isBase, uint256 amount, bytes calldata data) external;
function onFlashLoanTwoTokens(uint256 amountBase, uint256 amountQuote, bytes calldata data) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/// @notice Defines the interface for a Lending Adapter.
interface ILendingAdapter {
// ** Position management
function getPosition() external view returns (uint256, uint256, uint256, uint256);
function updatePosition(int256 deltaCL, int256 deltaCS, int256 deltaDL, int256 deltaDS) external;
// ** Long market
function getBorrowedLong() external view returns (uint256);
function borrowLong(uint256 amountUSDC) external;
function repayLong(uint256 amountUSDC) external;
function getCollateralLong() external view returns (uint256);
function removeCollateralLong(uint256 amountWETH) external;
function addCollateralLong(uint256 amountWETH) external;
// ** Short market
function getBorrowedShort() external view returns (uint256);
function borrowShort(uint256 amountWETH) external;
function repayShort(uint256 amountWETH) external;
function getCollateralShort() external view returns (uint256);
function removeCollateralShort(uint256 amountUSDC) external;
function addCollateralShort(uint256 amountUSDC) external;
// ** Helpers
function syncPositions() external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/// @notice Defines the interface for an Oracle.
interface IOracle {
error TotalDecimalsDeltaNotValid();
error PriceZero();
error SqrtPriceNotValid();
function price() external view returns (uint256);
function poolPrice() external view returns (uint256, uint160);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/// @notice Defines the interface for a Position Manager.
interface IPositionManager {
function positionAdjustmentPriceUp(uint256 deltaUSDC, uint256 deltaWETH, uint160 sqrtPrice) external;
function positionAdjustmentPriceDown(uint256 deltaUSDC, uint256 deltaWETH, uint160 sqrtPrice) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Defines the interface for a Rebalance Adapter.
interface IRebalanceAdapter {
function sqrtPriceAtLastRebalance() external view returns (uint160);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/// @notice Defines the interface for a Swap Adapter.
interface ISwapAdapter {
function swapExactOutput(bool isBaseToQuote, uint256 amountOut) external returns (uint256 amountIn);
function swapExactInput(bool isBaseToQuote, uint256 amountIn) external returns (uint256 amountOut);
}{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 800,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@forks/=test/forks/",
"@src/=src/",
"@test/=test/",
"forge-std/=lib/forge-std/src/",
"v4-core/=lib/v4-periphery/lib/v4-core/src/",
"v4-core-test/=lib/v4-periphery/lib/v4-core/test/",
"v4-periphery/=lib/v4-periphery/",
"@v3-periphery/=external/v3-periphery/",
"@openzeppelin/contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/token/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/contracts/token/",
"@openzeppelin/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/contracts/",
"@morpho-blue/=lib/morpho-blue/src/",
"@chainlink/=lib/chainlink-brownie-contracts/contracts/src/v0.8/",
"@prb-math/=lib/prb-math/src/",
"@morpho-oracles/=external/morpho-oracles/",
"@v3-core/=external/v3-core/",
"@v2-core/=external/v2-core/",
"@universal-router/=external/universal-router/",
"@euler-interfaces/=external/euler-interfaces/",
"@merkl-contracts/=external/merkl-contracts/",
"@permit2/=external/permit2/",
"@universal-rewards-distributor/=external/universal-rewards-distributor/",
"@solmate/=lib/v4-periphery/lib/v4-core/lib/solmate/",
"@ensdomains/=lib/v4-periphery/lib/v4-core/node_modules/@ensdomains/",
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"chainlink-brownie-contracts/=lib/chainlink-brownie-contracts/",
"ds-test/=lib/morpho-blue/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"halmos-cheatcodes/=lib/morpho-blue/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-periphery/lib/v4-core/node_modules/hardhat/",
"morpho-blue/=lib/morpho-blue/",
"openzeppelin-contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
"permit2/=lib/v4-periphery/lib/permit2/",
"prb-math/=lib/prb-math/src/",
"solmate/=lib/v4-periphery/lib/v4-core/lib/solmate/"
],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IERC20","name":"_base","type":"address"},{"internalType":"contract IERC20","name":"_quote","type":"address"},{"internalType":"contract IUniversalRouter","name":"_router","type":"address"},{"internalType":"contract IPoolManager","name":"_manager","type":"address"},{"internalType":"contract IPermit2","name":"_permit2","type":"address"},{"internalType":"contract IWETH9","name":"_WETH9","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"ContractNotActive","type":"error"},{"inputs":[],"name":"ContractPaused","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidNativeTokenSender","type":"error"},{"inputs":[],"name":"InvalidProtocolType","type":"error"},{"inputs":[],"name":"InvalidSwapRoute","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"NotALM","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"NotFlashLoanAdapter","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"NotHook","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"NotModule","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"NotRebalanceAdapter","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"NotRoutesOperator","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"PRBMath_MulDiv18_Overflow","type":"error"},{"inputs":[{"internalType":"bool","name":"isBaseToQuote","type":"bool"},{"internalType":"bool","name":"isExactInput","type":"bool"}],"name":"RouteNotFound","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"routesOperator","type":"address"}],"name":"RoutesOperatorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"swapRouteId","type":"uint256"},{"indexed":true,"internalType":"uint8","name":"protocolType","type":"uint8"},{"indexed":false,"internalType":"bytes","name":"input","type":"bytes"}],"name":"SwapPathSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint8","name":"swapKey","type":"uint8"},{"indexed":false,"internalType":"uint256[]","name":"swapRoute","type":"uint256[]"}],"name":"SwapRouteSet","type":"event"},{"inputs":[],"name":"BASE","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"QUOTE","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"alm","outputs":[{"internalType":"contract IALM","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"componentType","outputs":[{"internalType":"enum Base.ComponentType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"flashLoanAdapter","outputs":[{"internalType":"contract IFlashLoanAdapter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hook","outputs":[{"internalType":"contract IBaseStrategyHook","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lendingAdapter","outputs":[{"internalType":"contract ILendingAdapter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"contract IPoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"contract IOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"contract IPermit2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract IPositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalanceAdapter","outputs":[{"internalType":"contract IRebalanceAdapter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"contract IUniversalRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"routesOperator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IALM","name":"_alm","type":"address"},{"internalType":"contract IBaseStrategyHook","name":"_hook","type":"address"},{"internalType":"contract ILendingAdapter","name":"_lendingAdapter","type":"address"},{"internalType":"contract IFlashLoanAdapter","name":"_flashLoanAdapter","type":"address"},{"internalType":"contract IPositionManager","name":"_positionManager","type":"address"},{"internalType":"contract IOracle","name":"_oracle","type":"address"},{"internalType":"contract IRebalanceAdapter","name":"_rebalanceAdapter","type":"address"},{"internalType":"contract ISwapAdapter","name":"_swapAdapter","type":"address"}],"name":"setComponents","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_routesOperator","type":"address"}],"name":"setRoutesOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"swapPathId","type":"uint256"},{"internalType":"uint8","name":"protocolType","type":"uint8"},{"internalType":"bytes","name":"input","type":"bytes"}],"name":"setSwapPath","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"isExactInput","type":"bool"},{"internalType":"bool","name":"isBaseToQuote","type":"bool"},{"internalType":"uint256[]","name":"swapRoute","type":"uint256[]"}],"name":"setSwapRoute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapAdapter","outputs":[{"internalType":"contract ISwapAdapter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"isBaseToQuote","type":"bool"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"swapExactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"isBaseToQuote","type":"bool"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"swapExactOutput","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"swapPaths","outputs":[{"internalType":"uint8","name":"protocolType","type":"uint8"},{"internalType":"bytes","name":"input","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"","type":"uint8"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"swapRoutes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"isExactInput","type":"bool"},{"internalType":"bool","name":"isBaseToQuote","type":"bool"}],"name":"toSwapKey","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
610160604052348015610010575f80fd5b5060405161379c38038061379c83398101604081905261002f916104fc565b6004338787836080819052506001600160a01b0382811660a05281811660c0525f80546001600160a01b03191691851691821781556040517f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3505050506001600160a01b0384811660e052838116610100528281166101208190528282166101405260a0516100c59216905f196101e2565b6101205160a05160e0516040516387517c4560e01b81526001600160a01b03928316600482015290821660248201526044810182905265ffffffffffff60648201529116906387517c45906084015f604051808303815f87803b15801561012a575f80fd5b505af115801561013c573d5f803e3d5ffd5b50506101205160c05161015c93506001600160a01b031691505f196101e2565b6101205160c05160e0516040516387517c4560e01b81526001600160a01b03928316600482015290821660248201526044810182905265ffffffffffff60648201529116906387517c45906084015f604051808303815f87803b1580156101c1575f80fd5b505af11580156101d3573d5f803e3d5ffd5b505050505050505050506105b4565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b0390811663095ea7b360e01b1790915261023a90859083906102a616565b6102a057604080516001600160a01b03851660248201525f6044808301919091528251808303909101815260649091019091526020810180516001600160e01b0390811663095ea7b360e01b1790915261029691869161034716565b6102a08482610347565b50505050565b5f805f846001600160a01b0316846040516102c1919061057f565b5f604051808303815f865af19150503d805f81146102fa576040519150601f19603f3d011682016040523d82523d5f602084013e6102ff565b606091505b50915091508180156103295750805115806103295750808060200190518101906103299190610595565b801561033e57505f856001600160a01b03163b115b95945050505050565b5f61035b6001600160a01b038416836103b2565b905080515f1415801561037f57508080602001905181019061037d9190610595565b155b156103ad57604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b505050565b60606103bf83835f6103c6565b9392505050565b6060814710156103eb5760405163cd78605960e01b81523060048201526024016103a4565b5f80856001600160a01b03168486604051610406919061057f565b5f6040518083038185875af1925050503d805f8114610440576040519150601f19603f3d011682016040523d82523d5f602084013e610445565b606091505b509092509050610456868383610460565b9695505050505050565b60608261047557610470826104bc565b6103bf565b815115801561048c57506001600160a01b0384163b155b156104b557604051639996b31560e01b81526001600160a01b03851660048201526024016103a4565b50806103bf565b8051156104cc5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b50565b6001600160a01b03811681146104e5575f80fd5b5f805f805f8060c08789031215610511575f80fd5b865161051c816104e8565b602088015190965061052d816104e8565b604088015190955061053e816104e8565b606088015190945061054f816104e8565b6080880151909350610560816104e8565b60a0880151909250610571816104e8565b809150509295509295509295565b5f82518060208501845e5f920191825250919050565b5f602082840312156105a5575f80fd5b815180151581146103bf575f80fd5b60805160a05160c05160e0516101005161012051610140516130cc6106d05f395f818161024e0152818161045c015281816117e501528181611dac01528181611e8b015261215201525f61030f01525f8181610282015261040a01525f81816102b7015281816106e5015261176f01525f81816105750152818161084e015281816108c401528181610f2601528181610f9c015281816119010152818161196a01528181611bc401528181611ef50152611f9e01525f8181610655015281816108740152818161089e01528181610f4c01528181610f76015281816118cd0152818161193501528181611bea0152611f7801525f818161038c01528181610afb01528181610b4f01528181610bb30152610bee01526130cc5ff3fe6080604052600436106101a7575f3560e01c80638da5cb5b116100e7578063e3c50e6811610087578063f5272e6411610062578063f5272e6414610696578063f57ba117146106b5578063f887ea40146106d4578063fe47263114610707575f80fd5b8063e3c50e6814610625578063ec342ad014610644578063f2fde38b14610677575f80fd5b8063ac3a7f39116100c2578063ac3a7f3914610597578063b7aafcde146105c8578063b8f6eb8a146105e7578063ccf5a52414610606575f80fd5b80638da5cb5b1461051957806393243509146105375780639c57983914610564575f80fd5b8063491748341161015257806377bb1eb91161012d57806377bb1eb91461049d578063791b98bc146104bc5780637dc0d1d0146104db5780637f5a7c7b146104fa575f80fd5b8063491748341461042c5780634aa4a4fc1461044b5780634d6ee82f1461047e575f80fd5b80632f8637c8116101825780632f8637c8146103bb57806330811b29146103da578063481c6a75146103f9575f80fd5b806312261ee7146102fe578063144bf2fa1461034e5780632a942db71461037b575f80fd5b366102fa5760015f9054906101000a90046001600160a01b03166001600160a01b031663200d2ed26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101fc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061022091906123e8565b60ff166001036102435760405163ab35696f60e01b815260040160405180910390fd5b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148015906102a55750336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614155b80156102da5750336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614155b156102f85760405163040af20760e31b815260040160405180910390fd5b005b5f80fd5b348015610309575f80fd5b506103317f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b348015610359575f80fd5b5061036d610368366004612410565b610726565b604051908152602001610345565b348015610386575f80fd5b506103ae7f000000000000000000000000000000000000000000000000000000000000000081565b604051610345919061244e565b3480156103c6575f80fd5b506102f86103d5366004612474565b61098c565b3480156103e5575f80fd5b50600754610331906001600160a01b031681565b348015610404575f80fd5b506103317f000000000000000000000000000000000000000000000000000000000000000081565b348015610437575f80fd5b50600354610331906001600160a01b031681565b348015610456575f80fd5b506103317f000000000000000000000000000000000000000000000000000000000000000081565b348015610489575f80fd5b506102f861049836600461250d565b610a81565b3480156104a8575f80fd5b50600854610331906001600160a01b031681565b3480156104c7575f80fd5b50600554610331906001600160a01b031681565b3480156104e6575f80fd5b50600654610331906001600160a01b031681565b348015610505575f80fd5b50600254610331906001600160a01b031681565b348015610524575f80fd5b505f54610331906001600160a01b031681565b348015610542575f80fd5b506105566105513660046125b1565b610cba565b6040516103459291906125f6565b34801561056f575f80fd5b506103317f000000000000000000000000000000000000000000000000000000000000000081565b3480156105a2575f80fd5b506105b66105b1366004612619565b610d60565b60405160ff9091168152602001610345565b3480156105d3575f80fd5b506102f86105e2366004612650565b610d8e565b3480156105f2575f80fd5b50600154610331906001600160a01b031681565b348015610611575f80fd5b5061036d610620366004612410565b610e03565b348015610630575f80fd5b5061036d61063f36600461266b565b6110f5565b34801561064f575f80fd5b506103317f000000000000000000000000000000000000000000000000000000000000000081565b348015610682575f80fd5b506102f8610691366004612650565b611120565b3480156106a1575f80fd5b506102f86106b0366004612687565b6111b6565b3480156106c0575f80fd5b50600954610331906001600160a01b031681565b3480156106df575f80fd5b506103317f000000000000000000000000000000000000000000000000000000000000000081565b348015610712575f80fd5b50600454610331906001600160a01b031681565b6001545f906001600160a01b0316331480159061074e57506002546001600160a01b03163314155b801561076557506007546001600160a01b03163314155b801561077c57506005546001600160a01b03163314155b156107a15760405163cb11855160e01b81523360048201526024015b60405180910390fd5b60015f9054906101000a90046001600160a01b03166001600160a01b031663200d2ed26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107f1573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061081591906123e8565b60ff166001036108385760405163ab35696f60e01b815260040160405180910390fd5b815f0361084657505f610986565b5f83610872577f0000000000000000000000000000000000000000000000000000000000000000610894565b7f00000000000000000000000000000000000000000000000000000000000000005b90505f846108c2577f00000000000000000000000000000000000000000000000000000000000000006108e4565b7f00000000000000000000000000000000000000000000000000000000000000005b90506108fb6001600160a01b03831633308761127c565b610907856001866112fe565b6040516370a0823160e01b81523060048201526001600160a01b038216906370a0823190602401602060405180830381865afa158015610949573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061096d919061270a565b92506109836001600160a01b038216338561185e565b50505b92915050565b6009546001600160a01b031633146109b9576040516355f748ad60e11b8152336004820152602401610798565b60405180604001604052808460ff16815260200183838080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920182905250939094525050868152600a602090815260409091208351815460ff191660ff909116178155908301519091506001820190610a3990826127b8565b509050508260ff16847ff2191fc55efd701281b72273e11a86b3b00b78cfcd9dd1d76544c2352da055358484604051610a73929190612873565b60405180910390a350505050565b5f546001600160a01b03163314610aad5760405163118cdaa760e01b8152336004820152602401610798565b600180546001600160a01b03808b166001600160a01b031992831617909255600280548a841690831617905560068054868416908316179055600780549285169290911691909117905560037f00000000000000000000000000000000000000000000000000000000000000006004811115610b2b57610b2b61243a565b03610b4b57600354610b46906001600160a01b031687611894565b610c67565b60017f00000000000000000000000000000000000000000000000000000000000000006004811115610b7f57610b7f61243a565b03610bb057600354610b9a906001600160a01b031687611894565b600554610b46906001600160a01b031685611894565b5f7f00000000000000000000000000000000000000000000000000000000000000006004811115610be357610be361243a565b1480610c20575060027f00000000000000000000000000000000000000000000000000000000000000006004811115610c1e57610c1e61243a565b145b15610c6757600354610c3b906001600160a01b031687611894565b600454610c51906001600160a01b031686611894565b600854610c67906001600160a01b031682611894565b600380546001600160a01b039788166001600160a01b0319918216179091556004805496881696821696909617909555600880549187169186169190911790555050600580549190931691161790555050565b600a6020525f90815260409020805460018201805460ff9092169291610cdf90612735565b80601f0160208091040260200160405190810160405280929190818152602001828054610d0b90612735565b8015610d565780601f10610d2d57610100808354040283529160200191610d56565b820191905f5260205f20905b815481529060010190602001808311610d3957829003601f168201915b5050505050905082565b5f81610d6c575f610d6f565b60015b83610d7a575f610d7d565b60025b610d8791906128b5565b9392505050565b5f546001600160a01b03163314610dba5760405163118cdaa760e01b8152336004820152602401610798565b600980546001600160a01b0319166001600160a01b0383169081179091556040517f56d07dc61bef1fbbbc5d202bd5ee4f5a995de4be8a081b67ca1f8b89d2137fa8905f90a250565b6001545f906001600160a01b03163314801590610e2b57506002546001600160a01b03163314155b8015610e4257506007546001600160a01b03163314155b8015610e5957506005546001600160a01b03163314155b15610e795760405163cb11855160e01b8152336004820152602401610798565b60015f9054906101000a90046001600160a01b03166001600160a01b031663200d2ed26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ec9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eed91906123e8565b60ff16600103610f105760405163ab35696f60e01b815260040160405180910390fd5b815f03610f1e57505f610986565b5f83610f4a577f0000000000000000000000000000000000000000000000000000000000000000610f6c565b7f00000000000000000000000000000000000000000000000000000000000000005b90505f84610f9a577f0000000000000000000000000000000000000000000000000000000000000000610fbc565b7f00000000000000000000000000000000000000000000000000000000000000005b6040516370a0823160e01b81523360048201529091506001600160a01b038316906370a0823190602401602060405180830381865afa158015611001573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611025919061270a565b925061103c6001600160a01b03831633308661127c565b611047855f866112fe565b61105b6001600160a01b038216338661185e565b6040516370a0823160e01b81523060048201525f906001600160a01b038416906370a0823190602401602060405180830381865afa15801561109f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110c3919061270a565b905080156110ec576110df6001600160a01b038416338361185e565b6110e981856128ce565b93505b50505092915050565b600b602052815f5260405f20818154811061110e575f80fd5b905f5260205f20015f91509150505481565b5f546001600160a01b0316331461114c5760405163118cdaa760e01b8152336004820152602401610798565b5f546001600160a01b038281169116146111b3575f80546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a35f80546001600160a01b0319166001600160a01b0383161790555b50565b6009546001600160a01b031633146111e3576040516355f748ad60e11b8152336004820152602401610798565b6111ee6002826128f5565b5f0361120d576040516316b0de1160e01b815260040160405180910390fd5b5f6112188585610d60565b60ff81165f908152600b60205260409020909150611237908484612386565b508060ff167fb2daad02730c1f4cf68114e39005dda85963d6d18955ed0eb0ae3ac610cabbf2848460405161126d929190612908565b60405180910390a25050505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526112f89186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611996565b50505050565b60605f600b5f61130e8688610d60565b60ff1660ff1681526020019081526020015f2080548060200260200160405190810160405280929190818152602001828054801561136957602002820191905f5260205f20905b815481526020019060010190808311611355575b5050505050905080515f0361139d5760405163e7715ea160e01b815285151560048201528415156024820152604401610798565b5f6002825160016113ae9190612958565b6113b8919061296b565b6113c3906001612958565b67ffffffffffffffff8111156113db576113db612721565b60405190808252806020026020018201604052801561140e57816020015b60608152602001906001900390816113f95790505b509050835f5b8351611421906001612958565b8110156116c2575f600a5f86848151811061143e5761143e61297e565b602002602001015181526020019081526020015f206040518060400160405290815f82015f9054906101000a900460ff1660ff1660ff16815260200160018201805461148990612735565b80601f01602080910402602001604051908101604052809291908181526020018280546114b590612735565b80156115005780601f106114d757610100808354040283529160200191611500565b820191905f5260205f20905b8154815290600101906020018083116114e357829003601f168201915b50505050508152505090506003815f015160ff1611156115335760405163150fb45360e31b815260040160405180910390fd5b5f61153f836001612958565b865114611578576115738887611556866001612958565b815181106115665761156661297e565b60200260200101516119f7565b61157a565b835b90505f825f015160ff165f036115d65789611596576009611599565b60085b90506115aa8a838560200151611aa9565b866115b660028761296b565b815181106115c6576115c661297e565b6020026020010181905250611647565b825160ff1660010361160157896115ee5760016115f0565b5f5b90506115aa8a838560200151611b02565b6010905061161f8b8b855f015160ff16600314858760200151611b43565b8661162b60028761296b565b8151811061163b5761163b61297e565b60200260200101819052505b6040805160f883901b7fff000000000000000000000000000000000000000000000000000000000000001660208201528151600181830301815260218201909252611696918a916041016129a9565b60408051601f1981840301815291905297506116b282866128ce565b9450600284019350505050611414565b5060408051600160fa1b602082015281516001818303018152602182019092526116f09186916041016129a9565b60408051601f198184030181528282525f60208401819052309284019290925260608301919091529450608001604051602081830303815290604052826001845161173b91906128ce565b8151811061174b5761174b61297e565b6020908102919091010152604051630d64d59360e21b815247906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690633593564c9083906117aa90899088904290600401612a17565b5f604051808303818588803b1580156117c1575f80fd5b505af11580156117d3573d5f803e3d5ffd5b50505050504790505f811115611854577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004015f604051808303818588803b15801561183c575f80fd5b505af115801561184e573d5f803e3d5ffd5b50505050505b5050505050505050565b6040516001600160a01b0383811660248301526044820183905261188f91859182169063a9059cbb906064016112b1565b505050565b806001600160a01b0316826001600160a01b0316036118b1575050565b6001600160a01b03821615611928576118f46001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016835f61209e565b6119286001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016835f61209e565b61195d6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016825f1961209e565b6119926001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016825f1961209e565b5050565b5f6119aa6001600160a01b03841683612142565b905080515f141580156119ce5750808060200190518101906119cc9190612a5c565b155b1561188f57604051635274afe760e01b81526001600160a01b0384166004820152602401610798565b5f80805f19848609848602925082811083820303915050805f03611a285750670de0b6b3a764000090049050610986565b670de0b6b3a76400008110611a5a57604051635173648d60e01b81526004810186905260248101859052604401610798565b5f670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60605f82806020019051810190611ac09190612af4565b9050308486611ad0575f19611ad2565b5f5b836001604051602001611ae9959493929190612b89565b6040516020818303038152906040529150509392505050565b6060308385611b12575f19611b14565b5f5b846001604051602001611b2b959493929190612c01565b60405160208183030381529060405290509392505050565b604080516003808252608082019092526060915f9190816020015b6060815260200190600190039081611b5e5790505090505f808615611c9a57606085806020019051810190611b939190612cd1565b909250905088611ba4576009611ba7565b60075b92506040518060800160405280611c0e8b15158d151514611be8577f000000000000000000000000000000000000000000000000000000000000000061214f565b7f000000000000000000000000000000000000000000000000000000000000000061214f565b6001600160a01b03168152602001828152602001611c2b89612194565b6001600160801b031681526020018a611c4b576001600160801b03611c4d565b5f5b6001600160801b03169052604051611c689190602001612e19565b604051602081830303815290604052845f81518110611c8957611c8961297e565b602002602001018190525050611d8c565b6040805160a0810182525f808252602082018190529181018290526060810182905260808101919091525f606087806020019051810190611cdb9190612f12565b929650909450925090508a611cf1576008611cf4565b60065b94506040518060a001604052808481526020018315158152602001611d188b612194565b6001600160801b031681526020018c611d38576001600160801b03611d3a565b5f5b6001600160801b0316815260200182815250604051602001611d5c9190612fe7565b604051602081830303815290604052865f81518110611d7d57611d7d61297e565b60200260200101819052505050505b8015611eeb5787611e75576040516370a0823160e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d9082906370a0823190602401602060405180830381865afa158015611e01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e25919061270a565b6040518263ffffffff1660e01b8152600401611e4391815260200190565b5f604051808303815f87803b158015611e5a575f80fd5b505af1158015611e6c573d5f803e3d5ffd5b50505050611eeb565b604051632e1a7d4d60e01b8152600481018790527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d906024015f604051808303815f87803b158015611ed4575f80fd5b505af1158015611ee6573d5f803e3d5ffd5b505050505b611f1989611be8577f000000000000000000000000000000000000000000000000000000000000000061214f565b88611f25575f19611f27565b865b604080516001600160a01b03909316602084015282015260600160405160208183030381529060405283600181518110611f6357611f6361297e565b6020026020010181905250611fc289611f9c577f000000000000000000000000000000000000000000000000000000000000000061214f565b7f000000000000000000000000000000000000000000000000000000000000000061214f565b88611fcd5786611fcf565b5f5b604080516001600160a01b0390931660208401528201526060016040516020818303038152906040528360028151811061200b5761200b61297e565b6020908102919091018101919091526040517fff0000000000000000000000000000000000000000000000000000000000000060f885901b1691810191909152600360fa1b6021820152600f60f81b602282015260230160408051601f1981840301815290829052612081918590602001613090565b604051602081830303815290604052935050505095945050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663095ea7b360e01b17905261210484826121c7565b6112f8576040516001600160a01b0384811660248301525f604483015261213891869182169063095ea7b3906064016112b1565b6112f88482611996565b6060610d8783835f612268565b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03160361219057505f919050565b5090565b5f6001600160801b03821115612190576040516306dfcc6560e41b81526080600482015260248101839052604401610798565b5f805f846001600160a01b0316846040516121e291906130b4565b5f604051808303815f865af19150503d805f811461221b576040519150601f19603f3d011682016040523d82523d5f602084013e612220565b606091505b509150915081801561224a57508051158061224a57508080602001905181019061224a9190612a5c565b801561225f57505f856001600160a01b03163b115b95945050505050565b60608147101561228d5760405163cd78605960e01b8152306004820152602401610798565b5f80856001600160a01b031684866040516122a891906130b4565b5f6040518083038185875af1925050503d805f81146122e2576040519150601f19603f3d011682016040523d82523d5f602084013e6122e7565b606091505b50915091506122f7868383612301565b9695505050505050565b606082612316576123118261235d565b610d87565b815115801561232d57506001600160a01b0384163b155b1561235657604051639996b31560e01b81526001600160a01b0385166004820152602401610798565b5080610d87565b80511561236d5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b828054828255905f5260205f209081019282156123bf579160200282015b828111156123bf5782358255916020019190600101906123a4565b506121909291505b80821115612190575f81556001016123c7565b60ff811681146111b3575f80fd5b5f602082840312156123f8575f80fd5b8151610d87816123da565b80151581146111b3575f80fd5b5f8060408385031215612421575f80fd5b823561242c81612403565b946020939093013593505050565b634e487b7160e01b5f52602160045260245ffd5b602081016005831061246e57634e487b7160e01b5f52602160045260245ffd5b91905290565b5f805f8060608587031215612487575f80fd5b843593506020850135612499816123da565b9250604085013567ffffffffffffffff8111156124b4575f80fd5b8501601f810187136124c4575f80fd5b803567ffffffffffffffff8111156124da575f80fd5b8760208284010111156124eb575f80fd5b949793965060200194505050565b6001600160a01b03811681146111b3575f80fd5b5f805f805f805f80610100898b031215612525575f80fd5b8835612530816124f9565b97506020890135612540816124f9565b96506040890135612550816124f9565b95506060890135612560816124f9565b94506080890135612570816124f9565b935060a0890135612580816124f9565b925060c0890135612590816124f9565b915060e08901356125a0816124f9565b809150509295985092959890939650565b5f602082840312156125c1575f80fd5b5035919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b60ff83168152604060208201525f61261160408301846125c8565b949350505050565b5f806040838503121561262a575f80fd5b823561263581612403565b9150602083013561264581612403565b809150509250929050565b5f60208284031215612660575f80fd5b8135610d87816124f9565b5f806040838503121561267c575f80fd5b823561242c816123da565b5f805f806060858703121561269a575f80fd5b84356126a581612403565b935060208501356126b581612403565b9250604085013567ffffffffffffffff8111156126d0575f80fd5b8501601f810187136126e0575f80fd5b803567ffffffffffffffff8111156126f6575f80fd5b8760208260051b84010111156124eb575f80fd5b5f6020828403121561271a575f80fd5b5051919050565b634e487b7160e01b5f52604160045260245ffd5b600181811c9082168061274957607f821691505b60208210810361276757634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561188f57805f5260205f20601f840160051c810160208510156127925750805b601f840160051c820191505b818110156127b1575f815560010161279e565b5050505050565b815167ffffffffffffffff8111156127d2576127d2612721565b6127e6816127e08454612735565b8461276d565b6020601f821160018114612818575f83156128015750848201515b5f19600385901b1c1916600184901b1784556127b1565b5f84815260208120601f198516915b828110156128475787850151825560209485019460019092019101612827565b508482101561286457868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b634e487b7160e01b5f52601160045260245ffd5b60ff8181168382160190811115610986576109866128a1565b81810381811115610986576109866128a1565b634e487b7160e01b5f52601260045260245ffd5b5f82612903576129036128e1565b500690565b602081528160208201525f7f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561293f575f80fd5b8260051b80856040850137919091016040019392505050565b80820180821115610986576109866128a1565b5f82612979576129796128e1565b500490565b634e487b7160e01b5f52603260045260245ffd5b5f81518060208401855e5f93019283525090919050565b5f6126116129b78386612992565b84612992565b5f82825180855260208501945060208160051b830101602085015f5b83811015612a0b57601f198584030188526129f58383516125c8565b60209889019890935091909101906001016129d9565b50909695505050505050565b606081525f612a2960608301866125c8565b8281036020840152612a3b81866129bd565b915050826040830152949350505050565b8051612a5781612403565b919050565b5f60208284031215612a6c575f80fd5b8151610d8781612403565b60405160a0810167ffffffffffffffff81118282101715612a9a57612a9a612721565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715612ac957612ac9612721565b604052919050565b5f67ffffffffffffffff821115612aea57612aea612721565b5060051b60200190565b5f60208284031215612b04575f80fd5b815167ffffffffffffffff811115612b1a575f80fd5b8201601f81018413612b2a575f80fd5b8051612b3d612b3882612ad1565b612aa0565b8082825260208201915060208360051b850101925086831115612b5e575f80fd5b6020840193505b828410156122f7578351612b78816124f9565b825260209384019390910190612b65565b5f60a082016001600160a01b038816835286602084015285604084015260a0606084015280855180835260c0850191506020870192505f5b81811015612be85783516001600160a01b0316835260209384019390920191600101612bc1565b5050809250505082151560808301529695505050505050565b6001600160a01b038616815284602082015283604082015260a060608201525f612c2e60a08301856125c8565b905082151560808301529695505050505050565b805162ffffff81168114612a57575f80fd5b8051600281900b8114612a57575f80fd5b5f82601f830112612c74575f80fd5b815167ffffffffffffffff811115612c8e57612c8e612721565b612ca1601f8201601f1916602001612aa0565b818152846020838601011115612cb5575f80fd5b8160208501602083015e5f918101602001919091529392505050565b5f8060408385031215612ce2575f80fd5b8251612ced81612403565b602084015190925067ffffffffffffffff811115612d09575f80fd5b8301601f81018513612d19575f80fd5b8051612d27612b3882612ad1565b8082825260208201915060208360051b850101925087831115612d48575f80fd5b602084015b83811015612e0a57805167ffffffffffffffff811115612d6b575f80fd5b850160a0818b03601f19011215612d80575f80fd5b612d88612a77565b6020820151612d96816124f9565b8152612da460408301612c42565b6020820152612db560608301612c54565b60408201526080820151612dc8816124f9565b606082015260a082015167ffffffffffffffff811115612de6575f80fd5b612df58c602083860101612c65565b60808301525084525060209283019201612d4d565b50809450505050509250929050565b602081525f60a082016001600160a01b03845116602084015260208401516080604085015281815180845260c08601915060c08160051b87010193506020830192505f5b81811015612edd5760bf1987860301835283516001600160a01b03815116865262ffffff6020820151166020870152604081015160020b60408701526001600160a01b0360608201511660608701526080810151905060a06080870152612ec760a08701826125c8565b9550506020938401939290920191600101612e5d565b5050505060408401516001600160801b03811660608501525060608401516001600160801b0381166080850152509392505050565b5f805f80848603610100811215612f27575f80fd5b8551612f3281612403565b945060a0601f1982011215612f45575f80fd5b50612f4e612a77565b6020860151612f5c816124f9565b81526040860151612f6c816124f9565b6020820152612f7d60608701612c42565b6040820152612f8e60808701612c54565b606082015260a0860151612fa1816124f9565b60808201529250612fb460c08601612a4c565b915060e085015167ffffffffffffffff811115612fcf575f80fd5b612fdb87828801612c65565b91505092959194509250565b602081525f82516001600160a01b0381511660208401526001600160a01b03602082015116604084015262ffffff6040820151166060840152606081015160020b60808401526001600160a01b0360808201511660a084015250602083015161305460c084018215159052565b5060408301516001600160801b0390811660e08401526060840151166101008301526080830151610120808401526126116101408401826125c8565b604081525f6130a260408301856125c8565b828103602084015261225f81856129bd565b5f610d87828461299256fea164736f6c634300081a000a000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad60000000000000000000000004200000000000000000000000000000000000006000000000000000000000000ef740bf23acae26f6492b10de645d6b98dc8eaf30000000000000000000000001f98400000000000000000000000000000000004000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000004200000000000000000000000000000000000006
Deployed Bytecode
0x6080604052600436106101a7575f3560e01c80638da5cb5b116100e7578063e3c50e6811610087578063f5272e6411610062578063f5272e6414610696578063f57ba117146106b5578063f887ea40146106d4578063fe47263114610707575f80fd5b8063e3c50e6814610625578063ec342ad014610644578063f2fde38b14610677575f80fd5b8063ac3a7f39116100c2578063ac3a7f3914610597578063b7aafcde146105c8578063b8f6eb8a146105e7578063ccf5a52414610606575f80fd5b80638da5cb5b1461051957806393243509146105375780639c57983914610564575f80fd5b8063491748341161015257806377bb1eb91161012d57806377bb1eb91461049d578063791b98bc146104bc5780637dc0d1d0146104db5780637f5a7c7b146104fa575f80fd5b8063491748341461042c5780634aa4a4fc1461044b5780634d6ee82f1461047e575f80fd5b80632f8637c8116101825780632f8637c8146103bb57806330811b29146103da578063481c6a75146103f9575f80fd5b806312261ee7146102fe578063144bf2fa1461034e5780632a942db71461037b575f80fd5b366102fa5760015f9054906101000a90046001600160a01b03166001600160a01b031663200d2ed26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101fc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061022091906123e8565b60ff166001036102435760405163ab35696f60e01b815260040160405180910390fd5b336001600160a01b037f000000000000000000000000420000000000000000000000000000000000000616148015906102a55750336001600160a01b037f0000000000000000000000001f984000000000000000000000000000000000041614155b80156102da5750336001600160a01b037f000000000000000000000000ef740bf23acae26f6492b10de645d6b98dc8eaf31614155b156102f85760405163040af20760e31b815260040160405180910390fd5b005b5f80fd5b348015610309575f80fd5b506103317f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba381565b6040516001600160a01b0390911681526020015b60405180910390f35b348015610359575f80fd5b5061036d610368366004612410565b610726565b604051908152602001610345565b348015610386575f80fd5b506103ae7f000000000000000000000000000000000000000000000000000000000000000481565b604051610345919061244e565b3480156103c6575f80fd5b506102f86103d5366004612474565b61098c565b3480156103e5575f80fd5b50600754610331906001600160a01b031681565b348015610404575f80fd5b506103317f0000000000000000000000001f9840000000000000000000000000000000000481565b348015610437575f80fd5b50600354610331906001600160a01b031681565b348015610456575f80fd5b506103317f000000000000000000000000420000000000000000000000000000000000000681565b348015610489575f80fd5b506102f861049836600461250d565b610a81565b3480156104a8575f80fd5b50600854610331906001600160a01b031681565b3480156104c7575f80fd5b50600554610331906001600160a01b031681565b3480156104e6575f80fd5b50600654610331906001600160a01b031681565b348015610505575f80fd5b50600254610331906001600160a01b031681565b348015610524575f80fd5b505f54610331906001600160a01b031681565b348015610542575f80fd5b506105566105513660046125b1565b610cba565b6040516103459291906125f6565b34801561056f575f80fd5b506103317f000000000000000000000000420000000000000000000000000000000000000681565b3480156105a2575f80fd5b506105b66105b1366004612619565b610d60565b60405160ff9091168152602001610345565b3480156105d3575f80fd5b506102f86105e2366004612650565b610d8e565b3480156105f2575f80fd5b50600154610331906001600160a01b031681565b348015610611575f80fd5b5061036d610620366004612410565b610e03565b348015610630575f80fd5b5061036d61063f36600461266b565b6110f5565b34801561064f575f80fd5b506103317f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad681565b348015610682575f80fd5b506102f8610691366004612650565b611120565b3480156106a1575f80fd5b506102f86106b0366004612687565b6111b6565b3480156106c0575f80fd5b50600954610331906001600160a01b031681565b3480156106df575f80fd5b506103317f000000000000000000000000ef740bf23acae26f6492b10de645d6b98dc8eaf381565b348015610712575f80fd5b50600454610331906001600160a01b031681565b6001545f906001600160a01b0316331480159061074e57506002546001600160a01b03163314155b801561076557506007546001600160a01b03163314155b801561077c57506005546001600160a01b03163314155b156107a15760405163cb11855160e01b81523360048201526024015b60405180910390fd5b60015f9054906101000a90046001600160a01b03166001600160a01b031663200d2ed26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107f1573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061081591906123e8565b60ff166001036108385760405163ab35696f60e01b815260040160405180910390fd5b815f0361084657505f610986565b5f83610872577f0000000000000000000000004200000000000000000000000000000000000006610894565b7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad65b90505f846108c2577f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad66108e4565b7f00000000000000000000000042000000000000000000000000000000000000065b90506108fb6001600160a01b03831633308761127c565b610907856001866112fe565b6040516370a0823160e01b81523060048201526001600160a01b038216906370a0823190602401602060405180830381865afa158015610949573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061096d919061270a565b92506109836001600160a01b038216338561185e565b50505b92915050565b6009546001600160a01b031633146109b9576040516355f748ad60e11b8152336004820152602401610798565b60405180604001604052808460ff16815260200183838080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920182905250939094525050868152600a602090815260409091208351815460ff191660ff909116178155908301519091506001820190610a3990826127b8565b509050508260ff16847ff2191fc55efd701281b72273e11a86b3b00b78cfcd9dd1d76544c2352da055358484604051610a73929190612873565b60405180910390a350505050565b5f546001600160a01b03163314610aad5760405163118cdaa760e01b8152336004820152602401610798565b600180546001600160a01b03808b166001600160a01b031992831617909255600280548a841690831617905560068054868416908316179055600780549285169290911691909117905560037f00000000000000000000000000000000000000000000000000000000000000046004811115610b2b57610b2b61243a565b03610b4b57600354610b46906001600160a01b031687611894565b610c67565b60017f00000000000000000000000000000000000000000000000000000000000000046004811115610b7f57610b7f61243a565b03610bb057600354610b9a906001600160a01b031687611894565b600554610b46906001600160a01b031685611894565b5f7f00000000000000000000000000000000000000000000000000000000000000046004811115610be357610be361243a565b1480610c20575060027f00000000000000000000000000000000000000000000000000000000000000046004811115610c1e57610c1e61243a565b145b15610c6757600354610c3b906001600160a01b031687611894565b600454610c51906001600160a01b031686611894565b600854610c67906001600160a01b031682611894565b600380546001600160a01b039788166001600160a01b0319918216179091556004805496881696821696909617909555600880549187169186169190911790555050600580549190931691161790555050565b600a6020525f90815260409020805460018201805460ff9092169291610cdf90612735565b80601f0160208091040260200160405190810160405280929190818152602001828054610d0b90612735565b8015610d565780601f10610d2d57610100808354040283529160200191610d56565b820191905f5260205f20905b815481529060010190602001808311610d3957829003601f168201915b5050505050905082565b5f81610d6c575f610d6f565b60015b83610d7a575f610d7d565b60025b610d8791906128b5565b9392505050565b5f546001600160a01b03163314610dba5760405163118cdaa760e01b8152336004820152602401610798565b600980546001600160a01b0319166001600160a01b0383169081179091556040517f56d07dc61bef1fbbbc5d202bd5ee4f5a995de4be8a081b67ca1f8b89d2137fa8905f90a250565b6001545f906001600160a01b03163314801590610e2b57506002546001600160a01b03163314155b8015610e4257506007546001600160a01b03163314155b8015610e5957506005546001600160a01b03163314155b15610e795760405163cb11855160e01b8152336004820152602401610798565b60015f9054906101000a90046001600160a01b03166001600160a01b031663200d2ed26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ec9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eed91906123e8565b60ff16600103610f105760405163ab35696f60e01b815260040160405180910390fd5b815f03610f1e57505f610986565b5f83610f4a577f0000000000000000000000004200000000000000000000000000000000000006610f6c565b7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad65b90505f84610f9a577f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad6610fbc565b7f00000000000000000000000042000000000000000000000000000000000000065b6040516370a0823160e01b81523360048201529091506001600160a01b038316906370a0823190602401602060405180830381865afa158015611001573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611025919061270a565b925061103c6001600160a01b03831633308661127c565b611047855f866112fe565b61105b6001600160a01b038216338661185e565b6040516370a0823160e01b81523060048201525f906001600160a01b038416906370a0823190602401602060405180830381865afa15801561109f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110c3919061270a565b905080156110ec576110df6001600160a01b038416338361185e565b6110e981856128ce565b93505b50505092915050565b600b602052815f5260405f20818154811061110e575f80fd5b905f5260205f20015f91509150505481565b5f546001600160a01b0316331461114c5760405163118cdaa760e01b8152336004820152602401610798565b5f546001600160a01b038281169116146111b3575f80546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a35f80546001600160a01b0319166001600160a01b0383161790555b50565b6009546001600160a01b031633146111e3576040516355f748ad60e11b8152336004820152602401610798565b6111ee6002826128f5565b5f0361120d576040516316b0de1160e01b815260040160405180910390fd5b5f6112188585610d60565b60ff81165f908152600b60205260409020909150611237908484612386565b508060ff167fb2daad02730c1f4cf68114e39005dda85963d6d18955ed0eb0ae3ac610cabbf2848460405161126d929190612908565b60405180910390a25050505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526112f89186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611996565b50505050565b60605f600b5f61130e8688610d60565b60ff1660ff1681526020019081526020015f2080548060200260200160405190810160405280929190818152602001828054801561136957602002820191905f5260205f20905b815481526020019060010190808311611355575b5050505050905080515f0361139d5760405163e7715ea160e01b815285151560048201528415156024820152604401610798565b5f6002825160016113ae9190612958565b6113b8919061296b565b6113c3906001612958565b67ffffffffffffffff8111156113db576113db612721565b60405190808252806020026020018201604052801561140e57816020015b60608152602001906001900390816113f95790505b509050835f5b8351611421906001612958565b8110156116c2575f600a5f86848151811061143e5761143e61297e565b602002602001015181526020019081526020015f206040518060400160405290815f82015f9054906101000a900460ff1660ff1660ff16815260200160018201805461148990612735565b80601f01602080910402602001604051908101604052809291908181526020018280546114b590612735565b80156115005780601f106114d757610100808354040283529160200191611500565b820191905f5260205f20905b8154815290600101906020018083116114e357829003601f168201915b50505050508152505090506003815f015160ff1611156115335760405163150fb45360e31b815260040160405180910390fd5b5f61153f836001612958565b865114611578576115738887611556866001612958565b815181106115665761156661297e565b60200260200101516119f7565b61157a565b835b90505f825f015160ff165f036115d65789611596576009611599565b60085b90506115aa8a838560200151611aa9565b866115b660028761296b565b815181106115c6576115c661297e565b6020026020010181905250611647565b825160ff1660010361160157896115ee5760016115f0565b5f5b90506115aa8a838560200151611b02565b6010905061161f8b8b855f015160ff16600314858760200151611b43565b8661162b60028761296b565b8151811061163b5761163b61297e565b60200260200101819052505b6040805160f883901b7fff000000000000000000000000000000000000000000000000000000000000001660208201528151600181830301815260218201909252611696918a916041016129a9565b60408051601f1981840301815291905297506116b282866128ce565b9450600284019350505050611414565b5060408051600160fa1b602082015281516001818303018152602182019092526116f09186916041016129a9565b60408051601f198184030181528282525f60208401819052309284019290925260608301919091529450608001604051602081830303815290604052826001845161173b91906128ce565b8151811061174b5761174b61297e565b6020908102919091010152604051630d64d59360e21b815247906001600160a01b037f000000000000000000000000ef740bf23acae26f6492b10de645d6b98dc8eaf31690633593564c9083906117aa90899088904290600401612a17565b5f604051808303818588803b1580156117c1575f80fd5b505af11580156117d3573d5f803e3d5ffd5b50505050504790505f811115611854577f00000000000000000000000042000000000000000000000000000000000000066001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004015f604051808303818588803b15801561183c575f80fd5b505af115801561184e573d5f803e3d5ffd5b50505050505b5050505050505050565b6040516001600160a01b0383811660248301526044820183905261188f91859182169063a9059cbb906064016112b1565b505050565b806001600160a01b0316826001600160a01b0316036118b1575050565b6001600160a01b03821615611928576118f46001600160a01b037f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad616835f61209e565b6119286001600160a01b037f000000000000000000000000420000000000000000000000000000000000000616835f61209e565b61195d6001600160a01b037f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad616825f1961209e565b6119926001600160a01b037f000000000000000000000000420000000000000000000000000000000000000616825f1961209e565b5050565b5f6119aa6001600160a01b03841683612142565b905080515f141580156119ce5750808060200190518101906119cc9190612a5c565b155b1561188f57604051635274afe760e01b81526001600160a01b0384166004820152602401610798565b5f80805f19848609848602925082811083820303915050805f03611a285750670de0b6b3a764000090049050610986565b670de0b6b3a76400008110611a5a57604051635173648d60e01b81526004810186905260248101859052604401610798565b5f670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60605f82806020019051810190611ac09190612af4565b9050308486611ad0575f19611ad2565b5f5b836001604051602001611ae9959493929190612b89565b6040516020818303038152906040529150509392505050565b6060308385611b12575f19611b14565b5f5b846001604051602001611b2b959493929190612c01565b60405160208183030381529060405290509392505050565b604080516003808252608082019092526060915f9190816020015b6060815260200190600190039081611b5e5790505090505f808615611c9a57606085806020019051810190611b939190612cd1565b909250905088611ba4576009611ba7565b60075b92506040518060800160405280611c0e8b15158d151514611be8577f000000000000000000000000420000000000000000000000000000000000000661214f565b7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad661214f565b6001600160a01b03168152602001828152602001611c2b89612194565b6001600160801b031681526020018a611c4b576001600160801b03611c4d565b5f5b6001600160801b03169052604051611c689190602001612e19565b604051602081830303815290604052845f81518110611c8957611c8961297e565b602002602001018190525050611d8c565b6040805160a0810182525f808252602082018190529181018290526060810182905260808101919091525f606087806020019051810190611cdb9190612f12565b929650909450925090508a611cf1576008611cf4565b60065b94506040518060a001604052808481526020018315158152602001611d188b612194565b6001600160801b031681526020018c611d38576001600160801b03611d3a565b5f5b6001600160801b0316815260200182815250604051602001611d5c9190612fe7565b604051602081830303815290604052865f81518110611d7d57611d7d61297e565b60200260200101819052505050505b8015611eeb5787611e75576040516370a0823160e01b81523060048201527f00000000000000000000000042000000000000000000000000000000000000066001600160a01b031690632e1a7d4d9082906370a0823190602401602060405180830381865afa158015611e01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e25919061270a565b6040518263ffffffff1660e01b8152600401611e4391815260200190565b5f604051808303815f87803b158015611e5a575f80fd5b505af1158015611e6c573d5f803e3d5ffd5b50505050611eeb565b604051632e1a7d4d60e01b8152600481018790527f00000000000000000000000042000000000000000000000000000000000000066001600160a01b031690632e1a7d4d906024015f604051808303815f87803b158015611ed4575f80fd5b505af1158015611ee6573d5f803e3d5ffd5b505050505b611f1989611be8577f000000000000000000000000420000000000000000000000000000000000000661214f565b88611f25575f19611f27565b865b604080516001600160a01b03909316602084015282015260600160405160208183030381529060405283600181518110611f6357611f6361297e565b6020026020010181905250611fc289611f9c577f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad661214f565b7f000000000000000000000000420000000000000000000000000000000000000661214f565b88611fcd5786611fcf565b5f5b604080516001600160a01b0390931660208401528201526060016040516020818303038152906040528360028151811061200b5761200b61297e565b6020908102919091018101919091526040517fff0000000000000000000000000000000000000000000000000000000000000060f885901b1691810191909152600360fa1b6021820152600f60f81b602282015260230160408051601f1981840301815290829052612081918590602001613090565b604051602081830303815290604052935050505095945050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663095ea7b360e01b17905261210484826121c7565b6112f8576040516001600160a01b0384811660248301525f604483015261213891869182169063095ea7b3906064016112b1565b6112f88482611996565b6060610d8783835f612268565b5f7f00000000000000000000000042000000000000000000000000000000000000066001600160a01b0316826001600160a01b03160361219057505f919050565b5090565b5f6001600160801b03821115612190576040516306dfcc6560e41b81526080600482015260248101839052604401610798565b5f805f846001600160a01b0316846040516121e291906130b4565b5f604051808303815f865af19150503d805f811461221b576040519150601f19603f3d011682016040523d82523d5f602084013e612220565b606091505b509150915081801561224a57508051158061224a57508080602001905181019061224a9190612a5c565b801561225f57505f856001600160a01b03163b115b95945050505050565b60608147101561228d5760405163cd78605960e01b8152306004820152602401610798565b5f80856001600160a01b031684866040516122a891906130b4565b5f6040518083038185875af1925050503d805f81146122e2576040519150601f19603f3d011682016040523d82523d5f602084013e6122e7565b606091505b50915091506122f7868383612301565b9695505050505050565b606082612316576123118261235d565b610d87565b815115801561232d57506001600160a01b0384163b155b1561235657604051639996b31560e01b81526001600160a01b0385166004820152602401610798565b5080610d87565b80511561236d5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b828054828255905f5260205f209081019282156123bf579160200282015b828111156123bf5782358255916020019190600101906123a4565b506121909291505b80821115612190575f81556001016123c7565b60ff811681146111b3575f80fd5b5f602082840312156123f8575f80fd5b8151610d87816123da565b80151581146111b3575f80fd5b5f8060408385031215612421575f80fd5b823561242c81612403565b946020939093013593505050565b634e487b7160e01b5f52602160045260245ffd5b602081016005831061246e57634e487b7160e01b5f52602160045260245ffd5b91905290565b5f805f8060608587031215612487575f80fd5b843593506020850135612499816123da565b9250604085013567ffffffffffffffff8111156124b4575f80fd5b8501601f810187136124c4575f80fd5b803567ffffffffffffffff8111156124da575f80fd5b8760208284010111156124eb575f80fd5b949793965060200194505050565b6001600160a01b03811681146111b3575f80fd5b5f805f805f805f80610100898b031215612525575f80fd5b8835612530816124f9565b97506020890135612540816124f9565b96506040890135612550816124f9565b95506060890135612560816124f9565b94506080890135612570816124f9565b935060a0890135612580816124f9565b925060c0890135612590816124f9565b915060e08901356125a0816124f9565b809150509295985092959890939650565b5f602082840312156125c1575f80fd5b5035919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b60ff83168152604060208201525f61261160408301846125c8565b949350505050565b5f806040838503121561262a575f80fd5b823561263581612403565b9150602083013561264581612403565b809150509250929050565b5f60208284031215612660575f80fd5b8135610d87816124f9565b5f806040838503121561267c575f80fd5b823561242c816123da565b5f805f806060858703121561269a575f80fd5b84356126a581612403565b935060208501356126b581612403565b9250604085013567ffffffffffffffff8111156126d0575f80fd5b8501601f810187136126e0575f80fd5b803567ffffffffffffffff8111156126f6575f80fd5b8760208260051b84010111156124eb575f80fd5b5f6020828403121561271a575f80fd5b5051919050565b634e487b7160e01b5f52604160045260245ffd5b600181811c9082168061274957607f821691505b60208210810361276757634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561188f57805f5260205f20601f840160051c810160208510156127925750805b601f840160051c820191505b818110156127b1575f815560010161279e565b5050505050565b815167ffffffffffffffff8111156127d2576127d2612721565b6127e6816127e08454612735565b8461276d565b6020601f821160018114612818575f83156128015750848201515b5f19600385901b1c1916600184901b1784556127b1565b5f84815260208120601f198516915b828110156128475787850151825560209485019460019092019101612827565b508482101561286457868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b634e487b7160e01b5f52601160045260245ffd5b60ff8181168382160190811115610986576109866128a1565b81810381811115610986576109866128a1565b634e487b7160e01b5f52601260045260245ffd5b5f82612903576129036128e1565b500690565b602081528160208201525f7f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561293f575f80fd5b8260051b80856040850137919091016040019392505050565b80820180821115610986576109866128a1565b5f82612979576129796128e1565b500490565b634e487b7160e01b5f52603260045260245ffd5b5f81518060208401855e5f93019283525090919050565b5f6126116129b78386612992565b84612992565b5f82825180855260208501945060208160051b830101602085015f5b83811015612a0b57601f198584030188526129f58383516125c8565b60209889019890935091909101906001016129d9565b50909695505050505050565b606081525f612a2960608301866125c8565b8281036020840152612a3b81866129bd565b915050826040830152949350505050565b8051612a5781612403565b919050565b5f60208284031215612a6c575f80fd5b8151610d8781612403565b60405160a0810167ffffffffffffffff81118282101715612a9a57612a9a612721565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715612ac957612ac9612721565b604052919050565b5f67ffffffffffffffff821115612aea57612aea612721565b5060051b60200190565b5f60208284031215612b04575f80fd5b815167ffffffffffffffff811115612b1a575f80fd5b8201601f81018413612b2a575f80fd5b8051612b3d612b3882612ad1565b612aa0565b8082825260208201915060208360051b850101925086831115612b5e575f80fd5b6020840193505b828410156122f7578351612b78816124f9565b825260209384019390910190612b65565b5f60a082016001600160a01b038816835286602084015285604084015260a0606084015280855180835260c0850191506020870192505f5b81811015612be85783516001600160a01b0316835260209384019390920191600101612bc1565b5050809250505082151560808301529695505050505050565b6001600160a01b038616815284602082015283604082015260a060608201525f612c2e60a08301856125c8565b905082151560808301529695505050505050565b805162ffffff81168114612a57575f80fd5b8051600281900b8114612a57575f80fd5b5f82601f830112612c74575f80fd5b815167ffffffffffffffff811115612c8e57612c8e612721565b612ca1601f8201601f1916602001612aa0565b818152846020838601011115612cb5575f80fd5b8160208501602083015e5f918101602001919091529392505050565b5f8060408385031215612ce2575f80fd5b8251612ced81612403565b602084015190925067ffffffffffffffff811115612d09575f80fd5b8301601f81018513612d19575f80fd5b8051612d27612b3882612ad1565b8082825260208201915060208360051b850101925087831115612d48575f80fd5b602084015b83811015612e0a57805167ffffffffffffffff811115612d6b575f80fd5b850160a0818b03601f19011215612d80575f80fd5b612d88612a77565b6020820151612d96816124f9565b8152612da460408301612c42565b6020820152612db560608301612c54565b60408201526080820151612dc8816124f9565b606082015260a082015167ffffffffffffffff811115612de6575f80fd5b612df58c602083860101612c65565b60808301525084525060209283019201612d4d565b50809450505050509250929050565b602081525f60a082016001600160a01b03845116602084015260208401516080604085015281815180845260c08601915060c08160051b87010193506020830192505f5b81811015612edd5760bf1987860301835283516001600160a01b03815116865262ffffff6020820151166020870152604081015160020b60408701526001600160a01b0360608201511660608701526080810151905060a06080870152612ec760a08701826125c8565b9550506020938401939290920191600101612e5d565b5050505060408401516001600160801b03811660608501525060608401516001600160801b0381166080850152509392505050565b5f805f80848603610100811215612f27575f80fd5b8551612f3281612403565b945060a0601f1982011215612f45575f80fd5b50612f4e612a77565b6020860151612f5c816124f9565b81526040860151612f6c816124f9565b6020820152612f7d60608701612c42565b6040820152612f8e60808701612c54565b606082015260a0860151612fa1816124f9565b60808201529250612fb460c08601612a4c565b915060e085015167ffffffffffffffff811115612fcf575f80fd5b612fdb87828801612c65565b91505092959194509250565b602081525f82516001600160a01b0381511660208401526001600160a01b03602082015116604084015262ffffff6040820151166060840152606081015160020b60808401526001600160a01b0360808201511660a084015250602083015161305460c084018215159052565b5060408301516001600160801b0390811660e08401526060840151166101008301526080830151610120808401526126116101408401826125c8565b604081525f6130a260408301856125c8565b828103602084015261225f81856129bd565b5f610d87828461299256fea164736f6c634300081a000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad60000000000000000000000004200000000000000000000000000000000000006000000000000000000000000ef740bf23acae26f6492b10de645d6b98dc8eaf30000000000000000000000001f98400000000000000000000000000000000004000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000004200000000000000000000000000000000000006
-----Decoded View---------------
Arg [0] : _base (address): 0x078D782b760474a361dDA0AF3839290b0EF57AD6
Arg [1] : _quote (address): 0x4200000000000000000000000000000000000006
Arg [2] : _router (address): 0xEf740bf23aCaE26f6492B10de645D6B98dC8Eaf3
Arg [3] : _manager (address): 0x1F98400000000000000000000000000000000004
Arg [4] : _permit2 (address): 0x000000000022D473030F116dDEE9F6B43aC78BA3
Arg [5] : _WETH9 (address): 0x4200000000000000000000000000000000000006
-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad6
Arg [1] : 0000000000000000000000004200000000000000000000000000000000000006
Arg [2] : 000000000000000000000000ef740bf23acae26f6492b10de645d6b98dc8eaf3
Arg [3] : 0000000000000000000000001f98400000000000000000000000000000000004
Arg [4] : 000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3
Arg [5] : 0000000000000000000000004200000000000000000000000000000000000006
Net Worth in USD
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.