ETH Price: $3,076.66 (-2.15%)
Gas: 4 Gwei

Contract

0x211bA925B35b82246a3CCfa3A991a39A840f025C
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Nominate New Own...115141612020-12-24 4:35:221229 days ago1608784522IN
Synthetix: Binary Option Market Factory
0 ETH0.00555875125
0x60806040115133092020-12-24 1:22:351230 days ago1608772955IN
 Create: BinaryOptionMarketFactory
0 ETH1.23388864251

Latest 2 internal transactions

Advanced mode:
Parent Transaction Hash Block From To Value
119844312021-03-06 10:52:111157 days ago1615027931
Synthetix: Binary Option Market Factory
 Contract Creation0 ETH
115705962021-01-01 20:23:111221 days ago1609532591
Synthetix: Binary Option Market Factory
 Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
BinaryOptionMarketFactory

Compiler Version
v0.5.16+commit.9c3226ce

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2020-12-24
*/

/*
   ____            __   __        __   _
  / __/__ __ ___  / /_ / /  ___  / /_ (_)__ __
 _\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ /
/___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\
     /___/

* Synthetix: BinaryOptionMarketFactory.sol
*
* Latest source (may be newer): https://github.com/Synthetixio/synthetix/blob/master/contracts/BinaryOptionMarketFactory.sol
* Docs: https://docs.synthetix.io/contracts/BinaryOptionMarketFactory
*
* Contract Dependencies: 
*	- IAddressResolver
*	- IBinaryOption
*	- IBinaryOptionMarket
*	- IBinaryOptionMarketManager
*	- IERC20
*	- MixinResolver
*	- Owned
*	- Pausable
* Libraries: 
*	- AddressSetLib
*	- SafeDecimalMath
*	- SafeMath
*
* MIT License
* ===========
*
* Copyright (c) 2020 Synthetix
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/



pragma solidity ^0.5.16;


// https://docs.synthetix.io/contracts/source/contracts/owned
contract Owned {
    address public owner;
    address public nominatedOwner;

    constructor(address _owner) public {
        require(_owner != address(0), "Owner address cannot be 0");
        owner = _owner;
        emit OwnerChanged(address(0), _owner);
    }

    function nominateNewOwner(address _owner) external onlyOwner {
        nominatedOwner = _owner;
        emit OwnerNominated(_owner);
    }

    function acceptOwnership() external {
        require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership");
        emit OwnerChanged(owner, nominatedOwner);
        owner = nominatedOwner;
        nominatedOwner = address(0);
    }

    modifier onlyOwner {
        _onlyOwner();
        _;
    }

    function _onlyOwner() private view {
        require(msg.sender == owner, "Only the contract owner may perform this action");
    }

    event OwnerNominated(address newOwner);
    event OwnerChanged(address oldOwner, address newOwner);
}


// https://docs.synthetix.io/contracts/source/interfaces/iaddressresolver
interface IAddressResolver {
    function getAddress(bytes32 name) external view returns (address);

    function getSynth(bytes32 key) external view returns (address);

    function requireAndGetAddress(bytes32 name, string calldata reason) external view returns (address);
}


// https://docs.synthetix.io/contracts/source/interfaces/isynth
interface ISynth {
    // Views
    function currencyKey() external view returns (bytes32);

    function transferableSynths(address account) external view returns (uint);

    // Mutative functions
    function transferAndSettle(address to, uint value) external returns (bool);

    function transferFromAndSettle(
        address from,
        address to,
        uint value
    ) external returns (bool);

    // Restricted: used internally to Synthetix
    function burn(address account, uint amount) external;

    function issue(address account, uint amount) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/iissuer
interface IIssuer {
    // Views
    function anySynthOrSNXRateIsInvalid() external view returns (bool anyRateInvalid);

    function availableCurrencyKeys() external view returns (bytes32[] memory);

    function availableSynthCount() external view returns (uint);

    function availableSynths(uint index) external view returns (ISynth);

    function canBurnSynths(address account) external view returns (bool);

    function collateral(address account) external view returns (uint);

    function collateralisationRatio(address issuer) external view returns (uint);

    function collateralisationRatioAndAnyRatesInvalid(address _issuer)
        external
        view
        returns (uint cratio, bool anyRateIsInvalid);

    function debtBalanceOf(address issuer, bytes32 currencyKey) external view returns (uint debtBalance);

    function issuanceRatio() external view returns (uint);

    function lastIssueEvent(address account) external view returns (uint);

    function maxIssuableSynths(address issuer) external view returns (uint maxIssuable);

    function minimumStakeTime() external view returns (uint);

    function remainingIssuableSynths(address issuer)
        external
        view
        returns (
            uint maxIssuable,
            uint alreadyIssued,
            uint totalSystemDebt
        );

    function synths(bytes32 currencyKey) external view returns (ISynth);

    function getSynths(bytes32[] calldata currencyKeys) external view returns (ISynth[] memory);

    function synthsByAddress(address synthAddress) external view returns (bytes32);

    function totalIssuedSynths(bytes32 currencyKey, bool excludeEtherCollateral) external view returns (uint);

    function transferableSynthetixAndAnyRateIsInvalid(address account, uint balance)
        external
        view
        returns (uint transferable, bool anyRateIsInvalid);

    // Restricted: used internally to Synthetix
    function issueSynths(address from, uint amount) external;

    function issueSynthsOnBehalf(
        address issueFor,
        address from,
        uint amount
    ) external;

    function issueMaxSynths(address from) external;

    function issueMaxSynthsOnBehalf(address issueFor, address from) external;

    function burnSynths(address from, uint amount) external;

    function burnSynthsOnBehalf(
        address burnForAddress,
        address from,
        uint amount
    ) external;

    function burnSynthsToTarget(address from) external;

    function burnSynthsToTargetOnBehalf(address burnForAddress, address from) external;

    function liquidateDelinquentAccount(
        address account,
        uint susdAmount,
        address liquidator
    ) external returns (uint totalRedeemed, uint amountToLiquidate);
}


// Inheritance


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/addressresolver
contract AddressResolver is Owned, IAddressResolver {
    mapping(bytes32 => address) public repository;

    constructor(address _owner) public Owned(_owner) {}

    /* ========== RESTRICTED FUNCTIONS ========== */

    function importAddresses(bytes32[] calldata names, address[] calldata destinations) external onlyOwner {
        require(names.length == destinations.length, "Input lengths must match");

        for (uint i = 0; i < names.length; i++) {
            bytes32 name = names[i];
            address destination = destinations[i];
            repository[name] = destination;
            emit AddressImported(name, destination);
        }
    }

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

    function rebuildCaches(MixinResolver[] calldata destinations) external {
        for (uint i = 0; i < destinations.length; i++) {
            destinations[i].rebuildCache();
        }
    }

    /* ========== VIEWS ========== */

    function areAddressesImported(bytes32[] calldata names, address[] calldata destinations) external view returns (bool) {
        for (uint i = 0; i < names.length; i++) {
            if (repository[names[i]] != destinations[i]) {
                return false;
            }
        }
        return true;
    }

    function getAddress(bytes32 name) external view returns (address) {
        return repository[name];
    }

    function requireAndGetAddress(bytes32 name, string calldata reason) external view returns (address) {
        address _foundAddress = repository[name];
        require(_foundAddress != address(0), reason);
        return _foundAddress;
    }

    function getSynth(bytes32 key) external view returns (address) {
        IIssuer issuer = IIssuer(repository["Issuer"]);
        require(address(issuer) != address(0), "Cannot find Issuer address");
        return address(issuer.synths(key));
    }

    /* ========== EVENTS ========== */

    event AddressImported(bytes32 name, address destination);
}


// solhint-disable payable-fallback

// https://docs.synthetix.io/contracts/source/contracts/readproxy
contract ReadProxy is Owned {
    address public target;

    constructor(address _owner) public Owned(_owner) {}

    function setTarget(address _target) external onlyOwner {
        target = _target;
        emit TargetUpdated(target);
    }

    function() external {
        // The basics of a proxy read call
        // Note that msg.sender in the underlying will always be the address of this contract.
        assembly {
            calldatacopy(0, 0, calldatasize)

            // Use of staticcall - this will revert if the underlying function mutates state
            let result := staticcall(gas, sload(target_slot), 0, calldatasize, 0, 0)
            returndatacopy(0, 0, returndatasize)

            if iszero(result) {
                revert(0, returndatasize)
            }
            return(0, returndatasize)
        }
    }

    event TargetUpdated(address newTarget);
}


// Inheritance


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/mixinresolver
contract MixinResolver {
    AddressResolver public resolver;

    mapping(bytes32 => address) private addressCache;

    constructor(address _resolver) internal {
        resolver = AddressResolver(_resolver);
    }

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

    function combineArrays(bytes32[] memory first, bytes32[] memory second)
        internal
        pure
        returns (bytes32[] memory combination)
    {
        combination = new bytes32[](first.length + second.length);

        for (uint i = 0; i < first.length; i++) {
            combination[i] = first[i];
        }

        for (uint j = 0; j < second.length; j++) {
            combination[first.length + j] = second[j];
        }
    }

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

    // Note: this function is public not external in order for it to be overridden and invoked via super in subclasses
    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {}

    function rebuildCache() public {
        bytes32[] memory requiredAddresses = resolverAddressesRequired();
        // The resolver must call this function whenver it updates its state
        for (uint i = 0; i < requiredAddresses.length; i++) {
            bytes32 name = requiredAddresses[i];
            // Note: can only be invoked once the resolver has all the targets needed added
            address destination = resolver.requireAndGetAddress(
                name,
                string(abi.encodePacked("Resolver missing target: ", name))
            );
            addressCache[name] = destination;
            emit CacheUpdated(name, destination);
        }
    }

    /* ========== VIEWS ========== */

    function isResolverCached() external view returns (bool) {
        bytes32[] memory requiredAddresses = resolverAddressesRequired();
        for (uint i = 0; i < requiredAddresses.length; i++) {
            bytes32 name = requiredAddresses[i];
            // false if our cache is invalid or if the resolver doesn't have the required address
            if (resolver.getAddress(name) != addressCache[name] || addressCache[name] == address(0)) {
                return false;
            }
        }

        return true;
    }

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

    function requireAndGetAddress(bytes32 name) internal view returns (address) {
        address _foundAddress = addressCache[name];
        require(_foundAddress != address(0), string(abi.encodePacked("Missing address: ", name)));
        return _foundAddress;
    }

    /* ========== EVENTS ========== */

    event CacheUpdated(bytes32 name, address destination);
}


// https://docs.synthetix.io/contracts/source/interfaces/ibinaryoptionmarketmanager
interface IBinaryOptionMarketManager {
    /* ========== VIEWS / VARIABLES ========== */

    function fees()
        external
        view
        returns (
            uint poolFee,
            uint creatorFee,
            uint refundFee
        );

    function durations()
        external
        view
        returns (
            uint maxOraclePriceAge,
            uint expiryDuration,
            uint maxTimeToMaturity
        );

    function creatorLimits() external view returns (uint capitalRequirement, uint skewLimit);

    function marketCreationEnabled() external view returns (bool);

    function totalDeposited() external view returns (uint);

    function numActiveMarkets() external view returns (uint);

    function activeMarkets(uint index, uint pageSize) external view returns (address[] memory);

    function numMaturedMarkets() external view returns (uint);

    function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function createMarket(
        bytes32 oracleKey,
        uint strikePrice,
        bool refundsEnabled,
        uint[2] calldata times, // [biddingEnd, maturity]
        uint[2] calldata bids // [longBid, shortBid]
    ) external returns (IBinaryOptionMarket);

    function resolveMarket(address market) external;

    function cancelMarket(address market) external;

    function expireMarkets(address[] calldata market) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/ierc20
interface IERC20 {
    // ERC20 Optional Views
    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);

    // Views
    function totalSupply() external view returns (uint);

    function balanceOf(address owner) external view returns (uint);

    function allowance(address owner, address spender) external view returns (uint);

    // Mutative functions
    function transfer(address to, uint value) external returns (bool);

    function approve(address spender, uint value) external returns (bool);

    function transferFrom(
        address from,
        address to,
        uint value
    ) external returns (bool);

    // Events
    event Transfer(address indexed from, address indexed to, uint value);

    event Approval(address indexed owner, address indexed spender, uint value);
}


// https://docs.synthetix.io/contracts/source/interfaces/ibinaryoption
interface IBinaryOption {
    /* ========== VIEWS / VARIABLES ========== */

    function market() external view returns (IBinaryOptionMarket);

    function bidOf(address account) external view returns (uint);

    function totalBids() external view returns (uint);

    function balanceOf(address account) external view returns (uint);

    function totalSupply() external view returns (uint);

    function claimableBalanceOf(address account) external view returns (uint);

    function totalClaimableSupply() external view returns (uint);
}


// https://docs.synthetix.io/contracts/source/interfaces/ibinaryoptionmarket
interface IBinaryOptionMarket {
    /* ========== TYPES ========== */

    enum Phase {Bidding, Trading, Maturity, Expiry}
    enum Side {Long, Short}

    /* ========== VIEWS / VARIABLES ========== */

    function options() external view returns (IBinaryOption long, IBinaryOption short);

    function prices() external view returns (uint long, uint short);

    function times()
        external
        view
        returns (
            uint biddingEnd,
            uint maturity,
            uint destructino
        );

    function oracleDetails()
        external
        view
        returns (
            bytes32 key,
            uint strikePrice,
            uint finalPrice
        );

    function fees()
        external
        view
        returns (
            uint poolFee,
            uint creatorFee,
            uint refundFee
        );

    function creatorLimits() external view returns (uint capitalRequirement, uint skewLimit);

    function deposited() external view returns (uint);

    function creator() external view returns (address);

    function resolved() external view returns (bool);

    function refundsEnabled() external view returns (bool);

    function phase() external view returns (Phase);

    function oraclePriceAndTimestamp() external view returns (uint price, uint updatedAt);

    function canResolve() external view returns (bool);

    function result() external view returns (Side);

    function pricesAfterBidOrRefund(
        Side side,
        uint value,
        bool refund
    ) external view returns (uint long, uint short);

    function bidOrRefundForPrice(
        Side bidSide,
        Side priceSide,
        uint price,
        bool refund
    ) external view returns (uint);

    function bidsOf(address account) external view returns (uint long, uint short);

    function totalBids() external view returns (uint long, uint short);

    function claimableBalancesOf(address account) external view returns (uint long, uint short);

    function totalClaimableSupplies() external view returns (uint long, uint short);

    function balancesOf(address account) external view returns (uint long, uint short);

    function totalSupplies() external view returns (uint long, uint short);

    function exercisableDeposits() external view returns (uint);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function bid(Side side, uint value) external;

    function refund(Side side, uint value) external returns (uint refundMinusFee);

    function claimOptions() external returns (uint longClaimed, uint shortClaimed);

    function exerciseOptions() external returns (uint);
}


/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, "SafeMath: division by zero");
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, "SafeMath: modulo by zero");
        return a % b;
    }
}


// Libraries


// https://docs.synthetix.io/contracts/source/libraries/safedecimalmath
library SafeDecimalMath {
    using SafeMath for uint;

    /* Number of decimal places in the representations. */
    uint8 public constant decimals = 18;
    uint8 public constant highPrecisionDecimals = 27;

    /* The number representing 1.0. */
    uint public constant UNIT = 10**uint(decimals);

    /* The number representing 1.0 for higher fidelity numbers. */
    uint public constant PRECISE_UNIT = 10**uint(highPrecisionDecimals);
    uint private constant UNIT_TO_HIGH_PRECISION_CONVERSION_FACTOR = 10**uint(highPrecisionDecimals - decimals);

    /**
     * @return Provides an interface to UNIT.
     */
    function unit() external pure returns (uint) {
        return UNIT;
    }

    /**
     * @return Provides an interface to PRECISE_UNIT.
     */
    function preciseUnit() external pure returns (uint) {
        return PRECISE_UNIT;
    }

    /**
     * @return The result of multiplying x and y, interpreting the operands as fixed-point
     * decimals.
     *
     * @dev A unit factor is divided out after the product of x and y is evaluated,
     * so that product must be less than 2**256. As this is an integer division,
     * the internal division always rounds down. This helps save on gas. Rounding
     * is more expensive on gas.
     */
    function multiplyDecimal(uint x, uint y) internal pure returns (uint) {
        /* Divide by UNIT to remove the extra factor introduced by the product. */
        return x.mul(y) / UNIT;
    }

    /**
     * @return The result of safely multiplying x and y, interpreting the operands
     * as fixed-point decimals of the specified precision unit.
     *
     * @dev The operands should be in the form of a the specified unit factor which will be
     * divided out after the product of x and y is evaluated, so that product must be
     * less than 2**256.
     *
     * Unlike multiplyDecimal, this function rounds the result to the nearest increment.
     * Rounding is useful when you need to retain fidelity for small decimal numbers
     * (eg. small fractions or percentages).
     */
    function _multiplyDecimalRound(
        uint x,
        uint y,
        uint precisionUnit
    ) private pure returns (uint) {
        /* Divide by UNIT to remove the extra factor introduced by the product. */
        uint quotientTimesTen = x.mul(y) / (precisionUnit / 10);

        if (quotientTimesTen % 10 >= 5) {
            quotientTimesTen += 10;
        }

        return quotientTimesTen / 10;
    }

    /**
     * @return The result of safely multiplying x and y, interpreting the operands
     * as fixed-point decimals of a precise unit.
     *
     * @dev The operands should be in the precise unit factor which will be
     * divided out after the product of x and y is evaluated, so that product must be
     * less than 2**256.
     *
     * Unlike multiplyDecimal, this function rounds the result to the nearest increment.
     * Rounding is useful when you need to retain fidelity for small decimal numbers
     * (eg. small fractions or percentages).
     */
    function multiplyDecimalRoundPrecise(uint x, uint y) internal pure returns (uint) {
        return _multiplyDecimalRound(x, y, PRECISE_UNIT);
    }

    /**
     * @return The result of safely multiplying x and y, interpreting the operands
     * as fixed-point decimals of a standard unit.
     *
     * @dev The operands should be in the standard unit factor which will be
     * divided out after the product of x and y is evaluated, so that product must be
     * less than 2**256.
     *
     * Unlike multiplyDecimal, this function rounds the result to the nearest increment.
     * Rounding is useful when you need to retain fidelity for small decimal numbers
     * (eg. small fractions or percentages).
     */
    function multiplyDecimalRound(uint x, uint y) internal pure returns (uint) {
        return _multiplyDecimalRound(x, y, UNIT);
    }

    /**
     * @return The result of safely dividing x and y. The return value is a high
     * precision decimal.
     *
     * @dev y is divided after the product of x and the standard precision unit
     * is evaluated, so the product of x and UNIT must be less than 2**256. As
     * this is an integer division, the result is always rounded down.
     * This helps save on gas. Rounding is more expensive on gas.
     */
    function divideDecimal(uint x, uint y) internal pure returns (uint) {
        /* Reintroduce the UNIT factor that will be divided out by y. */
        return x.mul(UNIT).div(y);
    }

    /**
     * @return The result of safely dividing x and y. The return value is as a rounded
     * decimal in the precision unit specified in the parameter.
     *
     * @dev y is divided after the product of x and the specified precision unit
     * is evaluated, so the product of x and the specified precision unit must
     * be less than 2**256. The result is rounded to the nearest increment.
     */
    function _divideDecimalRound(
        uint x,
        uint y,
        uint precisionUnit
    ) private pure returns (uint) {
        uint resultTimesTen = x.mul(precisionUnit * 10).div(y);

        if (resultTimesTen % 10 >= 5) {
            resultTimesTen += 10;
        }

        return resultTimesTen / 10;
    }

    /**
     * @return The result of safely dividing x and y. The return value is as a rounded
     * standard precision decimal.
     *
     * @dev y is divided after the product of x and the standard precision unit
     * is evaluated, so the product of x and the standard precision unit must
     * be less than 2**256. The result is rounded to the nearest increment.
     */
    function divideDecimalRound(uint x, uint y) internal pure returns (uint) {
        return _divideDecimalRound(x, y, UNIT);
    }

    /**
     * @return The result of safely dividing x and y. The return value is as a rounded
     * high precision decimal.
     *
     * @dev y is divided after the product of x and the high precision unit
     * is evaluated, so the product of x and the high precision unit must
     * be less than 2**256. The result is rounded to the nearest increment.
     */
    function divideDecimalRoundPrecise(uint x, uint y) internal pure returns (uint) {
        return _divideDecimalRound(x, y, PRECISE_UNIT);
    }

    /**
     * @dev Convert a standard decimal representation to a high precision one.
     */
    function decimalToPreciseDecimal(uint i) internal pure returns (uint) {
        return i.mul(UNIT_TO_HIGH_PRECISION_CONVERSION_FACTOR);
    }

    /**
     * @dev Convert a high precision decimal to a standard decimal representation.
     */
    function preciseDecimalToDecimal(uint i) internal pure returns (uint) {
        uint quotientTimesTen = i / (UNIT_TO_HIGH_PRECISION_CONVERSION_FACTOR / 10);

        if (quotientTimesTen % 10 >= 5) {
            quotientTimesTen += 10;
        }

        return quotientTimesTen / 10;
    }
}


// Inheritance


// https://docs.synthetix.io/contracts/source/contracts/pausable
contract Pausable is Owned {
    uint public lastPauseTime;
    bool public paused;

    constructor() internal {
        // This contract is abstract, and thus cannot be instantiated directly
        require(owner != address(0), "Owner must be set");
        // Paused will be false, and lastPauseTime will be 0 upon initialisation
    }

    /**
     * @notice Change the paused state of the contract
     * @dev Only the contract owner may call this.
     */
    function setPaused(bool _paused) external onlyOwner {
        // Ensure we're actually changing the state before we do anything
        if (_paused == paused) {
            return;
        }

        // Set our paused state.
        paused = _paused;

        // If applicable, set the last pause time.
        if (paused) {
            lastPauseTime = now;
        }

        // Let everyone know that our pause state has changed.
        emit PauseChanged(paused);
    }

    event PauseChanged(bool isPaused);

    modifier notPaused {
        require(!paused, "This action cannot be performed while the contract is paused");
        _;
    }
}


// https://docs.synthetix.io/contracts/source/libraries/addresssetlib/
library AddressSetLib {
    struct AddressSet {
        address[] elements;
        mapping(address => uint) indices;
    }

    function contains(AddressSet storage set, address candidate) internal view returns (bool) {
        if (set.elements.length == 0) {
            return false;
        }
        uint index = set.indices[candidate];
        return index != 0 || set.elements[0] == candidate;
    }

    function getPage(
        AddressSet storage set,
        uint index,
        uint pageSize
    ) internal view returns (address[] memory) {
        // NOTE: This implementation should be converted to slice operators if the compiler is updated to v0.6.0+
        uint endIndex = index + pageSize; // The check below that endIndex <= index handles overflow.

        // If the page extends past the end of the list, truncate it.
        if (endIndex > set.elements.length) {
            endIndex = set.elements.length;
        }
        if (endIndex <= index) {
            return new address[](0);
        }

        uint n = endIndex - index; // We already checked for negative overflow.
        address[] memory page = new address[](n);
        for (uint i; i < n; i++) {
            page[i] = set.elements[i + index];
        }
        return page;
    }

    function add(AddressSet storage set, address element) internal {
        // Adding to a set is an idempotent operation.
        if (!contains(set, element)) {
            set.indices[element] = set.elements.length;
            set.elements.push(element);
        }
    }

    function remove(AddressSet storage set, address element) internal {
        require(contains(set, element), "Element not in set.");
        // Replace the removed element with the last element of the list.
        uint index = set.indices[element];
        uint lastIndex = set.elements.length - 1; // We required that element is in the list, so it is not empty.
        if (index != lastIndex) {
            // No need to shift the last element if it is the one we want to delete.
            address shiftedElement = set.elements[lastIndex];
            set.elements[index] = shiftedElement;
            set.indices[shiftedElement] = index;
        }
        set.elements.pop();
        delete set.indices[element];
    }
}


// https://docs.synthetix.io/contracts/source/interfaces/iexchangerates
interface IExchangeRates {
    // Structs
    struct RateAndUpdatedTime {
        uint216 rate;
        uint40 time;
    }

    struct InversePricing {
        uint entryPoint;
        uint upperLimit;
        uint lowerLimit;
        bool frozenAtUpperLimit;
        bool frozenAtLowerLimit;
    }

    // Views
    function aggregators(bytes32 currencyKey) external view returns (address);

    function aggregatorWarningFlags() external view returns (address);

    function anyRateIsInvalid(bytes32[] calldata currencyKeys) external view returns (bool);

    function canFreezeRate(bytes32 currencyKey) external view returns (bool);

    function currentRoundForRate(bytes32 currencyKey) external view returns (uint);

    function currenciesUsingAggregator(address aggregator) external view returns (bytes32[] memory);

    function effectiveValue(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey
    ) external view returns (uint value);

    function effectiveValueAndRates(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey
    )
        external
        view
        returns (
            uint value,
            uint sourceRate,
            uint destinationRate
        );

    function effectiveValueAtRound(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        uint roundIdForSrc,
        uint roundIdForDest
    ) external view returns (uint value);

    function getCurrentRoundId(bytes32 currencyKey) external view returns (uint);

    function getLastRoundIdBeforeElapsedSecs(
        bytes32 currencyKey,
        uint startingRoundId,
        uint startingTimestamp,
        uint timediff
    ) external view returns (uint);

    function inversePricing(bytes32 currencyKey)
        external
        view
        returns (
            uint entryPoint,
            uint upperLimit,
            uint lowerLimit,
            bool frozenAtUpperLimit,
            bool frozenAtLowerLimit
        );

    function lastRateUpdateTimes(bytes32 currencyKey) external view returns (uint256);

    function oracle() external view returns (address);

    function rateAndTimestampAtRound(bytes32 currencyKey, uint roundId) external view returns (uint rate, uint time);

    function rateAndUpdatedTime(bytes32 currencyKey) external view returns (uint rate, uint time);

    function rateAndInvalid(bytes32 currencyKey) external view returns (uint rate, bool isInvalid);

    function rateForCurrency(bytes32 currencyKey) external view returns (uint);

    function rateIsFlagged(bytes32 currencyKey) external view returns (bool);

    function rateIsFrozen(bytes32 currencyKey) external view returns (bool);

    function rateIsInvalid(bytes32 currencyKey) external view returns (bool);

    function rateIsStale(bytes32 currencyKey) external view returns (bool);

    function rateStalePeriod() external view returns (uint);

    function ratesAndUpdatedTimeForCurrencyLastNRounds(bytes32 currencyKey, uint numRounds)
        external
        view
        returns (uint[] memory rates, uint[] memory times);

    function ratesAndInvalidForCurrencies(bytes32[] calldata currencyKeys)
        external
        view
        returns (uint[] memory rates, bool anyRateInvalid);

    function ratesForCurrencies(bytes32[] calldata currencyKeys) external view returns (uint[] memory);

    // Mutative functions
    function freezeRate(bytes32 currencyKey) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/isystemstatus
interface ISystemStatus {
    struct Status {
        bool canSuspend;
        bool canResume;
    }

    struct Suspension {
        bool suspended;
        // reason is an integer code,
        // 0 => no reason, 1 => upgrading, 2+ => defined by system usage
        uint248 reason;
    }

    // Views
    function accessControl(bytes32 section, address account) external view returns (bool canSuspend, bool canResume);

    function requireSystemActive() external view;

    function requireIssuanceActive() external view;

    function requireExchangeActive() external view;

    function requireSynthActive(bytes32 currencyKey) external view;

    function requireSynthsActive(bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) external view;

    function synthSuspension(bytes32 currencyKey) external view returns (bool suspended, uint248 reason);

    // Restricted functions
    function suspendSynth(bytes32 currencyKey, uint256 reason) external;

    function updateAccessControl(
        bytes32 section,
        address account,
        bool canSuspend,
        bool canResume
    ) external;
}


// Inheritance


// Libraries


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/binaryoptionmarketmanager
contract BinaryOptionMarketManager is Owned, Pausable, MixinResolver, IBinaryOptionMarketManager {
    /* ========== LIBRARIES ========== */

    using SafeMath for uint;
    using AddressSetLib for AddressSetLib.AddressSet;

    /* ========== TYPES ========== */

    struct Fees {
        uint poolFee;
        uint creatorFee;
        uint refundFee;
    }

    struct Durations {
        uint maxOraclePriceAge;
        uint expiryDuration;
        uint maxTimeToMaturity;
    }

    struct CreatorLimits {
        uint capitalRequirement;
        uint skewLimit;
    }

    /* ========== STATE VARIABLES ========== */

    Fees public fees;
    Durations public durations;
    CreatorLimits public creatorLimits;

    bool public marketCreationEnabled = true;
    uint public totalDeposited;

    AddressSetLib.AddressSet internal _activeMarkets;
    AddressSetLib.AddressSet internal _maturedMarkets;

    BinaryOptionMarketManager internal _migratingManager;

    /* ---------- Address Resolver Configuration ---------- */

    bytes32 internal constant CONTRACT_SYSTEMSTATUS = "SystemStatus";
    bytes32 internal constant CONTRACT_SYNTHSUSD = "SynthsUSD";
    bytes32 internal constant CONTRACT_EXRATES = "ExchangeRates";
    bytes32 internal constant CONTRACT_BINARYOPTIONMARKETFACTORY = "BinaryOptionMarketFactory";

    /* ========== CONSTRUCTOR ========== */

    constructor(
        address _owner,
        address _resolver,
        uint _maxOraclePriceAge,
        uint _expiryDuration,
        uint _maxTimeToMaturity,
        uint _creatorCapitalRequirement,
        uint _creatorSkewLimit,
        uint _poolFee,
        uint _creatorFee,
        uint _refundFee
    ) public Owned(_owner) Pausable() MixinResolver(_resolver) {
        // Temporarily change the owner so that the setters don't revert.
        owner = msg.sender;
        setExpiryDuration(_expiryDuration);
        setMaxOraclePriceAge(_maxOraclePriceAge);
        setMaxTimeToMaturity(_maxTimeToMaturity);
        setCreatorCapitalRequirement(_creatorCapitalRequirement);
        setCreatorSkewLimit(_creatorSkewLimit);
        setPoolFee(_poolFee);
        setCreatorFee(_creatorFee);
        setRefundFee(_refundFee);
        owner = _owner;
    }

    /* ========== VIEWS ========== */

    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
        addresses = new bytes32[](4);
        addresses[0] = CONTRACT_SYSTEMSTATUS;
        addresses[1] = CONTRACT_SYNTHSUSD;
        addresses[2] = CONTRACT_EXRATES;
        addresses[3] = CONTRACT_BINARYOPTIONMARKETFACTORY;
    }

    /* ---------- Related Contracts ---------- */

    function _systemStatus() internal view returns (ISystemStatus) {
        return ISystemStatus(requireAndGetAddress(CONTRACT_SYSTEMSTATUS));
    }

    function _sUSD() internal view returns (IERC20) {
        return IERC20(requireAndGetAddress(CONTRACT_SYNTHSUSD));
    }

    function _exchangeRates() internal view returns (IExchangeRates) {
        return IExchangeRates(requireAndGetAddress(CONTRACT_EXRATES));
    }

    function _factory() internal view returns (BinaryOptionMarketFactory) {
        return BinaryOptionMarketFactory(requireAndGetAddress(CONTRACT_BINARYOPTIONMARKETFACTORY));
    }

    /* ---------- Market Information ---------- */

    function _isKnownMarket(address candidate) internal view returns (bool) {
        return _activeMarkets.contains(candidate) || _maturedMarkets.contains(candidate);
    }

    function numActiveMarkets() external view returns (uint) {
        return _activeMarkets.elements.length;
    }

    function activeMarkets(uint index, uint pageSize) external view returns (address[] memory) {
        return _activeMarkets.getPage(index, pageSize);
    }

    function numMaturedMarkets() external view returns (uint) {
        return _maturedMarkets.elements.length;
    }

    function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory) {
        return _maturedMarkets.getPage(index, pageSize);
    }

    function _isValidKey(bytes32 oracleKey) internal view returns (bool) {
        IExchangeRates exchangeRates = _exchangeRates();

        // If it has a rate, then it's possibly a valid key
        if (exchangeRates.rateForCurrency(oracleKey) != 0) {
            // But not sUSD
            if (oracleKey == "sUSD") {
                return false;
            }

            // and not inverse rates
            (uint entryPoint, , , , ) = exchangeRates.inversePricing(oracleKey);
            if (entryPoint != 0) {
                return false;
            }

            return true;
        }

        return false;
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    /* ---------- Setters ---------- */

    function setMaxOraclePriceAge(uint _maxOraclePriceAge) public onlyOwner {
        durations.maxOraclePriceAge = _maxOraclePriceAge;
        emit MaxOraclePriceAgeUpdated(_maxOraclePriceAge);
    }

    function setExpiryDuration(uint _expiryDuration) public onlyOwner {
        durations.expiryDuration = _expiryDuration;
        emit ExpiryDurationUpdated(_expiryDuration);
    }

    function setMaxTimeToMaturity(uint _maxTimeToMaturity) public onlyOwner {
        durations.maxTimeToMaturity = _maxTimeToMaturity;
        emit MaxTimeToMaturityUpdated(_maxTimeToMaturity);
    }

    function setPoolFee(uint _poolFee) public onlyOwner {
        uint totalFee = _poolFee + fees.creatorFee;
        require(totalFee < SafeDecimalMath.unit(), "Total fee must be less than 100%.");
        require(0 < totalFee, "Total fee must be nonzero.");
        fees.poolFee = _poolFee;
        emit PoolFeeUpdated(_poolFee);
    }

    function setCreatorFee(uint _creatorFee) public onlyOwner {
        uint totalFee = _creatorFee + fees.poolFee;
        require(totalFee < SafeDecimalMath.unit(), "Total fee must be less than 100%.");
        require(0 < totalFee, "Total fee must be nonzero.");
        fees.creatorFee = _creatorFee;
        emit CreatorFeeUpdated(_creatorFee);
    }

    function setRefundFee(uint _refundFee) public onlyOwner {
        require(_refundFee <= SafeDecimalMath.unit(), "Refund fee must be no greater than 100%.");
        fees.refundFee = _refundFee;
        emit RefundFeeUpdated(_refundFee);
    }

    function setCreatorCapitalRequirement(uint _creatorCapitalRequirement) public onlyOwner {
        creatorLimits.capitalRequirement = _creatorCapitalRequirement;
        emit CreatorCapitalRequirementUpdated(_creatorCapitalRequirement);
    }

    function setCreatorSkewLimit(uint _creatorSkewLimit) public onlyOwner {
        require(_creatorSkewLimit <= SafeDecimalMath.unit(), "Creator skew limit must be no greater than 1.");
        creatorLimits.skewLimit = _creatorSkewLimit;
        emit CreatorSkewLimitUpdated(_creatorSkewLimit);
    }

    /* ---------- Deposit Management ---------- */

    function incrementTotalDeposited(uint delta) external onlyActiveMarkets notPaused {
        _systemStatus().requireSystemActive();
        totalDeposited = totalDeposited.add(delta);
    }

    function decrementTotalDeposited(uint delta) external onlyKnownMarkets notPaused {
        _systemStatus().requireSystemActive();
        // NOTE: As individual market debt is not tracked here, the underlying markets
        //       need to be careful never to subtract more debt than they added.
        //       This can't be enforced without additional state/communication overhead.
        totalDeposited = totalDeposited.sub(delta);
    }

    /* ---------- Market Lifecycle ---------- */

    function createMarket(
        bytes32 oracleKey,
        uint strikePrice,
        bool refundsEnabled,
        uint[2] calldata times, // [biddingEnd, maturity]
        uint[2] calldata bids // [longBid, shortBid]
    )
        external
        notPaused
        returns (
            IBinaryOptionMarket // no support for returning BinaryOptionMarket polymorphically given the interface
        )
    {
        _systemStatus().requireSystemActive();
        require(marketCreationEnabled, "Market creation is disabled");
        require(_isValidKey(oracleKey), "Invalid key");

        (uint biddingEnd, uint maturity) = (times[0], times[1]);
        require(maturity <= now + durations.maxTimeToMaturity, "Maturity too far in the future");
        uint expiry = maturity.add(durations.expiryDuration);

        uint initialDeposit = bids[0].add(bids[1]);
        require(now < biddingEnd, "End of bidding has passed");
        require(biddingEnd < maturity, "Maturity predates end of bidding");
        // We also require maturity < expiry. But there is no need to check this.
        // Fees being in range are checked in the setters.
        // The market itself validates the capital and skew requirements.

        BinaryOptionMarket market = _factory().createMarket(
            msg.sender,
            [creatorLimits.capitalRequirement, creatorLimits.skewLimit],
            oracleKey,
            strikePrice,
            refundsEnabled,
            [biddingEnd, maturity, expiry],
            bids,
            [fees.poolFee, fees.creatorFee, fees.refundFee]
        );
        market.rebuildCache();
        _activeMarkets.add(address(market));

        // The debt can't be incremented in the new market's constructor because until construction is complete,
        // the manager doesn't know its address in order to grant it permission.
        totalDeposited = totalDeposited.add(initialDeposit);
        _sUSD().transferFrom(msg.sender, address(market), initialDeposit);

        emit MarketCreated(address(market), msg.sender, oracleKey, strikePrice, biddingEnd, maturity, expiry);
        return market;
    }

    function resolveMarket(address market) external {
        require(_activeMarkets.contains(market), "Not an active market");
        BinaryOptionMarket(market).resolve();
        _activeMarkets.remove(market);
        _maturedMarkets.add(market);
    }

    function cancelMarket(address market) external notPaused {
        require(_activeMarkets.contains(market), "Not an active market");
        address creator = BinaryOptionMarket(market).creator();
        require(msg.sender == creator, "Sender not market creator");
        BinaryOptionMarket(market).cancel(msg.sender);
        _activeMarkets.remove(market);
        emit MarketCancelled(market);
    }

    function expireMarkets(address[] calldata markets) external notPaused {
        for (uint i = 0; i < markets.length; i++) {
            address market = markets[i];

            // The market itself handles decrementing the total deposits.
            BinaryOptionMarket(market).expire(msg.sender);
            // Note that we required that the market is known, which guarantees
            // its index is defined and that the list of markets is not empty.
            _maturedMarkets.remove(market);
            emit MarketExpired(market);
        }
    }

    /* ---------- Upgrade and Administration ---------- */

    function rebuildMarketCaches(BinaryOptionMarket[] calldata marketsToSync) external {
        for (uint i = 0; i < marketsToSync.length; i++) {
            address market = address(marketsToSync[i]);

            // solhint-disable avoid-low-level-calls
            bytes memory payload = abi.encodeWithSignature("rebuildCache()");
            (bool success, ) = market.call(payload);

            if (!success) {
                // handle legacy markets that used an old cache rebuilding logic
                bytes memory payloadForLegacyCache = abi.encodeWithSignature(
                    "setResolverAndSyncCache(address)",
                    address(resolver)
                );

                // solhint-disable avoid-low-level-calls
                (bool legacySuccess, ) = market.call(payloadForLegacyCache);
                require(legacySuccess, "Cannot rebuild cache for market");
            }
        }
    }

    function setMarketCreationEnabled(bool enabled) public onlyOwner {
        if (enabled != marketCreationEnabled) {
            marketCreationEnabled = enabled;
            emit MarketCreationEnabledUpdated(enabled);
        }
    }

    function setMigratingManager(BinaryOptionMarketManager manager) public onlyOwner {
        _migratingManager = manager;
    }

    function migrateMarkets(
        BinaryOptionMarketManager receivingManager,
        bool active,
        BinaryOptionMarket[] calldata marketsToMigrate
    ) external onlyOwner {
        uint _numMarkets = marketsToMigrate.length;
        if (_numMarkets == 0) {
            return;
        }
        AddressSetLib.AddressSet storage markets = active ? _activeMarkets : _maturedMarkets;

        uint runningDepositTotal;
        for (uint i; i < _numMarkets; i++) {
            BinaryOptionMarket market = marketsToMigrate[i];
            require(_isKnownMarket(address(market)), "Market unknown.");

            // Remove it from our list and deposit total.
            markets.remove(address(market));
            runningDepositTotal = runningDepositTotal.add(market.deposited());

            // Prepare to transfer ownership to the new manager.
            market.nominateNewOwner(address(receivingManager));
        }
        // Deduct the total deposits of the migrated markets.
        totalDeposited = totalDeposited.sub(runningDepositTotal);
        emit MarketsMigrated(receivingManager, marketsToMigrate);

        // Now actually transfer the markets over to the new manager.
        receivingManager.receiveMarkets(active, marketsToMigrate);
    }

    function receiveMarkets(bool active, BinaryOptionMarket[] calldata marketsToReceive) external {
        require(msg.sender == address(_migratingManager), "Only permitted for migrating manager.");

        uint _numMarkets = marketsToReceive.length;
        if (_numMarkets == 0) {
            return;
        }
        AddressSetLib.AddressSet storage markets = active ? _activeMarkets : _maturedMarkets;

        uint runningDepositTotal;
        for (uint i; i < _numMarkets; i++) {
            BinaryOptionMarket market = marketsToReceive[i];
            require(!_isKnownMarket(address(market)), "Market already known.");

            market.acceptOwnership();
            markets.add(address(market));
            // Update the market with the new manager address,
            runningDepositTotal = runningDepositTotal.add(market.deposited());
        }
        totalDeposited = totalDeposited.add(runningDepositTotal);
        emit MarketsReceived(_migratingManager, marketsToReceive);
    }

    /* ========== MODIFIERS ========== */

    modifier onlyActiveMarkets() {
        require(_activeMarkets.contains(msg.sender), "Permitted only for active markets.");
        _;
    }

    modifier onlyKnownMarkets() {
        require(_isKnownMarket(msg.sender), "Permitted only for known markets.");
        _;
    }

    /* ========== EVENTS ========== */

    event MarketCreated(
        address market,
        address indexed creator,
        bytes32 indexed oracleKey,
        uint strikePrice,
        uint biddingEndDate,
        uint maturityDate,
        uint expiryDate
    );
    event MarketExpired(address market);
    event MarketCancelled(address market);
    event MarketsMigrated(BinaryOptionMarketManager receivingManager, BinaryOptionMarket[] markets);
    event MarketsReceived(BinaryOptionMarketManager migratingManager, BinaryOptionMarket[] markets);
    event MarketCreationEnabledUpdated(bool enabled);
    event MaxOraclePriceAgeUpdated(uint duration);
    event ExerciseDurationUpdated(uint duration);
    event ExpiryDurationUpdated(uint duration);
    event MaxTimeToMaturityUpdated(uint duration);
    event CreatorCapitalRequirementUpdated(uint value);
    event CreatorSkewLimitUpdated(uint value);
    event PoolFeeUpdated(uint fee);
    event CreatorFeeUpdated(uint fee);
    event RefundFeeUpdated(uint fee);
}


// Inheritance


// Libraries


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/binaryoption
contract BinaryOption is IERC20, IBinaryOption {
    /* ========== LIBRARIES ========== */

    using SafeMath for uint;
    using SafeDecimalMath for uint;

    /* ========== STATE VARIABLES ========== */

    string public constant name = "SNX Binary Option";
    string public constant symbol = "sOPT";
    uint8 public constant decimals = 18;

    BinaryOptionMarket public market;

    mapping(address => uint) public bidOf;
    uint public totalBids;

    mapping(address => uint) public balanceOf;
    uint public totalSupply;

    // The argument order is allowance[owner][spender]
    mapping(address => mapping(address => uint)) public allowance;

    // Enforce a 1 cent minimum bid balance
    uint internal constant _MINIMUM_BID = 1e16;

    /* ========== CONSTRUCTOR ========== */

    constructor(address initialBidder, uint initialBid) public {
        market = BinaryOptionMarket(msg.sender);
        bidOf[initialBidder] = initialBid;
        totalBids = initialBid;
    }

    /* ========== VIEWS ========== */

    function _claimableBalanceOf(
        uint _bid,
        uint price,
        uint exercisableDeposits
    ) internal view returns (uint) {
        uint owed = _bid.divideDecimal(price);
        uint supply = _totalClaimableSupply(exercisableDeposits);

        /* The last claimant might be owed slightly more or less than the actual remaining deposit
           based on rounding errors with the price.
           Therefore if the user's bid is the entire rest of the pot, just give them everything that's left.
           If there is no supply, then this option lost, and we'll return 0.
           */
        if ((_bid == totalBids && _bid != 0) || supply == 0) {
            return supply;
        }

        /* Note that option supply on the losing side and deposits can become decoupled,
           but losing options are not claimable, therefore we only need to worry about
           the situation where supply < owed on the winning side.

           If somehow a user who is not the last bidder is owed more than what's available,
           subsequent bidders will be disadvantaged. Given that the minimum bid is 10^16 wei,
           this should never occur in reality. */
        require(owed <= supply, "supply < claimable");
        return owed;
    }

    function claimableBalanceOf(address account) external view returns (uint) {
        (uint price, uint exercisableDeposits) = market.senderPriceAndExercisableDeposits();
        return _claimableBalanceOf(bidOf[account], price, exercisableDeposits);
    }

    function _totalClaimableSupply(uint exercisableDeposits) internal view returns (uint) {
        uint _totalSupply = totalSupply;
        // We'll avoid throwing an exception here to avoid breaking any dapps, but this case
        // should never occur given the minimum bid size.
        if (exercisableDeposits <= _totalSupply) {
            return 0;
        }
        return exercisableDeposits.sub(_totalSupply);
    }

    function totalClaimableSupply() external view returns (uint) {
        (, uint exercisableDeposits) = market.senderPriceAndExercisableDeposits();
        return _totalClaimableSupply(exercisableDeposits);
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    function _requireMinimumBid(uint bid) internal pure returns (uint) {
        require(bid >= _MINIMUM_BID || bid == 0, "Balance < $0.01");
        return bid;
    }

    // This must only be invoked during bidding.
    function bid(address bidder, uint newBid) external onlyMarket {
        bidOf[bidder] = _requireMinimumBid(bidOf[bidder].add(newBid));
        totalBids = totalBids.add(newBid);
    }

    // This must only be invoked during bidding.
    function refund(address bidder, uint newRefund) external onlyMarket {
        // The safe subtraction will catch refunds that are too large.
        bidOf[bidder] = _requireMinimumBid(bidOf[bidder].sub(newRefund));
        totalBids = totalBids.sub(newRefund);
    }

    // This must only be invoked after bidding.
    function claim(
        address claimant,
        uint price,
        uint depositsRemaining
    ) external onlyMarket returns (uint optionsClaimed) {
        uint _bid = bidOf[claimant];
        uint claimable = _claimableBalanceOf(_bid, price, depositsRemaining);
        // No options to claim? Nothing happens.
        if (claimable == 0) {
            return 0;
        }

        totalBids = totalBids.sub(_bid);
        bidOf[claimant] = 0;

        totalSupply = totalSupply.add(claimable);
        balanceOf[claimant] = balanceOf[claimant].add(claimable); // Increment rather than assigning since a transfer may have occurred.

        emit Transfer(address(0), claimant, claimable);
        emit Issued(claimant, claimable);

        return claimable;
    }

    // This must only be invoked after maturity.
    function exercise(address claimant) external onlyMarket {
        uint balance = balanceOf[claimant];

        if (balance == 0) {
            return;
        }

        balanceOf[claimant] = 0;
        totalSupply = totalSupply.sub(balance);

        emit Transfer(claimant, address(0), balance);
        emit Burned(claimant, balance);
    }

    // This must only be invoked after the exercise window is complete.
    // Note that any options which have not been exercised will linger.
    function expire(address payable beneficiary) external onlyMarket {
        selfdestruct(beneficiary);
    }

    /* ---------- ERC20 Functions ---------- */

    // This should only operate after bidding;
    // Since options can't be claimed until after bidding, all balances are zero until that time.
    // So we don't need to explicitly check the timestamp to prevent transfers.
    function _transfer(
        address _from,
        address _to,
        uint _value
    ) internal returns (bool success) {
        market.requireActiveAndUnpaused();
        require(_to != address(0) && _to != address(this), "Invalid address");

        uint fromBalance = balanceOf[_from];
        require(_value <= fromBalance, "Insufficient balance");

        balanceOf[_from] = fromBalance.sub(_value);
        balanceOf[_to] = balanceOf[_to].add(_value);

        emit Transfer(_from, _to, _value);
        return true;
    }

    function transfer(address _to, uint _value) external returns (bool success) {
        return _transfer(msg.sender, _to, _value);
    }

    function transferFrom(
        address _from,
        address _to,
        uint _value
    ) external returns (bool success) {
        uint fromAllowance = allowance[_from][msg.sender];
        require(_value <= fromAllowance, "Insufficient allowance");

        allowance[_from][msg.sender] = fromAllowance.sub(_value);
        return _transfer(_from, _to, _value);
    }

    function approve(address _spender, uint _value) external returns (bool success) {
        require(_spender != address(0));
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    /* ========== MODIFIERS ========== */

    modifier onlyMarket() {
        require(msg.sender == address(market), "Only market allowed");
        _;
    }

    /* ========== EVENTS ========== */

    event Issued(address indexed account, uint value);
    event Burned(address indexed account, uint value);
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
}


// https://docs.synthetix.io/contracts/source/interfaces/ifeepool
interface IFeePool {
    // Views

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

    function feesAvailable(address account) external view returns (uint, uint);

    function feePeriodDuration() external view returns (uint);

    function isFeesClaimable(address account) external view returns (bool);

    function targetThreshold() external view returns (uint);

    function totalFeesAvailable() external view returns (uint);

    function totalRewardsAvailable() external view returns (uint);

    // Mutative Functions
    function claimFees() external returns (bool);

    function claimOnBehalf(address claimingForAddress) external returns (bool);

    function closeCurrentFeePeriod() external;

    // Restricted: used internally to Synthetix
    function appendAccountIssuanceRecord(
        address account,
        uint lockedAmount,
        uint debtEntryIndex
    ) external;

    function recordFeePaid(uint sUSDAmount) external;

    function setRewardsToDistribute(uint amount) external;
}


// Inheritance


// Libraries


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/binaryoptionmarket
contract BinaryOptionMarket is Owned, MixinResolver, IBinaryOptionMarket {
    /* ========== LIBRARIES ========== */

    using SafeMath for uint;
    using SafeDecimalMath for uint;

    /* ========== TYPES ========== */

    struct Options {
        BinaryOption long;
        BinaryOption short;
    }

    struct Prices {
        uint long;
        uint short;
    }

    struct Times {
        uint biddingEnd;
        uint maturity;
        uint expiry;
    }

    struct OracleDetails {
        bytes32 key;
        uint strikePrice;
        uint finalPrice;
    }

    /* ========== STATE VARIABLES ========== */

    Options public options;
    Prices public prices;
    Times public times;
    OracleDetails public oracleDetails;
    BinaryOptionMarketManager.Fees public fees;
    BinaryOptionMarketManager.CreatorLimits public creatorLimits;

    // `deposited` tracks the sum of open bids on short and long, plus withheld refund fees.
    // This must explicitly be kept, in case tokens are transferred to the contract directly.
    uint public deposited;
    address public creator;
    bool public resolved;
    bool public refundsEnabled;

    uint internal _feeMultiplier;

    /* ---------- Address Resolver Configuration ---------- */

    bytes32 internal constant CONTRACT_SYSTEMSTATUS = "SystemStatus";
    bytes32 internal constant CONTRACT_EXRATES = "ExchangeRates";
    bytes32 internal constant CONTRACT_SYNTHSUSD = "SynthsUSD";
    bytes32 internal constant CONTRACT_FEEPOOL = "FeePool";

    /* ========== CONSTRUCTOR ========== */

    constructor(
        address _owner,
        address _creator,
        address _resolver,
        uint[2] memory _creatorLimits, // [capitalRequirement, skewLimit]
        bytes32 _oracleKey,
        uint _strikePrice,
        bool _refundsEnabled,
        uint[3] memory _times, // [biddingEnd, maturity, expiry]
        uint[2] memory _bids, // [longBid, shortBid]
        uint[3] memory _fees // [poolFee, creatorFee, refundFee]
    ) public Owned(_owner) MixinResolver(_resolver) {
        creator = _creator;
        creatorLimits = BinaryOptionMarketManager.CreatorLimits(_creatorLimits[0], _creatorLimits[1]);

        oracleDetails = OracleDetails(_oracleKey, _strikePrice, 0);
        times = Times(_times[0], _times[1], _times[2]);

        refundsEnabled = _refundsEnabled;

        (uint longBid, uint shortBid) = (_bids[0], _bids[1]);
        _checkCreatorLimits(longBid, shortBid);
        emit Bid(Side.Long, _creator, longBid);
        emit Bid(Side.Short, _creator, shortBid);

        // Note that the initial deposit of synths must be made by the manager, otherwise the contract's assumed
        // deposits will fall out of sync with its actual balance. Similarly the total system deposits must be updated in the manager.
        // A balance check isn't performed here since the manager doesn't know the address of the new contract until after it is created.
        uint initialDeposit = longBid.add(shortBid);
        deposited = initialDeposit;

        (uint poolFee, uint creatorFee) = (_fees[0], _fees[1]);
        fees = BinaryOptionMarketManager.Fees(poolFee, creatorFee, _fees[2]);
        _feeMultiplier = SafeDecimalMath.unit().sub(poolFee.add(creatorFee));

        // Compute the prices now that the fees and deposits have been set.
        _updatePrices(longBid, shortBid, initialDeposit);

        // Instantiate the options themselves
        options.long = new BinaryOption(_creator, longBid);
        options.short = new BinaryOption(_creator, shortBid);
    }

    /* ========== VIEWS ========== */

    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
        addresses = new bytes32[](4);
        addresses[0] = CONTRACT_SYSTEMSTATUS;
        addresses[1] = CONTRACT_EXRATES;
        addresses[2] = CONTRACT_SYNTHSUSD;
        addresses[3] = CONTRACT_FEEPOOL;
    }

    /* ---------- External Contracts ---------- */

    function _systemStatus() internal view returns (ISystemStatus) {
        return ISystemStatus(requireAndGetAddress(CONTRACT_SYSTEMSTATUS));
    }

    function _exchangeRates() internal view returns (IExchangeRates) {
        return IExchangeRates(requireAndGetAddress(CONTRACT_EXRATES));
    }

    function _sUSD() internal view returns (IERC20) {
        return IERC20(requireAndGetAddress(CONTRACT_SYNTHSUSD));
    }

    function _feePool() internal view returns (IFeePool) {
        return IFeePool(requireAndGetAddress(CONTRACT_FEEPOOL));
    }

    function _manager() internal view returns (BinaryOptionMarketManager) {
        return BinaryOptionMarketManager(owner);
    }

    /* ---------- Phases ---------- */

    function _biddingEnded() internal view returns (bool) {
        return times.biddingEnd < now;
    }

    function _matured() internal view returns (bool) {
        return times.maturity < now;
    }

    function _expired() internal view returns (bool) {
        return resolved && (times.expiry < now || deposited == 0);
    }

    function phase() external view returns (Phase) {
        if (!_biddingEnded()) {
            return Phase.Bidding;
        }
        if (!_matured()) {
            return Phase.Trading;
        }
        if (!_expired()) {
            return Phase.Maturity;
        }
        return Phase.Expiry;
    }

    /* ---------- Market Resolution ---------- */

    function _oraclePriceAndTimestamp() internal view returns (uint price, uint updatedAt) {
        return _exchangeRates().rateAndUpdatedTime(oracleDetails.key);
    }

    function oraclePriceAndTimestamp() external view returns (uint price, uint updatedAt) {
        return _oraclePriceAndTimestamp();
    }

    function _isFreshPriceUpdateTime(uint timestamp) internal view returns (bool) {
        (uint maxOraclePriceAge, , ) = _manager().durations();
        return (times.maturity.sub(maxOraclePriceAge)) <= timestamp;
    }

    function canResolve() external view returns (bool) {
        (, uint updatedAt) = _oraclePriceAndTimestamp();
        return !resolved && _matured() && _isFreshPriceUpdateTime(updatedAt);
    }

    function _result() internal view returns (Side) {
        uint price;
        if (resolved) {
            price = oracleDetails.finalPrice;
        } else {
            (price, ) = _oraclePriceAndTimestamp();
        }

        return oracleDetails.strikePrice <= price ? Side.Long : Side.Short;
    }

    function result() external view returns (Side) {
        return _result();
    }

    /* ---------- Option Prices ---------- */

    function _computePrices(
        uint longBids,
        uint shortBids,
        uint _deposited
    ) internal view returns (uint long, uint short) {
        require(longBids != 0 && shortBids != 0, "Bids must be nonzero");
        uint optionsPerSide = _exercisableDeposits(_deposited);

        // The math library rounds up on an exact half-increment -- the price on one side may be an increment too high,
        // but this only implies a tiny extra quantity will go to fees.
        return (longBids.divideDecimalRound(optionsPerSide), shortBids.divideDecimalRound(optionsPerSide));
    }

    function senderPriceAndExercisableDeposits() external view returns (uint price, uint exercisable) {
        // When the market is not yet resolved, both sides might be able to exercise all the options.
        // On the other hand, if the market has resolved, then only the winning side may exercise.
        exercisable = 0;
        if (!resolved || address(_option(_result())) == msg.sender) {
            exercisable = _exercisableDeposits(deposited);
        }

        // Send the correct price for each side of the market.
        if (msg.sender == address(options.long)) {
            price = prices.long;
        } else if (msg.sender == address(options.short)) {
            price = prices.short;
        } else {
            revert("Sender is not an option");
        }
    }

    function pricesAfterBidOrRefund(
        Side side,
        uint value,
        bool refund
    ) external view returns (uint long, uint short) {
        (uint longTotalBids, uint shortTotalBids) = _totalBids();
        // prettier-ignore
        function(uint, uint) pure returns (uint) operation = refund ? SafeMath.sub : SafeMath.add;

        if (side == Side.Long) {
            longTotalBids = operation(longTotalBids, value);
        } else {
            shortTotalBids = operation(shortTotalBids, value);
        }

        if (refund) {
            value = value.multiplyDecimalRound(SafeDecimalMath.unit().sub(fees.refundFee));
        }
        return _computePrices(longTotalBids, shortTotalBids, operation(deposited, value));
    }

    // Returns zero if the result would be negative. See the docs for the formulae this implements.
    function bidOrRefundForPrice(
        Side bidSide,
        Side priceSide,
        uint price,
        bool refund
    ) external view returns (uint) {
        uint adjustedPrice = price.multiplyDecimalRound(_feeMultiplier);
        uint bids = _option(priceSide).totalBids();
        uint _deposited = deposited;
        uint unit = SafeDecimalMath.unit();
        uint refundFeeMultiplier = unit.sub(fees.refundFee);

        if (bidSide == priceSide) {
            uint depositedByPrice = _deposited.multiplyDecimalRound(adjustedPrice);

            // For refunds, the numerator is the negative of the bid case and,
            // in the denominator the adjusted price has an extra factor of (1 - the refundFee).
            if (refund) {
                (depositedByPrice, bids) = (bids, depositedByPrice);
                adjustedPrice = adjustedPrice.multiplyDecimalRound(refundFeeMultiplier);
            }

            // The adjusted price is guaranteed to be less than 1: all its factors are also less than 1.
            return _subToZero(depositedByPrice, bids).divideDecimalRound(unit.sub(adjustedPrice));
        } else {
            uint bidsPerPrice = bids.divideDecimalRound(adjustedPrice);

            // For refunds, the numerator is the negative of the bid case.
            if (refund) {
                (bidsPerPrice, _deposited) = (_deposited, bidsPerPrice);
            }

            uint value = _subToZero(bidsPerPrice, _deposited);
            return refund ? value.divideDecimalRound(refundFeeMultiplier) : value;
        }
    }

    /* ---------- Option Balances and Bids ---------- */

    function _bidsOf(address account) internal view returns (uint long, uint short) {
        return (options.long.bidOf(account), options.short.bidOf(account));
    }

    function bidsOf(address account) external view returns (uint long, uint short) {
        return _bidsOf(account);
    }

    function _totalBids() internal view returns (uint long, uint short) {
        return (options.long.totalBids(), options.short.totalBids());
    }

    function totalBids() external view returns (uint long, uint short) {
        return _totalBids();
    }

    function _claimableBalancesOf(address account) internal view returns (uint long, uint short) {
        return (options.long.claimableBalanceOf(account), options.short.claimableBalanceOf(account));
    }

    function claimableBalancesOf(address account) external view returns (uint long, uint short) {
        return _claimableBalancesOf(account);
    }

    function totalClaimableSupplies() external view returns (uint long, uint short) {
        return (options.long.totalClaimableSupply(), options.short.totalClaimableSupply());
    }

    function _balancesOf(address account) internal view returns (uint long, uint short) {
        return (options.long.balanceOf(account), options.short.balanceOf(account));
    }

    function balancesOf(address account) external view returns (uint long, uint short) {
        return _balancesOf(account);
    }

    function totalSupplies() external view returns (uint long, uint short) {
        return (options.long.totalSupply(), options.short.totalSupply());
    }

    function _exercisableDeposits(uint _deposited) internal view returns (uint) {
        // Fees are deducted at resolution, so remove them if we're still bidding or trading.
        return resolved ? _deposited : _deposited.multiplyDecimalRound(_feeMultiplier);
    }

    function exercisableDeposits() external view returns (uint) {
        return _exercisableDeposits(deposited);
    }

    /* ---------- Utilities ---------- */

    function _chooseSide(
        Side side,
        uint longValue,
        uint shortValue
    ) internal pure returns (uint) {
        if (side == Side.Long) {
            return longValue;
        }
        return shortValue;
    }

    function _option(Side side) internal view returns (BinaryOption) {
        if (side == Side.Long) {
            return options.long;
        }
        return options.short;
    }

    // Returns zero if the result would be negative.
    function _subToZero(uint a, uint b) internal pure returns (uint) {
        return a < b ? 0 : a.sub(b);
    }

    function _checkCreatorLimits(uint longBid, uint shortBid) internal view {
        uint totalBid = longBid.add(shortBid);
        require(creatorLimits.capitalRequirement <= totalBid, "Insufficient capital");
        uint skewLimit = creatorLimits.skewLimit;
        require(
            skewLimit <= longBid.divideDecimal(totalBid) && skewLimit <= shortBid.divideDecimal(totalBid),
            "Bids too skewed"
        );
    }

    function _incrementDeposited(uint value) internal returns (uint _deposited) {
        _deposited = deposited.add(value);
        deposited = _deposited;
        _manager().incrementTotalDeposited(value);
    }

    function _decrementDeposited(uint value) internal returns (uint _deposited) {
        _deposited = deposited.sub(value);
        deposited = _deposited;
        _manager().decrementTotalDeposited(value);
    }

    function _requireManagerNotPaused() internal view {
        require(!_manager().paused(), "This action cannot be performed while the contract is paused");
    }

    function requireActiveAndUnpaused() external view {
        _systemStatus().requireSystemActive();
        _requireManagerNotPaused();
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    /* ---------- Bidding and Refunding ---------- */

    function _updatePrices(
        uint longBids,
        uint shortBids,
        uint _deposited
    ) internal {
        (uint256 longPrice, uint256 shortPrice) = _computePrices(longBids, shortBids, _deposited);
        prices = Prices(longPrice, shortPrice);
        emit PricesUpdated(longPrice, shortPrice);
    }

    function bid(Side side, uint value) external duringBidding {
        if (value == 0) {
            return;
        }

        _option(side).bid(msg.sender, value);
        emit Bid(side, msg.sender, value);

        uint _deposited = _incrementDeposited(value);
        _sUSD().transferFrom(msg.sender, address(this), value);

        (uint longTotalBids, uint shortTotalBids) = _totalBids();
        _updatePrices(longTotalBids, shortTotalBids, _deposited);
    }

    function refund(Side side, uint value) external duringBidding returns (uint refundMinusFee) {
        require(refundsEnabled, "Refunds disabled");
        if (value == 0) {
            return 0;
        }

        // Require the market creator to leave sufficient capital in the market.
        if (msg.sender == creator) {
            (uint thisBid, uint thatBid) = _bidsOf(msg.sender);
            if (side == Side.Short) {
                (thisBid, thatBid) = (thatBid, thisBid);
            }
            _checkCreatorLimits(thisBid.sub(value), thatBid);
        }

        // Safe subtraction here and in related contracts will fail if either the
        // total supply, deposits, or wallet balance are too small to support the refund.
        refundMinusFee = value.multiplyDecimalRound(SafeDecimalMath.unit().sub(fees.refundFee));

        _option(side).refund(msg.sender, value);
        emit Refund(side, msg.sender, refundMinusFee, value.sub(refundMinusFee));

        uint _deposited = _decrementDeposited(refundMinusFee);
        _sUSD().transfer(msg.sender, refundMinusFee);

        (uint longTotalBids, uint shortTotalBids) = _totalBids();
        _updatePrices(longTotalBids, shortTotalBids, _deposited);
    }

    /* ---------- Market Resolution ---------- */

    function resolve() external onlyOwner afterMaturity systemActive managerNotPaused {
        require(!resolved, "Market already resolved");

        // We don't need to perform stale price checks, so long as the price was
        // last updated recently enough before the maturity date.
        (uint price, uint updatedAt) = _oraclePriceAndTimestamp();
        require(_isFreshPriceUpdateTime(updatedAt), "Price is stale");

        oracleDetails.finalPrice = price;
        resolved = true;

        // Now remit any collected fees.
        // Since the constructor enforces that creatorFee + poolFee < 1, the balance
        // in the contract will be sufficient to cover these transfers.
        IERC20 sUSD = _sUSD();

        uint _deposited = deposited;
        uint poolFees = _deposited.multiplyDecimalRound(fees.poolFee);
        uint creatorFees = _deposited.multiplyDecimalRound(fees.creatorFee);
        _decrementDeposited(creatorFees.add(poolFees));
        sUSD.transfer(_feePool().FEE_ADDRESS(), poolFees);
        sUSD.transfer(creator, creatorFees);

        emit MarketResolved(_result(), price, updatedAt, deposited, poolFees, creatorFees);
    }

    /* ---------- Claiming and Exercising Options ---------- */

    function _claimOptions()
        internal
        systemActive
        managerNotPaused
        afterBidding
        returns (uint longClaimed, uint shortClaimed)
    {
        uint exercisable = _exercisableDeposits(deposited);
        Side outcome = _result();
        bool _resolved = resolved;

        // Only claim options if we aren't resolved, and only claim the winning side.
        uint longOptions;
        uint shortOptions;
        if (!_resolved || outcome == Side.Long) {
            longOptions = options.long.claim(msg.sender, prices.long, exercisable);
        }
        if (!_resolved || outcome == Side.Short) {
            shortOptions = options.short.claim(msg.sender, prices.short, exercisable);
        }

        require(longOptions != 0 || shortOptions != 0, "Nothing to claim");
        emit OptionsClaimed(msg.sender, longOptions, shortOptions);
        return (longOptions, shortOptions);
    }

    function claimOptions() external returns (uint longClaimed, uint shortClaimed) {
        return _claimOptions();
    }

    function exerciseOptions() external returns (uint) {
        // The market must be resolved if it has not been.
        if (!resolved) {
            _manager().resolveMarket(address(this));
        }

        // If there are options to be claimed, claim them and proceed.
        (uint claimableLong, uint claimableShort) = _claimableBalancesOf(msg.sender);
        if (claimableLong != 0 || claimableShort != 0) {
            _claimOptions();
        }

        // If the account holds no options, revert.
        (uint longBalance, uint shortBalance) = _balancesOf(msg.sender);
        require(longBalance != 0 || shortBalance != 0, "Nothing to exercise");

        // Each option only needs to be exercised if the account holds any of it.
        if (longBalance != 0) {
            options.long.exercise(msg.sender);
        }
        if (shortBalance != 0) {
            options.short.exercise(msg.sender);
        }

        // Only pay out the side that won.
        uint payout = _chooseSide(_result(), longBalance, shortBalance);
        emit OptionsExercised(msg.sender, payout);
        if (payout != 0) {
            _decrementDeposited(payout);
            _sUSD().transfer(msg.sender, payout);
        }
        return payout;
    }

    /* ---------- Market Expiry ---------- */

    function _selfDestruct(address payable beneficiary) internal {
        uint _deposited = deposited;
        if (_deposited != 0) {
            _decrementDeposited(_deposited);
        }

        // Transfer the balance rather than the deposit value in case there are any synths left over
        // from direct transfers.
        IERC20 sUSD = _sUSD();
        uint balance = sUSD.balanceOf(address(this));
        if (balance != 0) {
            sUSD.transfer(beneficiary, balance);
        }

        // Destroy the option tokens before destroying the market itself.
        options.long.expire(beneficiary);
        options.short.expire(beneficiary);
        selfdestruct(beneficiary);
    }

    function cancel(address payable beneficiary) external onlyOwner duringBidding {
        (uint longTotalBids, uint shortTotalBids) = _totalBids();
        (uint creatorLongBids, uint creatorShortBids) = _bidsOf(creator);
        bool cancellable = longTotalBids == creatorLongBids && shortTotalBids == creatorShortBids;
        require(cancellable, "Not cancellable");
        _selfDestruct(beneficiary);
    }

    function expire(address payable beneficiary) external onlyOwner {
        require(_expired(), "Unexpired options remaining");
        _selfDestruct(beneficiary);
    }

    /* ========== MODIFIERS ========== */

    modifier duringBidding() {
        require(!_biddingEnded(), "Bidding inactive");
        _;
    }

    modifier afterBidding() {
        require(_biddingEnded(), "Bidding incomplete");
        _;
    }

    modifier afterMaturity() {
        require(_matured(), "Not yet mature");
        _;
    }

    modifier systemActive() {
        _systemStatus().requireSystemActive();
        _;
    }

    modifier managerNotPaused() {
        _requireManagerNotPaused();
        _;
    }

    /* ========== EVENTS ========== */

    event Bid(Side side, address indexed account, uint value);
    event Refund(Side side, address indexed account, uint value, uint fee);
    event PricesUpdated(uint longPrice, uint shortPrice);
    event MarketResolved(
        Side result,
        uint oraclePrice,
        uint oracleTimestamp,
        uint deposited,
        uint poolFees,
        uint creatorFees
    );
    event OptionsClaimed(address indexed account, uint longOptions, uint shortOptions);
    event OptionsExercised(address indexed account, uint value);
}


// Inheritance


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/binaryoptionmarketfactory
contract BinaryOptionMarketFactory is Owned, MixinResolver {
    /* ========== STATE VARIABLES ========== */

    /* ---------- Address Resolver Configuration ---------- */

    bytes32 internal constant CONTRACT_BINARYOPTIONMARKETMANAGER = "BinaryOptionMarketManager";

    /* ========== CONSTRUCTOR ========== */

    constructor(address _owner, address _resolver) public Owned(_owner) MixinResolver(_resolver) {}

    /* ========== VIEWS ========== */

    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
        addresses = new bytes32[](1);
        addresses[0] = CONTRACT_BINARYOPTIONMARKETMANAGER;
    }

    /* ---------- Related Contracts ---------- */

    function _manager() internal view returns (address) {
        return requireAndGetAddress(CONTRACT_BINARYOPTIONMARKETMANAGER);
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    function createMarket(
        address creator,
        uint[2] calldata creatorLimits,
        bytes32 oracleKey,
        uint strikePrice,
        bool refundsEnabled,
        uint[3] calldata times, // [biddingEnd, maturity, expiry]
        uint[2] calldata bids, // [longBid, shortBid]
        uint[3] calldata fees // [poolFee, creatorFee, refundFee]
    ) external returns (BinaryOptionMarket) {
        address manager = _manager();
        require(address(manager) == msg.sender, "Only permitted by the manager.");

        return
            new BinaryOptionMarket(
                manager,
                creator,
                address(resolver),
                creatorLimits,
                oracleKey,
                strikePrice,
                refundsEnabled,
                times,
                bids,
                fees
            );
    }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_resolver","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"name","type":"bytes32"},{"indexed":false,"internalType":"address","name":"destination","type":"address"}],"name":"CacheUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"creator","type":"address"},{"internalType":"uint256[2]","name":"creatorLimits","type":"uint256[2]"},{"internalType":"bytes32","name":"oracleKey","type":"bytes32"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"bool","name":"refundsEnabled","type":"bool"},{"internalType":"uint256[3]","name":"times","type":"uint256[3]"},{"internalType":"uint256[2]","name":"bids","type":"uint256[2]"},{"internalType":"uint256[3]","name":"fees","type":"uint256[3]"}],"name":"createMarket","outputs":[{"internalType":"contract BinaryOptionMarket","name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"isResolverCached","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"rebuildCache","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"resolver","outputs":[{"internalType":"contract AddressResolver","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resolverAddressesRequired","outputs":[{"internalType":"bytes32[]","name":"addresses","type":"bytes32[]"}],"payable":false,"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b506040516158493803806158498339818101604052604081101561003357600080fd5b50805160209091015180826001600160a01b038116610099576040805162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f74206265203000000000000000604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b038316908117825560408051928352602083019190915280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a150600280546001600160a01b039092166001600160a01b03199092169190911790555050615725806101246000396000f3fe60806040523480156200001157600080fd5b5060043610620000a05760003560e01c806353a47bb7116200006f57806353a47bb7146200016857806374185360146200017257806379ba5097146200017c578063899ffef414620001865780638da5cb5b14620001e257620000a0565b806304f3bcec14620000a5578063130efa5014620000cb5780631627540c146200011f5780632af64bd3146200014a575b600080fd5b620000af620001ec565b604080516001600160a01b039092168252519081900360200190f35b620000af60048036036101c0811015620000e457600080fd5b506001600160a01b0381351690602081019060608101359060808101359060a081013515159060c081019061012081019061016001620001fb565b62000148600480360360208110156200013757600080fd5b50356001600160a01b03166200036e565b005b62000154620003cc565b604080519115158252519081900360200190f35b620000af620004e2565b62000148620004f1565b62000148620006c4565b6200019062000782565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015620001ce578181015183820152602001620001b4565b505050509050019250505060405180910390f35b620000af620007de565b6002546001600160a01b031681565b60008062000208620007ed565b90506001600160a01b038116331462000268576040805162461bcd60e51b815260206004820152601e60248201527f4f6e6c79207065726d697474656420627920746865206d616e616765722e0000604482015290519081900360640190fd5b808a600260009054906101000a90046001600160a01b03168b8b8b8b8b8b8b604051620002959062000950565b6001600160a01b03808c1682528a8116602083015289166040808301919091526060820190899080828437600083820152601f01601f191690910188815260208101889052861515604082015260609081019150859080828437600083820152601f01601f1916909101905083604080828437600083820152601f01601f19169091019050826060808284376000838201819052604051601f909201601f19169093018190039d509b50909950505050505050505050f0801580156200035f573d6000803e3d6000fd5b509a9950505050505050505050565b620003786200081b565b600180546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce229181900360200190a150565b60006060620003da62000782565b905060005b8151811015620004d8576000828281518110620003f857fe5b6020908102919091018101516000818152600383526040908190205460025482516321f8a72160e01b81526004810185905292519395506001600160a01b03918216949116926321f8a721926024808201939291829003018186803b1580156200046157600080fd5b505afa15801562000476573d6000803e3d6000fd5b505050506040513d60208110156200048d57600080fd5b50516001600160a01b0316141580620004bb57506000818152600360205260409020546001600160a01b0316155b15620004ce5760009350505050620004df565b50600101620003df565b5060019150505b90565b6001546001600160a01b031681565b6060620004fd62000782565b905060005b8151811015620006c05760008282815181106200051b57fe5b602090810291909101810151600254604080517f5265736f6c766572206d697373696e67207461726765743a2000000000000000818601526039808201859052825180830390910181526059820180845263dacb2d0160e01b9052605d8201858152607d83019384528151609d84015281519597506000966001600160a01b039095169563dacb2d01958995939492939260bd0191908501908083838c5b83811015620005d3578181015183820152602001620005b9565b50505050905090810190601f168015620006015780820380516001836020036101000a031916815260200191505b50935050505060206040518083038186803b1580156200062057600080fd5b505afa15801562000635573d6000803e3d6000fd5b505050506040513d60208110156200064c57600080fd5b505160008381526003602090815260409182902080546001600160a01b0319166001600160a01b03851690811790915582518681529182015281519293507f88a93678a3692f6789d9546fc621bf7234b101ddb7d4fe479455112831b8aa68929081900390910190a1505060010162000502565b5050565b6001546001600160a01b031633146200070f5760405162461bcd60e51b81526004018080602001828103825260358152602001806200568d6035913960400191505060405180910390fd5b600054600154604080516001600160a01b03938416815292909116602083015280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b60408051600180825281830190925260609160208083019080388339019050509050782134b730b93ca7b83a34b7b726b0b935b2ba26b0b730b3b2b960391b81600081518110620007cf57fe5b60200260200101818152505090565b6000546001600160a01b031681565b600062000816782134b730b93ca7b83a34b7b726b0b935b2ba26b0b730b3b2b960391b62000868565b905090565b6000546001600160a01b03163314620008665760405162461bcd60e51b815260040180806020018281038252602f815260200180620056c2602f913960400191505060405180910390fd5b565b600081815260036020908152604080832054815170026b4b9b9b4b7339030b2323932b9b99d1607d1b9381019390935260318084018690528251808503909101815260519093019091526001600160a01b03169081620009495760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156200090d578181015183820152602001620008f3565b50505050905090810190601f1680156200093b5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5092915050565b614d2e806200095f8339019056fe60806040523480156200001157600080fd5b5060405162004d2e38038062004d2e83398181016040526102008110156200003857600080fd5b5080516020820151604083015160a084015160c085015160e08601519495939492936060810193906101008101906101608101906101a001878a6001600160a01b038116620000ce576040805162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f74206265203000000000000000604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b038316908117825560408051928352602083019190915280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a150600280546001600160a01b03199081166001600160a01b0393841617909155601480546040805180820182528c518082526020808f01519281018390526011919091556012919091558151606080820184528d82528183018d90526000918401829052600b8e9055600c8d9055600d919091558251908101835289518082528a8301518284018190528b85015192909401829052600855600992909255600a919091559216928c169290921760ff60a81b1916600160a81b8715150217909155825190830151620001f982826200047b565b8a6001600160a01b031660008051602062004d0e833981519152600084604051808360018111156200022757fe5b60ff1681526020018281526020019250505060405180910390a28a6001600160a01b031660008051602062004d0e833981519152600183604051808360018111156200026f57fe5b60ff1681526020018281526020019250505060405180910390a26000620002a582846200058260201b620021f71790919060201c565b6013819055845160208087015160408051606081018252848152808401839052818a01519101819052600e849055600f8290556010559293509091906200038490620002fe908490849062000582811b620021f717901c565b7384d626b2bb4d0f064067e4bf80fce7055d8f3e7b63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b1580156200034357600080fd5b505af415801562000358573d6000803e3d6000fd5b505050506040513d60208110156200036f57600080fd5b505190620005e6602090811b62002bb317901c565b6015556200039d8585856001600160e01b036200064416565b8d85604051620003ad9062000976565b6001600160a01b0390921682526020820152604080519182900301906000f080158015620003df573d6000803e3d6000fd5b50600480546001600160a01b0319166001600160a01b03929092169190911790556040518e908590620004129062000976565b6001600160a01b0390921682526020820152604080519182900301906000f08015801562000444573d6000803e3d6000fd5b50600580546001600160a01b0319166001600160a01b039290921691909117905550620009849d5050505050505050505050505050565b60006200049782846200058260201b620021f71790919060201c565b9050806011600001541115620004f4576040805162461bcd60e51b815260206004820152601460248201527f496e73756666696369656e74206361706974616c000000000000000000000000604482015290519081900360640190fd5b6012546200050f8483620006be602090811b6200300417901c565b8111158015620005385750620005348284620006be60201b620030041790919060201c565b8111155b6200057c576040805162461bcd60e51b815260206004820152600f60248201526e109a591cc81d1bdbc81cdad95dd959608a1b604482015290519081900360640190fd5b50505050565b600082820183811015620005dd576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b6000828211156200063e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000806200065d8585856001600160e01b03620006f916565b604080518082018252838152602090810183905260068490556007839055815184815290810183905281519395509193507f6546f60f34df611fa42503098acc39d5ab88bc73febe64b3cc14e5a92e3a66a792918290030190a15050505050565b6000620005dd82620006e585670de0b6b3a7640000620007b6602090811b6200305417901c565b6200081460201b620030ad1790919060201c565b60008084158015906200070b57508315155b6200075d576040805162461bcd60e51b815260206004820152601460248201527f42696473206d757374206265206e6f6e7a65726f000000000000000000000000604482015290519081900360640190fd5b600062000773846001600160e01b036200088016565b90506200078f8187620008bb60201b62002e271790919060201c565b620007a98287620008bb60201b62002e271790919060201c565b9250925050935093915050565b600082620007c757506000620005e0565b82820282848281620007d557fe5b0414620005dd5760405162461bcd60e51b815260040180806020018281038252602181526020018062004ced6021913960400191505060405180910390fd5b60008082116200086b576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b60008284816200087757fe5b04949350505050565b601454600090600160a01b900460ff16620008b757620008b160155483620008db60201b620021db1790919060201c565b620005e0565b5090565b6000620005dd8383670de0b6b3a76400006001600160e01b03620008fb16565b6000620005dd8383670de0b6b3a76400006001600160e01b036200093f16565b6000806200092084620006e585600a0288620007b660201b620030541790919060201c565b90506005600a825b06106200093357600a015b600a9004949350505050565b600080600a8304620009608587620007b660201b620030541790919060201c565b816200096857fe5b0490506005600a8262000928565b61114a8062003ba383390190565b61320f80620009946000396000f3fe608060405234801561001057600080fd5b50600436106102485760003560e01c8063851492581161013b578063be5af9fe116100b8578063d3419bf31161007c578063d3419bf31461055c578063dbea363814610564578063e4cfbdbd1461058a578063eef49ee3146105c2578063fd087ee5146105ca57610248565b8063be5af9fe14610516578063c588f5261461051e578063c7a5bdc814610526578063c8db233e1461052e578063d068cdc51461055457610248565b80639af1d35a116100ff5780639af1d35a146104c05780639e3b34bf146104c8578063ac3791e3146104d0578063b1c9fe6e146104d8578063b634bfbc146104f057610248565b8063851492581461042a578063899ffef4146104325780638b0341361461048a5780638da5cb5b1461049257806398508ecd1461049a57610248565b80633dae89eb116101c957806353a47bb71161018d57806353a47bb7146103c05780636392a51f146103c857806365372147146103ee578063741853601461041a57806379ba50971461042257610248565b80633dae89eb1461035c5780633f6fa65514610364578063408e82af1461036c5780634c33fe9414610392578063532f1179146103b857610248565b806327745bae1161021057806327745bae146102e95780632810e1d6146102f157806329e77b5d146102f95780632af64bd3146103385780633d7a783b1461035457610248565b806302d05d3f1461024d57806304f3bcec146102715780631069143a146102795780631627540c146102a75780632115e303146102cf575b600080fd5b6102556105f8565b604080516001600160a01b039092168252519081900360200190f35b610255610607565b610281610616565b604080516001600160a01b03938416815291909216602082015281519081900390910190f35b6102cd600480360360208110156102bd57600080fd5b50356001600160a01b031661062c565b005b6102d7610688565b60408051918252519081900360200190f35b6102cd61069b565b6102cd6106fd565b61031f6004803603602081101561030f57600080fd5b50356001600160a01b0316610ad1565b6040805192835260208301919091528051918290030190f35b610340610ae6565b604080519115158252519081900360200190f35b61031f610bf0565b61031f610cdb565b610340610cee565b61031f6004803603602081101561038257600080fd5b50356001600160a01b0316610cfe565b6102cd600480360360208110156103a857600080fd5b50356001600160a01b0316610d0a565b610340610df4565b610255610e04565b61031f600480360360208110156103de57600080fd5b50356001600160a01b0316610e13565b6103f6610e1f565b6040518082600181111561040657fe5b60ff16815260200191505060405180910390f35b6102cd610e29565b6102cd610ff1565b6102d76110ad565b61043a61139e565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561047657818101518382015260200161045e565b505050509050019250505060405180910390f35b61031f611461565b61025561146c565b6104a261147b565b60408051938452602084019290925282820152519081900360600190f35b6104a2611487565b6104a2611493565b61034061149f565b6104e06114e2565b6040518082600381111561040657fe5b6102d76004803603604081101561050657600080fd5b5060ff8135169060200135611526565b61031f61186d565b61031f611876565b61031f611945565b6102cd6004803603602081101561054457600080fd5b50356001600160a01b0316611950565b61031f6119bd565b61031f611a72565b6102cd6004803603604081101561057a57600080fd5b5060ff8135169060200135611a7b565b6102d7600480360360808110156105a057600080fd5b5060ff8135811691602081013590911690604081013590606001351515611c64565b6102d7611e65565b61031f600480360360608110156105e057600080fd5b5060ff81351690602081013590604001351515611e6b565b6014546001600160a01b031681565b6002546001600160a01b031681565b6004546005546001600160a01b03918216911682565b610634611f5c565b600180546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce229181900360200190a150565b6000610695601354611fa5565b90505b90565b6106a3611fdc565b6001600160a01b031663086dabd16040518163ffffffff1660e01b815260040160006040518083038186803b1580156106db57600080fd5b505afa1580156106ef573d6000803e3d6000fd5b505050506106fb611ff6565b565b610705611f5c565b61070d61209e565b61074f576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420796574206d617475726560901b604482015290519081900360640190fd5b610757611fdc565b6001600160a01b031663086dabd16040518163ffffffff1660e01b815260040160006040518083038186803b15801561078f57600080fd5b505afa1580156107a3573d6000803e3d6000fd5b505050506107af611ff6565b601454600160a01b900460ff161561080e576040805162461bcd60e51b815260206004820152601760248201527f4d61726b657420616c7265616479207265736f6c766564000000000000000000604482015290519081900360640190fd5b6000806108196120a6565b9150915061082681612134565b610868576040805162461bcd60e51b815260206004820152600e60248201526d5072696365206973207374616c6560901b604482015290519081900360640190fd5b600d8290556014805460ff60a01b1916600160a01b179055600061088a6121c4565b601354600e54919250906000906108a890839063ffffffff6121db16565b600f549091506000906108c290849063ffffffff6121db16565b90506108dc6108d7828463ffffffff6121f716565b612251565b50836001600160a01b031663a9059cbb6108f46122d8565b6001600160a01b031663eb1edd616040518163ffffffff1660e01b815260040160206040518083038186803b15801561092c57600080fd5b505afa158015610940573d6000803e3d6000fd5b505050506040513d602081101561095657600080fd5b5051604080516001600160e01b031960e085901b1681526001600160a01b039092166004830152602482018690525160448083019260209291908290030181600087803b1580156109a657600080fd5b505af11580156109ba573d6000803e3d6000fd5b505050506040513d60208110156109d057600080fd5b50506014546040805163a9059cbb60e01b81526001600160a01b0392831660048201526024810184905290519186169163a9059cbb916044808201926020929091908290030181600087803b158015610a2857600080fd5b505af1158015610a3c573d6000803e3d6000fd5b505050506040513d6020811015610a5257600080fd5b507f5528b7e06f48a519cf814c4e5293ee2737c3f5c28d93e30cca112ac649fdd2359050610a7e6122ed565b8787601354868660405180876001811115610a9557fe5b60ff1681526020810196909652506040808601949094526060850192909252608084015260a0830152519081900360c0019150a1505050505050565b600080610add83612332565b91509150915091565b60006060610af261139e565b905060005b8151811015610be7576000828281518110610b0e57fe5b6020908102919091018101516000818152600383526040908190205460025482516321f8a72160e01b81526004810185905292519395506001600160a01b03918216949116926321f8a721926024808201939291829003018186803b158015610b7657600080fd5b505afa158015610b8a573d6000803e3d6000fd5b505050506040513d6020811015610ba057600080fd5b50516001600160a01b0316141580610bcd57506000818152600360205260409020546001600160a01b0316155b15610bde5760009350505050610698565b50600101610af7565b50600191505090565b6004805460408051636b7f817160e11b8152905160009384936001600160a01b03169263d6ff02e29281830192602092829003018186803b158015610c3457600080fd5b505afa158015610c48573d6000803e3d6000fd5b505050506040513d6020811015610c5e57600080fd5b505160055460408051636b7f817160e11b815290516001600160a01b039092169163d6ff02e291600481810192602092909190829003018186803b158015610ca557600080fd5b505afa158015610cb9573d6000803e3d6000fd5b505050506040513d6020811015610ccf57600080fd5b505190925090505b9091565b600080610ce6612433565b915091509091565b601454600160a01b900460ff1681565b600080610add836126fd565b610d12611f5c565b610d1a6127c8565b15610d5f576040805162461bcd60e51b815260206004820152601060248201526f42696464696e6720696e61637469766560801b604482015290519081900360640190fd5b600080610d6a6127d0565b60145491935091506000908190610d89906001600160a01b0316612332565b9150915060008285148015610d9d57508184145b905080610de3576040805162461bcd60e51b815260206004820152600f60248201526e4e6f742063616e63656c6c61626c6560881b604482015290519081900360640190fd5b610dec86612885565b505050505050565b601454600160a81b900460ff1681565b6001546001600160a01b031681565b600080610add83612a8c565b60006106956122ed565b6060610e3361139e565b905060005b8151811015610fed576000828281518110610e4f57fe5b602090810291909101810151600254604080517f5265736f6c766572206d697373696e67207461726765743a2000000000000000818601526039808201859052825180830390910181526059820180845263dacb2d0160e01b9052605d8201858152607d83019384528151609d84015281519597506000966001600160a01b039095169563dacb2d01958995939492939260bd0191908501908083838c5b83811015610f05578181015183820152602001610eed565b50505050905090810190601f168015610f325780820380516001836020036101000a031916815260200191505b50935050505060206040518083038186803b158015610f5057600080fd5b505afa158015610f64573d6000803e3d6000fd5b505050506040513d6020811015610f7a57600080fd5b505160008381526003602090815260409182902080546001600160a01b0319166001600160a01b03851690811790915582518681529182015281519293507f88a93678a3692f6789d9546fc621bf7234b101ddb7d4fe479455112831b8aa68929081900390910190a15050600101610e38565b5050565b6001546001600160a01b0316331461103a5760405162461bcd60e51b815260040180806020018281038252603581526020018061311a6035913960400191505060405180910390fd5b600054600154604080516001600160a01b03938416815292909116602083015280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b601454600090600160a01b900460ff16611139576110c9612b57565b6001600160a01b0316637859f410306040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050600060405180830381600087803b15801561112057600080fd5b505af1158015611134573d6000803e3d6000fd5b505050505b600080611145336126fd565b9150915081600014158061115857508015155b1561116857611165612433565b50505b60008061117433612a8c565b9150915081600014158061118757508015155b6111ce576040805162461bcd60e51b81526020600482015260136024820152724e6f7468696e6720746f20657865726369736560681b604482015290519081900360640190fd5b811561123a576004805460408051630d8acc1560e11b81523393810193909352516001600160a01b0390911691631b15982a91602480830192600092919082900301818387803b15801561122157600080fd5b505af1158015611235573d6000803e3d6000fd5b505050505b80156112a55760055460408051630d8acc1560e11b815233600482015290516001600160a01b0390921691631b15982a9160248082019260009290919082900301818387803b15801561128c57600080fd5b505af11580156112a0573d6000803e3d6000fd5b505050505b60006112b96112b26122ed565b8484612b66565b60408051828152905191925033917fd82b6f69d7477fb41cd83d936de94990cee2fa1a309feeee90101fc0513b6a439181900360200190a280156113955761130081612251565b506113096121c4565b6001600160a01b031663a9059cbb33836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561136857600080fd5b505af115801561137c573d6000803e3d6000fd5b505050506040513d602081101561139257600080fd5b50505b94505050505090565b60408051600480825260a08201909252606091602082016080803883390190505090506b53797374656d53746174757360a01b816000815181106113de57fe5b6020026020010181815250506c45786368616e6765526174657360981b8160018151811061140857fe5b6020026020010181815250506814de5b9d1a1cd554d160ba1b8160028151811061142e57fe5b60200260200101818152505066119959541bdbdb60ca1b8160038151811061145257fe5b60200260200101818152505090565b600080610ce66127d0565b6000546001600160a01b031681565b600b54600c54600d5483565b600e54600f5460105483565b600854600954600a5483565b6000806114aa6120a6565b601454909250600160a01b900460ff1615905080156114cc57506114cc61209e565b80156114dc57506114dc81612134565b91505090565b60006114ec6127c8565b6114f857506000610698565b61150061209e565b61150c57506001610698565b611514612b89565b61152057506002610698565b50600390565b60006115306127c8565b15611575576040805162461bcd60e51b815260206004820152601060248201526f42696464696e6720696e61637469766560801b604482015290519081900360640190fd5b601454600160a81b900460ff166115c6576040805162461bcd60e51b815260206004820152601060248201526f1499599d5b991cc8191a5cd8589b195960821b604482015290519081900360640190fd5b816115d357506000611867565b6014546001600160a01b0316331415611629576000806115f233612332565b9092509050600185600181111561160557fe5b141561160d57905b611626611620838663ffffffff612bb316565b82612c10565b50505b6116be6116b1600e600201547384d626b2bb4d0f064067e4bf80fce7055d8f3e7b63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b15801561167957600080fd5b505af415801561168d573d6000803e3d6000fd5b505050506040513d60208110156116a357600080fd5b50519063ffffffff612bb316565b839063ffffffff6121db16565b90506116c983612cef565b6001600160a01b031663410085df33846040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561172857600080fd5b505af115801561173c573d6000803e3d6000fd5b503392507f9bd0a8ca6625e01a9cee5e86eec7813a8234b41f1ca0c9f15a008d1e1d00ee5f915085905083611777868263ffffffff612bb316565b6040518084600181111561178757fe5b60ff168152602001838152602001828152602001935050505060405180910390a260006117b382612251565b90506117bd6121c4565b6001600160a01b031663a9059cbb33846040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561181c57600080fd5b505af1158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5060009050806118546127d0565b91509150611863828285612d27565b5050505b92915050565b60115460125482565b6014546000908190600160a01b900460ff1615806118ab5750336118a061189b6122ed565b612cef565b6001600160a01b0316145b156118be576118bb601354611fa5565b90505b6004546001600160a01b03163314156118db576006549150610cd7565b6005546001600160a01b03163314156118f8576007549150610cd7565b6040805162461bcd60e51b815260206004820152601760248201527f53656e646572206973206e6f7420616e206f7074696f6e000000000000000000604482015290519081900360640190fd5b600080610ce66120a6565b611958611f5c565b611960612b89565b6119b1576040805162461bcd60e51b815260206004820152601b60248201527f556e65787069726564206f7074696f6e732072656d61696e696e670000000000604482015290519081900360640190fd5b6119ba81612885565b50565b60048054604080516318160ddd60e01b8152905160009384936001600160a01b0316926318160ddd9281830192602092829003018186803b158015611a0157600080fd5b505afa158015611a15573d6000803e3d6000fd5b505050506040513d6020811015611a2b57600080fd5b5051600554604080516318160ddd60e01b815290516001600160a01b03909216916318160ddd91600481810192602092909190829003018186803b158015610ca557600080fd5b60065460075482565b611a836127c8565b15611ac8576040805162461bcd60e51b815260206004820152601060248201526f42696464696e6720696e61637469766560801b604482015290519081900360640190fd5b80611ad257610fed565b611adb82612cef565b6001600160a01b03166359d667a533836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b158015611b3a57600080fd5b505af1158015611b4e573d6000803e3d6000fd5b50505050336001600160a01b03167f70bd4a33bf447720d717d08f3affb5aecfe4d2ebb8e3dd94539f5313e2447643838360405180836001811115611b8f57fe5b60ff1681526020018281526020019250505060405180910390a26000611bb482612d96565b9050611bbe6121c4565b604080516323b872dd60e01b81523360048201523060248201526044810185905290516001600160a01b0392909216916323b872dd916064808201926020929091908290030181600087803b158015611c1657600080fd5b505af1158015611c2a573d6000803e3d6000fd5b505050506040513d6020811015611c4057600080fd5b506000905080611c4e6127d0565b91509150611c5d828285612d27565b5050505050565b600080611c7c601554856121db90919063ffffffff16565b90506000611c8986612cef565b6001600160a01b0316638b0341366040518163ffffffff1660e01b815260040160206040518083038186803b158015611cc157600080fd5b505afa158015611cd5573d6000803e3d6000fd5b505050506040513d6020811015611ceb57600080fd5b505160135460408051630241ebdb60e61b8152905192935090916000917384d626b2bb4d0f064067e4bf80fce7055d8f3e7b9163907af6c091600480820192602092909190829003018186803b158015611d4457600080fd5b505af4158015611d58573d6000803e3d6000fd5b505050506040513d6020811015611d6e57600080fd5b5051601054909150600090611d8a90839063ffffffff612bb316565b9050886001811115611d9857fe5b8a6001811115611da457fe5b1415611e0e576000611dbc848763ffffffff6121db16565b90508715611dd85793611dd5868363ffffffff6121db16565b95505b611e01611deb848863ffffffff612bb316565b611df58388612e00565b9063ffffffff612e2716565b9650505050505050611e5d565b6000611e20858763ffffffff612e2716565b90508715611e2a57925b6000611e368286612e00565b905088611e435780611e53565b611e53818463ffffffff612e2716565b9750505050505050505b949350505050565b60135481565b600080600080611e796127d0565b9150915061311785611e8d576121f7611e91565b612bb35b90506000886001811115611ea157fe5b1415611ebc57611eb583888363ffffffff16565b9250611ecd565b611eca82888363ffffffff16565b91505b8515611f3357611f30611f23600e600201547384d626b2bb4d0f064067e4bf80fce7055d8f3e7b63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b15801561167957600080fd5b889063ffffffff6121db16565b96505b611f4d8383611f486013548b8663ffffffff16565b612e3c565b94509450505050935093915050565b6000546001600160a01b031633146106fb5760405162461bcd60e51b815260040180806020018281038252602f81526020018061314f602f913960400191505060405180910390fd5b601454600090600160a01b900460ff16611fd257601554611fcd90839063ffffffff6121db16565b611fd4565b815b90505b919050565b60006106956b53797374656d53746174757360a01b612ecf565b611ffe612b57565b6001600160a01b0316635c975abb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561203657600080fd5b505afa15801561204a573d6000803e3d6000fd5b505050506040513d602081101561206057600080fd5b5051156106fb5760405162461bcd60e51b815260040180806020018281038252603c81526020018061319f603c913960400191505060405180910390fd5b600954421190565b6000806120b1612fac565b6001600160a01b0316634308a94f600b600001546040518263ffffffff1660e01b815260040180828152602001915050604080518083038186803b1580156120f857600080fd5b505afa15801561210c573d6000803e3d6000fd5b505050506040513d604081101561212257600080fd5b50805160209091015190925090509091565b60008061213f612b57565b6001600160a01b0316634a41d89d6040518163ffffffff1660e01b815260040160606040518083038186803b15801561217757600080fd5b505afa15801561218b573d6000803e3d6000fd5b505050506040513d60608110156121a157600080fd5b505160095490915083906121bb908363ffffffff612bb316565b11159392505050565b60006106956814de5b9d1a1cd554d160ba1b612ecf565b60006121f08383670de0b6b3a7640000612fc7565b9392505050565b6000828201838110156121f0576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b601354600090612267908363ffffffff612bb316565b60138190559050612276612b57565b6001600160a01b0316636b3a0984836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156122bb57600080fd5b505af11580156122cf573d6000803e3d6000fd5b50505050919050565b600061069566119959541bdbdb60ca1b612ecf565b6014546000908190600160a01b900460ff161561230d5750600d54612319565b6123156120a6565b5090505b600c5481101561232a5760016114dc565b600091505090565b60048054604080516308dc30b760e41b81526001600160a01b0385811694820194909452905160009384931691638dc30b70916024808301926020929190829003018186803b15801561238457600080fd5b505afa158015612398573d6000803e3d6000fd5b505050506040513d60208110156123ae57600080fd5b5051600554604080516308dc30b760e41b81526001600160a01b03878116600483015291519190921691638dc30b70916024808301926020929190829003018186803b1580156123fd57600080fd5b505afa158015612411573d6000803e3d6000fd5b505050506040513d602081101561242757600080fd5b50519092509050915091565b60008061243e611fdc565b6001600160a01b031663086dabd16040518163ffffffff1660e01b815260040160006040518083038186803b15801561247657600080fd5b505afa15801561248a573d6000803e3d6000fd5b50505050612496611ff6565b61249e6127c8565b6124e4576040805162461bcd60e51b815260206004820152601260248201527142696464696e6720696e636f6d706c65746560701b604482015290519081900360640190fd5b60006124f1601354611fa5565b905060006124fd6122ed565b601454909150600160a01b900460ff166000808215806125285750600084600181111561252657fe5b145b156125bc576004805460065460408051632bc43fd960e01b81523394810194909452602484019190915260448301889052516001600160a01b0390911691632bc43fd99160648083019260209291908290030181600087803b15801561258d57600080fd5b505af11580156125a1573d6000803e3d6000fd5b505050506040513d60208110156125b757600080fd5b505191505b8215806125d4575060018460018111156125d257fe5b145b156126665760055460075460408051632bc43fd960e01b8152336004820152602481019290925260448201889052516001600160a01b0390921691632bc43fd9916064808201926020929091908290030181600087803b15801561263757600080fd5b505af115801561264b573d6000803e3d6000fd5b505050506040513d602081101561266157600080fd5b505190505b8115158061267357508015155b6126b7576040805162461bcd60e51b815260206004820152601060248201526f4e6f7468696e6720746f20636c61696d60801b604482015290519081900360640190fd5b6040805183815260208101839052815133927fbbe753caa9bb201dbd1740ee3d61c6d2adf5fa89f30233d732281ae5db6a03d4928290030190a290955093505050509091565b600480546040805163270fb89160e21b81526001600160a01b0385811694820194909452905160009384931691639c3ee244916024808301926020929190829003018186803b15801561274f57600080fd5b505afa158015612763573d6000803e3d6000fd5b505050506040513d602081101561277957600080fd5b50516005546040805163270fb89160e21b81526001600160a01b03878116600483015291519190921691639c3ee244916024808301926020929190829003018186803b1580156123fd57600080fd5b600854421190565b6004805460408051634581a09b60e11b8152905160009384936001600160a01b031692638b0341369281830192602092829003018186803b15801561281457600080fd5b505afa158015612828573d6000803e3d6000fd5b505050506040513d602081101561283e57600080fd5b505160055460408051634581a09b60e11b815290516001600160a01b0390921691638b03413691600481810192602092909190829003018186803b158015610ca557600080fd5b60135480156128995761289781612251565b505b60006128a36121c4565b604080516370a0823160e01b815230600482015290519192506000916001600160a01b038416916370a08231916024808301926020929190829003018186803b1580156128ef57600080fd5b505afa158015612903573d6000803e3d6000fd5b505050506040513d602081101561291957600080fd5b5051905080156129b057816001600160a01b031663a9059cbb85836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561298357600080fd5b505af1158015612997573d6000803e3d6000fd5b505050506040513d60208110156129ad57600080fd5b50505b600480546040805163646d919f60e11b81526001600160a01b03888116948201949094529051929091169163c8db233e9160248082019260009290919082900301818387803b158015612a0257600080fd5b505af1158015612a16573d6000803e3d6000fd5b50506005546040805163646d919f60e11b81526001600160a01b038981166004830152915191909216935063c8db233e9250602480830192600092919082900301818387803b158015612a6857600080fd5b505af1158015612a7c573d6000803e3d6000fd5b50505050836001600160a01b0316ff5b60048054604080516370a0823160e01b81526001600160a01b03858116948201949094529051600093849316916370a08231916024808301926020929190829003018186803b158015612ade57600080fd5b505afa158015612af2573d6000803e3d6000fd5b505050506040513d6020811015612b0857600080fd5b5051600554604080516370a0823160e01b81526001600160a01b038781166004830152915191909216916370a08231916024808301926020929190829003018186803b1580156123fd57600080fd5b6000546001600160a01b031690565b600080846001811115612b7557fe5b1415612b825750816121f0565b5092915050565b601454600090600160a01b900460ff1680156106955750600a544211806106955750506013541590565b600082821115612c0a576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000612c22838363ffffffff6121f716565b9050806011600001541115612c75576040805162461bcd60e51b8152602060048201526014602482015273125b9cdd59999a58da595b9d0818d85c1a5d185b60621b604482015290519081900360640190fd5b601254612c88848363ffffffff61300416565b8111158015612ca65750612ca2838363ffffffff61300416565b8111155b612ce9576040805162461bcd60e51b815260206004820152600f60248201526e109a591cc81d1bdbc81cdad95dd959608a1b604482015290519081900360640190fd5b50505050565b600080826001811115612cfe57fe5b1415612d1657506004546001600160a01b0316611fd7565b50506005546001600160a01b031690565b600080612d35858585612e3c565b604080518082018252838152602090810183905260068490556007839055815184815290810183905281519395509193507f6546f60f34df611fa42503098acc39d5ab88bc73febe64b3cc14e5a92e3a66a792918290030190a15050505050565b601354600090612dac908363ffffffff6121f716565b60138190559050612dbb612b57565b6001600160a01b031663aeab5849836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156122bb57600080fd5b6000818310612e1e57612e19838363ffffffff612bb316565b6121f0565b50600092915050565b60006121f08383670de0b6b3a764000061302e565b6000808415801590612e4d57508315155b612e95576040805162461bcd60e51b815260206004820152601460248201527342696473206d757374206265206e6f6e7a65726f60601b604482015290519081900360640190fd5b6000612ea084611fa5565b9050612eb2868263ffffffff612e2716565b612ec2868363ffffffff612e2716565b9250925050935093915050565b600081815260036020908152604080832054815170026b4b9b9b4b7339030b2323932b9b99d1607d1b9381019390935260318084018690528251808503909101815260519093019091526001600160a01b03169081612b825760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612f71578181015183820152602001612f59565b50505050905090810190601f168015612f9e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b60006106956c45786368616e6765526174657360981b612ecf565b600080600a8304612fde868663ffffffff61305416565b81612fe557fe5b0490506005600a825b0610612ff857600a015b600a9004949350505050565b60006121f08261302285670de0b6b3a764000063ffffffff61305416565b9063ffffffff6130ad16565b6000806130488461302287600a870263ffffffff61305416565b90506005600a82612fee565b60008261306357506000611867565b8282028284828161307057fe5b04146121f05760405162461bcd60e51b815260040180806020018281038252602181526020018061317e6021913960400191505060405180910390fd5b6000808211613103576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b600082848161310e57fe5b04949350505050565bfefe596f75206d757374206265206e6f6d696e61746564206265666f726520796f752063616e20616363657074206f776e6572736869704f6e6c792074686520636f6e7472616374206f776e6572206d617920706572666f726d207468697320616374696f6e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775468697320616374696f6e2063616e6e6f7420626520706572666f726d6564207768696c652074686520636f6e747261637420697320706175736564a265627a7a72315820fa3a319db20b224bf5a7fcf5735fcda6b3169d4f1c5d8e67a79c3610c5116b3c64736f6c63430005100032608060405234801561001057600080fd5b5060405161114a38038061114a8339818101604052604081101561003357600080fd5b508051602091820151600080546001600160a01b031916331781556001600160a01b0390921682526001909252604090208190556002556110d1806100796000396000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c806370a08231116100ad5780639c3ee244116100715780639c3ee24414610383578063a9059cbb146103a9578063c8db233e146103d5578063d6ff02e2146103fb578063dd62ed3e1461040357610121565b806370a082311461030357806380f55605146103295780638b0341361461034d5780638dc30b701461035557806395d89b411461037b57610121565b806323b872dd116100f457806323b872dd146102255780632bc43fd91461025b578063313ce5671461028d578063410085df146102ab57806359d667a5146102d757610121565b806306fdde0314610126578063095ea7b3146101a357806318160ddd146101e35780631b15982a146101fd575b600080fd5b61012e610431565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610168578181015183820152602001610150565b50505050905090810190601f1680156101955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101cf600480360360408110156101b957600080fd5b506001600160a01b03813516906020013561045e565b604080519115158252519081900360200190f35b6101eb6104db565b60408051918252519081900360200190f35b6102236004803603602081101561021357600080fd5b50356001600160a01b03166104e1565b005b6101cf6004803603606081101561023b57600080fd5b506001600160a01b0381358116916020810135909116906040013561060e565b6101eb6004803603606081101561027157600080fd5b506001600160a01b0381351690602081013590604001356106ca565b610295610861565b6040805160ff9092168252519081900360200190f35b610223600480360360408110156102c157600080fd5b506001600160a01b038135169060200135610866565b610223600480360360408110156102ed57600080fd5b506001600160a01b038135169060200135610920565b6101eb6004803603602081101561031957600080fd5b50356001600160a01b03166109ce565b6103316109e0565b604080516001600160a01b039092168252519081900360200190f35b6101eb6109ef565b6101eb6004803603602081101561036b57600080fd5b50356001600160a01b03166109f5565b61012e610a07565b6101eb6004803603602081101561039957600080fd5b50356001600160a01b0316610a27565b6101cf600480360360408110156103bf57600080fd5b506001600160a01b038135169060200135610ad4565b610223600480360360208110156103eb57600080fd5b50356001600160a01b0316610ae1565b6101eb610b42565b6101eb6004803603604081101561041957600080fd5b506001600160a01b0381358116916020013516610bc3565b6040518060400160405280601181526020017029a72c102134b730b93c9027b83a34b7b760791b81525081565b60006001600160a01b03831661047357600080fd5b3360008181526005602090815260408083206001600160a01b03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60045481565b6000546001600160a01b03163314610536576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b0381166000908152600360205260409020548061055a575061060b565b6001600160a01b038216600090815260036020526040812055600454610586908263ffffffff610be016565b6004556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a36040805182815290516001600160a01b038416917f696de425f79f4a40bc6d2122ca50507f0efbeabbff86a84871b7196ab8ea8df7919081900360200190a2505b50565b6001600160a01b038316600090815260056020908152604080832033845290915281205480831115610680576040805162461bcd60e51b8152602060048201526016602482015275496e73756666696369656e7420616c6c6f77616e636560501b604482015290519081900360640190fd5b610690818463ffffffff610be016565b6001600160a01b03861660009081526005602090815260408083203384529091529020556106bf858585610c3d565b9150505b9392505050565b600080546001600160a01b03163314610720576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b03841660009081526001602052604081205490610745828686610e14565b905080610757576000925050506106c3565b60025461076a908363ffffffff610be016565b6002556001600160a01b038616600090815260016020526040812055600454610799908263ffffffff610eb016565b6004556001600160a01b0386166000908152600360205260409020546107c5908263ffffffff610eb016565b6001600160a01b03871660008181526003602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a36040805182815290516001600160a01b038816917fa59f12e354e8cd10bb74c559844c2dd69a5458e31fe56c7594c62ca57480509a919081900360200190a295945050505050565b601281565b6000546001600160a01b031633146108bb576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b0382166000908152600160205260409020546108ed906108e8908363ffffffff610be016565b610f0a565b6001600160a01b038316600090815260016020526040902055600254610919908263ffffffff610be016565b6002555050565b6000546001600160a01b03163314610975576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b0382166000908152600160205260409020546109a2906108e8908363ffffffff610eb016565b6001600160a01b038316600090815260016020526040902055600254610919908263ffffffff610eb016565b60036020526000908152604090205481565b6000546001600160a01b031681565b60025481565b60016020526000908152604090205481565b604051806040016040528060048152602001631cd3d41560e21b81525081565b60008054604080516362c47a9360e11b81528151849384936001600160a01b039091169263c588f5269260048083019392829003018186803b158015610a6c57600080fd5b505afa158015610a80573d6000803e3d6000fd5b505050506040513d6040811015610a9657600080fd5b5080516020918201516001600160a01b03871660009081526001909352604090922054909350909150610aca908383610e14565b925050505b919050565b60006106c3338484610c3d565b6000546001600160a01b03163314610b36576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b806001600160a01b0316ff5b60008054604080516362c47a9360e11b8152815184936001600160a01b03169263c588f5269260048082019391829003018186803b158015610b8357600080fd5b505afa158015610b97573d6000803e3d6000fd5b505050506040513d6040811015610bad57600080fd5b50602001519050610bbd81610f67565b91505090565b600560209081526000928352604080842090915290825290205481565b600082821115610c37576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008060009054906101000a90046001600160a01b03166001600160a01b03166327745bae6040518163ffffffff1660e01b815260040160006040518083038186803b158015610c8c57600080fd5b505afa158015610ca0573d6000803e3d6000fd5b505050506001600160a01b03831615801590610cc557506001600160a01b0383163014155b610d08576040805162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b604482015290519081900360640190fd5b6001600160a01b03841660009081526003602052604090205480831115610d6d576040805162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b604482015290519081900360640190fd5b610d7d818463ffffffff610be016565b6001600160a01b038087166000908152600360205260408082209390935590861681522054610db2908463ffffffff610eb016565b6001600160a01b0380861660008181526003602090815260409182902094909455805187815290519193928916927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3506001949350505050565b600080610e27858563ffffffff610f8e16565b90506000610e3484610f67565b905060025486148015610e4657508515155b80610e4f575080155b15610e5d5791506106c39050565b80821115610ea7576040805162461bcd60e51b8152602060048201526012602482015271737570706c79203c20636c61696d61626c6560701b604482015290519081900360640190fd5b50949350505050565b6000828201838110156106c3576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000662386f26fc1000082101580610f20575081155b610f63576040805162461bcd60e51b815260206004820152600f60248201526e42616c616e6365203c2024302e303160881b604482015290519081900360640190fd5b5090565b600454600090808311610f7e576000915050610acf565b6106c3838263ffffffff610be016565b60006106c382610fac85670de0b6b3a764000063ffffffff610fb816565b9063ffffffff61101116565b600082610fc7575060006104d5565b82820282848281610fd457fe5b04146106c35760405162461bcd60e51b815260040180806020018281038252602181526020018061107c6021913960400191505060405180910390fd5b6000808211611067576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b600082848161107257fe5b0494935050505056fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a265627a7a723158209d36c4dc6e88f30ecbfe2d2658ee6038aee82f1193e73bc5e5e4fa0a5342204564736f6c63430005100032536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7770bd4a33bf447720d717d08f3affb5aecfe4d2ebb8e3dd94539f5313e2447643596f75206d757374206265206e6f6d696e61746564206265666f726520796f752063616e20616363657074206f776e6572736869704f6e6c792074686520636f6e7472616374206f776e6572206d617920706572666f726d207468697320616374696f6ea265627a7a723158205c35abe02193bdb3b33e2be9b0add96786293058b40d53c20ec9f1ddbc6fdadf64736f6c63430005100032000000000000000000000000de910777c787903f78c89e7a0bf7f4c435cbb1fe0000000000000000000000004e3b31eb0e5cb73641ee1e65e7dcefe520ba3ef2

Deployed Bytecode

0x60806040523480156200001157600080fd5b5060043610620000a05760003560e01c806353a47bb7116200006f57806353a47bb7146200016857806374185360146200017257806379ba5097146200017c578063899ffef414620001865780638da5cb5b14620001e257620000a0565b806304f3bcec14620000a5578063130efa5014620000cb5780631627540c146200011f5780632af64bd3146200014a575b600080fd5b620000af620001ec565b604080516001600160a01b039092168252519081900360200190f35b620000af60048036036101c0811015620000e457600080fd5b506001600160a01b0381351690602081019060608101359060808101359060a081013515159060c081019061012081019061016001620001fb565b62000148600480360360208110156200013757600080fd5b50356001600160a01b03166200036e565b005b62000154620003cc565b604080519115158252519081900360200190f35b620000af620004e2565b62000148620004f1565b62000148620006c4565b6200019062000782565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015620001ce578181015183820152602001620001b4565b505050509050019250505060405180910390f35b620000af620007de565b6002546001600160a01b031681565b60008062000208620007ed565b90506001600160a01b038116331462000268576040805162461bcd60e51b815260206004820152601e60248201527f4f6e6c79207065726d697474656420627920746865206d616e616765722e0000604482015290519081900360640190fd5b808a600260009054906101000a90046001600160a01b03168b8b8b8b8b8b8b604051620002959062000950565b6001600160a01b03808c1682528a8116602083015289166040808301919091526060820190899080828437600083820152601f01601f191690910188815260208101889052861515604082015260609081019150859080828437600083820152601f01601f1916909101905083604080828437600083820152601f01601f19169091019050826060808284376000838201819052604051601f909201601f19169093018190039d509b50909950505050505050505050f0801580156200035f573d6000803e3d6000fd5b509a9950505050505050505050565b620003786200081b565b600180546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce229181900360200190a150565b60006060620003da62000782565b905060005b8151811015620004d8576000828281518110620003f857fe5b6020908102919091018101516000818152600383526040908190205460025482516321f8a72160e01b81526004810185905292519395506001600160a01b03918216949116926321f8a721926024808201939291829003018186803b1580156200046157600080fd5b505afa15801562000476573d6000803e3d6000fd5b505050506040513d60208110156200048d57600080fd5b50516001600160a01b0316141580620004bb57506000818152600360205260409020546001600160a01b0316155b15620004ce5760009350505050620004df565b50600101620003df565b5060019150505b90565b6001546001600160a01b031681565b6060620004fd62000782565b905060005b8151811015620006c05760008282815181106200051b57fe5b602090810291909101810151600254604080517f5265736f6c766572206d697373696e67207461726765743a2000000000000000818601526039808201859052825180830390910181526059820180845263dacb2d0160e01b9052605d8201858152607d83019384528151609d84015281519597506000966001600160a01b039095169563dacb2d01958995939492939260bd0191908501908083838c5b83811015620005d3578181015183820152602001620005b9565b50505050905090810190601f168015620006015780820380516001836020036101000a031916815260200191505b50935050505060206040518083038186803b1580156200062057600080fd5b505afa15801562000635573d6000803e3d6000fd5b505050506040513d60208110156200064c57600080fd5b505160008381526003602090815260409182902080546001600160a01b0319166001600160a01b03851690811790915582518681529182015281519293507f88a93678a3692f6789d9546fc621bf7234b101ddb7d4fe479455112831b8aa68929081900390910190a1505060010162000502565b5050565b6001546001600160a01b031633146200070f5760405162461bcd60e51b81526004018080602001828103825260358152602001806200568d6035913960400191505060405180910390fd5b600054600154604080516001600160a01b03938416815292909116602083015280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b60408051600180825281830190925260609160208083019080388339019050509050782134b730b93ca7b83a34b7b726b0b935b2ba26b0b730b3b2b960391b81600081518110620007cf57fe5b60200260200101818152505090565b6000546001600160a01b031681565b600062000816782134b730b93ca7b83a34b7b726b0b935b2ba26b0b730b3b2b960391b62000868565b905090565b6000546001600160a01b03163314620008665760405162461bcd60e51b815260040180806020018281038252602f815260200180620056c2602f913960400191505060405180910390fd5b565b600081815260036020908152604080832054815170026b4b9b9b4b7339030b2323932b9b99d1607d1b9381019390935260318084018690528251808503909101815260519093019091526001600160a01b03169081620009495760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156200090d578181015183820152602001620008f3565b50505050905090810190601f1680156200093b5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5092915050565b614d2e806200095f8339019056fe60806040523480156200001157600080fd5b5060405162004d2e38038062004d2e83398181016040526102008110156200003857600080fd5b5080516020820151604083015160a084015160c085015160e08601519495939492936060810193906101008101906101608101906101a001878a6001600160a01b038116620000ce576040805162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f74206265203000000000000000604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b038316908117825560408051928352602083019190915280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a150600280546001600160a01b03199081166001600160a01b0393841617909155601480546040805180820182528c518082526020808f01519281018390526011919091556012919091558151606080820184528d82528183018d90526000918401829052600b8e9055600c8d9055600d919091558251908101835289518082528a8301518284018190528b85015192909401829052600855600992909255600a919091559216928c169290921760ff60a81b1916600160a81b8715150217909155825190830151620001f982826200047b565b8a6001600160a01b031660008051602062004d0e833981519152600084604051808360018111156200022757fe5b60ff1681526020018281526020019250505060405180910390a28a6001600160a01b031660008051602062004d0e833981519152600183604051808360018111156200026f57fe5b60ff1681526020018281526020019250505060405180910390a26000620002a582846200058260201b620021f71790919060201c565b6013819055845160208087015160408051606081018252848152808401839052818a01519101819052600e849055600f8290556010559293509091906200038490620002fe908490849062000582811b620021f717901c565b7384d626b2bb4d0f064067e4bf80fce7055d8f3e7b63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b1580156200034357600080fd5b505af415801562000358573d6000803e3d6000fd5b505050506040513d60208110156200036f57600080fd5b505190620005e6602090811b62002bb317901c565b6015556200039d8585856001600160e01b036200064416565b8d85604051620003ad9062000976565b6001600160a01b0390921682526020820152604080519182900301906000f080158015620003df573d6000803e3d6000fd5b50600480546001600160a01b0319166001600160a01b03929092169190911790556040518e908590620004129062000976565b6001600160a01b0390921682526020820152604080519182900301906000f08015801562000444573d6000803e3d6000fd5b50600580546001600160a01b0319166001600160a01b039290921691909117905550620009849d5050505050505050505050505050565b60006200049782846200058260201b620021f71790919060201c565b9050806011600001541115620004f4576040805162461bcd60e51b815260206004820152601460248201527f496e73756666696369656e74206361706974616c000000000000000000000000604482015290519081900360640190fd5b6012546200050f8483620006be602090811b6200300417901c565b8111158015620005385750620005348284620006be60201b620030041790919060201c565b8111155b6200057c576040805162461bcd60e51b815260206004820152600f60248201526e109a591cc81d1bdbc81cdad95dd959608a1b604482015290519081900360640190fd5b50505050565b600082820183811015620005dd576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b6000828211156200063e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000806200065d8585856001600160e01b03620006f916565b604080518082018252838152602090810183905260068490556007839055815184815290810183905281519395509193507f6546f60f34df611fa42503098acc39d5ab88bc73febe64b3cc14e5a92e3a66a792918290030190a15050505050565b6000620005dd82620006e585670de0b6b3a7640000620007b6602090811b6200305417901c565b6200081460201b620030ad1790919060201c565b60008084158015906200070b57508315155b6200075d576040805162461bcd60e51b815260206004820152601460248201527f42696473206d757374206265206e6f6e7a65726f000000000000000000000000604482015290519081900360640190fd5b600062000773846001600160e01b036200088016565b90506200078f8187620008bb60201b62002e271790919060201c565b620007a98287620008bb60201b62002e271790919060201c565b9250925050935093915050565b600082620007c757506000620005e0565b82820282848281620007d557fe5b0414620005dd5760405162461bcd60e51b815260040180806020018281038252602181526020018062004ced6021913960400191505060405180910390fd5b60008082116200086b576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b60008284816200087757fe5b04949350505050565b601454600090600160a01b900460ff16620008b757620008b160155483620008db60201b620021db1790919060201c565b620005e0565b5090565b6000620005dd8383670de0b6b3a76400006001600160e01b03620008fb16565b6000620005dd8383670de0b6b3a76400006001600160e01b036200093f16565b6000806200092084620006e585600a0288620007b660201b620030541790919060201c565b90506005600a825b06106200093357600a015b600a9004949350505050565b600080600a8304620009608587620007b660201b620030541790919060201c565b816200096857fe5b0490506005600a8262000928565b61114a8062003ba383390190565b61320f80620009946000396000f3fe608060405234801561001057600080fd5b50600436106102485760003560e01c8063851492581161013b578063be5af9fe116100b8578063d3419bf31161007c578063d3419bf31461055c578063dbea363814610564578063e4cfbdbd1461058a578063eef49ee3146105c2578063fd087ee5146105ca57610248565b8063be5af9fe14610516578063c588f5261461051e578063c7a5bdc814610526578063c8db233e1461052e578063d068cdc51461055457610248565b80639af1d35a116100ff5780639af1d35a146104c05780639e3b34bf146104c8578063ac3791e3146104d0578063b1c9fe6e146104d8578063b634bfbc146104f057610248565b8063851492581461042a578063899ffef4146104325780638b0341361461048a5780638da5cb5b1461049257806398508ecd1461049a57610248565b80633dae89eb116101c957806353a47bb71161018d57806353a47bb7146103c05780636392a51f146103c857806365372147146103ee578063741853601461041a57806379ba50971461042257610248565b80633dae89eb1461035c5780633f6fa65514610364578063408e82af1461036c5780634c33fe9414610392578063532f1179146103b857610248565b806327745bae1161021057806327745bae146102e95780632810e1d6146102f157806329e77b5d146102f95780632af64bd3146103385780633d7a783b1461035457610248565b806302d05d3f1461024d57806304f3bcec146102715780631069143a146102795780631627540c146102a75780632115e303146102cf575b600080fd5b6102556105f8565b604080516001600160a01b039092168252519081900360200190f35b610255610607565b610281610616565b604080516001600160a01b03938416815291909216602082015281519081900390910190f35b6102cd600480360360208110156102bd57600080fd5b50356001600160a01b031661062c565b005b6102d7610688565b60408051918252519081900360200190f35b6102cd61069b565b6102cd6106fd565b61031f6004803603602081101561030f57600080fd5b50356001600160a01b0316610ad1565b6040805192835260208301919091528051918290030190f35b610340610ae6565b604080519115158252519081900360200190f35b61031f610bf0565b61031f610cdb565b610340610cee565b61031f6004803603602081101561038257600080fd5b50356001600160a01b0316610cfe565b6102cd600480360360208110156103a857600080fd5b50356001600160a01b0316610d0a565b610340610df4565b610255610e04565b61031f600480360360208110156103de57600080fd5b50356001600160a01b0316610e13565b6103f6610e1f565b6040518082600181111561040657fe5b60ff16815260200191505060405180910390f35b6102cd610e29565b6102cd610ff1565b6102d76110ad565b61043a61139e565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561047657818101518382015260200161045e565b505050509050019250505060405180910390f35b61031f611461565b61025561146c565b6104a261147b565b60408051938452602084019290925282820152519081900360600190f35b6104a2611487565b6104a2611493565b61034061149f565b6104e06114e2565b6040518082600381111561040657fe5b6102d76004803603604081101561050657600080fd5b5060ff8135169060200135611526565b61031f61186d565b61031f611876565b61031f611945565b6102cd6004803603602081101561054457600080fd5b50356001600160a01b0316611950565b61031f6119bd565b61031f611a72565b6102cd6004803603604081101561057a57600080fd5b5060ff8135169060200135611a7b565b6102d7600480360360808110156105a057600080fd5b5060ff8135811691602081013590911690604081013590606001351515611c64565b6102d7611e65565b61031f600480360360608110156105e057600080fd5b5060ff81351690602081013590604001351515611e6b565b6014546001600160a01b031681565b6002546001600160a01b031681565b6004546005546001600160a01b03918216911682565b610634611f5c565b600180546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce229181900360200190a150565b6000610695601354611fa5565b90505b90565b6106a3611fdc565b6001600160a01b031663086dabd16040518163ffffffff1660e01b815260040160006040518083038186803b1580156106db57600080fd5b505afa1580156106ef573d6000803e3d6000fd5b505050506106fb611ff6565b565b610705611f5c565b61070d61209e565b61074f576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420796574206d617475726560901b604482015290519081900360640190fd5b610757611fdc565b6001600160a01b031663086dabd16040518163ffffffff1660e01b815260040160006040518083038186803b15801561078f57600080fd5b505afa1580156107a3573d6000803e3d6000fd5b505050506107af611ff6565b601454600160a01b900460ff161561080e576040805162461bcd60e51b815260206004820152601760248201527f4d61726b657420616c7265616479207265736f6c766564000000000000000000604482015290519081900360640190fd5b6000806108196120a6565b9150915061082681612134565b610868576040805162461bcd60e51b815260206004820152600e60248201526d5072696365206973207374616c6560901b604482015290519081900360640190fd5b600d8290556014805460ff60a01b1916600160a01b179055600061088a6121c4565b601354600e54919250906000906108a890839063ffffffff6121db16565b600f549091506000906108c290849063ffffffff6121db16565b90506108dc6108d7828463ffffffff6121f716565b612251565b50836001600160a01b031663a9059cbb6108f46122d8565b6001600160a01b031663eb1edd616040518163ffffffff1660e01b815260040160206040518083038186803b15801561092c57600080fd5b505afa158015610940573d6000803e3d6000fd5b505050506040513d602081101561095657600080fd5b5051604080516001600160e01b031960e085901b1681526001600160a01b039092166004830152602482018690525160448083019260209291908290030181600087803b1580156109a657600080fd5b505af11580156109ba573d6000803e3d6000fd5b505050506040513d60208110156109d057600080fd5b50506014546040805163a9059cbb60e01b81526001600160a01b0392831660048201526024810184905290519186169163a9059cbb916044808201926020929091908290030181600087803b158015610a2857600080fd5b505af1158015610a3c573d6000803e3d6000fd5b505050506040513d6020811015610a5257600080fd5b507f5528b7e06f48a519cf814c4e5293ee2737c3f5c28d93e30cca112ac649fdd2359050610a7e6122ed565b8787601354868660405180876001811115610a9557fe5b60ff1681526020810196909652506040808601949094526060850192909252608084015260a0830152519081900360c0019150a1505050505050565b600080610add83612332565b91509150915091565b60006060610af261139e565b905060005b8151811015610be7576000828281518110610b0e57fe5b6020908102919091018101516000818152600383526040908190205460025482516321f8a72160e01b81526004810185905292519395506001600160a01b03918216949116926321f8a721926024808201939291829003018186803b158015610b7657600080fd5b505afa158015610b8a573d6000803e3d6000fd5b505050506040513d6020811015610ba057600080fd5b50516001600160a01b0316141580610bcd57506000818152600360205260409020546001600160a01b0316155b15610bde5760009350505050610698565b50600101610af7565b50600191505090565b6004805460408051636b7f817160e11b8152905160009384936001600160a01b03169263d6ff02e29281830192602092829003018186803b158015610c3457600080fd5b505afa158015610c48573d6000803e3d6000fd5b505050506040513d6020811015610c5e57600080fd5b505160055460408051636b7f817160e11b815290516001600160a01b039092169163d6ff02e291600481810192602092909190829003018186803b158015610ca557600080fd5b505afa158015610cb9573d6000803e3d6000fd5b505050506040513d6020811015610ccf57600080fd5b505190925090505b9091565b600080610ce6612433565b915091509091565b601454600160a01b900460ff1681565b600080610add836126fd565b610d12611f5c565b610d1a6127c8565b15610d5f576040805162461bcd60e51b815260206004820152601060248201526f42696464696e6720696e61637469766560801b604482015290519081900360640190fd5b600080610d6a6127d0565b60145491935091506000908190610d89906001600160a01b0316612332565b9150915060008285148015610d9d57508184145b905080610de3576040805162461bcd60e51b815260206004820152600f60248201526e4e6f742063616e63656c6c61626c6560881b604482015290519081900360640190fd5b610dec86612885565b505050505050565b601454600160a81b900460ff1681565b6001546001600160a01b031681565b600080610add83612a8c565b60006106956122ed565b6060610e3361139e565b905060005b8151811015610fed576000828281518110610e4f57fe5b602090810291909101810151600254604080517f5265736f6c766572206d697373696e67207461726765743a2000000000000000818601526039808201859052825180830390910181526059820180845263dacb2d0160e01b9052605d8201858152607d83019384528151609d84015281519597506000966001600160a01b039095169563dacb2d01958995939492939260bd0191908501908083838c5b83811015610f05578181015183820152602001610eed565b50505050905090810190601f168015610f325780820380516001836020036101000a031916815260200191505b50935050505060206040518083038186803b158015610f5057600080fd5b505afa158015610f64573d6000803e3d6000fd5b505050506040513d6020811015610f7a57600080fd5b505160008381526003602090815260409182902080546001600160a01b0319166001600160a01b03851690811790915582518681529182015281519293507f88a93678a3692f6789d9546fc621bf7234b101ddb7d4fe479455112831b8aa68929081900390910190a15050600101610e38565b5050565b6001546001600160a01b0316331461103a5760405162461bcd60e51b815260040180806020018281038252603581526020018061311a6035913960400191505060405180910390fd5b600054600154604080516001600160a01b03938416815292909116602083015280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b601454600090600160a01b900460ff16611139576110c9612b57565b6001600160a01b0316637859f410306040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050600060405180830381600087803b15801561112057600080fd5b505af1158015611134573d6000803e3d6000fd5b505050505b600080611145336126fd565b9150915081600014158061115857508015155b1561116857611165612433565b50505b60008061117433612a8c565b9150915081600014158061118757508015155b6111ce576040805162461bcd60e51b81526020600482015260136024820152724e6f7468696e6720746f20657865726369736560681b604482015290519081900360640190fd5b811561123a576004805460408051630d8acc1560e11b81523393810193909352516001600160a01b0390911691631b15982a91602480830192600092919082900301818387803b15801561122157600080fd5b505af1158015611235573d6000803e3d6000fd5b505050505b80156112a55760055460408051630d8acc1560e11b815233600482015290516001600160a01b0390921691631b15982a9160248082019260009290919082900301818387803b15801561128c57600080fd5b505af11580156112a0573d6000803e3d6000fd5b505050505b60006112b96112b26122ed565b8484612b66565b60408051828152905191925033917fd82b6f69d7477fb41cd83d936de94990cee2fa1a309feeee90101fc0513b6a439181900360200190a280156113955761130081612251565b506113096121c4565b6001600160a01b031663a9059cbb33836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561136857600080fd5b505af115801561137c573d6000803e3d6000fd5b505050506040513d602081101561139257600080fd5b50505b94505050505090565b60408051600480825260a08201909252606091602082016080803883390190505090506b53797374656d53746174757360a01b816000815181106113de57fe5b6020026020010181815250506c45786368616e6765526174657360981b8160018151811061140857fe5b6020026020010181815250506814de5b9d1a1cd554d160ba1b8160028151811061142e57fe5b60200260200101818152505066119959541bdbdb60ca1b8160038151811061145257fe5b60200260200101818152505090565b600080610ce66127d0565b6000546001600160a01b031681565b600b54600c54600d5483565b600e54600f5460105483565b600854600954600a5483565b6000806114aa6120a6565b601454909250600160a01b900460ff1615905080156114cc57506114cc61209e565b80156114dc57506114dc81612134565b91505090565b60006114ec6127c8565b6114f857506000610698565b61150061209e565b61150c57506001610698565b611514612b89565b61152057506002610698565b50600390565b60006115306127c8565b15611575576040805162461bcd60e51b815260206004820152601060248201526f42696464696e6720696e61637469766560801b604482015290519081900360640190fd5b601454600160a81b900460ff166115c6576040805162461bcd60e51b815260206004820152601060248201526f1499599d5b991cc8191a5cd8589b195960821b604482015290519081900360640190fd5b816115d357506000611867565b6014546001600160a01b0316331415611629576000806115f233612332565b9092509050600185600181111561160557fe5b141561160d57905b611626611620838663ffffffff612bb316565b82612c10565b50505b6116be6116b1600e600201547384d626b2bb4d0f064067e4bf80fce7055d8f3e7b63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b15801561167957600080fd5b505af415801561168d573d6000803e3d6000fd5b505050506040513d60208110156116a357600080fd5b50519063ffffffff612bb316565b839063ffffffff6121db16565b90506116c983612cef565b6001600160a01b031663410085df33846040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561172857600080fd5b505af115801561173c573d6000803e3d6000fd5b503392507f9bd0a8ca6625e01a9cee5e86eec7813a8234b41f1ca0c9f15a008d1e1d00ee5f915085905083611777868263ffffffff612bb316565b6040518084600181111561178757fe5b60ff168152602001838152602001828152602001935050505060405180910390a260006117b382612251565b90506117bd6121c4565b6001600160a01b031663a9059cbb33846040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561181c57600080fd5b505af1158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5060009050806118546127d0565b91509150611863828285612d27565b5050505b92915050565b60115460125482565b6014546000908190600160a01b900460ff1615806118ab5750336118a061189b6122ed565b612cef565b6001600160a01b0316145b156118be576118bb601354611fa5565b90505b6004546001600160a01b03163314156118db576006549150610cd7565b6005546001600160a01b03163314156118f8576007549150610cd7565b6040805162461bcd60e51b815260206004820152601760248201527f53656e646572206973206e6f7420616e206f7074696f6e000000000000000000604482015290519081900360640190fd5b600080610ce66120a6565b611958611f5c565b611960612b89565b6119b1576040805162461bcd60e51b815260206004820152601b60248201527f556e65787069726564206f7074696f6e732072656d61696e696e670000000000604482015290519081900360640190fd5b6119ba81612885565b50565b60048054604080516318160ddd60e01b8152905160009384936001600160a01b0316926318160ddd9281830192602092829003018186803b158015611a0157600080fd5b505afa158015611a15573d6000803e3d6000fd5b505050506040513d6020811015611a2b57600080fd5b5051600554604080516318160ddd60e01b815290516001600160a01b03909216916318160ddd91600481810192602092909190829003018186803b158015610ca557600080fd5b60065460075482565b611a836127c8565b15611ac8576040805162461bcd60e51b815260206004820152601060248201526f42696464696e6720696e61637469766560801b604482015290519081900360640190fd5b80611ad257610fed565b611adb82612cef565b6001600160a01b03166359d667a533836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b158015611b3a57600080fd5b505af1158015611b4e573d6000803e3d6000fd5b50505050336001600160a01b03167f70bd4a33bf447720d717d08f3affb5aecfe4d2ebb8e3dd94539f5313e2447643838360405180836001811115611b8f57fe5b60ff1681526020018281526020019250505060405180910390a26000611bb482612d96565b9050611bbe6121c4565b604080516323b872dd60e01b81523360048201523060248201526044810185905290516001600160a01b0392909216916323b872dd916064808201926020929091908290030181600087803b158015611c1657600080fd5b505af1158015611c2a573d6000803e3d6000fd5b505050506040513d6020811015611c4057600080fd5b506000905080611c4e6127d0565b91509150611c5d828285612d27565b5050505050565b600080611c7c601554856121db90919063ffffffff16565b90506000611c8986612cef565b6001600160a01b0316638b0341366040518163ffffffff1660e01b815260040160206040518083038186803b158015611cc157600080fd5b505afa158015611cd5573d6000803e3d6000fd5b505050506040513d6020811015611ceb57600080fd5b505160135460408051630241ebdb60e61b8152905192935090916000917384d626b2bb4d0f064067e4bf80fce7055d8f3e7b9163907af6c091600480820192602092909190829003018186803b158015611d4457600080fd5b505af4158015611d58573d6000803e3d6000fd5b505050506040513d6020811015611d6e57600080fd5b5051601054909150600090611d8a90839063ffffffff612bb316565b9050886001811115611d9857fe5b8a6001811115611da457fe5b1415611e0e576000611dbc848763ffffffff6121db16565b90508715611dd85793611dd5868363ffffffff6121db16565b95505b611e01611deb848863ffffffff612bb316565b611df58388612e00565b9063ffffffff612e2716565b9650505050505050611e5d565b6000611e20858763ffffffff612e2716565b90508715611e2a57925b6000611e368286612e00565b905088611e435780611e53565b611e53818463ffffffff612e2716565b9750505050505050505b949350505050565b60135481565b600080600080611e796127d0565b9150915061311785611e8d576121f7611e91565b612bb35b90506000886001811115611ea157fe5b1415611ebc57611eb583888363ffffffff16565b9250611ecd565b611eca82888363ffffffff16565b91505b8515611f3357611f30611f23600e600201547384d626b2bb4d0f064067e4bf80fce7055d8f3e7b63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b15801561167957600080fd5b889063ffffffff6121db16565b96505b611f4d8383611f486013548b8663ffffffff16565b612e3c565b94509450505050935093915050565b6000546001600160a01b031633146106fb5760405162461bcd60e51b815260040180806020018281038252602f81526020018061314f602f913960400191505060405180910390fd5b601454600090600160a01b900460ff16611fd257601554611fcd90839063ffffffff6121db16565b611fd4565b815b90505b919050565b60006106956b53797374656d53746174757360a01b612ecf565b611ffe612b57565b6001600160a01b0316635c975abb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561203657600080fd5b505afa15801561204a573d6000803e3d6000fd5b505050506040513d602081101561206057600080fd5b5051156106fb5760405162461bcd60e51b815260040180806020018281038252603c81526020018061319f603c913960400191505060405180910390fd5b600954421190565b6000806120b1612fac565b6001600160a01b0316634308a94f600b600001546040518263ffffffff1660e01b815260040180828152602001915050604080518083038186803b1580156120f857600080fd5b505afa15801561210c573d6000803e3d6000fd5b505050506040513d604081101561212257600080fd5b50805160209091015190925090509091565b60008061213f612b57565b6001600160a01b0316634a41d89d6040518163ffffffff1660e01b815260040160606040518083038186803b15801561217757600080fd5b505afa15801561218b573d6000803e3d6000fd5b505050506040513d60608110156121a157600080fd5b505160095490915083906121bb908363ffffffff612bb316565b11159392505050565b60006106956814de5b9d1a1cd554d160ba1b612ecf565b60006121f08383670de0b6b3a7640000612fc7565b9392505050565b6000828201838110156121f0576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b601354600090612267908363ffffffff612bb316565b60138190559050612276612b57565b6001600160a01b0316636b3a0984836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156122bb57600080fd5b505af11580156122cf573d6000803e3d6000fd5b50505050919050565b600061069566119959541bdbdb60ca1b612ecf565b6014546000908190600160a01b900460ff161561230d5750600d54612319565b6123156120a6565b5090505b600c5481101561232a5760016114dc565b600091505090565b60048054604080516308dc30b760e41b81526001600160a01b0385811694820194909452905160009384931691638dc30b70916024808301926020929190829003018186803b15801561238457600080fd5b505afa158015612398573d6000803e3d6000fd5b505050506040513d60208110156123ae57600080fd5b5051600554604080516308dc30b760e41b81526001600160a01b03878116600483015291519190921691638dc30b70916024808301926020929190829003018186803b1580156123fd57600080fd5b505afa158015612411573d6000803e3d6000fd5b505050506040513d602081101561242757600080fd5b50519092509050915091565b60008061243e611fdc565b6001600160a01b031663086dabd16040518163ffffffff1660e01b815260040160006040518083038186803b15801561247657600080fd5b505afa15801561248a573d6000803e3d6000fd5b50505050612496611ff6565b61249e6127c8565b6124e4576040805162461bcd60e51b815260206004820152601260248201527142696464696e6720696e636f6d706c65746560701b604482015290519081900360640190fd5b60006124f1601354611fa5565b905060006124fd6122ed565b601454909150600160a01b900460ff166000808215806125285750600084600181111561252657fe5b145b156125bc576004805460065460408051632bc43fd960e01b81523394810194909452602484019190915260448301889052516001600160a01b0390911691632bc43fd99160648083019260209291908290030181600087803b15801561258d57600080fd5b505af11580156125a1573d6000803e3d6000fd5b505050506040513d60208110156125b757600080fd5b505191505b8215806125d4575060018460018111156125d257fe5b145b156126665760055460075460408051632bc43fd960e01b8152336004820152602481019290925260448201889052516001600160a01b0390921691632bc43fd9916064808201926020929091908290030181600087803b15801561263757600080fd5b505af115801561264b573d6000803e3d6000fd5b505050506040513d602081101561266157600080fd5b505190505b8115158061267357508015155b6126b7576040805162461bcd60e51b815260206004820152601060248201526f4e6f7468696e6720746f20636c61696d60801b604482015290519081900360640190fd5b6040805183815260208101839052815133927fbbe753caa9bb201dbd1740ee3d61c6d2adf5fa89f30233d732281ae5db6a03d4928290030190a290955093505050509091565b600480546040805163270fb89160e21b81526001600160a01b0385811694820194909452905160009384931691639c3ee244916024808301926020929190829003018186803b15801561274f57600080fd5b505afa158015612763573d6000803e3d6000fd5b505050506040513d602081101561277957600080fd5b50516005546040805163270fb89160e21b81526001600160a01b03878116600483015291519190921691639c3ee244916024808301926020929190829003018186803b1580156123fd57600080fd5b600854421190565b6004805460408051634581a09b60e11b8152905160009384936001600160a01b031692638b0341369281830192602092829003018186803b15801561281457600080fd5b505afa158015612828573d6000803e3d6000fd5b505050506040513d602081101561283e57600080fd5b505160055460408051634581a09b60e11b815290516001600160a01b0390921691638b03413691600481810192602092909190829003018186803b158015610ca557600080fd5b60135480156128995761289781612251565b505b60006128a36121c4565b604080516370a0823160e01b815230600482015290519192506000916001600160a01b038416916370a08231916024808301926020929190829003018186803b1580156128ef57600080fd5b505afa158015612903573d6000803e3d6000fd5b505050506040513d602081101561291957600080fd5b5051905080156129b057816001600160a01b031663a9059cbb85836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561298357600080fd5b505af1158015612997573d6000803e3d6000fd5b505050506040513d60208110156129ad57600080fd5b50505b600480546040805163646d919f60e11b81526001600160a01b03888116948201949094529051929091169163c8db233e9160248082019260009290919082900301818387803b158015612a0257600080fd5b505af1158015612a16573d6000803e3d6000fd5b50506005546040805163646d919f60e11b81526001600160a01b038981166004830152915191909216935063c8db233e9250602480830192600092919082900301818387803b158015612a6857600080fd5b505af1158015612a7c573d6000803e3d6000fd5b50505050836001600160a01b0316ff5b60048054604080516370a0823160e01b81526001600160a01b03858116948201949094529051600093849316916370a08231916024808301926020929190829003018186803b158015612ade57600080fd5b505afa158015612af2573d6000803e3d6000fd5b505050506040513d6020811015612b0857600080fd5b5051600554604080516370a0823160e01b81526001600160a01b038781166004830152915191909216916370a08231916024808301926020929190829003018186803b1580156123fd57600080fd5b6000546001600160a01b031690565b600080846001811115612b7557fe5b1415612b825750816121f0565b5092915050565b601454600090600160a01b900460ff1680156106955750600a544211806106955750506013541590565b600082821115612c0a576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000612c22838363ffffffff6121f716565b9050806011600001541115612c75576040805162461bcd60e51b8152602060048201526014602482015273125b9cdd59999a58da595b9d0818d85c1a5d185b60621b604482015290519081900360640190fd5b601254612c88848363ffffffff61300416565b8111158015612ca65750612ca2838363ffffffff61300416565b8111155b612ce9576040805162461bcd60e51b815260206004820152600f60248201526e109a591cc81d1bdbc81cdad95dd959608a1b604482015290519081900360640190fd5b50505050565b600080826001811115612cfe57fe5b1415612d1657506004546001600160a01b0316611fd7565b50506005546001600160a01b031690565b600080612d35858585612e3c565b604080518082018252838152602090810183905260068490556007839055815184815290810183905281519395509193507f6546f60f34df611fa42503098acc39d5ab88bc73febe64b3cc14e5a92e3a66a792918290030190a15050505050565b601354600090612dac908363ffffffff6121f716565b60138190559050612dbb612b57565b6001600160a01b031663aeab5849836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156122bb57600080fd5b6000818310612e1e57612e19838363ffffffff612bb316565b6121f0565b50600092915050565b60006121f08383670de0b6b3a764000061302e565b6000808415801590612e4d57508315155b612e95576040805162461bcd60e51b815260206004820152601460248201527342696473206d757374206265206e6f6e7a65726f60601b604482015290519081900360640190fd5b6000612ea084611fa5565b9050612eb2868263ffffffff612e2716565b612ec2868363ffffffff612e2716565b9250925050935093915050565b600081815260036020908152604080832054815170026b4b9b9b4b7339030b2323932b9b99d1607d1b9381019390935260318084018690528251808503909101815260519093019091526001600160a01b03169081612b825760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612f71578181015183820152602001612f59565b50505050905090810190601f168015612f9e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b60006106956c45786368616e6765526174657360981b612ecf565b600080600a8304612fde868663ffffffff61305416565b81612fe557fe5b0490506005600a825b0610612ff857600a015b600a9004949350505050565b60006121f08261302285670de0b6b3a764000063ffffffff61305416565b9063ffffffff6130ad16565b6000806130488461302287600a870263ffffffff61305416565b90506005600a82612fee565b60008261306357506000611867565b8282028284828161307057fe5b04146121f05760405162461bcd60e51b815260040180806020018281038252602181526020018061317e6021913960400191505060405180910390fd5b6000808211613103576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b600082848161310e57fe5b04949350505050565bfefe596f75206d757374206265206e6f6d696e61746564206265666f726520796f752063616e20616363657074206f776e6572736869704f6e6c792074686520636f6e7472616374206f776e6572206d617920706572666f726d207468697320616374696f6e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775468697320616374696f6e2063616e6e6f7420626520706572666f726d6564207768696c652074686520636f6e747261637420697320706175736564a265627a7a72315820fa3a319db20b224bf5a7fcf5735fcda6b3169d4f1c5d8e67a79c3610c5116b3c64736f6c63430005100032608060405234801561001057600080fd5b5060405161114a38038061114a8339818101604052604081101561003357600080fd5b508051602091820151600080546001600160a01b031916331781556001600160a01b0390921682526001909252604090208190556002556110d1806100796000396000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c806370a08231116100ad5780639c3ee244116100715780639c3ee24414610383578063a9059cbb146103a9578063c8db233e146103d5578063d6ff02e2146103fb578063dd62ed3e1461040357610121565b806370a082311461030357806380f55605146103295780638b0341361461034d5780638dc30b701461035557806395d89b411461037b57610121565b806323b872dd116100f457806323b872dd146102255780632bc43fd91461025b578063313ce5671461028d578063410085df146102ab57806359d667a5146102d757610121565b806306fdde0314610126578063095ea7b3146101a357806318160ddd146101e35780631b15982a146101fd575b600080fd5b61012e610431565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610168578181015183820152602001610150565b50505050905090810190601f1680156101955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101cf600480360360408110156101b957600080fd5b506001600160a01b03813516906020013561045e565b604080519115158252519081900360200190f35b6101eb6104db565b60408051918252519081900360200190f35b6102236004803603602081101561021357600080fd5b50356001600160a01b03166104e1565b005b6101cf6004803603606081101561023b57600080fd5b506001600160a01b0381358116916020810135909116906040013561060e565b6101eb6004803603606081101561027157600080fd5b506001600160a01b0381351690602081013590604001356106ca565b610295610861565b6040805160ff9092168252519081900360200190f35b610223600480360360408110156102c157600080fd5b506001600160a01b038135169060200135610866565b610223600480360360408110156102ed57600080fd5b506001600160a01b038135169060200135610920565b6101eb6004803603602081101561031957600080fd5b50356001600160a01b03166109ce565b6103316109e0565b604080516001600160a01b039092168252519081900360200190f35b6101eb6109ef565b6101eb6004803603602081101561036b57600080fd5b50356001600160a01b03166109f5565b61012e610a07565b6101eb6004803603602081101561039957600080fd5b50356001600160a01b0316610a27565b6101cf600480360360408110156103bf57600080fd5b506001600160a01b038135169060200135610ad4565b610223600480360360208110156103eb57600080fd5b50356001600160a01b0316610ae1565b6101eb610b42565b6101eb6004803603604081101561041957600080fd5b506001600160a01b0381358116916020013516610bc3565b6040518060400160405280601181526020017029a72c102134b730b93c9027b83a34b7b760791b81525081565b60006001600160a01b03831661047357600080fd5b3360008181526005602090815260408083206001600160a01b03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60045481565b6000546001600160a01b03163314610536576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b0381166000908152600360205260409020548061055a575061060b565b6001600160a01b038216600090815260036020526040812055600454610586908263ffffffff610be016565b6004556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a36040805182815290516001600160a01b038416917f696de425f79f4a40bc6d2122ca50507f0efbeabbff86a84871b7196ab8ea8df7919081900360200190a2505b50565b6001600160a01b038316600090815260056020908152604080832033845290915281205480831115610680576040805162461bcd60e51b8152602060048201526016602482015275496e73756666696369656e7420616c6c6f77616e636560501b604482015290519081900360640190fd5b610690818463ffffffff610be016565b6001600160a01b03861660009081526005602090815260408083203384529091529020556106bf858585610c3d565b9150505b9392505050565b600080546001600160a01b03163314610720576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b03841660009081526001602052604081205490610745828686610e14565b905080610757576000925050506106c3565b60025461076a908363ffffffff610be016565b6002556001600160a01b038616600090815260016020526040812055600454610799908263ffffffff610eb016565b6004556001600160a01b0386166000908152600360205260409020546107c5908263ffffffff610eb016565b6001600160a01b03871660008181526003602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a36040805182815290516001600160a01b038816917fa59f12e354e8cd10bb74c559844c2dd69a5458e31fe56c7594c62ca57480509a919081900360200190a295945050505050565b601281565b6000546001600160a01b031633146108bb576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b0382166000908152600160205260409020546108ed906108e8908363ffffffff610be016565b610f0a565b6001600160a01b038316600090815260016020526040902055600254610919908263ffffffff610be016565b6002555050565b6000546001600160a01b03163314610975576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b6001600160a01b0382166000908152600160205260409020546109a2906108e8908363ffffffff610eb016565b6001600160a01b038316600090815260016020526040902055600254610919908263ffffffff610eb016565b60036020526000908152604090205481565b6000546001600160a01b031681565b60025481565b60016020526000908152604090205481565b604051806040016040528060048152602001631cd3d41560e21b81525081565b60008054604080516362c47a9360e11b81528151849384936001600160a01b039091169263c588f5269260048083019392829003018186803b158015610a6c57600080fd5b505afa158015610a80573d6000803e3d6000fd5b505050506040513d6040811015610a9657600080fd5b5080516020918201516001600160a01b03871660009081526001909352604090922054909350909150610aca908383610e14565b925050505b919050565b60006106c3338484610c3d565b6000546001600160a01b03163314610b36576040805162461bcd60e51b815260206004820152601360248201527213db9b1e481b585c9ad95d08185b1b1bddd959606a1b604482015290519081900360640190fd5b806001600160a01b0316ff5b60008054604080516362c47a9360e11b8152815184936001600160a01b03169263c588f5269260048082019391829003018186803b158015610b8357600080fd5b505afa158015610b97573d6000803e3d6000fd5b505050506040513d6040811015610bad57600080fd5b50602001519050610bbd81610f67565b91505090565b600560209081526000928352604080842090915290825290205481565b600082821115610c37576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008060009054906101000a90046001600160a01b03166001600160a01b03166327745bae6040518163ffffffff1660e01b815260040160006040518083038186803b158015610c8c57600080fd5b505afa158015610ca0573d6000803e3d6000fd5b505050506001600160a01b03831615801590610cc557506001600160a01b0383163014155b610d08576040805162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b604482015290519081900360640190fd5b6001600160a01b03841660009081526003602052604090205480831115610d6d576040805162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b604482015290519081900360640190fd5b610d7d818463ffffffff610be016565b6001600160a01b038087166000908152600360205260408082209390935590861681522054610db2908463ffffffff610eb016565b6001600160a01b0380861660008181526003602090815260409182902094909455805187815290519193928916927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3506001949350505050565b600080610e27858563ffffffff610f8e16565b90506000610e3484610f67565b905060025486148015610e4657508515155b80610e4f575080155b15610e5d5791506106c39050565b80821115610ea7576040805162461bcd60e51b8152602060048201526012602482015271737570706c79203c20636c61696d61626c6560701b604482015290519081900360640190fd5b50949350505050565b6000828201838110156106c3576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000662386f26fc1000082101580610f20575081155b610f63576040805162461bcd60e51b815260206004820152600f60248201526e42616c616e6365203c2024302e303160881b604482015290519081900360640190fd5b5090565b600454600090808311610f7e576000915050610acf565b6106c3838263ffffffff610be016565b60006106c382610fac85670de0b6b3a764000063ffffffff610fb816565b9063ffffffff61101116565b600082610fc7575060006104d5565b82820282848281610fd457fe5b04146106c35760405162461bcd60e51b815260040180806020018281038252602181526020018061107c6021913960400191505060405180910390fd5b6000808211611067576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b600082848161107257fe5b0494935050505056fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a265627a7a723158209d36c4dc6e88f30ecbfe2d2658ee6038aee82f1193e73bc5e5e4fa0a5342204564736f6c63430005100032536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7770bd4a33bf447720d717d08f3affb5aecfe4d2ebb8e3dd94539f5313e2447643596f75206d757374206265206e6f6d696e61746564206265666f726520796f752063616e20616363657074206f776e6572736869704f6e6c792074686520636f6e7472616374206f776e6572206d617920706572666f726d207468697320616374696f6ea265627a7a723158205c35abe02193bdb3b33e2be9b0add96786293058b40d53c20ec9f1ddbc6fdadf64736f6c63430005100032

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

000000000000000000000000de910777c787903f78c89e7a0bf7f4c435cbb1fe0000000000000000000000004e3b31eb0e5cb73641ee1e65e7dcefe520ba3ef2

-----Decoded View---------------
Arg [0] : _owner (address): 0xDe910777C787903F78C89e7a0bf7F4C435cBB1Fe
Arg [1] : _resolver (address): 0x4E3b31eB0E5CB73641EE1E65E7dCEFe520bA3ef2

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000de910777c787903f78c89e7a0bf7f4c435cbb1fe
Arg [1] : 0000000000000000000000004e3b31eb0e5cb73641ee1e65e7dcefe520ba3ef2


Libraries Used


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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