Mumbai Testnet

Contract

0x30654f4145A67345CF1B701eac259aA7a2e06FE7

Overview

MATIC Balance

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
Value
0x60806040256462852022-03-24 10:51:28797 days ago1648119088IN
 Create: OpiumProxyFactory
0 MATIC0.004775131.50000018

Parent Transaction Hash Block From To Value
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
OpiumProxyFactory

Compiler Version
v0.8.5+commit.a4f2e591

Optimization Enabled:
Yes with 800 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 23 : OpiumProxyFactory.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;

import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
import "./OpiumPositionToken.sol";
import "./base/RegistryManager.sol";
import "../libs/LibDerivative.sol";
import "../libs/LibPosition.sol";
import "../libs/LibBokkyPooBahsDateTimeLibrary.sol";
import "../interfaces/IOpiumPositionToken.sol";
import "../interfaces/IRegistry.sol";

/**
    Error codes:
    - F1 = ERROR_OPIUM_PROXY_FACTORY_NOT_CORE
    - F2 = ERROR_OPIUM_PROXY_CUSTOM_POSITION_TOKEN_NAME_TOO_LONG
 */

/// @title Opium.OpiumProxyFactory contract manages the deployment of ERC20 LONG/SHORT positions for a given `LibDerivative.Derivative` structure and it's responsible for minting and burning positions according to the parameters supplied by `Opium.Core`
contract OpiumProxyFactory is RegistryManager {
    using LibDerivative for LibDerivative.Derivative;
    using LibPosition for bytes32;

    event LogPositionTokenPair(
        bytes32 indexed _derivativeHash,
        address indexed _longPositionAddress,
        address indexed _shortPositionAddress
    );

    address private opiumPositionTokenImplementation;

    /// @notice It is applied to functions that must be called only by the `Opium.Core` contract
    modifier onlyCore() {
        require(msg.sender == registry.getCore(), "F1");
        _;
    }

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

    // ***** GETTERS *****

    /// @notice It retrieves the information about the underlying derivative
    /// @return _opiumPositionTokenParams OpiumPositionTokenParams struct which contains `LibDerivative.Derivative` schema of the derivative, the ` LibDerivative.PositionType` of the present ERC20 token and the bytes32 hash `derivativeHash` of the `LibDerivative.Derivative` derivative
    function getImplementationAddress() external view returns (address) {
        return opiumPositionTokenImplementation;
    }

    // ***** SETTERS *****

    /// @notice It is called only once upon deployment of the contract
    /// @dev It sets the the address of the implementation of the OpiumPositionToken contract which will be used for the factory-deployment of erc20 positions via the minimal proxy contract
    /// @param _registry address of Opium.Registry
    function initialize(address _registry) external initializer {
        __RegistryManager__init(_registry);
        opiumPositionTokenImplementation = address(new OpiumPositionToken());
    }

    /// @notice It creates a specified amount of LONG/SHORT position tokens on behalf of the buyer(LONG) and seller(SHORT) - the specified amount can be 0 in which case the ERC20 contract of the position tokens will only be deployed
    /// @dev if either of the LONG or SHORT position contracts already exists then it is expected to fail
    /// @param _buyer address of the recipient of the LONG position tokens
    /// @param _seller address of the recipient of the SHORT position tokens
    /// @param _amount amount of position tokens to be minted to the _positionHolder
    /// @param _derivativeHash bytes32 hash of `LibDerivative.Derivative`
    /// @param _derivative LibDerivative.Derivative Derivative definition
    function create(
        address _buyer,
        address _seller,
        uint256 _amount,
        bytes32 _derivativeHash,
        LibDerivative.Derivative calldata _derivative
    ) external onlyCore {
        address longPositionAddress = _derivativeHash.deployOpiumPosition(true, opiumPositionTokenImplementation);
        address shortPositionAddress = _derivativeHash.deployOpiumPosition(false, opiumPositionTokenImplementation);

        IOpiumPositionToken(longPositionAddress).initialize(
            _derivativeHash,
            LibDerivative.PositionType.LONG,
            _derivative
        );
        IOpiumPositionToken(shortPositionAddress).initialize(
            _derivativeHash,
            LibDerivative.PositionType.SHORT,
            _derivative
        );
        emit LogPositionTokenPair(_derivativeHash, longPositionAddress, shortPositionAddress);
        if (_amount > 0) {
            IOpiumPositionToken(longPositionAddress).mint(_buyer, _amount);
            IOpiumPositionToken(shortPositionAddress).mint(_seller, _amount);
        }
    }

    /// @notice it creates a specified amount of LONG/SHORT position tokens on behalf of the buyer(LONG) and seller(SHORT) - the specified amount can be 0 in which case the ERC20 contract of the position tokens will only be deployed
    /// @dev if LONG or SHORT position contracts have not been deployed yet at the provided addresses then it is expected to fail
    /// @param _buyer address of the recipient of the LONG position tokens
    /// @param _seller address of the recipient of the SHORT position tokens
    /// @param _longPositionAddress address of the deployed LONG position token
    /// @param _shortPositionAddress address of the deployed SHORT position token
    /// @param _amount amount of position tokens to be minted to the _positionHolder
    function mintPair(
        address _buyer,
        address _seller,
        address _longPositionAddress,
        address _shortPositionAddress,
        uint256 _amount
    ) external onlyCore {
        IOpiumPositionToken(_longPositionAddress).mint(_buyer, _amount);
        IOpiumPositionToken(_shortPositionAddress).mint(_seller, _amount);
    }

    /// @notice it burns specified amount of a specific position tokens on behalf of a specified owner
    /// @notice it is consumed by Opium.Core to execute or cancel a specific position type
    /// @dev if no position has been deployed at the provided address, it is expected to revert
    /// @param _positionOwner address of the owner of the specified position token
    /// @param _positionAddress address of the position token to be burnt
    /// @param _amount amount of position tokens to be minted to the _positionHolder
    function burn(
        address _positionOwner,
        address _positionAddress,
        uint256 _amount
    ) external onlyCore {
        IOpiumPositionToken(_positionAddress).burn(_positionOwner, _amount);
    }

    /// @notice It burns the specified amount of LONG/SHORT position tokens on behalf of a specified owner
    /// @notice It is consumed by Opium.Core to redeem market neutral position pairs
    /// @param _positionOwner address of the owner of the LONG/SHORT position tokens
    /// @param _longPositionAddress address of the deployed LONG position token
    /// @param _shortPositionAddress address of the deployed SHORT position token
    /// @param _amount amount of position tokens to be minted to the _positionHolder
    function burnPair(
        address _positionOwner,
        address _longPositionAddress,
        address _shortPositionAddress,
        uint256 _amount
    ) external onlyCore {
        IOpiumPositionToken(_longPositionAddress).burn(_positionOwner, _amount);
        IOpiumPositionToken(_shortPositionAddress).burn(_positionOwner, _amount);
    }

    // Reserved storage space to allow for layout changes in the future.
    uint256[50] private __gap;
}

File 2 of 23 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

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

File 2 of 23 : OpiumPositionToken.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
import "../interfaces/IDerivativeLogic.sol";
import "../libs/LibDerivative.sol";
import "../libs/LibBokkyPooBahsDateTimeLibrary.sol";

/**
    Error codes:
    - P1 = ERROR_OPIUM_POSITION_TOKEN_NOT_FACTORY
 */

/// @title Opium.OpiumPositionToken is an ERC20PermitUpgradeable child contract created by the Opium.OpiumProxyFactory. It represents a specific position (either LONG or SHORT) for a given `LibDerivative.Derivative` derivative
contract OpiumPositionToken is ERC20PermitUpgradeable {
    using LibDerivative for LibDerivative.Derivative;

    /// It describes the derivative whose position (either LONG or SHORT) is being represented by the OpiumPositionToken
    struct OpiumPositionTokenParams {
        LibDerivative.Derivative derivative;
        LibDerivative.PositionType positionType;
        bytes32 derivativeHash;
    }

    address private factory;
    OpiumPositionTokenParams private opiumPositionTokenParams;

    /// @notice It is applied to all the stateful functions in OpiumPositionToken as they are meant to be consumed only via the OpiumProxyFactory
    modifier onlyFactory() {
        require(msg.sender == factory, "P1");
        _;
    }

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

    // ***** SETTERS *****

    /// @notice `it is called only once upon deployment of the contract
    /// @dev it sets the state variables that are meant to be read-only and should be consumed by other contracts to retrieve information about the derivative
    /// @param _derivativeHash bytes32 hash of `LibDerivative.Derivative`
    /// @param _positionType  LibDerivative.PositionType _positionType describes whether the present ERC20 token is LONG or SHORT
    /// @param _derivative LibDerivative.Derivative Derivative definition
    function initialize(
        bytes32 _derivativeHash,
        LibDerivative.PositionType _positionType,
        LibDerivative.Derivative calldata _derivative
    ) external initializer {
        __ERC20_init("", "");
        __EIP712_init_unchained("Opium Position Token", "1");
        __ERC20Permit_init_unchained("");
        factory = msg.sender;
        opiumPositionTokenParams = OpiumPositionTokenParams({
            derivative: _derivative,
            positionType: _positionType,
            derivativeHash: _derivativeHash
        });
    }

    /// @notice it mints a specified amount of tokens to the given address
    /// @dev can only be called by the factory contract set in the `initialize` function
    /// @param _positionOwner address of the recipient of the position tokens
    /// @param _amount amount of position tokens to be minted to the _positionOwner
    function mint(address _positionOwner, uint256 _amount) external onlyFactory {
        _mint(_positionOwner, _amount);
    }

    /// @notice it burns a specified amount of tokens owned by the given address
    /// @dev can only be called by the factory contract set in the `initialize` function
    /// @param _positionOwner address of the owner of the position tokens
    /// @param _amount amount of position tokens to be burnt
    function burn(address _positionOwner, uint256 _amount) external onlyFactory {
        _burn(_positionOwner, _amount);
    }

    // ***** GETTERS *****

    /// @notice It retrieves the address of the factory contract set in the `initialize` function
    /// @return address of the factory contract (OpiumProxyFactory)
    function getFactoryAddress() external view returns (address) {
        return factory;
    }

    /// @notice It retrieves all the stored information about the underlying derivative
    /// @return _opiumPositionTokenParams OpiumPositionTokenParams struct which contains `LibDerivative.Derivative` schema of the derivative, the `LibDerivative.PositionType` of the present ERC20 token and the bytes32 hash `derivativeHash` of the `LibDerivative.Derivative` derivative
    function getPositionTokenData() external view returns (OpiumPositionTokenParams memory _opiumPositionTokenParams) {
        return opiumPositionTokenParams;
    }

    // ****************** PUBLIC FUNCTIONS ******************

    /**
     * @notice It overrides the OpenZeppelin name() getter and returns a custom erc20 name which is derived from the endTime of the erc20 token's associated derivative's maturity, the custom derivative name chosen by the derivative author and the derivative hash
     */
    function name() public view override returns (string memory) {
        string memory derivativeAuthorCustomName = IDerivativeLogic(opiumPositionTokenParams.derivative.syntheticId).getSyntheticIdName();
        string memory derivativeHashSlice = _toDerivativeHashStringIdentifier(opiumPositionTokenParams.derivativeHash);
        bytes memory endTimeDate = _toDerivativeEndTimeIdentifier(opiumPositionTokenParams.derivative.endTime);
        bytes memory baseCustomName = abi.encodePacked(
            "Opium:",
            endTimeDate,
            "-",
            derivativeAuthorCustomName,
            "-",
            derivativeHashSlice
        );
        return
            string(
                abi.encodePacked(
                    baseCustomName,
                    opiumPositionTokenParams.positionType == LibDerivative.PositionType.LONG ? "-LONG" : "-SHORT"
                )
            );
    }

    /**
     * @notice It overrides the OpenZeppelin symbol() getter and returns a custom erc20 symbol which is derived from the endTime of the erc20 token's associated derivative's maturity, the custom derivative name chosen by the derivative author and the derivative hash
     */
    function symbol() public view override returns (string memory) {
        string memory derivativeAuthorCustomName = IDerivativeLogic(opiumPositionTokenParams.derivative.syntheticId).getSyntheticIdName();
        string memory derivativeHashSlice = _toDerivativeHashStringIdentifier(opiumPositionTokenParams.derivativeHash);
        bytes memory endTimeDate = _toDerivativeEndTimeIdentifier(opiumPositionTokenParams.derivative.endTime);
        bytes memory customSymbol = abi.encodePacked(
            "OPIUM",
            "_",
            endTimeDate,
            "_",
            derivativeAuthorCustomName,
            "_",
            derivativeHashSlice
        );
        return
            string(
                abi.encodePacked(
                    customSymbol,
                    opiumPositionTokenParams.positionType == LibDerivative.PositionType.LONG ? "_L" : "_S"
                )
            );
    }

    // ****************** PRIVATE FUNCTIONS ******************

    /// @notice It is used to obtain a slice of derivativeHash and convert it to a string to be used as part of an Opium position token's name
    /// @param _data bytes32 representing a derivativeHash
    /// @return string representing the first 4 characters of a derivativeHash prefixed by "0x"
    function _toDerivativeHashStringIdentifier(bytes32 _data) private pure returns (string memory) {
        bytes4 result;
        assembly {
            result := or(
                and(
                    or(
                        shr(4, and(_data, 0xF000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000)),
                        shr(8, and(_data, 0x0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00))
                    ),
                    0xffff000000000000000000000000000000000000000000000000000000000000
                ),
                shr(
                    16,
                    or(
                        shr(4, and(shl(8, _data), 0xF000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000)),
                        shr(8, and(shl(8, _data), 0x0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00))
                    )
                )
            )
        }

        return
            string(
                abi.encodePacked(
                    "0x",
                    bytes4(0x30303030 + uint32(result) + (((uint32(result) + 0x06060606) >> 4) & 0x0F0F0F0F) * 7)
                )
            );
    }

    /// @notice It is used to convert a derivative.endTime to a human-readable date to be used as part of an Opium position token's name
    /// @dev { See the third-party library ./libs/LibBokkyPooBahsDateTimeLibrary.sol }
    /// @param _derivativeEndTime uint256 representing the timestamp of a given derivative's maturity
    /// @return bytes representing the encoding of the derivativeEndTime converted to day-month-year in the format DD/MM/YYYY
    function _toDerivativeEndTimeIdentifier(uint256 _derivativeEndTime) private pure returns (bytes memory) {
        (uint256 year, uint256 month, uint256 day) = BokkyPooBahsDateTimeLibrary.timestampToDate(_derivativeEndTime);

        return
            abi.encodePacked(
                StringsUpgradeable.toString(year),
                month < 10
                    ? abi.encodePacked("0", StringsUpgradeable.toString(month))
                    : bytes(StringsUpgradeable.toString(month)),
                day < 10
                    ? abi.encodePacked("0", StringsUpgradeable.toString(day))
                    : bytes(StringsUpgradeable.toString(day))
            );
    }

    // Reserved storage space to allow for layout changes in the future.
    // The gaps left for the `OpiumPositionToken` are less than the slots allocated for the other upgradeable contracts in the protocol because the OpiumPositionToken is the only contract that is programmatically deployed (frequently), hence we want to minimize the gas cost
    uint256[30] private __gap;
}

File 2 of 23 : RegistryManager.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../../interfaces/IRegistry.sol";

/**
    Error codes:
    - M1 = ERROR_REGISTRY_MANAGER_ONLY_REGISTRY_MANAGER_ROLE
    - M2 = ERROR_REGISTRY_MANAGER_ONLY_CORE_CONFIGURATION_UPDATER_ROLE
 */
contract RegistryManager is Initializable {
    event LogRegistryChanged(address indexed _changer, address indexed _newRegistryAddress);

    IRegistry internal registry;

    modifier onlyRegistryManager() {
        require(registry.isRegistryManager(msg.sender), "M1");
        _;
    }

    modifier onlyCoreConfigurationUpdater() {
        require(registry.isCoreConfigurationUpdater(msg.sender), "M2");
        _;
    }

    function __RegistryManager__init(address _registry) internal initializer {
        require(_registry != address(0));
        registry = IRegistry(_registry);
        emit LogRegistryChanged(msg.sender, _registry);
    }

    function setRegistry(address _registry) external onlyRegistryManager {
        registry = IRegistry(_registry);
        emit LogRegistryChanged(msg.sender, _registry);
    }

    function getRegistry() external view returns (address) {
        return address(registry);
    }

    // Reserved storage space to allow for layout changes in the future.
    uint256[50] private __gap;
}

File 2 of 23 : LibDerivative.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;

/// @title Opium.Lib.LibDerivative contract should be inherited by contracts that use Derivative structure and calculate derivativeHash
library LibDerivative {
    enum PositionType {
        SHORT,
        LONG
    }

    // Opium derivative structure (ticker) definition
    struct Derivative {
        // Margin parameter for syntheticId
        uint256 margin;
        // Maturity of derivative
        uint256 endTime;
        // Additional parameters for syntheticId
        uint256[] params;
        // oracleId of derivative
        address oracleId;
        // Margin token address of derivative
        address token;
        // syntheticId of derivative
        address syntheticId;
    }

    /// @notice Calculates hash of provided Derivative
    /// @param _derivative Derivative Instance of derivative to hash
    /// @return derivativeHash bytes32 Derivative hash
    function getDerivativeHash(Derivative memory _derivative) internal pure returns (bytes32 derivativeHash) {
        derivativeHash = keccak256(
            abi.encodePacked(
                _derivative.margin,
                _derivative.endTime,
                _derivative.params,
                _derivative.oracleId,
                _derivative.token,
                _derivative.syntheticId
            )
        );
    }
}

File 2 of 23 : LibPosition.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.5;

import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";

library LibPosition {
    function predictDeterministicAddress(
        bytes32 _derivativeHash,
        bool _isLong,
        address _positionImplementationAddress,
        address _factoryAddress
    ) internal pure returns (address) {
        return _predictDeterministicAddress(_derivativeHash, _isLong, _positionImplementationAddress, _factoryAddress);
    }

    function predictAndCheckDeterministicAddress(
        bytes32 _derivativeHash,
        bool _isLong,
        address _positionImplementationAddress,
        address _factoryAddress
    ) internal view returns (address, bool) {
        address predicted = _predictDeterministicAddress(
            _derivativeHash,
            _isLong,
            _positionImplementationAddress,
            _factoryAddress
        );
        bool isDeployed = _isContract(predicted);
        return (predicted, isDeployed);
    }

    function deployOpiumPosition(
        bytes32 _derivativeHash,
        bool _isLong,
        address _positionImplementationAddress
    ) internal returns (address) {
        bytes32 salt = keccak256(abi.encodePacked(_derivativeHash, _isLong ? "L" : "S"));
        return ClonesUpgradeable.cloneDeterministic(_positionImplementationAddress, salt);
    }

    function _predictDeterministicAddress(
        bytes32 _derivativeHash,
        bool _isLong,
        address _positionImplementationAddress,
        address _factoryAddress
    ) private pure returns (address) {
        bytes32 salt = keccak256(abi.encodePacked(_derivativeHash, _isLong ? "L" : "S"));
        return ClonesUpgradeable.predictDeterministicAddress(_positionImplementationAddress, salt, _factoryAddress);
    }

    /// @notice checks whether a contract has already been deployed at a specific address
    /// @return bool true if a contract has been deployed at a specific address and false otherwise
    function _isContract(address _address) private view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(_address)
        }
        return size > 0;
    }
}

File 2 of 23 : LibBokkyPooBahsDateTimeLibrary.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.5;

// ----------------------------------------------------------------------------
// BokkyPooBah's DateTime Library v1.01
//
// A gas-efficient Solidity date and time library
//
// https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary
//
// Tested date range 1970/01/01 to 2345/12/31
//
// Conventions:
// Unit      | Range         | Notes
// :-------- |:-------------:|:-----
// timestamp | >= 0          | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC
// year      | 1970 ... 2345 |
// month     | 1 ... 12      |
// day       | 1 ... 31      |
// hour      | 0 ... 23      |
// minute    | 0 ... 59      |
// second    | 0 ... 59      |
// dayOfWeek | 1 ... 7       | 1 = Monday, ..., 7 = Sunday
//
//
// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018-2019. The MIT Licence.
// ----------------------------------------------------------------------------

// version v1.01
library BokkyPooBahsDateTimeLibrary {
    uint256 constant SECONDS_PER_DAY = 24 * 60 * 60;
    int256 constant OFFSET19700101 = 2440588;

    // ------------------------------------------------------------------------
    // Calculate year/month/day from the number of days since 1970/01/01 using
    // the date conversion algorithm from
    //   http://aa.usno.navy.mil/faq/docs/JD_Formula.php
    // and adding the offset 2440588 so that 1970/01/01 is day 0
    //
    // int L = days + 68569 + offset
    // int N = 4 * L / 146097
    // L = L - (146097 * N + 3) / 4
    // year = 4000 * (L + 1) / 1461001
    // L = L - 1461 * year / 4 + 31
    // month = 80 * L / 2447
    // dd = L - 2447 * month / 80
    // L = month / 11
    // month = month + 2 - 12 * L
    // year = 100 * (N - 49) + year + L
    // ------------------------------------------------------------------------
    function _daysToDate(uint256 _days)
        internal
        pure
        returns (
            uint256 year,
            uint256 month,
            uint256 day
        )
    {
        int256 __days = int256(_days);

        int256 L = __days + 68569 + OFFSET19700101;
        int256 N = (4 * L) / 146097;
        L = L - (146097 * N + 3) / 4;
        int256 _year = (4000 * (L + 1)) / 1461001;
        L = L - (1461 * _year) / 4 + 31;
        int256 _month = (80 * L) / 2447;
        int256 _day = L - (2447 * _month) / 80;
        L = _month / 11;
        _month = _month + 2 - 12 * L;
        _year = 100 * (N - 49) + _year + L;

        year = uint256(_year);
        month = uint256(_month);
        day = uint256(_day);
    }

    function timestampToDate(uint256 timestamp)
        internal
        pure
        returns (
            uint256 year,
            uint256 month,
            uint256 day
        )
    {
        (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    }
}

File 2 of 23 : IOpiumPositionToken.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../libs/LibDerivative.sol";

interface IOpiumPositionToken is IERC20PermitUpgradeable, IERC20Upgradeable {
    struct OpiumPositionTokenParams {
        LibDerivative.Derivative derivative;
        LibDerivative.PositionType positionType;
        bytes32 derivativeHash;
    }

    function initialize(
        bytes32 _derivativeHash,
        LibDerivative.PositionType _positionType,
        LibDerivative.Derivative calldata _derivative
    ) external;

    function mint(address _positionOwner, uint256 _amount) external;

    function burn(address _positionOwner, uint256 _amount) external;

    function getFactoryAddress() external view returns (address);

    function getPositionTokenData() external view returns (OpiumPositionTokenParams memory opiumPositionTokenParams);

    function safeTransfer(
        IERC20Upgradeable token,
        address to,
        uint256 value
    ) external;

    function safeTransferFrom(
        IERC20Upgradeable token,
        address from,
        address to,
        uint256 value
    ) external;
}

File 2 of 23 : IRegistry.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;
import "../core/registry/RegistryEntities.sol";

interface IRegistry {
    function initialize(address _governor) external;

    function setProtocolAddresses(
        address _opiumProxyFactory,
        address _core,
        address _oracleAggregator,
        address _syntheticAggregator,
        address _tokenSpender
    ) external;

    function setNoDataCancellationPeriod(uint32 _noDataCancellationPeriod) external;

    function addToWhitelist(address _whitelisted) external;

    function removeFromWhitelist(address _whitelisted) external;

    function setProtocolExecutionReserveClaimer(address _protocolExecutionReserveClaimer) external;

    function setProtocolRedemptionReserveClaimer(address _protocolRedemptionReserveClaimer) external;

    function setProtocolExecutionReservePart(uint32 _protocolExecutionReservePart) external;

    function setDerivativeAuthorExecutionFeeCap(uint32 _derivativeAuthorExecutionFeeCap) external;

    function setProtocolRedemptionReservePart(uint32 _protocolRedemptionReservePart) external;

    function setDerivativeAuthorRedemptionReservePart(uint32 _derivativeAuthorRedemptionReservePart) external;

    function pause() external;

    function pauseProtocolPositionCreation() external;

    function pauseProtocolPositionMinting() external;

    function pauseProtocolPositionRedemption() external;

    function pauseProtocolPositionExecution() external;

    function pauseProtocolPositionCancellation() external;

    function pauseProtocolReserveClaim() external;

    function unpause() external;

    function getProtocolParameters() external view returns (RegistryEntities.ProtocolParametersArgs memory);

    function getProtocolAddresses() external view returns (RegistryEntities.ProtocolAddressesArgs memory);

    function isRegistryManager(address _address) external view returns (bool);

    function isCoreConfigurationUpdater(address _address) external view returns (bool);

    function getCore() external view returns (address);

    function isCoreSpenderWhitelisted(address _address) external view returns (bool);

    function isProtocolPaused() external view returns (bool);

    function isProtocolPositionCreationPaused() external view returns (bool);

    function isProtocolPositionMintingPaused() external view returns (bool);

    function isProtocolPositionRedemptionPaused() external view returns (bool);

    function isProtocolPositionExecutionPaused() external view returns (bool);

    function isProtocolPositionCancellationPaused() external view returns (bool);

    function isProtocolReserveClaimPaused() external view returns (bool);
}

File 2 of 23 : draft-ERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-ERC20Permit.sol)

pragma solidity ^0.8.0;

import "./draft-IERC20PermitUpgradeable.sol";
import "../ERC20Upgradeable.sol";
import "../../../utils/cryptography/draft-EIP712Upgradeable.sol";
import "../../../utils/cryptography/ECDSAUpgradeable.sol";
import "../../../utils/CountersUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * _Available since v3.4._
 */
abstract contract ERC20PermitUpgradeable is Initializable, ERC20Upgradeable, IERC20PermitUpgradeable, EIP712Upgradeable {
    using CountersUpgradeable for CountersUpgradeable.Counter;

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

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private _PERMIT_TYPEHASH;

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

    function __ERC20Permit_init_unchained(string memory name) internal onlyInitializing {
        _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");}

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

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

        bytes32 hash = _hashTypedDataV4(structHash);

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

        _approve(owner, spender, value);
    }

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

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

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

File 2 of 23 : IDerivativeLogic.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;

import "../libs/LibDerivative.sol";

/// @title Opium.Interface.IDerivativeLogic is an interface that every syntheticId should implement
interface IDerivativeLogic {
    // Event with syntheticId metadata JSON string (for DIB.ONE derivative explorer)
    event LogMetadataSet(string metadata);

    /// @notice Validates ticker
    /// @param _derivative Derivative Instance of derivative to validate
    /// @return Returns boolean whether ticker is valid
    function validateInput(LibDerivative.Derivative memory _derivative) external view returns (bool);

    /// @return Returns the custom name of a derivative ticker which will be used as part of the name of its positions
    function getSyntheticIdName() external view returns (string memory);

    /// @notice Calculates margin required for derivative creation
    /// @param _derivative Derivative Instance of derivative
    /// @return buyerMargin uint256 Margin needed from buyer (LONG position)
    /// @return sellerMargin uint256 Margin needed from seller (SHORT position)
    function getMargin(LibDerivative.Derivative memory _derivative)
        external
        view
        returns (uint256 buyerMargin, uint256 sellerMargin);

    /// @notice Calculates payout for derivative execution
    /// @param _derivative Derivative Instance of derivative
    /// @param _result uint256 Data retrieved from oracleId on the maturity
    /// @return buyerPayout uint256 Payout in ratio for buyer (LONG position holder)
    /// @return sellerPayout uint256 Payout in ratio for seller (SHORT position holder)
    function getExecutionPayout(LibDerivative.Derivative memory _derivative, uint256 _result)
        external
        view
        returns (uint256 buyerPayout, uint256 sellerPayout);

    /// @notice Returns syntheticId author address for Opium commissions
    /// @return authorAddress address The address of syntheticId address
    function getAuthorAddress() external view returns (address authorAddress);

    /// @notice Returns syntheticId author commission in base of COMMISSION_BASE
    /// @return commission uint256 Author commission
    function getAuthorCommission() external view returns (uint256 commission);

    /// @notice Returns whether thirdparty could execute on derivative's owner's behalf
    /// @param _derivativeOwner address Derivative owner address
    /// @return Returns boolean whether _derivativeOwner allowed third party execution
    function thirdpartyExecutionAllowed(address _derivativeOwner) external view returns (bool);

    /// @notice Sets whether thirds parties are allowed or not to execute derivative's on msg.sender's behalf
    /// @param _allow bool Flag for execution allowance
    function allowThirdpartyExecution(bool _allow) external;
}

File 2 of 23 : draft-IERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20PermitUpgradeable {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 2 of 23 : ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
        __Context_init_unchained();
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

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

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

        return true;
    }

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

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

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

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

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

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

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

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

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

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

File 2 of 23 : draft-EIP712Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/draft-EIP712.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712Upgradeable is Initializable {
    /* solhint-disable var-name-mixedcase */
    bytes32 private _HASHED_NAME;
    bytes32 private _HASHED_VERSION;
    bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    /* solhint-enable var-name-mixedcase */

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

    function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash());
    }

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

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

    /**
     * @dev The hash of the name parameter for the EIP712 domain.
     *
     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
     * are a concern.
     */
    function _EIP712NameHash() internal virtual view returns (bytes32) {
        return _HASHED_NAME;
    }

    /**
     * @dev The hash of the version parameter for the EIP712 domain.
     *
     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
     * are a concern.
     */
    function _EIP712VersionHash() internal virtual view returns (bytes32) {
        return _HASHED_VERSION;
    }
    uint256[50] private __gap;
}

File 2 of 23 : ECDSAUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../StringsUpgradeable.sol";

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

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

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

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

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

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

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

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

        return (signer, RecoverError.NoError);
    }

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

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

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

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

File 2 of 23 : CountersUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

File 2 of 23 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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 a proxied contract can't have 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));
    }
}

File 2 of 23 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

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

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

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

File 2 of 23 : ContextUpgradeable.sol
// 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 {
        __Context_init_unchained();
    }

    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;
    }
    uint256[50] private __gap;
}

File 2 of 23 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 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);
            }
        }
    }
}

File 2 of 23 : RegistryEntities.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.5;

library RegistryEntities {
    struct ProtocolParametersArgs {
        // Period of time after which ticker could be canceled if no data was provided to the `oracleId`
        uint32 noDataCancellationPeriod;
        // Max fee that derivative author can set
        // it works as an upper bound for when the derivative authors set their synthetic's fee
        uint32 derivativeAuthorExecutionFeeCap;
        // Fixed part (percentage) that the derivative author receives for each redemption of market neutral positions
        // It is not set by the derivative authors themselves
        uint32 derivativeAuthorRedemptionReservePart;
        // Represents which part of derivative author reserves originated from derivative executions go to the protocol reserves
        uint32 protocolExecutionReservePart;
        // Represents which part of derivative author reserves originated from redemption of market neutral positions go to the protocol reserves
        uint32 protocolRedemptionReservePart;
        /// Initially uninitialized variables to allow some flexibility in case of future changes and upgradeability
        uint32 __gapOne;
        uint32 __gapTwo;
        uint32 __gapThree;
    }

    struct ProtocolAddressesArgs {
        // Address of Opium.Core contract
        address core;
        // Address of Opium.OpiumProxyFactory contract
        address opiumProxyFactory;
        // Address of Opium.OracleAggregator contract
        address oracleAggregator;
        // Address of Opium.SyntheticAggregator contract
        address syntheticAggregator;
        // Address of Opium.TokenSpender contract
        address tokenSpender;
        // Address of the recipient of execution protocol reserves
        address protocolExecutionReserveClaimer;
        // Address of the recipient of redemption protocol reserves
        address protocolRedemptionReserveClaimer;
        /// Initially uninitialized variables to allow some flexibility in case of future changes and upgradeability
        uint32 __gapOne;
        uint32 __gapTwo;
    }

    struct ProtocolPausabilityArgs {
        // if true, all the protocol's entry-points are paused
        bool protocolGlobal;
        // if true, no new positions can be created
        bool protocolPositionCreation;
        // if true, no new positions can be minted
        bool protocolPositionMinting;
        // if true, no new positions can be redeemed
        bool protocolPositionRedemption;
        // if true, no new positions can be executed
        bool protocolPositionExecution;
        // if true, no new positions can be cancelled
        bool protocolPositionCancellation;
        // if true, no reserves can be claimed
        bool protocolReserveClaim;
        /// Initially uninitialized variables to allow some flexibility in case of future changes and upgradeability
        bool __gapOne;
        bool __gapTwo;
        bool __gapThree;
        bool __gapFour;
    }
}

File 2 of 23 : ClonesUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/Clones.sol)

pragma solidity ^0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 *
 * _Available since v3.4._
 */
library ClonesUpgradeable {
    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            instance := create(0, ptr, 0x37)
        }
        require(instance != address(0), "ERC1167: create failed");
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            instance := create2(0, ptr, 0x37, salt)
        }
        require(instance != address(0), "ERC1167: create2 failed");
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
            mstore(add(ptr, 0x38), shl(0x60, deployer))
            mstore(add(ptr, 0x4c), salt)
            mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
            predicted := keccak256(add(ptr, 0x37), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(address implementation, bytes32 salt)
        internal
        view
        returns (address predicted)
    {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"_derivativeHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"_longPositionAddress","type":"address"},{"indexed":true,"internalType":"address","name":"_shortPositionAddress","type":"address"}],"name":"LogPositionTokenPair","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_changer","type":"address"},{"indexed":true,"internalType":"address","name":"_newRegistryAddress","type":"address"}],"name":"LogRegistryChanged","type":"event"},{"inputs":[{"internalType":"address","name":"_positionOwner","type":"address"},{"internalType":"address","name":"_positionAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_positionOwner","type":"address"},{"internalType":"address","name":"_longPositionAddress","type":"address"},{"internalType":"address","name":"_shortPositionAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"burnPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_buyer","type":"address"},{"internalType":"address","name":"_seller","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"bytes32","name":"_derivativeHash","type":"bytes32"},{"components":[{"internalType":"uint256","name":"margin","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"uint256[]","name":"params","type":"uint256[]"},{"internalType":"address","name":"oracleId","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"syntheticId","type":"address"}],"internalType":"struct LibDerivative.Derivative","name":"_derivative","type":"tuple"}],"name":"create","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getImplementationAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_registry","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_buyer","type":"address"},{"internalType":"address","name":"_seller","type":"address"},{"internalType":"address","name":"_longPositionAddress","type":"address"},{"internalType":"address","name":"_shortPositionAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"mintPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_registry","type":"address"}],"name":"setRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b506138b5806100206000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c80639873dba91161005b5780639873dba9146100f5578063a91ee0dc14610108578063c4d66de81461011b578063f6b911bc1461012e57600080fd5b80630cbcae701461008d57806347704dbd146100b65780635ab1bd53146100cb5780636ade6d19146100e2575b600080fd5b6033546001600160a01b03165b6040516001600160a01b03909116815260200160405180910390f35b6100c96100c4366004610d7b565b610141565b005b6000546201000090046001600160a01b031661009a565b6100c96100f0366004610ddf565b6102dc565b6100c9610103366004610e71565b610471565b6100c9610116366004610d3a565b610756565b6100c9610129366004610d3a565b610869565b6100c961013c366004610e30565b61098d565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b15801561018f57600080fd5b505afa1580156101a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c79190610d5e565b6001600160a01b0316336001600160a01b0316146102115760405162461bcd60e51b8152602060048201526002602482015261463160f01b60448201526064015b60405180910390fd5b6040516340c10f1960e01b81526001600160a01b038681166004830152602482018390528416906340c10f1990604401600060405180830381600087803b15801561025b57600080fd5b505af115801561026f573d6000803e3d6000fd5b50506040516340c10f1960e01b81526001600160a01b03878116600483015260248201859052851692506340c10f199150604401600060405180830381600087803b1580156102bd57600080fd5b505af11580156102d1573d6000803e3d6000fd5b505050505050505050565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b15801561032a57600080fd5b505afa15801561033e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103629190610d5e565b6001600160a01b0316336001600160a01b0316146103a75760405162461bcd60e51b8152602060048201526002602482015261463160f01b6044820152606401610208565b604051632770a7eb60e21b81526001600160a01b03858116600483015260248201839052841690639dc29fac90604401600060405180830381600087803b1580156103f157600080fd5b505af1158015610405573d6000803e3d6000fd5b5050604051632770a7eb60e21b81526001600160a01b0387811660048301526024820185905285169250639dc29fac9150604401600060405180830381600087803b15801561045357600080fd5b505af1158015610467573d6000803e3d6000fd5b5050505050505050565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b1580156104bf57600080fd5b505afa1580156104d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f79190610d5e565b6001600160a01b0316336001600160a01b03161461053c5760405162461bcd60e51b8152602060048201526002602482015261463160f01b6044820152606401610208565b6033546000906105599084906001906001600160a01b0316610ab6565b60335490915060009061057890859083906001600160a01b0316610ab6565b6040516372d6d1b960e01b81529091506001600160a01b038316906372d6d1b9906105ac9087906001908890600401610fa6565b600060405180830381600087803b1580156105c657600080fd5b505af11580156105da573d6000803e3d6000fd5b50506040516372d6d1b960e01b81526001600160a01b03841692506372d6d1b9915061060f9087906000908890600401610fa6565b600060405180830381600087803b15801561062957600080fd5b505af115801561063d573d6000803e3d6000fd5b50505050806001600160a01b0316826001600160a01b0316857facda084bb7d7816e4761589dd38d696b720ae5609d71839a5cf8c40f9f6b3db360405160405180910390a4841561074d576040516340c10f1960e01b81526001600160a01b038881166004830152602482018790528316906340c10f1990604401600060405180830381600087803b1580156106d257600080fd5b505af11580156106e6573d6000803e3d6000fd5b50506040516340c10f1960e01b81526001600160a01b03898116600483015260248201899052841692506340c10f199150604401600060405180830381600087803b15801561073457600080fd5b505af1158015610748573d6000803e3d6000fd5b505050505b50505050505050565b600054604051634048d90960e01b8152336004820152620100009091046001600160a01b031690634048d9099060240160206040518083038186803b15801561079e57600080fd5b505afa1580156107b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107d69190610eee565b6108075760405162461bcd60e51b81526020600482015260026024820152614d3160f01b6044820152606401610208565b6000805475ffffffffffffffffffffffffffffffffffffffff00001916620100006001600160a01b038416908102919091178255604051909133917fec10a16af385903532506d1567380fd8d93d880e8ed4bcacc42b0848e781406a9190a350565b600054610100900460ff166108845760005460ff1615610888565b303b155b6108eb5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610208565b600054610100900460ff1615801561090d576000805461ffff19166101011790555b61091682610b35565b60405161092290610d1d565b604051809103906000f08015801561093e573d6000803e3d6000fd5b50603380547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03929092169190911790558015610989576000805461ff00191690555b5050565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b1580156109db57600080fd5b505afa1580156109ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a139190610d5e565b6001600160a01b0316336001600160a01b031614610a585760405162461bcd60e51b8152602060048201526002602482015261463160f01b6044820152606401610208565b604051632770a7eb60e21b81526001600160a01b03848116600483015260248201839052831690639dc29fac90604401600060405180830381600087803b158015610aa257600080fd5b505af115801561074d573d6000803e3d6000fd5b6000808484610ade57604051806040016040528060018152602001605360f81b815250610af9565b604051806040016040528060018152602001601360fa1b8152505b604051602001610b0a929190610f5f565b604051602081830303815290604052805190602001209050610b2c8382610c60565b95945050505050565b600054610100900460ff16610b505760005460ff1615610b54565b303b155b610bb75760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610208565b600054610100900460ff16158015610bd9576000805461ffff19166101011790555b6001600160a01b038216610bec57600080fd5b6000805475ffffffffffffffffffffffffffffffffffffffff00001916620100006001600160a01b038516908102919091178255604051909133917fec10a16af385903532506d1567380fd8d93d880e8ed4bcacc42b0848e781406a9190a38015610989576000805461ff00191690555050565b60006040517f3d602d80600a3d3981f3363d3d373d3d3d363d7300000000000000000000000081528360601b60148201527f5af43d82803e903d91602b57fd5bf300000000000000000000000000000000006028820152826037826000f59150506001600160a01b038116610d175760405162461bcd60e51b815260206004820152601760248201527f455243313136373a2063726561746532206661696c65640000000000000000006044820152606401610208565b92915050565b6127c8806110b883390190565b8035610d358161109f565b919050565b600060208284031215610d4c57600080fd5b8135610d578161109f565b9392505050565b600060208284031215610d7057600080fd5b8151610d578161109f565b600080600080600060a08688031215610d9357600080fd5b8535610d9e8161109f565b94506020860135610dae8161109f565b93506040860135610dbe8161109f565b92506060860135610dce8161109f565b949793965091946080013592915050565b60008060008060808587031215610df557600080fd5b8435610e008161109f565b93506020850135610e108161109f565b92506040850135610e208161109f565b9396929550929360600135925050565b600080600060608486031215610e4557600080fd5b8335610e508161109f565b92506020840135610e608161109f565b929592945050506040919091013590565b600080600080600060a08688031215610e8957600080fd5b8535610e948161109f565b94506020860135610ea48161109f565b93506040860135925060608601359150608086013567ffffffffffffffff811115610ece57600080fd5b860160c08189031215610ee057600080fd5b809150509295509295909350565b600060208284031215610f0057600080fd5b81518015158114610d5757600080fd5b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115610f4257600080fd5b8260051b8083602087013760009401602001938452509192915050565b8281526000825160005b81811015610f8557602081860181015185830182015201610f69565b81811115610f97576000602083860101525b50919091016020019392505050565b838152600060028410610fc957634e487b7160e01b600052602160045260246000fd5b8360208301526060604083015282356060830152602083013560808301526040830135601e19843603018112610ffe57600080fd5b8301803567ffffffffffffffff81111561101757600080fd5b8060051b360385131561102957600080fd5b60c060a085015261104261012085018260208501610f10565b91505061105160608501610d2a565b6001600160a01b031660c084015261106b60808501610d2a565b6001600160a01b031660e084015261108560a08501610d2a565b6001600160a01b0381166101008501525095945050505050565b6001600160a01b03811681146110b457600080fd5b5056fe608060405234801561001057600080fd5b506127a8806100206000396000f3fe608060405234801561001057600080fd5b50600436106101515760003560e01c806372d6d1b9116100cd578063a9059cbb11610081578063ce21286d11610066578063ce21286d146102a6578063d505accf146102bb578063dd62ed3e146102ce57600080fd5b8063a9059cbb14610278578063a9c2e36c1461028b57600080fd5b806395d89b41116100b257806395d89b411461024a5780639dc29fac14610252578063a457c2d71461026557600080fd5b806372d6d1b9146102245780637ecebe001461023757600080fd5b8063313ce56711610124578063395093511161010957806339509351146101d357806340c10f19146101e657806370a08231146101fb57600080fd5b8063313ce567146101bc5780633644e515146101cb57600080fd5b806306fdde0314610156578063095ea7b31461017457806318160ddd1461019757806323b872dd146101a9575b600080fd5b61015e610307565b60405161016b9190612265565b60405180910390f35b610187610182366004611f85565b610496565b604051901515815260200161016b565b6035545b60405190815260200161016b565b6101876101b7366004611ed6565b6104ac565b6040516012815260200161016b565b61019b610570565b6101876101e1366004611f85565b61057f565b6101f96101f4366004611f85565b6105bb565b005b61019b610209366004611e81565b6001600160a01b031660009081526033602052604090205490565b6101f9610232366004611faf565b610608565b61019b610245366004611e81565b61087c565b61015e61089c565b6101f9610260366004611f85565b6109dc565b610187610273366004611f85565b610a25565b610187610286366004611f85565b610ad6565b60cc546040516001600160a01b03909116815260200161016b565b6102ae610ae3565b60405161016b9190612298565b6101f96102c9366004611f12565b610c1b565b61019b6102dc366004611ea3565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b60d254604080516307ac921760e31b815290516060926000926001600160a01b0390911691633d6490b8916004808201928692909190829003018186803b15801561035157600080fd5b505afa158015610365573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261038d9190810190612013565b9050600061039f60cd60070154610d61565b60ce549091506000906103b190610e6f565b905060008184846040516020016103ca93929190612164565b60408051601f19818403018152919052905080600160d35460ff1660018111156103f6576103f6612730565b14610436576040518060400160405280600681526020017f2d53484f5254000000000000000000000000000000000000000000000000000081525061046d565b6040518060400160405280600581526020017f2d4c4f4e470000000000000000000000000000000000000000000000000000008152505b60405160200161047e9291906120c9565b60405160208183030381529060405294505050505090565b60006104a3338484610f37565b50600192915050565b60006104b984848461105c565b6001600160a01b0384166000908152603460209081526040808320338452909152902054828110156105585760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206160448201527f6c6c6f77616e636500000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b6105658533858403610f37565b506001949350505050565b600061057a611259565b905090565b3360008181526034602090815260408083206001600160a01b038716845290915281205490916104a39185906105b69086906123f5565b610f37565b60cc546001600160a01b031633146105fa5760405162461bcd60e51b8152602060048201526002602482015261503160f01b604482015260640161054f565b61060482826112d4565b5050565b600054610100900460ff166106235760005460ff1615610627565b303b155b6106995760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a6564000000000000000000000000000000000000606482015260840161054f565b600054610100900460ff161580156106bb576000805461ffff19166101011790555b6106e360405180602001604052806000815250604051806020016040528060008152506113b3565b61073b6040518060400160405280601481526020017f4f7069756d20506f736974696f6e20546f6b656e000000000000000000000000815250604051806040016040528060018152602001603160f81b815250611430565b610753604051806020016040528060008152506114b5565b60cc805473ffffffffffffffffffffffffffffffffffffffff19163317905560408051606081019091528061078784612577565b815260200184600181111561079e5761079e612730565b815260209081018690528151805160cd9081558183015160ce5560408201518051919384926107d19260cf920190611d92565b50606082015160038201805473ffffffffffffffffffffffffffffffffffffffff199081166001600160a01b03938416179091556080840151600484018054831691841691909117905560a090930151600590920180549093169116179055602082015160068201805460ff19166001838181111561085257610852612730565b0217905550604082015181600701559050508015610876576000805461ff00191690555b50505050565b6001600160a01b0381166000908152609960205260408120545b92915050565b60d254604080516307ac921760e31b815290516060926000926001600160a01b0390911691633d6490b8916004808201928692909190829003018186803b1580156108e657600080fd5b505afa1580156108fa573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526109229190810190612013565b9050600061093460cd60070154610d61565b60ce5490915060009061094690610e6f565b9050600081848460405160200161095f939291906121e7565b60408051601f19818403018152919052905080600160d35460ff16600181111561098b5761098b612730565b146109b057604051806040016040528060028152602001615f5360f01b81525061046d565b6040518060400160405280600281526020016117d360f21b81525060405160200161047e9291906120c9565b60cc546001600160a01b03163314610a1b5760405162461bcd60e51b8152602060048201526002602482015261503160f01b604482015260640161054f565b6106048282611547565b3360009081526034602090815260408083206001600160a01b038616845290915281205482811015610abf5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f000000000000000000000000000000000000000000000000000000606482015260840161054f565b610acc3385858403610f37565b5060019392505050565b60006104a333848461105c565b6040805161012081018252600060608083018281526080840183905260a084019190915260c0830182905260e08301829052610100830182905282526020820181905291810191909152604080516101208101825260cd80546060830190815260ce54608084015260cf80548551602082810282018101909752818152949593948694869360a08701939091830182828015610b9e57602002820191906000526020600020905b815481526020019060010190808311610b8a575b505050918352505060038201546001600160a01b0390811660208084019190915260048401548216604084015260059093015416606090910152908252600683015491019060ff166001811115610bf757610bf7612730565b6001811115610c0857610c08612730565b8152602001600782015481525050905090565b83421115610c6b5760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015260640161054f565b6000609a54888888610c7c8c611692565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000610cd7826116ba565b90506000610ce782878787611708565b9050896001600160a01b0316816001600160a01b031614610d4a5760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015260640161054f565b610d558a8a8a610f37565b50505050505050505050565b6060600f60f81b600483811c91909116600f60f01b600885901c161783821b7f0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f00167e0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f85161760101c1790610ddc60e083901c630606060661240d565b63ffffffff16901c630f0f0f0f166007610df691906124f5565b610e0860e083901c633030303061240d565b610e12919061240d565b60e01b604051602001610e58919061060f60f31b81527fffffffff0000000000000000000000000000000000000000000000000000000091909116600282015260060190565b604051602081830303815290604052915050919050565b60606000806000610e7f85611730565b925092509250610e8e83611756565b600a8310610ea457610e9f83611756565b610ecd565b610ead83611756565b604051602001610ebd919061213b565b6040516020818303038152906040525b600a8310610ee357610ede83611756565b610f0c565b610eec83611756565b604051602001610efc919061213b565b6040516020818303038152906040525b604051602001610f1e939291906120f8565b6040516020818303038152906040529350505050919050565b6001600160a01b038316610f995760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161054f565b6001600160a01b038216610ffa5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161054f565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b0383166110d85760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f6472657373000000000000000000000000000000000000000000000000000000606482015260840161054f565b6001600160a01b03821661113a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161054f565b6001600160a01b038316600090815260336020526040902054818110156111c95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e63650000000000000000000000000000000000000000000000000000606482015260840161054f565b6001600160a01b038085166000908152603360205260408082208585039055918516815290812080548492906112009084906123f5565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161124c91815260200190565b60405180910390a3610876565b600061057a7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f61128860655490565b6066546040805160208101859052908101839052606081018290524660808201523060a082015260009060c0016040516020818303038152906040528051906020012090509392505050565b6001600160a01b03821661132a5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161054f565b806035600082825461133c91906123f5565b90915550506001600160a01b038216600090815260336020526040812080548392906113699084906123f5565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b600054610100900460ff1661141e5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b611426611874565b61060482826118e1565b600054610100900460ff1661149b5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b815160209283012081519190920120606591909155606655565b600054610100900460ff166115205760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b507f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9609a55565b6001600160a01b0382166115a75760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161054f565b6001600160a01b0382166000908152603360205260409020548181101561161b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161054f565b6001600160a01b038316600090815260336020526040812083830390556035805484929061164a908490612560565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200161104f565b505050565b6001600160a01b03811660009081526099602052604090208054600181018255905b50919050565b60006108966116c7611259565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b600080600061171987878787611973565b9150915061172681611a60565b5095945050505050565b60008080611749611744620151808661245a565b611c1e565b9196909550909350915050565b60608161177a5750506040805180820190915260018152600360fc1b602082015290565b8160005b81156117a4578061178e816126d5565b915061179d9050600a8361245a565b915061177e565b60008167ffffffffffffffff8111156117bf576117bf61275c565b6040519080825280601f01601f1916602001820160405280156117e9576020820181803683370190505b5090505b841561186c576117fe600183612560565b915061180b600a866126f0565b6118169060306123f5565b60f81b81838151811061182b5761182b612746565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350611865600a8661245a565b94506117ed565b949350505050565b600054610100900460ff166118df5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b565b600054610100900460ff1661194c5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b815161195f906036906020850190611ddd565b50805161168d906037906020840190611ddd565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156119aa5750600090506003611a57565b8460ff16601b141580156119c257508460ff16601c14155b156119d35750600090506004611a57565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611a27573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611a5057600060019250925050611a57565b9150600090505b94509492505050565b6000816004811115611a7457611a74612730565b1415611a7d5750565b6001816004811115611a9157611a91612730565b1415611adf5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161054f565b6002816004811115611af357611af3612730565b1415611b415760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161054f565b6003816004811115611b5557611b55612730565b1415611bae5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b606482015260840161054f565b6004816004811115611bc257611bc2612730565b1415611c1b5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b606482015260840161054f565b50565b60008080838162253d8c611c358362010bd96123b5565b611c3f91906123b5565b9050600062023ab1611c5283600461246e565b611c5c919061242c565b90506004611c6d8262023ab161246e565b611c789060036123b5565b611c82919061242c565b611c8c9083612521565b9150600062164b09611c9f8460016123b5565b611cab90610fa061246e565b611cb5919061242c565b90506004611cc5826105b561246e565b611ccf919061242c565b611cd99084612521565b611ce490601f6123b5565b9250600061098f611cf685605061246e565b611d00919061242c565b905060006050611d128361098f61246e565b611d1c919061242c565b611d269086612521565b9050611d33600b8361242c565b9450611d4085600c61246e565b611d4b8360026123b5565b611d559190612521565b91508483611d64603187612521565b611d6f90606461246e565b611d7991906123b5565b611d8391906123b5565b9a919950975095505050505050565b828054828255906000526020600020908101928215611dcd579160200282015b82811115611dcd578251825591602001919060010190611db2565b50611dd9929150611e50565b5090565b828054611de9906126a0565b90600052602060002090601f016020900481019282611e0b5760008555611dcd565b82601f10611e2457805160ff1916838001178555611dcd565b82800160010185558215611dcd5791820182811115611dcd578251825591602001919060010190611db2565b5b80821115611dd95760008155600101611e51565b80356001600160a01b0381168114611e7c57600080fd5b919050565b600060208284031215611e9357600080fd5b611e9c82611e65565b9392505050565b60008060408385031215611eb657600080fd5b611ebf83611e65565b9150611ecd60208401611e65565b90509250929050565b600080600060608486031215611eeb57600080fd5b611ef484611e65565b9250611f0260208501611e65565b9150604084013590509250925092565b600080600080600080600060e0888a031215611f2d57600080fd5b611f3688611e65565b9650611f4460208901611e65565b95506040880135945060608801359350608088013560ff81168114611f6857600080fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215611f9857600080fd5b611fa183611e65565b946020939093013593505050565b600080600060608486031215611fc457600080fd5b83359250602084013560028110611fda57600080fd5b9150604084013567ffffffffffffffff811115611ff657600080fd5b840160c0818703121561200857600080fd5b809150509250925092565b60006020828403121561202557600080fd5b815167ffffffffffffffff8082111561203d57600080fd5b818401915084601f83011261205157600080fd5b8151818111156120635761206361275c565b612076601f8201601f1916602001612384565b915080825285602082850101111561208d57600080fd5b61209e816020840160208601612674565b50949350505050565b600281106120c557634e487b7160e01b600052602160045260246000fd5b9052565b600083516120db818460208801612674565b8351908301906120ef818360208801612674565b01949350505050565b6000845161210a818460208901612674565b84519083019061211e818360208901612674565b8451910190612131818360208801612674565b0195945050505050565b600360fc1b815260008251612157816001850160208701612674565b9190910160010192915050565b7f4f7069756d3a000000000000000000000000000000000000000000000000000081526000845161219c816006850160208901612674565b8083019050602d60f81b80600683015285516121bf816007850160208a01612674565b600792019182015283516121da816008840160208801612674565b0160080195945050505050565b7f4f5049554d00000000000000000000000000000000000000000000000000000081526000605f60f81b806005840152855161222a816006860160208a01612674565b80840190508160068201528551612248816007840160208a01612674565b0160078101919091528351906121da826008830160208801612674565b6020815260008251806020840152612284816040850160208701612674565b601f01601f19169190910160400192915050565b60208082528251606083830152805160808401528082015160a0840152604081015160c08085015280516101408501819052600093929183019084906101608701905b808310156122fb57835182529285019260019290920191908501906122db565b5060608401516001600160a01b0390811660e089015260808501518082166101008a015260a090950151908116610120890152939250938701519361234360408801866120a7565b60408801516060880152809550505050505092915050565b60405160c0810167ffffffffffffffff8111828210171561237e5761237e61275c565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156123ad576123ad61275c565b604052919050565b6000808212826001600160ff1b03038413811516156123d6576123d6612704565b600160ff1b83900384128116156123ef576123ef612704565b50500190565b6000821982111561240857612408612704565b500190565b600063ffffffff8083168185168083038211156120ef576120ef612704565b60008261243b5761243b61271a565b600160ff1b82146000198414161561245557612455612704565b500590565b6000826124695761246961271a565b500490565b60006001600160ff1b0360008413600084138583048511828216161561249657612496612704565b600160ff1b60008712828116878305891216156124b5576124b5612704565b600087129250878205871284841616156124d1576124d1612704565b878505871281841616156124e7576124e7612704565b505050929093029392505050565b600063ffffffff8083168185168183048111821515161561251857612518612704565b02949350505050565b60008083128015600160ff1b85018412161561253f5761253f612704565b836001600160ff1b0301831381161561255a5761255a612704565b50500390565b60008282101561257257612572612704565b500390565b600060c0823603121561258957600080fd5b61259161235b565b8235815260208084013581830152604084013567ffffffffffffffff808211156125ba57600080fd5b9085019036601f8301126125cd57600080fd5b8135818111156125df576125df61275c565b8060051b91506125f0848301612384565b81815284810190848601368587018801111561260b57600080fd5b600095505b8386101561262e578035835260019590950194918601918601612610565b5080604088015250505050505061264760608401611e65565b606082015261265860808401611e65565b608082015261266960a08401611e65565b60a082015292915050565b60005b8381101561268f578181015183820152602001612677565b838111156108765750506000910152565b600181811c908216806126b457607f821691505b602082108114156116b457634e487b7160e01b600052602260045260246000fd5b60006000198214156126e9576126e9612704565b5060010190565b6000826126ff576126ff61271a565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fdfea2646970667358221220d013804a35b6569a79e1c51da50e3c7627c6c41797383926a7a7f6e21d13efe864736f6c63430008050033a26469706673582212208c263834c46e17e36e9f84ff59097b8743d41380defaddedaec80da87e983b6864736f6c63430008050033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100885760003560e01c80639873dba91161005b5780639873dba9146100f5578063a91ee0dc14610108578063c4d66de81461011b578063f6b911bc1461012e57600080fd5b80630cbcae701461008d57806347704dbd146100b65780635ab1bd53146100cb5780636ade6d19146100e2575b600080fd5b6033546001600160a01b03165b6040516001600160a01b03909116815260200160405180910390f35b6100c96100c4366004610d7b565b610141565b005b6000546201000090046001600160a01b031661009a565b6100c96100f0366004610ddf565b6102dc565b6100c9610103366004610e71565b610471565b6100c9610116366004610d3a565b610756565b6100c9610129366004610d3a565b610869565b6100c961013c366004610e30565b61098d565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b15801561018f57600080fd5b505afa1580156101a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c79190610d5e565b6001600160a01b0316336001600160a01b0316146102115760405162461bcd60e51b8152602060048201526002602482015261463160f01b60448201526064015b60405180910390fd5b6040516340c10f1960e01b81526001600160a01b038681166004830152602482018390528416906340c10f1990604401600060405180830381600087803b15801561025b57600080fd5b505af115801561026f573d6000803e3d6000fd5b50506040516340c10f1960e01b81526001600160a01b03878116600483015260248201859052851692506340c10f199150604401600060405180830381600087803b1580156102bd57600080fd5b505af11580156102d1573d6000803e3d6000fd5b505050505050505050565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b15801561032a57600080fd5b505afa15801561033e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103629190610d5e565b6001600160a01b0316336001600160a01b0316146103a75760405162461bcd60e51b8152602060048201526002602482015261463160f01b6044820152606401610208565b604051632770a7eb60e21b81526001600160a01b03858116600483015260248201839052841690639dc29fac90604401600060405180830381600087803b1580156103f157600080fd5b505af1158015610405573d6000803e3d6000fd5b5050604051632770a7eb60e21b81526001600160a01b0387811660048301526024820185905285169250639dc29fac9150604401600060405180830381600087803b15801561045357600080fd5b505af1158015610467573d6000803e3d6000fd5b5050505050505050565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b1580156104bf57600080fd5b505afa1580156104d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f79190610d5e565b6001600160a01b0316336001600160a01b03161461053c5760405162461bcd60e51b8152602060048201526002602482015261463160f01b6044820152606401610208565b6033546000906105599084906001906001600160a01b0316610ab6565b60335490915060009061057890859083906001600160a01b0316610ab6565b6040516372d6d1b960e01b81529091506001600160a01b038316906372d6d1b9906105ac9087906001908890600401610fa6565b600060405180830381600087803b1580156105c657600080fd5b505af11580156105da573d6000803e3d6000fd5b50506040516372d6d1b960e01b81526001600160a01b03841692506372d6d1b9915061060f9087906000908890600401610fa6565b600060405180830381600087803b15801561062957600080fd5b505af115801561063d573d6000803e3d6000fd5b50505050806001600160a01b0316826001600160a01b0316857facda084bb7d7816e4761589dd38d696b720ae5609d71839a5cf8c40f9f6b3db360405160405180910390a4841561074d576040516340c10f1960e01b81526001600160a01b038881166004830152602482018790528316906340c10f1990604401600060405180830381600087803b1580156106d257600080fd5b505af11580156106e6573d6000803e3d6000fd5b50506040516340c10f1960e01b81526001600160a01b03898116600483015260248201899052841692506340c10f199150604401600060405180830381600087803b15801561073457600080fd5b505af1158015610748573d6000803e3d6000fd5b505050505b50505050505050565b600054604051634048d90960e01b8152336004820152620100009091046001600160a01b031690634048d9099060240160206040518083038186803b15801561079e57600080fd5b505afa1580156107b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107d69190610eee565b6108075760405162461bcd60e51b81526020600482015260026024820152614d3160f01b6044820152606401610208565b6000805475ffffffffffffffffffffffffffffffffffffffff00001916620100006001600160a01b038416908102919091178255604051909133917fec10a16af385903532506d1567380fd8d93d880e8ed4bcacc42b0848e781406a9190a350565b600054610100900460ff166108845760005460ff1615610888565b303b155b6108eb5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610208565b600054610100900460ff1615801561090d576000805461ffff19166101011790555b61091682610b35565b60405161092290610d1d565b604051809103906000f08015801561093e573d6000803e3d6000fd5b50603380547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03929092169190911790558015610989576000805461ff00191690555b5050565b600060029054906101000a90046001600160a01b03166001600160a01b031663da4fbe526040518163ffffffff1660e01b815260040160206040518083038186803b1580156109db57600080fd5b505afa1580156109ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a139190610d5e565b6001600160a01b0316336001600160a01b031614610a585760405162461bcd60e51b8152602060048201526002602482015261463160f01b6044820152606401610208565b604051632770a7eb60e21b81526001600160a01b03848116600483015260248201839052831690639dc29fac90604401600060405180830381600087803b158015610aa257600080fd5b505af115801561074d573d6000803e3d6000fd5b6000808484610ade57604051806040016040528060018152602001605360f81b815250610af9565b604051806040016040528060018152602001601360fa1b8152505b604051602001610b0a929190610f5f565b604051602081830303815290604052805190602001209050610b2c8382610c60565b95945050505050565b600054610100900460ff16610b505760005460ff1615610b54565b303b155b610bb75760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610208565b600054610100900460ff16158015610bd9576000805461ffff19166101011790555b6001600160a01b038216610bec57600080fd5b6000805475ffffffffffffffffffffffffffffffffffffffff00001916620100006001600160a01b038516908102919091178255604051909133917fec10a16af385903532506d1567380fd8d93d880e8ed4bcacc42b0848e781406a9190a38015610989576000805461ff00191690555050565b60006040517f3d602d80600a3d3981f3363d3d373d3d3d363d7300000000000000000000000081528360601b60148201527f5af43d82803e903d91602b57fd5bf300000000000000000000000000000000006028820152826037826000f59150506001600160a01b038116610d175760405162461bcd60e51b815260206004820152601760248201527f455243313136373a2063726561746532206661696c65640000000000000000006044820152606401610208565b92915050565b6127c8806110b883390190565b8035610d358161109f565b919050565b600060208284031215610d4c57600080fd5b8135610d578161109f565b9392505050565b600060208284031215610d7057600080fd5b8151610d578161109f565b600080600080600060a08688031215610d9357600080fd5b8535610d9e8161109f565b94506020860135610dae8161109f565b93506040860135610dbe8161109f565b92506060860135610dce8161109f565b949793965091946080013592915050565b60008060008060808587031215610df557600080fd5b8435610e008161109f565b93506020850135610e108161109f565b92506040850135610e208161109f565b9396929550929360600135925050565b600080600060608486031215610e4557600080fd5b8335610e508161109f565b92506020840135610e608161109f565b929592945050506040919091013590565b600080600080600060a08688031215610e8957600080fd5b8535610e948161109f565b94506020860135610ea48161109f565b93506040860135925060608601359150608086013567ffffffffffffffff811115610ece57600080fd5b860160c08189031215610ee057600080fd5b809150509295509295909350565b600060208284031215610f0057600080fd5b81518015158114610d5757600080fd5b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115610f4257600080fd5b8260051b8083602087013760009401602001938452509192915050565b8281526000825160005b81811015610f8557602081860181015185830182015201610f69565b81811115610f97576000602083860101525b50919091016020019392505050565b838152600060028410610fc957634e487b7160e01b600052602160045260246000fd5b8360208301526060604083015282356060830152602083013560808301526040830135601e19843603018112610ffe57600080fd5b8301803567ffffffffffffffff81111561101757600080fd5b8060051b360385131561102957600080fd5b60c060a085015261104261012085018260208501610f10565b91505061105160608501610d2a565b6001600160a01b031660c084015261106b60808501610d2a565b6001600160a01b031660e084015261108560a08501610d2a565b6001600160a01b0381166101008501525095945050505050565b6001600160a01b03811681146110b457600080fd5b5056fe608060405234801561001057600080fd5b506127a8806100206000396000f3fe608060405234801561001057600080fd5b50600436106101515760003560e01c806372d6d1b9116100cd578063a9059cbb11610081578063ce21286d11610066578063ce21286d146102a6578063d505accf146102bb578063dd62ed3e146102ce57600080fd5b8063a9059cbb14610278578063a9c2e36c1461028b57600080fd5b806395d89b41116100b257806395d89b411461024a5780639dc29fac14610252578063a457c2d71461026557600080fd5b806372d6d1b9146102245780637ecebe001461023757600080fd5b8063313ce56711610124578063395093511161010957806339509351146101d357806340c10f19146101e657806370a08231146101fb57600080fd5b8063313ce567146101bc5780633644e515146101cb57600080fd5b806306fdde0314610156578063095ea7b31461017457806318160ddd1461019757806323b872dd146101a9575b600080fd5b61015e610307565b60405161016b9190612265565b60405180910390f35b610187610182366004611f85565b610496565b604051901515815260200161016b565b6035545b60405190815260200161016b565b6101876101b7366004611ed6565b6104ac565b6040516012815260200161016b565b61019b610570565b6101876101e1366004611f85565b61057f565b6101f96101f4366004611f85565b6105bb565b005b61019b610209366004611e81565b6001600160a01b031660009081526033602052604090205490565b6101f9610232366004611faf565b610608565b61019b610245366004611e81565b61087c565b61015e61089c565b6101f9610260366004611f85565b6109dc565b610187610273366004611f85565b610a25565b610187610286366004611f85565b610ad6565b60cc546040516001600160a01b03909116815260200161016b565b6102ae610ae3565b60405161016b9190612298565b6101f96102c9366004611f12565b610c1b565b61019b6102dc366004611ea3565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b60d254604080516307ac921760e31b815290516060926000926001600160a01b0390911691633d6490b8916004808201928692909190829003018186803b15801561035157600080fd5b505afa158015610365573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261038d9190810190612013565b9050600061039f60cd60070154610d61565b60ce549091506000906103b190610e6f565b905060008184846040516020016103ca93929190612164565b60408051601f19818403018152919052905080600160d35460ff1660018111156103f6576103f6612730565b14610436576040518060400160405280600681526020017f2d53484f5254000000000000000000000000000000000000000000000000000081525061046d565b6040518060400160405280600581526020017f2d4c4f4e470000000000000000000000000000000000000000000000000000008152505b60405160200161047e9291906120c9565b60405160208183030381529060405294505050505090565b60006104a3338484610f37565b50600192915050565b60006104b984848461105c565b6001600160a01b0384166000908152603460209081526040808320338452909152902054828110156105585760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206160448201527f6c6c6f77616e636500000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b6105658533858403610f37565b506001949350505050565b600061057a611259565b905090565b3360008181526034602090815260408083206001600160a01b038716845290915281205490916104a39185906105b69086906123f5565b610f37565b60cc546001600160a01b031633146105fa5760405162461bcd60e51b8152602060048201526002602482015261503160f01b604482015260640161054f565b61060482826112d4565b5050565b600054610100900460ff166106235760005460ff1615610627565b303b155b6106995760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a6564000000000000000000000000000000000000606482015260840161054f565b600054610100900460ff161580156106bb576000805461ffff19166101011790555b6106e360405180602001604052806000815250604051806020016040528060008152506113b3565b61073b6040518060400160405280601481526020017f4f7069756d20506f736974696f6e20546f6b656e000000000000000000000000815250604051806040016040528060018152602001603160f81b815250611430565b610753604051806020016040528060008152506114b5565b60cc805473ffffffffffffffffffffffffffffffffffffffff19163317905560408051606081019091528061078784612577565b815260200184600181111561079e5761079e612730565b815260209081018690528151805160cd9081558183015160ce5560408201518051919384926107d19260cf920190611d92565b50606082015160038201805473ffffffffffffffffffffffffffffffffffffffff199081166001600160a01b03938416179091556080840151600484018054831691841691909117905560a090930151600590920180549093169116179055602082015160068201805460ff19166001838181111561085257610852612730565b0217905550604082015181600701559050508015610876576000805461ff00191690555b50505050565b6001600160a01b0381166000908152609960205260408120545b92915050565b60d254604080516307ac921760e31b815290516060926000926001600160a01b0390911691633d6490b8916004808201928692909190829003018186803b1580156108e657600080fd5b505afa1580156108fa573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526109229190810190612013565b9050600061093460cd60070154610d61565b60ce5490915060009061094690610e6f565b9050600081848460405160200161095f939291906121e7565b60408051601f19818403018152919052905080600160d35460ff16600181111561098b5761098b612730565b146109b057604051806040016040528060028152602001615f5360f01b81525061046d565b6040518060400160405280600281526020016117d360f21b81525060405160200161047e9291906120c9565b60cc546001600160a01b03163314610a1b5760405162461bcd60e51b8152602060048201526002602482015261503160f01b604482015260640161054f565b6106048282611547565b3360009081526034602090815260408083206001600160a01b038616845290915281205482811015610abf5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f000000000000000000000000000000000000000000000000000000606482015260840161054f565b610acc3385858403610f37565b5060019392505050565b60006104a333848461105c565b6040805161012081018252600060608083018281526080840183905260a084019190915260c0830182905260e08301829052610100830182905282526020820181905291810191909152604080516101208101825260cd80546060830190815260ce54608084015260cf80548551602082810282018101909752818152949593948694869360a08701939091830182828015610b9e57602002820191906000526020600020905b815481526020019060010190808311610b8a575b505050918352505060038201546001600160a01b0390811660208084019190915260048401548216604084015260059093015416606090910152908252600683015491019060ff166001811115610bf757610bf7612730565b6001811115610c0857610c08612730565b8152602001600782015481525050905090565b83421115610c6b5760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015260640161054f565b6000609a54888888610c7c8c611692565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000610cd7826116ba565b90506000610ce782878787611708565b9050896001600160a01b0316816001600160a01b031614610d4a5760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015260640161054f565b610d558a8a8a610f37565b50505050505050505050565b6060600f60f81b600483811c91909116600f60f01b600885901c161783821b7f0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f00167e0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f85161760101c1790610ddc60e083901c630606060661240d565b63ffffffff16901c630f0f0f0f166007610df691906124f5565b610e0860e083901c633030303061240d565b610e12919061240d565b60e01b604051602001610e58919061060f60f31b81527fffffffff0000000000000000000000000000000000000000000000000000000091909116600282015260060190565b604051602081830303815290604052915050919050565b60606000806000610e7f85611730565b925092509250610e8e83611756565b600a8310610ea457610e9f83611756565b610ecd565b610ead83611756565b604051602001610ebd919061213b565b6040516020818303038152906040525b600a8310610ee357610ede83611756565b610f0c565b610eec83611756565b604051602001610efc919061213b565b6040516020818303038152906040525b604051602001610f1e939291906120f8565b6040516020818303038152906040529350505050919050565b6001600160a01b038316610f995760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161054f565b6001600160a01b038216610ffa5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161054f565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b0383166110d85760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f6472657373000000000000000000000000000000000000000000000000000000606482015260840161054f565b6001600160a01b03821661113a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161054f565b6001600160a01b038316600090815260336020526040902054818110156111c95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e63650000000000000000000000000000000000000000000000000000606482015260840161054f565b6001600160a01b038085166000908152603360205260408082208585039055918516815290812080548492906112009084906123f5565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161124c91815260200190565b60405180910390a3610876565b600061057a7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f61128860655490565b6066546040805160208101859052908101839052606081018290524660808201523060a082015260009060c0016040516020818303038152906040528051906020012090509392505050565b6001600160a01b03821661132a5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161054f565b806035600082825461133c91906123f5565b90915550506001600160a01b038216600090815260336020526040812080548392906113699084906123f5565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b600054610100900460ff1661141e5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b611426611874565b61060482826118e1565b600054610100900460ff1661149b5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b815160209283012081519190920120606591909155606655565b600054610100900460ff166115205760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b507f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9609a55565b6001600160a01b0382166115a75760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161054f565b6001600160a01b0382166000908152603360205260409020548181101561161b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161054f565b6001600160a01b038316600090815260336020526040812083830390556035805484929061164a908490612560565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200161104f565b505050565b6001600160a01b03811660009081526099602052604090208054600181018255905b50919050565b60006108966116c7611259565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b600080600061171987878787611973565b9150915061172681611a60565b5095945050505050565b60008080611749611744620151808661245a565b611c1e565b9196909550909350915050565b60608161177a5750506040805180820190915260018152600360fc1b602082015290565b8160005b81156117a4578061178e816126d5565b915061179d9050600a8361245a565b915061177e565b60008167ffffffffffffffff8111156117bf576117bf61275c565b6040519080825280601f01601f1916602001820160405280156117e9576020820181803683370190505b5090505b841561186c576117fe600183612560565b915061180b600a866126f0565b6118169060306123f5565b60f81b81838151811061182b5761182b612746565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350611865600a8661245a565b94506117ed565b949350505050565b600054610100900460ff166118df5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b565b600054610100900460ff1661194c5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161054f565b815161195f906036906020850190611ddd565b50805161168d906037906020840190611ddd565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156119aa5750600090506003611a57565b8460ff16601b141580156119c257508460ff16601c14155b156119d35750600090506004611a57565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611a27573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611a5057600060019250925050611a57565b9150600090505b94509492505050565b6000816004811115611a7457611a74612730565b1415611a7d5750565b6001816004811115611a9157611a91612730565b1415611adf5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161054f565b6002816004811115611af357611af3612730565b1415611b415760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161054f565b6003816004811115611b5557611b55612730565b1415611bae5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b606482015260840161054f565b6004816004811115611bc257611bc2612730565b1415611c1b5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b606482015260840161054f565b50565b60008080838162253d8c611c358362010bd96123b5565b611c3f91906123b5565b9050600062023ab1611c5283600461246e565b611c5c919061242c565b90506004611c6d8262023ab161246e565b611c789060036123b5565b611c82919061242c565b611c8c9083612521565b9150600062164b09611c9f8460016123b5565b611cab90610fa061246e565b611cb5919061242c565b90506004611cc5826105b561246e565b611ccf919061242c565b611cd99084612521565b611ce490601f6123b5565b9250600061098f611cf685605061246e565b611d00919061242c565b905060006050611d128361098f61246e565b611d1c919061242c565b611d269086612521565b9050611d33600b8361242c565b9450611d4085600c61246e565b611d4b8360026123b5565b611d559190612521565b91508483611d64603187612521565b611d6f90606461246e565b611d7991906123b5565b611d8391906123b5565b9a919950975095505050505050565b828054828255906000526020600020908101928215611dcd579160200282015b82811115611dcd578251825591602001919060010190611db2565b50611dd9929150611e50565b5090565b828054611de9906126a0565b90600052602060002090601f016020900481019282611e0b5760008555611dcd565b82601f10611e2457805160ff1916838001178555611dcd565b82800160010185558215611dcd5791820182811115611dcd578251825591602001919060010190611db2565b5b80821115611dd95760008155600101611e51565b80356001600160a01b0381168114611e7c57600080fd5b919050565b600060208284031215611e9357600080fd5b611e9c82611e65565b9392505050565b60008060408385031215611eb657600080fd5b611ebf83611e65565b9150611ecd60208401611e65565b90509250929050565b600080600060608486031215611eeb57600080fd5b611ef484611e65565b9250611f0260208501611e65565b9150604084013590509250925092565b600080600080600080600060e0888a031215611f2d57600080fd5b611f3688611e65565b9650611f4460208901611e65565b95506040880135945060608801359350608088013560ff81168114611f6857600080fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215611f9857600080fd5b611fa183611e65565b946020939093013593505050565b600080600060608486031215611fc457600080fd5b83359250602084013560028110611fda57600080fd5b9150604084013567ffffffffffffffff811115611ff657600080fd5b840160c0818703121561200857600080fd5b809150509250925092565b60006020828403121561202557600080fd5b815167ffffffffffffffff8082111561203d57600080fd5b818401915084601f83011261205157600080fd5b8151818111156120635761206361275c565b612076601f8201601f1916602001612384565b915080825285602082850101111561208d57600080fd5b61209e816020840160208601612674565b50949350505050565b600281106120c557634e487b7160e01b600052602160045260246000fd5b9052565b600083516120db818460208801612674565b8351908301906120ef818360208801612674565b01949350505050565b6000845161210a818460208901612674565b84519083019061211e818360208901612674565b8451910190612131818360208801612674565b0195945050505050565b600360fc1b815260008251612157816001850160208701612674565b9190910160010192915050565b7f4f7069756d3a000000000000000000000000000000000000000000000000000081526000845161219c816006850160208901612674565b8083019050602d60f81b80600683015285516121bf816007850160208a01612674565b600792019182015283516121da816008840160208801612674565b0160080195945050505050565b7f4f5049554d00000000000000000000000000000000000000000000000000000081526000605f60f81b806005840152855161222a816006860160208a01612674565b80840190508160068201528551612248816007840160208a01612674565b0160078101919091528351906121da826008830160208801612674565b6020815260008251806020840152612284816040850160208701612674565b601f01601f19169190910160400192915050565b60208082528251606083830152805160808401528082015160a0840152604081015160c08085015280516101408501819052600093929183019084906101608701905b808310156122fb57835182529285019260019290920191908501906122db565b5060608401516001600160a01b0390811660e089015260808501518082166101008a015260a090950151908116610120890152939250938701519361234360408801866120a7565b60408801516060880152809550505050505092915050565b60405160c0810167ffffffffffffffff8111828210171561237e5761237e61275c565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156123ad576123ad61275c565b604052919050565b6000808212826001600160ff1b03038413811516156123d6576123d6612704565b600160ff1b83900384128116156123ef576123ef612704565b50500190565b6000821982111561240857612408612704565b500190565b600063ffffffff8083168185168083038211156120ef576120ef612704565b60008261243b5761243b61271a565b600160ff1b82146000198414161561245557612455612704565b500590565b6000826124695761246961271a565b500490565b60006001600160ff1b0360008413600084138583048511828216161561249657612496612704565b600160ff1b60008712828116878305891216156124b5576124b5612704565b600087129250878205871284841616156124d1576124d1612704565b878505871281841616156124e7576124e7612704565b505050929093029392505050565b600063ffffffff8083168185168183048111821515161561251857612518612704565b02949350505050565b60008083128015600160ff1b85018412161561253f5761253f612704565b836001600160ff1b0301831381161561255a5761255a612704565b50500390565b60008282101561257257612572612704565b500390565b600060c0823603121561258957600080fd5b61259161235b565b8235815260208084013581830152604084013567ffffffffffffffff808211156125ba57600080fd5b9085019036601f8301126125cd57600080fd5b8135818111156125df576125df61275c565b8060051b91506125f0848301612384565b81815284810190848601368587018801111561260b57600080fd5b600095505b8386101561262e578035835260019590950194918601918601612610565b5080604088015250505050505061264760608401611e65565b606082015261265860808401611e65565b608082015261266960a08401611e65565b60a082015292915050565b60005b8381101561268f578181015183820152602001612677565b838111156108765750506000910152565b600181811c908216806126b457607f821691505b602082108114156116b457634e487b7160e01b600052602260045260246000fd5b60006000198214156126e9576126e9612704565b5060010190565b6000826126ff576126ff61271a565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fdfea2646970667358221220d013804a35b6569a79e1c51da50e3c7627c6c41797383926a7a7f6e21d13efe864736f6c63430008050033a26469706673582212208c263834c46e17e36e9f84ff59097b8743d41380defaddedaec80da87e983b6864736f6c63430008050033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.