MON Price: $0.020321 (-4.48%)

Contract

0x6B133f13D837666AAa5524f027b12f1cF6b1D190

Overview

MON Balance

Monad Chain LogoMonad Chain LogoMonad Chain Logo0 MON

MON Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
LiquidityBondsEvolution

Compiler Version
v0.8.22+commit.4fc1097e

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;

import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import {
    ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {
    IERC721ReceiverUpgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

import { ILiquidityBonds } from "./interface/ILiquidityBonds.sol";
import { INonFungiblePositionManager } from "./interface/INonfungiblePositionManager.sol";
import { IUniswapV3Pool } from "./interface/IUniswapV3Pool.sol";
import { IERC20MintBurn } from "./interface/IERC20MintBurn.sol";

/**
 * @title  LiquidityBondLockerV3
 * @author Energi Core
 * @notice Manages Uniswap V3 liquidity bond locking/unlocking for rewards.
 */
contract LiquidityBondsEvolution is
    OwnableUpgradeable,
    PausableUpgradeable,
    ReentrancyGuardUpgradeable,
    IERC721ReceiverUpgradeable
{
    /*//////////////////////////////////////////////////////////////
                                EVENTS
    //////////////////////////////////////////////////////////////*/

    event BondSet(
        uint256 indexed bondId,
        address collection,
        address token0,
        address token1,
        uint256 requiredAmount1,
        uint256 fee,
        uint256 bondType,
        uint256 lockDuration,
        uint256 multiplier,
        bool isActive
    );

    event LayerSet(
        uint256 indexed layerId,
        uint256 indexed bondId,
        address baseLayer,
        address outputLayer,
        address token,
        uint256 fee
    );

    event UniswapPositionManagerSet(address indexed oldManager, address indexed newManager);
    event PositionLocked(uint256 indexed bondId, uint256 totalBonds, address indexed user);
    event PositionUnlocked(
        uint256 indexed lpBondTokenId,
        uint256 indexed uniswapV3PositionId,
        uint256 indexed bondId,
        address user
    );

    event GMISet(address indexed oldGMI, address indexed newGMI);
    event EthRecovered(address indexed to, uint256 amount);
    event Erc20sRecovered(address indexed token, address indexed to, uint256 amount);
    event Erc721Recovered(address indexed token, address indexed to, uint256 tokenId);
    event AdditionalSet(uint256 additional);
    event SignerSet(address indexed oldSigner, address indexed newSigner);

    /*//////////////////////////////////////////////////////////////
                                STRUCTS
    //////////////////////////////////////////////////////////////*/

    struct Bond {
        uint256 bondId;
        address collection;
        address token0;
        address token1;
        uint256 requiredAmount1;
        uint256 fee;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 bondType;
        uint256 lockDuration;
        uint256 multiplier;
        bool isActive;
        address pool;
        bool isGMIPool;
    }

    struct Lock {
        uint256 uniswapV3PositionId;
        uint256 lpBondId;
        uint256 bondId;
        uint256 startTime;
        uint256 lockedAmount0;
        uint256 lockedAmount1;
        bool isLocked;
    }

    struct Layer {
        uint256 layerId;
        uint256 origBondId;
        uint256 bondId;
        address baseLayer;
        address outputLayer;
        address token;
        uint256 fee;
    }

    /*//////////////////////////////////////////////////////////////
                                STORAGE
    //////////////////////////////////////////////////////////////*/

    /// @notice Bond configurations by bond ID
    mapping(uint256 => Bond) public bonds;

    /// @notice Lock information by Uniswap V3 position ID
    mapping(uint256 => Lock) public locks;

    /// @notice Base position ID for each bond (first position created)
    mapping(uint256 => uint256) public basePositions;

    /// @notice Uniswap V3 Position Manager contract
    INonFungiblePositionManager public uniswapPositionManager;

    /// @notice GMI contract
    IERC20 public gmi;

    /// @notice Additional amount added to token0 calculations
    uint256 public additional;

    /// @notice Authorized signer for off-chain signatures
    address public signer;

    /// @notice Nonce used for signature
    uint256 public nonce;

    /// @notice Multisig to store Minted positions
    address public multiSig;

    mapping(uint256 => uint256) public startTime;

    mapping(uint256 => mapping(uint256 => Layer)) public layers;

    address public multiSigBurned;

    /*//////////////////////////////////////////////////////////////
                                MODIFIERS
    //////////////////////////////////////////////////////////////*/

    modifier bondExists(uint256 bondId) {
        require(bonds[bondId].collection != address(0), "LiquidityBondLocker: Bond does not exist");
        _;
    }

    modifier basePositionNotExists(uint256 bondId) {
        require(basePositions[bondId] == 0, "LiquidityBondLocker: Base position exists");
        _;
    }

    modifier basePositionExists(uint256 bondId) {
        require(basePositions[bondId] != 0, "LiquidityBondLocker: Base position does not exist");
        _;
    }

    /*//////////////////////////////////////////////////////////////
                                INITIALIZER
    //////////////////////////////////////////////////////////////*/

    function initialize(address uniswapPositionManager_, address signer_, address gmi_) external initializer {
        require(uniswapPositionManager_ != address(0), "LiquidityBondLocker: Invalid position manager");
        require(signer_ != address(0), "LiquidityBondLocker: Invalid signer");

        uniswapPositionManager = INonFungiblePositionManager(uniswapPositionManager_);
        signer = signer_;
        gmi = IERC20(gmi_);

        __Ownable_init();
        __Pausable_init();
        __ReentrancyGuard_init();
    }

    /*//////////////////////////////////////////////////////////////
                            LOCK/UNLOCK FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Lock additional positions using off-chain signature verification
     * @param _bondId The bond configuration to use
     * @param _amount0 Amount of token0 to lock
     * @param _amount1 Amount of token1 to lock per bond
     * @param _signature Off-chain signature for verification
     */
    function lockPositionChild(
        uint256 _bondId,
        uint256 _layerId,
        uint256[] memory _baseTokenId,
        uint256 _amount0,
        uint256 _amount1,
        uint256 _fee,
        bytes memory _signature,
        uint256 _numberOfBonds
    ) external payable nonReentrant whenNotPaused bondExists(_bondId) basePositionExists(_bondId) {
        Layer storage layer = layers[_bondId][_layerId];
        Bond storage bond = bonds[layer.bondId];
        ILiquidityBonds lpbond = ILiquidityBonds(bond.collection);

        require(signer != address(0), "LiquidityBondLocker: Signer not set");
        require(bond.isActive, "LiquidityBondLocker: Bond not active");
        require(_amount0 != 0, "LiquidityBondLocker: _amount0 cannot be 0");
        require(_amount1 != 0, "LiquidityBondLocker: _amount1 cannot be 0");
        require(_baseTokenId.length == _numberOfBonds, "LiquidityBondLocker: Base token IDs length mismatch");
        require(_baseTokenId.length > 0, "LiquidityBondLocker: Base token IDs required");

        for (uint i = 0; i < _baseTokenId.length; i++) {
            IERC721 baseNFT = IERC721(layer.baseLayer);
            require(
                baseNFT.ownerOf(_baseTokenId[i]) == _msgSender(),
                "LiquidityBondLocker: Not owner of base position"
            );
            baseNFT.transferFrom(_msgSender(), multiSigBurned, _baseTokenId[i]);
        }

        uint256 numberOfBonds = _numberOfBonds;
        require(numberOfBonds > 0, "LiquidityBondLocker: Number of bonds must be greater than 0");

        nonce += 1;
        if (bond.token0 < bond.token1) {
            _verifySignature(_bondId, _amount0, _amount1, _signature);
        } else {
            _verifySignature(_bondId, _amount1, _amount0, _signature);
        }

        IERC20MintBurn curToken0 = IERC20MintBurn(bond.token0);
        IERC20MintBurn curToken1 = IERC20MintBurn(bond.token1);

        curToken0.approve(address(uniswapPositionManager), type(uint256).max);
        curToken1.approve(address(uniswapPositionManager), type(uint256).max);

        curToken0.transferFrom(_msgSender(), address(this), _amount0 * numberOfBonds);
        curToken1.mint(address(this), _amount1 * numberOfBonds);

        uint256 fee = (_amount0 * numberOfBonds * layer.fee) / 10000;
        require(_fee >= fee, "LiquidityBondLocker: Insufficient fee");
        curToken0.transferFrom(_msgSender(), multiSig, fee);

        for (uint256 i = 0; i < numberOfBonds; i++) {
            INonFungiblePositionManager.MintParams memory params = INonFungiblePositionManager.MintParams({
                token0: bond.token0 < bond.token1 ? bond.token0 : bond.token1,
                token1: bond.token0 < bond.token1 ? bond.token1 : bond.token0,
                fee: uint24(bond.fee),
                tickLower: bond.tickLower,
                tickUpper: bond.tickUpper,
                amount0Desired: bond.token0 < bond.token1 ? _amount0 : _amount1,
                amount1Desired: bond.token0 < bond.token1 ? _amount1 : _amount0,
                amount0Min: bond.amount0Min,
                amount1Min: bond.amount1Min,
                recipient: address(this),
                deadline: block.timestamp + 300
            });

            (uint256 tokenId, , , ) = uniswapPositionManager.mint(params);

            uniswapPositionManager.transferFrom(address(this), multiSig, tokenId);

            lpbond.mint(_msgSender(), tokenId);

            locks[tokenId] = Lock({
                uniswapV3PositionId: tokenId,
                lpBondId: lpbond.currentIndex(),
                bondId: bond.bondId,
                startTime: block.timestamp,
                lockedAmount0: bond.token0 < bond.token1 ? _amount0 : _amount1,
                lockedAmount1: bond.token0 < bond.token1 ? _amount1 : _amount0,
                isLocked: true
            });
        }

        emit PositionLocked(bond.bondId, numberOfBonds, _msgSender());
    }

    /**
     * @notice Unlock a liquidity position and claim rewards
     * @param _lpBondTokenId The LP bond token ID to unlock
     * @param _bondId The bond ID for validation
     */
    function unlockPosition(uint256 _lpBondTokenId, uint256 _bondId) external nonReentrant whenNotPaused {
        Bond storage bond = bonds[_bondId];
        ILiquidityBonds lpBond = ILiquidityBonds(bond.collection);

        require(lpBond.ownerOf(_lpBondTokenId) == _msgSender(), "LiquidityBondLocker: Not owner");
        require(bond.isActive, "LiquidityBondLocker: Bond not active");

        (uint256 uniswapV3PositionId, , , , , ) = lpBond.getBondInfo(_lpBondTokenId);
        Lock storage lock = locks[uniswapV3PositionId];

        require(lock.bondId == _bondId, "LiquidityBondLocker: Bond ID mismatch");
        require(lock.lpBondId == _lpBondTokenId, "LiquidityBondLocker: LP Bond ID mismatch");
        require(lock.isLocked, "LiquidityBondLocker: Not locked");
        // c
        require(block.timestamp >= bond.lockDuration, "LiquidityBondLocker: Lock not expired");

        (, , address token0, address token1, , , , , , , , ) = uniswapPositionManager.positions(uniswapV3PositionId);

        uint256 rewards0 = getRewards0(uniswapV3PositionId);
        if (rewards0 > 0) {
            if (bond.isGMIPool) {
                if (token0 == address(gmi)) {
                    IERC20(token0).transfer(_msgSender(), rewards0);
                }
                if (token1 == address(gmi)) {
                    IERC20(token1).transfer(_msgSender(), rewards0);
                }
            } else {
                gmi.transfer(_msgSender(), rewards0);
            }
        }

        uniswapPositionManager.transferFrom(address(this), _msgSender(), uniswapV3PositionId);
        locks[uniswapV3PositionId].isLocked = false;
        lpBond.burn(_lpBondTokenId);

        emit PositionUnlocked(_lpBondTokenId, uniswapV3PositionId, bond.bondId, _msgSender());
    }

    /*//////////////////////////////////////////////////////////////
                            INTERNAL FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Verify off-chain signature for position data
     */
    function _verifySignature(
        uint256 _bondId,
        uint256 _amount0,
        uint256 _amount1,
        bytes memory _signature
    ) internal view {
        bytes32 msgHash = keccak256(
            abi.encodePacked(basePositions[_bondId], _amount0, _amount1, address(this), nonce, msg.sender)
        );
        bytes32 ethSignedMessageHash = MessageHashUtils.toEthSignedMessageHash(msgHash);
        address recoveredSigner = ECDSA.recover(ethSignedMessageHash, _signature);

        require(recoveredSigner == signer, "LiquidityBondLocker: Invalid signature");
    }

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

    /**
     * @notice Get rewards for a locked position
     * @param _uniswapV3PositionId The Uniswap V3 position ID
     * @return rewards0 The calculated rewards in token0
     */
    function getRewards0(uint256 _uniswapV3PositionId) public view returns (uint256 rewards0) {
        Lock storage lock = locks[_uniswapV3PositionId];
        Bond storage bond = bonds[lock.bondId];

        uint256 timeDiff = bond.lockDuration - lock.startTime;

        uint256 totalRewards = lock.lockedAmount0 * bond.multiplier * timeDiff;
        uint256 rewardsAccured = totalRewards / (bond.lockDuration - startTime[lock.bondId]);

        if (bond.isGMIPool) {
            if (block.timestamp >= bond.lockDuration) {
                rewards0 = (rewardsAccured * bond.multiplier) / 10000;
            } else {
                uint256 timeElapsed = block.timestamp - lock.startTime;
                uint256 intrewards0 = (rewardsAccured * bond.multiplier * timeElapsed) / (timeDiff * 10000);
                rewards0 = intrewards0 / 10000;
            }
        }
    }

    /*//////////////////////////////////////////////////////////////
                            ADMIN FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Set or update a bond configuration
     */
    function setBond(
        uint256 _bondId,
        address _collection,
        address _token0,
        address _token1,
        uint256 _requiredAmount1,
        uint256 _fee,
        int24 _tickLower,
        int24 _tickUpper,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint256 _bondType,
        uint256 _lockDuration,
        uint256 _multiplier,
        bool _isActive,
        address _pool,
        bool _isGMIPool
    ) external onlyOwner {
        require(_bondId != 0, "LiquidityBondLocker: Bond ID cannot be zero");
        require(_lockDuration > 0, "LiquidityBondLocker: Invalid lock duration");
        require(_multiplier > 0, "LiquidityBondLocker: Invalid multiplier");
        require(_requiredAmount1 > 0, "LiquidityBondLocker: Invalid required amount");
        require(_collection != address(0), "LiquidityBondLocker: Invalid collection");
        require(_token0 != address(0), "LiquidityBondLocker: Invalid token0");
        require(_token1 != address(0), "LiquidityBondLocker: Invalid token1");
        require(_token0 != _token1, "LiquidityBondLocker: Identical tokens");
        require(_pool != address(0), "LiquidityBondLocker: Invalid pool");

        bonds[_bondId] = Bond({
            bondId: _bondId,
            collection: _collection,
            token0: _token0,
            token1: _token1,
            requiredAmount1: _requiredAmount1,
            fee: _fee,
            tickLower: _tickLower,
            tickUpper: _tickUpper,
            amount0Min: _amount0Min,
            amount1Min: _amount1Min,
            bondType: _bondType,
            lockDuration: _lockDuration,
            multiplier: _multiplier,
            isActive: _isActive,
            pool: _pool,
            isGMIPool: _isGMIPool
        });

        emit BondSet(
            _bondId,
            _collection,
            _token0,
            _token1,
            _requiredAmount1,
            _fee,
            _bondType,
            _lockDuration,
            _multiplier,
            _isActive
        );
    }

    function setLayer(
        uint256 _layerId,
        uint256 _origBondId,
        uint256 _bondId,
        address _baseLayer,
        address _outputLayer,
        address _token,
        uint256 _fee
    ) external onlyOwner {
        layers[_origBondId][_layerId] = Layer({
            layerId: _layerId,
            origBondId: _origBondId,
            bondId: _bondId,
            baseLayer: _baseLayer,
            outputLayer: _outputLayer,
            token: _token,
            fee: _fee
        });

        emit LayerSet(_layerId, _bondId, _baseLayer, _outputLayer, _token, _fee);
    }

    function setUniswapPositionManager(address _uniswapPositionManager) external onlyOwner {
        require(_uniswapPositionManager != address(0), "LiquidityBondLocker: Invalid address");
        address oldManager = address(uniswapPositionManager);
        require(oldManager != _uniswapPositionManager, "LiquidityBondLocker: Same address");

        uniswapPositionManager = INonFungiblePositionManager(_uniswapPositionManager);
        emit UniswapPositionManagerSet(oldManager, _uniswapPositionManager);
    }

    function setGMI(address _newGMI) external onlyOwner {
        require(_newGMI != address(0), "LiquidityBondLocker: Invalid address");
        address oldGMI = address(gmi);

        gmi = IERC20(_newGMI);
        emit GMISet(oldGMI, _newGMI);
    }

    function setSigner(address _newSigner) external onlyOwner {
        require(_newSigner != address(0), "LiquidityBondLocker: Invalid address");
        address oldSigner = signer;
        require(oldSigner != _newSigner, "LiquidityBondLocker: Same address");

        signer = _newSigner;
        emit SignerSet(oldSigner, _newSigner);
    }

    function setAdditional(uint256 _newAdditional) external onlyOwner {
        additional = _newAdditional;
        emit AdditionalSet(_newAdditional);
    }

    function setBasePosition(uint256 _bondId, uint256 _basePosition) external onlyOwner {
        require(_bondId != 0, "LiquidityBondLocker: Invalid bond ID");
        require(_basePosition != 0, "LiquidityBondLocker: Invalid position ID");
        basePositions[_bondId] = _basePosition;
    }

    function pause() external onlyOwner whenNotPaused {
        _pause();
    }

    function unpause() external onlyOwner whenPaused {
        _unpause();
    }

    function setMultiSig(address _multiSig) external onlyOwner {
        multiSig = _multiSig;
    }

    function setMultiSigBurned(address _multiSigBurned) external onlyOwner {
        multiSigBurned = _multiSigBurned;
    }

    /*//////////////////////////////////////////////////////////////
                            EMERGENCY RECOVERY
    //////////////////////////////////////////////////////////////*/

    function recoverETH(address _to, uint256 _amount) external onlyOwner {
        require(_to != address(0), "LiquidityBondLocker: Invalid address");
        require(_amount > 0, "LiquidityBondLocker: Invalid amount");
        require(address(this).balance >= _amount, "LiquidityBondLocker: Insufficient balance");

        (bool success, ) = _to.call{ value: _amount }("");
        require(success, "LiquidityBondLocker: ETH transfer failed");
        emit EthRecovered(_to, _amount);
    }

    function recoverERC721(address _token, address _to, uint256 _tokenId) external onlyOwner {
        require(_token != address(0), "LiquidityBondLocker: Invalid token address");
        require(_to != address(0), "LiquidityBondLocker: Invalid recipient");

        IERC721(_token).transferFrom(address(this), _to, _tokenId);
        emit Erc721Recovered(_token, _to, _tokenId);
    }

    function recoverERC20(address _token, address _to, uint256 _amount) external onlyOwner {
        require(_token != address(0), "LiquidityBondLocker: Invalid token address");
        require(_to != address(0), "LiquidityBondLocker: Invalid recipient");
        require(_amount > 0, "LiquidityBondLocker: Invalid amount");

        IERC20(_token).transfer(_to, _amount);
        emit Erc20sRecovered(_token, _to, _amount);
    }

    /**
     * @notice Set the start time for a specific bond ID
     * @param _bondId bond id to set the start time for
     * @param _startTime start time to set
     */
    function setStartTime(uint256 _bondId, uint256 _startTime) external onlyOwner {
        startTime[_bondId] = _startTime;
    }

    /*//////////////////////////////////////////////////////////////
                            ERC721 RECEIVER
    //////////////////////////////////////////////////////////////*/

    function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4) {
        return this.onERC721Received.selector;
    }

    function _currentTime() internal view virtual returns (uint256) {
        return block.timestamp;
    }

    /*//////////////////////////////////////////////////////////////
                            FALLBACK
    //////////////////////////////////////////////////////////////*/

    receive() external payable {}
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @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() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

    /**
     * This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 3 of 22 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

    /**
     * This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

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

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

    /**
     * This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 6 of 22 : IERC721ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721ReceiverUpgradeable {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

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

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

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

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    /**
     * This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC-721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC-721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @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
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-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]
     */
    function tryRecover(
        bytes32 hash,
        bytes memory signature
    ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
        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.
            assembly ("memory-safe") {
                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, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        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[ERC-2098 short signatures]
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            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.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
        // 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, s);
        }

        // 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, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @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, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

import {Strings} from "../Strings.sol";

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an ERC-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        assembly ("memory-safe") {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an ERC-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an ERC-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.
     */
    function toDataWithIntendedValidatorHash(
        address validator,
        bytes32 messageHash
    ) internal pure returns (bytes32 digest) {
        assembly ("memory-safe") {
            mstore(0x00, hex"19_00")
            mstore(0x02, shl(96, validator))
            mstore(0x16, messageHash)
            digest := keccak256(0x00, 0x36)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 14 of 22 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Return the 512-bit addition of two uint256.
     *
     * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
     */
    function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
        assembly ("memory-safe") {
            low := add(a, b)
            high := lt(low, a)
        }
    }

    /**
     * @dev Return the 512-bit multiplication of two uint256.
     *
     * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
     */
    function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
        // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
        // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
        // variables such that product = high * 2²⁵⁶ + low.
        assembly ("memory-safe") {
            let mm := mulmod(a, b, not(0))
            low := mul(a, b)
            high := sub(sub(mm, low), lt(mm, low))
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a + b;
            success = c >= a;
            result = c * SafeCast.toUint(success);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a - b;
            success = c <= a;
            result = c * SafeCast.toUint(success);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a * b;
            assembly ("memory-safe") {
                // Only true when the multiplication doesn't overflow
                // (c / a == b) || (a == 0)
                success := or(eq(div(c, a), b), iszero(a))
            }
            // equivalent to: success ? c : 0
            result = c * SafeCast.toUint(success);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            success = b > 0;
            assembly ("memory-safe") {
                // The `DIV` opcode returns zero when the denominator is 0.
                result := div(a, b)
            }
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            success = b > 0;
            assembly ("memory-safe") {
                // The `MOD` opcode returns zero when the denominator is 0.
                result := mod(a, b)
            }
        }
    }

    /**
     * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
     */
    function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
        (bool success, uint256 result) = tryAdd(a, b);
        return ternary(success, result, type(uint256).max);
    }

    /**
     * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
     */
    function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
        (, uint256 result) = trySub(a, b);
        return result;
    }

    /**
     * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
     */
    function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
        (bool success, uint256 result) = tryMul(a, b);
        return ternary(success, result, type(uint256).max);
    }

    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * SafeCast.toUint(condition));
        }
    }

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

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return ternary(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 towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }

        // The following calculation ensures accurate ceiling division without overflow.
        // Since a is non-zero, (a - 1) / b will not overflow.
        // The largest possible result occurs when (a - 1) / b is type(uint256).max,
        // but the largest value we can obtain is type(uint256).max - 1, which happens
        // when a = type(uint256).max and b = 1.
        unchecked {
            return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
        }
    }

    /**
     * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     *
     * 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 {
            (uint256 high, uint256 low) = mul512(x, y);

            // Handle non-overflow cases, 256 by 256 division.
            if (high == 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 low / denominator;
            }

            // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
            if (denominator <= high) {
                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
            }

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

            // Make division exact by subtracting the remainder from [high low].
            uint256 remainder;
            assembly ("memory-safe") {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                high := sub(high, gt(remainder, low))
                low := sub(low, 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.

            uint256 twos = denominator & (0 - denominator);
            assembly ("memory-safe") {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [high low] by twos.
                low := div(low, twos)

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

            // Shift in bits from high into low.
            low |= high * twos;

            // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
            // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv ≡ 1 mod 2⁴.
            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⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

            // 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²⁵⁶. Since the preconditions guarantee that the outcome is
            // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
            // is no longer required.
            result = low * inverse;
            return result;
        }
    }

    /**
     * @dev 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) {
        return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
    }

    /**
     * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
     */
    function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
        unchecked {
            (uint256 high, uint256 low) = mul512(x, y);
            if (high >= 1 << n) {
                Panic.panic(Panic.UNDER_OVERFLOW);
            }
            return (high << (256 - n)) | (low >> n);
        }
    }

    /**
     * @dev Calculates x * y >> n with full precision, following the selected rounding direction.
     */
    function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
        return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
    }

    /**
     * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
     *
     * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
     * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
     *
     * If the input value is not inversible, 0 is returned.
     *
     * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
     * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
     */
    function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
        unchecked {
            if (n == 0) return 0;

            // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
            // Used to compute integers x and y such that: ax + ny = gcd(a, n).
            // When the gcd is 1, then the inverse of a modulo n exists and it's x.
            // ax + ny = 1
            // ax = 1 + (-y)n
            // ax ≡ 1 (mod n) # x is the inverse of a modulo n

            // If the remainder is 0 the gcd is n right away.
            uint256 remainder = a % n;
            uint256 gcd = n;

            // Therefore the initial coefficients are:
            // ax + ny = gcd(a, n) = n
            // 0a + 1n = n
            int256 x = 0;
            int256 y = 1;

            while (remainder != 0) {
                uint256 quotient = gcd / remainder;

                (gcd, remainder) = (
                    // The old remainder is the next gcd to try.
                    remainder,
                    // Compute the next remainder.
                    // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
                    // where gcd is at most n (capped to type(uint256).max)
                    gcd - remainder * quotient
                );

                (x, y) = (
                    // Increment the coefficient of a.
                    y,
                    // Decrement the coefficient of n.
                    // Can overflow, but the result is casted to uint256 so that the
                    // next value of y is "wrapped around" to a value between 0 and n - 1.
                    x - y * int256(quotient)
                );
            }

            if (gcd != 1) return 0; // No inverse exists.
            return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
        }
    }

    /**
     * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
     *
     * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
     * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
     * `a**(p-2)` is the modular multiplicative inverse of a in Fp.
     *
     * NOTE: this function does NOT check that `p` is a prime greater than `2`.
     */
    function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
        unchecked {
            return Math.modExp(a, p - 2, p);
        }
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
     *
     * Requirements:
     * - modulus can't be zero
     * - underlying staticcall to precompile must succeed
     *
     * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
     * sure the chain you're using it on supports the precompiled contract for modular exponentiation
     * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
     * the underlying function will succeed given the lack of a revert, but the result may be incorrectly
     * interpreted as 0.
     */
    function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
        (bool success, uint256 result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
     * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
     * to operate modulo 0 or if the underlying precompile reverted.
     *
     * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
     * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
     * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
     * of a revert, but the result may be incorrectly interpreted as 0.
     */
    function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
        if (m == 0) return (false, 0);
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            // | Offset    | Content    | Content (Hex)                                                      |
            // |-----------|------------|--------------------------------------------------------------------|
            // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x60:0x7f | value of b | 0x<.............................................................b> |
            // | 0x80:0x9f | value of e | 0x<.............................................................e> |
            // | 0xa0:0xbf | value of m | 0x<.............................................................m> |
            mstore(ptr, 0x20)
            mstore(add(ptr, 0x20), 0x20)
            mstore(add(ptr, 0x40), 0x20)
            mstore(add(ptr, 0x60), b)
            mstore(add(ptr, 0x80), e)
            mstore(add(ptr, 0xa0), m)

            // Given the result < m, it's guaranteed to fit in 32 bytes,
            // so we can use the memory scratch space located at offset 0.
            success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
            result := mload(0x00)
        }
    }

    /**
     * @dev Variant of {modExp} that supports inputs of arbitrary length.
     */
    function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
        (bool success, bytes memory result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Variant of {tryModExp} that supports inputs of arbitrary length.
     */
    function tryModExp(
        bytes memory b,
        bytes memory e,
        bytes memory m
    ) internal view returns (bool success, bytes memory result) {
        if (_zeroBytes(m)) return (false, new bytes(0));

        uint256 mLen = m.length;

        // Encode call args in result and move the free memory pointer
        result = abi.encodePacked(b.length, e.length, mLen, b, e, m);

        assembly ("memory-safe") {
            let dataPtr := add(result, 0x20)
            // Write result on top of args to avoid allocating extra memory.
            success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
            // Overwrite the length.
            // result.length > returndatasize() is guaranteed because returndatasize() == m.length
            mstore(result, mLen)
            // Set the memory pointer after the returned data.
            mstore(0x40, add(dataPtr, mLen))
        }
    }

    /**
     * @dev Returns whether the provided byte array is zero.
     */
    function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
        for (uint256 i = 0; i < byteArray.length; ++i) {
            if (byteArray[i] != 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * This method is based on Newton's method for computing square roots; the algorithm is restricted to only
     * using integer operations.
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        unchecked {
            // Take care of easy edge cases when a == 0 or a == 1
            if (a <= 1) {
                return a;
            }

            // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
            // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
            // the current value as `ε_n = | x_n - sqrt(a) |`.
            //
            // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
            // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
            // bigger than any uint256.
            //
            // By noticing that
            // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
            // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
            // to the msb function.
            uint256 aa = a;
            uint256 xn = 1;

            if (aa >= (1 << 128)) {
                aa >>= 128;
                xn <<= 64;
            }
            if (aa >= (1 << 64)) {
                aa >>= 64;
                xn <<= 32;
            }
            if (aa >= (1 << 32)) {
                aa >>= 32;
                xn <<= 16;
            }
            if (aa >= (1 << 16)) {
                aa >>= 16;
                xn <<= 8;
            }
            if (aa >= (1 << 8)) {
                aa >>= 8;
                xn <<= 4;
            }
            if (aa >= (1 << 4)) {
                aa >>= 4;
                xn <<= 2;
            }
            if (aa >= (1 << 2)) {
                xn <<= 1;
            }

            // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
            //
            // We can refine our estimation by noticing that the middle of that interval minimizes the error.
            // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
            // This is going to be our x_0 (and ε_0)
            xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)

            // From here, Newton's method give us:
            // x_{n+1} = (x_n + a / x_n) / 2
            //
            // One should note that:
            // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
            //              = ((x_n² + a) / (2 * x_n))² - a
            //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
            //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
            //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
            //              = (x_n² - a)² / (2 * x_n)²
            //              = ((x_n² - a) / (2 * x_n))²
            //              ≥ 0
            // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
            //
            // This gives us the proof of quadratic convergence of the sequence:
            // ε_{n+1} = | x_{n+1} - sqrt(a) |
            //         = | (x_n + a / x_n) / 2 - sqrt(a) |
            //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
            //         = | (x_n - sqrt(a))² / (2 * x_n) |
            //         = | ε_n² / (2 * x_n) |
            //         = ε_n² / | (2 * x_n) |
            //
            // For the first iteration, we have a special case where x_0 is known:
            // ε_1 = ε_0² / | (2 * x_0) |
            //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
            //     ≤ 2**(2*e-4) / (3 * 2**(e-1))
            //     ≤ 2**(e-3) / 3
            //     ≤ 2**(e-3-log2(3))
            //     ≤ 2**(e-4.5)
            //
            // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
            // ε_{n+1} = ε_n² / | (2 * x_n) |
            //         ≤ (2**(e-k))² / (2 * 2**(e-1))
            //         ≤ 2**(2*e-2*k) / 2**e
            //         ≤ 2**(e-2*k)
            xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above
            xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5
            xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9
            xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18
            xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36
            xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72

            // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
            // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
            // sqrt(a) or sqrt(a) + 1.
            return xn - SafeCast.toUint(xn > a / xn);
        }
    }

    /**
     * @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 x) internal pure returns (uint256 r) {
        // If value has upper 128 bits set, log2 result is at least 128
        r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
        // If upper 64 bits of 128-bit half set, add 64 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
        // If upper 32 bits of 64-bit half set, add 32 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
        // If upper 16 bits of 32-bit half set, add 16 to result
        r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
        // If upper 8 bits of 16-bit half set, add 8 to result
        r |= SafeCast.toUint((x >> r) > 0xff) << 3;
        // If upper 4 bits of 8-bit half set, add 4 to result
        r |= SafeCast.toUint((x >> r) > 0xf) << 2;

        // Shifts value right by the current result and use it as an index into this lookup table:
        //
        // | x (4 bits) |  index  | table[index] = MSB position |
        // |------------|---------|-----------------------------|
        // |    0000    |    0    |        table[0] = 0         |
        // |    0001    |    1    |        table[1] = 0         |
        // |    0010    |    2    |        table[2] = 1         |
        // |    0011    |    3    |        table[3] = 1         |
        // |    0100    |    4    |        table[4] = 2         |
        // |    0101    |    5    |        table[5] = 2         |
        // |    0110    |    6    |        table[6] = 2         |
        // |    0111    |    7    |        table[7] = 2         |
        // |    1000    |    8    |        table[8] = 3         |
        // |    1001    |    9    |        table[9] = 3         |
        // |    1010    |   10    |        table[10] = 3        |
        // |    1011    |   11    |        table[11] = 3        |
        // |    1100    |   12    |        table[12] = 3        |
        // |    1101    |   13    |        table[13] = 3        |
        // |    1110    |   14    |        table[14] = 3        |
        // |    1111    |   15    |        table[15] = 3        |
        //
        // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
        assembly ("memory-safe") {
            r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
        }
    }

    /**
     * @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * 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 x) internal pure returns (uint256 r) {
        // If value has upper 128 bits set, log2 result is at least 128
        r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
        // If upper 64 bits of 128-bit half set, add 64 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
        // If upper 32 bits of 64-bit half set, add 32 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
        // If upper 16 bits of 32-bit half set, add 16 to result
        r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
        // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
        return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
    }

    /**
     * @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

File 15 of 22 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }

    /**
     * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
     */
    function toUint(bool b) internal pure returns (uint256 u) {
        assembly ("memory-safe") {
            u := iszero(iszero(b))
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

import {SafeCast} from "./SafeCast.sol";

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
        }
    }

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

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return ternary(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 {
            // Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
            // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
            // taking advantage of the most significant (or "sign" bit) in two's complement representation.
            // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
            // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
            int256 mask = n >> 255;

            // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
            return uint256((n + mask) ^ mask);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)

pragma solidity ^0.8.20;

/**
 * @dev Helper library for emitting standardized panic codes.
 *
 * ```solidity
 * contract Example {
 *      using Panic for uint256;
 *
 *      // Use any of the declared internal constants
 *      function foo() { Panic.GENERIC.panic(); }
 *
 *      // Alternatively
 *      function foo() { Panic.panic(Panic.GENERIC); }
 * }
 * ```
 *
 * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
 *
 * _Available since v5.1._
 */
// slither-disable-next-line unused-state
library Panic {
    /// @dev generic / unspecified error
    uint256 internal constant GENERIC = 0x00;
    /// @dev used by the assert() builtin
    uint256 internal constant ASSERT = 0x01;
    /// @dev arithmetic underflow or overflow
    uint256 internal constant UNDER_OVERFLOW = 0x11;
    /// @dev division or modulo by zero
    uint256 internal constant DIVISION_BY_ZERO = 0x12;
    /// @dev enum conversion error
    uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
    /// @dev invalid encoding in storage
    uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
    /// @dev empty array pop
    uint256 internal constant EMPTY_ARRAY_POP = 0x31;
    /// @dev array out of bounds access
    uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
    /// @dev resource error (too large allocation or too large array)
    uint256 internal constant RESOURCE_ERROR = 0x41;
    /// @dev calling invalid internal function
    uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;

    /// @dev Reverts with a panic code. Recommended to use with
    /// the internal constants with predefined codes.
    function panic(uint256 code) internal pure {
        assembly ("memory-safe") {
            mstore(0x00, 0x4e487b71)
            mstore(0x20, code)
            revert(0x1c, 0x24)
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    using SafeCast for *;

    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;
    uint256 private constant SPECIAL_CHARS_LOOKUP =
        (1 << 0x08) | // backspace
            (1 << 0x09) | // tab
            (1 << 0x0a) | // newline
            (1 << 0x0c) | // form feed
            (1 << 0x0d) | // carriage return
            (1 << 0x22) | // double quote
            (1 << 0x5c); // backslash

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev The string being parsed contains characters that are not in scope of the given base.
     */
    error StringsInvalidChar();

    /**
     * @dev The string being parsed is not a properly formatted address.
     */
    error StringsInvalidAddressFormat();

    /**
     * @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;
            assembly ("memory-safe") {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                assembly ("memory-safe") {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(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) {
        uint256 localValue = value;
        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] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        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 Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
     * representation, according to EIP-55.
     */
    function toChecksumHexString(address addr) internal pure returns (string memory) {
        bytes memory buffer = bytes(toHexString(addr));

        // hash the hex part of buffer (skip length + 2 bytes, length 40)
        uint256 hashValue;
        assembly ("memory-safe") {
            hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
        }

        for (uint256 i = 41; i > 1; --i) {
            // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
            if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
                // case shift by xoring with 0x20
                buffer[i] ^= 0x20;
            }
            hashValue >>= 4;
        }
        return string(buffer);
    }

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

    /**
     * @dev Parse a decimal string and returns the value as a `uint256`.
     *
     * Requirements:
     * - The string must be formatted as `[0-9]*`
     * - The result must fit into an `uint256` type
     */
    function parseUint(string memory input) internal pure returns (uint256) {
        return parseUint(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `[0-9]*`
     * - The result must fit into an `uint256` type
     */
    function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
        (bool success, uint256 value) = tryParseUint(input, begin, end);
        if (!success) revert StringsInvalidChar();
        return value;
    }

    /**
     * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
        return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
     * character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseUint(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, uint256 value) {
        if (end > bytes(input).length || begin > end) return (false, 0);
        return _tryParseUintUncheckedBounds(input, begin, end);
    }

    /**
     * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
     * `begin <= end <= input.length`. Other inputs would result in undefined behavior.
     */
    function _tryParseUintUncheckedBounds(
        string memory input,
        uint256 begin,
        uint256 end
    ) private pure returns (bool success, uint256 value) {
        bytes memory buffer = bytes(input);

        uint256 result = 0;
        for (uint256 i = begin; i < end; ++i) {
            uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
            if (chr > 9) return (false, 0);
            result *= 10;
            result += chr;
        }
        return (true, result);
    }

    /**
     * @dev Parse a decimal string and returns the value as a `int256`.
     *
     * Requirements:
     * - The string must be formatted as `[-+]?[0-9]*`
     * - The result must fit in an `int256` type.
     */
    function parseInt(string memory input) internal pure returns (int256) {
        return parseInt(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `[-+]?[0-9]*`
     * - The result must fit in an `int256` type.
     */
    function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
        (bool success, int256 value) = tryParseInt(input, begin, end);
        if (!success) revert StringsInvalidChar();
        return value;
    }

    /**
     * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
     * the result does not fit in a `int256`.
     *
     * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
     */
    function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
        return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
    }

    uint256 private constant ABS_MIN_INT256 = 2 ** 255;

    /**
     * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
     * character or if the result does not fit in a `int256`.
     *
     * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
     */
    function tryParseInt(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, int256 value) {
        if (end > bytes(input).length || begin > end) return (false, 0);
        return _tryParseIntUncheckedBounds(input, begin, end);
    }

    /**
     * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that
     * `begin <= end <= input.length`. Other inputs would result in undefined behavior.
     */
    function _tryParseIntUncheckedBounds(
        string memory input,
        uint256 begin,
        uint256 end
    ) private pure returns (bool success, int256 value) {
        bytes memory buffer = bytes(input);

        // Check presence of a negative sign.
        bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
        bool positiveSign = sign == bytes1("+");
        bool negativeSign = sign == bytes1("-");
        uint256 offset = (positiveSign || negativeSign).toUint();

        (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);

        if (absSuccess && absValue < ABS_MIN_INT256) {
            return (true, negativeSign ? -int256(absValue) : int256(absValue));
        } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
            return (true, type(int256).min);
        } else return (false, 0);
    }

    /**
     * @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
     *
     * Requirements:
     * - The string must be formatted as `(0x)?[0-9a-fA-F]*`
     * - The result must fit in an `uint256` type.
     */
    function parseHexUint(string memory input) internal pure returns (uint256) {
        return parseHexUint(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
     * - The result must fit in an `uint256` type.
     */
    function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
        (bool success, uint256 value) = tryParseHexUint(input, begin, end);
        if (!success) revert StringsInvalidChar();
        return value;
    }

    /**
     * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
        return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
     * invalid character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseHexUint(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, uint256 value) {
        if (end > bytes(input).length || begin > end) return (false, 0);
        return _tryParseHexUintUncheckedBounds(input, begin, end);
    }

    /**
     * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
     * `begin <= end <= input.length`. Other inputs would result in undefined behavior.
     */
    function _tryParseHexUintUncheckedBounds(
        string memory input,
        uint256 begin,
        uint256 end
    ) private pure returns (bool success, uint256 value) {
        bytes memory buffer = bytes(input);

        // skip 0x prefix if present
        bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
        uint256 offset = hasPrefix.toUint() * 2;

        uint256 result = 0;
        for (uint256 i = begin + offset; i < end; ++i) {
            uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
            if (chr > 15) return (false, 0);
            result *= 16;
            unchecked {
                // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
                // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.
                result += chr;
            }
        }
        return (true, result);
    }

    /**
     * @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
     *
     * Requirements:
     * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
     */
    function parseAddress(string memory input) internal pure returns (address) {
        return parseAddress(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
     */
    function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
        (bool success, address value) = tryParseAddress(input, begin, end);
        if (!success) revert StringsInvalidAddressFormat();
        return value;
    }

    /**
     * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
     * formatted address. See {parseAddress-string} requirements.
     */
    function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
        return tryParseAddress(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
     * formatted address. See {parseAddress-string-uint256-uint256} requirements.
     */
    function tryParseAddress(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, address value) {
        if (end > bytes(input).length || begin > end) return (false, address(0));

        bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
        uint256 expectedLength = 40 + hasPrefix.toUint() * 2;

        // check that input is the correct length
        if (end - begin == expectedLength) {
            // length guarantees that this does not overflow, and value is at most type(uint160).max
            (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
            return (s, address(uint160(v)));
        } else {
            return (false, address(0));
        }
    }

    function _tryParseChr(bytes1 chr) private pure returns (uint8) {
        uint8 value = uint8(chr);

        // Try to parse `chr`:
        // - Case 1: [0-9]
        // - Case 2: [a-f]
        // - Case 3: [A-F]
        // - otherwise not supported
        unchecked {
            if (value > 47 && value < 58) value -= 48;
            else if (value > 96 && value < 103) value -= 87;
            else if (value > 64 && value < 71) value -= 55;
            else return type(uint8).max;
        }

        return value;
    }

    /**
     * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
     *
     * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
     *
     * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
     * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
     * characters that are not in this range, but other tooling may provide different results.
     */
    function escapeJSON(string memory input) internal pure returns (string memory) {
        bytes memory buffer = bytes(input);
        bytes memory output = new bytes(2 * buffer.length); // worst case scenario
        uint256 outputLength = 0;

        for (uint256 i; i < buffer.length; ++i) {
            bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));
            if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {
                output[outputLength++] = "\\";
                if (char == 0x08) output[outputLength++] = "b";
                else if (char == 0x09) output[outputLength++] = "t";
                else if (char == 0x0a) output[outputLength++] = "n";
                else if (char == 0x0c) output[outputLength++] = "f";
                else if (char == 0x0d) output[outputLength++] = "r";
                else if (char == 0x5c) output[outputLength++] = "\\";
                else if (char == 0x22) {
                    // solhint-disable-next-line quotes
                    output[outputLength++] = '"';
                }
            } else {
                output[outputLength++] = char;
            }
        }
        // write the actual length and deallocate unused memory
        assembly ("memory-safe") {
            mstore(output, outputLength)
            mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))
        }

        return string(output);
    }

    /**
     * @dev Reads a bytes32 from a bytes array without bounds checking.
     *
     * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
     * assembly block as such would prevent some optimizations.
     */
    function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
        // This is not memory safe in the general case, but all calls to this private function are within bounds.
        assembly ("memory-safe") {
            value := mload(add(buffer, add(0x20, offset)))
        }
    }
}

// Copyright 2025 Energi Core

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

// Energi Governance system is the fundamental part of Energi Core.

// NOTE: It's not allowed to change the compiler due to byte-to-byte
//       match requirement.

/// @title  IERC20MintBurn
/// @author Energi Core

pragma solidity 0.8.22;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IERC20MintBurn is IERC20 {
    function mint(address to, uint256 amount) external;

    function burn(address from, uint256 amount) external;
}

// Copyright 2025 Energi Core

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

// Energi Governance system is the fundamental part of Energi Core.

// NOTE: It's not allowed to change the compiler due to byte-to-byte
//       match requirement.

/// @title  ILiquidityBonds
/// @author Energi Core

pragma solidity 0.8.22;

import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";

interface ILiquidityBonds is IERC721 {
    function mint(address _to, uint256 _uniswapV3PositionId) external;

    function burn(uint256 _tokenId) external;

    function currentIndex() external view returns (uint256);

    function getBondInfo(
        uint256 _bondId
    )
        external
        view
        returns (
            uint256 uniswapV3PositionId,
            uint256 startTime,
            uint256 duration,
            uint256 durationLeft,
            uint256 rewardsGMI,
            uint256 rewardsWETH9
        );
}

// Copyright 2025 Energi Core

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

// Energi Governance system is the fundamental part of Energi Core.

// NOTE: It's not allowed to change the compiler due to byte-to-byte
//       match requirement.

/// @title  INonFungiblePositionManager
/// @author Energi Core

pragma solidity 0.8.22;

import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";

interface INonFungiblePositionManager is IERC721 {
    /// @notice Emitted when liquidity is increased for a position NFT
    /// @dev Also emitted when a token is minted
    /// @param tokenId The ID of the token for which liquidity was increased
    /// @param liquidity The amount by which liquidity for the NFT position was increased
    /// @param amount0 The amount of token0 that was paid for the increase in liquidity
    /// @param amount1 The amount of token1 that was paid for the increase in liquidity
    event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when liquidity is decreased for a position NFT
    /// @param tokenId The ID of the token for which liquidity was decreased
    /// @param liquidity The amount by which liquidity for the NFT position was decreased
    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when tokens are collected for a position NFT
    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
    /// @param tokenId The ID of the token for which underlying tokens were collected
    /// @param recipient The address of the account that received the collected tokens
    /// @param amount0 The amount of token0 owed to the position that was collected
    /// @param amount1 The amount of token1 owed to the position that was collected
    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

    /// @notice Returns the position information associated with a given token ID.
    /// @dev Throws if the token ID is not valid.
    /// @param tokenId The ID of the token that represents the position
    /// @return nonce The nonce for permits
    /// @return operator The address that is approved for spending
    /// @return token0 The address of the token0 for a specific pool
    /// @return token1 The address of the token1 for a specific pool
    /// @return fee The fee associated with the pool
    /// @return tickLower The lower end of the tick range for the position
    /// @return tickUpper The higher end of the tick range for the position
    /// @return liquidity The liquidity of the position
    /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
    /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
    /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
    /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
    function positions(
        uint256 tokenId
    )
        external
        view
        returns (
            uint96 nonce,
            address operator,
            address token0,
            address token1,
            uint24 fee,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    struct MintParams {
        address token0;
        address token1;
        uint24 fee;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        address recipient;
        uint256 deadline;
    }

    /// @notice Creates a new position wrapped in a NFT
    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
    /// a method does not exist, i.e. the pool is assumed to be initialized.
    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
    /// @return tokenId The ID of the token that represents the minted position
    /// @return liquidity The amount of liquidity for this position
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function mint(
        MintParams calldata params
    ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);

    struct IncreaseLiquidityParams {
        uint256 tokenId;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
    /// @param params tokenId The ID of the token for which liquidity is being increased,
    /// amount0Desired The desired amount of token0 to be spent,
    /// amount1Desired The desired amount of token1 to be spent,
    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return liquidity The new liquidity amount as a result of the increase
    /// @return amount0 The amount of token0 to acheive resulting liquidity
    /// @return amount1 The amount of token1 to acheive resulting liquidity
    function increaseLiquidity(
        IncreaseLiquidityParams calldata params
    ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);

    struct DecreaseLiquidityParams {
        uint256 tokenId;
        uint128 liquidity;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Decreases the amount of liquidity in a position and accounts it to the position
    /// @param params tokenId The ID of the token for which liquidity is being decreased,
    /// amount The amount by which liquidity will be decreased,
    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return amount0 The amount of token0 accounted to the position's tokens owed
    /// @return amount1 The amount of token1 accounted to the position's tokens owed
    function decreaseLiquidity(
        DecreaseLiquidityParams calldata params
    ) external payable returns (uint256 amount0, uint256 amount1);

    struct CollectParams {
        uint256 tokenId;
        address recipient;
        uint128 amount0Max;
        uint128 amount1Max;
    }

    /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
    /// @param params tokenId The ID of the NFT for which tokens are being collected,
    /// recipient The account that should receive the tokens,
    /// amount0Max The maximum amount of token0 to collect,
    /// amount1Max The maximum amount of token1 to collect
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);

    /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
    /// must be collected first.
    /// @param tokenId The ID of the token that is being burned
    function burn(uint256 tokenId) external payable;
}

File 22 of 22 : IUniswapV3Pool.sol
// Copyright 2025 Energi Core

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

// Energi Governance system is the fundamental part of Energi Core.

// NOTE: It's not allowed to change the compiler due to byte-to-byte
//       match requirement.

/// @title  IUniswapV3Pool
/// @author Energi Core

pragma solidity 0.8.22;

import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";

interface IUniswapV3Pool is IERC721 {
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );
}

//  // the current price
//         uint160 sqrtPriceX96;
//         // the current tick
//         int24 tick;
//         // the most-recently updated index of the observations array
//         uint16 observationIndex;
//         // the current maximum number of observations that are being stored
//         uint16 observationCardinality;
//         // the next maximum number of observations to store, triggered in observations.write
//         uint16 observationCardinalityNext;
//         // the current protocol fee as a percentage of the swap fee taken on withdrawal
//         // represented as an integer denominator (1/x)%
//         uint8 feeProtocol;
//         // whether the pool is locked
//         bool unlocked;

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "viaIR": true,
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"additional","type":"uint256"}],"name":"AdditionalSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bondId","type":"uint256"},{"indexed":false,"internalType":"address","name":"collection","type":"address"},{"indexed":false,"internalType":"address","name":"token0","type":"address"},{"indexed":false,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"uint256","name":"requiredAmount1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bondType","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lockDuration","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"multiplier","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isActive","type":"bool"}],"name":"BondSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Erc20sRecovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Erc721Recovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EthRecovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldGMI","type":"address"},{"indexed":true,"internalType":"address","name":"newGMI","type":"address"}],"name":"GMISet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"layerId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"bondId","type":"uint256"},{"indexed":false,"internalType":"address","name":"baseLayer","type":"address"},{"indexed":false,"internalType":"address","name":"outputLayer","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"LayerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bondId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalBonds","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"PositionLocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lpBondTokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"uniswapV3PositionId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"bondId","type":"uint256"},{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"PositionUnlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldSigner","type":"address"},{"indexed":true,"internalType":"address","name":"newSigner","type":"address"}],"name":"SignerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldManager","type":"address"},{"indexed":true,"internalType":"address","name":"newManager","type":"address"}],"name":"UniswapPositionManagerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"additional","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"basePositions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bonds","outputs":[{"internalType":"uint256","name":"bondId","type":"uint256"},{"internalType":"address","name":"collection","type":"address"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"requiredAmount1","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"bondType","type":"uint256"},{"internalType":"uint256","name":"lockDuration","type":"uint256"},{"internalType":"uint256","name":"multiplier","type":"uint256"},{"internalType":"bool","name":"isActive","type":"bool"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"bool","name":"isGMIPool","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_uniswapV3PositionId","type":"uint256"}],"name":"getRewards0","outputs":[{"internalType":"uint256","name":"rewards0","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gmi","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"uniswapPositionManager_","type":"address"},{"internalType":"address","name":"signer_","type":"address"},{"internalType":"address","name":"gmi_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"layers","outputs":[{"internalType":"uint256","name":"layerId","type":"uint256"},{"internalType":"uint256","name":"origBondId","type":"uint256"},{"internalType":"uint256","name":"bondId","type":"uint256"},{"internalType":"address","name":"baseLayer","type":"address"},{"internalType":"address","name":"outputLayer","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bondId","type":"uint256"},{"internalType":"uint256","name":"_layerId","type":"uint256"},{"internalType":"uint256[]","name":"_baseTokenId","type":"uint256[]"},{"internalType":"uint256","name":"_amount0","type":"uint256"},{"internalType":"uint256","name":"_amount1","type":"uint256"},{"internalType":"uint256","name":"_fee","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"},{"internalType":"uint256","name":"_numberOfBonds","type":"uint256"}],"name":"lockPositionChild","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"locks","outputs":[{"internalType":"uint256","name":"uniswapV3PositionId","type":"uint256"},{"internalType":"uint256","name":"lpBondId","type":"uint256"},{"internalType":"uint256","name":"bondId","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"lockedAmount0","type":"uint256"},{"internalType":"uint256","name":"lockedAmount1","type":"uint256"},{"internalType":"bool","name":"isLocked","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"multiSig","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"multiSigBurned","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"recoverERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"recoverERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"recoverETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newAdditional","type":"uint256"}],"name":"setAdditional","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bondId","type":"uint256"},{"internalType":"uint256","name":"_basePosition","type":"uint256"}],"name":"setBasePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bondId","type":"uint256"},{"internalType":"address","name":"_collection","type":"address"},{"internalType":"address","name":"_token0","type":"address"},{"internalType":"address","name":"_token1","type":"address"},{"internalType":"uint256","name":"_requiredAmount1","type":"uint256"},{"internalType":"uint256","name":"_fee","type":"uint256"},{"internalType":"int24","name":"_tickLower","type":"int24"},{"internalType":"int24","name":"_tickUpper","type":"int24"},{"internalType":"uint256","name":"_amount0Min","type":"uint256"},{"internalType":"uint256","name":"_amount1Min","type":"uint256"},{"internalType":"uint256","name":"_bondType","type":"uint256"},{"internalType":"uint256","name":"_lockDuration","type":"uint256"},{"internalType":"uint256","name":"_multiplier","type":"uint256"},{"internalType":"bool","name":"_isActive","type":"bool"},{"internalType":"address","name":"_pool","type":"address"},{"internalType":"bool","name":"_isGMIPool","type":"bool"}],"name":"setBond","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newGMI","type":"address"}],"name":"setGMI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_layerId","type":"uint256"},{"internalType":"uint256","name":"_origBondId","type":"uint256"},{"internalType":"uint256","name":"_bondId","type":"uint256"},{"internalType":"address","name":"_baseLayer","type":"address"},{"internalType":"address","name":"_outputLayer","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setLayer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_multiSig","type":"address"}],"name":"setMultiSig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_multiSigBurned","type":"address"}],"name":"setMultiSigBurned","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newSigner","type":"address"}],"name":"setSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bondId","type":"uint256"},{"internalType":"uint256","name":"_startTime","type":"uint256"}],"name":"setStartTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_uniswapPositionManager","type":"address"}],"name":"setUniswapPositionManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"startTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"uniswapPositionManager","outputs":[{"internalType":"contract INonFungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lpBondTokenId","type":"uint256"},{"internalType":"uint256","name":"_bondId","type":"uint256"}],"name":"unlockPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

608080604052346100165761364a908161001c8239f35b600080fdfe6080604052600436101561001b575b361561001957600080fd5b005b6000803560e01c8063021c025d146126b75780630e11ffae146119055780631171bda914611804578063150b7a02146117955780631aac4c5e146116ae5780631ffc67fb14611685578063238ac9331461165c578063284d30ef146116115780632cdf2c351461152b5780633395acc7146114d057806336e0004a146114a757806339a2d2fe1461130f5780633e0c0629146111a75780633ec4c9681461117d5780633f4ba83a1461110b57806356a701311461108c5780635c975abb146110695780635f1c17c014610f6a5780636c19e78314610edf578063715018a614610e7e578063810d675a14610e575780638456cb5914610de15780638da5cb5b14610db857806390d082e914610d8e5780639de3567c14610d03578063affed0e014610ce5578063b44eeea71461064c578063ba278e0814610618578063c0c53b8b146103f9578063ca1de4fe146103ae578063db358f2f14610385578063e5047b301461035c578063e8ea79c01461033e578063edf8bc05146102c0578063f2fde38b146102265763f4dadc61146101b3575061000e565b3461022357602036600319011261022357604060e091600435815260ca602052208054906001810154906002810154600382015460048301549160ff600660058601549501541694604051968752602087015260408601526060850152608084015260a0830152151560c0820152f35b80fd5b503461022357602036600319011261022357610240612d72565b6033546001600160a01b03906102599082163314612fac565b81161561026c576102699061341a565b80f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b503461022357604060e0916102d436612cee565b90825260d360205282822090825260205220805490600181015490600281015460018060a01b039081600384015416906006836004860154169360058601541694015494604051968752602087015260408601526060850152608084015260a083015260c0820152f35b5034610223578060031936011261022357602060ce54604051908152f35b503461022357806003193601126102235760cc546040516001600160a01b039091168152602090f35b503461022357806003193601126102235760cd546040516001600160a01b039091168152602090f35b5034610223576020366003190112610223576103c8612d72565b6033546001600160a01b0391906103e29083163314612fac565b166001600160601b0360a01b60d454161760d45580f35b503461022357606036600319011261022357610413612d72565b61041b612d88565b610423612db4565b9183549260ff8460081c168060001461060e57303b155b156105b2571593846105a1575b506001600160a01b0391821692831561054657821680156104f5576001600160601b0360a01b938460cc54161760cc558360cf54161760cf55169060cd54161760cd556104a360ff835460081c1661049e81613463565b613463565b6104ac3361341a565b8154906104de60ff8360081c166104c281613463565b6104cb81613463565b60ff196065541660655561049e81613463565b60016097556104eb575080f35b61ff001916815580f35b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964207369676044820152623732b960e91b6064820152608490fd5b60405162461bcd60e51b815260206004820152602d60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420706f7360448201526c34ba34b7b71036b0b730b3b2b960991b6064820152608490fd5b61ffff191661010117855538610447565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b60ff85161561043a565b50346102235761062736612cee565b9061063d60018060a01b03603354163314612fac565b825260d2602052604082205580f35b50346102235761020036600319011261022357610667612d88565b61066f612db4565b610677612d9e565b60c435918260020b8303610ce05760e435928360020b8403610ce0576101a435938415158503610ce0576101c4356001600160a01b0381168103610ce0576101e435918215158303610ce0576106d860018060a01b03603354163314612fac565b60043515610c87576101643515610c2f576101843515610bda5760843515610b80576001600160a01b03881615610b2b576001600160a01b03851615610ada576001600160a01b03861615610a89576001600160a01b0385811690871614610a36576001600160a01b038216156109e757604051938461020081011067ffffffffffffffff610200870111176109d1576102008501604052600435855260018060a01b038916602086015260018060a01b038616604086015260018060a01b0387166060860152608435608086015260a43560a086015260020b60c085015260020b60e084015261010435610100840152610124356101208401526101443561014084015261016435610160840152610184356101808401528515156101a084015260018060a01b03166101c083015215156101e0820152600435865260c9602052600c60408720825181556001810160018060a01b03602085015116906001600160601b0360a01b91828254161790556002820160018060a01b0360408601511682825416179055600382019060018060a01b03606086015116908254161790556080830151600482015560a083015160058201556006810160c0840151815462ffffff60e087015160181b65ffffff0000001692169065ffffffffffff191617179055610100830151600782015561012083015160088201556101408301516009820155610160830151600a820155610180830151600b82015501906109136101a08201511515839060ff801983541691151516179055565b6101c081015182546101e090920151610100600160b01b031990921660089190911b610100600160a81b03161790151560a81b60ff60a81b16179055604080516001600160a01b03958616815291851660208301529190931690830152608435606083015260a43560808301526101443560a08301526101643560c08301526101843560e08301521515610100820152600435907f1ec2cb67b4962fb16bf5646dd75edc5850e0424571d73e6091e80788a3f4ad5f9061012090a280f35b634e487b7160e01b600052604160045260246000fd5b60405162461bcd60e51b815260206004820152602160248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420706f6f6044820152601b60fa1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602560248201527f4c6971756964697479426f6e644c6f636b65723a204964656e746963616c20746044820152646f6b656e7360d81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420746f6b604482015262656e3160e81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420746f6b6044820152620656e360ec1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420636f6c6044820152663632b1ba34b7b760c91b6064820152608490fd5b60405162461bcd60e51b815260206004820152602c60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c69642072657160448201526b1d5a5c995908185b5bdd5b9d60a21b6064820152608490fd5b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964206d756c6044820152663a34b83634b2b960c91b6064820152608490fd5b60405162461bcd60e51b815260206004820152602a60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964206c6f636044820152693590323ab930ba34b7b760b11b6064820152608490fd5b60405162461bcd60e51b815260206004820152602b60248201527f4c6971756964697479426f6e644c6f636b65723a20426f6e642049442063616e60448201526a6e6f74206265207a65726f60a81b6064820152608490fd5b600080fd5b5034610223578060031936011261022357602060d054604051908152f35b503461022357602036600319011261022357610d1d612d72565b6033546001600160a01b03918291610d389083163314612fac565b1690610d45821515613109565b8160cc5491821691610d59828414156131a4565b6001600160a01b0319161760cc557fdc191f971b2df5e9dfb661b1bd934266d7873a21719372ac9a6415b7f5c679668380a380f35b5034610223576020366003190112610223576040602091600435815260cb83522054604051908152f35b50346102235780600319360112610223576033546040516001600160a01b039091168152602090f35b5034610223578060031936011261022357610e0760018060a01b03603354163314612fac565b6001606554610e2260ff821615610e1d81612e4b565b612e4b565b60ff1916176065557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a180f35b5034610223576020366003190112610223576020610e76600435613207565b604051908152f35b50346102235780600319360112610223576033546000906001600160a01b03811690610eab338314612fac565b6001600160a01b0319166033557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b503461022357602036600319011261022357610ef9612d72565b6033546001600160a01b03918291610f149083163314612fac565b1690610f21821515613109565b8160cf5491821691610f35828414156131a4565b6001600160a01b0319161760cf557fb0604c365feafa080c833b6f6814d321a7561528e696ac2a112c2a0231b0ed358380a380f35b503461022357602036600319011261022357604061020091600435815260c96020522060ff81549160018060a01b036001820154169060018060a01b0360028201541660018060a01b03600383015416600483015460058401546006850154600786015491600887015493600988015495600a89015497600c600b8b01549a01549a60206040519e8f908152015260408d015260608c015260808b015260a08a01528060020b60c08a015260181c60020b60e089015261010088015261012087015261014086015261016085015261018084015281811615156101a084015260018060a01b038160081c166101c084015260a81c1615156101e0820152f35b5034610223578060031936011261022357602060ff606554166040519015158152f35b5034610223576020366003190112610223576110a6612d72565b6033546001600160a01b039182916110c19083163314612fac565b16906110ce821515613109565b60cd54826001600160601b0360a01b82161760cd55167f3a753e7c76490009eaecdc23ebd537d53b956ed9b6ada05cabd6a2e36b4e43d38380a380f35b503461022357806003193601126102235761113160018060a01b03603354163314612fac565b60655461114960ff821661114481613161565b613161565b60ff19166065557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a180f35b5034610223576020366003190112610223576040602091600435815260d283522054604051908152f35b5034610223576040366003190112610223576111c1612d72565b60243560018060a01b036111da81603354163314612fac565b8216916111e8831515613109565b6111f38215156130b1565b8147106112b8578380808481945af13d156112b3573d61121281612d56565b906112206040519283612d34565b81528460203d92013e5b1561125d5760207fd01205615e35ba1dd087bd6dac5922e0370961b3726c247c078cd59baae5770e91604051908152a280f35b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e644c6f636b65723a20455448207472616e7366656044820152671c8819985a5b195960c21b6064820152608490fd5b61122a565b60405162461bcd60e51b815260206004820152602960248201527f4c6971756964697479426f6e644c6f636b65723a20496e73756666696369656e604482015268742062616c616e636560b81b6064820152608490fd5b50346102235760e036600319011261022357611329612d9e565b6084356001600160a01b0381168103610ce05760a435906001600160a01b0382168203610ce05761136560018060a01b03603354163314612fac565b60405161137181612d18565b60043581526024356020820152604435604082015260018060a01b03841660608201526006608082019160018060a01b038416835260a0810160018060a01b038616815260c082019160c4358352602435895260d3602052604089206004358a5260205260408920948151865560208201516001870155604082015160028701556003860191606060018060a01b0391015116916001600160601b0360a01b9283825416179055600486019060018060a01b0390511682825416179055600585019160018060a01b0390511690825416179055519101556040519260018060a01b0316835260018060a01b0316602083015260018060a01b0316604082015260c4356060820152604435907f7a31dd6f7d05deffb176e095cb8d04693c64ab6a61343b972c49f525ab83e403608060043592a380f35b503461022357806003193601126102235760d1546040516001600160a01b039091168152602090f35b5034610223576020366003190112610223577f460a822779d1e75985c2b12b355b8c73d1622f575a10f55fb7aae5bd66f00e23602060043561151d60018060a01b03603354163314612fac565b8060ce55604051908152a180f35b50346102235761153a36612dca565b60335491926001600160a01b0392859184916115599083163314612fac565b1692611566841515612ff7565b841693611574851515613056565b833b1561160d576040516323b872dd60e01b81523060048201526001600160a01b0391909116602482015260448101839052818160648183885af18015611602576115ea575b505060207fbac52ce088f0b87a6de233d6dfedfcb5587da9f954ed3a555c468169bd46ed7f91604051908152a380f35b6115f390612d04565b6115fe5783386115ba565b8380fd5b6040513d84823e3d90fd5b5080fd5b50346102235760203660031901126102235761162b612d72565b6033546001600160a01b0391906116459083163314612fac565b166001600160601b0360a01b60d154161760d15580f35b503461022357806003193601126102235760cf546040516001600160a01b039091168152602090f35b503461022357806003193601126102235760d4546040516001600160a01b039091168152602090f35b5034610223576116bd36612cee565b906116d360018060a01b03603354163314612fac565b80156117445781156116ee57825260cb602052604082205580f35b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420706f736044820152671a5d1a5bdb88125160c21b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420626f6e6044820152631908125160e21b6064820152608490fd5b5034610223576080366003190112610223576117af612d72565b506117b8612d88565b5060643567ffffffffffffffff8082116118005736602383011215611800578160040135908111611800573691016024011161022357604051630a85bd0160e11b8152602090f35b8280fd5b50346102235761188b61181636612dca565b60208160018060a09795971b03809561183482603354163314612fac565b1694611841861515612ff7565b86169561184f871515613056565b61185a8215156130b1565b60405163a9059cbb60e01b81526001600160a01b039091166004820152602481019190915292839081906044820190565b038188875af19081156118fa577fedce930554908e152dd7472edd740ccb66cdafafc759fd83714a85b7c043ff91926020926118cd575b50604051908152a380f35b6118ec90833d85116118f3575b6118e48183612d34565b810190612f21565b50386118c2565b503d6118da565b6040513d87823e3d90fd5b506101003660031901126102235760443567ffffffffffffffff811161160d573660238201121561160d5780600401359067ffffffffffffffff82116126a3578160051b6040519261195a6020830185612d34565b8352602460208401918301019136831161220657602401905b8282106126935750505067ffffffffffffffff60c4351161160d5736602360c43501121561160d576119aa60c43560040135612d56565b906119b86040519283612d34565b600460c43590810135808452369101602401116118005760c43560040135602460c43501602084013782602060c43560040135840101526119fe60026097541415612dff565b6002609755611a1260ff6065541615612e4b565b600435835260c960205260408320600101546001600160a01b03161561263d57600435835260cb6020526040832054156125de57600435835260d360209081526040808520602435865282528085206002810154865260c99092528420600181015460cf546001600160a01b0391821691161561258d57611a9960ff600c84015416612e9e565b6064351561253657608435156124df5760e43584510361247e5783511561242457855b8451811015611c455760038401546001600160a01b0316611add8287612f39565b51604051906331a9108f60e11b82526004820152602081602481855afa908115611c3a578991611bfc575b50336001600160a01b0390911603611b9f5760d4548891906001600160a01b0316611b338489612f39565b51823b156115fe576040516323b872dd60e01b81523360048201526001600160a01b0392909216602483015260448201529082908290606490829084905af1801561160257611b87575b5050600101611abc565b611b9090612d04565b611b9b578638611b7d565b8680fd5b60405162461bcd60e51b815260206004820152602f60248201527f4c6971756964697479426f6e644c6f636b65723a204e6f74206f776e6572206f60448201526e33103130b9b2903837b9b4ba34b7b760891b6064820152608490fd5b90506020813d602011611c32575b81611c1760209383612d34565b81010312611c2e57611c2890612e8a565b38611b08565b8880fd5b3d9150611c0a565b6040513d8b823e3d90fd5b5084869360e435156123b95760d0546001810181116123a55760010160d055600284015460038501546001600160a01b03918216938792909116908185101561238e57611c9a9060843560643560043561331c565b60cc5460405163095ea7b360e01b81526001600160a01b039091166004820152600019602482015260208160448186895af180156123455761236f575b5060cc5460405163095ea7b360e01b81526001600160a01b039091166004820152600019602482015260208160448186865af1801561234557612350575b50611d566020611d2960e435606435612f63565b6040516323b872dd60e01b8152336004820152306024820152604481019190915291829081906064820190565b038186895af1801561234557612326575b50611d7660e435608435612f63565b90803b15611800576040516340c10f1960e01b8152306004820152602481019290925282908290604490829084905af1801561160257612312575b5050611dd3612710916006611dca60e435606435612f63565b91015490612f63565b04908160a435106122bf5760d1546040516323b872dd60e01b81523360048201526001600160a01b03909116602482015260448101929092526020908290606490829088905af180156122b457612295575b50825b60e4358110611e6b575050546040519060e43582527fe208b1beff6c3a6fe20dcae144201f21da6cfd58e48b4d3291784a2bbbaaaf8f60203393a3600160975580f35b600283015460038401546001600160a01b0391821692911680831090811561228e57835b82156122865750905b62ffffff600587015416906006870154908060001461227d57606435905b1561227457608435915b60078901549360088a01549561012c4201421161226057604051988961016081011067ffffffffffffffff6101608c0111176109d1576101608a0160405260018060a01b0316895260018060a01b0316602089015260408801528060020b606088015260181c60020b608087015260a086015260c085015260e08401526101008301523061012083015261012c4201610140830152608061014061016460018060a01b0360cc541694886040519687948593634418b22b60e11b855260018060a01b03815116600486015260018060a01b03602082015116602486015262ffffff6040820151166044860152606081015160020b60648601528781015160020b608486015260a081015160a486015260c081015160c486015260e081015160e486015261010081015161010486015260018060a01b036101208201511661012486015201516101448401525af19182156118fa57859261221e575b5060cc5460d15486916001600160a01b039182169116803b15611800576040516323b872dd60e01b81523060048201526001600160a01b039290921660248301526044820185905282908290606490829084905af180156116025761220a575b5050823b15612206576040516340c10f1960e01b8152336004820152602481018390528590818160448183895af18015611602576121f2575b5050604051630134c3db60e51b8152602081600481875afa9081156121e75786916121b0575b508454600286015460038701546001956121979493600693919290916001600160a01b0390811691161180156121a757606435905b1561219d578a608435925b6040519661212788612d18565b85885260208801908152604088019182526040606089019342855260808a0195865260a08a0196875260c08a01978d8952815260ca6020522097518855518a88015551600287015551600386015551600485015551600584015551151591019060ff801983541691151516179055565b01611e28565b8a6064359261211a565b6084359061210f565b90506020813d6020116121df575b816121cb60209383612d34565b810103126121db575160016120da565b8580fd5b3d91506121be565b6040513d88823e3d90fd5b6121fb90612d04565b6122065784866120b4565b8480fd5b61221390612d04565b61220657848661207b565b9091506080813d608011612258575b8161223a60809383612d34565b8101031261220657612250602082519201612f04565b50908561201b565b3d915061222d565b634e487b7160e01b8c52601160045260248cfd5b60643591611ec0565b60843590611eb6565b905090611e98565b8093611e8f565b6122ad9060203d6020116118f3576118e48183612d34565b5083611e25565b6040513d86823e3d90fd5b60405162461bcd60e51b815260206004820152602560248201527f4c6971756964697479426f6e644c6f636b65723a20496e73756666696369656e604482015264742066656560d81b6064820152608490fd5b61231b90612d04565b612206578486611db1565b61233e9060203d6020116118f3576118e48183612d34565b5087611d67565b6040513d85823e3d90fd5b6123689060203d6020116118f3576118e48183612d34565b5087611d15565b6123879060203d6020116118f3576118e48183612d34565b5087611cd7565b6123a09060643560843560043561331c565b611c9a565b634e487b7160e01b86526011600452602486fd5b60405162461bcd60e51b815260206004820152603b60248201527f4c6971756964697479426f6e644c6f636b65723a204e756d626572206f66206260448201527f6f6e6473206d7573742062652067726561746572207468616e203000000000006064820152608490fd5b60405162461bcd60e51b815260206004820152602c60248201527f4c6971756964697479426f6e644c6f636b65723a204261736520746f6b656e2060448201526b12511cc81c995c5d5a5c995960a21b6064820152608490fd5b60405162461bcd60e51b815260206004820152603360248201527f4c6971756964697479426f6e644c6f636b65723a204261736520746f6b656e2060448201527209288e640d8cadccee8d040dad2e6dac2e8c6d606b1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602960248201527f4c6971756964697479426f6e644c6f636b65723a205f616d6f756e743120636160448201526806e6e6f7420626520360bc1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602960248201527f4c6971756964697479426f6e644c6f636b65723a205f616d6f756e743020636160448201526806e6e6f7420626520360bc1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a205369676e6572206e6f74206044820152621cd95d60ea1b6064820152608490fd5b60405162461bcd60e51b815260206004820152603160248201527f4c6971756964697479426f6e644c6f636b65723a204261736520706f736974696044820152701bdb88191bd95cc81b9bdd08195e1a5cdd607a1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e644c6f636b65723a20426f6e6420646f6573206e6044820152671bdd08195e1a5cdd60c21b6064820152608490fd5b8135815260209182019101611973565b634e487b7160e01b83526041600452602483fd5b5034610223576126c636612cee565b6126d560026097541415612dff565b60026097556126e960ff6065541615612e4b565b80835260209160c983526040842060018060a01b038060018301541690604051906331a9108f60e11b825284600483015260249187818481875afa908115611c3a578991612cb9575b508133911603612c7557600c84015461274d60ff8216612e9e565b60405163067257d960e31b8152600481018790529660c0888581885afa978815612c6a578a98612c32575b50878a5260ca895260408a2090600282015403612be05786600182015403612b8b576006015460ff1615612b4757600a8501544210612af55788908260cc541690604051809263133f757160e31b82528a600483015281876101809384935afa9081156122b4578b9385918693612a3c575b50506127f58b613207565b92836128fc575b50505050505060cc5416803b156128f8576040516323b872dd60e01b8152306004820152336024820152604481018790529088908290606490829084905af180156128ed576128d8575b5084875260ca865260408720600601805460ff19169055869190813b15611800578291829160405180948193630852cd8d60e31b83528960048401525af18015611602576128c4575b50507fdc0fef3b12f4e0e8b930e6005b605ed39d90dd8d0ae5c88328b0c912029ba65f905493604051338152a4600160975580f35b6128cd90612d04565b61220657843861288f565b6128e59097919297612d04565b959038612846565b6040513d8a823e3d90fd5b8780fd5b60a81c60ff16156129e157858060cd5416911690811461298f575b50848060cd54169116908114612938575b505050505b8787388080806127fc565b60405163a9059cbb60e01b815233600482015260248101929092529092839160449183915af18015611c3a57612972575b87818a92612928565b61298890883d8a116118f3576118e48183612d34565b5038612969565b60405163a9059cbb60e01b81523360048201526024810184905293908490604490829088905af19283156122b4578b9315612917576129da90843d86116118f3576118e48183612d34565b5038612917565b505060cd5460405163a9059cbb60e01b8152336004820152602481019290925290928391604491839187165af18015611c3a57612a1f575b5061292d565b612a3590883d8a116118f3576118e48183612d34565b5038612a19565b925093505082813d8311612aee575b612a558183612d34565b810103126118005781516001600160601b0381160361180057612a798a8301612e8a565b50612a8660408301612e8a565b612a9260608401612e8a565b90608084015162ffffff81160361220657612ae661016085612ab78f9760a001612ef6565b50612ac460c08201612ef6565b50612ad160e08201612f04565b50612adf6101408201612f04565b5001612f04565b5038806127ea565b503d612a4b565b60405162461bcd60e51b8152600481018990526025818501527f4c6971756964697479426f6e644c6f636b65723a204c6f636b206e6f742065786044820152641c1a5c995960da1b6064820152608490fd5b60405162461bcd60e51b815260048101899052601f818501527f4c6971756964697479426f6e644c6f636b65723a204e6f74206c6f636b6564006044820152606490fd5b60405162461bcd60e51b8152600481018a90526028818601527f4c6971756964697479426f6e644c6f636b65723a204c5020426f6e64204944206044820152670dad2e6dac2e8c6d60c31b6064820152608490fd5b60405162461bcd60e51b8152600481018a90526025818601527f4c6971756964697479426f6e644c6f636b65723a20426f6e64204944206d69736044820152640dac2e8c6d60db1b6064820152608490fd5b90975060c0813d60c011612c62575b81612c4e60c09383612d34565b81010312612c5e57519638612778565b8980fd5b3d9150612c41565b6040513d8c823e3d90fd5b60405162461bcd60e51b815260048101889052601e818401527f4c6971756964697479426f6e644c6f636b65723a204e6f74206f776e657200006044820152606490fd5b90508781813d8311612ce7575b612cd08183612d34565b81010312611c2e57612ce190612e8a565b38612732565b503d612cc6565b6040906003190112610ce0576004359060243590565b67ffffffffffffffff81116109d157604052565b60e0810190811067ffffffffffffffff8211176109d157604052565b90601f8019910116810190811067ffffffffffffffff8211176109d157604052565b67ffffffffffffffff81116109d157601f01601f191660200190565b600435906001600160a01b0382168203610ce057565b602435906001600160a01b0382168203610ce057565b606435906001600160a01b0382168203610ce057565b604435906001600160a01b0382168203610ce057565b6060906003190112610ce0576001600160a01b03906004358281168103610ce057916024359081168103610ce0579060443590565b15612e0657565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b15612e5257565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b51906001600160a01b0382168203610ce057565b15612ea557565b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e644c6f636b65723a20426f6e64206e6f742061636044820152637469766560e01b6064820152608490fd5b51908160020b8203610ce057565b51906fffffffffffffffffffffffffffffffff82168203610ce057565b90816020910312610ce057518015158103610ce05790565b8051821015612f4d5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b81810292918115918404141715612f7657565b634e487b7160e01b600052601160045260246000fd5b8115612f96570490565b634e487b7160e01b600052601260045260246000fd5b15612fb357565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b15612ffe57565b60405162461bcd60e51b815260206004820152602a60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420746f6b604482015269656e206164647265737360b01b6064820152608490fd5b1561305d57565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964207265636044820152651a5c1a595b9d60d21b6064820152608490fd5b156130b857565b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420616d6f6044820152621d5b9d60ea1b6064820152608490fd5b1561311057565b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964206164646044820152637265737360e01b6064820152608490fd5b1561316857565b60405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b156131ab57565b60405162461bcd60e51b815260206004820152602160248201527f4c6971756964697479426f6e644c6f636b65723a2053616d65206164647265736044820152607360f81b6064820152608490fd5b91908203918211612f7657565b90600091600090815260ca602052604081209060028201549081815260c96020526040812092600a84015460038201549060ff600c613283600461324b86866131fa565b9601549761326787613262600b8d0154809c612f63565b612f63565b90885260d260205261327d6040892054866131fa565b90612f8c565b97015460a81c16613297575b505050505050565b90919293949596504210156000146132c7575050506132b99061271092612f63565b04905b38808080808061328f565b6132e1929491936132db61326292426131fa565b92612f63565b612710928383029280840485149015171561330857509061330191612f8c565b04906132bc565b634e487b7160e01b81526011600452602490fd5b916133af93916133a69360005260cb6020526040600020549160d054906040519260208401948552604084015260608301523060601b608083015260948201523360601b60b482015260a8815261337281612d18565b5190207f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c6000206134c3565b909291926134ff565b60cf546001600160a01b039081169116036133c657565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964207369676044820152656e617475726560d01b6064820152608490fd5b603380546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b1561346a57565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b81519190604183036134f4576134ed92506020820151906060604084015193015160001a90613584565b9192909190565b505060009160029190565b600481101561356e5780613511575050565b6001810361352b5760405163f645eedf60e01b8152600490fd5b6002810361354c5760405163fce698f760e01b815260048101839052602490fd5b6003146135565750565b602490604051906335e2f38360e21b82526004820152fd5b634e487b7160e01b600052602160045260246000fd5b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841161360857926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa156135fc5780516001600160a01b038116156135f357918190565b50809160019190565b604051903d90823e3d90fd5b5050506000916003919056fea2646970667358221220017e08b5bcc7fb383916d0ac6d2c1d6c12dae723a525e1693a1364f51a6eb59d64736f6c63430008160033

Deployed Bytecode

0x6080604052600436101561001b575b361561001957600080fd5b005b6000803560e01c8063021c025d146126b75780630e11ffae146119055780631171bda914611804578063150b7a02146117955780631aac4c5e146116ae5780631ffc67fb14611685578063238ac9331461165c578063284d30ef146116115780632cdf2c351461152b5780633395acc7146114d057806336e0004a146114a757806339a2d2fe1461130f5780633e0c0629146111a75780633ec4c9681461117d5780633f4ba83a1461110b57806356a701311461108c5780635c975abb146110695780635f1c17c014610f6a5780636c19e78314610edf578063715018a614610e7e578063810d675a14610e575780638456cb5914610de15780638da5cb5b14610db857806390d082e914610d8e5780639de3567c14610d03578063affed0e014610ce5578063b44eeea71461064c578063ba278e0814610618578063c0c53b8b146103f9578063ca1de4fe146103ae578063db358f2f14610385578063e5047b301461035c578063e8ea79c01461033e578063edf8bc05146102c0578063f2fde38b146102265763f4dadc61146101b3575061000e565b3461022357602036600319011261022357604060e091600435815260ca602052208054906001810154906002810154600382015460048301549160ff600660058601549501541694604051968752602087015260408601526060850152608084015260a0830152151560c0820152f35b80fd5b503461022357602036600319011261022357610240612d72565b6033546001600160a01b03906102599082163314612fac565b81161561026c576102699061341a565b80f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b503461022357604060e0916102d436612cee565b90825260d360205282822090825260205220805490600181015490600281015460018060a01b039081600384015416906006836004860154169360058601541694015494604051968752602087015260408601526060850152608084015260a083015260c0820152f35b5034610223578060031936011261022357602060ce54604051908152f35b503461022357806003193601126102235760cc546040516001600160a01b039091168152602090f35b503461022357806003193601126102235760cd546040516001600160a01b039091168152602090f35b5034610223576020366003190112610223576103c8612d72565b6033546001600160a01b0391906103e29083163314612fac565b166001600160601b0360a01b60d454161760d45580f35b503461022357606036600319011261022357610413612d72565b61041b612d88565b610423612db4565b9183549260ff8460081c168060001461060e57303b155b156105b2571593846105a1575b506001600160a01b0391821692831561054657821680156104f5576001600160601b0360a01b938460cc54161760cc558360cf54161760cf55169060cd54161760cd556104a360ff835460081c1661049e81613463565b613463565b6104ac3361341a565b8154906104de60ff8360081c166104c281613463565b6104cb81613463565b60ff196065541660655561049e81613463565b60016097556104eb575080f35b61ff001916815580f35b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964207369676044820152623732b960e91b6064820152608490fd5b60405162461bcd60e51b815260206004820152602d60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420706f7360448201526c34ba34b7b71036b0b730b3b2b960991b6064820152608490fd5b61ffff191661010117855538610447565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b60ff85161561043a565b50346102235761062736612cee565b9061063d60018060a01b03603354163314612fac565b825260d2602052604082205580f35b50346102235761020036600319011261022357610667612d88565b61066f612db4565b610677612d9e565b60c435918260020b8303610ce05760e435928360020b8403610ce0576101a435938415158503610ce0576101c4356001600160a01b0381168103610ce0576101e435918215158303610ce0576106d860018060a01b03603354163314612fac565b60043515610c87576101643515610c2f576101843515610bda5760843515610b80576001600160a01b03881615610b2b576001600160a01b03851615610ada576001600160a01b03861615610a89576001600160a01b0385811690871614610a36576001600160a01b038216156109e757604051938461020081011067ffffffffffffffff610200870111176109d1576102008501604052600435855260018060a01b038916602086015260018060a01b038616604086015260018060a01b0387166060860152608435608086015260a43560a086015260020b60c085015260020b60e084015261010435610100840152610124356101208401526101443561014084015261016435610160840152610184356101808401528515156101a084015260018060a01b03166101c083015215156101e0820152600435865260c9602052600c60408720825181556001810160018060a01b03602085015116906001600160601b0360a01b91828254161790556002820160018060a01b0360408601511682825416179055600382019060018060a01b03606086015116908254161790556080830151600482015560a083015160058201556006810160c0840151815462ffffff60e087015160181b65ffffff0000001692169065ffffffffffff191617179055610100830151600782015561012083015160088201556101408301516009820155610160830151600a820155610180830151600b82015501906109136101a08201511515839060ff801983541691151516179055565b6101c081015182546101e090920151610100600160b01b031990921660089190911b610100600160a81b03161790151560a81b60ff60a81b16179055604080516001600160a01b03958616815291851660208301529190931690830152608435606083015260a43560808301526101443560a08301526101643560c08301526101843560e08301521515610100820152600435907f1ec2cb67b4962fb16bf5646dd75edc5850e0424571d73e6091e80788a3f4ad5f9061012090a280f35b634e487b7160e01b600052604160045260246000fd5b60405162461bcd60e51b815260206004820152602160248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420706f6f6044820152601b60fa1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602560248201527f4c6971756964697479426f6e644c6f636b65723a204964656e746963616c20746044820152646f6b656e7360d81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420746f6b604482015262656e3160e81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420746f6b6044820152620656e360ec1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420636f6c6044820152663632b1ba34b7b760c91b6064820152608490fd5b60405162461bcd60e51b815260206004820152602c60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c69642072657160448201526b1d5a5c995908185b5bdd5b9d60a21b6064820152608490fd5b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964206d756c6044820152663a34b83634b2b960c91b6064820152608490fd5b60405162461bcd60e51b815260206004820152602a60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964206c6f636044820152693590323ab930ba34b7b760b11b6064820152608490fd5b60405162461bcd60e51b815260206004820152602b60248201527f4c6971756964697479426f6e644c6f636b65723a20426f6e642049442063616e60448201526a6e6f74206265207a65726f60a81b6064820152608490fd5b600080fd5b5034610223578060031936011261022357602060d054604051908152f35b503461022357602036600319011261022357610d1d612d72565b6033546001600160a01b03918291610d389083163314612fac565b1690610d45821515613109565b8160cc5491821691610d59828414156131a4565b6001600160a01b0319161760cc557fdc191f971b2df5e9dfb661b1bd934266d7873a21719372ac9a6415b7f5c679668380a380f35b5034610223576020366003190112610223576040602091600435815260cb83522054604051908152f35b50346102235780600319360112610223576033546040516001600160a01b039091168152602090f35b5034610223578060031936011261022357610e0760018060a01b03603354163314612fac565b6001606554610e2260ff821615610e1d81612e4b565b612e4b565b60ff1916176065557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a180f35b5034610223576020366003190112610223576020610e76600435613207565b604051908152f35b50346102235780600319360112610223576033546000906001600160a01b03811690610eab338314612fac565b6001600160a01b0319166033557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b503461022357602036600319011261022357610ef9612d72565b6033546001600160a01b03918291610f149083163314612fac565b1690610f21821515613109565b8160cf5491821691610f35828414156131a4565b6001600160a01b0319161760cf557fb0604c365feafa080c833b6f6814d321a7561528e696ac2a112c2a0231b0ed358380a380f35b503461022357602036600319011261022357604061020091600435815260c96020522060ff81549160018060a01b036001820154169060018060a01b0360028201541660018060a01b03600383015416600483015460058401546006850154600786015491600887015493600988015495600a89015497600c600b8b01549a01549a60206040519e8f908152015260408d015260608c015260808b015260a08a01528060020b60c08a015260181c60020b60e089015261010088015261012087015261014086015261016085015261018084015281811615156101a084015260018060a01b038160081c166101c084015260a81c1615156101e0820152f35b5034610223578060031936011261022357602060ff606554166040519015158152f35b5034610223576020366003190112610223576110a6612d72565b6033546001600160a01b039182916110c19083163314612fac565b16906110ce821515613109565b60cd54826001600160601b0360a01b82161760cd55167f3a753e7c76490009eaecdc23ebd537d53b956ed9b6ada05cabd6a2e36b4e43d38380a380f35b503461022357806003193601126102235761113160018060a01b03603354163314612fac565b60655461114960ff821661114481613161565b613161565b60ff19166065557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a180f35b5034610223576020366003190112610223576040602091600435815260d283522054604051908152f35b5034610223576040366003190112610223576111c1612d72565b60243560018060a01b036111da81603354163314612fac565b8216916111e8831515613109565b6111f38215156130b1565b8147106112b8578380808481945af13d156112b3573d61121281612d56565b906112206040519283612d34565b81528460203d92013e5b1561125d5760207fd01205615e35ba1dd087bd6dac5922e0370961b3726c247c078cd59baae5770e91604051908152a280f35b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e644c6f636b65723a20455448207472616e7366656044820152671c8819985a5b195960c21b6064820152608490fd5b61122a565b60405162461bcd60e51b815260206004820152602960248201527f4c6971756964697479426f6e644c6f636b65723a20496e73756666696369656e604482015268742062616c616e636560b81b6064820152608490fd5b50346102235760e036600319011261022357611329612d9e565b6084356001600160a01b0381168103610ce05760a435906001600160a01b0382168203610ce05761136560018060a01b03603354163314612fac565b60405161137181612d18565b60043581526024356020820152604435604082015260018060a01b03841660608201526006608082019160018060a01b038416835260a0810160018060a01b038616815260c082019160c4358352602435895260d3602052604089206004358a5260205260408920948151865560208201516001870155604082015160028701556003860191606060018060a01b0391015116916001600160601b0360a01b9283825416179055600486019060018060a01b0390511682825416179055600585019160018060a01b0390511690825416179055519101556040519260018060a01b0316835260018060a01b0316602083015260018060a01b0316604082015260c4356060820152604435907f7a31dd6f7d05deffb176e095cb8d04693c64ab6a61343b972c49f525ab83e403608060043592a380f35b503461022357806003193601126102235760d1546040516001600160a01b039091168152602090f35b5034610223576020366003190112610223577f460a822779d1e75985c2b12b355b8c73d1622f575a10f55fb7aae5bd66f00e23602060043561151d60018060a01b03603354163314612fac565b8060ce55604051908152a180f35b50346102235761153a36612dca565b60335491926001600160a01b0392859184916115599083163314612fac565b1692611566841515612ff7565b841693611574851515613056565b833b1561160d576040516323b872dd60e01b81523060048201526001600160a01b0391909116602482015260448101839052818160648183885af18015611602576115ea575b505060207fbac52ce088f0b87a6de233d6dfedfcb5587da9f954ed3a555c468169bd46ed7f91604051908152a380f35b6115f390612d04565b6115fe5783386115ba565b8380fd5b6040513d84823e3d90fd5b5080fd5b50346102235760203660031901126102235761162b612d72565b6033546001600160a01b0391906116459083163314612fac565b166001600160601b0360a01b60d154161760d15580f35b503461022357806003193601126102235760cf546040516001600160a01b039091168152602090f35b503461022357806003193601126102235760d4546040516001600160a01b039091168152602090f35b5034610223576116bd36612cee565b906116d360018060a01b03603354163314612fac565b80156117445781156116ee57825260cb602052604082205580f35b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420706f736044820152671a5d1a5bdb88125160c21b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420626f6e6044820152631908125160e21b6064820152608490fd5b5034610223576080366003190112610223576117af612d72565b506117b8612d88565b5060643567ffffffffffffffff8082116118005736602383011215611800578160040135908111611800573691016024011161022357604051630a85bd0160e11b8152602090f35b8280fd5b50346102235761188b61181636612dca565b60208160018060a09795971b03809561183482603354163314612fac565b1694611841861515612ff7565b86169561184f871515613056565b61185a8215156130b1565b60405163a9059cbb60e01b81526001600160a01b039091166004820152602481019190915292839081906044820190565b038188875af19081156118fa577fedce930554908e152dd7472edd740ccb66cdafafc759fd83714a85b7c043ff91926020926118cd575b50604051908152a380f35b6118ec90833d85116118f3575b6118e48183612d34565b810190612f21565b50386118c2565b503d6118da565b6040513d87823e3d90fd5b506101003660031901126102235760443567ffffffffffffffff811161160d573660238201121561160d5780600401359067ffffffffffffffff82116126a3578160051b6040519261195a6020830185612d34565b8352602460208401918301019136831161220657602401905b8282106126935750505067ffffffffffffffff60c4351161160d5736602360c43501121561160d576119aa60c43560040135612d56565b906119b86040519283612d34565b600460c43590810135808452369101602401116118005760c43560040135602460c43501602084013782602060c43560040135840101526119fe60026097541415612dff565b6002609755611a1260ff6065541615612e4b565b600435835260c960205260408320600101546001600160a01b03161561263d57600435835260cb6020526040832054156125de57600435835260d360209081526040808520602435865282528085206002810154865260c99092528420600181015460cf546001600160a01b0391821691161561258d57611a9960ff600c84015416612e9e565b6064351561253657608435156124df5760e43584510361247e5783511561242457855b8451811015611c455760038401546001600160a01b0316611add8287612f39565b51604051906331a9108f60e11b82526004820152602081602481855afa908115611c3a578991611bfc575b50336001600160a01b0390911603611b9f5760d4548891906001600160a01b0316611b338489612f39565b51823b156115fe576040516323b872dd60e01b81523360048201526001600160a01b0392909216602483015260448201529082908290606490829084905af1801561160257611b87575b5050600101611abc565b611b9090612d04565b611b9b578638611b7d565b8680fd5b60405162461bcd60e51b815260206004820152602f60248201527f4c6971756964697479426f6e644c6f636b65723a204e6f74206f776e6572206f60448201526e33103130b9b2903837b9b4ba34b7b760891b6064820152608490fd5b90506020813d602011611c32575b81611c1760209383612d34565b81010312611c2e57611c2890612e8a565b38611b08565b8880fd5b3d9150611c0a565b6040513d8b823e3d90fd5b5084869360e435156123b95760d0546001810181116123a55760010160d055600284015460038501546001600160a01b03918216938792909116908185101561238e57611c9a9060843560643560043561331c565b60cc5460405163095ea7b360e01b81526001600160a01b039091166004820152600019602482015260208160448186895af180156123455761236f575b5060cc5460405163095ea7b360e01b81526001600160a01b039091166004820152600019602482015260208160448186865af1801561234557612350575b50611d566020611d2960e435606435612f63565b6040516323b872dd60e01b8152336004820152306024820152604481019190915291829081906064820190565b038186895af1801561234557612326575b50611d7660e435608435612f63565b90803b15611800576040516340c10f1960e01b8152306004820152602481019290925282908290604490829084905af1801561160257612312575b5050611dd3612710916006611dca60e435606435612f63565b91015490612f63565b04908160a435106122bf5760d1546040516323b872dd60e01b81523360048201526001600160a01b03909116602482015260448101929092526020908290606490829088905af180156122b457612295575b50825b60e4358110611e6b575050546040519060e43582527fe208b1beff6c3a6fe20dcae144201f21da6cfd58e48b4d3291784a2bbbaaaf8f60203393a3600160975580f35b600283015460038401546001600160a01b0391821692911680831090811561228e57835b82156122865750905b62ffffff600587015416906006870154908060001461227d57606435905b1561227457608435915b60078901549360088a01549561012c4201421161226057604051988961016081011067ffffffffffffffff6101608c0111176109d1576101608a0160405260018060a01b0316895260018060a01b0316602089015260408801528060020b606088015260181c60020b608087015260a086015260c085015260e08401526101008301523061012083015261012c4201610140830152608061014061016460018060a01b0360cc541694886040519687948593634418b22b60e11b855260018060a01b03815116600486015260018060a01b03602082015116602486015262ffffff6040820151166044860152606081015160020b60648601528781015160020b608486015260a081015160a486015260c081015160c486015260e081015160e486015261010081015161010486015260018060a01b036101208201511661012486015201516101448401525af19182156118fa57859261221e575b5060cc5460d15486916001600160a01b039182169116803b15611800576040516323b872dd60e01b81523060048201526001600160a01b039290921660248301526044820185905282908290606490829084905af180156116025761220a575b5050823b15612206576040516340c10f1960e01b8152336004820152602481018390528590818160448183895af18015611602576121f2575b5050604051630134c3db60e51b8152602081600481875afa9081156121e75786916121b0575b508454600286015460038701546001956121979493600693919290916001600160a01b0390811691161180156121a757606435905b1561219d578a608435925b6040519661212788612d18565b85885260208801908152604088019182526040606089019342855260808a0195865260a08a0196875260c08a01978d8952815260ca6020522097518855518a88015551600287015551600386015551600485015551600584015551151591019060ff801983541691151516179055565b01611e28565b8a6064359261211a565b6084359061210f565b90506020813d6020116121df575b816121cb60209383612d34565b810103126121db575160016120da565b8580fd5b3d91506121be565b6040513d88823e3d90fd5b6121fb90612d04565b6122065784866120b4565b8480fd5b61221390612d04565b61220657848661207b565b9091506080813d608011612258575b8161223a60809383612d34565b8101031261220657612250602082519201612f04565b50908561201b565b3d915061222d565b634e487b7160e01b8c52601160045260248cfd5b60643591611ec0565b60843590611eb6565b905090611e98565b8093611e8f565b6122ad9060203d6020116118f3576118e48183612d34565b5083611e25565b6040513d86823e3d90fd5b60405162461bcd60e51b815260206004820152602560248201527f4c6971756964697479426f6e644c6f636b65723a20496e73756666696369656e604482015264742066656560d81b6064820152608490fd5b61231b90612d04565b612206578486611db1565b61233e9060203d6020116118f3576118e48183612d34565b5087611d67565b6040513d85823e3d90fd5b6123689060203d6020116118f3576118e48183612d34565b5087611d15565b6123879060203d6020116118f3576118e48183612d34565b5087611cd7565b6123a09060643560843560043561331c565b611c9a565b634e487b7160e01b86526011600452602486fd5b60405162461bcd60e51b815260206004820152603b60248201527f4c6971756964697479426f6e644c6f636b65723a204e756d626572206f66206260448201527f6f6e6473206d7573742062652067726561746572207468616e203000000000006064820152608490fd5b60405162461bcd60e51b815260206004820152602c60248201527f4c6971756964697479426f6e644c6f636b65723a204261736520746f6b656e2060448201526b12511cc81c995c5d5a5c995960a21b6064820152608490fd5b60405162461bcd60e51b815260206004820152603360248201527f4c6971756964697479426f6e644c6f636b65723a204261736520746f6b656e2060448201527209288e640d8cadccee8d040dad2e6dac2e8c6d606b1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602960248201527f4c6971756964697479426f6e644c6f636b65723a205f616d6f756e743120636160448201526806e6e6f7420626520360bc1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602960248201527f4c6971756964697479426f6e644c6f636b65723a205f616d6f756e743020636160448201526806e6e6f7420626520360bc1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a205369676e6572206e6f74206044820152621cd95d60ea1b6064820152608490fd5b60405162461bcd60e51b815260206004820152603160248201527f4c6971756964697479426f6e644c6f636b65723a204261736520706f736974696044820152701bdb88191bd95cc81b9bdd08195e1a5cdd607a1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e644c6f636b65723a20426f6e6420646f6573206e6044820152671bdd08195e1a5cdd60c21b6064820152608490fd5b8135815260209182019101611973565b634e487b7160e01b83526041600452602483fd5b5034610223576126c636612cee565b6126d560026097541415612dff565b60026097556126e960ff6065541615612e4b565b80835260209160c983526040842060018060a01b038060018301541690604051906331a9108f60e11b825284600483015260249187818481875afa908115611c3a578991612cb9575b508133911603612c7557600c84015461274d60ff8216612e9e565b60405163067257d960e31b8152600481018790529660c0888581885afa978815612c6a578a98612c32575b50878a5260ca895260408a2090600282015403612be05786600182015403612b8b576006015460ff1615612b4757600a8501544210612af55788908260cc541690604051809263133f757160e31b82528a600483015281876101809384935afa9081156122b4578b9385918693612a3c575b50506127f58b613207565b92836128fc575b50505050505060cc5416803b156128f8576040516323b872dd60e01b8152306004820152336024820152604481018790529088908290606490829084905af180156128ed576128d8575b5084875260ca865260408720600601805460ff19169055869190813b15611800578291829160405180948193630852cd8d60e31b83528960048401525af18015611602576128c4575b50507fdc0fef3b12f4e0e8b930e6005b605ed39d90dd8d0ae5c88328b0c912029ba65f905493604051338152a4600160975580f35b6128cd90612d04565b61220657843861288f565b6128e59097919297612d04565b959038612846565b6040513d8a823e3d90fd5b8780fd5b60a81c60ff16156129e157858060cd5416911690811461298f575b50848060cd54169116908114612938575b505050505b8787388080806127fc565b60405163a9059cbb60e01b815233600482015260248101929092529092839160449183915af18015611c3a57612972575b87818a92612928565b61298890883d8a116118f3576118e48183612d34565b5038612969565b60405163a9059cbb60e01b81523360048201526024810184905293908490604490829088905af19283156122b4578b9315612917576129da90843d86116118f3576118e48183612d34565b5038612917565b505060cd5460405163a9059cbb60e01b8152336004820152602481019290925290928391604491839187165af18015611c3a57612a1f575b5061292d565b612a3590883d8a116118f3576118e48183612d34565b5038612a19565b925093505082813d8311612aee575b612a558183612d34565b810103126118005781516001600160601b0381160361180057612a798a8301612e8a565b50612a8660408301612e8a565b612a9260608401612e8a565b90608084015162ffffff81160361220657612ae661016085612ab78f9760a001612ef6565b50612ac460c08201612ef6565b50612ad160e08201612f04565b50612adf6101408201612f04565b5001612f04565b5038806127ea565b503d612a4b565b60405162461bcd60e51b8152600481018990526025818501527f4c6971756964697479426f6e644c6f636b65723a204c6f636b206e6f742065786044820152641c1a5c995960da1b6064820152608490fd5b60405162461bcd60e51b815260048101899052601f818501527f4c6971756964697479426f6e644c6f636b65723a204e6f74206c6f636b6564006044820152606490fd5b60405162461bcd60e51b8152600481018a90526028818601527f4c6971756964697479426f6e644c6f636b65723a204c5020426f6e64204944206044820152670dad2e6dac2e8c6d60c31b6064820152608490fd5b60405162461bcd60e51b8152600481018a90526025818601527f4c6971756964697479426f6e644c6f636b65723a20426f6e64204944206d69736044820152640dac2e8c6d60db1b6064820152608490fd5b90975060c0813d60c011612c62575b81612c4e60c09383612d34565b81010312612c5e57519638612778565b8980fd5b3d9150612c41565b6040513d8c823e3d90fd5b60405162461bcd60e51b815260048101889052601e818401527f4c6971756964697479426f6e644c6f636b65723a204e6f74206f776e657200006044820152606490fd5b90508781813d8311612ce7575b612cd08183612d34565b81010312611c2e57612ce190612e8a565b38612732565b503d612cc6565b6040906003190112610ce0576004359060243590565b67ffffffffffffffff81116109d157604052565b60e0810190811067ffffffffffffffff8211176109d157604052565b90601f8019910116810190811067ffffffffffffffff8211176109d157604052565b67ffffffffffffffff81116109d157601f01601f191660200190565b600435906001600160a01b0382168203610ce057565b602435906001600160a01b0382168203610ce057565b606435906001600160a01b0382168203610ce057565b604435906001600160a01b0382168203610ce057565b6060906003190112610ce0576001600160a01b03906004358281168103610ce057916024359081168103610ce0579060443590565b15612e0657565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b15612e5257565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b51906001600160a01b0382168203610ce057565b15612ea557565b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e644c6f636b65723a20426f6e64206e6f742061636044820152637469766560e01b6064820152608490fd5b51908160020b8203610ce057565b51906fffffffffffffffffffffffffffffffff82168203610ce057565b90816020910312610ce057518015158103610ce05790565b8051821015612f4d5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b81810292918115918404141715612f7657565b634e487b7160e01b600052601160045260246000fd5b8115612f96570490565b634e487b7160e01b600052601260045260246000fd5b15612fb357565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b15612ffe57565b60405162461bcd60e51b815260206004820152602a60248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420746f6b604482015269656e206164647265737360b01b6064820152608490fd5b1561305d57565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964207265636044820152651a5c1a595b9d60d21b6064820152608490fd5b156130b857565b60405162461bcd60e51b815260206004820152602360248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c696420616d6f6044820152621d5b9d60ea1b6064820152608490fd5b1561311057565b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964206164646044820152637265737360e01b6064820152608490fd5b1561316857565b60405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b156131ab57565b60405162461bcd60e51b815260206004820152602160248201527f4c6971756964697479426f6e644c6f636b65723a2053616d65206164647265736044820152607360f81b6064820152608490fd5b91908203918211612f7657565b90600091600090815260ca602052604081209060028201549081815260c96020526040812092600a84015460038201549060ff600c613283600461324b86866131fa565b9601549761326787613262600b8d0154809c612f63565b612f63565b90885260d260205261327d6040892054866131fa565b90612f8c565b97015460a81c16613297575b505050505050565b90919293949596504210156000146132c7575050506132b99061271092612f63565b04905b38808080808061328f565b6132e1929491936132db61326292426131fa565b92612f63565b612710928383029280840485149015171561330857509061330191612f8c565b04906132bc565b634e487b7160e01b81526011600452602490fd5b916133af93916133a69360005260cb6020526040600020549160d054906040519260208401948552604084015260608301523060601b608083015260948201523360601b60b482015260a8815261337281612d18565b5190207f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c6000206134c3565b909291926134ff565b60cf546001600160a01b039081169116036133c657565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e644c6f636b65723a20496e76616c6964207369676044820152656e617475726560d01b6064820152608490fd5b603380546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b1561346a57565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b81519190604183036134f4576134ed92506020820151906060604084015193015160001a90613584565b9192909190565b505060009160029190565b600481101561356e5780613511575050565b6001810361352b5760405163f645eedf60e01b8152600490fd5b6002810361354c5760405163fce698f760e01b815260048101839052602490fd5b6003146135565750565b602490604051906335e2f38360e21b82526004820152fd5b634e487b7160e01b600052602160045260246000fd5b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841161360857926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa156135fc5780516001600160a01b038116156135f357918190565b50809160019190565b604051903d90823e3d90fd5b5050506000916003919056fea2646970667358221220017e08b5bcc7fb383916d0ac6d2c1d6c12dae723a525e1693a1364f51a6eb59d64736f6c63430008160033

Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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.