ETH Price: $2,867.36 (-9.82%)
Gas: 14 Gwei

Contract

0x007597aAF6A4E4652e7843aF5C44c359321368c2
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Approve201719372024-06-25 23:19:359 days ago1719357575IN
0x007597aA...9321368c2
0 ETH0.000186724.03282869
Approve199420572024-05-24 20:15:1141 days ago1716581711IN
0x007597aA...9321368c2
0 ETH0.000358547.74373625
Approve198774782024-05-15 19:29:2350 days ago1715801363IN
0x007597aA...9321368c2
0 ETH0.0003878.35841634
Approve198715952024-05-14 23:48:3551 days ago1715730515IN
0x007597aA...9321368c2
0 ETH0.00017053.68255502
Approve198639322024-05-13 21:58:4752 days ago1715637527IN
0x007597aA...9321368c2
0 ETH0.00022014.75374975
Approve198602252024-05-13 9:33:3552 days ago1715592815IN
0x007597aA...9321368c2
0 ETH0.000342387.39482119
Approve198533952024-05-12 10:38:3553 days ago1715510315IN
0x007597aA...9321368c2
0 ETH0.000154733.34196941
Approve198065692024-05-05 21:27:2360 days ago1714944443IN
0x007597aA...9321368c2
0 ETH0.000114464.33568942
Approve198065692024-05-05 21:27:2360 days ago1714944443IN
0x007597aA...9321368c2
0 ETH0.000200754.33596322
Approve196955552024-04-20 8:52:2375 days ago1713603143IN
0x007597aA...9321368c2
0 ETH0.000313626.77360198
Approve196078492024-04-08 2:02:3588 days ago1712541755IN
0x007597aA...9321368c2
0 ETH0.0005764212.44956536
Approve196054562024-04-07 17:59:2388 days ago1712512763IN
0x007597aA...9321368c2
0 ETH0.0008268117.85729506
Approve194956142024-03-23 6:48:23104 days ago1711176503IN
0x007597aA...9321368c2
0 ETH0.0009441120.26467914
Approve194897992024-03-22 11:14:35104 days ago1711106075IN
0x007597aA...9321368c2
0 ETH0.0009684920.91745388
Approve194145812024-03-11 21:37:59115 days ago1710193079IN
0x007597aA...9321368c2
0 ETH0.0032419370.01873453
Approve194141692024-03-11 20:14:59115 days ago1710188099IN
0x007597aA...9321368c2
0 ETH0.00479496102.92063244
Approve194139152024-03-11 19:23:59115 days ago1710185039IN
0x007597aA...9321368c2
0 ETH0.003183768.33605285
Approve193993692024-03-09 18:35:47117 days ago1710009347IN
0x007597aA...9321368c2
0 ETH0.0037007679.43425181
Approve193854362024-03-07 19:39:11119 days ago1709840351IN
0x007597aA...9321368c2
0 ETH0.0032745770.72368336
Approve193690532024-03-05 12:46:11121 days ago1709642771IN
0x007597aA...9321368c2
0 ETH0.0028679561.95765942
Approve192935482024-02-23 23:24:47132 days ago1708730687IN
0x007597aA...9321368c2
0 ETH0.0010948223.63970759
Approve192575902024-02-18 22:17:59137 days ago1708294679IN
0x007597aA...9321368c2
0 ETH0.0011018323.65003826
Approve190192352024-01-16 11:45:23170 days ago1705405523IN
0x007597aA...9321368c2
0 ETH0.001329428.53469387
Approve189756592024-01-10 9:29:35176 days ago1704878975IN
0x007597aA...9321368c2
0 ETH0.001216326.10718715
Approve189335322024-01-04 11:00:11182 days ago1704366011IN
0x007597aA...9321368c2
0 ETH0.0007089415.3115589
View all transactions

Latest 1 internal transaction

Advanced mode:
Parent Transaction Hash Block From To Value
185267532023-11-08 10:50:35239 days ago1699440635  Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SmardexPair

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 25 : SmardexPair.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity =0.8.17;

// contracts
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

// libraries
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "./libraries/SmardexLibrary.sol";
import "./libraries/TransferHelper.sol";

// interfaces
import "./interfaces/ISmardexPair.sol";
import "./interfaces/ISmardexOwnableFactory.sol";
import "./interfaces/ISmardexSwapCallback.sol";
import "./interfaces/ISmardexMintCallback.sol";

/**
 * @title SmardexPair
 * @notice Pair contract that allows user to swap 2 ERC20-strict tokens in a decentralised and automated way
 */
contract SmardexPair is ISmardexPair, ERC20Permit {
    using SafeCast for uint256;
    using SafeCast for int256;

    uint8 private constant CONTRACT_UNLOCKED = 1;
    uint8 private constant CONTRACT_LOCKED = 2;
    uint256 private constant MINIMUM_LIQUIDITY = 10 ** 3;
    bytes4 private constant AUTOSWAP_SELECTOR = bytes4(keccak256(bytes("executeWork(address,address)")));

    address public immutable factory;
    address public token0;
    address public token1;

    // smardex pair fees numerators, denominator is 1_000_000
    uint128 internal feesLP = 1; // numerator of fees sent to lp, min 1,
    uint128 internal feesPool; // numerator of fees sent to pool

    // smardex new fictive reserves
    uint128 internal fictiveReserve0;
    uint128 internal fictiveReserve1; // accessible via getFictiveReserves()

    // moving average on the price
    uint128 internal priceAverage0;
    uint128 internal priceAverage1;
    uint40 internal priceAverageLastTimestamp; // accessible via getPriceAverage()

    // fee for FEE_POOL
    uint104 internal feeToAmount0;
    uint104 internal feeToAmount1; // accessible via getFeeToAmounts()

    // reentrancy
    uint8 private lockStatus = CONTRACT_UNLOCKED;

    modifier lock() {
        require(lockStatus == CONTRACT_UNLOCKED, "SmarDex: LOCKED");
        lockStatus = CONTRACT_LOCKED;
        _;
        lockStatus = CONTRACT_UNLOCKED;
    }

    modifier onlyFactoryOwner() {
        require(msg.sender == ISmardexOwnableFactory(factory).owner(), "SmarDex: NOT_OWNER");
        _;
    }

    constructor() ERC20("SmarDex LP-Token", "SDEX-LP") ERC20Permit("SmarDex LP-Token") {
        factory = msg.sender;
    }

    ///@inheritdoc ISmardexPair
    function initialize(address _token0, address _token1, uint128 _feesLP, uint128 _feesPool) external override {
        require(msg.sender == factory, "SmarDex: FORBIDDEN"); // sufficient check
        token0 = _token0;
        token1 = _token1;
        _setFees(_feesLP, _feesPool);
    }

    ///@inheritdoc ISmardexPair
    function getReserves() external view override returns (uint256 reserve0_, uint256 reserve1_) {
        reserve0_ = IERC20(token0).balanceOf(address(this)) - feeToAmount0;
        reserve1_ = IERC20(token1).balanceOf(address(this)) - feeToAmount1;
    }

    ///@inheritdoc ISmardexPair
    function getFictiveReserves() external view override returns (uint256 fictiveReserve0_, uint256 fictiveReserve1_) {
        fictiveReserve0_ = fictiveReserve0;
        fictiveReserve1_ = fictiveReserve1;
    }

    ///@inheritdoc ISmardexPair
    function getFeeToAmounts() external view override returns (uint256 fees0_, uint256 fees1_) {
        fees0_ = feeToAmount0;
        fees1_ = feeToAmount1;
    }

    ///@inheritdoc ISmardexPair
    function getPairFees() external view override returns (uint128 feesLP_, uint128 feesPool_) {
        feesLP_ = feesLP;
        feesPool_ = feesPool;
    }

    ///@inheritdoc ISmardexPair
    function getPriceAverage()
        external
        view
        returns (uint256 priceAverage0_, uint256 priceAverage1_, uint256 priceAverageLastTimestamp_)
    {
        priceAverage0_ = priceAverage0;
        priceAverage1_ = priceAverage1;
        priceAverageLastTimestamp_ = priceAverageLastTimestamp;
    }

    ///@inheritdoc ISmardexPair
    function getUpdatedPriceAverage(
        uint256 _fictiveReserveIn,
        uint256 _fictiveReserveOut,
        uint256 _priceAverageLastTimestamp,
        uint256 _priceAverageIn,
        uint256 _priceAverageOut,
        uint256 _currentTimestamp
    ) public pure returns (uint256 priceAverageIn_, uint256 priceAverageOut_) {
        (priceAverageIn_, priceAverageOut_) = SmardexLibrary.getUpdatedPriceAverage(
            _fictiveReserveIn,
            _fictiveReserveOut,
            _priceAverageLastTimestamp,
            _priceAverageIn,
            _priceAverageOut,
            _currentTimestamp
        );
    }

    ///@inheritdoc ISmardexPair
    function mint(
        address _to,
        uint256 _amount0,
        uint256 _amount1,
        address _payer
    ) external override returns (uint256 liquidity_) {
        liquidity_ = _mintBeforeFee(_to, _amount0, _amount1, _payer);

        // we call feeTo out of the internal locked mint (_mintExt) function to be able to swap fees in here
        _feeToSwap();
    }

    ///@inheritdoc ISmardexPair
    function burn(address _to) external override returns (uint256 amount0_, uint256 amount1_) {
        (amount0_, amount1_) = _burnBeforeFee(_to);

        // we call feeTo out of the internal locked burn (_burnExt) function to be able to swap fees in here
        _feeToSwap();
    }

    ///@inheritdoc ISmardexPair
    function swap(
        address _to,
        bool _zeroForOne,
        int256 _amountSpecified,
        bytes calldata _data
    ) external override lock returns (int256 amount0_, int256 amount1_) {
        require(_amountSpecified != 0, "SmarDex: ZERO_AMOUNT");

        ISmardexPair.SwapParams memory _params = SwapParams({
            amountCalculated: 0,
            fictiveReserveIn: 0,
            fictiveReserveOut: 0,
            priceAverageIn: 0,
            priceAverageOut: 0,
            token0: token0,
            token1: token1,
            balanceIn: 0,
            balanceOut: 0
        });

        require(_to != _params.token0 && _to != _params.token1, "SmarDex: INVALID_TO");
        (
            _params.balanceIn,
            _params.balanceOut,
            _params.fictiveReserveIn,
            _params.fictiveReserveOut,
            _params.priceAverageIn,
            _params.priceAverageOut
        ) = _zeroForOne
            ? (
                IERC20(_params.token0).balanceOf(address(this)) - feeToAmount0,
                IERC20(_params.token1).balanceOf(address(this)) - feeToAmount1,
                fictiveReserve0,
                fictiveReserve1,
                priceAverage0,
                priceAverage1
            )
            : (
                IERC20(_params.token1).balanceOf(address(this)) - feeToAmount1,
                IERC20(_params.token0).balanceOf(address(this)) - feeToAmount0,
                fictiveReserve1,
                fictiveReserve0,
                priceAverage1,
                priceAverage0
            );

        // compute new price average
        (_params.priceAverageIn, _params.priceAverageOut) = SmardexLibrary.getUpdatedPriceAverage(
            _params.fictiveReserveIn,
            _params.fictiveReserveOut,
            priceAverageLastTimestamp,
            _params.priceAverageIn,
            _params.priceAverageOut,
            block.timestamp
        );

        // SSTORE new price average
        (priceAverage0, priceAverage1, priceAverageLastTimestamp) = _zeroForOne
            ? (_params.priceAverageIn.toUint128(), _params.priceAverageOut.toUint128(), uint40(block.timestamp))
            : (_params.priceAverageOut.toUint128(), _params.priceAverageIn.toUint128(), uint40(block.timestamp));

        uint128 _feesPool = feesPool; // caching feesPool to save gas

        if (_amountSpecified > 0) {
            uint256 _temp;
            (_temp, , , _params.fictiveReserveIn, _params.fictiveReserveOut) = SmardexLibrary.getAmountOut(
                SmardexLibrary.GetAmountParameters({
                    amount: _amountSpecified.toUint256(),
                    reserveIn: _params.balanceIn,
                    reserveOut: _params.balanceOut,
                    fictiveReserveIn: _params.fictiveReserveIn,
                    fictiveReserveOut: _params.fictiveReserveOut,
                    priceAverageIn: _params.priceAverageIn,
                    priceAverageOut: _params.priceAverageOut,
                    feesLP: feesLP,
                    feesPool: _feesPool
                })
            );
            _params.amountCalculated = _temp.toInt256();
        } else {
            uint256 _temp;
            (_temp, , , _params.fictiveReserveIn, _params.fictiveReserveOut) = SmardexLibrary.getAmountIn(
                SmardexLibrary.GetAmountParameters({
                    amount: (-_amountSpecified).toUint256(),
                    reserveIn: _params.balanceIn,
                    reserveOut: _params.balanceOut,
                    fictiveReserveIn: _params.fictiveReserveIn,
                    fictiveReserveOut: _params.fictiveReserveOut,
                    priceAverageIn: _params.priceAverageIn,
                    priceAverageOut: _params.priceAverageOut,
                    feesLP: feesLP,
                    feesPool: _feesPool
                })
            );
            _params.amountCalculated = _temp.toInt256();
        }

        (amount0_, amount1_) = _zeroForOne
            ? (
                _amountSpecified > 0
                    ? (_amountSpecified, -_params.amountCalculated)
                    : (_params.amountCalculated, _amountSpecified)
            )
            : (
                _amountSpecified > 0
                    ? (-_params.amountCalculated, _amountSpecified)
                    : (_amountSpecified, _params.amountCalculated)
            );

        if (_zeroForOne) {
            if (amount1_ < 0) {
                TransferHelper.safeTransfer(_params.token1, _to, uint256(-amount1_));
            }
            ISmardexSwapCallback(msg.sender).smardexSwapCallback(amount0_, amount1_, _data);
            uint256 _balanceInBefore = _params.balanceIn;
            _params.balanceIn = IERC20(token0).balanceOf(address(this));
            require(
                _balanceInBefore + feeToAmount0 + (amount0_).toUint256() <= _params.balanceIn,
                "SmarDex: INSUFFICIENT_TOKEN0_INPUT_AMOUNT"
            );
            _params.balanceOut = IERC20(token1).balanceOf(address(this));
        } else {
            if (amount0_ < 0) {
                TransferHelper.safeTransfer(_params.token0, _to, uint256(-amount0_));
            }
            ISmardexSwapCallback(msg.sender).smardexSwapCallback(amount0_, amount1_, _data);
            uint256 _balanceInBefore = _params.balanceIn;
            _params.balanceIn = IERC20(token1).balanceOf(address(this));
            require(
                _balanceInBefore + feeToAmount1 + (amount1_).toUint256() <= _params.balanceIn,
                "SmarDex: INSUFFICIENT_TOKEN1_INPUT_AMOUNT"
            );
            _params.balanceOut = IERC20(token0).balanceOf(address(this));
        }

        // update feeTopart
        bool _feeOn = ISmardexOwnableFactory(factory).feeTo() != address(0);
        if (_zeroForOne) {
            if (_feeOn) {
                feeToAmount0 += ((uint256(amount0_) * _feesPool) / SmardexLibrary.FEES_BASE).toUint104();
            }
            _update(
                _params.balanceIn,
                _params.balanceOut,
                _params.fictiveReserveIn,
                _params.fictiveReserveOut,
                _params.priceAverageIn,
                _params.priceAverageOut
            );
        } else {
            if (_feeOn) {
                feeToAmount1 += ((uint256(amount1_) * _feesPool) / SmardexLibrary.FEES_BASE).toUint104();
            }
            _update(
                _params.balanceOut,
                _params.balanceIn,
                _params.fictiveReserveOut,
                _params.fictiveReserveIn,
                _params.priceAverageOut,
                _params.priceAverageIn
            );
        }

        emit Swap(msg.sender, _to, amount0_, amount1_);
    }

    ///@inheritdoc ISmardexPair
    function setFees(uint128 _feesLP, uint128 _feesPool) external onlyFactoryOwner {
        _setFees(_feesLP, _feesPool);
    }

    /**
     * @notice set feesLP and feesPool of the pair
     * @notice sum of new feesLp and feesPool must be <= 100_000
     * @param _feesLP new numerator of fees sent to LP, must be >= 1
     * @param _feesPool new numerator of fees sent to Pool, could be = 0
     */
    function _setFees(uint128 _feesLP, uint128 _feesPool) internal {
        require(_feesLP != 0, "SmarDex: ZERO_FEES_LP");
        require(_feesLP + _feesPool <= SmardexLibrary.FEES_MAX, "SmarDex: FEES_MAX");
        feesLP = _feesLP;
        feesPool = _feesPool;

        emit FeesChanged(_feesLP, _feesPool);
    }

    /**
     * @notice update fictive reserves and emit the Sync event
     * @param _balance0 the new balance of token0
     * @param _balance1 the new balance of token1
     * @param _fictiveReserve0 the new fictive reserves of token0
     * @param _fictiveReserve1 the new fictive reserves of token1
     * @param _priceAverage0 the new priceAverage of token0
     * @param _priceAverage1 the new priceAverage of token1
     */
    function _update(
        uint256 _balance0,
        uint256 _balance1,
        uint256 _fictiveReserve0,
        uint256 _fictiveReserve1,
        uint256 _priceAverage0,
        uint256 _priceAverage1
    ) private {
        require(_fictiveReserve0 != 0 && _fictiveReserve1 != 0, "SmarDex: FICTIVE_RESERVES_TOO_LOW");
        require(_fictiveReserve0 <= type(uint128).max && _fictiveReserve1 <= type(uint128).max, "SmarDex: OVERFLOW");
        fictiveReserve0 = uint128(_fictiveReserve0);
        fictiveReserve1 = uint128(_fictiveReserve1);

        emit Sync(
            _balance0 - feeToAmount0,
            _balance1 - feeToAmount1,
            _fictiveReserve0,
            _fictiveReserve1,
            _priceAverage0,
            _priceAverage1
        );
    }

    /**
     * @notice transfers feeToAmount of tokens 0 and 1 to feeTo, and reset feeToAmounts
     * @return feeOn_ if part of the fees goes to feeTo
     */
    function _sendFee() private returns (bool feeOn_) {
        address _feeTo = ISmardexFactory(factory).feeTo();
        feeOn_ = _feeTo != address(0);
        if (feeOn_) {
            // gas saving
            uint256 _feeToAmount0 = feeToAmount0;
            uint256 _feeToAmount1 = feeToAmount1;

            if (_feeToAmount0 != 0) {
                TransferHelper.safeTransfer(token0, _feeTo, _feeToAmount0);
                feeToAmount0 = 0;
            }
            if (_feeToAmount1 != 0) {
                TransferHelper.safeTransfer(token1, _feeTo, _feeToAmount1);
                feeToAmount1 = 0;
            }
        } else {
            feeToAmount0 = 0;
            feeToAmount1 = 0;
        }
    }

    /**
     * @notice Mint lp tokens proportionally of added tokens in balance.
     * @param _to address who will receive minted tokens
     * @param _amount0 amount of token0 to provide
     * @param _amount1 amount of token1 to provide
     * @param _payer address of the payer to provide token for the mint
     * @return liquidity_ amount of lp tokens minted and sent to the address defined in parameter
     */
    function _mintBeforeFee(
        address _to,
        uint256 _amount0,
        uint256 _amount1,
        address _payer
    ) internal lock returns (uint256 liquidity_) {
        _sendFee();

        uint256 _fictiveReserve0;
        uint256 _fictiveReserve1;

        // gas saving
        uint256 _balance0 = IERC20(token0).balanceOf(address(this));
        uint256 _balance1 = IERC20(token1).balanceOf(address(this));
        uint256 _totalSupply = totalSupply();

        ISmardexMintCallback(msg.sender).smardexMintCallback(
            ISmardexMintCallback.MintCallbackData({
                token0: token0,
                token1: token1,
                amount0: _amount0,
                amount1: _amount1,
                payer: _payer
            })
        );

        // gas savings
        uint256 _balance0after = IERC20(token0).balanceOf(address(this));
        uint256 _balance1after = IERC20(token1).balanceOf(address(this));

        require(_balance0after >= _balance0 + _amount0, "SmarDex: INSUFFICIENT_AMOUNT_0");
        require(_balance1after >= _balance1 + _amount1, "SmarDex: INSUFFICIENT_AMOUNT_1");

        if (_totalSupply == 0) {
            liquidity_ = Math.sqrt(_amount0 * _amount1) - MINIMUM_LIQUIDITY;
            _mint(address(0xdead), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
            _fictiveReserve0 = _balance0after / 2;
            _fictiveReserve1 = _balance1after / 2;
        } else {
            liquidity_ = Math.min((_amount0 * _totalSupply) / _balance0, (_amount1 * _totalSupply) / _balance1);

            // update proportionally the fictiveReserves
            _fictiveReserve0 = (fictiveReserve0 * (_totalSupply + liquidity_)) / _totalSupply;
            _fictiveReserve1 = (fictiveReserve1 * (_totalSupply + liquidity_)) / _totalSupply;
        }

        require(liquidity_ != 0, "SmarDex: INSUFFICIENT_LIQUIDITY_MINTED");
        _mint(_to, liquidity_);

        _update(_balance0after, _balance1after, _fictiveReserve0, _fictiveReserve1, priceAverage0, priceAverage1);

        emit Mint(msg.sender, _to, _amount0, _amount1);
    }

    /**
     * @notice Burn lp tokens in the balance of the contract. Sends to the defined address the amount of token0 and
     * token1 proportionally of the amount burned.
     * @param _to address who will receive tokens
     * @return amount0_ amount of token0 sent to the address defined in parameter
     * @return amount1_ amount of token0 sent to the address defined in parameter
     */
    function _burnBeforeFee(address _to) internal lock returns (uint256 amount0_, uint256 amount1_) {
        _sendFee();

        // gas savings
        address _token0 = token0;
        address _token1 = token1;
        uint256 _balance0 = IERC20(_token0).balanceOf(address(this));
        uint256 _balance1 = IERC20(_token1).balanceOf(address(this));
        uint256 _liquidity = balanceOf(address(this));
        uint256 _totalSupply = totalSupply();

        // pro-rata distribution
        amount0_ = (_liquidity * _balance0) / _totalSupply;
        amount1_ = (_liquidity * _balance1) / _totalSupply;
        require(amount0_ != 0 && amount1_ != 0, "SmarDex: INSUFFICIENT_LIQUIDITY_BURNED");

        // update proportionally the fictiveReserves
        uint256 _fictiveReserve0 = fictiveReserve0;
        uint256 _fictiveReserve1 = fictiveReserve1;
        _fictiveReserve0 -= (_fictiveReserve0 * _liquidity) / _totalSupply;
        _fictiveReserve1 -= (_fictiveReserve1 * _liquidity) / _totalSupply;

        _burn(address(this), _liquidity);
        TransferHelper.safeTransfer(_token0, _to, amount0_);
        TransferHelper.safeTransfer(_token1, _to, amount1_);

        _balance0 = IERC20(_token0).balanceOf(address(this));
        _balance1 = IERC20(_token1).balanceOf(address(this));

        _update(_balance0, _balance1, _fictiveReserve0, _fictiveReserve1, priceAverage0, priceAverage1);

        emit Burn(msg.sender, _to, amount0_, amount1_);
    }

    /**
     * @notice execute function "executeWork(address,address)" of the feeTo contract. Doesn't revert tx if it reverts
     */
    function _feeToSwap() internal {
        address _feeTo = ISmardexOwnableFactory(factory).feeTo();

        // call contract destination for handling fees
        // We don't handle return values so it does not revert for LP if something went wrong in feeTo
        // Will swap fees to SDEX and send them. We want this to not revert if the swap failed
        // but to revert if not enough gas
        _feeTo.call(abi.encodeWithSelector(AUTOSWAP_SELECTOR, token0, token1));

        // After the _feeTo call, we check if gas is not equal to 0. Though seemingly redundant
        // (as running out of gas would fail the transaction anyway), this require prevents the
        // compiler from ignoring a simple gasleft() expression, which it may perceive as
        // useless if not used elsewhere. The aim here is to consume some gas to ensure the
        // transaction isn't out of gas at this point. This acts as a safeguard against potential
        // exploitation where a low gasLimit prevents the _feeTo call from fully executing.
        require(gasleft() != 0, "");
    }

    ///@inheritdoc ISmardexPair
    function skim(address _to) external lock {
        require(totalSupply() == 0, "SmarDex: ONLY_EMPTY_PAIR");

        // gas savings
        address _token0 = token0;
        address _token1 = token1;
        uint256 _balance0 = IERC20(_token0).balanceOf(address(this));
        uint256 _balance1 = IERC20(_token1).balanceOf(address(this));

        if (_balance0 != 0) {
            TransferHelper.safeTransfer(_token0, _to, _balance0);
        }
        if (_balance1 != 0) {
            TransferHelper.safeTransfer(_token1, _to, _balance1);
        }
    }
}

File 2 of 25 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.0;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

File 3 of 25 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(address from, address to, uint256 amount) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}

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

pragma solidity ^0.8.0;

// EIP-2612 is Final as of 2022-11-01. This file is deprecated.

import "./IERC20Permit.sol";

File 5 of 25 : ERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC20Permit.sol)

pragma solidity ^0.8.0;

import "./IERC20Permit.sol";
import "../ERC20.sol";
import "../../../utils/cryptography/ECDSA.sol";
import "../../../utils/cryptography/EIP712.sol";
import "../../../utils/Counters.sol";

/**
 * @dev Implementation 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.
 *
 * _Available since v3.4._
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
    using Counters for Counters.Counter;

    mapping(address => Counters.Counter) private _nonces;

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private constant _PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
    /**
     * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.
     * However, to ensure consistency with the upgradeable transpiler, we will continue
     * to reserve a slot.
     * @custom:oz-renamed-from _PERMIT_TYPEHASH
     */
    // solhint-disable-next-line var-name-mixedcase
    bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) EIP712(name, "1") {}

    /**
     * @dev See {IERC20Permit-permit}.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual override {
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _approve(owner, spender, value);
    }

    /**
     * @dev See {IERC20Permit-nonces}.
     */
    function nonces(address owner) public view virtual override returns (uint256) {
        return _nonces[owner].current();
    }

    /**
     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view override returns (bytes32) {
        return _domainSeparatorV4();
    }

    /**
     * @dev "Consume a nonce": return the current value and increment.
     *
     * _Available since v4.1._
     */
    function _useNonce(address owner) internal virtual returns (uint256 current) {
        Counters.Counter storage nonce = _nonces[owner];
        current = nonce.current();
        nonce.increment();
    }
}

File 6 of 25 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 7 of 25 : IERC20Permit.sol
// 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);
}

File 8 of 25 : IERC20.sol
// 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);
}

File 9 of 25 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 10 of 25 : Counters.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

File 11 of 25 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV // Deprecated in v4.8
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32")
            mstore(0x1c, hash)
            message := keccak256(0x00, 0x3c)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, "\x19\x01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x00", validator, data));
    }
}

File 12 of 25 : EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.8;

import "./ECDSA.sol";
import "../ShortStrings.sol";
import "../../interfaces/IERC5267.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * _Available since v3.4._
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

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

    // 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.
    bytes32 private immutable _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

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

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev See {EIP-5267}.
     *
     * _Available since v4.9._
     */
    function eip712Domain()
        public
        view
        virtual
        override
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _name.toStringWithFallback(_nameFallback),
            _version.toStringWithFallback(_versionFallback),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }
}

File 13 of 25 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 14 of 25 : 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 15 of 25 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 16 of 25 : ShortStrings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol)

pragma solidity ^0.8.8;

import "./StorageSlot.sol";

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(_FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

File 17 of 25 : StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 18 of 25 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 19 of 25 : ISmardexFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.17;

interface ISmardexFactory {
    /**
     * @notice emitted at each SmardexPair created
     * @param token0 address of the token0
     * @param token1 address of the token1
     * @param pair address of the SmardexPair created
     * @param totalPair number of SmardexPair created so far
     */
    event PairCreated(address indexed token0, address indexed token1, address pair, uint256 totalPair);

    /**
     * @notice emitted at each SmardexPair manually added
     * @param token0 address of the token0
     * @param token1 address of the token1
     * @param pair address of the SmardexPair created
     * @param totalPair number of SmardexPair created so far
     */
    event PairAdded(address indexed token0, address indexed token1, address pair, uint256 totalPair);

    /**
     * @notice emitted each time feesLP and feesPool are changed
     * @param feesLP new feesLP
     * @param feesPool new feesPool
     */
    event FeesChanged(uint256 indexed feesLP, uint256 indexed feesPool);

    /**
     * @notice emitted when the feeTo is updated
     * @param previousFeeTo the previous feeTo address
     * @param newFeeTo the new feeTo address
     */
    event FeeToUpdated(address indexed previousFeeTo, address indexed newFeeTo);

    /**
     * @notice return which address fees will be transferred
     */
    function feeTo() external view returns (address);

    /**
     * @notice return the address of the pair of 2 tokens
     */
    function getPair(address _tokenA, address _tokenB) external view returns (address pair_);

    /**
     * @notice return the address of the pair at index
     * @param _index index of the pair
     * @return pair_ address of the pair
     */
    function allPairs(uint256 _index) external view returns (address pair_);

    /**
     * @notice return the quantity of pairs
     * @return quantity in uint256
     */
    function allPairsLength() external view returns (uint256);

    /**
     * @notice return numerators of pair fees, denominator is 1_000_000
     * @return feesLP_ numerator of fees sent to LP at pair creation
     * @return feesPool_ numerator of fees sent to Pool at pair creation
     */
    function getDefaultFees() external view returns (uint128 feesLP_, uint128 feesPool_);

    /**
     * @notice whether whitelist is open
     * @return open_ true if the whitelist is open, false otherwise
     */
    function whitelistOpen() external view returns (bool open_);

    /**
     * @notice create pair with 2 address
     * @param _tokenA address of tokenA
     * @param _tokenB address of tokenB
     * @return pair_ address of the pair created
     */
    function createPair(address _tokenA, address _tokenB) external returns (address pair_);

    /**
     * @notice set the address who will receive fees, can only be call by the owner
     * @param _feeTo address to replace
     */
    function setFeeTo(address _feeTo) external;

    /**
     * @notice set feesLP and feesPool for each new pair (onlyOwner)
     * @notice sum of new feesLp and feesPool must be <= FEES_MAX = 10% FEES_BASE
     * @param _feesLP new numerator of fees sent to LP, must be >= 1
     * @param _feesPool new numerator of fees sent to Pool, could be = 0
     */
    function setFees(uint128 _feesLP, uint128 _feesPool) external;

    /**
     * @notice disable whitelist (onlyOwner)
     * whitelist cannot be re-opened after that.
     */
    function closeWhitelist() external;

    /**
     * @notice add a pair manually
     * @param _pair pair address to add (must be an ISmardexPair)
     */
    function addPair(address _pair) external;
}

File 20 of 25 : ISmardexMintCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.17;

interface ISmardexMintCallback {
    /**
     * @notice callback data for mint
     * @param token0 address of the first token of the pair
     * @param token1 address of the second token of the pair
     * @param amount0 amount of token0 to provide
     * @param amount1 amount of token1 to provide
     * @param payer address of the payer to provide token for the mint
     */
    struct MintCallbackData {
        address token0;
        address token1;
        uint256 amount0;
        uint256 amount1;
        address payer;
    }

    /**
     * @notice callback to implement when calling SmardexPair.mint
     * @param _data callback data for mint
     */
    function smardexMintCallback(MintCallbackData calldata _data) external;
}

File 21 of 25 : ISmardexOwnableFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.17;

import "./ISmardexFactory.sol";

/**
 * @notice the real interface of SmardexFactory, including owner's functions.
 *         Needs to be separate due to a missing IOwner interface of OpenZeppelin
 */
interface ISmardexOwnableFactory is ISmardexFactory {
    /**
     * @notice emitted each ownership transfer
     * @param previousOwner previous owner
     * @param newOwner new owner
     */
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the current owner.
     * @return address of the owner
     */
    function owner() external view returns (address);

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() external;

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     * @param _newOwner : address of the new owner
     */
    function transferOwnership(address _newOwner) external;
}

File 22 of 25 : ISmardexPair.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.17;

// interfaces
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";

interface ISmardexPair is IERC20, IERC20Permit {
    /**
     * @notice swap parameters used by function swap
     * @param amountCalculated return amount from getAmountIn/Out is always positive but to avoid too much cast, is int
     * @param fictiveReserveIn fictive reserve of the in-token of the pair
     * @param fictiveReserveOut fictive reserve of the out-token of the pair
     * @param priceAverageIn in-token ratio component of the price average
     * @param priceAverageOut out-token ratio component of the price average
     * @param token0 address of the token0
     * @param token1 address of the token1
     * @param balanceIn contract balance of the in-token
     * @param balanceOut contract balance of the out-token
     */
    struct SwapParams {
        int256 amountCalculated;
        uint256 fictiveReserveIn;
        uint256 fictiveReserveOut;
        uint256 priceAverageIn;
        uint256 priceAverageOut;
        address token0;
        address token1;
        uint256 balanceIn;
        uint256 balanceOut;
    }

    /**
     * @notice emitted at each mint
     * @param sender address calling the mint function (usually the Router contract)
     * @param to address that receives the LP-tokens
     * @param amount0 amount of token0 to be added in liquidity
     * @param amount1 amount of token1 to be added in liquidity
     * @dev the amount of LP-token sent can be caught using the transfer event of the pair
     */
    event Mint(address indexed sender, address indexed to, uint256 amount0, uint256 amount1);

    /**
     * @notice emitted at each burn
     * @param sender address calling the burn function (usually the Router contract)
     * @param to address that receives the tokens
     * @param amount0 amount of token0 to be withdrawn
     * @param amount1 amount of token1 to be withdrawn
     * @dev the amount of LP-token sent can be caught using the transfer event of the pair
     */
    event Burn(address indexed sender, address indexed to, uint256 amount0, uint256 amount1);

    /**
     * @notice emitted at each swap
     * @param sender address calling the swap function (usually the Router contract)
     * @param to address that receives the out-tokens
     * @param amount0 amount of token0 to be swapped
     * @param amount1 amount of token1 to be swapped
     * @dev one of the 2 amount is always negative, the other one is always positive. The positive one is the one that
     * the user send to the contract, the negative one is the one that the contract send to the user.
     */
    event Swap(address indexed sender, address indexed to, int256 amount0, int256 amount1);

    /**
     * @notice emitted each time the fictive reserves are changed (mint, burn, swap)
     * @param reserve0 the new reserve of token0
     * @param reserve1 the new reserve of token1
     * @param fictiveReserve0 the new fictive reserve of token0
     * @param fictiveReserve1 the new fictive reserve of token1
     * @param priceAverage0 the new priceAverage of token0
     * @param priceAverage1 the new priceAverage of token1
     */
    event Sync(
        uint256 reserve0,
        uint256 reserve1,
        uint256 fictiveReserve0,
        uint256 fictiveReserve1,
        uint256 priceAverage0,
        uint256 priceAverage1
    );

    /**
     * @notice emitted each time feesLP and feesPool are changed
     * @param feesLP new feesLP
     * @param feesPool new feesPool
     */
    event FeesChanged(uint256 indexed feesLP, uint256 indexed feesPool);

    /**
     * @notice get the factory address
     * @return address of the factory
     */
    function factory() external view returns (address);

    /**
     * @notice get the token0 address
     * @return address of the token0
     */
    function token0() external view returns (address);

    /**
     * @notice get the token1 address
     * @return address of the token1
     */
    function token1() external view returns (address);

    /**
     * @notice called once by the factory at time of deployment
     * @param _token0 address of token0
     * @param _token1 address of token1
     * @param _feesLP uint128 feesLP numerator
     * @param _feesPool uint128 feesPool numerator
     */
    function initialize(address _token0, address _token1, uint128 _feesLP, uint128 _feesPool) external;

    /**
     * @notice return current Reserves of both token in the pair,
     *  corresponding to token balance - pending fees
     * @return reserve0_ current reserve of token0 - pending fee0
     * @return reserve1_ current reserve of token1 - pending fee1
     */
    function getReserves() external view returns (uint256 reserve0_, uint256 reserve1_);

    /**
     * @notice return current fictive reserves of both token in the pair
     * @return fictiveReserve0_ current fictive reserve of token0
     * @return fictiveReserve1_ current fictive reserve of token1
     */
    function getFictiveReserves() external view returns (uint256 fictiveReserve0_, uint256 fictiveReserve1_);

    /**
     * @notice return current pending fees of both token in the pair
     * @return fees0_ current pending fees of token0
     * @return fees1_ current pending fees of token1
     */
    function getFeeToAmounts() external view returns (uint256 fees0_, uint256 fees1_);

    /**
     * @notice return numerators of pair fees, denominator is 1_000_000
     * @return feesLP_ numerator of fees sent to LP
     * @return feesPool_ numerator of fees sent to Pool
     */
    function getPairFees() external view returns (uint128 feesLP_, uint128 feesPool_);

    /**
     * @notice return last updated price average at timestamp of both token in the pair,
     *  read price0Average/price1Average for current price of token0/token1
     * @return priceAverage0_ current price for token0
     * @return priceAverage1_ current price for token1
     * @return blockTimestampLast_ last block timestamp when price was updated
     */
    function getPriceAverage()
        external
        view
        returns (uint256 priceAverage0_, uint256 priceAverage1_, uint256 blockTimestampLast_);

    /**
     * @notice return current price average of both token in the pair for provided currentTimeStamp
     *  read price0Average/price1Average for current price of token0/token1
     * @param _fictiveReserveIn,
     * @param _fictiveReserveOut,
     * @param _priceAverageLastTimestamp,
     * @param _priceAverageIn current price for token0
     * @param _priceAverageOut current price for token1
     * @param _currentTimestamp block timestamp to get price
     * @return priceAverageIn_ current price for token0
     * @return priceAverageOut_ current price for token1
     */
    function getUpdatedPriceAverage(
        uint256 _fictiveReserveIn,
        uint256 _fictiveReserveOut,
        uint256 _priceAverageLastTimestamp,
        uint256 _priceAverageIn,
        uint256 _priceAverageOut,
        uint256 _currentTimestamp
    ) external pure returns (uint256 priceAverageIn_, uint256 priceAverageOut_);

    /**
     * @notice Mint lp tokens proportionally of added tokens in balance. Should be called from a contract
     * that makes safety checks like the SmardexRouter
     * @param _to address who will receive minted tokens
     * @param _amount0 amount of token0 to provide
     * @param _amount1 amount of token1 to provide
     * @return liquidity_ amount of lp tokens minted and sent to the address defined in parameter
     */
    function mint(
        address _to,
        uint256 _amount0,
        uint256 _amount1,
        address _payer
    ) external returns (uint256 liquidity_);

    /**
     * @notice Burn lp tokens in the balance of the contract. Sends to the defined address the amount of token0 and
     * token1 proportionally of the amount burned. Should be called from a contract that makes safety checks like the
     * SmardexRouter
     * @param _to address who will receive tokens
     * @return amount0_ amount of token0 sent to the address defined in parameter
     * @return amount1_ amount of token0 sent to the address defined in parameter
     */
    function burn(address _to) external returns (uint256 amount0_, uint256 amount1_);

    /**
     * @notice Swaps tokens. Sends to the defined address the amount of token0 and token1 defined in parameters.
     * Tokens to trade should be already sent in the contract.
     * Swap function will check if the resulted balance is correct with current reserves and reserves fictive.
     * Should be called from a contract that makes safety checks like the SmardexRouter
     * @param _to address who will receive tokens
     * @param _zeroForOne token0 to token1
     * @param _amountSpecified amount of token wanted
     * @param _data used for flash swap, data.length must be 0 for regular swap
     */
    function swap(
        address _to,
        bool _zeroForOne,
        int256 _amountSpecified,
        bytes calldata _data
    ) external returns (int256 amount0_, int256 amount1_);

    /**
     * @notice set feesLP and feesPool of the pair
     * @notice sum of new feesLp and feesPool must be <= 100_000
     * @param _feesLP new numerator of fees sent to LP, must be >= 1
     * @param _feesPool new numerator of fees sent to Pool, could be = 0
     */
    function setFees(uint128 _feesLP, uint128 _feesPool) external;

    /**
     * @notice withdraw all reserve on the pair in case no liquidity has never been provided
     * @param _to address who will receive tokens
     */
    function skim(address _to) external;
}

File 23 of 25 : ISmardexSwapCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.17;

interface ISmardexSwapCallback {
    /**
     * @notice callback data for swap from SmardexRouter
     * @param path path of the swap, array of token addresses tightly packed
     * @param payer address of the payer for the swap
     */
    struct SwapCallbackData {
        bytes path;
        address payer;
    }

    /**
     * @notice callback data for swap
     * @param _amount0Delta amount of token0 for the swap (negative is incoming, positive is required to pay to pair)
     * @param _amount1Delta amount of token1 for the swap (negative is incoming, positive is required to pay to pair)
     * @param _data for Router path and payer for the swap (see router for details)
     */
    function smardexSwapCallback(int256 _amount0Delta, int256 _amount1Delta, bytes calldata _data) external;
}

File 24 of 25 : SmardexLibrary.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.17;

// libraries
import "@openzeppelin/contracts/utils/math/Math.sol";

// interfaces
import "../interfaces/ISmardexPair.sol";

library SmardexLibrary {
    /// @notice base of the FEES
    uint256 public constant FEES_BASE = 1_000_000;

    /// @notice max fees of feesLP and feesPool sum, 10% FEES_BASE
    uint256 public constant FEES_MAX = FEES_BASE / 10;

    /// @notice precision for approxEq, not in percent but in APPROX_PRECISION_BASE
    uint256 public constant APPROX_PRECISION = 1;

    /// @notice base of the APPROX_PRECISION
    uint256 public constant APPROX_PRECISION_BASE = 1_000_000;

    /// @notice number of seconds to reset priceAverage
    uint256 private constant MAX_BLOCK_DIFF_SECONDS = 300;

    /// @notice parameters of getAmountIn and getAmountOut
    struct GetAmountParameters {
        uint256 amount;
        uint256 reserveIn;
        uint256 reserveOut;
        uint256 fictiveReserveIn;
        uint256 fictiveReserveOut;
        uint256 priceAverageIn;
        uint256 priceAverageOut;
        uint128 feesLP;
        uint128 feesPool;
    }

    /**
     * @notice check if 2 numbers are approximately equal, using APPROX_PRECISION
     * @param _x number to compare
     * @param _y number to compare
     * @return true if numbers are approximately equal, false otherwise
     */
    function approxEq(uint256 _x, uint256 _y) internal pure returns (bool) {
        if (_x == _y) {
            return true;
        } else if (_x > _y) {
            return _x < (_y + (_y * APPROX_PRECISION) / APPROX_PRECISION_BASE);
        } else {
            return _y < (_x + (_x * APPROX_PRECISION) / APPROX_PRECISION_BASE);
        }
    }

    /**
     * @notice check if 2 ratio are approximately equal: _xNum _/ xDen ~= _yNum / _yDen
     * @param _xNum numerator of the first ratio to compare
     * @param _xDen denominator of the first ratio to compare
     * @param _yNum numerator of the second ratio to compare
     * @param _yDen denominator of the second ratio to compare
     * @return true if ratio are approximately equal, false otherwise
     */
    function ratioApproxEq(uint256 _xNum, uint256 _xDen, uint256 _yNum, uint256 _yDen) internal pure returns (bool) {
        return approxEq(_xNum * _yDen, _xDen * _yNum);
    }

    /**
     * @notice update priceAverage given old timestamp, new timestamp and prices
     * @param _fictiveReserveIn ratio component of the new price of the in-token
     * @param _fictiveReserveOut ratio component of the new price of the out-token
     * @param _priceAverageLastTimestamp timestamp of the last priceAverage update (0, if never updated)
     * @param _priceAverageIn ratio component of the last priceAverage of the in-token
     * @param _priceAverageOut ratio component of the last priceAverage of the out-token
     * @param _currentTimestamp timestamp of the priceAverage to update
     * @return newPriceAverageIn_ ratio component of the updated priceAverage of the in-token
     * @return newPriceAverageOut_ ratio component of the updated priceAverage of the out-token
     */
    function getUpdatedPriceAverage(
        uint256 _fictiveReserveIn,
        uint256 _fictiveReserveOut,
        uint256 _priceAverageLastTimestamp,
        uint256 _priceAverageIn,
        uint256 _priceAverageOut,
        uint256 _currentTimestamp
    ) internal pure returns (uint256 newPriceAverageIn_, uint256 newPriceAverageOut_) {
        require(_currentTimestamp >= _priceAverageLastTimestamp, "SmardexPair: INVALID_TIMESTAMP");

        // very first time
        if (_priceAverageLastTimestamp == 0) {
            newPriceAverageIn_ = _fictiveReserveIn;
            newPriceAverageOut_ = _fictiveReserveOut;
        }
        // another tx has been done in the same timestamp
        else if (_priceAverageLastTimestamp == _currentTimestamp) {
            newPriceAverageIn_ = _priceAverageIn;
            newPriceAverageOut_ = _priceAverageOut;
        }
        // need to compute new linear-average price
        else {
            // compute new price:
            uint256 _timeDiff = Math.min(_currentTimestamp - _priceAverageLastTimestamp, MAX_BLOCK_DIFF_SECONDS);

            newPriceAverageIn_ = _fictiveReserveIn;
            newPriceAverageOut_ =
                (((MAX_BLOCK_DIFF_SECONDS - _timeDiff) * _priceAverageOut * newPriceAverageIn_) /
                    _priceAverageIn +
                    _timeDiff *
                    _fictiveReserveOut) /
                MAX_BLOCK_DIFF_SECONDS;
        }
    }

    /**
     * @notice compute the firstTradeAmountIn so that the price reach the price Average
     * @param _param contain all params required from struct GetAmountParameters
     * @return firstAmountIn_ the first amount of in-token
     *
     * @dev if the trade is going in the direction that the price will never reach the priceAverage, or if _amountIn
     * is not big enough to reach the priceAverage or if the price is already equal to the priceAverage, then
     * firstAmountIn_ will be set to _amountIn
     */
    function computeFirstTradeQtyIn(GetAmountParameters memory _param) internal pure returns (uint256 firstAmountIn_) {
        // default value
        firstAmountIn_ = _param.amount;

        // if trade is in the good direction
        if (_param.fictiveReserveOut * _param.priceAverageIn > _param.fictiveReserveIn * _param.priceAverageOut) {
            // pre-compute all operands
            uint256 _toSub = _param.fictiveReserveIn * ((FEES_BASE * 2) - (_param.feesPool * 2) - _param.feesLP);
            uint256 _toDiv = (FEES_BASE - _param.feesPool) * 2;
            uint256 _inSqrt = (((_param.fictiveReserveIn * _param.fictiveReserveOut) * 4) / _param.priceAverageOut) *
                _param.priceAverageIn *
                ((FEES_BASE - _param.feesPool - _param.feesLP) * (FEES_BASE - _param.feesPool)) +
                ((_param.fictiveReserveIn * _param.fictiveReserveIn) * (_param.feesLP * _param.feesLP));

            // reverse sqrt check to only compute sqrt if really needed
            uint256 _inSqrtCompare = _toSub + _param.amount * _toDiv;
            if (_inSqrt < _inSqrtCompare * _inSqrtCompare) {
                firstAmountIn_ = (Math.sqrt(_inSqrt) - _toSub) / _toDiv;
            }
        }
    }

    /**
     * @notice compute the firstTradeAmountOut so that the price reach the price Average
     * @param _param contain all params required from struct GetAmountParameters
     * @return firstAmountOut_ the first amount of out-token
     *
     * @dev if the trade is going in the direction that the price will never reach the priceAverage, or if _amountOut
     * is not big enough to reach the priceAverage or if the price is already equal to the priceAverage, then
     * firstAmountOut_ will be set to _amountOut
     */
    function computeFirstTradeQtyOut(
        GetAmountParameters memory _param
    ) internal pure returns (uint256 firstAmountOut_) {
        // default value
        firstAmountOut_ = _param.amount;
        uint256 _reverseFeesTotal = FEES_BASE - _param.feesPool - _param.feesLP;
        // if trade is in the good direction
        if (_param.fictiveReserveOut * _param.priceAverageIn > _param.fictiveReserveIn * _param.priceAverageOut) {
            // pre-compute all operands
            uint256 _fictiveReserveOutPredFees = (_param.fictiveReserveIn * _param.feesLP * _param.priceAverageOut) /
                _param.priceAverageIn;
            uint256 _toAdd = ((_param.fictiveReserveOut * _reverseFeesTotal) * 2) + _fictiveReserveOutPredFees;
            uint256 _toDiv = _reverseFeesTotal * 2;

            uint256 _inSqrt = (((_param.fictiveReserveOut * _fictiveReserveOutPredFees) * 4) *
                (_reverseFeesTotal * (FEES_BASE - _param.feesPool))) /
                _param.feesLP +
                (_fictiveReserveOutPredFees * _fictiveReserveOutPredFees);

            // reverse sqrt check to only compute sqrt if really needed
            uint256 _inSqrtCompare = _toAdd - _param.amount * _toDiv;
            if (_inSqrt > _inSqrtCompare * _inSqrtCompare) {
                firstAmountOut_ = (_toAdd - Math.sqrt(_inSqrt)) / _toDiv;
            }
        }
    }

    /**
     * @notice compute fictive reserves
     * @param _reserveIn reserve of the in-token
     * @param _reserveOut reserve of the out-token
     * @param _fictiveReserveIn fictive reserve of the in-token
     * @param _fictiveReserveOut fictive reserve of the out-token
     * @return newFictiveReserveIn_ new fictive reserve of the in-token
     * @return newFictiveReserveOut_ new fictive reserve of the out-token
     */
    function computeFictiveReserves(
        uint256 _reserveIn,
        uint256 _reserveOut,
        uint256 _fictiveReserveIn,
        uint256 _fictiveReserveOut
    ) internal pure returns (uint256 newFictiveReserveIn_, uint256 newFictiveReserveOut_) {
        if (_reserveOut * _fictiveReserveIn < _reserveIn * _fictiveReserveOut) {
            uint256 _temp = (((_reserveOut * _reserveOut) / _fictiveReserveOut) * _fictiveReserveIn) / _reserveIn;
            newFictiveReserveIn_ =
                (_temp * _fictiveReserveIn) /
                _fictiveReserveOut +
                (_reserveOut * _fictiveReserveIn) /
                _fictiveReserveOut;
            newFictiveReserveOut_ = _reserveOut + _temp;
        } else {
            newFictiveReserveIn_ = (_fictiveReserveIn * _reserveOut) / _fictiveReserveOut + _reserveIn;
            newFictiveReserveOut_ = (_reserveIn * _fictiveReserveOut) / _fictiveReserveIn + _reserveOut;
        }

        // div all values by 4
        newFictiveReserveIn_ /= 4;
        newFictiveReserveOut_ /= 4;
    }

    /**
     * @notice apply k const rule using fictive reserve, when the amountIn is specified
     * @param _param contain all params required from struct GetAmountParameters
     * @return amountOut_ qty of token that leaves in the contract
     * @return newReserveIn_ new reserve of the in-token after the transaction
     * @return newReserveOut_ new reserve of the out-token after the transaction
     * @return newFictiveReserveIn_ new fictive reserve of the in-token after the transaction
     * @return newFictiveReserveOut_ new fictive reserve of the out-token after the transaction
     */
    function applyKConstRuleOut(
        GetAmountParameters memory _param
    )
        internal
        pure
        returns (
            uint256 amountOut_,
            uint256 newReserveIn_,
            uint256 newReserveOut_,
            uint256 newFictiveReserveIn_,
            uint256 newFictiveReserveOut_
        )
    {
        // k const rule
        uint256 _amountInWithFee = _param.amount * (FEES_BASE - _param.feesLP - _param.feesPool);
        uint256 _numerator = _amountInWithFee * _param.fictiveReserveOut;
        uint256 _denominator = _param.fictiveReserveIn * FEES_BASE + _amountInWithFee;
        amountOut_ = _numerator / _denominator;

        // update new reserves and add lp-fees to pools
        uint256 _amountInWithFeeLp = (_amountInWithFee + (_param.amount * _param.feesLP)) / FEES_BASE;
        newReserveIn_ = _param.reserveIn + _amountInWithFeeLp;
        newFictiveReserveIn_ = _param.fictiveReserveIn + _amountInWithFeeLp;
        newReserveOut_ = _param.reserveOut - amountOut_;
        newFictiveReserveOut_ = _param.fictiveReserveOut - amountOut_;
    }

    /**
     * @notice apply k const rule using fictive reserve, when the amountOut is specified
     * @param _param contain all params required from struct GetAmountParameters
     * @return amountIn_ qty of token that arrives in the contract
     * @return newReserveIn_ new reserve of the in-token after the transaction
     * @return newReserveOut_ new reserve of the out-token after the transaction
     * @return newFictiveReserveIn_ new fictive reserve of the in-token after the transaction
     * @return newFictiveReserveOut_ new fictive reserve of the out-token after the transaction
     */
    function applyKConstRuleIn(
        GetAmountParameters memory _param
    )
        internal
        pure
        returns (
            uint256 amountIn_,
            uint256 newReserveIn_,
            uint256 newReserveOut_,
            uint256 newFictiveReserveIn_,
            uint256 newFictiveReserveOut_
        )
    {
        // k const rule
        uint256 _numerator = _param.fictiveReserveIn * _param.amount * FEES_BASE;
        uint256 _denominator = (_param.fictiveReserveOut - _param.amount) *
            (FEES_BASE - _param.feesPool - _param.feesLP);
        amountIn_ = _numerator / _denominator + 1;

        // update new reserves
        uint256 _amountInWithFeeLp = (amountIn_ * (FEES_BASE - _param.feesPool)) / FEES_BASE;
        newReserveIn_ = _param.reserveIn + _amountInWithFeeLp;
        newFictiveReserveIn_ = _param.fictiveReserveIn + _amountInWithFeeLp;
        newReserveOut_ = _param.reserveOut - _param.amount;
        newFictiveReserveOut_ = _param.fictiveReserveOut - _param.amount;
    }

    /**
     * @notice return the amount of tokens the user would get by doing a swap
     * @param _param contain all params required from struct GetAmountParameters
     * @return amountOut_ The amount of token the user would receive
     * @return newReserveIn_ reserves of the selling token after the swap
     * @return newReserveOut_ reserves of the buying token after the swap
     * @return newFictiveReserveIn_ fictive reserve of the selling token after the swap
     * @return newFictiveReserveOut_ fictive reserve of the buying token after the swap
     */
    function getAmountOut(
        GetAmountParameters memory _param
    )
        internal
        pure
        returns (
            uint256 amountOut_,
            uint256 newReserveIn_,
            uint256 newReserveOut_,
            uint256 newFictiveReserveIn_,
            uint256 newFictiveReserveOut_
        )
    {
        require(_param.amount != 0, "SmarDexLibrary: INSUFFICIENT_INPUT_AMOUNT");
        require(
            _param.reserveIn != 0 &&
                _param.reserveOut != 0 &&
                _param.fictiveReserveIn != 0 &&
                _param.fictiveReserveOut != 0,
            "SmarDexLibrary: INSUFFICIENT_LIQUIDITY"
        );

        uint256 _amountInWithFees = (_param.amount * (FEES_BASE - _param.feesPool - _param.feesLP)) / FEES_BASE;
        uint256 _firstAmountIn = computeFirstTradeQtyIn(
            SmardexLibrary.GetAmountParameters({
                amount: _amountInWithFees,
                reserveIn: _param.reserveIn,
                reserveOut: _param.reserveOut,
                fictiveReserveIn: _param.fictiveReserveIn,
                fictiveReserveOut: _param.fictiveReserveOut,
                priceAverageIn: _param.priceAverageIn,
                priceAverageOut: _param.priceAverageOut,
                feesLP: _param.feesLP,
                feesPool: _param.feesPool
            })
        );

        // if there is 2 trade: 1st trade mustn't re-compute fictive reserves, 2nd should
        if (
            _firstAmountIn == _amountInWithFees &&
            ratioApproxEq(
                _param.fictiveReserveIn,
                _param.fictiveReserveOut,
                _param.priceAverageIn,
                _param.priceAverageOut
            )
        ) {
            (_param.fictiveReserveIn, _param.fictiveReserveOut) = computeFictiveReserves(
                _param.reserveIn,
                _param.reserveOut,
                _param.fictiveReserveIn,
                _param.fictiveReserveOut
            );
        }

        // avoid stack too deep
        {
            uint256 _firstAmountInNoFees = (_firstAmountIn * FEES_BASE) / (FEES_BASE - _param.feesPool - _param.feesLP);
            (
                amountOut_,
                newReserveIn_,
                newReserveOut_,
                newFictiveReserveIn_,
                newFictiveReserveOut_
            ) = applyKConstRuleOut(
                SmardexLibrary.GetAmountParameters({
                    amount: _firstAmountInNoFees,
                    reserveIn: _param.reserveIn,
                    reserveOut: _param.reserveOut,
                    fictiveReserveIn: _param.fictiveReserveIn,
                    fictiveReserveOut: _param.fictiveReserveOut,
                    priceAverageIn: _param.priceAverageIn,
                    priceAverageOut: _param.priceAverageOut,
                    feesLP: _param.feesLP,
                    feesPool: _param.feesPool
                })
            );

            // update amountIn in case there is a second trade
            _param.amount -= _firstAmountInNoFees;
        }

        // if we need a second trade
        if (_firstAmountIn < _amountInWithFees) {
            // in the second trade ALWAYS recompute fictive reserves
            (newFictiveReserveIn_, newFictiveReserveOut_) = computeFictiveReserves(
                newReserveIn_,
                newReserveOut_,
                newFictiveReserveIn_,
                newFictiveReserveOut_
            );

            uint256 _secondAmountOutNoFees;
            (
                _secondAmountOutNoFees,
                newReserveIn_,
                newReserveOut_,
                newFictiveReserveIn_,
                newFictiveReserveOut_
            ) = applyKConstRuleOut(
                SmardexLibrary.GetAmountParameters({
                    amount: _param.amount,
                    reserveIn: newReserveIn_,
                    reserveOut: newReserveOut_,
                    fictiveReserveIn: newFictiveReserveIn_,
                    fictiveReserveOut: newFictiveReserveOut_,
                    priceAverageIn: _param.priceAverageIn,
                    priceAverageOut: _param.priceAverageOut,
                    feesLP: _param.feesLP,
                    feesPool: _param.feesPool
                })
            );
            amountOut_ += _secondAmountOutNoFees;
        }
    }

    /**
     * @notice return the amount of tokens the user should spend by doing a swap
     * @param _param contain all params required from struct GetAmountParameters
     * @return amountIn_ The amount of token the user would spend to receive _amountOut
     * @return newReserveIn_ reserves of the selling token after the swap
     * @return newReserveOut_ reserves of the buying token after the swap
     * @return newFictiveReserveIn_ fictive reserve of the selling token after the swap
     * @return newFictiveReserveOut_ fictive reserve of the buying token after the swap
     */
    function getAmountIn(
        GetAmountParameters memory _param
    )
        internal
        pure
        returns (
            uint256 amountIn_,
            uint256 newReserveIn_,
            uint256 newReserveOut_,
            uint256 newFictiveReserveIn_,
            uint256 newFictiveReserveOut_
        )
    {
        require(_param.amount != 0, "SmarDexLibrary: INSUFFICIENT_OUTPUT_AMOUNT");
        require(
            _param.amount < _param.fictiveReserveOut &&
                _param.reserveIn != 0 &&
                _param.reserveOut != 0 &&
                _param.fictiveReserveIn != 0 &&
                _param.fictiveReserveOut != 0,
            "SmarDexLibrary: INSUFFICIENT_LIQUIDITY"
        );

        uint256 _firstAmountOut = computeFirstTradeQtyOut(_param);

        // if there is 2 trade: 1st trade mustn't re-compute fictive reserves, 2nd should
        if (
            _firstAmountOut == _param.amount &&
            ratioApproxEq(
                _param.fictiveReserveIn,
                _param.fictiveReserveOut,
                _param.priceAverageIn,
                _param.priceAverageOut
            )
        ) {
            (_param.fictiveReserveIn, _param.fictiveReserveOut) = computeFictiveReserves(
                _param.reserveIn,
                _param.reserveOut,
                _param.fictiveReserveIn,
                _param.fictiveReserveOut
            );
        }

        (amountIn_, newReserveIn_, newReserveOut_, newFictiveReserveIn_, newFictiveReserveOut_) = applyKConstRuleIn(
            SmardexLibrary.GetAmountParameters({
                amount: _firstAmountOut,
                reserveIn: _param.reserveIn,
                reserveOut: _param.reserveOut,
                fictiveReserveIn: _param.fictiveReserveIn,
                fictiveReserveOut: _param.fictiveReserveOut,
                priceAverageIn: _param.priceAverageIn,
                priceAverageOut: _param.priceAverageOut,
                feesLP: _param.feesLP,
                feesPool: _param.feesPool
            })
        );

        // if we need a second trade
        if (_firstAmountOut < _param.amount) {
            // in the second trade ALWAYS recompute fictive reserves
            (newFictiveReserveIn_, newFictiveReserveOut_) = computeFictiveReserves(
                newReserveIn_,
                newReserveOut_,
                newFictiveReserveIn_,
                newFictiveReserveOut_
            );

            uint256 _secondAmountIn;
            (
                _secondAmountIn,
                newReserveIn_,
                newReserveOut_,
                newFictiveReserveIn_,
                newFictiveReserveOut_
            ) = applyKConstRuleIn(
                SmardexLibrary.GetAmountParameters({
                    amount: _param.amount - _firstAmountOut,
                    reserveIn: newReserveIn_,
                    reserveOut: newReserveOut_,
                    fictiveReserveIn: newFictiveReserveIn_,
                    fictiveReserveOut: newFictiveReserveOut_,
                    priceAverageIn: _param.priceAverageIn,
                    priceAverageOut: _param.priceAverageOut,
                    feesLP: _param.feesLP,
                    feesPool: _param.feesPool
                })
            );
            amountIn_ += _secondAmountIn;
        }
    }
}

File 25 of 25 : TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity =0.8.17;

/**
 * @title TransferHelper
 * @notice helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
 * @custom:from Uniswap lib, adapted to version 0.8.17
 * @custom:url https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/TransferHelper.sol
 */
library TransferHelper {
    function safeApprove(address token, address to, uint256 value) internal {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper::safeApprove: approve failed"
        );
    }

    function safeTransfer(address token, address to, uint256 value) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper::safeTransfer: transfer failed"
        );
    }

    function safeTransferFrom(address token, address from, address to, uint256 value) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper::transferFrom: transferFrom failed"
        );
    }

    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{ value: value }(new bytes(0));
        require(success, "TransferHelper::safeTransferETH: ETH transfer failed");
    }
}

Settings
{
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"feesLP","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"feesPool","type":"uint256"}],"name":"FeesChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"int256","name":"amount0","type":"int256"},{"indexed":false,"internalType":"int256","name":"amount1","type":"int256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reserve0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reserve1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fictiveReserve0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fictiveReserve1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"priceAverage0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"priceAverage1","type":"uint256"}],"name":"Sync","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0_","type":"uint256"},{"internalType":"uint256","name":"amount1_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFeeToAmounts","outputs":[{"internalType":"uint256","name":"fees0_","type":"uint256"},{"internalType":"uint256","name":"fees1_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFictiveReserves","outputs":[{"internalType":"uint256","name":"fictiveReserve0_","type":"uint256"},{"internalType":"uint256","name":"fictiveReserve1_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPairFees","outputs":[{"internalType":"uint128","name":"feesLP_","type":"uint128"},{"internalType":"uint128","name":"feesPool_","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPriceAverage","outputs":[{"internalType":"uint256","name":"priceAverage0_","type":"uint256"},{"internalType":"uint256","name":"priceAverage1_","type":"uint256"},{"internalType":"uint256","name":"priceAverageLastTimestamp_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReserves","outputs":[{"internalType":"uint256","name":"reserve0_","type":"uint256"},{"internalType":"uint256","name":"reserve1_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fictiveReserveIn","type":"uint256"},{"internalType":"uint256","name":"_fictiveReserveOut","type":"uint256"},{"internalType":"uint256","name":"_priceAverageLastTimestamp","type":"uint256"},{"internalType":"uint256","name":"_priceAverageIn","type":"uint256"},{"internalType":"uint256","name":"_priceAverageOut","type":"uint256"},{"internalType":"uint256","name":"_currentTimestamp","type":"uint256"}],"name":"getUpdatedPriceAverage","outputs":[{"internalType":"uint256","name":"priceAverageIn_","type":"uint256"},{"internalType":"uint256","name":"priceAverageOut_","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token0","type":"address"},{"internalType":"address","name":"_token1","type":"address"},{"internalType":"uint128","name":"_feesLP","type":"uint128"},{"internalType":"uint128","name":"_feesPool","type":"uint128"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount0","type":"uint256"},{"internalType":"uint256","name":"_amount1","type":"uint256"},{"internalType":"address","name":"_payer","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"liquidity_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"_feesLP","type":"uint128"},{"internalType":"uint128","name":"_feesPool","type":"uint128"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"skim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"bool","name":"_zeroForOne","type":"bool"},{"internalType":"int256","name":"_amountSpecified","type":"int256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"swap","outputs":[{"internalType":"int256","name":"amount0_","type":"int256"},{"internalType":"int256","name":"amount1_","type":"int256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

610180604052600b80546001600160801b0319166001179055600e80546001600160f81b0316600160f81b1790553480156200003a57600080fd5b506040518060400160405280601081526020016f29b6b0b92232bc10262816aa37b5b2b760811b81525080604051806040016040528060018152602001603160f81b8152506040518060400160405280601081526020016f29b6b0b92232bc10262816aa37b5b2b760811b815250604051806040016040528060078152602001660534445582d4c560cc1b8152508160039081620000d991906200030a565b506004620000e882826200030a565b50505062000106600583620001c660201b62001a1e1790919060201c565b6101205262000123816006620001c6602090811b62001a1e17901c565b61014052815160208084019190912060e052815190820120610100524660a052620001b160e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60805250503060c0525033610160526200044b565b6000602083511015620001e657620001de8362000216565b905062000210565b82620001fd836200026260201b62001a4f1760201c565b906200020a90826200030a565b5060ff90505b92915050565b600080829050601f815111156200024d578260405163305a27a960e01b8152600401620002449190620003d6565b60405180910390fd5b80516200025a8262000426565b179392505050565b90565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200029057607f821691505b602082108103620002b157634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200030557600081815260208120601f850160051c81016020861015620002e05750805b601f850160051c820191505b818110156200030157828155600101620002ec565b5050505b505050565b81516001600160401b0381111562000326576200032662000265565b6200033e816200033784546200027b565b84620002b7565b602080601f8311600181146200037657600084156200035d5750858301515b600019600386901b1c1916600185901b17855562000301565b600085815260208120601f198616915b82811015620003a75788860151825594840194600190910190840162000386565b5085821015620003c65787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600060208083528351808285015260005b818110156200040557858101830151858201604001528201620003e7565b506000604082860101526040601f19601f8301168501019250505092915050565b80516020808301519190811015620002b15760001960209190910360031b1b16919050565b60805160a05160c05160e05161010051610120516101405161016051614daf620004d4600039600081816104050152818161069d015281816111d40152818161142701528181612f3e0152613e62015260006115920152600061156701526000612a7f01526000612a57015260006129b2015260006129dc01526000612a060152614daf6000f3fe608060405234801561001057600080fd5b50600436106101d95760003560e01c806384b0196e11610104578063bc25cf77116100a2578063dd62ed3e11610071578063dd62ed3e1461044d578063ee2046c714610460578063f74bfe8e1461049c578063fb753b69146104af57600080fd5b8063bc25cf77146103ed578063c45a015514610400578063d21220a714610427578063d505accf1461043a57600080fd5b80639a20767b116100de5780639a20767b14610389578063a457c2d7146103a5578063a6706e14146103b8578063a9059cbb146103da57600080fd5b806384b0196e1461035357806389afcb441461036e57806395d89b411461038157600080fd5b80631f18b3711161017c5780633644e5151161014b5780633644e515146102fc578063395093511461030457806370a08231146103175780637ecebe001461034057600080fd5b80631f18b371146102b457806323b872dd146102c7578063313ce567146102da57806332760c7a146102e957600080fd5b8063095ea7b3116101b8578063095ea7b31461023f5780630dfe168114610262578063123a456a1461028d57806318160ddd146102a257600080fd5b80623b15fd146101de57806306fdde031461020d5780630902f1ac14610222575b600080fd5b600b54604080516001600160801b038084168252600160801b9093049092166020830152015b60405180910390f35b6102156104c2565b6040516102049190614608565b61022a610554565b60408051928352602083019190915201610204565b61025261024d366004614630565b610678565b6040519015158152602001610204565b600954610275906001600160a01b031681565b6040516001600160a01b039091168152602001610204565b6102a061029b366004614673565b610692565b005b6002545b604051908152602001610204565b61022a6102c23660046146d9565b610744565b6102526102d5366004614778565b611401565b60405160128152602001610204565b6102a06102f73660046147b9565b611425565b6102a661150a565b610252610312366004614630565b611519565b6102a66103253660046147ec565b6001600160a01b031660009081526020819052604090205490565b6102a661034e3660046147ec565b61153b565b61035b611559565b6040516102049796959493929190614809565b61022a61037c3660046147ec565b6115e2565b610215611600565b600c546001600160801b0380821691600160801b90041661022a565b6102526103b3366004614630565b61160f565b600e546001600160681b03600160281b8204811691600160901b90041661022a565b6102526103e8366004614630565b61168a565b6102a06103fb3660046147ec565b611698565b6102757f000000000000000000000000000000000000000000000000000000000000000081565b600a54610275906001600160a01b031681565b6102a061044836600461489f565b61184f565b6102a661045b366004614916565b6119b3565b600d54600e54604080516001600160801b038085168252600160801b909404909316602084015264ffffffffff90911690820152606001610204565b6102a66104aa36600461494f565b6119de565b61022a6104bd366004614999565b6119fe565b6060600380546104d1906149dc565b80601f01602080910402602001604051908101604052809291908181526020018280546104fd906149dc565b801561054a5780601f1061051f5761010080835404028352916020019161054a565b820191906000526020600020905b81548152906001019060200180831161052d57829003601f168201915b5050505050905090565b600e546009546040516370a0823160e01b81523060048201526000928392600160281b9091046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156105b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105da9190614a10565b6105e49190614a3f565b600e54600a546040516370a0823160e01b8152306004820152929450600160901b9091046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610644573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106689190614a10565b6106729190614a3f565b90509091565b600033610686818585611a52565b60019150505b92915050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146107045760405162461bcd60e51b815260206004820152601260248201527129b6b0b92232bc1d102327a92124a22222a760711b60448201526064015b60405180910390fd5b600980546001600160a01b038087166001600160a01b031992831617909255600a80549286169290911691909117905561073e8282611b76565b50505050565b600e546000908190600160f81b900460ff166001146107755760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b17905560008590036107d25760405162461bcd60e51b815260206004820152601460248201527314db585c91195e0e8816915493d7d05353d5539560621b60448201526064016106fb565b604080516101208101825260008082526020820181905291810182905260608101829052608081018290526009546001600160a01b0390811660a08301819052600a54821660c084015260e0830184905261010083019390935290919089161480159061085557508060c001516001600160a01b0316886001600160a01b031614155b6108975760405162461bcd60e51b8152602060048201526013602482015272536d61724465783a20494e56414c49445f544f60681b60448201526064016106fb565b866109de57600e5460c08201516040516370a0823160e01b8152306004820152600160901b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156108fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091f9190614a10565b6109299190614a3f565b600e5460a08301516040516370a0823160e01b8152306004820152600160281b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610988573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ac9190614a10565b6109b69190614a3f565b600c54600d546001600160801b03600160801b80840482169382169290810482169116610b1f565b600e5460a08201516040516370a0823160e01b8152306004820152600160281b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610a3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a619190614a10565b610a6b9190614a3f565b600e5460c08301516040516370a0823160e01b8152306004820152600160901b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610aca573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aee9190614a10565b610af89190614a3f565b600c54600d546001600160801b0380831692600160801b9081900482169280831692919004165b6001600160801b0390811660808801819052918116606088018190529281166040880181905293166020870181905261010087019490945260e0860194909452600e54610b779464ffffffffff909116919042611c72565b6080830152606082015286610ba657610b938160800151611d61565b610ba08260600151611d61565b42610bc2565b610bb38160600151611d61565b610bc08260800151611d61565b425b600e805464ffffffffff90921664ffffffffff199092169190911790556001600160801b03918216908216600160801b9081026fffffffffffffffffffffffffffffffff191691909117600d55600b5404166000871315610cd0576000610caf604051806101200160405280610c378b611dce565b81526020018560e001518152602001856101000151815260200185602001518152602001856040015181526020018560600151815260200185608001518152602001600b60009054906101000a90046001600160801b03166001600160801b03168152602001846001600160801b0316815250611e20565b6040880152602087015250909150610cc89050816121a1565b835250610d88565b6000610d6b604051806101200160405280610cf38b610cee90614a7b565b611dce565b81526020018560e001518152602001856101000151815260200185602001518152602001856040015181526020018560600151815260200185608001518152602001600b60009054906101000a90046001600160801b03166001600160801b03168152602001846001600160801b031681525061220b565b6040880152602087015250909150610d849050816121a1565b8352505b87610daf5760008713610d9e5781518790610dcc565b8151610da990614a7b565b87610dcc565b60008713610dbf57815187610dcc565b81518790610dcc90614a7b565b90945092508715610fd3576000831215610df857610df88260c001518a85610df390614a7b565b612480565b60405163a1dab4eb60e01b8152339063a1dab4eb90610e2190879087908b908b90600401614a97565b600060405180830381600087803b158015610e3b57600080fd5b505af1158015610e4f573d6000803e3d6000fd5b5050505060e08201516009546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610ea0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ec49190614a10565b60e08401819052610ed486611dce565b600e54610ef190600160281b90046001600160681b031684614ad4565b610efb9190614ad4565b1115610f5b5760405162461bcd60e51b815260206004820152602960248201527f536d61724465783a20494e53554646494349454e545f544f4b454e305f494e50604482015268155517d05353d5539560ba1b60648201526084016106fb565b600a546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610fa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fc79190614a10565b610100840152506111c6565b6000841215610fef57610fef8260a001518a86610df390614a7b565b60405163a1dab4eb60e01b8152339063a1dab4eb9061101890879087908b908b90600401614a97565b600060405180830381600087803b15801561103257600080fd5b505af1158015611046573d6000803e3d6000fd5b5050505060e0820151600a546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015611097573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110bb9190614a10565b60e084018190526110cb85611dce565b600e546110e890600160901b90046001600160681b031684614ad4565b6110f29190614ad4565b11156111525760405162461bcd60e51b815260206004820152602960248201527f536d61724465783a20494e53554646494349454e545f544f4b454e315f494e50604482015268155517d05353d5539560ba1b60648201526084016106fb565b6009546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa15801561119a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111be9190614a10565b610100840152505b6000806001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663017e7e586040518163ffffffff1660e01b8152600401602060405180830381865afa158015611230573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112549190614ae7565b6001600160a01b03161415905088156113095780156112dd57611296620f42406112876001600160801b03851688614b04565b6112919190614b31565b6125b1565b600e80546005906112b8908490600160281b90046001600160681b0316614b53565b92506101000a8154816001600160681b0302191690836001600160681b031602179055505b6113048360e00151846101000151856020015186604001518760600151886080015161261a565b611397565b801561137057611329620f42406112876001600160801b03851687614b04565b600e805460129061134b908490600160901b90046001600160681b0316614b53565b92506101000a8154816001600160681b0302191690836001600160681b031602179055505b6113978361010001518460e00151856040015186602001518760800151886060015161261a565b60408051868152602081018690526001600160a01b038c169133917fa4228e1eb11eb9b31069d9ed20e7af9a010ca1a02d4855cee54e08e188fcc32c910160405180910390a35050600e80546001600160f81b0316600160f81b1790555090969095509350505050565b60003361140f85828561278d565b61141a858585612801565b506001949350505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611483573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a79190614ae7565b6001600160a01b0316336001600160a01b0316146114fc5760405162461bcd60e51b815260206004820152601260248201527129b6b0b92232bc1d102727aa2fa7aba722a960711b60448201526064016106fb565b6115068282611b76565b5050565b60006115146129a5565b905090565b60003361068681858561152c83836119b3565b6115369190614ad4565b611a52565b6001600160a01b03811660009081526007602052604081205461068c565b60006060808280808361158d7f00000000000000000000000000000000000000000000000000000000000000006005612ad0565b6115b87f00000000000000000000000000000000000000000000000000000000000000006006612ad0565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6000806115ee83612b74565b90925090506115fb612f3a565b915091565b6060600480546104d1906149dc565b6000338161161d82866119b3565b90508381101561167d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016106fb565b61141a8286868403611a52565b600033610686818585612801565b600e54600160f81b900460ff166001146116c45760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b179055600254156117295760405162461bcd60e51b815260206004820152601860248201527f536d61724465783a204f4e4c595f454d5054595f50414952000000000000000060448201526064016106fb565b600954600a546040516370a0823160e01b81523060048201526001600160a01b03928316929091169060009083906370a0823190602401602060405180830381865afa15801561177d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a19190614a10565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156117eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180f9190614a10565b9050811561182257611822848684612480565b801561183357611833838683612480565b5050600e80546001600160f81b0316600160f81b179055505050565b8342111561189f5760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e6500000060448201526064016106fb565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886118ce8c6130c5565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000611929826130ed565b905060006119398287878761311a565b9050896001600160a01b0316816001600160a01b03161461199c5760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e6174757265000060448201526064016106fb565b6119a78a8a8a611a52565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60006119ec85858585613142565b90506119f6612f3a565b949350505050565b600080611a0f888888888888611c72565b90999098509650505050505050565b6000602083511015611a3a57611a33836136ad565b905061068c565b81611a458482614bde565b5060ff905061068c565b90565b6001600160a01b038316611ab45760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016106fb565b6001600160a01b038216611b155760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016106fb565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b816001600160801b0316600003611bc75760405162461bcd60e51b81526020600482015260156024820152740536d61724465783a205a45524f5f464545535f4c5605c1b60448201526064016106fb565b611bd5600a620f4240614b31565b611bdf8284614c9e565b6001600160801b03161115611c2a5760405162461bcd60e51b81526020600482015260116024820152700a6dac2e488caf074408c8a8aa6be9a82b607b1b60448201526064016106fb565b6001600160801b03828116600160801b9183169182028117600b556040517f64f84976d9c917a44796104a59950fdbd9b3c16a5dd348b546d738301f6bd06890600090a35050565b60008085831015611cc55760405162461bcd60e51b815260206004820152601e60248201527f536d6172646578506169723a20494e56414c49445f54494d455354414d50000060448201526064016106fb565b85600003611cd7575086905085611d56565b828603611ce8575083905082611d56565b6000611cff611cf78886614a3f565b61012c6136eb565b899350905061012c611d118983614b04565b878588611d208661012c614a3f565b611d2a9190614b04565b611d349190614b04565b611d3e9190614b31565b611d489190614ad4565b611d529190614b31565b9150505b965096945050505050565b60006001600160801b03821115611dca5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b60648201526084016106fb565b5090565b600080821215611dca5760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f73697469766560448201526064016106fb565b60008060008060008560000151600003611e8e5760405162461bcd60e51b815260206004820152602960248201527f536d61724465784c6962726172793a20494e53554646494349454e545f494e50604482015268155517d05353d5539560ba1b60648201526084016106fb565b602086015115801590611ea45750604086015115155b8015611eb35750606086015115155b8015611ec25750608086015115155b611ede5760405162461bcd60e51b81526004016106fb90614cbe565b6000620f42408760e001516001600160801b03168861010001516001600160801b0316620f4240611f0f9190614a3f565b611f199190614a3f565b8851611f259190614b04565b611f2f9190614b31565b90506000611fae6040518061012001604052808481526020018a6020015181526020018a6040015181526020018a6060015181526020018a6080015181526020018a60a0015181526020018a60c0015181526020018a60e001516001600160801b031681526020018a61010001516001600160801b0316815250613703565b90508181148015611fd65750611fd6886060015189608001518a60a001518b60c00151613900565b1561200257611ff7886020015189604001518a606001518b60800151613927565b60808a015260608901525b60008860e001516001600160801b03168961010001516001600160801b0316620f424061202f9190614a3f565b6120399190614a3f565b612046620f424084614b04565b6120509190614b31565b90506120cd6040518061012001604052808381526020018b6020015181526020018b6040015181526020018b6060015181526020018b6080015181526020018b60a0015181526020018b60c0015181526020018b60e001516001600160801b031681526020018b61010001516001600160801b0316815250613a23565b8d51949c50929a509098509650945081908a906120eb908390614a3f565b90525050818110156121965761210386868686613927565b8094508195505050600061217c6040518061012001604052808b6000015181526020018981526020018881526020018781526020018681526020018b60a0015181526020018b60c0015181526020018b60e001516001600160801b031681526020018b61010001516001600160801b0316815250613a23565b929a509098509650945090506121928189614ad4565b9750505b505091939590929450565b60006001600160ff1b03821115611dca5760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b60648201526084016106fb565b6000806000806000856000015160000361227a5760405162461bcd60e51b815260206004820152602a60248201527f536d61724465784c6962726172793a20494e53554646494349454e545f4f555460448201526914155517d05353d5539560b21b60648201526084016106fb565b608086015186511080156122915750602086015115155b80156122a05750604086015115155b80156122af5750606086015115155b80156122be5750608086015115155b6122da5760405162461bcd60e51b81526004016106fb90614cbe565b60006122e587613b3f565b87519091508114801561230f575061230f876060015188608001518960a001518a60c00151613900565b1561233b576123308760200151886040015189606001518a60800151613927565b608089015260608801525b6123b6604051806101200160405280838152602001896020015181526020018960400151815260200189606001518152602001896080015181526020018960a0015181526020018960c0015181526020018960e001516001600160801b031681526020018961010001516001600160801b0316815250613cf2565b8b51949a5092985090965094509250811015612476576123d885858585613927565b8093508194505050600061245c604051806101200160405280848b600001516124019190614a3f565b81526020018881526020018781526020018681526020018581526020018a60a0015181526020018a60c0015181526020018a60e001516001600160801b031681526020018a61010001516001600160801b0316815250613cf2565b9299509097509550935090506124728188614ad4565b9650505b5091939590929450565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916124dc9190614d04565b6000604051808303816000865af19150503d8060008114612519576040519150601f19603f3d011682016040523d82523d6000602084013e61251e565b606091505b50915091508180156125485750805115806125485750808060200190518101906125489190614d20565b6125aa5760405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b60648201526084016106fb565b5050505050565b60006001600160681b03821115611dca5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663034206269747360c81b60648201526084016106fb565b831580159061262857508215155b61267e5760405162461bcd60e51b815260206004820152602160248201527f536d61724465783a20464943544956455f52455345525645535f544f4f5f4c4f6044820152605760f81b60648201526084016106fb565b6001600160801b03841180159061269c57506001600160801b038311155b6126dc5760405162461bcd60e51b8152602060048201526011602482015270536d61724465783a204f564552464c4f5760781b60448201526064016106fb565b6001600160801b03838116600160801b0290851617600c55600e547f2a368c7f33bb86e2d999940a3989d849031aff29b750f67947e6b8e8c3d2ffd690612734906001600160681b03600160281b9091041688614a3f565b600e5461275190600160901b90046001600160681b031688614a3f565b6040805192835260208301919091528101869052606081018590526080810184905260a0810183905260c00160405180910390a1505050505050565b600061279984846119b3565b9050600019811461073e57818110156127f45760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016106fb565b61073e8484848403611a52565b6001600160a01b0383166128655760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016106fb565b6001600160a01b0382166128c75760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016106fb565b6001600160a01b0383166000908152602081905260409020548181101561293f5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016106fb565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a361073e565b6000306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161480156129fe57507f000000000000000000000000000000000000000000000000000000000000000046145b15612a2857507f000000000000000000000000000000000000000000000000000000000000000090565b611514604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b606060ff8314612ae357611a3383613e1e565b818054612aef906149dc565b80601f0160208091040260200160405190810160405280929190818152602001828054612b1b906149dc565b8015612b685780601f10612b3d57610100808354040283529160200191612b68565b820191906000526020600020905b815481529060010190602001808311612b4b57829003601f168201915b5050505050905061068c565b600e546000908190600160f81b900460ff16600114612ba55760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b179055612bc2613e5d565b50600954600a546040516370a0823160e01b81523060048201526001600160a01b03928316929091169060009083906370a0823190602401602060405180830381865afa158015612c17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c3b9190614a10565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612c85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ca99190614a10565b306000908152602081905260409020546002549192509080612ccb8584614b04565b612cd59190614b31565b975080612ce28484614b04565b612cec9190614b31565b96508715801590612cfc57508615155b612d575760405162461bcd60e51b815260206004820152602660248201527f536d61724465783a20494e53554646494349454e545f4c49515549444954595f60448201526510955493915160d21b60648201526084016106fb565b600c546001600160801b0380821691600160801b90041682612d798584614b04565b612d839190614b31565b612d8d9083614a3f565b915082612d9a8583614b04565b612da49190614b31565b612dae9082614a3f565b9050612dba3085613fa4565b612dc5888c8c612480565b612dd0878c8b612480565b6040516370a0823160e01b81523060048201526001600160a01b038916906370a0823190602401602060405180830381865afa158015612e14573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e389190614a10565b6040516370a0823160e01b81523060048201529096506001600160a01b038816906370a0823190602401602060405180830381865afa158015612e7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ea39190614a10565b600d54909550612ece9087908790859085906001600160801b0380821691600160801b90041661261a565b604080518b8152602081018b90526001600160a01b038d169133917f5d624aa9c148153ab3446c1b154f660ee7701e549fe9b62dab7171b1c80e6fa2910160405180910390a35050600e80546001600160f81b0316600160f81b17905550959794965093945050505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663017e7e586040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fbe9190614ae7565b604080518082018252601c81527f65786563757465576f726b28616464726573732c616464726573732900000000602091820152600954600a5483516001600160a01b039283166024820152908216604480830191909152845180830390910181526064909101845291820180516001600160e01b0316633048c02960e01b1790529151929350908316916130539190614d04565b6000604051808303816000865af19150503d8060008114613090576040519150601f19603f3d011682016040523d82523d6000602084013e613095565b606091505b5050505a6000036130c25760405162461bcd60e51b815260206004820152600060248201526044016106fb565b50565b6001600160a01b03811660009081526007602052604090208054600181018255905b50919050565b600061068c6130fa6129a5565b8360405161190160f01b8152600281019290925260228201526042902090565b600080600061312b878787876140d6565b915091506131388161419a565b5095945050505050565b600e54600090600160f81b900460ff166001146131715760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b17905561318e613e5d565b506009546040516370a0823160e01b8152306004820152600091829182916001600160a01b0316906370a0823190602401602060405180830381865afa1580156131dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132009190614a10565b600a546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa15801561324e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132729190614a10565b9050600061327f60025490565b6040805160a0810182526009546001600160a01b039081168252600a548116602083019081528284018e8152606084018e81528d841660808601908152955163797c4a1360e01b815294518416600486015291518316602485015251604484015251606483015291519091166084820152909150339063797c4a139060a401600060405180830381600087803b15801561331857600080fd5b505af115801561332c573d6000803e3d6000fd5b50506009546040516370a0823160e01b8152306004820152600093506001600160a01b0390911691506370a0823190602401602060405180830381865afa15801561337b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061339f9190614a10565b600a546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156133ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134119190614a10565b905061341d8b86614ad4565b82101561346c5760405162461bcd60e51b815260206004820152601e60248201527f536d61724465783a20494e53554646494349454e545f414d4f554e545f30000060448201526064016106fb565b6134768a85614ad4565b8110156134c55760405162461bcd60e51b815260206004820152601e60248201527f536d61724465783a20494e53554646494349454e545f414d4f554e545f31000060448201526064016106fb565b8260000361351b576103e86134e26134dd8c8e614b04565b6142e4565b6134ec9190614a3f565b97506134fc61dead6103e86143cc565b613507600283614b31565b9650613514600282614b31565b95506135b1565b61354d85613529858e614b04565b6135339190614b31565b8561353e868e614b04565b6135489190614b31565b6136eb565b97508261355a8982614ad4565b600c5461357091906001600160801b0316614b04565b61357a9190614b31565b9650826135878982614ad4565b600c546135a49190600160801b90046001600160801b0316614b04565b6135ae9190614b31565b95505b876000036136105760405162461bcd60e51b815260206004820152602660248201527f536d61724465783a20494e53554646494349454e545f4c49515549444954595f60448201526513525395115160d21b60648201526084016106fb565b61361a8c896143cc565b600d5461364290839083908a908a906001600160801b0380821691600160801b90041661261a565b604080518c8152602081018c90526001600160a01b038e169133917f2f00e3cdd69a77be7ed215ec7b2a36784dd158f921fca79ac29deffa353fe6ee910160405180910390a35050600e80546001600160f81b0316600160f81b179055509398975050505050505050565b600080829050601f815111156136d8578260405163305a27a960e01b81526004016106fb9190614608565b80516136e382614d3d565b179392505050565b60008183106136fa57816136fc565b825b9392505050565b805160c082015160608301516137199190614b04565b8260a00151836080015161372d9190614b04565b11156138fb5760008260e001516001600160801b031683610100015160026137559190614d61565b6001600160801b031661376c620f42406002614b04565b6137769190614a3f565b6137809190614a3f565b836060015161378f9190614b04565b905060008361010001516001600160801b0316620f42406137b09190614a3f565b6137bb906002614b04565b60e08501519091506000906137d09080614d61565b6001600160801b0316856060015186606001516137ed9190614b04565b6137f79190614b04565b610100860151613813906001600160801b0316620f4240614a3f565b8660e001516001600160801b03168761010001516001600160801b0316620f424061383e9190614a3f565b6138489190614a3f565b6138529190614b04565b8660a001518760c00151886080015189606001516138709190614b04565b61387b906004614b04565b6138859190614b31565b61388f9190614b04565b6138999190614b04565b6138a39190614ad4565b905060008286600001516138b79190614b04565b6138c19085614ad4565b90506138cd8180614b04565b8210156138f65782846138df846142e4565b6138e99190614a3f565b6138f39190614b31565b94505b505050505b919050565b600061391e61390f8387614b04565b6139198587614b04565b61448b565b95945050505050565b6000806139348387614b04565b61393e8587614b04565b10156139bb5760008685856139538980614b04565b61395d9190614b31565b6139679190614b04565b6139719190614b31565b90508361397e8688614b04565b6139889190614b31565b846139938784614b04565b61399d9190614b31565b6139a79190614ad4565b92506139b38187614ad4565b915050613a00565b85836139c78787614b04565b6139d19190614b31565b6139db9190614ad4565b915084846139e98589614b04565b6139f39190614b31565b6139fd9190614ad4565b90505b613a0b600483614b31565b9150613a18600482614b31565b905094509492505050565b6000806000806000808661010001516001600160801b03168760e001516001600160801b0316620f4240613a579190614a3f565b613a619190614a3f565b8751613a6d9190614b04565b90506000876080015182613a819190614b04565b9050600082620f42408a60600151613a999190614b04565b613aa39190614ad4565b9050613aaf8183614b31565b97506000620f42408a60e001516001600160801b03168b60000151613ad49190614b04565b613ade9086614ad4565b613ae89190614b31565b9050808a60200151613afa9190614ad4565b9750808a60600151613b0c9190614ad4565b9550888a60400151613b1e9190614a3f565b9650888a60800151613b309190614a3f565b94505050505091939590929450565b805160e08201516101008301516000916001600160801b0390811691613b699116620f4240614a3f565b613b739190614a3f565b90508260c001518360600151613b899190614b04565b8360a001518460800151613b9d9190614b04565b11156130e75760008360a001518460c001518560e001516001600160801b03168660600151613bcc9190614b04565b613bd69190614b04565b613be09190614b31565b9050600081838660800151613bf59190614b04565b613c00906002614b04565b613c0a9190614ad4565b90506000613c19846002614b04565b90506000613c278480614b04565b8760e001516001600160801b03168861010001516001600160801b0316620f4240613c529190614a3f565b613c5c9088614b04565b868a60800151613c6c9190614b04565b613c77906004614b04565b613c819190614b04565b613c8b9190614b31565b613c959190614ad4565b90506000828860000151613ca99190614b04565b613cb39085614a3f565b9050613cbf8180614b04565b821115613ce75782613cd0836142e4565b613cda9086614a3f565b613ce49190614b31565b96505b505050505050919050565b600080600080600080620f424087600001518860600151613d139190614b04565b613d1d9190614b04565b905060008760e001516001600160801b03168861010001516001600160801b0316620f4240613d4c9190614a3f565b613d569190614a3f565b885160808a0151613d679190614a3f565b613d719190614b04565b9050613d7d8183614b31565b613d88906001614ad4565b96506000620f42408961010001516001600160801b0316620f4240613dad9190614a3f565b613db7908a614b04565b613dc19190614b31565b9050808960200151613dd39190614ad4565b9650808960600151613de59190614ad4565b895160408b0151919650613df891614a3f565b895160808b0151919750613e0b91614a3f565b935050505091939590929450565b505050565b60606000613e2b836144fc565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663017e7e586040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ebe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ee29190614ae7565b6001600160a01b0381161580159350909150613f8b57600e546001600160681b03600160281b8204811691600160901b9004168115613f4e57600954613f32906001600160a01b03168484612480565b600e805471ffffffffffffffffffffffffff0000000000191690555b8015613f8557600a54613f6b906001600160a01b03168483612480565b600e80546cffffffffffffffffffffffffff60901b191690555b50505090565b600e805465010000000000600160f81b03191690555090565b6001600160a01b0382166140045760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016106fb565b6001600160a01b038216600090815260208190526040902054818110156140785760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b60648201526084016106fb565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561410d5750600090506003614191565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614161573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661418a57600060019250925050614191565b9150600090505b94509492505050565b60008160048111156141ae576141ae614d8c565b036141b65750565b60018160048111156141ca576141ca614d8c565b036142175760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016106fb565b600281600481111561422b5761422b614d8c565b036142785760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016106fb565b600381600481111561428c5761428c614d8c565b036130c25760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016106fb565b6000816000036142f657506000919050565b6000600161430384614524565b901c6001901b9050600181848161431c5761431c614b1b565b048201901c9050600181848161433457614334614b1b565b048201901c9050600181848161434c5761434c614b1b565b048201901c9050600181848161436457614364614b1b565b048201901c9050600181848161437c5761437c614b1b565b048201901c9050600181848161439457614394614b1b565b048201901c905060018184816143ac576143ac614b1b565b048201901c90506136fc818285816143c6576143c6614b1b565b046136eb565b6001600160a01b0382166144225760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016106fb565b80600260008282546144349190614ad4565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600081830361449c5750600161068c565b818311156144d057620f42406144b3600184614b04565b6144bd9190614b31565b6144c79083614ad4565b8310905061068c565b620f42406144df600185614b04565b6144e99190614b31565b6144f39084614ad4565b8210905061068c565b600060ff8216601f81111561068c57604051632cd44ac360e21b815260040160405180910390fd5b600080608083901c1561453957608092831c92015b604083901c1561454b57604092831c92015b602083901c1561455d57602092831c92015b601083901c1561456f57601092831c92015b600883901c1561458157600892831c92015b600483901c1561459357600492831c92015b600283901c156145a557600292831c92015b600183901c1561068c5760010192915050565b60005b838110156145d35781810151838201526020016145bb565b50506000910152565b600081518084526145f48160208601602086016145b8565b601f01601f19169290920160200192915050565b6020815260006136fc60208301846145dc565b6001600160a01b03811681146130c257600080fd5b6000806040838503121561464357600080fd5b823561464e8161461b565b946020939093013593505050565b80356001600160801b03811681146138fb57600080fd5b6000806000806080858703121561468957600080fd5b84356146948161461b565b935060208501356146a48161461b565b92506146b26040860161465c565b91506146c06060860161465c565b905092959194509250565b80151581146130c257600080fd5b6000806000806000608086880312156146f157600080fd5b85356146fc8161461b565b9450602086013561470c816146cb565b935060408601359250606086013567ffffffffffffffff8082111561473057600080fd5b818801915088601f83011261474457600080fd5b81358181111561475357600080fd5b89602082850101111561476557600080fd5b9699959850939650602001949392505050565b60008060006060848603121561478d57600080fd5b83356147988161461b565b925060208401356147a88161461b565b929592945050506040919091013590565b600080604083850312156147cc57600080fd5b6147d58361465c565b91506147e36020840161465c565b90509250929050565b6000602082840312156147fe57600080fd5b81356136fc8161461b565b60ff60f81b881681526000602060e08184015261482960e084018a6145dc565b838103604085015261483b818a6145dc565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b8181101561488d57835183529284019291840191600101614871565b50909c9b505050505050505050505050565b600080600080600080600060e0888a0312156148ba57600080fd5b87356148c58161461b565b965060208801356148d58161461b565b95506040880135945060608801359350608088013560ff811681146148f957600080fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561492957600080fd5b82356149348161461b565b915060208301356149448161461b565b809150509250929050565b6000806000806080858703121561496557600080fd5b84356149708161461b565b93506020850135925060408501359150606085013561498e8161461b565b939692955090935050565b60008060008060008060c087890312156149b257600080fd5b505084359660208601359650604086013595606081013595506080810135945060a0013592509050565b600181811c908216806149f057607f821691505b6020821081036130e757634e487b7160e01b600052602260045260246000fd5b600060208284031215614a2257600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561068c5761068c614a29565b6020808252600f908201526e14db585c91195e0e881313d0d2d151608a1b604082015260600190565b6000600160ff1b8201614a9057614a90614a29565b5060000390565b84815283602082015260606040820152816060820152818360808301376000818301608090810191909152601f909201601f191601019392505050565b8082018082111561068c5761068c614a29565b600060208284031215614af957600080fd5b81516136fc8161461b565b808202811582820484141761068c5761068c614a29565b634e487b7160e01b600052601260045260246000fd5b600082614b4e57634e487b7160e01b600052601260045260246000fd5b500490565b6001600160681b03818116838216019080821115614b7357614b73614a29565b5092915050565b634e487b7160e01b600052604160045260246000fd5b601f821115613e1957600081815260208120601f850160051c81016020861015614bb75750805b601f850160051c820191505b81811015614bd657828155600101614bc3565b505050505050565b815167ffffffffffffffff811115614bf857614bf8614b7a565b614c0c81614c0684546149dc565b84614b90565b602080601f831160018114614c415760008415614c295750858301515b600019600386901b1c1916600185901b178555614bd6565b600085815260208120601f198616915b82811015614c7057888601518255948401946001909101908401614c51565b5085821015614c8e5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160801b03818116838216019080821115614b7357614b73614a29565b60208082526026908201527f536d61724465784c6962726172793a20494e53554646494349454e545f4c495160408201526555494449545960d01b606082015260800190565b60008251614d168184602087016145b8565b9190910192915050565b600060208284031215614d3257600080fd5b81516136fc816146cb565b805160208083015191908110156130e75760001960209190910360031b1b16919050565b6001600160801b03818116838216028082169190828114614d8457614d84614a29565b505092915050565b634e487b7160e01b600052602160045260246000fdfea164736f6c6343000811000a

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101d95760003560e01c806384b0196e11610104578063bc25cf77116100a2578063dd62ed3e11610071578063dd62ed3e1461044d578063ee2046c714610460578063f74bfe8e1461049c578063fb753b69146104af57600080fd5b8063bc25cf77146103ed578063c45a015514610400578063d21220a714610427578063d505accf1461043a57600080fd5b80639a20767b116100de5780639a20767b14610389578063a457c2d7146103a5578063a6706e14146103b8578063a9059cbb146103da57600080fd5b806384b0196e1461035357806389afcb441461036e57806395d89b411461038157600080fd5b80631f18b3711161017c5780633644e5151161014b5780633644e515146102fc578063395093511461030457806370a08231146103175780637ecebe001461034057600080fd5b80631f18b371146102b457806323b872dd146102c7578063313ce567146102da57806332760c7a146102e957600080fd5b8063095ea7b3116101b8578063095ea7b31461023f5780630dfe168114610262578063123a456a1461028d57806318160ddd146102a257600080fd5b80623b15fd146101de57806306fdde031461020d5780630902f1ac14610222575b600080fd5b600b54604080516001600160801b038084168252600160801b9093049092166020830152015b60405180910390f35b6102156104c2565b6040516102049190614608565b61022a610554565b60408051928352602083019190915201610204565b61025261024d366004614630565b610678565b6040519015158152602001610204565b600954610275906001600160a01b031681565b6040516001600160a01b039091168152602001610204565b6102a061029b366004614673565b610692565b005b6002545b604051908152602001610204565b61022a6102c23660046146d9565b610744565b6102526102d5366004614778565b611401565b60405160128152602001610204565b6102a06102f73660046147b9565b611425565b6102a661150a565b610252610312366004614630565b611519565b6102a66103253660046147ec565b6001600160a01b031660009081526020819052604090205490565b6102a661034e3660046147ec565b61153b565b61035b611559565b6040516102049796959493929190614809565b61022a61037c3660046147ec565b6115e2565b610215611600565b600c546001600160801b0380821691600160801b90041661022a565b6102526103b3366004614630565b61160f565b600e546001600160681b03600160281b8204811691600160901b90041661022a565b6102526103e8366004614630565b61168a565b6102a06103fb3660046147ec565b611698565b6102757f000000000000000000000000b878dc600550367e14220d4916ff678fb284214f81565b600a54610275906001600160a01b031681565b6102a061044836600461489f565b61184f565b6102a661045b366004614916565b6119b3565b600d54600e54604080516001600160801b038085168252600160801b909404909316602084015264ffffffffff90911690820152606001610204565b6102a66104aa36600461494f565b6119de565b61022a6104bd366004614999565b6119fe565b6060600380546104d1906149dc565b80601f01602080910402602001604051908101604052809291908181526020018280546104fd906149dc565b801561054a5780601f1061051f5761010080835404028352916020019161054a565b820191906000526020600020905b81548152906001019060200180831161052d57829003601f168201915b5050505050905090565b600e546009546040516370a0823160e01b81523060048201526000928392600160281b9091046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156105b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105da9190614a10565b6105e49190614a3f565b600e54600a546040516370a0823160e01b8152306004820152929450600160901b9091046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610644573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106689190614a10565b6106729190614a3f565b90509091565b600033610686818585611a52565b60019150505b92915050565b336001600160a01b037f000000000000000000000000b878dc600550367e14220d4916ff678fb284214f16146107045760405162461bcd60e51b815260206004820152601260248201527129b6b0b92232bc1d102327a92124a22222a760711b60448201526064015b60405180910390fd5b600980546001600160a01b038087166001600160a01b031992831617909255600a80549286169290911691909117905561073e8282611b76565b50505050565b600e546000908190600160f81b900460ff166001146107755760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b17905560008590036107d25760405162461bcd60e51b815260206004820152601460248201527314db585c91195e0e8816915493d7d05353d5539560621b60448201526064016106fb565b604080516101208101825260008082526020820181905291810182905260608101829052608081018290526009546001600160a01b0390811660a08301819052600a54821660c084015260e0830184905261010083019390935290919089161480159061085557508060c001516001600160a01b0316886001600160a01b031614155b6108975760405162461bcd60e51b8152602060048201526013602482015272536d61724465783a20494e56414c49445f544f60681b60448201526064016106fb565b866109de57600e5460c08201516040516370a0823160e01b8152306004820152600160901b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156108fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091f9190614a10565b6109299190614a3f565b600e5460a08301516040516370a0823160e01b8152306004820152600160281b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610988573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ac9190614a10565b6109b69190614a3f565b600c54600d546001600160801b03600160801b80840482169382169290810482169116610b1f565b600e5460a08201516040516370a0823160e01b8152306004820152600160281b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610a3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a619190614a10565b610a6b9190614a3f565b600e5460c08301516040516370a0823160e01b8152306004820152600160901b9092046001600160681b0316916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610aca573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aee9190614a10565b610af89190614a3f565b600c54600d546001600160801b0380831692600160801b9081900482169280831692919004165b6001600160801b0390811660808801819052918116606088018190529281166040880181905293166020870181905261010087019490945260e0860194909452600e54610b779464ffffffffff909116919042611c72565b6080830152606082015286610ba657610b938160800151611d61565b610ba08260600151611d61565b42610bc2565b610bb38160600151611d61565b610bc08260800151611d61565b425b600e805464ffffffffff90921664ffffffffff199092169190911790556001600160801b03918216908216600160801b9081026fffffffffffffffffffffffffffffffff191691909117600d55600b5404166000871315610cd0576000610caf604051806101200160405280610c378b611dce565b81526020018560e001518152602001856101000151815260200185602001518152602001856040015181526020018560600151815260200185608001518152602001600b60009054906101000a90046001600160801b03166001600160801b03168152602001846001600160801b0316815250611e20565b6040880152602087015250909150610cc89050816121a1565b835250610d88565b6000610d6b604051806101200160405280610cf38b610cee90614a7b565b611dce565b81526020018560e001518152602001856101000151815260200185602001518152602001856040015181526020018560600151815260200185608001518152602001600b60009054906101000a90046001600160801b03166001600160801b03168152602001846001600160801b031681525061220b565b6040880152602087015250909150610d849050816121a1565b8352505b87610daf5760008713610d9e5781518790610dcc565b8151610da990614a7b565b87610dcc565b60008713610dbf57815187610dcc565b81518790610dcc90614a7b565b90945092508715610fd3576000831215610df857610df88260c001518a85610df390614a7b565b612480565b60405163a1dab4eb60e01b8152339063a1dab4eb90610e2190879087908b908b90600401614a97565b600060405180830381600087803b158015610e3b57600080fd5b505af1158015610e4f573d6000803e3d6000fd5b5050505060e08201516009546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610ea0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ec49190614a10565b60e08401819052610ed486611dce565b600e54610ef190600160281b90046001600160681b031684614ad4565b610efb9190614ad4565b1115610f5b5760405162461bcd60e51b815260206004820152602960248201527f536d61724465783a20494e53554646494349454e545f544f4b454e305f494e50604482015268155517d05353d5539560ba1b60648201526084016106fb565b600a546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610fa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fc79190614a10565b610100840152506111c6565b6000841215610fef57610fef8260a001518a86610df390614a7b565b60405163a1dab4eb60e01b8152339063a1dab4eb9061101890879087908b908b90600401614a97565b600060405180830381600087803b15801561103257600080fd5b505af1158015611046573d6000803e3d6000fd5b5050505060e0820151600a546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015611097573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110bb9190614a10565b60e084018190526110cb85611dce565b600e546110e890600160901b90046001600160681b031684614ad4565b6110f29190614ad4565b11156111525760405162461bcd60e51b815260206004820152602960248201527f536d61724465783a20494e53554646494349454e545f544f4b454e315f494e50604482015268155517d05353d5539560ba1b60648201526084016106fb565b6009546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa15801561119a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111be9190614a10565b610100840152505b6000806001600160a01b03167f000000000000000000000000b878dc600550367e14220d4916ff678fb284214f6001600160a01b031663017e7e586040518163ffffffff1660e01b8152600401602060405180830381865afa158015611230573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112549190614ae7565b6001600160a01b03161415905088156113095780156112dd57611296620f42406112876001600160801b03851688614b04565b6112919190614b31565b6125b1565b600e80546005906112b8908490600160281b90046001600160681b0316614b53565b92506101000a8154816001600160681b0302191690836001600160681b031602179055505b6113048360e00151846101000151856020015186604001518760600151886080015161261a565b611397565b801561137057611329620f42406112876001600160801b03851687614b04565b600e805460129061134b908490600160901b90046001600160681b0316614b53565b92506101000a8154816001600160681b0302191690836001600160681b031602179055505b6113978361010001518460e00151856040015186602001518760800151886060015161261a565b60408051868152602081018690526001600160a01b038c169133917fa4228e1eb11eb9b31069d9ed20e7af9a010ca1a02d4855cee54e08e188fcc32c910160405180910390a35050600e80546001600160f81b0316600160f81b1790555090969095509350505050565b60003361140f85828561278d565b61141a858585612801565b506001949350505050565b7f000000000000000000000000b878dc600550367e14220d4916ff678fb284214f6001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611483573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a79190614ae7565b6001600160a01b0316336001600160a01b0316146114fc5760405162461bcd60e51b815260206004820152601260248201527129b6b0b92232bc1d102727aa2fa7aba722a960711b60448201526064016106fb565b6115068282611b76565b5050565b60006115146129a5565b905090565b60003361068681858561152c83836119b3565b6115369190614ad4565b611a52565b6001600160a01b03811660009081526007602052604081205461068c565b60006060808280808361158d7f536d6172446578204c502d546f6b656e000000000000000000000000000000106005612ad0565b6115b87f31000000000000000000000000000000000000000000000000000000000000016006612ad0565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6000806115ee83612b74565b90925090506115fb612f3a565b915091565b6060600480546104d1906149dc565b6000338161161d82866119b3565b90508381101561167d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016106fb565b61141a8286868403611a52565b600033610686818585612801565b600e54600160f81b900460ff166001146116c45760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b179055600254156117295760405162461bcd60e51b815260206004820152601860248201527f536d61724465783a204f4e4c595f454d5054595f50414952000000000000000060448201526064016106fb565b600954600a546040516370a0823160e01b81523060048201526001600160a01b03928316929091169060009083906370a0823190602401602060405180830381865afa15801561177d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a19190614a10565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156117eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180f9190614a10565b9050811561182257611822848684612480565b801561183357611833838683612480565b5050600e80546001600160f81b0316600160f81b179055505050565b8342111561189f5760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e6500000060448201526064016106fb565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886118ce8c6130c5565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000611929826130ed565b905060006119398287878761311a565b9050896001600160a01b0316816001600160a01b03161461199c5760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e6174757265000060448201526064016106fb565b6119a78a8a8a611a52565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60006119ec85858585613142565b90506119f6612f3a565b949350505050565b600080611a0f888888888888611c72565b90999098509650505050505050565b6000602083511015611a3a57611a33836136ad565b905061068c565b81611a458482614bde565b5060ff905061068c565b90565b6001600160a01b038316611ab45760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016106fb565b6001600160a01b038216611b155760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016106fb565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b816001600160801b0316600003611bc75760405162461bcd60e51b81526020600482015260156024820152740536d61724465783a205a45524f5f464545535f4c5605c1b60448201526064016106fb565b611bd5600a620f4240614b31565b611bdf8284614c9e565b6001600160801b03161115611c2a5760405162461bcd60e51b81526020600482015260116024820152700a6dac2e488caf074408c8a8aa6be9a82b607b1b60448201526064016106fb565b6001600160801b03828116600160801b9183169182028117600b556040517f64f84976d9c917a44796104a59950fdbd9b3c16a5dd348b546d738301f6bd06890600090a35050565b60008085831015611cc55760405162461bcd60e51b815260206004820152601e60248201527f536d6172646578506169723a20494e56414c49445f54494d455354414d50000060448201526064016106fb565b85600003611cd7575086905085611d56565b828603611ce8575083905082611d56565b6000611cff611cf78886614a3f565b61012c6136eb565b899350905061012c611d118983614b04565b878588611d208661012c614a3f565b611d2a9190614b04565b611d349190614b04565b611d3e9190614b31565b611d489190614ad4565b611d529190614b31565b9150505b965096945050505050565b60006001600160801b03821115611dca5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b60648201526084016106fb565b5090565b600080821215611dca5760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f73697469766560448201526064016106fb565b60008060008060008560000151600003611e8e5760405162461bcd60e51b815260206004820152602960248201527f536d61724465784c6962726172793a20494e53554646494349454e545f494e50604482015268155517d05353d5539560ba1b60648201526084016106fb565b602086015115801590611ea45750604086015115155b8015611eb35750606086015115155b8015611ec25750608086015115155b611ede5760405162461bcd60e51b81526004016106fb90614cbe565b6000620f42408760e001516001600160801b03168861010001516001600160801b0316620f4240611f0f9190614a3f565b611f199190614a3f565b8851611f259190614b04565b611f2f9190614b31565b90506000611fae6040518061012001604052808481526020018a6020015181526020018a6040015181526020018a6060015181526020018a6080015181526020018a60a0015181526020018a60c0015181526020018a60e001516001600160801b031681526020018a61010001516001600160801b0316815250613703565b90508181148015611fd65750611fd6886060015189608001518a60a001518b60c00151613900565b1561200257611ff7886020015189604001518a606001518b60800151613927565b60808a015260608901525b60008860e001516001600160801b03168961010001516001600160801b0316620f424061202f9190614a3f565b6120399190614a3f565b612046620f424084614b04565b6120509190614b31565b90506120cd6040518061012001604052808381526020018b6020015181526020018b6040015181526020018b6060015181526020018b6080015181526020018b60a0015181526020018b60c0015181526020018b60e001516001600160801b031681526020018b61010001516001600160801b0316815250613a23565b8d51949c50929a509098509650945081908a906120eb908390614a3f565b90525050818110156121965761210386868686613927565b8094508195505050600061217c6040518061012001604052808b6000015181526020018981526020018881526020018781526020018681526020018b60a0015181526020018b60c0015181526020018b60e001516001600160801b031681526020018b61010001516001600160801b0316815250613a23565b929a509098509650945090506121928189614ad4565b9750505b505091939590929450565b60006001600160ff1b03821115611dca5760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b60648201526084016106fb565b6000806000806000856000015160000361227a5760405162461bcd60e51b815260206004820152602a60248201527f536d61724465784c6962726172793a20494e53554646494349454e545f4f555460448201526914155517d05353d5539560b21b60648201526084016106fb565b608086015186511080156122915750602086015115155b80156122a05750604086015115155b80156122af5750606086015115155b80156122be5750608086015115155b6122da5760405162461bcd60e51b81526004016106fb90614cbe565b60006122e587613b3f565b87519091508114801561230f575061230f876060015188608001518960a001518a60c00151613900565b1561233b576123308760200151886040015189606001518a60800151613927565b608089015260608801525b6123b6604051806101200160405280838152602001896020015181526020018960400151815260200189606001518152602001896080015181526020018960a0015181526020018960c0015181526020018960e001516001600160801b031681526020018961010001516001600160801b0316815250613cf2565b8b51949a5092985090965094509250811015612476576123d885858585613927565b8093508194505050600061245c604051806101200160405280848b600001516124019190614a3f565b81526020018881526020018781526020018681526020018581526020018a60a0015181526020018a60c0015181526020018a60e001516001600160801b031681526020018a61010001516001600160801b0316815250613cf2565b9299509097509550935090506124728188614ad4565b9650505b5091939590929450565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916124dc9190614d04565b6000604051808303816000865af19150503d8060008114612519576040519150601f19603f3d011682016040523d82523d6000602084013e61251e565b606091505b50915091508180156125485750805115806125485750808060200190518101906125489190614d20565b6125aa5760405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b60648201526084016106fb565b5050505050565b60006001600160681b03821115611dca5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663034206269747360c81b60648201526084016106fb565b831580159061262857508215155b61267e5760405162461bcd60e51b815260206004820152602160248201527f536d61724465783a20464943544956455f52455345525645535f544f4f5f4c4f6044820152605760f81b60648201526084016106fb565b6001600160801b03841180159061269c57506001600160801b038311155b6126dc5760405162461bcd60e51b8152602060048201526011602482015270536d61724465783a204f564552464c4f5760781b60448201526064016106fb565b6001600160801b03838116600160801b0290851617600c55600e547f2a368c7f33bb86e2d999940a3989d849031aff29b750f67947e6b8e8c3d2ffd690612734906001600160681b03600160281b9091041688614a3f565b600e5461275190600160901b90046001600160681b031688614a3f565b6040805192835260208301919091528101869052606081018590526080810184905260a0810183905260c00160405180910390a1505050505050565b600061279984846119b3565b9050600019811461073e57818110156127f45760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016106fb565b61073e8484848403611a52565b6001600160a01b0383166128655760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016106fb565b6001600160a01b0382166128c75760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016106fb565b6001600160a01b0383166000908152602081905260409020548181101561293f5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016106fb565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a361073e565b6000306001600160a01b037f000000000000000000000000007597aaf6a4e4652e7843af5c44c359321368c2161480156129fe57507f000000000000000000000000000000000000000000000000000000000000000146145b15612a2857507f03f695d3c9ef75772475cb87c258a7992deb368d490232272b13782a6bd54eb690565b611514604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f275d5e42e4a96c3036f895e876c66d4c817af525bf99191834ae509ca1fdb684918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b606060ff8314612ae357611a3383613e1e565b818054612aef906149dc565b80601f0160208091040260200160405190810160405280929190818152602001828054612b1b906149dc565b8015612b685780601f10612b3d57610100808354040283529160200191612b68565b820191906000526020600020905b815481529060010190602001808311612b4b57829003601f168201915b5050505050905061068c565b600e546000908190600160f81b900460ff16600114612ba55760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b179055612bc2613e5d565b50600954600a546040516370a0823160e01b81523060048201526001600160a01b03928316929091169060009083906370a0823190602401602060405180830381865afa158015612c17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c3b9190614a10565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612c85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ca99190614a10565b306000908152602081905260409020546002549192509080612ccb8584614b04565b612cd59190614b31565b975080612ce28484614b04565b612cec9190614b31565b96508715801590612cfc57508615155b612d575760405162461bcd60e51b815260206004820152602660248201527f536d61724465783a20494e53554646494349454e545f4c49515549444954595f60448201526510955493915160d21b60648201526084016106fb565b600c546001600160801b0380821691600160801b90041682612d798584614b04565b612d839190614b31565b612d8d9083614a3f565b915082612d9a8583614b04565b612da49190614b31565b612dae9082614a3f565b9050612dba3085613fa4565b612dc5888c8c612480565b612dd0878c8b612480565b6040516370a0823160e01b81523060048201526001600160a01b038916906370a0823190602401602060405180830381865afa158015612e14573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e389190614a10565b6040516370a0823160e01b81523060048201529096506001600160a01b038816906370a0823190602401602060405180830381865afa158015612e7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ea39190614a10565b600d54909550612ece9087908790859085906001600160801b0380821691600160801b90041661261a565b604080518b8152602081018b90526001600160a01b038d169133917f5d624aa9c148153ab3446c1b154f660ee7701e549fe9b62dab7171b1c80e6fa2910160405180910390a35050600e80546001600160f81b0316600160f81b17905550959794965093945050505050565b60007f000000000000000000000000b878dc600550367e14220d4916ff678fb284214f6001600160a01b031663017e7e586040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fbe9190614ae7565b604080518082018252601c81527f65786563757465576f726b28616464726573732c616464726573732900000000602091820152600954600a5483516001600160a01b039283166024820152908216604480830191909152845180830390910181526064909101845291820180516001600160e01b0316633048c02960e01b1790529151929350908316916130539190614d04565b6000604051808303816000865af19150503d8060008114613090576040519150601f19603f3d011682016040523d82523d6000602084013e613095565b606091505b5050505a6000036130c25760405162461bcd60e51b815260206004820152600060248201526044016106fb565b50565b6001600160a01b03811660009081526007602052604090208054600181018255905b50919050565b600061068c6130fa6129a5565b8360405161190160f01b8152600281019290925260228201526042902090565b600080600061312b878787876140d6565b915091506131388161419a565b5095945050505050565b600e54600090600160f81b900460ff166001146131715760405162461bcd60e51b81526004016106fb90614a52565b600e80546001600160f81b0316600160f91b17905561318e613e5d565b506009546040516370a0823160e01b8152306004820152600091829182916001600160a01b0316906370a0823190602401602060405180830381865afa1580156131dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132009190614a10565b600a546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa15801561324e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132729190614a10565b9050600061327f60025490565b6040805160a0810182526009546001600160a01b039081168252600a548116602083019081528284018e8152606084018e81528d841660808601908152955163797c4a1360e01b815294518416600486015291518316602485015251604484015251606483015291519091166084820152909150339063797c4a139060a401600060405180830381600087803b15801561331857600080fd5b505af115801561332c573d6000803e3d6000fd5b50506009546040516370a0823160e01b8152306004820152600093506001600160a01b0390911691506370a0823190602401602060405180830381865afa15801561337b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061339f9190614a10565b600a546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156133ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134119190614a10565b905061341d8b86614ad4565b82101561346c5760405162461bcd60e51b815260206004820152601e60248201527f536d61724465783a20494e53554646494349454e545f414d4f554e545f30000060448201526064016106fb565b6134768a85614ad4565b8110156134c55760405162461bcd60e51b815260206004820152601e60248201527f536d61724465783a20494e53554646494349454e545f414d4f554e545f31000060448201526064016106fb565b8260000361351b576103e86134e26134dd8c8e614b04565b6142e4565b6134ec9190614a3f565b97506134fc61dead6103e86143cc565b613507600283614b31565b9650613514600282614b31565b95506135b1565b61354d85613529858e614b04565b6135339190614b31565b8561353e868e614b04565b6135489190614b31565b6136eb565b97508261355a8982614ad4565b600c5461357091906001600160801b0316614b04565b61357a9190614b31565b9650826135878982614ad4565b600c546135a49190600160801b90046001600160801b0316614b04565b6135ae9190614b31565b95505b876000036136105760405162461bcd60e51b815260206004820152602660248201527f536d61724465783a20494e53554646494349454e545f4c49515549444954595f60448201526513525395115160d21b60648201526084016106fb565b61361a8c896143cc565b600d5461364290839083908a908a906001600160801b0380821691600160801b90041661261a565b604080518c8152602081018c90526001600160a01b038e169133917f2f00e3cdd69a77be7ed215ec7b2a36784dd158f921fca79ac29deffa353fe6ee910160405180910390a35050600e80546001600160f81b0316600160f81b179055509398975050505050505050565b600080829050601f815111156136d8578260405163305a27a960e01b81526004016106fb9190614608565b80516136e382614d3d565b179392505050565b60008183106136fa57816136fc565b825b9392505050565b805160c082015160608301516137199190614b04565b8260a00151836080015161372d9190614b04565b11156138fb5760008260e001516001600160801b031683610100015160026137559190614d61565b6001600160801b031661376c620f42406002614b04565b6137769190614a3f565b6137809190614a3f565b836060015161378f9190614b04565b905060008361010001516001600160801b0316620f42406137b09190614a3f565b6137bb906002614b04565b60e08501519091506000906137d09080614d61565b6001600160801b0316856060015186606001516137ed9190614b04565b6137f79190614b04565b610100860151613813906001600160801b0316620f4240614a3f565b8660e001516001600160801b03168761010001516001600160801b0316620f424061383e9190614a3f565b6138489190614a3f565b6138529190614b04565b8660a001518760c00151886080015189606001516138709190614b04565b61387b906004614b04565b6138859190614b31565b61388f9190614b04565b6138999190614b04565b6138a39190614ad4565b905060008286600001516138b79190614b04565b6138c19085614ad4565b90506138cd8180614b04565b8210156138f65782846138df846142e4565b6138e99190614a3f565b6138f39190614b31565b94505b505050505b919050565b600061391e61390f8387614b04565b6139198587614b04565b61448b565b95945050505050565b6000806139348387614b04565b61393e8587614b04565b10156139bb5760008685856139538980614b04565b61395d9190614b31565b6139679190614b04565b6139719190614b31565b90508361397e8688614b04565b6139889190614b31565b846139938784614b04565b61399d9190614b31565b6139a79190614ad4565b92506139b38187614ad4565b915050613a00565b85836139c78787614b04565b6139d19190614b31565b6139db9190614ad4565b915084846139e98589614b04565b6139f39190614b31565b6139fd9190614ad4565b90505b613a0b600483614b31565b9150613a18600482614b31565b905094509492505050565b6000806000806000808661010001516001600160801b03168760e001516001600160801b0316620f4240613a579190614a3f565b613a619190614a3f565b8751613a6d9190614b04565b90506000876080015182613a819190614b04565b9050600082620f42408a60600151613a999190614b04565b613aa39190614ad4565b9050613aaf8183614b31565b97506000620f42408a60e001516001600160801b03168b60000151613ad49190614b04565b613ade9086614ad4565b613ae89190614b31565b9050808a60200151613afa9190614ad4565b9750808a60600151613b0c9190614ad4565b9550888a60400151613b1e9190614a3f565b9650888a60800151613b309190614a3f565b94505050505091939590929450565b805160e08201516101008301516000916001600160801b0390811691613b699116620f4240614a3f565b613b739190614a3f565b90508260c001518360600151613b899190614b04565b8360a001518460800151613b9d9190614b04565b11156130e75760008360a001518460c001518560e001516001600160801b03168660600151613bcc9190614b04565b613bd69190614b04565b613be09190614b31565b9050600081838660800151613bf59190614b04565b613c00906002614b04565b613c0a9190614ad4565b90506000613c19846002614b04565b90506000613c278480614b04565b8760e001516001600160801b03168861010001516001600160801b0316620f4240613c529190614a3f565b613c5c9088614b04565b868a60800151613c6c9190614b04565b613c77906004614b04565b613c819190614b04565b613c8b9190614b31565b613c959190614ad4565b90506000828860000151613ca99190614b04565b613cb39085614a3f565b9050613cbf8180614b04565b821115613ce75782613cd0836142e4565b613cda9086614a3f565b613ce49190614b31565b96505b505050505050919050565b600080600080600080620f424087600001518860600151613d139190614b04565b613d1d9190614b04565b905060008760e001516001600160801b03168861010001516001600160801b0316620f4240613d4c9190614a3f565b613d569190614a3f565b885160808a0151613d679190614a3f565b613d719190614b04565b9050613d7d8183614b31565b613d88906001614ad4565b96506000620f42408961010001516001600160801b0316620f4240613dad9190614a3f565b613db7908a614b04565b613dc19190614b31565b9050808960200151613dd39190614ad4565b9650808960600151613de59190614ad4565b895160408b0151919650613df891614a3f565b895160808b0151919750613e0b91614a3f565b935050505091939590929450565b505050565b60606000613e2b836144fc565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b6000807f000000000000000000000000b878dc600550367e14220d4916ff678fb284214f6001600160a01b031663017e7e586040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ebe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ee29190614ae7565b6001600160a01b0381161580159350909150613f8b57600e546001600160681b03600160281b8204811691600160901b9004168115613f4e57600954613f32906001600160a01b03168484612480565b600e805471ffffffffffffffffffffffffff0000000000191690555b8015613f8557600a54613f6b906001600160a01b03168483612480565b600e80546cffffffffffffffffffffffffff60901b191690555b50505090565b600e805465010000000000600160f81b03191690555090565b6001600160a01b0382166140045760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016106fb565b6001600160a01b038216600090815260208190526040902054818110156140785760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b60648201526084016106fb565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561410d5750600090506003614191565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614161573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661418a57600060019250925050614191565b9150600090505b94509492505050565b60008160048111156141ae576141ae614d8c565b036141b65750565b60018160048111156141ca576141ca614d8c565b036142175760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016106fb565b600281600481111561422b5761422b614d8c565b036142785760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016106fb565b600381600481111561428c5761428c614d8c565b036130c25760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016106fb565b6000816000036142f657506000919050565b6000600161430384614524565b901c6001901b9050600181848161431c5761431c614b1b565b048201901c9050600181848161433457614334614b1b565b048201901c9050600181848161434c5761434c614b1b565b048201901c9050600181848161436457614364614b1b565b048201901c9050600181848161437c5761437c614b1b565b048201901c9050600181848161439457614394614b1b565b048201901c905060018184816143ac576143ac614b1b565b048201901c90506136fc818285816143c6576143c6614b1b565b046136eb565b6001600160a01b0382166144225760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016106fb565b80600260008282546144349190614ad4565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600081830361449c5750600161068c565b818311156144d057620f42406144b3600184614b04565b6144bd9190614b31565b6144c79083614ad4565b8310905061068c565b620f42406144df600185614b04565b6144e99190614b31565b6144f39084614ad4565b8210905061068c565b600060ff8216601f81111561068c57604051632cd44ac360e21b815260040160405180910390fd5b600080608083901c1561453957608092831c92015b604083901c1561454b57604092831c92015b602083901c1561455d57602092831c92015b601083901c1561456f57601092831c92015b600883901c1561458157600892831c92015b600483901c1561459357600492831c92015b600283901c156145a557600292831c92015b600183901c1561068c5760010192915050565b60005b838110156145d35781810151838201526020016145bb565b50506000910152565b600081518084526145f48160208601602086016145b8565b601f01601f19169290920160200192915050565b6020815260006136fc60208301846145dc565b6001600160a01b03811681146130c257600080fd5b6000806040838503121561464357600080fd5b823561464e8161461b565b946020939093013593505050565b80356001600160801b03811681146138fb57600080fd5b6000806000806080858703121561468957600080fd5b84356146948161461b565b935060208501356146a48161461b565b92506146b26040860161465c565b91506146c06060860161465c565b905092959194509250565b80151581146130c257600080fd5b6000806000806000608086880312156146f157600080fd5b85356146fc8161461b565b9450602086013561470c816146cb565b935060408601359250606086013567ffffffffffffffff8082111561473057600080fd5b818801915088601f83011261474457600080fd5b81358181111561475357600080fd5b89602082850101111561476557600080fd5b9699959850939650602001949392505050565b60008060006060848603121561478d57600080fd5b83356147988161461b565b925060208401356147a88161461b565b929592945050506040919091013590565b600080604083850312156147cc57600080fd5b6147d58361465c565b91506147e36020840161465c565b90509250929050565b6000602082840312156147fe57600080fd5b81356136fc8161461b565b60ff60f81b881681526000602060e08184015261482960e084018a6145dc565b838103604085015261483b818a6145dc565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b8181101561488d57835183529284019291840191600101614871565b50909c9b505050505050505050505050565b600080600080600080600060e0888a0312156148ba57600080fd5b87356148c58161461b565b965060208801356148d58161461b565b95506040880135945060608801359350608088013560ff811681146148f957600080fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561492957600080fd5b82356149348161461b565b915060208301356149448161461b565b809150509250929050565b6000806000806080858703121561496557600080fd5b84356149708161461b565b93506020850135925060408501359150606085013561498e8161461b565b939692955090935050565b60008060008060008060c087890312156149b257600080fd5b505084359660208601359650604086013595606081013595506080810135945060a0013592509050565b600181811c908216806149f057607f821691505b6020821081036130e757634e487b7160e01b600052602260045260246000fd5b600060208284031215614a2257600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561068c5761068c614a29565b6020808252600f908201526e14db585c91195e0e881313d0d2d151608a1b604082015260600190565b6000600160ff1b8201614a9057614a90614a29565b5060000390565b84815283602082015260606040820152816060820152818360808301376000818301608090810191909152601f909201601f191601019392505050565b8082018082111561068c5761068c614a29565b600060208284031215614af957600080fd5b81516136fc8161461b565b808202811582820484141761068c5761068c614a29565b634e487b7160e01b600052601260045260246000fd5b600082614b4e57634e487b7160e01b600052601260045260246000fd5b500490565b6001600160681b03818116838216019080821115614b7357614b73614a29565b5092915050565b634e487b7160e01b600052604160045260246000fd5b601f821115613e1957600081815260208120601f850160051c81016020861015614bb75750805b601f850160051c820191505b81811015614bd657828155600101614bc3565b505050505050565b815167ffffffffffffffff811115614bf857614bf8614b7a565b614c0c81614c0684546149dc565b84614b90565b602080601f831160018114614c415760008415614c295750858301515b600019600386901b1c1916600185901b178555614bd6565b600085815260208120601f198616915b82811015614c7057888601518255948401946001909101908401614c51565b5085821015614c8e5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160801b03818116838216019080821115614b7357614b73614a29565b60208082526026908201527f536d61724465784c6962726172793a20494e53554646494349454e545f4c495160408201526555494449545960d01b606082015260800190565b60008251614d168184602087016145b8565b9190910192915050565b600060208284031215614d3257600080fd5b81516136fc816146cb565b805160208083015191908110156130e75760001960209190910360031b1b16919050565b6001600160801b03818116838216028082169190828114614d8457614d84614a29565b505092915050565b634e487b7160e01b600052602160045260246000fdfea164736f6c6343000811000a

Block Transaction Difficulty 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
Loading...
Loading
[ 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.