HYPE Price: $37.16 (-3.72%)

Contract

0x5Abe35DDb420703bA6Dd7226ACDCb24be71192e5

Overview

HYPE Balance

HyperEvm LogoHyperEvm LogoHyperEvm Logo0 HYPE

HYPE Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Swap67301572025-06-25 15:37:2912 days ago1750865849IN
0x5Abe35DD...be71192e5
5 HYPE0.000283571.26
Swap67293522025-06-25 15:24:1712 days ago1750865057IN
0x5Abe35DD...be71192e5
0.07528034 HYPE0.000024760.11
Swap67283032025-06-25 15:07:0512 days ago1750864025IN
0x5Abe35DD...be71192e5
3 HYPE0.000066060.29352359
Swap67054932025-06-25 8:53:0912 days ago1750841589IN
0x5Abe35DD...be71192e5
0.5 HYPE0.000024750.11
Swap66979422025-06-25 6:49:2212 days ago1750834162IN
0x5Abe35DD...be71192e5
7 HYPE0.00002250.1
Swap66964022025-06-25 6:24:0712 days ago1750832647IN
0x5Abe35DD...be71192e5
6 HYPE0.00002250.1
Swap66963592025-06-25 6:23:2512 days ago1750832605IN
0x5Abe35DD...be71192e5
6 HYPE0.00002250.1
Swap66963132025-06-25 6:22:4012 days ago1750832560IN
0x5Abe35DD...be71192e5
6 HYPE0.00002250.1
Swap66962592025-06-25 6:21:4712 days ago1750832507IN
0x5Abe35DD...be71192e5
6 HYPE0.00002250.1
Swap66813312025-06-25 2:17:0313 days ago1750817823IN
0x5Abe35DD...be71192e5
0.03 HYPE0.00016020.67
Swap66763032025-06-25 0:54:3813 days ago1750812878IN
0x5Abe35DD...be71192e5
0.19699 HYPE0.000760833.38
Swap66611942025-06-24 20:46:5713 days ago1750798017IN
0x5Abe35DD...be71192e5
2.49087404 HYPE0.00005740.24
Swap66545732025-06-24 18:58:2413 days ago1750791504IN
0x5Abe35DD...be71192e5
1 HYPE0.000434361.93
Swap66441002025-06-24 16:06:4313 days ago1750781203IN
0x5Abe35DD...be71192e5
0.1 HYPE0.00053572.38
Swap66430992025-06-24 15:50:1813 days ago1750780218IN
0x5Abe35DD...be71192e5
1 HYPE0.000024750.11
Swap66430132025-06-24 15:48:5413 days ago1750780134IN
0x5Abe35DD...be71192e5
0.102305 HYPE0.000023910.1
Swap66369832025-06-24 14:10:0213 days ago1750774202IN
0x5Abe35DD...be71192e5
75 HYPE0.000027010.12
Swap66138122025-06-24 7:50:1113 days ago1750751411IN
0x5Abe35DD...be71192e5
2 HYPE0.000029070.13
Swap66026652025-06-24 4:47:2713 days ago1750740447IN
0x5Abe35DD...be71192e5
6 HYPE0.00002250.1
Swap65913692025-06-24 1:42:1614 days ago1750729336IN
0x5Abe35DD...be71192e5
4.1090325 HYPE0.000047270.21
Swap65728922025-06-23 20:39:2214 days ago1750711162IN
0x5Abe35DD...be71192e5
0.356755 HYPE0.000028690.12
Swap65727862025-06-23 20:37:3814 days ago1750711058IN
0x5Abe35DD...be71192e5
0.1 HYPE0.000049510.22
Swap65637252025-06-23 18:09:0514 days ago1750702145IN
0x5Abe35DD...be71192e5
0.01 HYPE0.000715843.18084459
Swap65628592025-06-23 17:54:5414 days ago1750701294IN
0x5Abe35DD...be71192e5
39.85 HYPE0.000036010.16
Swap65458782025-06-23 13:16:3114 days ago1750684591IN
0x5Abe35DD...be71192e5
0.05 HYPE0.000064550.27
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
67955152025-06-26 9:28:5711 days ago1750930137
0x5Abe35DD...be71192e5
0.49985008 HYPE
67955152025-06-26 9:28:5711 days ago1750930137
0x5Abe35DD...be71192e5
0.49985008 HYPE
67361672025-06-25 17:16:0012 days ago1750871760
0x5Abe35DD...be71192e5
0.90583797 HYPE
67361672025-06-25 17:16:0012 days ago1750871760
0x5Abe35DD...be71192e5
0.90583797 HYPE
67302282025-06-25 15:38:3912 days ago1750865919
0x5Abe35DD...be71192e5
6.50079037 HYPE
67302282025-06-25 15:38:3912 days ago1750865919
0x5Abe35DD...be71192e5
6.50079037 HYPE
67301572025-06-25 15:37:2912 days ago1750865849
0x5Abe35DD...be71192e5
5 HYPE
67294302025-06-25 15:25:3412 days ago1750865134
0x5Abe35DD...be71192e5
0.07525777 HYPE
67294302025-06-25 15:25:3412 days ago1750865134
0x5Abe35DD...be71192e5
0.07525777 HYPE
67293522025-06-25 15:24:1712 days ago1750865057
0x5Abe35DD...be71192e5
0.07528034 HYPE
67283302025-06-25 15:07:3212 days ago1750864052
0x5Abe35DD...be71192e5
2.99910032 HYPE
67283302025-06-25 15:07:3212 days ago1750864052
0x5Abe35DD...be71192e5
2.99910032 HYPE
67283032025-06-25 15:07:0512 days ago1750864025
0x5Abe35DD...be71192e5
3 HYPE
67174562025-06-25 12:09:1612 days ago1750853356
0x5Abe35DD...be71192e5
3.99995758 HYPE
67174562025-06-25 12:09:1612 days ago1750853356
0x5Abe35DD...be71192e5
3.99995758 HYPE
67100022025-06-25 10:07:0412 days ago1750846024
0x5Abe35DD...be71192e5
0.99995001 HYPE
67100022025-06-25 10:07:0412 days ago1750846024
0x5Abe35DD...be71192e5
0.99995001 HYPE
67054932025-06-25 8:53:0912 days ago1750841589
0x5Abe35DD...be71192e5
0.5 HYPE
66979872025-06-25 6:50:0612 days ago1750834206
0x5Abe35DD...be71192e5
6.99790062 HYPE
66979872025-06-25 6:50:0612 days ago1750834206
0x5Abe35DD...be71192e5
6.99790062 HYPE
66979422025-06-25 6:49:2212 days ago1750834162
0x5Abe35DD...be71192e5
7 HYPE
66964292025-06-25 6:24:3412 days ago1750832674
0x5Abe35DD...be71192e5
5.99820063 HYPE
66964292025-06-25 6:24:3412 days ago1750832674
0x5Abe35DD...be71192e5
5.99820063 HYPE
66964022025-06-25 6:24:0712 days ago1750832647
0x5Abe35DD...be71192e5
6 HYPE
66963852025-06-25 6:23:5112 days ago1750832631
0x5Abe35DD...be71192e5
5.99820064 HYPE
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ValantisSwapRouter

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 20000 runs

Other Settings:
paris EvmVersion
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import { SafeCast } from '@valantis-core/lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol';
import { IERC20 } from '@valantis-core/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol';
import { SafeERC20 } from '@valantis-core/lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol';
import { IUniversalPool } from '@valantis-core/src/pools/interfaces/IUniversalPool.sol';
import { ISovereignPool } from '@valantis-core/src/pools/interfaces/ISovereignPool.sol';
import {
    SovereignPoolSwapContextData,
    SovereignPoolSwapParams
} from '@valantis-core/src/pools/structs/SovereignPoolStructs.sol';
import { SwapParams } from '@valantis-core/src/pools/structs/UniversalPoolStructs.sol';
import { ReentrancyGuard } from '@valantis-core/src/utils/ReentrancyGuard.sol';

import { EIP712 } from './EIP712.sol';
import { SignatureVerification } from './libraries/SignatureVerification.sol';
import { IWETH9 } from './interfaces/IWETH9.sol';
import { IProtocolFactory } from '../../lib/valantis-core/src/protocol-factory/interfaces/IProtocolFactory.sol';
import { IAllowanceTransfer } from './interfaces/IAllowanceTransfer.sol';
import { IValantisSwapRouter } from './interfaces/IValantisSwapRouter.sol';
import { GaslessSwapIntentHash } from './libraries/GaslessSwapIntentHash.sol';
import { GaslessSwap } from './libraries/GaslessSwap.sol';
import { DirectSwap } from './libraries/DirectSwap.sol';
import { NonceBitmap } from './libraries/NonceBitmap.sol';
import {
    GaslessSwapParams,
    GaslessSwapIntent,
    DirectSwapParams,
    ExecuteSwapParams,
    UniversalPoolSwapPayload,
    SovereignPoolSwapPayload
} from './structs/ValantisSwapRouterStructs.sol';

contract ValantisSwapRouter is IValantisSwapRouter, EIP712, ReentrancyGuard {
    using GaslessSwapIntentHash for GaslessSwapIntent;
    using GaslessSwap for GaslessSwapParams;
    using DirectSwap for DirectSwapParams;
    using NonceBitmap for mapping(uint256 => uint256);
    using SafeCast for uint256;
    using SafeERC20 for IERC20;
    using SignatureVerification for bytes;

    /**
     *
     *  CUSTOM ERRORS
     *
     */
    error ValantisSwapRouter__batchGaslessSwaps_invalidArrayLengths();
    error ValantisSwapRouter__receive_onlyWeth();
    error ValantisSwapRouter__sovereignPoolSwapCallback_invalidTokenIn();
    error ValantisSwapRouter__sovereignPoolSwapCallback_poolNotAllowed();
    error ValantisSwapRouter__swap_invalidNativeTokenSwap();
    error ValantisSwapRouter__swap_insufficientAmountOut();
    error ValantisSwapRouter__swap_tokenOutNotWeth();
    error ValantisSwapRouter__sweep_invalidRecipient();
    error ValantisSwapRouter__sweep_invalidTokenAddress();
    error ValantisSwapRouter__sweep_invalidTokensArrayLength();
    error ValantisSwapRouter__universalPoolSwapCallback_invalidTokenIn();
    error ValantisSwapRouter__universalPoolSwapCallback_poolNotAllowed();
    error ValantisSwapRouter___executeSwaps_invalidAmountSpecifiedFirstSwap();
    error ValantisSwapRouter___executeSingleSwapSovereignPool_invalidSovereignPool();
    error ValantisSwapRouter___executeSingleSwapUniversalPool_invalidUniversalPool();
    error ValantisSwapRouter___executeGaslessSwap_excessiveFee();
    error ValantisSwapRouter___gaslessSwap_insufficientAmountOut();
    error ValantisSwapRouter___gaslessSwap_tokenOutNotWeth();
    error ValantisSwapRouter___sendNativeToken_ethTransferFailed();

    /**
     *
     *  IMMUTABLES
     *
     */

    /**
     * @notice Address of wrapped Native token.
     */
    // solhint-disable-next-line var-name-mixedcase
    address public immutable WETH9;

    /**
     * @notice Permit2 deployment.
     */
    IAllowanceTransfer private immutable _permit2;

    /**
     * @notice Valantis Protocol Factory.
     */
    IProtocolFactory private immutable _protocolFactory;

    /**
     *
     *  STORAGE
     *
     */

    /**
     * @notice Nonce bitmap for each signer and word.
     */
    mapping(address => mapping(uint256 => uint256)) public nonceBitmap;

    /**
     * @notice For each swap, only one Universal Pool is allowed to call `universalPoolSwapCallback`.
     */
    address public allowedUniversalPool;

    /**
     * @notice For each swap, only one Sovereign Pool is allowed to call `sovereignPoolSwapCallback`.
     */
    address public allowedSovereignPool;

    /**
     *
     *  CONSTRUCTOR
     *
     */
    constructor(address protocolFactory_, address _weth9, address permit2_) {
        _protocolFactory = IProtocolFactory(protocolFactory_);
        WETH9 = _weth9;
        _permit2 = IAllowanceTransfer(permit2_);

        allowedUniversalPool = address(1);
        allowedSovereignPool = address(1);
    }

    /**
     *
     *  VIEW FUNCTIONS
     *
     */

    /**
     * @notice Address of Permit2 deployment.
     */
    function permit2() external view override returns (address) {
        return address(_permit2);
    }

    /**
     * @notice Address of Valantis Protocol Factory.
     */
    function protocolFactory() external view override returns (address) {
        return address(_protocolFactory);
    }

    /**
     * @notice Exposes the status of reentrancy lock.
     * @dev Mainly useful for read-only reentrancy protection.
     */
    function isLocked() external view override returns (bool) {
        return _status == _ENTERED;
    }

    /**
     *
     *  EXTERNAL FUNCTIONS
     *
     */

    /**
     * @dev Required for swaps where tokenOut is ETH.
     * @dev Only callable by `WETH9`.
     */
    receive() external payable {
        if (msg.sender != WETH9) revert ValantisSwapRouter__receive_onlyWeth();
    }

    /**
     * @notice Callback function that Universal Pools can use to claim input token during a swap.
     * @dev Callable only by `allowedUniversalPool` at swap time.
     * @param _tokenIn Address of input token.
     * @param _amountInUsed Amount of input token used.
     * @param _swapCallbackContext Bytes encoded data required to execute the callback.
     */
    function universalPoolSwapCallback(
        address _tokenIn,
        uint256 _amountInUsed,
        bytes calldata _swapCallbackContext
    ) external override {
        if (msg.sender != allowedUniversalPool) {
            revert ValantisSwapRouter__universalPoolSwapCallback_poolNotAllowed();
        }

        (address tokenIn, address payer) = abi.decode(_swapCallbackContext, (address, address));

        if (payer != address(this) && tokenIn != _tokenIn) {
            revert ValantisSwapRouter__universalPoolSwapCallback_invalidTokenIn();
        }

        _executeTransfer(_tokenIn, payer, msg.sender, _amountInUsed);
    }

    /**
     * @notice Callback function that Sovereign Pools can use to claim input token during a swap.
     * @dev Callable only by `allowedSovereignPool` at swap time.
     * @param _tokenIn Address of input token.
     * @param _amountInUsed Amount of input token used.
     * @param _swapCallbackContext Bytes encoded data required to execute the callback.
     */
    function sovereignPoolSwapCallback(
        address _tokenIn,
        uint256 _amountInUsed,
        bytes calldata _swapCallbackContext
    ) external override {
        if (msg.sender != allowedSovereignPool) {
            revert ValantisSwapRouter__sovereignPoolSwapCallback_poolNotAllowed();
        }

        (address tokenIn, address payer) = abi.decode(_swapCallbackContext, (address, address));

        if (payer != address(this) && tokenIn != _tokenIn) {
            revert ValantisSwapRouter__sovereignPoolSwapCallback_invalidTokenIn();
        }

        // Sovereign Pools can have a custom recipient address for swaps
        address recipient = ISovereignPool(msg.sender).sovereignVault();
        _executeTransfer(_tokenIn, payer, recipient, _amountInUsed);
    }

    /**
     * @notice Swaps against Valantis liquidity pools using intents.
     * @dev Fee token payments, if any, are pulled from owner via Permit2.
     * @param _gaslessSwapParams Struct containing all intent parameters to be signed.
     * @param _ownerSignature EIP-712 signature of intent struct from owner.
     * @param _fee Fee to be charged for this transaction in feeToken.
     * @dev `_fee` must not exceed maxFee.
     */
    function gaslessSwap(
        GaslessSwapParams calldata _gaslessSwapParams,
        bytes calldata _ownerSignature,
        uint128 _fee
    ) external override nonReentrant returns (uint256 amountOut) {
        amountOut = _gaslessSwap(_gaslessSwapParams, _ownerSignature, _fee);
    }

    /**
     * @notice Allows caller to execute batched swaps against Valantis liquidity pools.
     * @dev Each swap is expressed as an intent.
     * @param _gaslessSwapParamsArray Array containing struct parameters for each swap.
     * @param _ownerSignaturesArray Array containing intent signature from each owner.
     * @param _feeArray Array of fees that caller charges on each swap.
     * @return amountOutArray Array containing output token amount from each swap.
     */
    function batchGaslessSwaps(
        GaslessSwapParams[] calldata _gaslessSwapParamsArray,
        bytes[] calldata _ownerSignaturesArray,
        uint128[] calldata _feeArray
    ) external override nonReentrant returns (uint256[] memory amountOutArray) {
        // Array length consistency
        if (
            _gaslessSwapParamsArray.length != _ownerSignaturesArray.length ||
            _ownerSignaturesArray.length != _feeArray.length
        ) {
            revert ValantisSwapRouter__batchGaslessSwaps_invalidArrayLengths();
        }

        uint256 length = _gaslessSwapParamsArray.length;
        amountOutArray = new uint256[](length);
        for (uint256 i; i < length; ) {
            amountOutArray[i] = _gaslessSwap(_gaslessSwapParamsArray[i], _ownerSignaturesArray[i], _feeArray[i]);

            unchecked {
                ++i;
            }
        }
    }

    /**
     * @notice Allows msg.sender to swap against Valantis liquidity pools.
     * @param _directSwapParams Struct containing all relevant parameters to execute the swap(s).
     * @return amountOut Amount of output token.
     */
    function swap(
        DirectSwapParams calldata _directSwapParams
    ) external payable override nonReentrant returns (uint256 amountOut) {
        // WETH related checks
        if (msg.value > 0 && _directSwapParams.tokenIn != WETH9) {
            revert ValantisSwapRouter__swap_invalidNativeTokenSwap();
        }

        if (_directSwapParams.isTokenOutEth && _directSwapParams.tokenOut != WETH9) {
            revert ValantisSwapRouter__swap_tokenOutNotWeth();
        }

        // Input params checks
        _directSwapParams.checkDirectSwapParams(msg.value);

        // Execute swap(s)
        uint256 tokenOutPreBalance = IERC20(_directSwapParams.tokenOut).balanceOf(
            _directSwapParams.isTokenOutEth ? address(this) : _directSwapParams.recipient
        );
        (uint256 amountInTotal, uint256 amountOutTotal) = _executeSwaps(
            ExecuteSwapParams({
                isUniversalPool: _directSwapParams.isUniversalPool,
                pools: _directSwapParams.pools,
                amountInSpecified: _directSwapParams.amountInSpecified,
                payloads: _directSwapParams.payloads,
                tokenIn: _directSwapParams.tokenIn,
                tokenOut: _directSwapParams.tokenOut,
                owner: msg.sender,
                deadline: _directSwapParams.deadline
            })
        );

        amountOut =
            IERC20(_directSwapParams.tokenOut).balanceOf(
                _directSwapParams.isTokenOutEth ? address(this) : _directSwapParams.recipient
            ) -
            tokenOutPreBalance;

        if (amountOut < _directSwapParams.amountOutMin || amountOutTotal < _directSwapParams.amountOutMin) {
            revert ValantisSwapRouter__swap_insufficientAmountOut();
        }

        if (msg.value > 0) {
            // Refund unspent ETH to recipient
            _sendNativeToken(_directSwapParams.recipient, address(this).balance);
        } else if (_directSwapParams.isTokenOutEth) {
            // Convert WETH into ETH and transfer to recipient
            IWETH9(WETH9).withdraw(amountOut);
            _sendNativeToken(_directSwapParams.recipient, amountOut);
        }

        emit DirectSwapLog(
            msg.sender,
            _directSwapParams.recipient,
            _directSwapParams.tokenIn,
            _directSwapParams.tokenOut,
            amountInTotal,
            amountOut,
            msg.value > 0,
            _directSwapParams.isTokenOutEth
        );
    }

    /**
     * @notice Sweep token balances which have been locked into this contract.
     * @dev Anyone can call this to sweep tokens.
     * @param _tokens Array of token address to claim balances for.
     * @param _recipient Recipient of incoming token balances.
     */
    function sweep(address[] memory _tokens, address _recipient) external nonReentrant {
        if (_tokens.length == 0) revert ValantisSwapRouter__sweep_invalidTokensArrayLength();

        if (_recipient == address(0)) revert ValantisSwapRouter__sweep_invalidRecipient();

        for (uint256 i; i < _tokens.length; i++) {
            IERC20 token = IERC20(_tokens[i]);
            if (address(token) == address(0)) revert ValantisSwapRouter__sweep_invalidTokenAddress();

            uint256 balance = token.balanceOf(address(this));
            if (balance > 0) token.safeTransfer(_recipient, balance);
        }
    }

    /**
     *
     *  PRIVATE FUNCTIONS
     *
     */
    function _gaslessSwap(
        GaslessSwapParams calldata gaslessSwapParams,
        bytes calldata ownerSignature,
        uint128 fee
    ) private returns (uint256 amountOut) {
        if (gaslessSwapParams.intent.isTokenOutEth && gaslessSwapParams.intent.tokenOut != WETH9) {
            revert ValantisSwapRouter___gaslessSwap_tokenOutNotWeth();
        }

        uint256 tokenOutPreBalance = IERC20(gaslessSwapParams.intent.tokenOut).balanceOf(
            gaslessSwapParams.intent.isTokenOutEth ? address(this) : gaslessSwapParams.intent.recipient
        );

        (uint256 amountInTotal, uint256 amountOutTotal) = _executeGaslessSwap(gaslessSwapParams, ownerSignature, fee);

        amountOut =
            IERC20(gaslessSwapParams.intent.tokenOut).balanceOf(
                gaslessSwapParams.intent.isTokenOutEth ? address(this) : gaslessSwapParams.intent.recipient
            ) -
            tokenOutPreBalance;

        if (
            amountOut < gaslessSwapParams.intent.amountOutMin || amountOutTotal < gaslessSwapParams.intent.amountOutMin
        ) {
            revert ValantisSwapRouter___gaslessSwap_insufficientAmountOut();
        }

        if (gaslessSwapParams.intent.isTokenOutEth) {
            // Convert WETH into ETH and transfer to recipient
            IWETH9(WETH9).withdraw(amountOut);
            _sendNativeToken(gaslessSwapParams.intent.recipient, amountOut);
        }

        emit GaslessSwapLog(
            gaslessSwapParams.intent.owner,
            gaslessSwapParams.intent.authorizedSender,
            gaslessSwapParams.intent.recipient,
            gaslessSwapParams.intent.tokenIn,
            gaslessSwapParams.intent.tokenOut,
            amountInTotal,
            amountOut,
            gaslessSwapParams.intent.isTokenOutEth
        );
    }

    function _executeGaslessSwap(
        GaslessSwapParams calldata gaslessSwapParams,
        bytes calldata ownerSignature,
        uint128 fee
    ) private returns (uint256 amountInTotal, uint256 amountOutTotal) {
        // Input params checks
        gaslessSwapParams.checkGaslessSwapParams();

        if (fee > gaslessSwapParams.intent.maxFee) revert ValantisSwapRouter___executeGaslessSwap_excessiveFee();

        // Consume nonce
        nonceBitmap[gaslessSwapParams.intent.owner].consumeNonce(gaslessSwapParams.intent.nonce);

        // Verify owner signature
        ownerSignature.verify(_hashTypedDataV4(gaslessSwapParams.intent.hashStruct()), gaslessSwapParams.intent.owner);

        // Execute swap(s)
        (amountInTotal, amountOutTotal) = _executeSwaps(
            ExecuteSwapParams({
                isUniversalPool: gaslessSwapParams.isUniversalPool,
                pools: gaslessSwapParams.pools,
                amountInSpecified: gaslessSwapParams.amountInSpecified,
                payloads: gaslessSwapParams.payloads,
                tokenIn: gaslessSwapParams.intent.tokenIn,
                tokenOut: gaslessSwapParams.intent.tokenOut,
                owner: gaslessSwapParams.intent.owner,
                deadline: gaslessSwapParams.intent.deadline
            })
        );

        // Pay fee in feeToken
        if (fee > 0) {
            _permit2.transferFrom(
                gaslessSwapParams.intent.owner,
                gaslessSwapParams.intent.authorizedSender,
                uint160(fee),
                gaslessSwapParams.intent.feeToken
            );
        }
    }

    function _executeSwaps(
        ExecuteSwapParams memory params
    ) private returns (uint256 amountInTotal, uint256 amountOutTotal) {
        uint256 amountOutSwap;

        // First swap's amountIn must be specified by owner
        if (params.amountInSpecified[0] == 0) {
            revert ValantisSwapRouter___executeSwaps_invalidAmountSpecifiedFirstSwap();
        }

        for (uint256 i; i < params.pools.length; ) {
            uint256 amountInUsed;
            address tokenOutSwap;
            (amountInUsed, tokenOutSwap, amountOutSwap) = params.isUniversalPool[i]
                ? _executeSingleSwapUniversalPool(
                    params.amountInSpecified[i] > 0 ? params.amountInSpecified[i] : amountOutSwap,
                    params.deadline,
                    params.pools[i],
                    abi.encode(params.tokenIn, params.amountInSpecified[i] > 0 ? params.owner : address(this)),
                    params.payloads[i]
                )
                : _executeSingleSwapSovereignPool(
                    params.amountInSpecified[i] > 0 ? params.amountInSpecified[i] : amountOutSwap,
                    params.deadline,
                    params.pools[i],
                    abi.encode(params.tokenIn, params.amountInSpecified[i] > 0 ? params.owner : address(this)),
                    params.payloads[i]
                );

            // Equivalent to user's tokenIn being the input token of this swap
            if (params.amountInSpecified[i] > 0) {
                amountInTotal += amountInUsed;
            }

            if (tokenOutSwap == params.tokenOut) {
                amountOutTotal += amountOutSwap;
            }

            unchecked {
                ++i;
            }
        }
    }

    function _executeSingleSwapUniversalPool(
        uint256 amountIn,
        uint256 deadline,
        address pool,
        bytes memory swapCallbackContext,
        bytes memory payload
    ) private returns (uint256 amountInUsed, address tokenOut, uint256 amountOut) {
        if (!_protocolFactory.isValidUniversalPool(pool)) {
            revert ValantisSwapRouter___executeSingleSwapUniversalPool_invalidUniversalPool();
        }

        UniversalPoolSwapPayload memory payloadStruct = abi.decode(payload, (UniversalPoolSwapPayload));

        allowedUniversalPool = pool;

        (amountInUsed, amountOut) = IUniversalPool(pool).swap(
            SwapParams({
                isZeroToOne: payloadStruct.isZeroToOne,
                isSwapCallback: true,
                limitPriceTick: payloadStruct.limitPriceTick,
                recipient: payloadStruct.recipient,
                amountIn: amountIn,
                amountOutMin: payloadStruct.amountOutMin,
                deadline: deadline,
                swapCallbackContext: swapCallbackContext,
                swapFeeModuleContext: payloadStruct.swapFeeModuleContext,
                almOrdering: payloadStruct.almOrdering,
                externalContext: payloadStruct.externalContext
            })
        );

        tokenOut = payloadStruct.isZeroToOne ? IUniversalPool(pool).token1() : IUniversalPool(pool).token0();

        allowedUniversalPool = address(1);
    }

    function _executeSingleSwapSovereignPool(
        uint256 amountIn,
        uint256 deadline,
        address pool,
        bytes memory swapCallbackContext,
        bytes memory payload
    ) private returns (uint256 amountInUsed, address tokenOut, uint256 amountOut) {
        if (!_protocolFactory.isValidSovereignPool(pool)) {
            revert ValantisSwapRouter___executeSingleSwapSovereignPool_invalidSovereignPool();
        }

        SovereignPoolSwapPayload memory payloadStruct = abi.decode(payload, (SovereignPoolSwapPayload));

        allowedSovereignPool = pool;

        (amountInUsed, amountOut) = ISovereignPool(pool).swap(
            SovereignPoolSwapParams({
                isSwapCallback: true,
                isZeroToOne: payloadStruct.isZeroToOne,
                amountIn: amountIn,
                amountOutMin: payloadStruct.amountOutMin,
                deadline: deadline,
                recipient: payloadStruct.recipient,
                swapTokenOut: payloadStruct.swapTokenOut,
                swapContext: SovereignPoolSwapContextData(
                    payloadStruct.externalContext,
                    payloadStruct.verificationContext,
                    swapCallbackContext,
                    payloadStruct.swapFeeModuleContext
                )
            })
        );
        tokenOut = payloadStruct.swapTokenOut;

        allowedSovereignPool = address(1);
    }

    function _executeTransfer(address token, address payer, address recipient, uint256 amount) private {
        if (token == WETH9 && address(this).balance >= amount) {
            IWETH9(WETH9).deposit{ value: amount }();
            IWETH9(WETH9).transfer(recipient, amount);
        } else if (payer == address(this)) {
            IERC20(token).safeTransfer(recipient, amount);
        } else {
            _permit2.transferFrom(payer, recipient, amount.toUint160(), token);
        }
    }

    function _sendNativeToken(address recipient, uint256 amount) private {
        if (amount > 0) {
            (bool success, ) = payable(recipient).call{ value: amount }('');
            if (!success) {
                revert ValantisSwapRouter___sendNativeToken_ethTransferFailed();
            }
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @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.
 */
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].
     */
    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 v4.9.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../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 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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 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);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @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.isContract(address(token));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * 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.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @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`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}

File 6 of 31 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

/**
 * @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.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        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
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        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
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        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
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        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
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        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
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        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
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        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
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        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
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        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
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @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
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @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
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @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
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @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
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @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
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @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
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 7 of 31 : UniversalALMStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

struct ALMLiquidityQuotePoolInputs {
    bool isZeroToOne;
    int24 limitPriceTick;
    int24 currentSpotPriceTick;
    uint256 amountInRemaining;
    uint256 amountOutExpected;
}

struct ALMLiquidityQuote {
    uint256 tokenOutAmount;
    int24 nextLiquidPriceTick;
    bytes internalContext;
}

struct ALMCachedLiquidityQuote {
    uint256 tokenOutAmount;
    int24 priceTick;
    int24 nextLiquidPriceTick;
    bytes internalContext;
}

struct ALMReserves {
    uint256 tokenInReserves;
    uint256 tokenOutReserves;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface IUniversalOracle {
    /**
        @notice Returns the address of the pool associated with the oracle.
        @return pool The address of the pool.
     */
    function pool() external view returns (address);

    /**
        @notice Writes an update to the oracle after a swap in the Universal Pool.
        @param isZeroToOne True if the swap is from token0 to token1, false otherwise.
        @param amountInUsed The amount of the tokenIn used for the swap.
        @param fee The fee amount.
        @param amountOut The amount of the tokenOut transferred to the user.
        @param spotPriceTick The spot price tick after the swap.
        @param spotPriceTickStart The spot price tick before the swap.
     */
    function writeOracleUpdate(
        bool isZeroToOne,
        uint256 amountInUsed,
        uint256 fee,
        uint256 amountOut,
        int24 spotPriceTick,
        int24 spotPriceTickStart
    ) external;
}

File 9 of 31 : IFlashBorrower.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

interface IFlashBorrower {
    /**
        @dev Receive a flash loan.
        @param initiator The initiator of the loan.
        @param token The loan currency.
        @param amount The amount of tokens lent.
        @param data Arbitrary data structure, intended to contain user-defined parameters.
        @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
     */
    function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        bytes calldata data
    ) external returns (bytes32);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { IValantisPool } from '../interfaces/IValantisPool.sol';
import { PoolLocks } from '../structs/ReentrancyGuardStructs.sol';
import { SovereignPoolSwapContextData, SovereignPoolSwapParams } from '../structs/SovereignPoolStructs.sol';

interface ISovereignPool is IValantisPool {
    event SwapFeeModuleSet(address swapFeeModule);
    event ALMSet(address alm);
    event GaugeSet(address gauge);
    event PoolManagerSet(address poolManager);
    event PoolManagerFeeSet(uint256 poolManagerFeeBips);
    event SovereignOracleSet(address sovereignOracle);
    event PoolManagerFeesClaimed(uint256 amount0, uint256 amount1);
    event DepositLiquidity(uint256 amount0, uint256 amount1);
    event WithdrawLiquidity(address indexed recipient, uint256 amount0, uint256 amount1);
    event Swap(address indexed sender, bool isZeroToOne, uint256 amountIn, uint256 fee, uint256 amountOut);

    function getTokens() external view returns (address[] memory tokens);

    function sovereignVault() external view returns (address);

    function protocolFactory() external view returns (address);

    function gauge() external view returns (address);

    function poolManager() external view returns (address);

    function sovereignOracleModule() external view returns (address);

    function swapFeeModule() external view returns (address);

    function verifierModule() external view returns (address);

    function isLocked() external view returns (bool);

    function isRebaseTokenPool() external view returns (bool);

    function poolManagerFeeBips() external view returns (uint256);

    function defaultSwapFeeBips() external view returns (uint256);

    function swapFeeModuleUpdateTimestamp() external view returns (uint256);

    function alm() external view returns (address);

    function getPoolManagerFees() external view returns (uint256 poolManagerFee0, uint256 poolManagerFee1);

    function getReserves() external view returns (uint256 reserve0, uint256 reserve1);

    function setPoolManager(address _manager) external;

    function setGauge(address _gauge) external;

    function setPoolManagerFeeBips(uint256 _poolManagerFeeBips) external;

    function setSovereignOracle(address sovereignOracle) external;

    function setSwapFeeModule(address _swapFeeModule) external;

    function setALM(address _alm) external;

    function swap(SovereignPoolSwapParams calldata _swapParams) external returns (uint256, uint256);

    function depositLiquidity(
        uint256 _amount0,
        uint256 _amount1,
        address _sender,
        bytes calldata _verificationContext,
        bytes calldata _depositData
    ) external returns (uint256 amount0Deposited, uint256 amount1Deposited);

    function withdrawLiquidity(
        uint256 _amount0,
        uint256 _amount1,
        address _sender,
        address _recipient,
        bytes calldata _verificationContext
    ) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface ISovereignPoolSwapCallback {
    /**
        @notice Function called by Sovereign Pool during a swap, to transfer the funds.
        @dev This function is only called if isSwapCallback is set to true in swapParams.
        @param _tokenIn The address of the token that the user wants to swap.
        @param _amountInUsed The amount of the tokenIn used for the swap.
        @param _swapCallbackContext Arbitrary bytes data which can be sent to the swap callback.
     */
    function sovereignPoolSwapCallback(
        address _tokenIn,
        uint256 _amountInUsed,
        bytes calldata _swapCallbackContext
    ) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { Slot0, ALMPosition, ALMStatus, PoolState, SwapParams } from '../structs/UniversalPoolStructs.sol';
import { IValantisPool } from '../interfaces/IValantisPool.sol';
import { PoolLocks } from '../structs/ReentrancyGuardStructs.sol';
import { ALMReserves } from '../../ALM/structs/UniversalALMStructs.sol';

interface IUniversalPool is IValantisPool {
    /************************************************
     *  EVENTS
     ***********************************************/

    event Swap(address indexed user, uint256 amountIn, uint256 amountOut, bool isZeroToOne);
    event GaugeSet(address gauge);
    event InitializeTick(int24 tick);

    /************************************************
     *  VIEW FUNCTIONS
     ***********************************************/

    function spotPriceTick() external view returns (int24);

    function state() external view returns (PoolState memory);

    function getALMReserves(address _almPositionAddress, bool _isZeroToOne) external view returns (ALMReserves memory);

    function getALMPositionsList() external view returns (ALMPosition[] memory);

    function getPoolLockStatus() external view returns (PoolLocks memory);

    function getALMPositionAtAddress(
        address _almPositionAddress
    ) external view returns (ALMStatus status, ALMPosition memory);

    /************************************************
     *  EXTERNAL FUNCTIONS
     ***********************************************/

    function addALMPosition(
        bool _isMetaALM,
        bool _isCallbackOnSwapEndRequired,
        bool _shareQuotes,
        uint64 _metaALMFeeShare,
        address _almAddress
    ) external;

    function removeALMPosition(address _almAddress) external;

    function setPoolState(PoolState memory newState) external;

    function swap(SwapParams calldata _swapParams) external returns (uint256, uint256);

    function depositLiquidity(uint256 _amount0, uint256 _amount1, bytes memory _depositData) external;

    function withdrawLiquidity(uint256 _amount0, uint256 _amount1, address _recipient) external;

    function initializeTick(int24 _tick) external;

    function setMetaALMFeeShare(address _almAddress, uint64 _feeShare) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface IUniversalPoolSwapCallback {
    /**
        @notice Function called by Universal Pool during a swap, to transfer the funds.
        @dev This function is only called if isSwapCallback is set to true in swapParams.
        @param _tokenIn The address of the token that the user wants to swap.
        @param _amountInUsed The amount of the tokenIn used for the swap.
        @param _swapCallbackContext Arbitrary bytes data which can be sent to the swap callback.
     */
    function universalPoolSwapCallback(
        address _tokenIn,
        uint256 _amountInUsed,
        bytes calldata _swapCallbackContext
    ) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { IFlashBorrower } from './IFlashBorrower.sol';

interface IValantisPool {
    /************************************************
     *  EVENTS
     ***********************************************/

    event Flashloan(address indexed initiator, address indexed receiver, uint256 amount, address token);

    /************************************************
     *  ERRORS
     ***********************************************/

    error ValantisPool__flashloan_callbackFailed();
    error ValantisPool__flashLoan_flashLoanDisabled();
    error ValantisPool__flashLoan_flashLoanNotRepaid();
    error ValantisPool__flashLoan_rebaseTokenNotAllowed();

    /************************************************
     *  VIEW FUNCTIONS
     ***********************************************/

    /**
        @notice Address of ERC20 token0 of the pool.
     */
    function token0() external view returns (address);

    /**
        @notice Address of ERC20 token1 of the pool.
     */
    function token1() external view returns (address);

    /************************************************
     *  EXTERNAL FUNCTIONS
     ***********************************************/

    /**
        @notice Claim share of protocol fees accrued by this pool.
        @dev Can only be claimed by `gauge` of the pool. 
     */
    function claimProtocolFees() external returns (uint256, uint256);

    /**
        @notice Claim share of fees accrued by this pool
                And optionally share some with the protocol.
        @dev Only callable by `poolManager`.
        @param _feeProtocol0Bips Percent of `token0` fees to be shared with protocol.
        @param _feeProtocol1Bips Percent of `token1` fees to be shared with protocol.
     */
    function claimPoolManagerFees(
        uint256 _feeProtocol0Bips,
        uint256 _feeProtocol1Bips
    ) external returns (uint256 feePoolManager0Received, uint256 feePoolManager1Received);

    /**
        @notice Sets the gauge contract address for the pool.
        @dev Only callable by `protocolFactory`.
        @dev Once a gauge is set it cannot be changed again.
        @param _gauge address of the gauge.
     */
    function setGauge(address _gauge) external;

    /**
        @notice Allows anyone to flash loan any amount of tokens from the pool.
        @param _isTokenZero True if token0 is being flash loaned, False otherwise.
        @param _receiver Address of the flash loan receiver.
        @param _amount Amount of tokens to be flash loaned.
        @param _data Bytes encoded data for flash loan callback.
     */
    function flashLoan(bool _isTokenZero, IFlashBorrower _receiver, uint256 _amount, bytes calldata _data) external;
}

File 15 of 31 : ReentrancyGuardStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

enum Lock {
    WITHDRAWAL,
    DEPOSIT,
    SWAP,
    SPOT_PRICE_TICK
}

struct PoolLocks {
    /**
        @notice Locks all functions that require any withdrawal of funds from the pool
                This involves the following functions -
                * withdrawLiquidity
                * claimProtocolFees
                * claimPoolManagerFees
     */
    uint8 withdrawals;
    /**
        @notice Only locks the deposit function
    */
    uint8 deposit;
    /**
        @notice Only locks the swap function
    */
    uint8 swap;
    /**
        @notice Only locks the spotPriceTick function
    */
    uint8 spotPriceTick;
}

File 16 of 31 : SovereignPoolStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { IERC20 } from '../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol';

import { ISwapFeeModule } from '../../swap-fee-modules/interfaces/ISwapFeeModule.sol';

struct SovereignPoolConstructorArgs {
    address token0;
    address token1;
    address protocolFactory;
    address poolManager;
    address sovereignVault;
    address verifierModule;
    bool isToken0Rebase;
    bool isToken1Rebase;
    uint256 token0AbsErrorTolerance;
    uint256 token1AbsErrorTolerance;
    uint256 defaultSwapFeeBips;
}

struct SovereignPoolSwapContextData {
    bytes externalContext;
    bytes verifierContext;
    bytes swapCallbackContext;
    bytes swapFeeModuleContext;
}

struct SwapCache {
    ISwapFeeModule swapFeeModule;
    IERC20 tokenInPool;
    IERC20 tokenOutPool;
    uint256 amountInWithoutFee;
}

struct SovereignPoolSwapParams {
    bool isSwapCallback;
    bool isZeroToOne;
    uint256 amountIn;
    uint256 amountOutMin;
    uint256 deadline;
    address recipient;
    address swapTokenOut;
    SovereignPoolSwapContextData swapContext;
}

File 17 of 31 : UniversalPoolStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ALMCachedLiquidityQuote, ALMReserves } from '../../ALM/structs/UniversalALMStructs.sol';
import { IUniversalOracle } from '../../oracles/interfaces/IUniversalOracle.sol';
import { SwapFeeModuleData } from '../../swap-fee-modules/interfaces/ISwapFeeModule.sol';

struct Slot0 {
    bool isMetaALM;
    bool isCallbackOnSwapEndRequired;
    bool shareQuotes;
    uint64 metaALMFeeShare;
    address almAddress;
}

struct ALMPosition {
    Slot0 slot0;
    uint256 reserve0;
    uint256 reserve1;
    uint256 feeCumulative0;
    uint256 feeCumulative1;
}

struct UnderlyingALMQuote {
    bool isValidQuote;
    address almAddress;
    uint256 tokenOutAmount;
}

struct MetaALMData {
    UnderlyingALMQuote[] almQuotes;
    bytes almContext;
}

struct SwapParams {
    bool isZeroToOne;
    bool isSwapCallback;
    int24 limitPriceTick;
    address recipient;
    uint256 amountIn;
    uint256 amountOutMin;
    uint256 deadline;
    bytes swapCallbackContext;
    bytes swapFeeModuleContext;
    uint8[] almOrdering;
    bytes[] externalContext;
}

/************************************************
 *  CACHE STRUCTS
 ***********************************************/

struct SwapCache {
    bool isMetaALMPool;
    int24 spotPriceTick;
    int24 spotPriceTickStart;
    address swapFeeModule;
    uint256 amountInMinusFee;
    uint256 amountInRemaining;
    uint256 amountOutFilled;
    uint256 effectiveFee;
    uint256 numBaseALMs;
    uint256 baseShareQuoteLiquidity;
    uint256 feeInBips;
}

struct InternalSwapALMState {
    bool isParticipatingInSwap;
    bool refreshReserves;
    Slot0 almSlot0;
    uint256 totalLiquidityProvided;
    uint256 totalLiquidityReceived;
    ALMReserves almReserves;
    uint256 feeEarned;
    ALMCachedLiquidityQuote latestLiquidityQuote;
}

struct PoolState {
    uint256 poolManagerFeeBips;
    uint256 feeProtocol0;
    uint256 feeProtocol1;
    uint256 feePoolManager0;
    uint256 feePoolManager1;
    uint256 swapFeeModuleUpdateTimestamp;
    address swapFeeModule;
    address poolManager;
    address universalOracle;
    address gauge;
}

enum ALMStatus {
    NULL, // ALM was never added to the pool
    ACTIVE, // ALM was added to the pool, and is in operation
    REMOVED // ALM was added to the pool, and then removed, not in operation
}

File 18 of 31 : IProtocolFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { SovereignPoolConstructorArgs } from '../../pools/structs/SovereignPoolStructs.sol';

interface IProtocolFactory {
    event GovernanceTokenSet(address governanceToken);
    event ProtocolManagerSet(address protocolManager);
    event UniversalPoolFactorySet(address universalPoolFactory);
    event SovereignPoolFactorySet(address sovereignPoolFactory);
    event AuctionControllerSet(address auctionController);
    event EmissionsControllerSet(address emissionsController);
    event UniversalGaugeFactorySet(address universalGaugeFactory);
    event SovereignGaugeFactorySet(address sovereignGaugeFactory);

    event UniversalALMDeployed(address alm, address pool, address factory);
    event SovereignALMDeployed(address alm, address pool, address factory);
    event SwapFeeModuleDeployed(address swapFeeModule, address pool, address factory);
    event UniversalOracleDeployed(address universalOracle, address pool, address factory);
    event SovereignOracleDeployed(address sovereignOracle, address pool, address factory);
    event UniversalPoolDeployed(address indexed token0, address indexed token1, address pool);
    event SovereignPoolDeployed(address indexed token0, address indexed token1, address pool);
    event UniversalGaugeDeployed(address gauge, address pool, address manager);
    event SovereignGaugeDeployed(address gauge, address pool, address manager);

    event UniversalALMFactoryAdded(address factory);
    event UniversalALMFactoryRemoved(address factory);
    event SovereignALMFactoryAdded(address factory);
    event SovereignALMFactoryRemoved(address factory);
    event SwapFeeModuleFactoryAdded(address factory);
    event SwapFeeModuleFactoryRemoved(address factory);
    event UniversalOracleFactoryAdded(address factory);
    event UniversalOracleFactoryRemoved(address factory);
    event SovereignOracleFactoryAdded(address factory);
    event SovereignOracleFactoryRemoved(address factory);

    function protocolDeployer() external view returns (address);

    function almFactories(address _almPosition) external view returns (address);

    function swapFeeModules(address _pool) external view returns (address);

    function universalOracleModules(address _pool) external view returns (address);

    function sovereignOracleModules(address _pool) external view returns (address);

    function auctionController() external view returns (address);

    function emissionsController() external view returns (address);

    function almNonce() external view returns (uint256);

    function swapFeeModuleNonce() external view returns (uint256);

    function universalOracleModuleNonce() external view returns (uint256);

    function sovereignOracleModuleNonce() external view returns (uint256);

    function protocolManager() external view returns (address);

    function governanceToken() external view returns (address);

    function universalPoolFactory() external view returns (address);

    function sovereignPoolFactory() external view returns (address);

    function universalGaugeFactory() external view returns (address);

    function sovereignGaugeFactory() external view returns (address);

    function getUniversalALMFactories() external view returns (address[] memory);

    function getSovereignALMFactories() external view returns (address[] memory);

    function getSwapFeeModuleFactories() external view returns (address[] memory);

    function getUniversalOracleModuleFactories() external view returns (address[] memory);

    function getSovereignOracleModuleFactories() external view returns (address[] memory);

    function gaugeByPool(address _pool) external view returns (address);

    function poolByGauge(address _gauge) external view returns (address);

    function isValidUniversalPool(address _pool) external view returns (bool);

    function isValidSovereignPool(address _pool) external view returns (bool);

    function isValidUniversalALMFactory(address _almFactory) external view returns (bool);

    function isValidSovereignALMFactory(address _almFactory) external view returns (bool);

    function isValidSwapFeeModuleFactory(address _swapFeeModuleFactory) external view returns (bool);

    function isValidUniversalOracleModuleFactory(address _universalOracleModuleFactory) external view returns (bool);

    function isValidSovereignOracleModuleFactory(address _sovereignOracleModuleFactory) external view returns (bool);

    function isValidUniversalALMPosition(address _almPosition) external view returns (bool);

    function isValidSovereignALMPosition(address _almPosition) external view returns (bool);

    function isValidSwapFeeModule(address _swapFeeModule) external view returns (bool);

    function isValidUniversalOracleModule(address _universalOracleModule) external view returns (bool);

    function isValidSovereignOracleModule(address _sovereignOracleModule) external view returns (bool);

    function setGovernanceToken(address _governanceToken) external;

    function setProtocolManager(address _protocolManager) external;

    function setUniversalPoolFactory(address _universalPoolFactory) external;

    function setSovereignPoolFactory(address _sovereignPoolFactory) external;

    function setAuctionController(address _auctionController) external;

    function setEmissionsController(address _emissionsController) external;

    function setSovereignGaugeFactory(address _poolGaugeFactory) external;

    function setUniversalGaugeFactory(address _universalGaugeFactory) external;

    function deployUniversalGauge(address _pool, address _manager) external returns (address gauge);

    function deploySovereignGauge(address _pool, address _manager) external returns (address gauge);

    function deployALMPositionForUniversalPool(
        address _pool,
        address _almFactory,
        bytes calldata _constructorArgs
    ) external returns (address alm);

    function deployALMPositionForSovereignPool(
        address _pool,
        address _almFactory,
        bytes calldata _constructorArgs
    ) external returns (address alm);

    function deploySwapFeeModuleForPool(
        address _pool,
        address _swapFeeModuleFactory,
        bytes calldata _constructorArgs
    ) external returns (address swapFeeModule);

    function deployUniversalPool(
        address _token0,
        address _token1,
        address _poolManager,
        uint256 _deploySwapFeeBips
    ) external returns (address pool);

    function deploySovereignPool(SovereignPoolConstructorArgs memory _args) external returns (address pool);

    function deployUniversalOracleForPool(
        address _pool,
        address _universalOracleModuleFactory,
        bytes calldata _constructorArgs
    ) external returns (address universalOracleModule);

    function deploySovereignOracleForPool(
        address _pool,
        address _sovereignOracleModuleFactory,
        bytes calldata _constructorArgs
    ) external returns (address sovereignOracleModule);

    function addUniversalALMFactory(address _almFactory) external;

    function addSovereignALMFactory(address _almFactory) external;

    function addSwapFeeModuleFactory(address _swapFeeModuleFactory) external;

    function addUniversalOracleModuleFactory(address _universalOracleModuleFactory) external;

    function addSovereignOracleModuleFactory(address _sovereignOracleModuleFactory) external;

    function removeUniversalALMFactory(address _almFactory) external;

    function removeSovereignALMFactory(address _almFactory) external;

    function removeSwapFeeModuleFactory(address _swapFeeModuleFactory) external;

    function removeUniversalOracleModuleFactory(address _universalOracleModuleFactory) external;

    function removeSovereignOracleModuleFactory(address _sovereignOracleModuleFactory) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/**
    @notice Struct returned by the swapFeeModule during the getSwapFeeInBips call.
    * feeInBips: The swap fee in bips.
    * internalContext: Arbitrary bytes context data.
 */
struct SwapFeeModuleData {
    uint256 feeInBips;
    bytes internalContext;
}

interface ISwapFeeModuleMinimal {
    /**
        @notice Returns the swap fee in bips for both Universal & Sovereign Pools.
        @param _tokenIn The address of the token that the user wants to swap.
        @param _tokenOut The address of the token that the user wants to receive.
        @param _amountIn The amount of tokenIn being swapped.
        @param _user The address of the user.
        @param _swapFeeModuleContext Arbitrary bytes data which can be sent to the swap fee module.
        @return swapFeeModuleData A struct containing the swap fee in bips, and internal context data.
     */
    function getSwapFeeInBips(
        address _tokenIn,
        address _tokenOut,
        uint256 _amountIn,
        address _user,
        bytes memory _swapFeeModuleContext
    ) external returns (SwapFeeModuleData memory swapFeeModuleData);
}

interface ISwapFeeModule is ISwapFeeModuleMinimal {
    /**
        @notice Callback function called by the pool after the swap has finished. ( Universal Pools )
        @param _effectiveFee The effective fee charged for the swap.
        @param _spotPriceTick The spot price tick after the swap.
        @param _amountInUsed The amount of tokenIn used for the swap.
        @param _amountOut The amount of the tokenOut transferred to the user.
        @param _swapFeeModuleData The context data returned by getSwapFeeInBips.
     */
    function callbackOnSwapEnd(
        uint256 _effectiveFee,
        int24 _spotPriceTick,
        uint256 _amountInUsed,
        uint256 _amountOut,
        SwapFeeModuleData memory _swapFeeModuleData
    ) external;

    /**
        @notice Callback function called by the pool after the swap has finished. ( Sovereign Pools )
        @param _effectiveFee The effective fee charged for the swap.
        @param _amountInUsed The amount of tokenIn used for the swap.
        @param _amountOut The amount of the tokenOut transferred to the user.
        @param _swapFeeModuleData The context data returned by getSwapFeeInBips.
     */
    function callbackOnSwapEnd(
        uint256 _effectiveFee,
        uint256 _amountInUsed,
        uint256 _amountOut,
        SwapFeeModuleData memory _swapFeeModuleData
    ) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/**
    @notice Adapted from:
            https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.3/contracts/security/ReentrancyGuard.sol
    @dev Uses internal variables and functions
         so that child contracts can be explicit about view-function reentrancy risk.
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 internal constant _NOT_ENTERED = 1;
    uint256 internal constant _ENTERED = 2;

    uint256 internal _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() internal {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, 'ReentrancyGuard: reentrant call');

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() internal {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

/**
 * @notice EIP712 helpers for Valantis Swap Router.
 *     @dev Adapted from: https://github.com/Uniswap/permit2/blob/main/src/EIP712.sol
 */
contract EIP712 {
    // Cache the domain separator as an immutable value, but also store the chain id that it
    // corresponds to, in order to invalidate the cached domain separator if the chain id changes.
    // solhint-disable-next-line var-name-mixedcase
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    // solhint-disable-next-line var-name-mixedcase
    uint256 private immutable _CACHED_CHAIN_ID;

    bytes32 private constant _HASHED_NAME = keccak256("ValantisSwapRouter");

    bytes32 private constant _DOMAIN_HASH =
        keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

    constructor() {
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(_DOMAIN_HASH, _HASHED_NAME);
    }

    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() public view returns (bytes32) {
        return block.chainid == _CACHED_CHAIN_ID
            ? _CACHED_DOMAIN_SEPARATOR
            : _buildDomainSeparator(_DOMAIN_HASH, _HASHED_NAME);
    }

    function _buildDomainSeparator(bytes32 typeHash, bytes32 nameHash) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, block.chainid, address(this)));
    }

    function _hashTypedDataV4(bytes32 intentHash) internal view returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), intentHash));
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/// @title AllowanceTransfer
// solhint-disable-next-line max-line-length
/// @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 {
    /// @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
    );

    // solhint-disable-next-line max-line-length
    /// @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 allownce
    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;
    }

    // solhint-disable-next-line max-line-length
    /// @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]
    // solhint-disable-next-line max-line-length
    /// @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.19;

interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     *     @param hash      Hash of the data to be signed
     *     @param signature Signature byte array associated with _data
     *     @return magicValue The bytes4 magic value 0x1626ba7e
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ISovereignPoolSwapCallback} from "@valantis-core/src/pools/interfaces/ISovereignPoolSwapCallback.sol";
import {IUniversalPoolSwapCallback} from "@valantis-core/src/pools/interfaces/IUniversalPoolSwapCallback.sol";

import {GaslessSwapParams, DirectSwapParams} from "../structs/ValantisSwapRouterStructs.sol";

interface IValantisSwapRouter is ISovereignPoolSwapCallback, IUniversalPoolSwapCallback {
    event DirectSwapLog(
        address user,
        address recipient,
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 amountOut,
        bool isTokenInEth,
        bool isTokenOutEth
    );

    event GaslessSwapLog(
        address user,
        address solver,
        address recipient,
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 amountOut,
        bool isTokenOutEth
    );

    // solhint-disable-next-line func-name-mixedcase
    function WETH9() external view returns (address);

    function nonceBitmap(address _signer, uint256 _wordPosition) external view returns (uint256);

    function isLocked() external view returns (bool);

    function allowedUniversalPool() external view returns (address);

    function allowedSovereignPool() external view returns (address);

    function permit2() external view returns (address);

    function protocolFactory() external view returns (address);

    function gaslessSwap(GaslessSwapParams calldata _gaslessSwapParams, bytes calldata _ownerSignature, uint128 _fee)
        external
        returns (uint256 amountOut);

    function batchGaslessSwaps(
        GaslessSwapParams[] calldata _gaslessSwapParamsArray,
        bytes[] calldata _ownerSignaturesArray,
        uint128[] calldata _feeArray
    ) external returns (uint256[] memory amountOutArray);

    function swap(DirectSwapParams calldata _directSwapParams) external payable returns (uint256 amountOut);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {IERC20} from "@valantis-core/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

interface IWETH9 is IERC20 {
    function deposit() external payable;

    function withdraw(uint256) external;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {DirectSwapParams} from "../structs/ValantisSwapRouterStructs.sol";

library DirectSwap {
    error DirectSwap__checkDirectSwapParams_arrayLengthMismatch();
    error DirectSwap__checkDirectSwapParams_equalTokenInAndTokenOut();
    error DirectSwap__checkDirectSwapParams_incorrectNativeTokenAmountIn();
    error DirectSwap__checkDirectSwapParams_invalidArrayLength();
    error DirectSwap__checkDirectSwapParams_invalidDeadline();

    function checkDirectSwapParams(DirectSwapParams calldata directSwapParams, uint256 msgValue) internal view {
        if (block.timestamp > directSwapParams.deadline) revert DirectSwap__checkDirectSwapParams_invalidDeadline();

        if (directSwapParams.isUniversalPool.length == 0) {
            revert DirectSwap__checkDirectSwapParams_invalidArrayLength();
        }

        if (
            directSwapParams.isUniversalPool.length != directSwapParams.pools.length
                || directSwapParams.pools.length != directSwapParams.amountInSpecified.length
                || directSwapParams.amountInSpecified.length != directSwapParams.payloads.length
        ) revert DirectSwap__checkDirectSwapParams_arrayLengthMismatch();

        // tokenIn and tokenOut cannot be the same
        if (directSwapParams.tokenIn == directSwapParams.tokenOut) {
            revert DirectSwap__checkDirectSwapParams_equalTokenInAndTokenOut();
        }

        // In case tokenIn is ETH, we require that msg.value is equal to total amountIn specified
        if (msgValue > 0) {
            uint256 amountInTotal;
            for (uint256 i; i < directSwapParams.amountInSpecified.length;) {
                amountInTotal += directSwapParams.amountInSpecified[i];

                unchecked {
                    ++i;
                }
            }

            if (amountInTotal != msgValue) {
                revert DirectSwap__checkDirectSwapParams_incorrectNativeTokenAmountIn();
            }
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {GaslessSwapParams} from "../structs/ValantisSwapRouterStructs.sol";

library GaslessSwap {
    error GaslessSwap__checkGaslessSwapParams_arrayLengthMismatch();
    error GaslessSwap__checkGaslessSwapParams_equalTokenInAndTokenOut();
    error GaslessSwap__checkGaslessSwapParams_invalidAmountInSpecifiedArray();
    error GaslessSwap__checkGaslessSwapParams_invalidArrayLength();
    error GaslessSwap__checkGaslessSwapParams_invalidDeadline();
    error GaslessSwap__checkGaslessSwapParams_senderNotAuthorized();

    function checkGaslessSwapParams(GaslessSwapParams calldata gaslessSwapParams) internal view {
        if (block.timestamp > gaslessSwapParams.intent.deadline) {
            revert GaslessSwap__checkGaslessSwapParams_invalidDeadline();
        }

        if (gaslessSwapParams.isUniversalPool.length == 0) {
            revert GaslessSwap__checkGaslessSwapParams_invalidArrayLength();
        }

        if (
            gaslessSwapParams.isUniversalPool.length != gaslessSwapParams.pools.length
                || gaslessSwapParams.pools.length != gaslessSwapParams.amountInSpecified.length
                || gaslessSwapParams.amountInSpecified.length != gaslessSwapParams.payloads.length
        ) revert GaslessSwap__checkGaslessSwapParams_arrayLengthMismatch();

        // tokenIn and tokenOut cannot be the same
        if (gaslessSwapParams.intent.tokenIn == gaslessSwapParams.intent.tokenOut) {
            revert GaslessSwap__checkGaslessSwapParams_equalTokenInAndTokenOut();
        }

        uint256 amountInSpecifiedSum;
        uint256 numTokenInSwaps = gaslessSwapParams.amountInSpecified.length;
        for (uint256 i; i < numTokenInSwaps;) {
            amountInSpecifiedSum += gaslessSwapParams.amountInSpecified[i];

            unchecked {
                ++i;
            }
        }

        // Total sum of amount specified array must match amountIn
        if (amountInSpecifiedSum != gaslessSwapParams.intent.amountIn) {
            revert GaslessSwap__checkGaslessSwapParams_invalidAmountInSpecifiedArray();
        }

        // Enforce that caller is authorizedSender
        if (msg.sender != gaslessSwapParams.intent.authorizedSender) {
            revert GaslessSwap__checkGaslessSwapParams_senderNotAuthorized();
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {GaslessSwapIntent} from "../structs/ValantisSwapRouterStructs.sol";

library GaslessSwapIntentHash {
    bytes32 public constant GASLESS_SWAP_INTENT_TYPEHASH = keccak256(
        // solhint-disable-next-line max-line-length
        "GaslessSwapIntent(bool isTokenOutEth,address tokenIn,address tokenOut,address owner,address recipient,address authorizedSender,address feeToken,uint256 amountIn,uint256 amountOutMin,uint128 maxFee,uint256 nonce,uint256 deadline)"
    );

    function hashStruct(GaslessSwapIntent calldata swapIntent) internal pure returns (bytes32) {
        return keccak256(abi.encode(GASLESS_SWAP_INTENT_TYPEHASH, swapIntent));
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

library NonceBitmap {
    error NonceBitmap__consumeNonce_InvalidNonce();

    function consumeNonce(mapping(uint256 => uint256) storage nonces, uint256 nonce) internal {
        uint256 wordPosition = uint248(nonce >> 8);
        uint256 bitPosition = uint8(nonce);

        uint256 bit = 1 << bitPosition;

        uint256 flipped = nonces[wordPosition] ^= bit;

        if (flipped & bit == 0) revert NonceBitmap__consumeNonce_InvalidNonce();
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {IERC1271} from "../interfaces/IERC1271.sol";

/**
 * @notice Verification of ECDSA signatures for EOAs and smart contracts (EIP 1271).
 *     @dev Ported from: https://github.com/Uniswap/permit2/blob/main/src/libraries/SignatureVerification.sol
 */
library SignatureVerification {
    /**
     * @notice Thrown when the passed in signature is not a valid length
     */
    error InvalidSignatureLength();

    /**
     * @notice Thrown when the recovered signer is equal to the zero address
     */
    error InvalidSignature();

    /**
     * @notice Thrown when the recovered signer does not equal the claimedSigner
     */
    error InvalidSigner();

    /**
     * @notice Thrown when the recovered contract signature is incorrect
     */
    error InvalidContractSignature();

    bytes32 constant UPPER_BIT_MASK = (0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);

    function verify(bytes calldata signature, bytes32 hash, address claimedSigner) internal view {
        bytes32 r;
        bytes32 s;
        uint8 v;

        if (claimedSigner.code.length == 0) {
            if (signature.length == 65) {
                (r, s) = abi.decode(signature, (bytes32, bytes32));
                v = uint8(signature[64]);
            } else if (signature.length == 64) {
                // EIP-2098
                bytes32 vs;
                (r, vs) = abi.decode(signature, (bytes32, bytes32));
                s = vs & UPPER_BIT_MASK;
                v = uint8(uint256(vs >> 255)) + 27;
            } else {
                revert InvalidSignatureLength();
            }

            // Prevent Signature malleability attacks
            if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
                revert InvalidSignature();
            }

            address signer = ecrecover(hash, v, r, s);
            if (signer == address(0)) revert InvalidSignature();
            if (signer != claimedSigner) revert InvalidSigner();
        } else {
            bytes4 magicValue = IERC1271(claimedSigner).isValidSignature(hash, signature);
            if (magicValue != IERC1271.isValidSignature.selector) revert InvalidContractSignature();
        }
    }
}

File 31 of 31 : ValantisSwapRouterStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

/**
 * @notice Swap params passed by solvers and executed on behalf of due owner.
 */
struct GaslessSwapParams {
    bool[] isUniversalPool;
    address[] pools;
    uint256[] amountInSpecified;
    bytes[] payloads;
    GaslessSwapIntent intent;
}

/**
 * @notice Intent struct, to be EIP-712 signed by `owner`.
 */
struct GaslessSwapIntent {
    bool isTokenOutEth;
    address tokenIn;
    address tokenOut;
    address owner;
    address recipient;
    address authorizedSender;
    address feeToken;
    uint256 amountIn;
    uint256 amountOutMin;
    uint128 maxFee;
    uint256 nonce;
    uint256 deadline;
}

/**
 * @notice Struct containing params for direct swap.
 */
struct DirectSwapParams {
    bool[] isUniversalPool;
    address[] pools;
    uint256[] amountInSpecified;
    bytes[] payloads;
    bool isTokenOutEth;
    address tokenIn;
    address tokenOut;
    address recipient;
    uint256 amountOutMin;
    uint256 deadline;
}

/**
 * @notice Auxiliary struct containing parameters for `_executeSwaps`.
 *     @dev Required in order to bypass stack-too-deep errors.
 */
struct ExecuteSwapParams {
    bool[] isUniversalPool;
    address[] pools;
    uint256[] amountInSpecified;
    bytes[] payloads;
    address tokenIn;
    address tokenOut;
    address owner;
    uint256 deadline;
}

/**
 * @notice Internal struct used for single swap payloads in Universal pools.
 */
struct UniversalPoolSwapPayload {
    bool isZeroToOne;
    address recipient;
    int24 limitPriceTick;
    uint256 amountOutMin;
    uint8[] almOrdering;
    bytes[] externalContext;
    bytes swapFeeModuleContext;
}

/**
 * @notice Internal struct used for single swap payloads in Sovereign pools.
 */
struct SovereignPoolSwapPayload {
    bool isZeroToOne;
    address recipient;
    address swapTokenOut;
    uint256 amountOutMin;
    bytes externalContext;
    bytes verificationContext;
    bytes swapFeeModuleContext;
}

Settings
{
  "evmVersion": "paris",
  "libraries": {},
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "enabled": true,
    "runs": 20000
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "@permit2/=lib/permit2/",
    "@solmate/=lib/solmate/",
    "@valantis-core/=lib/valantis-core/",
    "ds-test/=lib/solmate/lib/ds-test/src/",
    "erc4626-tests/=lib/valantis-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
    "openzeppelin-contracts/=lib/valantis-core/lib/openzeppelin-contracts/",
    "openzeppelin/=lib/valantis-core/lib/openzeppelin-contracts/contracts/",
    "permit2/=lib/permit2/",
    "solmate/=lib/solmate/src/",
    "valantis-core/=lib/valantis-core/src/"
  ],
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"protocolFactory_","type":"address"},{"internalType":"address","name":"_weth9","type":"address"},{"internalType":"address","name":"permit2_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DirectSwap__checkDirectSwapParams_arrayLengthMismatch","type":"error"},{"inputs":[],"name":"DirectSwap__checkDirectSwapParams_equalTokenInAndTokenOut","type":"error"},{"inputs":[],"name":"DirectSwap__checkDirectSwapParams_incorrectNativeTokenAmountIn","type":"error"},{"inputs":[],"name":"DirectSwap__checkDirectSwapParams_invalidArrayLength","type":"error"},{"inputs":[],"name":"DirectSwap__checkDirectSwapParams_invalidDeadline","type":"error"},{"inputs":[],"name":"GaslessSwap__checkGaslessSwapParams_arrayLengthMismatch","type":"error"},{"inputs":[],"name":"GaslessSwap__checkGaslessSwapParams_equalTokenInAndTokenOut","type":"error"},{"inputs":[],"name":"GaslessSwap__checkGaslessSwapParams_invalidAmountInSpecifiedArray","type":"error"},{"inputs":[],"name":"GaslessSwap__checkGaslessSwapParams_invalidArrayLength","type":"error"},{"inputs":[],"name":"GaslessSwap__checkGaslessSwapParams_invalidDeadline","type":"error"},{"inputs":[],"name":"GaslessSwap__checkGaslessSwapParams_senderNotAuthorized","type":"error"},{"inputs":[],"name":"InvalidContractSignature","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidSignatureLength","type":"error"},{"inputs":[],"name":"InvalidSigner","type":"error"},{"inputs":[],"name":"NonceBitmap__consumeNonce_InvalidNonce","type":"error"},{"inputs":[],"name":"ValantisSwapRouter___executeGaslessSwap_excessiveFee","type":"error"},{"inputs":[],"name":"ValantisSwapRouter___executeSingleSwapSovereignPool_invalidSovereignPool","type":"error"},{"inputs":[],"name":"ValantisSwapRouter___executeSingleSwapUniversalPool_invalidUniversalPool","type":"error"},{"inputs":[],"name":"ValantisSwapRouter___executeSwaps_invalidAmountSpecifiedFirstSwap","type":"error"},{"inputs":[],"name":"ValantisSwapRouter___gaslessSwap_insufficientAmountOut","type":"error"},{"inputs":[],"name":"ValantisSwapRouter___gaslessSwap_tokenOutNotWeth","type":"error"},{"inputs":[],"name":"ValantisSwapRouter___sendNativeToken_ethTransferFailed","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__batchGaslessSwaps_invalidArrayLengths","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__receive_onlyWeth","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__sovereignPoolSwapCallback_invalidTokenIn","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__sovereignPoolSwapCallback_poolNotAllowed","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__swap_insufficientAmountOut","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__swap_invalidNativeTokenSwap","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__swap_tokenOutNotWeth","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__sweep_invalidRecipient","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__sweep_invalidTokenAddress","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__sweep_invalidTokensArrayLength","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__universalPoolSwapCallback_invalidTokenIn","type":"error"},{"inputs":[],"name":"ValantisSwapRouter__universalPoolSwapCallback_poolNotAllowed","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":false,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isTokenInEth","type":"bool"},{"indexed":false,"internalType":"bool","name":"isTokenOutEth","type":"bool"}],"name":"DirectSwapLog","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"solver","type":"address"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":false,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isTokenOutEth","type":"bool"}],"name":"GaslessSwapLog","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowedSovereignPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowedUniversalPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bool[]","name":"isUniversalPool","type":"bool[]"},{"internalType":"address[]","name":"pools","type":"address[]"},{"internalType":"uint256[]","name":"amountInSpecified","type":"uint256[]"},{"internalType":"bytes[]","name":"payloads","type":"bytes[]"},{"components":[{"internalType":"bool","name":"isTokenOutEth","type":"bool"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"authorizedSender","type":"address"},{"internalType":"address","name":"feeToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint128","name":"maxFee","type":"uint128"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct GaslessSwapIntent","name":"intent","type":"tuple"}],"internalType":"struct GaslessSwapParams[]","name":"_gaslessSwapParamsArray","type":"tuple[]"},{"internalType":"bytes[]","name":"_ownerSignaturesArray","type":"bytes[]"},{"internalType":"uint128[]","name":"_feeArray","type":"uint128[]"}],"name":"batchGaslessSwaps","outputs":[{"internalType":"uint256[]","name":"amountOutArray","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool[]","name":"isUniversalPool","type":"bool[]"},{"internalType":"address[]","name":"pools","type":"address[]"},{"internalType":"uint256[]","name":"amountInSpecified","type":"uint256[]"},{"internalType":"bytes[]","name":"payloads","type":"bytes[]"},{"components":[{"internalType":"bool","name":"isTokenOutEth","type":"bool"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"authorizedSender","type":"address"},{"internalType":"address","name":"feeToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint128","name":"maxFee","type":"uint128"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct GaslessSwapIntent","name":"intent","type":"tuple"}],"internalType":"struct GaslessSwapParams","name":"_gaslessSwapParams","type":"tuple"},{"internalType":"bytes","name":"_ownerSignature","type":"bytes"},{"internalType":"uint128","name":"_fee","type":"uint128"}],"name":"gaslessSwap","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isLocked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"nonceBitmap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenIn","type":"address"},{"internalType":"uint256","name":"_amountInUsed","type":"uint256"},{"internalType":"bytes","name":"_swapCallbackContext","type":"bytes"}],"name":"sovereignPoolSwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool[]","name":"isUniversalPool","type":"bool[]"},{"internalType":"address[]","name":"pools","type":"address[]"},{"internalType":"uint256[]","name":"amountInSpecified","type":"uint256[]"},{"internalType":"bytes[]","name":"payloads","type":"bytes[]"},{"internalType":"bool","name":"isTokenOutEth","type":"bool"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct DirectSwapParams","name":"_directSwapParams","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokens","type":"address[]"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenIn","type":"address"},{"internalType":"uint256","name":"_amountInUsed","type":"uint256"},{"internalType":"bytes","name":"_swapCallbackContext","type":"bytes"}],"name":"universalPoolSwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

6101206040523480156200001257600080fd5b506040516200428f3803806200428f83398101604081905262000035916200011c565b4660a0818152604080517f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a8666020808301919091527f6794a53fcf09e99d9d74f0c68fae6aeaf87f61f3080249d20898bb8c957f3e538284015260608201949094523060808083019190915282518083039091018152920190528051910120608052600160008190556001600160a01b039384166101005291831660c05290911660e052600280546001600160a01b0319908116831790915560038054909116909117905562000166565b80516001600160a01b03811681146200011757600080fd5b919050565b6000806000606084860312156200013257600080fd5b6200013d84620000ff565b92506200014d60208501620000ff565b91506200015d60408501620000ff565b90509250925092565b60805160a05160c05160e0516101005161408a620002056000396000818161035b0152818161227101526124ce01526000818161015e015281816115e10152611f9301526000818160f10152818161025d0152818161097801528181610a0c01528181610e380152818161101f015281816112df0152818161144b01528181611491015261153f015260006105a40152600061061b015261408a6000f3fe6080604052600436106100e15760003560e01c80634fe02b441161007f578063c370530911610059578063c3705309146102f9578063d20c88bd14610319578063ea18d8d514610339578063f489048a1461034c57600080fd5b80634fe02b441461027f5780639fbd86ad146102b7578063a4e2d634146102d757600080fd5b80633315ac9b116100bb5780633315ac9b146101e8578063340dffab146102085780633644e515146102285780634aa4a4fc1461024b57600080fd5b806312261ee71461014f57806318dcb77b1461019b57806319e9ca22146101bb57600080fd5b3661014a57336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610148576040517f753ceebb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b005b600080fd5b34801561015b57600080fd5b507f00000000000000000000000000000000000000000000000000000000000000005b6040516001600160a01b0390911681526020015b60405180910390f35b3480156101a757600080fd5b5060035461017e906001600160a01b031681565b3480156101c757600080fd5b506101db6101d636600461301e565b61037f565b60405161019291906130b8565b3480156101f457600080fd5b5060025461017e906001600160a01b031681565b34801561021457600080fd5b50610148610223366004613161565b6104d2565b34801561023457600080fd5b5061023d6105a0565b604051908152602001610192565b34801561025757600080fd5b5061017e7f000000000000000000000000000000000000000000000000000000000000000081565b34801561028b57600080fd5b5061023d61029a3660046131bd565b600160209081526000928352604080842090915290825290205481565b3480156102c357600080fd5b506101486102d2366004613161565b61063d565b3480156102e357600080fd5b5060005460405160029091148152602001610192565b34801561030557600080fd5b5061023d610314366004613209565b610772565b34801561032557600080fd5b50610148610334366004613358565b61079c565b61023d610347366004613409565b610959565b34801561035857600080fd5b507f000000000000000000000000000000000000000000000000000000000000000061017e565b6060610389610f84565b85841415806103985750838214155b156103cf576040517f1160587700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b858067ffffffffffffffff8111156103e9576103e961328d565b604051908082528060200260200182016040528015610412578160200160208202803683370190505b50915060005b818110156104bc576104978989838181106104355761043561344c565b9050602002810190610447919061347b565b8888848181106104595761045961344c565b905060200281019061046b91906134b9565b88888681811061047d5761047d61344c565b9050602002016020810190610492919061351e565b610ffc565b8382815181106104a9576104a961344c565b6020908102919091010152600101610418565b50506104c86001600055565b9695505050505050565b6002546001600160a01b03163314610516576040517fc923fbd700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008061052583850185613539565b90925090506001600160a01b03811630148015906105555750856001600160a01b0316826001600160a01b031614155b1561058c576040517f76f7658d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61059886823388611449565b505050505050565b60007f00000000000000000000000000000000000000000000000000000000000000004614610618576106137f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a8667f6794a53fcf09e99d9d74f0c68fae6aeaf87f61f3080249d20898bb8c957f3e536116a8565b905090565b507f000000000000000000000000000000000000000000000000000000000000000090565b6003546001600160a01b03163314610681576040517fdd45deef00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008061069083850185613539565b90925090506001600160a01b03811630148015906106c05750856001600160a01b0316826001600160a01b031614155b156106f7576040517f1fddbbd400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000336001600160a01b031663baad44eb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610737573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075b919061357d565b905061076987838389611449565b50505050505050565b600061077c610f84565b61078885858585610ffc565b90506107946001600055565b949350505050565b6107a4610f84565b81516000036107df576040517fb3d4d1db00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03811661081f576040517f0ab36d2900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b825181101561094a57600083828151811061083f5761083f61344c565b6020026020010151905060006001600160a01b0316816001600160a01b031603610895576040517f07502a9100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156108f5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610919919061359a565b90508015610935576109356001600160a01b03831685836116ea565b50508080610942906135e2565b915050610822565b506109556001600055565b5050565b6000610963610f84565b6000341180156109b457506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166109a860c0840160a0850161361a565b6001600160a01b031614155b156109eb576040517f9c81312d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109fb60a0830160808401613650565b8015610a4857506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016610a3c60e0840160c0850161361a565b6001600160a01b031614155b15610a7f576040517f2689b94f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a89823461176f565b6000610a9b60e0840160c0850161361a565b6001600160a01b03166370a08231610ab960a0860160808701613650565b610ad357610ace610100860160e0870161361a565b610ad5565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610b31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b55919061359a565b9050600080610ca5604051806101000160405280878060000190610b79919061366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602090810190610bbf9089018961366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001610c03604089018961366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001610c47606089018961366d565b610c509161371b565b8152602001610c6560c0890160a08a0161361a565b6001600160a01b03168152602001610c8360e0890160c08a0161361a565b6001600160a01b03168152336020820152610120880135604090910152611991565b909250905082610cbb60e0870160c0880161361a565b6001600160a01b03166370a08231610cd960a0890160808a01613650565b610cf357610cee610100890160e08a0161361a565b610cf5565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d75919061359a565b610d7f91906137cb565b9350846101000135841080610d98575084610100013581105b15610dcf576040517f7fb6ed1900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3415610df457610def610de9610100870160e0880161361a565b47611c90565b610eb8565b610e0460a0860160808701613650565b15610eb8576040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015610e8457600080fd5b505af1158015610e98573d6000803e3d6000fd5b50610eb89250610eb2915050610100870160e0880161361a565b85611c90565b7feed67591fd6d29a115c34e918efec3891cd94eb1b82c66ecfd8ed0d422d15c4933610eeb610100880160e0890161361a565b610efb60c0890160a08a0161361a565b610f0b60e08a0160c08b0161361a565b8689341515610f2060a08e0160808f01613650565b604080516001600160a01b03998a168152978916602089015295881695870195909552959092166060850152608084015260a083015291151560c082015290151560e08201526101000160405180910390a1505050610f7f6001600055565b919050565b600260005403610ff5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064015b60405180910390fd5b6002600055565b600061100e60a0860160808701613650565b801561105b57506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001661104f60e0870160c0880161361a565b6001600160a01b031614155b15611092576040517f9d38d4fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006110a460e0870160c0880161361a565b6001600160a01b03166370a082316110c260a0890160808a01613650565b6110dd576110d861012089016101008a0161361a565b6110df565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561113b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115f919061359a565b905060008061117088888888611d23565b90925090508261118660e08a0160c08b0161361a565b6001600160a01b03166370a082316111a460a08c0160808d01613650565b6111bf576111ba6101208c016101008d0161361a565b6111c1565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561121d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611241919061359a565b61124b91906137cb565b9350610180880135841080611264575061018088013581105b1561129b576040517fa4ed23c600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6112ab60a0890160808a01613650565b1561135a576040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561132b57600080fd5b505af115801561133f573d6000803e3d6000fd5b5061135a9250610eb29150506101208a016101008b0161361a565b7fe06490c1ee6e6c082db362f38ed400dab1759def892a48e10c4ebb0ca8f348c161138c6101008a0160e08b0161361a565b61139e6101408b016101208c0161361a565b6113b06101208c016101008d0161361a565b6113c060c08d0160a08e0161361a565b6113d060e08e0160c08f0161361a565b878a8f60800160000160208101906113e89190613650565b604080516001600160a01b03998a16815297891660208901529588169587019590955292861660608601529416608084015260a083019390935260c082019290925290151560e08201526101000160405180910390a1505050949350505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614801561148a5750804710155b156115b6577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156114ea57600080fd5b505af11580156114fe573d6000803e3d6000fd5b50506040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038681166004830152602482018690527f000000000000000000000000000000000000000000000000000000000000000016935063a9059cbb925060440190506020604051808303816000875af115801561158c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115b091906137e9565b506116a2565b306001600160a01b038416036115df576115da6001600160a01b03851683836116ea565b6116a2565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166336c78516848461161985612093565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b0393841660048201529183166024830152821660448201529087166064820152608401600060405180830381600087803b15801561168957600080fd5b505af115801561169d573d6000803e3d6000fd5b505050505b50505050565b604080516020810184905290810182905246606082015230608082015260009060a0016040516020818303038152906040528051906020012090505b92915050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb0000000000000000000000000000000000000000000000000000000017905261176a908490612130565b505050565b8161012001354211156117ae576040517f95595b7b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6117b8828061366d565b90506000036117f3576040517fd59b3f9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611800602083018361366d565b905061180c838061366d565b90501415806118375750611823604083018361366d565b9050611832602084018461366d565b905014155b8061185e575061184a606083018361366d565b9050611859604084018461366d565b905014155b15611895576040517fc7ea213d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6118a560e0830160c0840161361a565b6001600160a01b03166118be60c0840160a0850161361a565b6001600160a01b0316036118fe576040517f200bb78000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8015610955576000805b611915604085018561366d565b90508110156119575761192b604085018561366d565b8281811061193b5761193b61344c565b905060200201358261194d9190613806565b9150600101611908565b5081811461176a576040517fa7459f3300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080600083604001516000815181106119ad576119ad61344c565b60200260200101516000036119ee576040517f34cbfb2f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b846020015151811015611c895760008086600001518381518110611a1757611a1761344c565b6020026020010151611b1f57611b1a600088604001518581518110611a3e57611a3e61344c565b602002602001015111611a515784611a70565b87604001518481518110611a6757611a6761344c565b60200260200101515b8860e0015189602001518681518110611a8b57611a8b61344c565b60200260200101518a6080015160008c604001518981518110611ab057611ab061344c565b602002602001015111611ac35730611ac9565b8b60c001515b604080516001600160a01b03938416602082015292909116908201526060016040516020818303038152906040528b606001518881518110611b0d57611b0d61344c565b6020026020010151612232565b611c16565b611c16600088604001518581518110611b3a57611b3a61344c565b602002602001015111611b4d5784611b6c565b87604001518481518110611b6357611b6361344c565b60200260200101515b8860e0015189602001518681518110611b8757611b8761344c565b60200260200101518a6080015160008c604001518981518110611bac57611bac61344c565b602002602001015111611bbf5730611bc5565b8b60c001515b604080516001600160a01b03938416602082015292909116908201526060016040516020818303038152906040528b606001518881518110611c0957611c0961344c565b602002602001015161248f565b809650819350829450505050600087604001518481518110611c3a57611c3a61344c565b60200260200101511115611c5557611c528287613806565b95505b8660a001516001600160a01b0316816001600160a01b031603611c7f57611c7c8486613806565b94505b50506001016119f1565b5050915091565b8015610955576000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611ce3576040519150601f19603f3d011682016040523d82523d6000602084013e611ce8565b606091505b505090508061176a576040517f351e6d4500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080611d2f866127a6565b611d416101c087016101a0880161351e565b6fffffffffffffffffffffffffffffffff16836fffffffffffffffffffffffffffffffff161115611d9e576040517fe483256400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611ddb6101c087013560016000611dbc6101008b0160e08c0161361a565b6001600160a01b03168152602081019190915260400160002090612a28565b611e0c611df2611ded88608001612a8c565b612ade565b611e03610100890160e08a0161361a565b87918791612b28565b604080516101008101909152611f6c9080611e27898061366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602090810190611e6d908a018a61366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001611eb160408a018a61366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001611ef560608a018a61366d565b611efe9161371b565b8152602001611f1360c08a0160a08b0161361a565b6001600160a01b03168152602001611f3160e08a0160c08b0161361a565b6001600160a01b03168152602001611f506101008a0160e08b0161361a565b6001600160a01b031681526101e0890135602090910152611991565b90925090506fffffffffffffffffffffffffffffffff83161561208a576001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166336c78516611fc9610100890160e08a0161361a565b611fdb6101408a016101208b0161361a565b6fffffffffffffffffffffffffffffffff87166120006101608c016101408d0161361a565b60405160e086901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b039485166004820152928416602484015290831660448301529091166064820152608401600060405180830381600087803b15801561207157600080fd5b505af1158015612085573d6000803e3d6000fd5b505050505b94509492505050565b60006001600160a01b0382111561212c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201527f36302062697473000000000000000000000000000000000000000000000000006064820152608401610fec565b5090565b6000612185826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612e7b9092919063ffffffff16565b90508051600014806121a65750808060200190518101906121a691906137e9565b61176a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610fec565b6040517ffc4328520000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152600091829182917f00000000000000000000000000000000000000000000000000000000000000009091169063fc43285290602401602060405180830381865afa1580156122ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122de91906137e9565b612314576040517fd85d90e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008480602001905181019061232a9190613882565b905086600360006101000a8154816001600160a01b0302191690836001600160a01b03160217905550866001600160a01b031663373290096040518061010001604052806001151581526020018460000151151581526020018c8152602001846060015181526020018b815260200184602001516001600160a01b0316815260200184604001516001600160a01b031681526020016040518060800160405280866080015181526020018660a0015181526020018b81526020018660c001518152508152506040518263ffffffff1660e01b815260040161240b9190613a29565b60408051808303816000875af1158015612429573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061244d9190613aac565b604090920151600380547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001179055909a90995090975095505050505050565b6040517f9416b8f30000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152600091829182917f000000000000000000000000000000000000000000000000000000000000000090911690639416b8f390602401602060405180830381865afa158015612517573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061253b91906137e9565b612571576040517fcb05115a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000848060200190518101906125879190613bd8565b905086600260006101000a8154816001600160a01b0302191690836001600160a01b03160217905550866001600160a01b031663a50f6e8a604051806101600160405280846000015115158152602001600115158152602001846040015160020b815260200184602001516001600160a01b031681526020018c8152602001846060015181526020018b81526020018981526020018460c001518152602001846080015181526020018460a001518152506040518263ffffffff1660e01b81526004016126549190613d2a565b60408051808303816000875af1158015612672573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126969190613aac565b8251919550925061270857866001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156126df573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612703919061357d565b61276a565b866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612746573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061276a919061357d565b600280547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001179055939993985090965091945050505050565b6101e08101354211156127e5576040517f8d739acd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6127ef818061366d565b905060000361282a576040517f5efa59fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612837602082018261366d565b9050612843828061366d565b905014158061286e575061285a604082018261366d565b9050612869602083018361366d565b905014155b806128955750612881606082018261366d565b9050612890604083018361366d565b905014155b156128cc576040517f21bb7dcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6128dc60e0820160c0830161361a565b6001600160a01b03166128f560c0830160a0840161361a565b6001600160a01b031603612935576040517f9f0ecb6e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080612945604084018461366d565b9050905060005b8181101561298d57612961604085018561366d565b828181106129715761297161344c565b90506020020135836129839190613806565b925060010161294c565b5061016083013582146129cc576040517f5328f79300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6129de6101408401610120850161361a565b6001600160a01b0316336001600160a01b03161461176a576040517f80bd2ef400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600881901c60008181526020849052604081208054600160ff861690811b91821892839055929091908183169003610598576040517f0838650000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60007f8c911b939d917e4764db40337f23e2ac4fbfa3823f1a03481437cf6aa20fb38582604051602001612ac1929190613e33565b604051602081830303815290604052805190602001209050919050565b6000612ae86105a0565b6040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281019190915260428101839052606201612ac1565b6000806000836001600160a01b03163b600003612d71576041869003612b7d57612b5486880188613f5e565b909350915086866040818110612b6c57612b6c61344c565b919091013560f81c9150612c079050565b6040869003612bd5576000612b9487890189613f5e565b9094507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811693509050612bcd60ff82901c601b613f80565b915050612c07565b6040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115612c61576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160008082526020820180845288905260ff841692820192909252606081018590526080810184905260019060a0016020604051602081039080840390855afa158015612cb5573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150506001600160a01b038116612d20576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b846001600160a01b0316816001600160a01b031614612d6b576040517f815e1d6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50610769565b6040517f1626ba7e0000000000000000000000000000000000000000000000000000000081526000906001600160a01b03861690631626ba7e90612dbd9089908c908c90600401613f99565b602060405180830381865afa158015612dda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dfe9190613fed565b90507fffffffff0000000000000000000000000000000000000000000000000000000081167f1626ba7e000000000000000000000000000000000000000000000000000000001461169d576040517fb0669cbc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060610794848460008585600080866001600160a01b03168587604051612ea2919061402f565b60006040518083038185875af1925050503d8060008114612edf576040519150601f19603f3d011682016040523d82523d6000602084013e612ee4565b606091505b5091509150612ef587838387612f00565b979650505050505050565b60608315612f89578251600003612f82576001600160a01b0385163b612f82576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610fec565b5081610794565b6107948383815115612f9e5781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fec9190614041565b60008083601f840112612fe457600080fd5b50813567ffffffffffffffff811115612ffc57600080fd5b6020830191508360208260051b850101111561301757600080fd5b9250929050565b6000806000806000806060878903121561303757600080fd5b863567ffffffffffffffff8082111561304f57600080fd5b61305b8a838b01612fd2565b9098509650602089013591508082111561307457600080fd5b6130808a838b01612fd2565b9096509450604089013591508082111561309957600080fd5b506130a689828a01612fd2565b979a9699509497509295939492505050565b6020808252825182820181905260009190848201906040850190845b818110156130f0578351835292840192918401916001016130d4565b50909695505050505050565b6001600160a01b038116811461311157600080fd5b50565b8035610f7f816130fc565b60008083601f84011261313157600080fd5b50813567ffffffffffffffff81111561314957600080fd5b60208301915083602082850101111561301757600080fd5b6000806000806060858703121561317757600080fd5b8435613182816130fc565b935060208501359250604085013567ffffffffffffffff8111156131a557600080fd5b6131b18782880161311f565b95989497509550505050565b600080604083850312156131d057600080fd5b82356131db816130fc565b946020939093013593505050565b80356fffffffffffffffffffffffffffffffff81168114610f7f57600080fd5b6000806000806060858703121561321f57600080fd5b843567ffffffffffffffff8082111561323757600080fd5b90860190610200828903121561324c57600080fd5b9094506020860135908082111561326257600080fd5b5061326f8782880161311f565b90945092506132829050604086016131e9565b905092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405160e0810167ffffffffffffffff811182821017156132df576132df61328d565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff8111828210171561332c5761332c61328d565b604052919050565b600067ffffffffffffffff82111561334e5761334e61328d565b5060051b60200190565b6000806040838503121561336b57600080fd5b823567ffffffffffffffff81111561338257600080fd5b8301601f8101851361339357600080fd5b803560206133a86133a383613334565b6132e5565b82815260059290921b830181019181810190888411156133c757600080fd5b938201935b838510156133ee5784356133df816130fc565b825293820193908201906133cc565b95506133fd9050868201613114565b93505050509250929050565b60006020828403121561341b57600080fd5b813567ffffffffffffffff81111561343257600080fd5b8201610140818503121561344557600080fd5b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe018336030181126134af57600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126134ee57600080fd5b83018035915067ffffffffffffffff82111561350957600080fd5b60200191503681900382131561301757600080fd5b60006020828403121561353057600080fd5b613445826131e9565b6000806040838503121561354c57600080fd5b8235613557816130fc565b91506020830135613567816130fc565b809150509250929050565b8051610f7f816130fc565b60006020828403121561358f57600080fd5b8151613445816130fc565b6000602082840312156135ac57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203613613576136136135b3565b5060010190565b60006020828403121561362c57600080fd5b8135613445816130fc565b801515811461311157600080fd5b8035610f7f81613637565b60006020828403121561366257600080fd5b813561344581613637565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126136a257600080fd5b83018035915067ffffffffffffffff8211156136bd57600080fd5b6020019150600581901b360382131561301757600080fd5b600067ffffffffffffffff8211156136ef576136ef61328d565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b60006137296133a384613334565b80848252602080830192508560051b85013681111561374757600080fd5b855b818110156137bf57803567ffffffffffffffff8111156137695760008081fd5b870136601f82011261377b5760008081fd5b80356137896133a3826136d5565b818152368683850101111561379e5760008081fd5b81868401878301376000918101860191909152865250938201938201613749565b50919695505050505050565b818103818111156116e4576116e46135b3565b8051610f7f81613637565b6000602082840312156137fb57600080fd5b815161344581613637565b808201808211156116e4576116e46135b3565b60005b8381101561383457818101518382015260200161381c565b50506000910152565b600082601f83011261384e57600080fd5b815161385c6133a3826136d5565b81815284602083860101111561387157600080fd5b610794826020830160208701613819565b60006020828403121561389457600080fd5b815167ffffffffffffffff808211156138ac57600080fd5b9083019060e082860312156138c057600080fd5b6138c86132bc565b6138d1836137de565b81526138df60208401613572565b60208201526138f060408401613572565b60408201526060830151606082015260808301518281111561391157600080fd5b61391d8782860161383d565b60808301525060a08301518281111561393557600080fd5b6139418782860161383d565b60a08301525060c08301518281111561395957600080fd5b6139658782860161383d565b60c08301525095945050505050565b6000815180845261398c816020860160208601613819565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60008151608084526139d36080850182613974565b9050602083015184820360208601526139ec8282613974565b91505060408301518482036040860152613a068282613974565b91505060608301518482036060860152613a208282613974565b95945050505050565b602081528151151560208201526020820151151560408201526040820151606082015260608201516080820152608082015160a0820152600060a0830151613a7c60c08401826001600160a01b03169052565b5060c08301516001600160a01b03811660e08401525060e0830151610100838101526107946101208401826139be565b60008060408385031215613abf57600080fd5b505080516020909101519092909150565b8051600281900b8114610f7f57600080fd5b600082601f830112613af357600080fd5b81516020613b036133a383613334565b82815260059290921b84018101918181019086841115613b2257600080fd5b8286015b84811015613b4d57805160ff81168114613b405760008081fd5b8352918301918301613b26565b509695505050505050565b600082601f830112613b6957600080fd5b81516020613b796133a383613334565b82815260059290921b84018101918181019086841115613b9857600080fd5b8286015b84811015613b4d57805167ffffffffffffffff811115613bbc5760008081fd5b613bca8986838b010161383d565b845250918301918301613b9c565b600060208284031215613bea57600080fd5b815167ffffffffffffffff80821115613c0257600080fd5b9083019060e08286031215613c1657600080fd5b613c1e6132bc565b613c27836137de565b8152613c3560208401613572565b6020820152613c4660408401613ad0565b604082015260608301516060820152608083015182811115613c6757600080fd5b613c7387828601613ae2565b60808301525060a083015182811115613c8b57600080fd5b61394187828601613b58565b600081518084526020808501945080840160005b83811015613cca57815160ff1687529582019590820190600101613cab565b509495945050505050565b600081518084526020808501808196508360051b8101915082860160005b85811015613d1d578284038952613d0b848351613974565b98850198935090840190600101613cf3565b5091979650505050505050565b60208152613d3d60208201835115159052565b60006020830151613d52604084018215159052565b506040830151613d67606084018260020b9052565b5060608301516001600160a01b038116608084015250608083015160a083015260a083015160c083015260c083015160e083015260e08301516101606101008181860152613db9610180860184613974565b92508086015190507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610120818786030181880152613df88584613974565b945080880151925050610140818786030181880152613e178584613c97565b9088015187820390920184880152935090506104c88382613cd5565b8281526101a08101613e5160208301613e4b85613645565b15159052565b613e5d60208401613114565b6001600160a01b038116604084015250613e7960408401613114565b6001600160a01b038116606084015250613e9560608401613114565b6001600160a01b038116608084015250613eb160808401613114565b6001600160a01b03811660a084015250613ecd60a08401613114565b6001600160a01b03811660c084015250613ee960c08401613114565b6001600160a01b03811660e08401525061010060e0840135818401526101208185013581850152613f1b8186016131e9565b915050610140613f3e818501836fffffffffffffffffffffffffffffffff169052565b610160915080850135828501525080840135610180840152509392505050565b60008060408385031215613f7157600080fd5b50508035926020909101359150565b60ff81811683821601908111156116e4576116e46135b3565b83815260406020820152816040820152818360608301376000818301606090810191909152601f9092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016010192915050565b600060208284031215613fff57600080fd5b81517fffffffff000000000000000000000000000000000000000000000000000000008116811461344557600080fd5b600082516134af818460208701613819565b602081526000613445602083018461397456fea2646970667358221220c875d372eed306dc1c122dc4635a310d9c929b86b4114d8d0a1102bf1952beee64736f6c634300081300330000000000000000000000007e028ac56cb2af75292f3d967978189698c247320000000000000000000000005555555555555555555555555555555555555555000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3

Deployed Bytecode

0x6080604052600436106100e15760003560e01c80634fe02b441161007f578063c370530911610059578063c3705309146102f9578063d20c88bd14610319578063ea18d8d514610339578063f489048a1461034c57600080fd5b80634fe02b441461027f5780639fbd86ad146102b7578063a4e2d634146102d757600080fd5b80633315ac9b116100bb5780633315ac9b146101e8578063340dffab146102085780633644e515146102285780634aa4a4fc1461024b57600080fd5b806312261ee71461014f57806318dcb77b1461019b57806319e9ca22146101bb57600080fd5b3661014a57336001600160a01b037f00000000000000000000000055555555555555555555555555555555555555551614610148576040517f753ceebb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b005b600080fd5b34801561015b57600080fd5b507f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba35b6040516001600160a01b0390911681526020015b60405180910390f35b3480156101a757600080fd5b5060035461017e906001600160a01b031681565b3480156101c757600080fd5b506101db6101d636600461301e565b61037f565b60405161019291906130b8565b3480156101f457600080fd5b5060025461017e906001600160a01b031681565b34801561021457600080fd5b50610148610223366004613161565b6104d2565b34801561023457600080fd5b5061023d6105a0565b604051908152602001610192565b34801561025757600080fd5b5061017e7f000000000000000000000000555555555555555555555555555555555555555581565b34801561028b57600080fd5b5061023d61029a3660046131bd565b600160209081526000928352604080842090915290825290205481565b3480156102c357600080fd5b506101486102d2366004613161565b61063d565b3480156102e357600080fd5b5060005460405160029091148152602001610192565b34801561030557600080fd5b5061023d610314366004613209565b610772565b34801561032557600080fd5b50610148610334366004613358565b61079c565b61023d610347366004613409565b610959565b34801561035857600080fd5b507f0000000000000000000000007e028ac56cb2af75292f3d967978189698c2473261017e565b6060610389610f84565b85841415806103985750838214155b156103cf576040517f1160587700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b858067ffffffffffffffff8111156103e9576103e961328d565b604051908082528060200260200182016040528015610412578160200160208202803683370190505b50915060005b818110156104bc576104978989838181106104355761043561344c565b9050602002810190610447919061347b565b8888848181106104595761045961344c565b905060200281019061046b91906134b9565b88888681811061047d5761047d61344c565b9050602002016020810190610492919061351e565b610ffc565b8382815181106104a9576104a961344c565b6020908102919091010152600101610418565b50506104c86001600055565b9695505050505050565b6002546001600160a01b03163314610516576040517fc923fbd700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008061052583850185613539565b90925090506001600160a01b03811630148015906105555750856001600160a01b0316826001600160a01b031614155b1561058c576040517f76f7658d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61059886823388611449565b505050505050565b60007f00000000000000000000000000000000000000000000000000000000000003e74614610618576106137f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a8667f6794a53fcf09e99d9d74f0c68fae6aeaf87f61f3080249d20898bb8c957f3e536116a8565b905090565b507f6b4f478cb52798356dc7c774a7e29e3fa928ba85e7ec14edaf56395d9a03a92890565b6003546001600160a01b03163314610681576040517fdd45deef00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008061069083850185613539565b90925090506001600160a01b03811630148015906106c05750856001600160a01b0316826001600160a01b031614155b156106f7576040517f1fddbbd400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000336001600160a01b031663baad44eb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610737573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075b919061357d565b905061076987838389611449565b50505050505050565b600061077c610f84565b61078885858585610ffc565b90506107946001600055565b949350505050565b6107a4610f84565b81516000036107df576040517fb3d4d1db00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03811661081f576040517f0ab36d2900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b825181101561094a57600083828151811061083f5761083f61344c565b6020026020010151905060006001600160a01b0316816001600160a01b031603610895576040517f07502a9100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156108f5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610919919061359a565b90508015610935576109356001600160a01b03831685836116ea565b50508080610942906135e2565b915050610822565b506109556001600055565b5050565b6000610963610f84565b6000341180156109b457506001600160a01b037f0000000000000000000000005555555555555555555555555555555555555555166109a860c0840160a0850161361a565b6001600160a01b031614155b156109eb576040517f9c81312d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109fb60a0830160808401613650565b8015610a4857506001600160a01b037f000000000000000000000000555555555555555555555555555555555555555516610a3c60e0840160c0850161361a565b6001600160a01b031614155b15610a7f576040517f2689b94f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a89823461176f565b6000610a9b60e0840160c0850161361a565b6001600160a01b03166370a08231610ab960a0860160808701613650565b610ad357610ace610100860160e0870161361a565b610ad5565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610b31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b55919061359a565b9050600080610ca5604051806101000160405280878060000190610b79919061366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602090810190610bbf9089018961366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001610c03604089018961366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001610c47606089018961366d565b610c509161371b565b8152602001610c6560c0890160a08a0161361a565b6001600160a01b03168152602001610c8360e0890160c08a0161361a565b6001600160a01b03168152336020820152610120880135604090910152611991565b909250905082610cbb60e0870160c0880161361a565b6001600160a01b03166370a08231610cd960a0890160808a01613650565b610cf357610cee610100890160e08a0161361a565b610cf5565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d75919061359a565b610d7f91906137cb565b9350846101000135841080610d98575084610100013581105b15610dcf576040517f7fb6ed1900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3415610df457610def610de9610100870160e0880161361a565b47611c90565b610eb8565b610e0460a0860160808701613650565b15610eb8576040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018590527f00000000000000000000000055555555555555555555555555555555555555556001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015610e8457600080fd5b505af1158015610e98573d6000803e3d6000fd5b50610eb89250610eb2915050610100870160e0880161361a565b85611c90565b7feed67591fd6d29a115c34e918efec3891cd94eb1b82c66ecfd8ed0d422d15c4933610eeb610100880160e0890161361a565b610efb60c0890160a08a0161361a565b610f0b60e08a0160c08b0161361a565b8689341515610f2060a08e0160808f01613650565b604080516001600160a01b03998a168152978916602089015295881695870195909552959092166060850152608084015260a083015291151560c082015290151560e08201526101000160405180910390a1505050610f7f6001600055565b919050565b600260005403610ff5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064015b60405180910390fd5b6002600055565b600061100e60a0860160808701613650565b801561105b57506001600160a01b037f00000000000000000000000055555555555555555555555555555555555555551661104f60e0870160c0880161361a565b6001600160a01b031614155b15611092576040517f9d38d4fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006110a460e0870160c0880161361a565b6001600160a01b03166370a082316110c260a0890160808a01613650565b6110dd576110d861012089016101008a0161361a565b6110df565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561113b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115f919061359a565b905060008061117088888888611d23565b90925090508261118660e08a0160c08b0161361a565b6001600160a01b03166370a082316111a460a08c0160808d01613650565b6111bf576111ba6101208c016101008d0161361a565b6111c1565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561121d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611241919061359a565b61124b91906137cb565b9350610180880135841080611264575061018088013581105b1561129b576040517fa4ed23c600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6112ab60a0890160808a01613650565b1561135a576040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018590527f00000000000000000000000055555555555555555555555555555555555555556001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561132b57600080fd5b505af115801561133f573d6000803e3d6000fd5b5061135a9250610eb29150506101208a016101008b0161361a565b7fe06490c1ee6e6c082db362f38ed400dab1759def892a48e10c4ebb0ca8f348c161138c6101008a0160e08b0161361a565b61139e6101408b016101208c0161361a565b6113b06101208c016101008d0161361a565b6113c060c08d0160a08e0161361a565b6113d060e08e0160c08f0161361a565b878a8f60800160000160208101906113e89190613650565b604080516001600160a01b03998a16815297891660208901529588169587019590955292861660608601529416608084015260a083019390935260c082019290925290151560e08201526101000160405180910390a1505050949350505050565b7f00000000000000000000000055555555555555555555555555555555555555556001600160a01b0316846001600160a01b031614801561148a5750804710155b156115b6577f00000000000000000000000055555555555555555555555555555555555555556001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156114ea57600080fd5b505af11580156114fe573d6000803e3d6000fd5b50506040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038681166004830152602482018690527f000000000000000000000000555555555555555555555555555555555555555516935063a9059cbb925060440190506020604051808303816000875af115801561158c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115b091906137e9565b506116a2565b306001600160a01b038416036115df576115da6001600160a01b03851683836116ea565b6116a2565b7f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b03166336c78516848461161985612093565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b0393841660048201529183166024830152821660448201529087166064820152608401600060405180830381600087803b15801561168957600080fd5b505af115801561169d573d6000803e3d6000fd5b505050505b50505050565b604080516020810184905290810182905246606082015230608082015260009060a0016040516020818303038152906040528051906020012090505b92915050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb0000000000000000000000000000000000000000000000000000000017905261176a908490612130565b505050565b8161012001354211156117ae576040517f95595b7b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6117b8828061366d565b90506000036117f3576040517fd59b3f9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611800602083018361366d565b905061180c838061366d565b90501415806118375750611823604083018361366d565b9050611832602084018461366d565b905014155b8061185e575061184a606083018361366d565b9050611859604084018461366d565b905014155b15611895576040517fc7ea213d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6118a560e0830160c0840161361a565b6001600160a01b03166118be60c0840160a0850161361a565b6001600160a01b0316036118fe576040517f200bb78000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8015610955576000805b611915604085018561366d565b90508110156119575761192b604085018561366d565b8281811061193b5761193b61344c565b905060200201358261194d9190613806565b9150600101611908565b5081811461176a576040517fa7459f3300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080600083604001516000815181106119ad576119ad61344c565b60200260200101516000036119ee576040517f34cbfb2f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b846020015151811015611c895760008086600001518381518110611a1757611a1761344c565b6020026020010151611b1f57611b1a600088604001518581518110611a3e57611a3e61344c565b602002602001015111611a515784611a70565b87604001518481518110611a6757611a6761344c565b60200260200101515b8860e0015189602001518681518110611a8b57611a8b61344c565b60200260200101518a6080015160008c604001518981518110611ab057611ab061344c565b602002602001015111611ac35730611ac9565b8b60c001515b604080516001600160a01b03938416602082015292909116908201526060016040516020818303038152906040528b606001518881518110611b0d57611b0d61344c565b6020026020010151612232565b611c16565b611c16600088604001518581518110611b3a57611b3a61344c565b602002602001015111611b4d5784611b6c565b87604001518481518110611b6357611b6361344c565b60200260200101515b8860e0015189602001518681518110611b8757611b8761344c565b60200260200101518a6080015160008c604001518981518110611bac57611bac61344c565b602002602001015111611bbf5730611bc5565b8b60c001515b604080516001600160a01b03938416602082015292909116908201526060016040516020818303038152906040528b606001518881518110611c0957611c0961344c565b602002602001015161248f565b809650819350829450505050600087604001518481518110611c3a57611c3a61344c565b60200260200101511115611c5557611c528287613806565b95505b8660a001516001600160a01b0316816001600160a01b031603611c7f57611c7c8486613806565b94505b50506001016119f1565b5050915091565b8015610955576000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611ce3576040519150601f19603f3d011682016040523d82523d6000602084013e611ce8565b606091505b505090508061176a576040517f351e6d4500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080611d2f866127a6565b611d416101c087016101a0880161351e565b6fffffffffffffffffffffffffffffffff16836fffffffffffffffffffffffffffffffff161115611d9e576040517fe483256400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611ddb6101c087013560016000611dbc6101008b0160e08c0161361a565b6001600160a01b03168152602081019190915260400160002090612a28565b611e0c611df2611ded88608001612a8c565b612ade565b611e03610100890160e08a0161361a565b87918791612b28565b604080516101008101909152611f6c9080611e27898061366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602090810190611e6d908a018a61366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001611eb160408a018a61366d565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001611ef560608a018a61366d565b611efe9161371b565b8152602001611f1360c08a0160a08b0161361a565b6001600160a01b03168152602001611f3160e08a0160c08b0161361a565b6001600160a01b03168152602001611f506101008a0160e08b0161361a565b6001600160a01b031681526101e0890135602090910152611991565b90925090506fffffffffffffffffffffffffffffffff83161561208a576001600160a01b037f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3166336c78516611fc9610100890160e08a0161361a565b611fdb6101408a016101208b0161361a565b6fffffffffffffffffffffffffffffffff87166120006101608c016101408d0161361a565b60405160e086901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b039485166004820152928416602484015290831660448301529091166064820152608401600060405180830381600087803b15801561207157600080fd5b505af1158015612085573d6000803e3d6000fd5b505050505b94509492505050565b60006001600160a01b0382111561212c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201527f36302062697473000000000000000000000000000000000000000000000000006064820152608401610fec565b5090565b6000612185826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612e7b9092919063ffffffff16565b90508051600014806121a65750808060200190518101906121a691906137e9565b61176a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610fec565b6040517ffc4328520000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152600091829182917f0000000000000000000000007e028ac56cb2af75292f3d967978189698c247329091169063fc43285290602401602060405180830381865afa1580156122ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122de91906137e9565b612314576040517fd85d90e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008480602001905181019061232a9190613882565b905086600360006101000a8154816001600160a01b0302191690836001600160a01b03160217905550866001600160a01b031663373290096040518061010001604052806001151581526020018460000151151581526020018c8152602001846060015181526020018b815260200184602001516001600160a01b0316815260200184604001516001600160a01b031681526020016040518060800160405280866080015181526020018660a0015181526020018b81526020018660c001518152508152506040518263ffffffff1660e01b815260040161240b9190613a29565b60408051808303816000875af1158015612429573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061244d9190613aac565b604090920151600380547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001179055909a90995090975095505050505050565b6040517f9416b8f30000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152600091829182917f0000000000000000000000007e028ac56cb2af75292f3d967978189698c2473290911690639416b8f390602401602060405180830381865afa158015612517573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061253b91906137e9565b612571576040517fcb05115a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000848060200190518101906125879190613bd8565b905086600260006101000a8154816001600160a01b0302191690836001600160a01b03160217905550866001600160a01b031663a50f6e8a604051806101600160405280846000015115158152602001600115158152602001846040015160020b815260200184602001516001600160a01b031681526020018c8152602001846060015181526020018b81526020018981526020018460c001518152602001846080015181526020018460a001518152506040518263ffffffff1660e01b81526004016126549190613d2a565b60408051808303816000875af1158015612672573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126969190613aac565b8251919550925061270857866001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156126df573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612703919061357d565b61276a565b866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612746573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061276a919061357d565b600280547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001179055939993985090965091945050505050565b6101e08101354211156127e5576040517f8d739acd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6127ef818061366d565b905060000361282a576040517f5efa59fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612837602082018261366d565b9050612843828061366d565b905014158061286e575061285a604082018261366d565b9050612869602083018361366d565b905014155b806128955750612881606082018261366d565b9050612890604083018361366d565b905014155b156128cc576040517f21bb7dcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6128dc60e0820160c0830161361a565b6001600160a01b03166128f560c0830160a0840161361a565b6001600160a01b031603612935576040517f9f0ecb6e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080612945604084018461366d565b9050905060005b8181101561298d57612961604085018561366d565b828181106129715761297161344c565b90506020020135836129839190613806565b925060010161294c565b5061016083013582146129cc576040517f5328f79300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6129de6101408401610120850161361a565b6001600160a01b0316336001600160a01b03161461176a576040517f80bd2ef400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600881901c60008181526020849052604081208054600160ff861690811b91821892839055929091908183169003610598576040517f0838650000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60007f8c911b939d917e4764db40337f23e2ac4fbfa3823f1a03481437cf6aa20fb38582604051602001612ac1929190613e33565b604051602081830303815290604052805190602001209050919050565b6000612ae86105a0565b6040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281019190915260428101839052606201612ac1565b6000806000836001600160a01b03163b600003612d71576041869003612b7d57612b5486880188613f5e565b909350915086866040818110612b6c57612b6c61344c565b919091013560f81c9150612c079050565b6040869003612bd5576000612b9487890189613f5e565b9094507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811693509050612bcd60ff82901c601b613f80565b915050612c07565b6040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115612c61576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160008082526020820180845288905260ff841692820192909252606081018590526080810184905260019060a0016020604051602081039080840390855afa158015612cb5573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150506001600160a01b038116612d20576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b846001600160a01b0316816001600160a01b031614612d6b576040517f815e1d6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50610769565b6040517f1626ba7e0000000000000000000000000000000000000000000000000000000081526000906001600160a01b03861690631626ba7e90612dbd9089908c908c90600401613f99565b602060405180830381865afa158015612dda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dfe9190613fed565b90507fffffffff0000000000000000000000000000000000000000000000000000000081167f1626ba7e000000000000000000000000000000000000000000000000000000001461169d576040517fb0669cbc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6060610794848460008585600080866001600160a01b03168587604051612ea2919061402f565b60006040518083038185875af1925050503d8060008114612edf576040519150601f19603f3d011682016040523d82523d6000602084013e612ee4565b606091505b5091509150612ef587838387612f00565b979650505050505050565b60608315612f89578251600003612f82576001600160a01b0385163b612f82576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610fec565b5081610794565b6107948383815115612f9e5781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fec9190614041565b60008083601f840112612fe457600080fd5b50813567ffffffffffffffff811115612ffc57600080fd5b6020830191508360208260051b850101111561301757600080fd5b9250929050565b6000806000806000806060878903121561303757600080fd5b863567ffffffffffffffff8082111561304f57600080fd5b61305b8a838b01612fd2565b9098509650602089013591508082111561307457600080fd5b6130808a838b01612fd2565b9096509450604089013591508082111561309957600080fd5b506130a689828a01612fd2565b979a9699509497509295939492505050565b6020808252825182820181905260009190848201906040850190845b818110156130f0578351835292840192918401916001016130d4565b50909695505050505050565b6001600160a01b038116811461311157600080fd5b50565b8035610f7f816130fc565b60008083601f84011261313157600080fd5b50813567ffffffffffffffff81111561314957600080fd5b60208301915083602082850101111561301757600080fd5b6000806000806060858703121561317757600080fd5b8435613182816130fc565b935060208501359250604085013567ffffffffffffffff8111156131a557600080fd5b6131b18782880161311f565b95989497509550505050565b600080604083850312156131d057600080fd5b82356131db816130fc565b946020939093013593505050565b80356fffffffffffffffffffffffffffffffff81168114610f7f57600080fd5b6000806000806060858703121561321f57600080fd5b843567ffffffffffffffff8082111561323757600080fd5b90860190610200828903121561324c57600080fd5b9094506020860135908082111561326257600080fd5b5061326f8782880161311f565b90945092506132829050604086016131e9565b905092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405160e0810167ffffffffffffffff811182821017156132df576132df61328d565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff8111828210171561332c5761332c61328d565b604052919050565b600067ffffffffffffffff82111561334e5761334e61328d565b5060051b60200190565b6000806040838503121561336b57600080fd5b823567ffffffffffffffff81111561338257600080fd5b8301601f8101851361339357600080fd5b803560206133a86133a383613334565b6132e5565b82815260059290921b830181019181810190888411156133c757600080fd5b938201935b838510156133ee5784356133df816130fc565b825293820193908201906133cc565b95506133fd9050868201613114565b93505050509250929050565b60006020828403121561341b57600080fd5b813567ffffffffffffffff81111561343257600080fd5b8201610140818503121561344557600080fd5b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe018336030181126134af57600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126134ee57600080fd5b83018035915067ffffffffffffffff82111561350957600080fd5b60200191503681900382131561301757600080fd5b60006020828403121561353057600080fd5b613445826131e9565b6000806040838503121561354c57600080fd5b8235613557816130fc565b91506020830135613567816130fc565b809150509250929050565b8051610f7f816130fc565b60006020828403121561358f57600080fd5b8151613445816130fc565b6000602082840312156135ac57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203613613576136136135b3565b5060010190565b60006020828403121561362c57600080fd5b8135613445816130fc565b801515811461311157600080fd5b8035610f7f81613637565b60006020828403121561366257600080fd5b813561344581613637565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126136a257600080fd5b83018035915067ffffffffffffffff8211156136bd57600080fd5b6020019150600581901b360382131561301757600080fd5b600067ffffffffffffffff8211156136ef576136ef61328d565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b60006137296133a384613334565b80848252602080830192508560051b85013681111561374757600080fd5b855b818110156137bf57803567ffffffffffffffff8111156137695760008081fd5b870136601f82011261377b5760008081fd5b80356137896133a3826136d5565b818152368683850101111561379e5760008081fd5b81868401878301376000918101860191909152865250938201938201613749565b50919695505050505050565b818103818111156116e4576116e46135b3565b8051610f7f81613637565b6000602082840312156137fb57600080fd5b815161344581613637565b808201808211156116e4576116e46135b3565b60005b8381101561383457818101518382015260200161381c565b50506000910152565b600082601f83011261384e57600080fd5b815161385c6133a3826136d5565b81815284602083860101111561387157600080fd5b610794826020830160208701613819565b60006020828403121561389457600080fd5b815167ffffffffffffffff808211156138ac57600080fd5b9083019060e082860312156138c057600080fd5b6138c86132bc565b6138d1836137de565b81526138df60208401613572565b60208201526138f060408401613572565b60408201526060830151606082015260808301518281111561391157600080fd5b61391d8782860161383d565b60808301525060a08301518281111561393557600080fd5b6139418782860161383d565b60a08301525060c08301518281111561395957600080fd5b6139658782860161383d565b60c08301525095945050505050565b6000815180845261398c816020860160208601613819565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60008151608084526139d36080850182613974565b9050602083015184820360208601526139ec8282613974565b91505060408301518482036040860152613a068282613974565b91505060608301518482036060860152613a208282613974565b95945050505050565b602081528151151560208201526020820151151560408201526040820151606082015260608201516080820152608082015160a0820152600060a0830151613a7c60c08401826001600160a01b03169052565b5060c08301516001600160a01b03811660e08401525060e0830151610100838101526107946101208401826139be565b60008060408385031215613abf57600080fd5b505080516020909101519092909150565b8051600281900b8114610f7f57600080fd5b600082601f830112613af357600080fd5b81516020613b036133a383613334565b82815260059290921b84018101918181019086841115613b2257600080fd5b8286015b84811015613b4d57805160ff81168114613b405760008081fd5b8352918301918301613b26565b509695505050505050565b600082601f830112613b6957600080fd5b81516020613b796133a383613334565b82815260059290921b84018101918181019086841115613b9857600080fd5b8286015b84811015613b4d57805167ffffffffffffffff811115613bbc5760008081fd5b613bca8986838b010161383d565b845250918301918301613b9c565b600060208284031215613bea57600080fd5b815167ffffffffffffffff80821115613c0257600080fd5b9083019060e08286031215613c1657600080fd5b613c1e6132bc565b613c27836137de565b8152613c3560208401613572565b6020820152613c4660408401613ad0565b604082015260608301516060820152608083015182811115613c6757600080fd5b613c7387828601613ae2565b60808301525060a083015182811115613c8b57600080fd5b61394187828601613b58565b600081518084526020808501945080840160005b83811015613cca57815160ff1687529582019590820190600101613cab565b509495945050505050565b600081518084526020808501808196508360051b8101915082860160005b85811015613d1d578284038952613d0b848351613974565b98850198935090840190600101613cf3565b5091979650505050505050565b60208152613d3d60208201835115159052565b60006020830151613d52604084018215159052565b506040830151613d67606084018260020b9052565b5060608301516001600160a01b038116608084015250608083015160a083015260a083015160c083015260c083015160e083015260e08301516101606101008181860152613db9610180860184613974565b92508086015190507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610120818786030181880152613df88584613974565b945080880151925050610140818786030181880152613e178584613c97565b9088015187820390920184880152935090506104c88382613cd5565b8281526101a08101613e5160208301613e4b85613645565b15159052565b613e5d60208401613114565b6001600160a01b038116604084015250613e7960408401613114565b6001600160a01b038116606084015250613e9560608401613114565b6001600160a01b038116608084015250613eb160808401613114565b6001600160a01b03811660a084015250613ecd60a08401613114565b6001600160a01b03811660c084015250613ee960c08401613114565b6001600160a01b03811660e08401525061010060e0840135818401526101208185013581850152613f1b8186016131e9565b915050610140613f3e818501836fffffffffffffffffffffffffffffffff169052565b610160915080850135828501525080840135610180840152509392505050565b60008060408385031215613f7157600080fd5b50508035926020909101359150565b60ff81811683821601908111156116e4576116e46135b3565b83815260406020820152816040820152818360608301376000818301606090810191909152601f9092017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016010192915050565b600060208284031215613fff57600080fd5b81517fffffffff000000000000000000000000000000000000000000000000000000008116811461344557600080fd5b600082516134af818460208701613819565b602081526000613445602083018461397456fea2646970667358221220c875d372eed306dc1c122dc4635a310d9c929b86b4114d8d0a1102bf1952beee64736f6c63430008130033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000007e028ac56cb2af75292f3d967978189698c247320000000000000000000000005555555555555555555555555555555555555555000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3

-----Decoded View---------------
Arg [0] : protocolFactory_ (address): 0x7E028ac56cB2AF75292F3D967978189698C24732
Arg [1] : _weth9 (address): 0x5555555555555555555555555555555555555555
Arg [2] : permit2_ (address): 0x000000000022D473030F116dDEE9F6B43aC78BA3

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000007e028ac56cb2af75292f3d967978189698c24732
Arg [1] : 0000000000000000000000005555555555555555555555555555555555555555
Arg [2] : 000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3


Block Transaction Gas Used Reward
view all blocks ##produced##

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]
[ Download: CSV Export  ]

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.